Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

Firewall-start script op AC66U wordt niet gestart

Pagina: 1
Acties:

Vraag


  • Tallguy
  • Registratie: Augustus 2000
  • Niet online

Tallguy

There is no place like 127.0.0

Topicstarter
Mijn vraag
Ik heb een ASUS RT-AC66U van Merlin-Asuswrt 380.59 firmware. Onder Administration - System heb ik de JFFS partitie enabled, aangevinkt dat hij die partitie mag formateren en de router gereboot (na een reboot zet hij die format optie weer op disabled, daarom staat die zo in het screenshot)
Afbeeldingslocatie: https://tweakers.net/ext/f/EsqDQXQSBz97hQUF2EgS1PUr/full.png

De Firewall staat (default) al aan:
Afbeeldingslocatie: https://tweakers.net/ext/f/cgA8tkipkAVr8bwxpRjMZulo/full.png

Ik heb via deze site: https://github.com/RMerl/asuswrt-merlin/wiki/Using-ipset het script gebruikt om een block op een aantal landen te laten uitvoeren (althans, dat is de bedoeling) door mijn AC66U

Via WinSCP heb ik contact gemaakt mijn mijn AC66u en op de genoemde locatie in de site een file aangemaakt 'firewall-start' (zonder extentie)
Afbeeldingslocatie: https://tweakers.net/ext/f/0wRXo6924n6dyiBVx4ZE2aVd/full.png
De rechten had ik overgenomen van de site via commando:chmod +x /jffs/scripts/firewall-start. Zelf nog wat extra rechten geprobeerd zoals te zien is.

Ik heb het script alleen maar aangevuld met een aantal extra landen zoals Korea, Rusland, Filipijnen, Oekraïne, Saudi Arabië etc... (regel #40 in het script)

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

# Loading ipset modules
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

# Preparing folder to cache downloaded files
IPSET_LISTS_DIR=/jffs/ipset_lists
[ -d "$IPSET_LISTS_DIR" ] || mkdir -p $IPSET_LISTS_DIR

# Different routers got different iptables syntax
case $(uname -m) in
  armv7l)
    MATCH_SET='--match-set'
    ;;
  mips)
    MATCH_SET='--set'
    ;;
esac

# Block traffic from Tor nodes
if [ "$(ipset --swap TorNodes TorNodes 2>&1 | grep 'Unknown set')" != "" ]
then
    ipset -N TorNodes iphash
    [ -e $IPSET_LISTS_DIR/tor.lst ] || wget -q -O $IPSET_LISTS_DIR/tor.lst http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv
    for IP in $(cat $IPSET_LISTS_DIR/tor.lst)
    do
        ipset -A TorNodes $IP
    done
fi
[ -z "$(iptables-save | grep TorNodes)" ] && iptables -I INPUT -m set $MATCH_SET TorNodes src -j DROP

# Block incoming traffic from some countries. cn pk sa kr in ru ua ro th and ph is for China Pakistan Saudi Arabia Korea India Russia Ukraine Romania Thailand and Philippines See other countries code at http://www.ipdeny.com/ipblocks/
if [ "$(ipset --swap BlockedCountries BlockedCountries 2>&1 | grep 'Unknown set')" != "" ]
then
    ipset -N BlockedCountries nethash
    for country in pk cn ph sa kr in ru ua ro th 
    do
        [ -e $IPSET_LISTS_DIR/$country.lst ] || wget -q -O $IPSET_LISTS_DIR/$country.lst http://www.ipdeny.com/ipblocks/data/countries/$country.zone
        for IP in $(cat $IPSET_LISTS_DIR/$country.lst)
        do
            ipset -A BlockedCountries $IP
        done
    done
fi
[ -z "$(iptables-save | grep BlockedCountries)" ] && iptables -I INPUT -m set $MATCH_SET BlockedCountries src -j DROP

# Block Microsoft telemetry spying servers
if [ "$(ipset --swap MicrosoftSpyServers MicrosoftSpyServers 2>&1 | grep 'Unknown set')" != "" ]
then
    ipset -N MicrosoftSpyServers iphash
    for IP in 23.99.10.11 63.85.36.35 63.85.36.50 64.4.6.100 64.4.54.22 64.4.54.32 64.4.54.254 \
              65.52.100.7 65.52.100.9 65.52.100.11 65.52.100.91 65.52.100.92 65.52.100.93 65.52.100.94 \
              65.55.29.238 65.55.39.10 65.55.44.108 65.55.163.222 65.55.252.43 65.55.252.63 65.55.252.71 \
              65.55.252.92 65.55.252.93 66.119.144.157 93.184.215.200 104.76.146.123 111.221.29.177 \
              131.107.113.238 131.253.40.37 134.170.52.151 134.170.58.190 134.170.115.60 134.170.115.62 \
              134.170.188.248 157.55.129.21 157.55.133.204 157.56.91.77 168.62.187.13 191.234.72.183 \
              191.234.72.186 191.234.72.188 191.234.72.190 204.79.197.200 207.46.223.94 207.68.166.254
    do
        ipset -A MicrosoftSpyServers $IP
    done
fi
[ -z "$(iptables-save | grep MicrosoftSpyServers)" ] && iptables -I FORWARD -m set $MATCH_SET MicrosoftSpyServers dst -j DROP


Daarna de file opgeslagen, nogmaals de rechten erop gezet voor de zekerheid en de router laten rebooten.

In de SYSLOG zie ik echter niet dat het script wordt gestart:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Aug  5 14:04:05 rc_service: ntp 430:notify_rc restart_upnp
Aug  5 14:04:05 rc_service: ntp 430:notify_rc restart_diskmon
Aug  5 14:04:05 disk_monitor: Finish
Aug  5 14:04:05 disk monitor: be idle
Aug  5 14:04:21 dnsmasq-dhcp[248]: DHCPREQUEST(br0) 192.168.0.198 a4:d1:xx:xx:xx:xx 
Aug  5 14:04:21 dnsmasq-dhcp[248]: DHCPACK(br0) 192.168.0.198 a4:d1:d2:xx:xx:xx Workings-iPad
Aug  5 14:04:29 hour monitor: daemon is starting
Aug  5 14:04:40 crond[251]: time disparity of 533524 minutes detected
Aug  5 14:11:55 dropbear[464]: Child connection from 192.168.0.199:57523
Aug  5 14:12:06 dropbear[464]: Password auth succeeded for 'admin' from 192.168.0.199:57523
Aug  5 14:14:29 dropbear[464]: Exit (admin): Exited normally
Aug  5 14:14:39 dropbear[482]: Child connection from 192.168.0.199:57684
Aug  5 14:14:45 dropbear[482]: Password auth succeeded for 'admin' from 192.168.0.199:57684
Aug  5 14:16:36 dropbear[482]: Exit (admin): Exited normally


Ik ben geen *ux kenner en weet even niet waarom het script niet wil starten. Hoort er soms wèl een extentie achter te staan?
Handmatig het script starten door met PuTTY naar de locatie te gaan waar die file staat en de filenaam in te typen, geeft als resultaat 'not found' :?

Wat zie ik over het hoofd?

specs | 3360wP met SE3000

Alle reacties


  • daxy
  • Registratie: Februari 2004
  • Laatst online: 10:39
De rechten staan goed, mijne staan ook zo.
Als je inlogt met Putty, kan je dan wel dit commando uitvoeren: /jffs/scripts/firewall-start

Dit is de juiste manier om een script te starten op Linux. Een extentie is niet nodig, dit staat goed (1e regel roept het betreffende script op, /bin/sh in dit geval).

Welke rechten hebben de directories /jffs en /jffs/scripts bij jou?

Kan je ook eens dit commando uitvoeren in Putty: grep firewall-start /tmp/syslog.log*
Hiermee weet je zeker of hij wel of niet uitgevoerd is :)

[ Voor 16% gewijzigd door daxy op 05-08-2016 16:16 . Reden: grep info toegevoegd, laatste alinea ]

Do not argue with a fool. He will drag you down to his level and beat you with experience.


  • Tallguy
  • Registratie: Augustus 2000
  • Niet online

Tallguy

There is no place like 127.0.0

Topicstarter
@daxy

Met het grep commando krijg ik dit terug:
admin@RT-AC66U:/tmp/home/root# grep firewall-start /tmp/syslog.log*
Aug 1 02:00:23 custom script: Running /jffs/scripts/firewall-start (args: eth0)

Het uitvoeren van het script met je commando geeft iig geen error terug, maar ook geen prompt.

De rechten:
JFFS: rwxr-xr-x
Scripts rwxr-xr-x

Vreemd: ik dacht "zoals het vaak gaat in de IT heeft een reboot soms onverwacht toch zin (ook al zou eht nergens op slaan, maar ja...)". Dus...reboot gegeven en kijk nou eens:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Aug  5 17:36:18 rc_service: ntp 799:notify_rc restart_upnp
Aug  5 17:36:18 rc_service: ntp 799:notify_rc restart_diskmon
Aug  5 17:36:18 disk_monitor: Finish
Aug  5 17:36:18 disk monitor: be idle
Aug  5 17:36:19 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 1024 to 1536
Aug  5 17:36:20 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 1536 to 2304
Aug  5 17:36:21 dnsmasq-dhcp[248]: DHCPREQUEST(br0) 192.168.0.130 78:xx:xx:xx:xx:xx 
Aug  5 17:36:21 dnsmasq-dhcp[248]: DHCPACK(br0) 192.168.0.130 78:xx:xx:xx:xx:xx Iphone-2
Aug  5 17:36:22 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 2304 to 3456
Aug  5 17:36:27 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 3456 to 5184
Aug  5 17:36:31 dnsmasq-dhcp[248]: DHCPREQUEST(br0) 192.168.0.198 a4:d1:xx:xx:xx:xx 
Aug  5 17:36:31 dnsmasq-dhcp[248]: DHCPACK(br0) 192.168.0.198 a4:d1:xx:xx:xx:xx Workings-iPad
Aug  5 17:36:32 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 5184 to 7776
Aug  5 17:36:37 dropbear[4110]: Child connection from 192.168.0.199:62062
Aug  5 17:36:38 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 7776 to 11664
Aug  5 17:36:41 hour monitor: daemon is starting
Aug  5 17:36:42 dropbear[4110]: Password auth succeeded for 'admin' from 192.168.0.199:62062
Aug  5 17:36:48 kernel: net/ipv4/netfilter/ip_set_iphash.c: iphash_retry: rehashing of set TorNodes triggered: hashsize grows from 11664 to 17496
Aug  5 17:36:52 crond[251]: time disparity of 533736 minutes detected
Aug  5 17:36:54 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 1024 to 1536
Aug  5 17:36:56 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 1536 to 2304
Aug  5 17:36:57 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 2304 to 3456
Aug  5 17:36:58 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 2304 to 5184
Aug  5 17:36:58 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 2304 to 7776
Aug  5 17:37:03 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 7776 to 11664
Aug  5 17:37:04 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 11664 to 17496
Aug  5 17:37:08 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 17496 to 26244
Aug  5 17:37:08 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 17496 to 39366
Aug  5 17:37:30 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 39366 to 59049
Aug  5 17:37:32 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 59049 to 88573
Aug  5 17:37:48 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 88573 to 132859
Aug  5 17:37:49 kernel: net/ipv4/netfilter/ip_set_nethash.c: nethash_retry: rehashing of set BlockedCountries triggered: hashsize grows from 132859 to 199288


Snapt u het nog? 8)7

specs | 3360wP met SE3000


  • Tallguy
  • Registratie: Augustus 2000
  • Niet online

Tallguy

There is no place like 127.0.0

Topicstarter
Omdat ik toch graag wat meer mijn netwerk wilde dichtzetten voor malware, zit ik ook te kijken of ik het malware script niet kan samenvoegen met het firewall script.

Ik zat daarom hieraan te denken

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh

# Loading ipset modules
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

# Preparing folder to cache downloaded files
IPSET_LISTS_DIR=/jffs/ipset_lists
[ -d "$IPSET_LISTS_DIR" ] || mkdir -p $IPSET_LISTS_DIR

# Different routers got different iptables syntax
case $(uname -m) in
  armv7l)
    MATCH_SET='--match-set'
    ;;
  mips)
    MATCH_SET='--set'
    ;;
esac

# Block traffic from Tor nodes
if [ "$(ipset --swap TorNodes TorNodes 2>&1 | grep 'Unknown set')" != "" ]
then
    ipset -N TorNodes iphash
    [ -e $IPSET_LISTS_DIR/tor.lst ] || wget -q -O $IPSET_LISTS_DIR/tor.lst http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv
    for IP in $(cat $IPSET_LISTS_DIR/tor.lst)
    do
        ipset -A TorNodes $IP
    done
fi
[ -z "$(iptables-save | grep TorNodes)" ] && iptables -I INPUT -m set $MATCH_SET TorNodes src -j DROP

# Block incoming traffic from some countries. cn and pk is for China and Pakistan. See other countries code at http://www.ipdeny.com/ipblocks/
if [ "$(ipset --swap BlockedCountries BlockedCountries 2>&1 | grep 'Unknown set')" != "" ]
then
    ipset -N BlockedCountries nethash
    for country in pk cn ph sa kr in ru ua ro th tr us br it hu
    do
        [ -e $IPSET_LISTS_DIR/$country.lst ] || wget -q -O $IPSET_LISTS_DIR/$country.lst http://www.ipdeny.com/ipblocks/data/countries/$country.zone
        for IP in $(cat $IPSET_LISTS_DIR/$country.lst)
        do
            ipset -A BlockedCountries $IP
        done
    done
fi
[ -z "$(iptables-save | grep BlockedCountries)" ] && iptables -I INPUT -m set $MATCH_SET BlockedCountries src -j DROP

# Block Microsoft telemetry spying servers
if [ "$(ipset --swap MicrosoftSpyServers MicrosoftSpyServers 2>&1 | grep 'Unknown set')" != "" ]
then
    ipset -N MicrosoftSpyServers iphash
    for IP in 23.99.10.11 63.85.36.35 63.85.36.50 64.4.6.100 64.4.54.22 64.4.54.32 64.4.54.254 \
              65.52.100.7 65.52.100.9 65.52.100.11 65.52.100.91 65.52.100.92 65.52.100.93 65.52.100.94 \
              65.55.29.238 65.55.39.10 65.55.44.108 65.55.163.222 65.55.252.43 65.55.252.63 65.55.252.71 \
              65.55.252.92 65.55.252.93 66.119.144.157 93.184.215.200 104.76.146.123 111.221.29.177 \
              131.107.113.238 131.253.40.37 134.170.52.151 134.170.58.190 134.170.115.60 134.170.115.62 \
              134.170.188.248 157.55.129.21 157.55.133.204 157.56.91.77 168.62.187.13 191.234.72.183 \
              191.234.72.186 191.234.72.188 191.234.72.190 204.79.197.200 207.46.223.94 207.68.166.254
    do
        ipset -A MicrosoftSpyServers $IP
    done
fi
[ -z "$(iptables-save | grep MicrosoftSpyServers)" ] && iptables -I FORWARD -m set $MATCH_SET MicrosoftSpyServers dst -j DROP

# SET CONFIG
path=/jffs/filters
#path for malware filter files
# END CONFIG

# SET VARIBLES
regexp=`echo "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"`
# END VARIBLES

# Loading ipset modules
lsmod | grep "ipt_set" > /dev/null 2>&1 || \
    for module in ip_set ip_set_iptreemap ipt_set; do
        insmod $module
    done

# 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
 }

get_update () {
        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-updates.txt
 }

# Create the malware-filter (primary) if does not exists
if [ "$(ipset --swap malware-filter malware-filter 2>&1 | grep 'Unknown set')" != "" ]; then
    get_list
    ipset -N malware-filter iphash
        for IP in $(cat $path/malware-filter.txt)
    do
        ipset -A malware-filter $IP
    done
    [ -z "$(iptables-save | grep malware-filter)" ] && iptables -I FORWARD -m set $MATCH_SET malware-filter dst -j DROP
fi

# Destroy this transient set just in case
ipset --destroy malware-update > /dev/null 2>&1

# Load the latest rule(s)
(echo -e "-N malware-update iphash\n" && \
    get_update | \
        nice sed 's/^/-A malware-update /' && \
    echo -e "\nCOMMIT\n" \
) | \

nice ipset --restore && \
nice ipset --swap malware-update malware-filter && \
nice ipset --destroy malware-update
exit $?


Ik heb ze simpel gezeggd samen gevoegd (malware script onderaan erbij geplakt) vanaf regel #68 en alleen het #!/bin/sh stukje eraf gehaald omdat die bovenaan het script al bestaat.
Zou dit zo moeten werken? Want ik merk nl wel, na een reboot, dat de landenblock wordt toegepast, maar ik mis de malware entries.

Ik krijg trouwens nu ook deze melding bij de landenblock
"ipset v4.5: IP/port/element is outside of the set or set is full". Ik heb wel iets van 15 landen in de block staan. Ik heb pas 62 van de 172MB RAM in gebruik.

specs | 3360wP met SE3000