Git Product home page Git Product logo

ban2sql's Introduction

Ban2SQL

Ban2SQL is a Fail2Ban plugin for logging attacks in a MySQL database for easy report building, and mapping. This application makes use of the MaxMind GeoIP database for gathering geo data.

Requirements

There are a couple of requirements prior to running Ban2SQL. First is Fail2Ban, while its not an absolute requirement, it does automate the insertion of bans into the database. Ban2SQL was written in Perl, so there are a few modules you will need to install. File::Copy, Geo::IP::PurePerl, DBI, LWP::Simple, Archive::Extract, IO::Uncompress::Gunzip.

Installation

  1. Create a MySQL database called ban2sql (this step isn't necessary if you are sharing a db)

   $ mysql -u'root' -p
   $ mysql> CREATE DATABASE `ban2sql`;
  1. Create ban2sql MySQL user to access ban2sql database (needs SELECT, INSERT, UPDATE, DELETE)

   $ mysql -u'root' -p
   $ mysql> CREATE USER 'ban2sql_user'@'localhost' IDENTIFIED BY 'ban2sql_password';
   $ mysql> GRANT SELECT, INSERT, UPDATE, DELETE PRIVILEGES ON `ban2sql`.* to 'ban2sql_user'@'localhost';
  1. Create table by piping base.sql into mysql (mysql -u'ban2sql_user' -p'ban2sql_password' ban2sql < sql/base.sql)

   $ mysql -u'ban2sql_user' -p'ban2sql_password' `ban2sql` < sql/base.sql

You can also populate your table with some sample data by piping data.sql into your new table.


   $ mysql -u'ban2sql_user' -p'ban2sql_password' `ban2sql` < sql/data.sql
  1. Edit ban2sql.pl and change home path and sql login details at the top of the file.

  2. Update Geo IP Database (./ban2sql.pl -u)

  3. Tell fail2ban to call ban2sql by appending to actionban in your action script. Usually the default action is 'banaction = iptables-multiport'

Example for

/etc/fail2ban/action.d/iptables-multiport.conf


actionban = iptables -I fail2ban-<name> 1 -s <ip> -j DROP
            /etc/fail2ban/Ban2SQL/ban2sql.pl -i <name> <protocol> <port> <ip>

Usage


 Usage: ./ban2sql.pl <argument>
  -l  : List the last 50 Bans.
  -u  : Download the latest MaxMind GeoIP database.
  -i  : Insert a new record into the database.
  -d  : Remove a record from the database.
  -c  : Clear the database and start fresh.
  -h  : The help menu.

Notes

Incase its not immediately obvious, here is a breakdown of how the database is built. This might be handy incase you would like to tweak the application (add db rows, etc).

MySQL Database Row Chart

Row IDRow NameRow Meaning
1nameService being attacked (ssh, ftp, etc..)
2protocolProtocol this attack is taking place over
3portPort number this service attack is taking place on
4ipIP address of the attacker
5countNumber of attempts this ip has made
6longitudeGeolocational longitude of attacker
7latitudeGeolocational latitude of attacker
8countryCountry this attacker originates from (2 letters)
9geoMore specific regional information about this attacker
10date_last_seenDate/Time of latest ban
11date_first_seenDate/Time of first ban

Contact/Credits

Ban2SQL by Kotori [email protected]
Based off of Fail2SQL by Jordan Tomkinson [email protected]
Project Page: https://github.com/kotori/Ban2SQL

ban2sql's People

Contributors

kotori avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.