-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddos-create-whitelist
93 lines (79 loc) · 1.94 KB
/
ddos-create-whitelist
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
#!/bin/bash
#copyright matveynator.ru
LANG=C
cmdname=`basename $0`
newtmpdir=`mktemp -d /tmp/${cmdname}.XXXXXX`
spool="$newtmpdir/spool"
ripedb='/var/cache/ripe.db.inetnum'
tcwhitelist='/etc/nginx/testcookie_whitelist.conf';
nginxwhitelist='/etc/nginx/whitelist.conf';
test
function cleanup () {
rm -rf "${newtmpdir}"
}
function usage() {
cat <<EOF
Usage: ${cmdname} xsolla
This program will search RIPE database and produce whitelist for nginx and firewall.
-h : Help - this screen.
-u : Update RIPE database.
-n NAME : Produce whitelist for nginx.
-t NAME : Produce whitelist for testcookie.
-tor : Produce blacklist of TOR addresses for nginx
EOF
}
trap 'cleanup' EXIT
trap 'cleanup' SIGTERM
function WhitelistNginx() {
grep -i "${searchname}" -B 10 ${ripedb} |grep -E 'inetnum:|NetRange:' |awk '{system("ipcalc -r "$2" - "$4)}' | grep "/" |awk '{print"allow "$1";"}' |tee $nginxwhitelist;
cat /dev/null > $spool;
sort -u $nginxwhitelist | uniq > $spool;
cat $spool > $nginxwhitelist;
nginx -t;
}
function WhitelistTestCookie() {
grep -i "${searchname}" -B 10 ${ripedb} |grep -E 'inetnum:|NetRange:' |awk '{system("ipcalc -r "$2" - "$4)}' | grep "/" |awk '{print$1";"}' |tee $tcwhitelist;
cat /dev/null > $spool;
sort -u $tcwhitelist | uniq > $spool;
cat $spool > $tcwhitelist;
nginx -t;
}
function UpdateRIPEdb() {
curl 'https://ftp.ripe.net/ripe/dbase/split/ripe.db.inetnum.gz' > ${newtmpdir}/ripe.db.inetnum.gz;
gunzip ${newtmpdir}/ripe.db.inetnum.gz;
cat ${newtmpdir}/ripe.db.inetnum > /var/cache/ripe.db.inetnum;
}
function BlacklistTOR() {
curl -s 'https://check.torproject.org/exit-addresses' |grep 'ExitAddress' |awk '{print"deny "$2";"}' | sort -u
}
case "$1" in
-h|--help)
usage
exit
;;
-u)
UpdateRIPEdb
;;
-n)
if [[ "$2" != "" ]]
then
searchname=$2
WhitelistNginx;
else
usage
fi
;;
-t)
if [[ "$2" != "" ]]
then
searchname=$2
fi
WhitelistTestCookie;
;;
-tor)
BlacklistTOR;
;;
*)
usage
;;
esac