Blacklisted but not in IPFW table

Create issue
Issue #110 closed
Former user created an issue

Good morning,

I am running SSHGuard 2.2.0 on FreeBSD 11.2. It successfully captures SSH and SMTPauth failures, creating temporary blocks which appear in IPFW table 22.

I have enabled /var/db/sshguard/blacklist.db and by the time it is growing (currently about 1000 records). I can view it via cat. But IPs in the blacklist are not in table 22 - currently the table is empty.

I am pretty sure SSHguard only add its records into defined table, and has no direct access to the firewall itself. So how could be blacklisted IPs disabled permanently, if they are not in the table 22?

What is wrong? Please advise.

Many thanks in advance. Have a nice day :-)

Peter Rosa

Comments (11)

  1. Kevin Zheng

    You're right, it looks like something is wrong. Either SSHGuard isn't loading the blacklisted addresses when it starts up (1), or it's not able to add the entries to the firewall (2). To troubleshoot 2:

    From your shell, run: echo "block" | $PREFIX/libexec/sshg-fw-ipfw

    Replacing "" with an address you don't care about. Make sure that actually appears in your table 22.

  2. Peter Rosa

    OK, I tried following commands:

    # echo "block" | /usr/local/libexec/sshg-fw-ipfw
    added: 0
    # ipfw table 22 list
    --- table(22), set(0) ---
    ** 0** 0 0 0
    # echo "block" | /usr/local/libexec/sshg-fw-ipfw
    exists: 0
    ipfw: Adding record failed: record already exists
    # ipfw table 22 list
    --- table(22), set(0) ---
    ** 0** 0 0 0

    As you can see, it is not there, but "echo "block" | /usr/local/libexec/sshg-fw-ipfw" creates entry which effectively stops all communication. I double checked - it is really added by above command.

    If I use netmask/32, it is added and shows in the table

    # echo "block" | /usr/local/libexec/sshg-fw-ipfw
    added: 0
    # ipfw table 22 list
    --- table(22), set(0) --- 0 0 0
    ** 0** 0 0 0 0
  3. Kevin Zheng

    Sorry, I made a mistake in the command I gave you. It should be:

    $ echo "block 4 32" | $PREFIX/libexec/sshg-fw-ipfw

    Where those three fields are address, address type (4 or 6), and the last bit is the address range (e.g. /32). If the new command does the right thing, then it's the blocker not loading from your database at startup.

  4. Peter Rosa

    Ok, understand. Just tried the new comman:

    # echo "block 4 32" | /usr/local/libexec/sshg-fw-ipfw
    added: 0
    # ipfw table 22 list
    --- table(22), set(0) --- 0 0 0
    ** 0** 0 0 0 0

    IP is in the table 22. Now - how to solve this? Saying "it's the blocker not loading from your database at startup." is only the part of the solution. Am I really the only one to whom blacklist is not working? I would like to use blacklist for sure. Guys are trying from same IPs, so lock them down forever...

  5. Kevin Zheng

    Right, so we need more information to debug. Can you start SSHGuard in verbose mode and try to get the messages from sshg-blocker and see what's going on?

  6. Peter Rosa

    OK, I started:

    # env SSHGUARD_DEBUG=foo /usr/local/sbin/sshguard
    sshguard[49561]: whitelist: add IPv4 block: with mask 24.
    sshguard[49561]: blacklist: blocking 544 addresses
    sshguard[49561]: whitelist: add '' as plain IPv4.
    sshguard[49561]: whitelist: add plain IPv4
    sshguard[49561]: Now monitoring attacks.

    it wrote full blacklist onscreen. Then, after Ctrl+C, table 22 was clean again.

    So I restarted sshguard (/usr/local/etc/rc.d/sshguard restart). It wrote: sshguard is not running, check /var/run/ then wrote whole blacklist onscreen and table 22 is now filled.

    Seems like it was not running - but I double checked it via ps ax | grep sshg. There was working sshg, adding temporary blocks and cleaning them away. Only the blacklist is not there.

    I just restarted the machine... Whole blacklist is loaded in the table 22, sshg operates normally. I ran:

    # ps ax | grep sshg
     656  -  Is    0:00.00 /bin/sh /usr/local/sbin/sshguard -b 120:/var/db/sshguard/blacklist.db -i /var/run/
     660  -  IC    0:00.00 /usr/local/libexec/sshg-parser
     661  -  IC    0:00.00 /usr/local/libexec/sshg-blocker -a 10 -b 120:/var/db/sshguard/blacklist.db -i /var/run/ -p 120 -
     662  -  I     0:00.00 /bin/sh /usr/local/sbin/sshguard -b 120:/var/db/sshguard/blacklist.db -i /var/run/
     663  -  I     0:00.03 /bin/sh /usr/local/libexec/sshg-fw-ipfw
    # cat /var/run/

    Seems like started twice (656 and 662), but it can be OK, I do not know.

    On monday I will re-check the table and write here the result. Right now it seems like the problem was solved by restart.

  7. Peter Rosa

    Good afternoon,

    it seems table 22 still has its 545 records and number of attacks significantly decreased. So sshguard seems to work properly. But I still do think there is some small error - see my previous post, "So I restarted...". SSHguard was running, but had no PID-file and no blacklist loaded.

    Right now, consider this thread as closed (solved). If I will be able repeat previous error and find out conditions, when it breaks, I will create another one with exact/accurate description.

    Thank you for helping me. Have a nice day.

  8. Kevin Zheng

    The PID file-writer is managed by the sshg-blocker process. I'm not sure what went wrong there, but sometimes the PID file does seem to get out of sync with what sshg-blocker is doing.

    As for the duplicate 'sshguard -b ...', they're actually just subshells spawned by the driver sshguard script (notice the /bin/sh) in the beginning. Right now the driver needs to spawn a subshell to correctly check for a child exit; it doesn't mean that two SSHGuard processes are running.

  9. Log in to comment