forked from toralf/torutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddos-inbound.sh
executable file
·64 lines (54 loc) · 1.43 KB
/
ddos-inbound.sh
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
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
# set -x
# count inbound to local ORPort per remote ip address
function show() {
local sum=0
local ips=0
while read -r conns ip
do
if [[ $conns -gt $limit ]]; then
printf "%-10s %-40s %5i\n" address$v $ip $conns
(( ++ips ))
(( sum = sum + conns ))
fi
done < <(
ss --no-header --tcp -${v:-4} --numeric |\
grep "^ESTAB .* $(sed -e 's,\[,\\[,g' -e 's,\],\\],g' <<< $relay) " |\
awk '{ print $5 }' | sort | sed 's,:[[:digit:]]*$,,g' | uniq -c
)
if [[ $ips -gt 0 ]]; then
printf "relay:%-40s adresses:%-5i conns:%-5i\n\n" $relay $ips $sum
fi
}
#######################################################################
set -euf
export LANG=C.utf8
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
limit=2
# is the local relay address contained in the ORPort config value ?
relays=$(grep "^ORPort" /etc/tor/torrc{,*} 2>/dev/null | awk '{ print $2 }' | sort)
if [[ ! $relays =~ '.' ]]; then
# no, so get it here
address=$(grep "^Address" /etc/tor/torrc | awk '{ print $2 }' | sort -u)
relays="$address:$relays"
fi
while getopts l:r: opt
do
case $opt in
l) limit=$OPTARG ;;
r) relays=$OPTARG ;;
*) echo "unknown parameter '$opt'"; exit 1 ;;
esac
done
for v in '' 6
do
for relay in $relays
do
if [[ $relay =~ '.' && "$v" = "" ]]; then
show
elif [[ ! $relay =~ '.' && "$v" = "6" ]]; then
show
fi
done
done