Ich hab mir gerade ein kleines Skript geschrieben um SSH Attacken zu visualisieren. Das Skript gibt eine CSV Datei aus mit Infos über: die IPs der Angreifer, die Anzahl der Angriffe, der reverse DNS der IP, und das Land zu dem die IP gehört. Dazu nutze ich die Log /var/log/auth.log
#!/bin/sh TEMP=/tmp/ssh_attacks cat /var/log/auth.log | grep Invalid | cut -d ' ' -f 10 | sort | uniq -c | sort -nr > $TEMP while IFS= read -r line do echo -n $(echo $line | sed "s/ /,/g"); IP=$(echo $line | cut -d ' ' -f 2) echo -n "," echo -n $(host $IP | cut -d ' ' -f 5) echo -n "," echo $(geoiplookup $IP) done < "$TEMP" rm $TEMP
Der Output schaut bei mir z.B. so aus:
513,84.38.66.18,vserver1804.vserver-on.de.,GeoIP Country Edition: DE, Germany
182,121.180.16.51,3(NXDOMAIN),GeoIP Country Edition: KR, Korea, Republic of
134,58.40.18.81,3(NXDOMAIN),GeoIP Country Edition: CN, China
65,113.18.11.76,3(NXDOMAIN),GeoIP Country Edition: CN, China
48,124.127.125.2,mail.navinfo.com.,GeoIP Country Edition: CN, China
23,121.119.160.134,i121-119-160-134.s30.a048.ap.plala.or.jp.,GeoIP Country Edition: JP, Japan
12,112.4.78.68,3(NXDOMAIN),GeoIP Country Edition: CN, China
7,202.102.111.179,3(NXDOMAIN),GeoIP Country Edition: CN, China
2,60.13.129.139,3(NXDOMAIN),GeoIP Country Edition: CN, China
2,203.171.30.41,3(NXDOMAIN),GeoIP Country Edition: VN, Vietnam
1,119.145.36.194,3(NXDOMAIN),GeoIP Country Edition: CN, China
Die erste Spalte ist die Anzahl der Zugriffe, daraufhin kommt die IP, die Reverse DNS Adresse(falls vorhanden) und zuletzt das Land
Unter Ubuntu müssen die Packete dnsutils und geoip-bin instralliert sein. Zudem muss Lesezugriff auf /var/log/auth.log gewährleistet sein. Das macht ihr am einfachsten indem ihr euren User der Gruppe adm hinzufügt. Also kurz “sudo adduser BENUTZERNAME adm” machen, und neu einloggen.
Categories: Allgemein
Tags: Linux, Sicherheit, SSH, Ubuntu
Comments: No Comments.