IT-Sicherheit ############# Datum: 21.05.2021 Sicherheitsinstitutionen ======================== Zuerst müssen wir hier natürlich das `Bundesamt für Sicherheit in der Informationstechnik `_ erwähnen, das einen Grundschutzkatalog anbietet und die wichtigsten Schutzziele definiert: - Vertraulichkeit - Verfügbarkeit - Integrität - Authentizität - Verbindlichkeit Anlaufstellen für Sicherheitsvorkommnisse sind jedoch eher diese Organisationen: - Bugtraq: https://www.securityfocus.com/ = eine moderierte Mailingliste - CERT (Computer Emergency Response Team): https://de.wikipedia.org/wiki/Computer_Emergency_Response_Team * https://www.cert-bund.de/overview * https://www.bsi-fuer-buerger.de/BSIFB/DE/Service/Buerger-CERT/Buerger-CERT_node.html - CIAC (Computer Incident Advisory Capability): https://en.wikipedia.org/wiki/Computer_Incident_Advisory_Capability - Private Webportale: * https://www.heise.de/security/ * https://www.golem.de/specials/security/ * https://www.pro-linux.de/sicherheit/ Manuelle Untersuchung ===================== In Voraussetzung sollte eine Härtung der Systeme durchgeführt worden sein (unnütze Software entfernen, Nutzeraccounts und ssh-Logins mit ~/.ssh/authorized_keys überprüfen, ...), danach stellt sich die Frage, welche Dienste über evl. Routing/Forwarding-Verfahren erreichbar sind. .. highlight:: shell-session :: my@bash $ telnet 10.1.1.3 25 Trying 10.1.1.3... Connected to 10.1.1.3. Escape character is '^]'. 220 deb-int1.haus1.tld ESMTP Postfix (Debian/GNU) helo ichbins 250 deb-int1.haus1.tld mail from: axel@pemmann.de 250 2.1.0 Ok rcpt to: tux@localhost 250 2.1.5 Ok data 354 End data with . Willkommen in 2021... . 250 2.0.0 Ok: queued as E3EA2672D quit 221 2.0.0 Bye Connection closed by foreign host. my@bash $ my@bash $ find /home/*/.maildir/ -cmin -3 /home/tux/.maildir/ /home/tux/.maildir/tmp /home/tux/.maildir/new /home/tux/.maildir/new/1609747366.M849266P545.deb-int1,S=395,W=406 /home/tux/.maildir/dovecot.index.log /home/tux/.maildir/dovecot-uidlist /home/tux/.maildir/dovecot.index.cache my@bash $ my@bash $ cat /home/tux/.maildir/new/1609747366.M849266P545.deb-int1\,S\=395\,W\=406 Return-Path: X-Original-To: tux@localhost Delivered-To: tux@localhost Received: from ichbins (unknown [10.1.1.3]) by deb-int1.haus1.tld (Postfix) with SMTP id E3EA2672D for ; Mon, 4 Jan 2021 09:01:04 +0100 (CET) Message-Id: <20210104080200.E3EA2672D@deb-int1.haus1.tld> Date: Mon, 4 Jan 2021 09:01:04 +0100 (CET) From: axel@pemmann.de Willkommen in 2021... my@bash $ Wieder auf den Host zurückgekehrt, soll von hier aus die Mail-Kommunikation getestet werden: .. highlight:: shell-session :: my@bash $ lxc exec alp-router bash bash-4.4# bash-4.4# ip -4 addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 6: eth0@if7: mtu 1500 qdisc noqueue state UP qlen 1000 inet 192.168.2.103/24 scope global eth0 valid_lft forever preferred_lft forever 8: eth1@if9: mtu 1500 qdisc noqueue state UP qlen 1000 inet 10.1.1.1/24 scope global eth1 valid_lft forever preferred_lft forever bash-4.4# bash-4.4# bash-4.4# iptables -t nat -vnL PREROUTING Chain PREROUTING (policy ACCEPT 609 packets, 36974 bytes) pkts bytes target prot opt in out source destination 0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:993 to:10.1.1.3:993 0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:25 to:10.1.1.3:25 bash-4.4# bash-4.4# bash-4.4# ## >> Jetzt wird klar, wie wir von SuSE aus den Mail-Server ansprechen müssen: via 192.168.2.103 und Port 25. bash-4.4# my@bash $ ## Versuchen wir nun wieder vom SuSE-Host aus, den Mail-Server zu erreichen: my@bash $ telnet 192.168.2.103 25 Trying 192.168.2.103... Connected to 192.168.2.103. Escape character is '^]'. 220 deb-int1.haus1.tld ESMTP Postfix (Debian/GNU) ehlo pemmann.de 250-deb-int1.haus1.tld 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-SMTPUTF8 250 CHUNKING quit 221 2.0.0 Bye Connection closed by foreign host. my@bash $ my@bash $ ## >> Alles OK. Auf dem Alp-Router Updates und das vollständige 'lsof'-Kommando installieren: .. highlight:: shell-session :: my@bash $ apk update fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz v3.9.6-134-g6ba14936d5 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main] v3.9.6-135-g2b576c0b2c [http://dl-cdn.alpinelinux.org/alpine/v3.9/community] OK: 9774 distinct packages available my@bash $ my@bash $ apk upgrade OK: 57 MiB in 80 packages my@bash $ my@bash $ apk -dv search lsof lsof-doc-4.91-r0 - LiSt Open Files (documentation) lsof-4.91-r0 - LiSt Open Files my@bash $ my@bash $ ls -l /usr/bin/lsof lrwxrwxrwx 1 root root 12 Aug 20 10:00 /usr/bin/lsof -> /bin/busybox my@bash $ my@bash $ apk add lsof (1/1) Installing lsof (4.91-r0) Executing busybox-1.29.3-r10.trigger OK: 57 MiB in 81 packages my@bash $ my@bash $ ls -l /usr/bin/lsof -rwxr-xr-x 1 root root 142456 Dec 19 2018 /usr/bin/lsof my@bash $ my@bash $ ## >> Deutlich zu sehen: lsof ist nun ein standalone-Kommando. my@bash $ my@bash $ lsof -i -Pn COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME dhcpd 428 dhcp 8u IPv4 34727 0t0 UDP *:67 sshd 491 root 3u IPv4 36454 0t0 TCP *:22 (LISTEN) sshd 491 root 4u IPv6 36456 0t0 TCP *:22 (LISTEN) my@bash $ my@bash $ ## >> Dieser minimale Router führt lediglich einen DHCP-Client und den SSHD aus. my@bash $ my@bash $ ## Dies zur Sicht von innen heraus (iptables: "lokale Prozesse"). Wir testen nun vom "Internet" aus, was der Router zuzüglich iptables/PREROUTING anbietet: .. highlight:: shell-session :: my@bash $ ## __Auf SusiLeap.haus1.tld (LXD-Host + Master DNS)__ my@bash $ /bin/su - Passwort: my@bash $ my@bash $ nmap -PN -F 192.168.2.103 Starting Nmap 7.70 ( https://nmap.org ) at 2021-01-04 09:24 CET Nmap scan report for 192.168.2.103 Host is up (0.000014s latency). Not shown: 97 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 993/tcp open imaps MAC Address: 00:16:3E:DC:92:41 (Xensource) Nmap done: 1 IP address (1 host up) scanned in 1.56 seconds my@bash $ my@bash $ ## >> Die war ein Default TCP-Scan (-sT) my@bash $ my@bash $ my@bash $ nmap -PN -F -sU 192.168.2.103 Starting Nmap 7.70 ( https://nmap.org ) at 2021-01-04 09:25 CET Stats: 0:00:22 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan UDP Scan Timing: About 42.56% done; ETC: 09:26 (0:00:31 remaining) Stats: 0:00:34 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan UDP Scan Timing: About 52.89% done; ETC: 09:26 (0:00:31 remaining) my@bash $ nmap -PN -F -sU 192.168.2.103 Starting Nmap 7.70 ( https://nmap.org ) at 2021-01-04 09:25 CET Stats: 0:00:22 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan UDP Scan Timing: About 42.56% done; ETC: 09:26 (0:00:31 remaining) Stats: 0:00:34 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan UDP Scan Timing: About 52.89% done; ETC: 09:26 (0:00:31 remaining) Nmap scan report for 192.168.2.103 Host is up (0.00011s latency). Not shown: 99 closed ports PORT STATE SERVICE 67/udp open|filtered dhcps MAC Address: 00:16:3E:DC:92:41 (Xensource) Nmap done: 1 IP address (1 host up) scanned in 103.36 seconds my@bash $ Auf dem internen Debian-Mail-Server einen Port testweise/"versehentlich" öffnen: .. highlight:: shell-session :: my@bash $ apt-get install netcat-openbsd my@bash $ # OK. my@bash $ my@bash $ nc -l -p 80 -v Listening on [0.0.0.0] (family 2, port 80) Nun Testen wir wieder mit dem Portscanner, geben allerdings die Portnummern an: .. highlight:: shell-session :: my@bash $ ## __Auf SusiLeap.haus1.tld (LXD-Host + Master DNS)__ my@bash $ nmap -PN -p22,25,80,135,137-139,143,993 192.168.2.103 Starting Nmap 7.70 ( https://nmap.org ) at 2021-01-04 09:57 CET Nmap scan report for 192.168.2.103 Host is up (0.000064s latency). PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 80/tcp closed http 135/tcp closed msrpc 137/tcp closed netbios-ns 138/tcp closed netbios-dgm 139/tcp closed netbios-ssn 143/tcp closed imap 993/tcp open imaps MAC Address: 00:16:3E:DC:92:41 (Xensource) Nmap done: 1 IP address (1 host up) scanned in 0.55 seconds my@bash $ my@bash $ my@bash $ ## >> Port 80 ist weder auf dem Router selber noch via PREROUTING aktiv. :-) Testweise den Port 80 weiterleiten (PAT): .. highlight:: shell-session :: my@bash $ hostname -f alp-router.haus1.tld my@bash $ my@bash $ iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.3:80 my@bash $ my@bash $ iptables -t nat -vnL PREROUTING Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 2 88 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:993 to:10.1.1.3:993 3 148 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:25 to:10.1.1.3:25 0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:10.1.1.3:80 my@bash $ Wir testen wiederum vom SuSE-Host aus: .. highlight:: shell-session :: my@bash $ nmap -PN -p80 192.168.2.103 Starting Nmap 7.70 ( https://nmap.org ) at 2021-01-04 10:02 CET Nmap scan report for 192.168.2.103 Host is up (0.00013s latency). PORT STATE SERVICE 80/tcp open http MAC Address: 00:16:3E:DC:92:41 (Xensource) Nmap done: 1 IP address (1 host up) scanned in 0.54 seconds my@bash $ Automatische Sicherheitssysteme =============================== Grundbegriffe ------------- Eine sinnvolle Unterteilung: - Intrusion Prevention System (IPS): vorbeugendes Verhindern von Einbrüchen (z.B. fail2ban, artillery) - Host based Intrusion Detection System (HIDS): Überwachung des lokalen Hosts mit seinen Dateien (z.B. aide, tripwire) - Network based Intrusion Detection System (NIDS): Überwachung des lokalen Netzwerks (z.B. snort, suricata, prelude) Spezielle iptables-Regeln ------------------------- - Grundpolicy DROP nutzen: ``iptables -P INPUT DROP`` - SPI-Regeln für den OUTPUT nutzen: ``iptables ... -m conntrack --ctstate ESTABLISHED,RELATED ...`` - Limitierung von eintreffenden Datenpaketen: ``iptables ... -m limit --limit 3/hour --limit-burst 3 ...`` Siehe dazu auch: - https://www.cyberpratibha.com/blog/nmap-port-scanner/nmap-sx/ - https://linoxide.com/firewall/block-common-attacks-iptables/