2020-10-25 13:46:26 +00:00
|
|
|
# Fail2Ban configuration file
|
|
|
|
#
|
|
|
|
# Mikrotik routerOS action to add/remove address-list entries
|
|
|
|
#
|
|
|
|
# Author: Duncan Bellamy <dunk@denkimushi.com>
|
|
|
|
# based on forum.mikrotik.com post by pakjebakmeel
|
2020-12-06 10:53:21 +00:00
|
|
|
#
|
2020-10-25 13:46:26 +00:00
|
|
|
# in the instructions:
|
|
|
|
# (10.0.0.1 is ip of mikrotik router)
|
|
|
|
# (10.0.0.2 is ip of fail2ban machine)
|
|
|
|
#
|
|
|
|
# on fail2ban machine:
|
|
|
|
# sudo mkdir /var/lib/fail2ban/ssh
|
|
|
|
# sudo chmod 700 /var/lib/fail2ban/ssh
|
|
|
|
# sudo ssh-keygen -N "" -f /var/lib/fail2ban/ssh/fail2ban_id_rsa
|
|
|
|
# sudo scp /var/lib/fail2ban/ssh/fail2ban_id_rsa.pub admin@10.0.0.1:/
|
|
|
|
# ssh admin@10.0.0.1
|
|
|
|
#
|
|
|
|
# on mikrotik router:
|
|
|
|
# /user add name=miki-f2b group=write address=10.0.0.2 password=""
|
|
|
|
# /user ssh-keys import public-key-file=fail2ban_id_rsa.pub user=miki-f2b
|
|
|
|
# /quit
|
|
|
|
#
|
|
|
|
# on fail2ban machine:
|
|
|
|
# (check password login fails)
|
|
|
|
# ssh miki-f2b@10.0.0.1
|
|
|
|
# (check private key works)
|
|
|
|
# sudo ssh -i /var/lib/fail2ban/ssh/fail2ban_id_rsa miki-f2b@10.0.0.1
|
|
|
|
#
|
|
|
|
# Then create rules on mikrorik router that use address
|
|
|
|
# list(s) maintained by fail2ban eg in the forward chain
|
|
|
|
# drop from address list, or in the forward chain drop
|
|
|
|
# from address list to server
|
|
|
|
#
|
|
|
|
# example extract from jail.local overriding some defaults
|
2023-03-08 09:29:03 +00:00
|
|
|
# action = mikrotik[keyfile="%(mkeyfile)s", user="%(muser)s", host="%(mhost)s", list="%(mlist)s"]
|
2020-10-25 13:46:26 +00:00
|
|
|
#
|
|
|
|
# ignoreip = 127.0.0.1/8 192.168.0.0/24
|
|
|
|
|
|
|
|
# mkeyfile = /etc/fail2ban/ssh/mykey_id_rsa
|
|
|
|
# muser = myuser
|
|
|
|
# mhost = 192.168.0.1
|
2023-03-08 09:29:03 +00:00
|
|
|
# mlist = BAD LIST
|
2020-10-25 13:46:26 +00:00
|
|
|
|
|
|
|
[Definition]
|
|
|
|
|
|
|
|
actionstart =
|
|
|
|
|
2020-11-25 18:53:43 +00:00
|
|
|
actionstop = %(actionflush)s
|
|
|
|
|
2023-03-08 09:29:03 +00:00
|
|
|
actionflush = %(command)s "/ip firewall address-list remove [find list=\"%(list)s\" comment~\"%(startcomment)s-*\"]"
|
2020-10-25 13:46:26 +00:00
|
|
|
|
|
|
|
actioncheck =
|
|
|
|
|
2023-03-08 09:29:03 +00:00
|
|
|
actionban = %(command)s "/ip firewall address-list add list=\"%(list)s\" address=<ip> comment=%(comment)s"
|
2020-10-25 13:46:26 +00:00
|
|
|
|
2023-03-08 09:29:03 +00:00
|
|
|
actionunban = %(command)s "/ip firewall address-list remove [find list=\"%(list)s\" comment=%(comment)s]"
|
2020-10-25 13:46:26 +00:00
|
|
|
|
2023-03-08 12:16:35 +00:00
|
|
|
command = ssh -l %(user)s -p%(port)s -i %(keyfile)s %(host)s
|
2020-10-25 13:46:26 +00:00
|
|
|
|
2023-03-08 09:29:03 +00:00
|
|
|
# Option: user
|
2020-10-25 13:46:26 +00:00
|
|
|
# Notes.: username to use when connecting to routerOS
|
2023-03-08 12:16:35 +00:00
|
|
|
user =
|
2023-03-08 09:29:03 +00:00
|
|
|
# Option: port
|
2020-10-25 13:46:26 +00:00
|
|
|
# Notes.: port to use when connecting to routerOS
|
2023-03-08 12:16:35 +00:00
|
|
|
port = 22
|
2023-03-08 09:29:03 +00:00
|
|
|
# Option: keyfile
|
2020-10-25 13:46:26 +00:00
|
|
|
# Notes.: ssh private key to use for connecting to routerOS
|
2023-03-08 12:16:35 +00:00
|
|
|
keyfile =
|
2023-03-08 09:29:03 +00:00
|
|
|
# Option: host
|
2020-10-25 13:46:26 +00:00
|
|
|
# Notes.: hostname or ip of router
|
2023-03-08 12:16:35 +00:00
|
|
|
host =
|
2023-03-08 09:29:03 +00:00
|
|
|
# Option: list
|
2020-10-25 13:46:26 +00:00
|
|
|
# Notes.: name of "address-list" to use on router
|
2023-03-08 12:16:35 +00:00
|
|
|
list = Fail2Ban
|
2020-11-25 18:53:43 +00:00
|
|
|
# Option: startcomment
|
|
|
|
# Notes.: used as a prefix to all comments, and used to match for flushing rules
|
2020-12-29 13:17:41 +00:00
|
|
|
startcomment = f2b-<name>
|
2023-03-08 09:29:03 +00:00
|
|
|
# Option: comment
|
2020-10-25 13:46:26 +00:00
|
|
|
# Notes.: comment to use on routerOS (must be unique as used for ip address removal)
|
2023-03-08 12:16:35 +00:00
|
|
|
comment = %(startcomment)s-<ip>
|
2020-10-25 13:46:26 +00:00
|
|
|
|
|
|
|
[Init]
|
|
|
|
name="%(__name__)s"
|