admin@RT-AC68U-F000:/jffs/scripts# sh -x firewall-startSo this is my cleanup feel free to go thru it and suggest improvements and please change on the wiki and not just post to this thread.
also added a link for mirai blocklist on the wiki
Code:#!/bin/sh # Original script by swetoast. Updates by Neurophile & Octopus. # SET CONFIG path=/opt/var/cache/malware-filter #path for malware filter files # END CONFIG # SET VARIBLES regexp=`echo "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"` # END VARIBLES #Load ipset modules ipset -v | grep -i "v4" > /dev/null 2>&1 if [ $? -eq 0 ]; then # old ipset ipsetv=4 lsmod | grep "ipt_set" > /dev/null 2>&1 || \ for module in ip_set ip_set_nethash ip_set_iphash ipt_set do insmod $module done else # new ipset ipsetv=6 lsmod | grep "xt_set" > /dev/null 2>&1 || \ for module in ip_set ip_set_hash_net ip_set_hash_ip xt_set do insmod $module done fi #Different routers got different iptables syntax case $(uname -m) in armv7l) MATCH_SET='--match-set' ;; mips) MATCH_SET='--set' ;; esac # Get lists get_list () { mkdir -p $path wget -q --show-progress -i $path/malware-filter.list -O $path/malware-list.pre cat $path/malware-list.pre | grep -oE "$regexp" | sort -u >$path/malware-filter.txt } run_ipset () { get_list ipset --destroy malware-filter > /dev/null 2>&1 # destroy the old rules to get new ones. # Create ip set if [ "$(ipset --swap malware-filter malware-filter 2>&1 | grep -E 'Unknown set|The set with the given name does not exist')" != "" ]; then ipset -N malware-filter iphash fi # Apply iptables rule iptables-save | grep malware-filter > /dev/null 2>&1 || \ iptables -I FORWARD -m set $MATCH_SET malware-filter src,dst -j DROP } run_ipset exit $?
Something which is interesting happening is
when you ping the malware ip's from outside the router
i.e., from your pc/mac etc., the ping fails.
But when you ping the same malware ip from within your router shell
i.e., after login in with ssh, the ping succeeds.
Hi to All,So its working
#!/bin/sh
# Original script by swetoast. Updates by Neurophile & Octopus.
path=/opt/var/cache/malware-filter # Set your path here
regexp=`echo "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"` # Dont change this value
ipset -v | grep -i "v4" > /dev/null 2>&1
if [ $? -eq 0 ]; then
ipsetv=4
lsmod | grep "ipt_set" > /dev/null 2>&1 || \
for module in ip_set ip_set_nethash ip_set_iphash ipt_set
do
insmod $module
done
else
ipsetv=6
lsmod | grep "xt_set" > /dev/null 2>&1 || \
for module in ip_set ip_set_hash_net ip_set_hash_ip xt_set
do
insmod $module
done
fi
case $(uname -m) in
armv7l)
MATCH_SET='--match-set' # Value for ARM Routers
;;
mips)
MATCH_SET='--set' # Value for Mips Routers
;;
esac
get_list () {
mkdir -p $path
wget -q --show-progress -i $path/malware-filter.list -O $path/malware-list.pre
cat $path/malware-list.pre | grep -oE "$regexp" | sort -u >$path/malware-filter.txt
}
run_ipset () {
get_list
ipset --destroy malware-filter > /dev/null 2>&1 # Delete the filter so it doesnt clash with the update
if [ "$(ipset --swap malware-filter malware-filter 2>&1 | grep -E 'Unknown set|The set with the given name does not exist')" != "" ]; then
ipset -N malware-filter iphash
while [ $((--i)) -ge 0 ]; do
ipset --add temp_ipset $(cat $path/malware-filter.txt)
done
fi
iptables-save | grep malware-filter > /dev/null 2>&1 || \
iptables -I FORWARD -m set $MATCH_SET malware-filter src,dst -j REJECT
}
run_ipset
exit $?
That is because the rule is applied to chain FORWARD. If you want to block traffic originating in the router itself you need to add a rule to chain OUTPUT.
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!