Einbruchserkennung ================== Zur Motivation: https://www.heise.de/newsticker/meldung/10-Jahre-Sony-Rootkit-Schadsoftware-vom-Hersteller-2865426.html Wir unterscheiden: # a) Host based Intrusion Detection: aide, tripwire, ``rpm --verify --all > /media/stick/rpm-sums.verify`` # b) Network based Intrusion Detection: snort, suricata, prelude :: root@deb10srv:~# # Zu b) root@deb10srv:~# apt-get install snort Paketlisten werden gelesen... Fertig Abhängigkeitsbaum wird aufgebaut. Statusinformationen werden eingelesen.... Fertig Die folgenden zusätzlichen Pakete werden installiert: libauthen-sasl-perl libdaq2 libdata-dump-perl libdumbnet1 libfile-listing-perl libfont-afm-perl libhtml-form-perl libhtml-format-perl libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-negotiate-perl libio-socket-ssl-perl liblwp-protocol-https-perl libmailtools-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libtry-tiny-perl libwww-perl libwww-robotrules-perl oinkmaster perl-openssl-defaults snort-common snort-common-libraries snort-rules-default Vorgeschlagene Pakete: libdigest-hmac-perl libgssapi-perl libcrypt-ssleay-perl libauthen-ntlm-perl snort-doc Die folgenden NEUEN Pakete werden installiert: libauthen-sasl-perl libdaq2 libdata-dump-perl libdumbnet1 libfile-listing-perl libfont-afm-perl libhtml-form-perl libhtml-format-perl libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-negotiate-perl libio-socket-ssl-perl liblwp-protocol-https-perl libmailtools-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libtry-tiny-perl libwww-perl libwww-robotrules-perl oinkmaster perl-openssl-defaults snort snort-common snort-common-libraries snort-rules-default 0 aktualisiert, 27 neu installiert, 0 zu entfernen und 1 nicht aktualisiert. Es müssen 3.564 kB an Archiven heruntergeladen werden. Nach dieser Operation werden 11,3 MB Plattenplatz zusätzlich benutzt. Möchten Sie fortfahren? [J/n] ┌───────────────────────┤ Konfiguriere snort ├───────────────────────┐ │ Schnittstelle(n) an der/denen Snort auf Verbindungen warten soll: │ │ │ │ br0_______________________________________________________________ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────────────────┘ ┌───────────────────────────────────────────────────┤ Konfiguriere snort ├───────────────────────────────────────────────────┐ │ Bitte benutzen Sie das CIDR-Format, z. B. 192.168.1.0/24 für einen Block von 256 IP-Adressen oder 192.168.1.42/32 für nur │ │ eine. Mehrere IP-Adressen sollten durch Kommas getrennt werden (ohne Leerzeichen). │ │ │ │ Bitte beachten Sie: Wenn für Snort mehrere Schnittstellen eingerichtet sind, wird es diese Festlegung als │ │ HOME_NET-Definition für alle gemeinsam verwenden. │ │ │ │ Adressbereich des lokalen Netzwerks: │ │ │ │ 192.168.0.0/16____________________________________________________________________________________________________________ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Paketkonfiguration ┌───────────────────────────────────────────────────┤ Konfiguriere snort ├───────────────────────────────────────────────────┐ │ │ │ Dieser Wert ist normalerweise »eth0«, aber das kann in einigen Netzwerkumgebungen anders sein; bei einer │ │ Einwahlverbindung könnte »ppp0« besser passen (sehen Sie sich die Ausgabe des Befehls »/sbin/ifconfig« an). │ │ │ │ Normalerweise ist das dieselbe Schnittstelle, auf die die »Standard-Route« zeigt. Sie können die verwendete Schnittstelle │ │ mit dem Befehl »/sbin/route -n« herausfinden (suchen Sie nach »0.0.0.0«). │ │ │ │ Es ist auch üblich, Snort an einer Schnittstelle ohne IP-Adresse im Modus »promiscuous« zu betreiben. In diesem Fall │ │ wählen Sie die Schnittstelle aus, die physisch mit dem Netzwerk verbunden ist, das Sie überwachen wollen und schalten │ │ später den Modus »promiscuous« ein. Stellen Sie sicher, dass der Netzwerkverkehr die Schnittstelle erreicht (entweder ist │ │ sie mit einem Anschluss für »Port-Mirroring/Spanning« eines Switches, mit einem Hub oder Tap verbunden). │ │ │ │ Sie können mehrere Schnittstellennamen durch Leerzeichen getrennt eingeben. Jede Schnittstelle kann eigene Einstellungen │ │ haben. │ │ │ │ │ │ │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ libwww-perl (6.36-2) wird eingerichtet ... oinkmaster (2.0-4) wird eingerichtet ... liblwp-protocol-https-perl (6.07-2) wird eingerichtet ... Trigger für libc-bin (2.28-10) werden verarbeitet ... Trigger für systemd (241-7~deb10u7) werden verarbeitet ... Trigger für man-db (2.8.5-2) werden verarbeitet ... root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# pgrep -alfi snort 23417 /usr/sbin/snort -m 027 -D -d -l /var/log/snort -u snort -g snort -c /etc/snort/snort.conf -S HOME_NET=[192.168.0.0/16] -i br0 root@deb10srv:~# root@deb10srv:~# # >> eine alert-Logdatei wird hierbei noch nicht erzeugt. root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# ## Einfach nur als Paketanalyser laufen lassen: root@deb10srv:~# snort -i br0 WARNING: No preprocessors configured for policy 0. =============================================================================== Run time for packet processing was 4.92191 seconds Snort processed 685 packets. Snort ran for 0 days 0 hours 0 minutes 4 seconds Pkts/sec: 171 =============================================================================== Memory usage summary: Total non-mmapped bytes (arena): 786432 Bytes in mapped regions (hblkhd): 12906496 Total allocated space (uordblks): 689152 Total free space (fordblks): 97280 Topmost releasable block (keepcost): 94224 =============================================================================== Packet I/O Totals: Received: 819 Analyzed: 685 ( 83.639%) Dropped: 0 ( 0.000%) Filtered: 0 ( 0.000%) Outstanding: 134 ( 16.361%) Injected: 0 =============================================================================== Breakdown by protocol (includes rebuilt packets): Eth: 685 (100.000%) VLAN: 0 ( 0.000%) IP4: 683 ( 99.708%) Frag: 0 ( 0.000%) ICMP: 0 ( 0.000%) UDP: 164 ( 23.942%) TCP: 478 ( 69.781%) IP6: 2 ( 0.292%) IP6 Ext: 2 ( 0.292%) IP6 Opts: 0 ( 0.000%) Frag6: 0 ( 0.000%) ICMP6: 2 ( 0.292%) UDP6: 0 ( 0.000%) TCP6: 0 ( 0.000%) Teredo: 0 ( 0.000%) ICMP-IP: 0 ( 0.000%) IP4/IP4: 0 ( 0.000%) IP4/IP6: 0 ( 0.000%) IP6/IP4: 0 ( 0.000%) IP6/IP6: 0 ( 0.000%) GRE: 0 ( 0.000%) GRE Eth: 0 ( 0.000%) GRE VLAN: 0 ( 0.000%) GRE IP4: 0 ( 0.000%) GRE IP6: 0 ( 0.000%) GRE IP6 Ext: 0 ( 0.000%) GRE PPTP: 0 ( 0.000%) GRE ARP: 0 ( 0.000%) GRE IPX: 0 ( 0.000%) GRE Loop: 0 ( 0.000%) MPLS: 0 ( 0.000%) ARP: 0 ( 0.000%) IPX: 0 ( 0.000%) Eth Loop: 0 ( 0.000%) Eth Disc: 0 ( 0.000%) IP4 Disc: 41 ( 5.985%) IP6 Disc: 0 ( 0.000%) TCP Disc: 0 ( 0.000%) UDP Disc: 0 ( 0.000%) ICMP Disc: 0 ( 0.000%) All Discard: 41 ( 5.985%) Other: 0 ( 0.000%) Bad Chk Sum: 33 ( 4.818%) Bad TTL: 0 ( 0.000%) S5 G 1: 0 ( 0.000%) S5 G 2: 0 ( 0.000%) Total: 685 =============================================================================== Snort exiting root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# history 7 2181 # Zu b) 2182 apt-get install snort 2183 pgrep -alfi snort 2184 # >> eine alert-Logdatei wird hierbei noch nicht erzeugt. 2185 ## Einfach nur als Paketanalyser laufen lassen: 2186 snort -i br0 2187 history 7 root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# # Wir wollen aber die kostenlos verteilten Rules nutzen und zur Anzeige bringen: root@deb10srv:~# ls -l /etc/snort/rules/ | head insgesamt 1600 -rw-r--r-- 1 root root 5520 Jun 30 2015 attack-responses.rules -rw-r--r-- 1 root root 17898 Jun 30 2015 backdoor.rules -rw-r--r-- 1 root root 3862 Jun 30 2015 bad-traffic.rules -rw-r--r-- 1 root root 7994 Jun 30 2015 chat.rules -rw-r--r-- 1 root root 12759 Jun 30 2015 community-bot.rules -rw-r--r-- 1 root root 1223 Jun 30 2015 community-deleted.rules -rw-r--r-- 1 root root 2042 Jun 30 2015 community-dos.rules -rw-r--r-- 1 root root 2176 Jun 30 2015 community-exploit.rules -rw-r--r-- 1 root root 249 Jun 30 2015 community-ftp.rules root@deb10srv:~# root@deb10srv:~# # >> HINWEIS: mit ``oinkmaster`` kann man abonnierte Rules automatisch downloaden. root@deb10srv:~# root@deb10srv:~# whatis oinkmaster oinkmaster (1) - update Snort signatures root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# ## Mit der Option '-A' wird die Art und Weise der Aufzeichnung gesteuert: root@deb10srv:~# man snort | grep -A3 '\-A' snort [-bCdDeEfHIMNOpqQsTUvVwWxXy?] [-A alert-mode ] [-B address-conversion-mask ] [-c rules-file ] [-F bpf-file ] [-g group-name ] [-G id ] [-h home-net ] [-i interface ] [-k checksum-mode ] [-K logging-mode ] [-l log-dir ] [-L bin-log- file ] [-m umask ] [-n packet-count ] [-P snap-length ] [-r tcpdump-file ] [-R name ] [-S variable=value ] [-t ch‐ root_directory ] [-u user-name ] [-Z pathname ] [--logid id ] [--perfmon-file pathname ] [--pid-path pathname ] -- -A alert-mode Alert using the specified alert-mode. Valid alert modes include fast, full, none, and unsock. Fast writes alerts to the default "alert" file in a single-line, syslog style alert message. Full writes the alert to the "alert" file with the full decoded header as well as the alert message. None turns off alerting. Unsock is an root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# vi /etc/default/snort root@deb10srv:~# head -3 /etc/default/snort # Parameters for the daemon # Add any additional parameteres here. PARAMS="-m 027 -D -d -A fast" root@deb10srv:~# root@deb10srv:~# # >> "-A fast" in Zeile 3 hinzugefügt. root@deb10srv:~# root@deb10srv:~# root@deb10srv:~# tail -f /var/log/snort/alert tail: '/var/log/snort/alert' kann nicht zum Lesen geöffnet werden: Datei oder Verzeichnis nicht gefunden tail: Keine Dateien mehr übrig root@deb10srv:~# root@deb10srv:~# systemctl restart snort root@deb10srv:~# root@deb10srv:~# tail -f /var/log/snort/alert root@deb-srv:~# ping -b 192.168.2.255 -c1 WARNING: pinging broadcast address PING 192.168.2.255 (192.168.2.255) 56(84) bytes of data. 64 bytes from 192.168.2.255: icmp_seq=1 ttl=64 time=0.499 ms --- 192.168.2.255 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.499/0.499/0.499/0.000 ms root@deb-srv:~# root@deb-srv:~# 05/20-12:19:47.772171 [**] [1:366:7] ICMP PING *NIX [**] [Classification: Misc activity] [Priority: 3] {ICMP} 192.168.2.233 -> 192.168.2.255 05/20-12:19:47.772171 [**] [1:384:5] ICMP PING [**] [Classification: Misc activity] [Priority: 3] {ICMP} 192.168.2.233 -> 192.168.2.255 05/20-12:19:47.772650 [**] [1:408:5] ICMP Echo Reply [**] [Classification: Misc activity] [Priority: 3] {ICMP} 192.168.2.255 -> 192.168.2.233 root@deb-srv:~# root@deb-srv:~# # => https://www.kaspersky.de/resource-center/definitions/what-is-a-smurf-attack root@deb-srv:~# root@deb10srv:~# root@deb10srv:~# # tail -f /var/log/snort/alert root@deb10srv:~# root@deb10srv:~# ls -l /var/log/snort/alert -rw-r--r-- 1 root adm 2811 Mai 20 12:19 /var/log/snort/alert root@deb10srv:~# root@deb10srv:~# pgrep -alfi snort 24115 /usr/sbin/snort -m 027 -D -d -A fast -l /var/log/snort -u snort -g snort -c /etc/snort/snort.conf -S HOME_NET=[192.168.0.0/16] -i br0 root@deb10srv:~# root@deb10srv:~# root@deb-srv:~# root@deb-srv:~# # apt-get install nmap root@deb-srv:~# root@deb-srv:~# nmap -A -T4 deb10srv Starting Nmap 7.70 ( https://nmap.org ) at 2021-05-20 12:23 CEST Nmap scan report for deb10srv (192.168.2.202) Host is up (0.000091s latency). rDNS record for 192.168.2.202: deb10srv.dom1.test Not shown: 990 closed ports PORT STATE SERVICE VERSION 21/tcp open ftp Pure-FTPd 22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0) | ssh-hostkey: | 2048 d1:ef:76:7f:7a:13:3a:7a:a7:73:b4:39:9a:7a:e4:e7 (RSA) | 256 5d:43:22:70:ac:cd:85:31:57:d6:4f:5e:8e:7c:17:ab (ECDSA) |_ 256 81:b5:56:01:b4:5b:09:97:99:92:8a:91:2f:aa:ee:c7 (ED25519) 53/tcp open domain ISC BIND 9.11.5-P4-5.1+deb10u5 (Debian Linux) | dns-nsid: |_ bind.version: 9.11.5-P4-5.1+deb10u5-Debian 80/tcp open http Apache httpd 2.4.38 | http-ls: Volume / | SIZE TIME FILENAME | 24 2021-04-20 08:48 phpinfo.php | 46 2021-04-15 08:38 start.html |_ |_http-server-header: Apache/2.4.38 (Debian) |_http-title: Index of / 111/tcp open rpcbind 2-4 (RPC #100000) | rpcinfo: | program version port/proto service | 100000 2,3,4 111/tcp rpcbind |_ 100000 2,3,4 111/udp rpcbind 139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: CC-TESTBED) 389/tcp open ldap OpenLDAP 2.2.X - 2.3.X 443/tcp open ssl/ssl Apache httpd (SSL-only mode) | http-ls: Volume / | SIZE TIME FILENAME | 24 2021-04-20 08:48 phpinfo.php | 46 2021-04-15 08:38 start.html |_ |_http-server-header: Apache/2.4.38 (Debian) |_http-title: Index of / | ssl-cert: Subject: commonName=deb10srv.dom1.test/organizationName=COMCAVE/stateOrProvinceName=Sachsen/countryName=DE | Not valid before: 2021-04-15T10:02:55 |_Not valid after: 2031-04-13T10:02:55 |_ssl-date: TLS randomness does not represent time | tls-alpn: | http/1.1 | http/1.1 (gekürzt) | http/1.1 |_ http/1.1 445/tcp open netbios-ssn Samba smbd 4.9.5-Debian (workgroup: CC-TESTBED) 3128/tcp open http-proxy Squid http proxy 4.6 |_http-server-header: squid/4.6 |_http-title: ERROR: The requested URL could not be retrieved MAC Address: 08:00:27:F4:F3:71 (Oracle VirtualBox virtual NIC) No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.70%E=4%D=5/20%OT=21%CT=1%CU=30444%PV=Y%DS=1%DC=D%G=Y%M=080027%T OS:M=60A638DE%P=x86_64-pc-linux-gnu)SEQ(SP=107%GCD=1%ISR=10D%TI=Z%CI=Z%TS=A OS:)SEQ(SP=107%GCD=1%ISR=10D%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M5B4ST11NW7%O2=M5B4 OS:ST11NW7%O3=M5B4NNT11NW7%O4=M5B4ST11NW7%O5=M5B4ST11NW7%O6=M5B4ST11)WIN(W1 OS:=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)ECN(R=Y%DF=Y%T=40%W=FAF0%O OS:=M5B4NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N OS:)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A= OS:S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF OS:=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL= OS:G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S) Network Distance: 1 hop Service Info: Host: DEB10SRV; OS: Linux; CPE: cpe:/o:linux:linux_kernel Host script results: |_clock-skew: mean: -40m00s, deviation: 1h09m16s, median: 0s |_nbstat: NetBIOS name: DEB10SRV, NetBIOS user: , NetBIOS MAC: (unknown) | smb-os-discovery: | OS: Windows 6.1 (Samba 4.9.5-Debian) | Computer name: deb10srv | NetBIOS computer name: DEB10SRV\x00 | Domain name: dom1.test | FQDN: deb10srv.dom1.test |_ System time: 2021-05-20T12:24:07+02:00 | smb-security-mode: | account_used: guest | authentication_level: user | challenge_response: supported |_ message_signing: disabled (dangerous, but default) | smb2-security-mode: | 2.02: |_ Message signing enabled but not required | smb2-time: | date: 2021-05-20 12:24:07 |_ start_date: N/A TRACEROUTE HOP RTT ADDRESS 1 0.09 ms deb10srv.dom1.test (192.168.2.202) OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 51.95 seconds root@deb-srv:~# root@deb10srv:~# root@deb10srv:~# ## Und im Alarmlog haben wir z.B. XMAS drin: root@deb10srv:~# grep -i xmas /var/log/snort/alert 05/20-12:23:54.931536 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:23:55.109769 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:23:55.287855 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:23:55.466150 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:24:00.095806 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:24:03.794730 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:24:03.947034 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:24:06.452421 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 05/20-12:24:06.605407 [**] [1:1228:7] SCAN nmap XMAS [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.2.233:54299 -> 192.168.2.202:1 root@deb10srv:~#