Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Auto-Reporting LFD Block Reports to Abuse IP DB v2

Auto-Reporting LFD Block Reports to Abuse IP DB v2

10

Due to popular demand, I have upgraded my initial LFD reporting script to use the IP Abuse DB v2 APIs. This post covers the new script and how it can be used. Please read my previous post to understand the background of the script.

Prerequisites

  • CSF / LFD plugin installed and configured
  • AbuseIPDB Account
  • AbuseIPDB APIv2 Key

The PHP Script

The PHP script is designed to be called from the command line. It has been updated to use v2 of the Abuse IP DB API.

The above script captures the arguments sent by LFD in the command line, which includes the remote IP, a message that contains the reason for the IP block and relevant log messages (among other information). The full argument list is as follows:

ARG 1 = IP Address # The IP address or CIDR being blocked
ARG 2 = ports # Port, comma separated list or * for all ports
ARG 3 = permanent # 0=temporary block, 1=permanent block
ARG 4 = inout # Direction of block: in, out or inout
ARG 5 = timeout # If a temporary block, TTL in seconds, otherwise 0
ARG 6 = message # Message containing reason for block
ARG 7 = logs # The logs lines that triggered the block (will contain # line feeds between each log line)
ARG 8 = trigger # The configuration settings triggered

The script then check if the IP has already been reported by your account (lines 87-97). If the IP hasn’t been reported, a new report is created on AbuseIPDB (line 102). The above script only checks reports from the last day (line 88, maxAgeInDays=1).

The verbose flag (line 88) is used in the API to return additional information on each report, including the AbuseIPDB User ID who created the report. This is used to make sure you don’t report the same IP more than once in 24 hour period.

I stored the script in /root/lfd-v2.php and added the relevant execution permissions using chmod 755 lfd-v2.php.

Thanks to line 1 in the above code, you can simply run lfd-v2.php in the command line and it will trigger the PHP code (without the need for the php prefix).

Configuring CSF / LFD

Once the script was ready, I updated the CSF configuration to trigger the script:

  1. Edit /etc/csf/csf.conf using your favourite editor
  2. Find the line starting with BLOCK_REPORT
  3. Update the line so it reads: BLOCK_REPORT = "/root/lfd-v2.php"
  4. Restart lfd using service lfd restart or using the web interface

Testing

To test the script, you can either trigger the PHP script manually or wait for a block event to occur. To test manually, you can run the following command line:

/root/lfd-v2.php "REMOTE_IP" "PORTS" "1" "*" "*" "blocked REMOTE_IP for SSH brute force" "sshd"

The above command line mimics what LFD would send to the script when a block has occurred. If successful, the command line will display the output of the script, including the IP that was reported:

If the script reports the confidence score, the IP was correctly reported, and will therefore appear on the website:

Firewall, Hacking, IP Abuse, Security

10 comments on “Auto-Reporting LFD Block Reports to Abuse IP DB v2”

  1. Auto-Reporting LFD Block Reports to Abuse IP DB | Web Niraj says:
    March 12, 2019 at 12:42 PM

    […] UPDATE: This script has been updated to use v2 APIs. Please see the updated version here. […]

    Reply
  2. slav123 says:
    June 7, 2019 at 9:34 AM

    I can’t find /etc/csf/csf.conf file ? got latest directadmin running on CentOs

    Reply
    • Niraj Shah says:
      June 7, 2019 at 9:57 AM

      The csf.conf file comes with the ConfigServer Security & Firewall plugin. It would need to be installed on your server before you can configure it.

      Reply
  3. Reporting cPanel cPHulk IPs to Abuse IP DB | Web Niraj says:
    January 21, 2020 at 9:28 AM

    […] a previous post, I’ve shared a script that allows server administrators to report abusive IPs to the Abuse IP database. But did you know […]

    Reply
  4. Clapper says:
    March 3, 2020 at 3:32 AM

    Good but some improvements mentioned here https://gist.github.com/niraj-shah/5395c080d28b02302ed6ea93bf9107ec#file-lfd-v2-php

    Reply
  5. mikeramsey899 says:
    May 30, 2020 at 12:23 PM

    @Clapper

    Setup a snippet based off this version with your suggestions and some of my mods along with easy to implement usage for setting up on multiple servers.
    https://gitlab.com/snippets/1981817

    Reply
  6. Solace says:
    March 25, 2024 at 12:24 AM

    This is good, thanks @niraj-shah

    How could we implement better privacy and redact the hostname that sometimes gets shown in the abuseipdb reports?

    For example:

    61.72.22.177 (KR/South Korea/-), 10 distributed smtpauth attacks on account [mailer-daemon@theuserdomain.net] in the last 3600 secs;

    Would be good if we can show [redacted] or something?

    61.72.22.177 (KR/South Korea/-), 10 distributed smtpauth attacks on account [redacted] in the last 3600 secs;

    Suggestion – see this
    https://github.com/centminmod/centminmod-abuseipdb-reporter/blob/master/abuseipdb-reporter.py

    Reply
    • Niraj Shah says:
      March 25, 2024 at 12:07 PM

      I’ve actually done something similar in the version that runs on my own severs. I have an array of terms that I want to hide, e.g. (add after line 27):

      $hide = [ 'x.x.x.x', 'y.y.y.y', 'username1', 'username2', 'username3' ];

      Then on line 37, I added the following to find/replace the items I want to using a loop:

      foreach ($hide as $item) {
        $msg = str_replace($item, 'REDACTED', $msg);
        $log = str_replace($item, 'REDACTED', $log);
      }
      Reply
      • Solace says:
        March 27, 2024 at 12:36 AM

        Thanks @niraj
        I think it would be better to simply redact everything contained within the square brackets that LFD produces? How could we do that?

        I will try your great suggestion meanwhile 🙂 Where is your “buymeacoffee” link? eh?
        Cheers mate!

      • Niraj Shah says:
        May 10, 2024 at 12:16 PM

        You could try a regex replace to find anything in the square brackets and replace it with REDACTED. A basic example:

        preg_replace('/(.*)(\[.*\]+)(.*)/', '$1 [REDACTED] $3', $input_lines);

        See live example here: https://www.phpliveregex.com/p/LDN#tab-preg-replace

Leave a Reply to mikeramsey899Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Firewall Flash Gadget Geolocation Google Nexus 5 Hacking HTML5 iOS JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy