This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
networking:router:mikrotik_manual_blacklist [2014/12/19 09:51] gcooper |
networking:router:mikrotik_manual_blacklist [2025/02/25 16:10] (current) gcooper |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Manually Add and Remove IP Addresses to a Blacklist ====== | + | ====== Manually Add and Remove IP Addresses to a Mikrotik |
+ | |||
+ | FIXME **New**: https:// | ||
:!: This assumes you have a address list named '' | :!: This assumes you have a address list named '' | ||
Line 7: | Line 9: | ||
</ | </ | ||
- | /< | + | < |
- | ip firewall address-list remove [/ip firewall address-list find address=xxx.xxx.xxx.xxx] | + | /ip firewall address-list remove [/ip firewall address-list find address=xxx.xxx.xxx.xxx] |
+ | </ | ||
+ | |||
+ | ===== Create Blacklist from Apache Logs ===== | ||
+ | |||
+ | Filter the log entries for attackers first. | ||
+ | |||
+ | Example from a recent Joomla experience where an attacking botnet utilized a vulnerable ' | ||
+ | |||
+ | :!: You will want to change '' | ||
+ | |||
+ | < | ||
+ | grep contact-me / | ||
+ | </ | ||
+ | |||
+ | :!: Some Apache logs have the IP address as the first field. | ||
+ | |||
+ | Strip it down to IP addresses: | ||
+ | |||
+ | < | ||
+ | awk '{ print $1 } ' example.txt | sort | uniq > evildoers.txt | ||
+ | </ | ||
+ | |||
+ | Or, to just determine how many attackers there were: | ||
+ | |||
+ | < | ||
+ | awk '{ print $1 } ' example.txt | sort | uniq | wc -l | ||
+ | </ | ||
+ | |||
+ | :!: Some newer Apache logs have the IP address deeper in the line. | ||
+ | |||
+ | < | ||
+ | cat bloody1.txt | awk '{ print $11 } ' | awk -F ':' | ||
+ | </ | ||
+ | |||
+ | Create a Mikrotik script to add the evildoers to a ' | ||
+ | |||
+ | < | ||
+ | echo "/ip firewall address-list" | ||
+ | cat evildoers.txt | awk --posix '/ | ||
+ | </ | ||
+ | |||
+ | You can make the address-list entries dynamic by specifying a timeout by adding '' | ||
+ | |||
+ | Upload the '' | ||
+ | |||
+ | < | ||
+ | /import add-to-blacklist.rsc | ||
+ | </ | ||
+ | |||
+ | ====== Script ====== | ||
+ | |||
+ | FIXME Super slow and may not be 100% correct for ROS v7. | ||
+ | |||
+ | :!: You should first run this script at the ROS command line to look for errors. | ||
+ | |||
+ | :!: Make sure UNIX line endings are used in the '' | ||
+ | |||
+ | :!: Make sure the '' | ||
+ | |||
+ | < | ||
+ | /system script add dont-require-permissions=no name=add-ip-addresses-to-blacklist owner=\ | ||
+ | admin policy=\ | ||
+ | ftp, | ||
+ | # Generic IP address list input\r\ | ||
+ | \n## Based on a script written by Sam Norris, ChangeIP.com 2008\r\ | ||
+ | \n## Edited by Andrew Cox, AccessPlus.com.au 2008\r\ | ||
+ | \n##\r\ | ||
+ | \n:put \" | ||
+ | \n:put \"This script requires the address text file to have UNIX line endings.\"; | ||
+ | \n\ | ||
+ | \n:put \" | ||
+ | \n:put \"Hard coded source is file ipaddress.txt file.\"; | ||
+ | \n\ | ||
+ | \n:put \"Hard coded destination is the blacklist address-list.\"; | ||
+ | \n\ | ||
+ | \n:put \" | ||
+ | \n\ | ||
+ | \n:put \"The ipaddress.txt file must be smaller than 4KB.\"; | ||
+ | \n:put \" | ||
+ | \n##:put \" | ||
+ | \n##/ip firewall address-list remove [/ip firewall address-list find list=blacklist]; | ||
+ | \n:global content [/file get [/file find name=ipaddress.txt] contents] ;\r\ | ||
+ | \n:global contentLen [ :len \$content ] ;\r\ | ||
+ | \n:global lineEnd 0;\r\ | ||
+ | \n:global line \" | ||
+ | \n:global lastEnd 0;\r\ | ||
+ | \n:do {\r\ | ||
+ | \n :set lineEnd [:find \$content \" | ||
+ | \n :set line [:pick \$content \$lastEnd \$lineEnd] ;\r\ | ||
+ | \n :set lastEnd ( \$lineEnd + 1 ) ;\r\ | ||
+ | \n #If the line doesn' | ||
+ | \n :if ( [:pick \$line 0 1] != \"# | ||
+ | \n :local entry [:pick \$line 0 \$lineEnd ]\r\ | ||
+ | \n :if ( [:len \$entry ] > 0 ) do={\r\ | ||
+ | \n :put \" | ||
+ | \n /ip firewall address-list remove [find list=\" | ||
+ | \n :put \" | ||
+ | \n /ip firewall address-list add list=blacklist address=\$entry comment=\" | ||
+ | \n | ||
+ | \n }\r\ | ||
+ | \n } while (\$lineEnd < \$contentLen)\r\ | ||
+ | \n}" | ||
</ | </ |