Skip to content

Instantly share code, notes, and snippets.

@luiseok
Last active September 20, 2023 07:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save luiseok/fb6d43701b17f4d1de5afa4121f21f27 to your computer and use it in GitHub Desktop.
Save luiseok/fb6d43701b17f4d1de5afa4121f21f27 to your computer and use it in GitHub Desktop.
Fail2ban MongoDB filter.d configuration file
#
# File Path : /etc/fail2ban/jail.local
#
# Please modify the port and logpath that you configured.
#
[mongo-auth]
enabled = true
filter = mongo-auth
logpath = /var/log/mongodb/mongod.log
maxretry = 3
port = 27017
banaction = iptables-multiport[name="mongo", port="27017"]
bantime = 86400
findtime = 300
#
# File Path : /etc/fail2ban/filter.d/mongo-auth.conf
#
# Fail2Ban filter for unsuccesfull MongoDB authentication attempts
# Tested on fail2ban-client v0.9.3
#
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf
[Definition]
_daemon = mongodb
failregex = ^.*[aA]uthentication [fF]ail(ed|ure) for \w+ on \w+ from client <HOST>:[0-9].*|$
ignoreregex =
# DEV Notes:
#
# This file is intended to prevent access to MongoDB with an incorrect account.
#
# Example
# 2017-08-15T07:48:03.291+0900 I ACCESS [conn18] SCRAM-SHA-1 authentication failed for admin on admin from client 192.168.0.7:11696 ; UserNotFound: Could not find user admin@admin
# 2017-08-15T07:57:17.752+0900 I ACCESS [conn28] SCRAM-SHA-1 authentication failed for luiseok on admin from client 192.168.0.12:53380 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch
# Author: luiseok (https://github.com/luiseok)
@luiseok
Copy link
Author

luiseok commented Aug 14, 2017

After modifying the jail.local file, do not forget to restart fail2ban.
sudo service fail2ban restart or sudo fail2ban-client reload

@niftylettuce
Copy link

@luiseok pls fix file paths to be prefixed with /etc/

@luiseok
Copy link
Author

luiseok commented Sep 6, 2018

@niftylettuce thanks. now fixed.

@Zeedinstein
Copy link

Does this still work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment