dadaniel
Goto Top

Frage zu src-nat

Hi,

ich habe von meinem Kontakt bei Mikrotik folgenden Tipp erhalten:

"Please, fix your srcnat so that only traffic that is leaving the public interface is NATed.
This is to eliminate any possibility for some requests from outside to be able to abuse your NAT configuration."

Ich habe nur eine NAT Regel:

action=src-nat chain=srcnat src-address=192.168.0.0/24 to-addresses=213.47.xxx.xxx


Frage ist nun: Von welcher Sicherheitslücke spricht er? Wie könnte jemand diese "Fehlkonfiguration" ausnutzen?


Wenn ich die erwähnte Anpassung mache, hab ich den (unerwünschten) Nebeneffekt, dass bei Zugriffen ausgehend von einem PC im 192er Netz auf PCs in meinem /28er Netz (welches auf anderen Schnittstellen des Routerboards anliegt) als Quell-IP 192.x.x.x aufscheint. Das ist insofern blöd, weil private IP-Ranges auf den WAN-Schnittstellen der dort angeschlossenen Geräte standardmäßig blockiert werden.

Content-Key: 214302

Url: https://administrator.de/contentid/214302

Printed on: April 19, 2024 at 21:04 o'clock

Mitglied: 108012
108012 Aug 14, 2013 at 14:49:20 (UTC)
Goto Top
Hallo,

ich denke man kann Dir wohl besser helfen, wenn Du einmal die Konfiguration hier "postest", ich bin jetzt nicht der RouterOS
Profi, aber die die es sind können dann schon eine dezidierte Aussage dazu machen.
/ export compact

Sollte das richtige Kommando dafür sein denke ich.

Gruß
Dobby
Member: dadaniel
dadaniel Aug 14, 2013 updated at 15:12:09 (UTC)
Goto Top
#aug/14/2013 17:00:00 by DaDaniel fuer RouterOS 6

#Schnittstellen benennen und HW Switch auf Port 2,3,4 fuer Geraete mit oeffentlichen IPs aktivieren
/interface ethernet
set 0 name=ether1-modem
set 1 name=ether2-wan1
set 2 master-port=ether2-wan1 name=ether3-wan2
set 3 master-port=ether2-wan1 name=ether4-wan3
set 4 name=ether5-lan

#IP Adressen des Routerboards definieren, DHCP Client aktivieren um Haupt-IP vom UPC Modem zu bekommen
/ip dhcp-client
add dhcp-options=hostname,clientid disabled=no interface=ether1-modem use-peer-dns=no use-peer-ntp=no
/ip address
add address=213.47.xxx.xx5/28 interface=ether2-wan1 network=213.47.xxx.xx4
add address=213.47.xxx.xx7/28 interface=ether2-wan1 network=213.47.xxx.xx4
add address=192.168.0.1/24 interface=ether5-lan network=192.168.0.0
/ip firewall address-list
add address=213.47.xxx.xx4/28 list=unsernetz
add address=192.168.0.0/24 list=unsernetz

#DNS Server definieren, lokalen DNS Server aktivieren, Hostname des Routerboards definieren
/ip dns static
add address=192.168.0.1 name=routerboard
/ip dns
set allow-remote-requests=yes servers=8.8.8.8,195.34.133.21

#DHCP Server Konfiguration fuer das interne LAN
/ip pool
add name=dhcp-lan ranges=192.168.0.160-192.168.0.180
/ip dhcp-server network
add address=192.168.0.0/24 dns-server=192.168.0.1 gateway=192.168.0.1
/ip dhcp-server
add address-pool=dhcp-lan disabled=no interface=ether5-lan lease-time=10h name=dhcp-lan

#NAT fuer das interne LAN aktivieren, Portforwarding fuer Terminalserver
/ip firewall nat
add action=src-nat chain=srcnat src-address=192.168.0.0/24 to-addresses=213.47.xxx.xx7
add action=dst-nat chain=dstnat dst-address=213.47.xxx.xx7 dst-port=3389 protocol=tcp to-addresses=192.168.0.110 to-ports=3389

#UPnP fuer das interne LAN aktivieren
/ip upnp interfaces
add forced-external-ip=213.47.xxx.xx7 interface=ether2-wan1 type=external
add interface=ether5-lan type=internal
/ip upnp
set allow-disable-external-interface=no enabled=yes

#Firewall
/ip firewall filter
add action=drop chain=forward comment="ungueltige Pakete blockieren" connection-state=invalid
add chain=input comment="ALLE Verbindungen vom LAN zum ROUTER erlauben" in-interface=ether5-lan
add chain=forward comment="10 Ping Anfragen pro Sekunde von EINER Quell-IP zulassen" dst-limit=10,2,src-address protocol=icmp
add chain=input dst-limit=10,2,src-address protocol=icmp
add chain=input comment="bestehende Verbindungen erlauben" connection-state=established
add action=drop chain=forward comment="gesperrte POP3 IPs blockieren" src-address-list=pop3_blacklist
add action=drop chain=forward comment="mehr als 10 Ping Anfragen pro Sekunde von EINER Quell-IP blockieren" protocol=icmp
add action=drop chain=forward comment="gesperrte RDP IPs blockieren" src-address-list=rdp_blacklist
add action=drop chain=forward comment="gesperrte SSH IPs blockieren" src-address-list=ssh_blacklist
add action=drop chain=forward comment="gesperrte FTP IPs blockieren" src-address-list=ftp_blacklist
add action=drop chain=forward comment="gesperrte Port-Scan IPs blockieren" disabled=yes src-address-list=portscan_blacklist
add action=jump chain=forward comment="Quell-IP nach 4 neuen SSH Verbindungen innerhalb einer Minute fuer 1 Woche auf die Blocklist" connection-state=new dst-port=22 jump-target="log and add to SSH addr-list" protocol=tcp src-address-list=ssh_stage3
add action=add-src-to-address-list address-list=ssh_stage3 address-list-timeout=1m chain=forward connection-state=new dst-port=22 protocol=tcp src-address-list=ssh_stage2
add action=add-src-to-address-list address-list=ssh_stage2 address-list-timeout=1m chain=forward connection-state=new dst-port=22 protocol=tcp src-address-list=ssh_stage1
add action=add-src-to-address-list address-list=ssh_stage1 address-list-timeout=1m chain=forward connection-state=new dst-port=22 protocol=tcp src-address-list=!unsernetz
add action=jump chain=forward comment="Quell-IP nach 6 neuen RDP Verbindungen innerhalb einer Minute fuer 1 Woche auf die Blocklist" connection-state=new dst-port=3389 jump-target="log and add to RDP addr-list" protocol=tcp src-address-list=rdp_stage5
add action=add-src-to-address-list address-list=rdp_stage5 address-list-timeout=1m chain=forward connection-state=new dst-port=3389 protocol=tcp src-address-list=rdp_stage4
add action=add-src-to-address-list address-list=rdp_stage4 address-list-timeout=1m chain=forward connection-state=new dst-port=3389 protocol=tcp src-address-list=rdp_stage3
add action=add-src-to-address-list address-list=rdp_stage3 address-list-timeout=1m chain=forward connection-state=new dst-port=3389 protocol=tcp src-address-list=rdp_stage2
add action=add-src-to-address-list address-list=rdp_stage2 address-list-timeout=1m chain=forward connection-state=new dst-port=3389 protocol=tcp src-address-list=rdp_stage1
add action=add-src-to-address-list address-list=rdp_stage1 address-list-timeout=1m chain=forward connection-state=new dst-port=3389 protocol=tcp src-address-list=!unsernetz
add chain=forward comment="4 falsche POP3 Anmeldungen pro Minute erlauben" content="-ERR Authentication failed" dst-address-list=!unsernetz dst-limit=1/1m,4,dst-address/1m protocol=tcp src-port=110
add action=jump chain=forward comment="Quell-IP nach der 5. falschen POP3 Anmeldung fuer 1 Woche auf die Blocklist" content="-ERR Authentication failed" dst-address-list=!unsernetz jump-target="log and add to POP3 addr-list" protocol=tcp src-port=110
add chain=forward comment="4 falsche FTP Anmeldungen pro Minute erlauben" content="530 Login incorrect" dst-address-list=!unsernetz dst-limit=1/1m,4,dst-address/1m protocol=tcp src-port=21
add action=jump chain=forward comment="Quell-IP nach der 5. falschen FTP Anmeldung fuer 1 Woche auf die Blocklist" content="530 Login incorrect" dst-address-list=!unsernetz jump-target="log and add to FTP addr-list" protocol=tcp src-port=21
add action=jump chain=forward comment="Port-Scans erkennen und Quell-IP fuer 1 Woche auf die Blocklist" disabled=yes jump-target="log and add to PORTSCAN addr-list" protocol=tcp psd=30,3s,3,1 src-address-list=!unsernetz
add action=jump chain=input disabled=yes jump-target="log and add to PORTSCAN addr-list" protocol=tcp psd=30,3s,3,1 src-address-list=!unsernetz
add action=log chain="log and add to RDP addr-list"
add action=add-src-to-address-list address-list=rdp_blacklist address-list-timeout=1w chain="log and add to RDP addr-list"
add action=log chain="log and add to POP3 addr-list"
add action=add-dst-to-address-list address-list=pop3_blacklist address-list-timeout=1w chain="log and add to POP3 addr-list"
add action=log chain="log and add to SSH addr-list"
add action=add-src-to-address-list address-list=ssh_blacklist address-list-timeout=1w chain="log and add to SSH addr-list"
add action=log chain="log and add to FTP addr-list"
add action=add-dst-to-address-list address-list=ftp_blacklist address-list-timeout=1w chain="log and add to FTP addr-list"
add action=log chain="log and add to PORTSCAN addr-list" disabled=yes
add action=add-src-to-address-list address-list=portscan_blacklist address-list-timeout=1w chain="log and add to PORTSCAN addr-list" disabled=yes
add chain=input comment="Zusatzverbindungen zu bestehenden erlauben" connection-state=related
add action=drop chain=input comment="Alle anderen Verbindungen ZUM ROUTER blockieren"

/ip settings
set tcp-syncookies=yes

#Routerboardverwaltung ueber die Modemschnittstelle ausschalten
/tool mac-server
set [ find default=yes ] disabled=yes
add disabled=no interface=ether2-wan1
add disabled=no interface=ether3-wan2
add disabled=no interface=ether4-wan3
add disabled=no interface=ether5-lan
/tool mac-server mac-winbox
set [ find default=yes ] disabled=yes
add interface=ether2-wan1
add interface=ether3-wan2
add interface=ether4-wan3
add interface=ether5-lan
/ip neighbor discovery
set ether1-modem discover=no

#Zeitzone setzen und Systemzeit abrufen
/system clock
set time-zone-name=Europe/Vienna
/system ntp client
set enabled=yes mode=unicast primary-ntp=129.6.15.28 secondary-ntp=129.6.15.29

#grafische Statistiken einschalten
/tool graphing interface
add
/tool graphing resource
add

#Logsize anpassen
/system logging action
set 0 memory-lines=2000
Member: dog
dog Aug 14, 2013 updated at 23:17:33 (UTC)
Goto Top
Von welcher Sicherheitslücke spricht er?

Rein theoretisch wäre es möglich, dass vor deinem WAN-Interface jemand IP-Spoofing macht und dann deine öffentliche NAT-IP benutzt.
Dazu muss aber schon eine ganze Reihe verschiedener Faktoren zusammen passen...

Zum Schutz musst du dir aber mal das Packet Flow Diagramm angucken:
http://wiki.mikrotik.com/wiki/Manual:Packet_Flow

Traffic der geroutet wird geht durch die Chains Prerouting, Forward und Postrouting.
Source NAT ist eine Funktion des Post-Routing, kommt also nach den eigentlichen Firewallregeln (Forward).

Somit reicht eine einfache Firewall-Regel ala in-interface=!etherX src-address=192.168.0.0/24 action=drop im Forward-Chain um das zu unterbinden.
Bei ROS 6 kann auch schon das aktivieren von RP_FILTER reichen.
Member: dadaniel
dadaniel Aug 16, 2013 updated at 09:37:02 (UTC)
Goto Top
Vielen Dank! Jetzt versteh ich es face-smile

Ich habe nun

/ip firewall filter
add action=drop chain=forward comment="IP Spoofing verhindern" in-interface=!ether5-lan src-address=192.168.0.0/24
add action=drop chain=forward in-interface=!ether2-wan1 src-address=213.47.xxx.xx4/28
/ip settings
set rp-filter=strict

eingefügt.


Eine Frage hätt ich noch:

Ist ein "add action=drop chain=input connection-state=invalid" überhaupt nötig wenn am Ende der Firewall als letzte Regel eh schon "add action=drop chain=input" steht?