• Login
  • Stats
  • Tools
  • Whois
  • Email Whois
  • Fingerprint
  • Logout
  • Contact
  • Lost Password
WebTracker.one
 
Login
Site Stats
Tools
Whois
Email Whois
Fingerprint
Logout
Contact
Lost Password
Please enable JavaScript to view this site.

Fail2Ban - Block SQL Injection Attacks

Apache mod_cache provides a nice activity log as described in the following post: Website Acceleration - Apache Caching. I am using the records in this log to identify attacks.

In order to create a new Fail2ban jail that will house the IP inmates identified in the mod_cache activity log, enter the following command:

sudo nano /etc/fail2ban/filter.d/hacker2.conf
Note: I already have a hacker.conf file for blocking IP addresses that generate certain Apache errors: Protect Your Website with Fail2Ban. Therefore, I named this fail, hacker2.
The following is the contents of the new hacker2.conf file: # Fail2Ban simple filter to block SQL injection attacks [Definition] resources = %%28|%%29|%%3C|%%3E|%%5B|%%5D|%%5E|%%7B|%%7D|%%2e%%2e|**|///|%%C3|[|]|<|>|- 301 failregex = ^<HOST>.* /.*(%(resources)s).*$ ignoreregex = do_not_check_this_page.php datepattern = {^LN-BEG}
Note: If you want to add a word such as drop to resources above to identify attacker attempts to drop SQL databases, and you want that word to be case insensitive, add it like so:
|(?i:drop)|
Then go to /etc/fail2ban/jail.local and enter the following hacker2 jail - (The jail is set up to ban their IP address one day after one attempt): [hacker2] enabled = true port = http,https filter = hacker2 logpath = /var/log/apache2/cache.log maxretry = 1 bantime = 1 day

Reload fail2ban:

sudo fail2ban-client reload

You can check the status of the hacker2 jail by running this command:

sudo fail2ban-client status hacker2

You can obtain additional information on the queries that triggered a hit by running this second command:

sudo fail2ban-regex '/var/log/apache2/cache.log' /etc/fail2ban/filter.d/hacker2.conf --print-all-matched

I found the following match from IP address 185.164.121.186:

/entries.php?thread_id=%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))

Per URL Decoder, this translates to:

/entries.php?thread_id='nvOpzp; AND 1=1 OR (<''>iKO))

An entry at Stackoverflow explains the purpose of the attack.

As a final note, you can pull up a list of all jailed IP addresses by running the following command:

sudo iptables -L --line-numbers

     * posted by Robert on Fri, Sep 02, 2022



Fail2Ban - Block SQL Injection Attacks

Reply 1:

Fail2ban currently does not work in Ubuntu 24.04. The new version of Ubuntu upgrades to Python 3.12, which is missing the asynchat module. Fail2ban cannot function without this module.

There are two fixes available. The first is easier:

Fix 1: Install the following:

wget https://launchpad.net/ubuntu/+source/fail2ban/1.1.0-1/+build/28291332/+files/fail2ban_1.1.0-1_all.deb
sudo dpkg -i fail2ban_1.1.0-1_all.deb

Fix 2: Follow the steps below:

sudo mkdir /usr/lib/python3/dist-packages/fail2ban/compat

sudo wget -O /usr/lib/python3/dist-packages/fail2ban/compat/asynchat.py https://github.com/fail2ban/fail2ban/raw/1024452fe1befeb5a0a014386a81ec183cd45bb5/fail2ban/compat/asynchat.py

sudo wget -O /usr/lib/python3/dist-packages/fail2ban/compat/asyncore.py https://github.com/fail2ban/fail2ban/raw/1024452fe1befeb5a0a014386a81ec183cd45bb5/fail2ban/compat/asyncore.py

sudo wget -O /usr/lib/python3/dist-packages/fail2ban/server/asyncserver.py https://github.com/fail2ban/fail2ban/raw/1024452fe1befeb5a0a014386a81ec183cd45bb5/fail2ban/server/asyncserver.py

sudo apt install python3-setuptools

sudo fail2ban-client start

     * posted by Robert on Fri, May 10, 2024



Fail2Ban - Block SQL Injection Attacks

Reply 2:

Nftables succeeds iptables on Linux systems, and is now the default firewall.

The Art of the Web explains how to bind Fail2ban to nftables.

Here are the basic steps in brief:

Call up the service file to make edits:

sudo systemctl edit --full fail2ban.service

Replace the Unit and Install sections of the page with the following text (but leave the existing Service section as is):

[Unit]
Requires=nftables.service
PartOf=nftables.service

[Install] WantedBy=multi-user.target nftables.service

Enter the following commands:

sudo systemctl enable nftables.service
sudo systemctl enable fail2ban.service
sudo systemctl daemon-reload

If you use IPsets, you will need to translate your ipsets from iptables to nftables.

See Moving_from_ipset_to_nftables for an explanation of the following steps:

sudo ipset save > sets.ipset
sudo ipset-translate restore < sets.ipset
sudo iptables-save

You can then list the nftables as follows:
sudo nft list tables

To view the rules of an individual table such as table ip filter, enter the following command:
sudo nft list table ip filter

     * posted by Robert on Mon, May 13, 2024


Return to Weblog Home



Site built and hosted by RJdesign.one