
Ich versuche, eine Deep Packet Inspection für HTTP-Pakete durchzuführen. Der Zweck besteht darin, HTTP-Nutzdaten zu sammeln und dann einige Proxy-/Cache-unabhängige Berichte zu erstellen. Anschließend besteht die Idee darin, spezielle Proxy-/Cache-Plugins (z. B. Squid) zu entwickeln, um die Berichte zu verwenden.
Ich verwende das folgende Testszenario (VirtualBox-Maschinen, alle Maschinen sind CentOS 6.3):
ROUTER:
Schnittstellen:
eth0 verbunden mit Netzwerk 192.168.1.0/24 (IP 192.168.1.10)
eth1 verbunden mit Netzwerk 192.168.2.0/24 (IP 192.168.2.20)
eth2 verbunden mit Netzwerk 192.168.3.0/24 (IP 192.168.3.30)
eth3 Internet-Zugang
PC1 (Deep Packet Inspection – DPI PC):
Schnittstellen:
eth0 verbunden mit Netzwerk 192.168.1.0/24 (IP 192.168.1.1)
HTTP-Anfragen von PCs in den Netzwerken 192.168.2.0 und 192.168.3.0 werden mit iptables markiert und dann an den DPI-PC weitergeleitet.
ROUTER iptables-Skript:
#ALL CHAINS POLICY = ACCEPT
# DPI PC IP
IP_DPI=192.168.1.1
# Interface to reach DPI PC from router
IF_DPI_OUT=eth0
# Internet access interface
IF_MASQ=eth3
# Flush everything
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
# Zero counters
iptables -Z
iptables -t nat -Z
iptables -t mangle -Z
# Enable MASQUERADING
iptables -t nat -A POSTROUTING -s 192.16.1.0/24 -o $IF_MASQ -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o $IF_MASQ -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.3.0/24 -o $IF_MASQ -j MASQUERADE
### HTTP packets redirection
# Mark HTTP packets
iptables -t mangle -A PREROUTING -p tcp --dport 80 -m state --state NEW -s 192.168.2.0/24 -i eth1 -j MARK --set-mark 7
iptables -t mangle -A PREROUTING -p tcp --dport 80 -m state --state NEW -s 192.168.3.0/24 -i eth2 -j MARK --set-mark 7
# Create routing table named "http_redirect"
echo 202 http_redirect >> /etc/iproute2/rt_tables
# Marked packets use "http_redirect" table
ip rule add fwmark 7 table http_redirect
# Sent packets to DPI PC
ip route add default via $IP_DPI dev $IF_DPI_OUT table http_redirect
# Flush route cache
ip route flush cache
In DPI PC mache ich dasselbe, Pakete werden wieder zum Router umgeleitet:
DPI PC iptables-Skript:
#ALL CHAINS POLICY = ACCEPT
IP_ROUTER=192.168.1.10
IF_ROUTER_OUT=eth0
# Flush everything
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
# Zero counters
iptables -Z
iptables -t nat -Z
iptables -t mangle -Z
### HTTP packets redirection
# Mark HTTP packets
iptables -t mangle -A PREROUTING -p tcp --dport 80 -i eth0 -j MARK --set-mark 7
# Create routing table named "http_redirect"
echo 202 http_redirect >> /etc/iproute2/rt_tables
# Marked packets use "http_redirect" table
ip rule add fwmark 7 table http_redirect
# Sent packets back to ROUTER
ip route add default via $IP_ROUTER dev $IF_ROUTER_OUT table http_redirect
# Flush route cache
ip route flush cache
Anhand des iptables-Protokolls kann ich erkennen, dass nur das erste Paket (Paket mit aktiviertem SYN) vom ROUTER zum DPI-PC und vom DPI-PC zurück zum ROUTER umgeleitet wird. Sobald das Paket jedoch wieder den ROUTER erreicht, wird es nicht über eth3 (Internetzugang) weitergeleitet. Anschließend wird ein neues Paket mit aktiviertem SYN und ID=vorherige_ID+1 generiert und die Schritte werden erneut wiederholt.
Mit folgendem auf einem lokalen PC (IP 192.168.3.3):
wget www.yahoo.com
Protokoll des DPI-PCs:
Jan 8 19:29:03 localhost kernel: D:IN:eth0:HTTP:d80: IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305)
Jan 8 19:29:03 localhost kernel: D:IN:eth0:MARK-1.0 IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305)
Jan 8 19:29:03 localhost kernel: D:OUT:eth0:HTTP:d80: IN= OUT=eth0
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=62 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305) MARK=0x7
Jan 8 19:29:04 localhost kernel: D:IN:eth0:HTTP:d80: IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305)
Jan 8 19:29:04 localhost kernel: D:IN:eth0:MARK-1.0 IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305)
Jan 8 19:29:04 localhost kernel: D:OUT:eth0:HTTP:d80: IN= OUT=eth0
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=62 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305) MARK=0x7
Jan 8 19:29:06 localhost kernel: D:IN:eth0:HTTP:d80: IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305)
Jan 8 19:29:06 localhost kernel: D:IN:eth0:MARK-1.0 IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305)
Jan 8 19:29:06 localhost kernel: D:OUT:eth0:HTTP:d80: IN= OUT=eth0
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=62 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305) MARK=0x7
Protokoll des ROUTERS:
Jan 8 19:28:48 localhost kernel: R:IN:eth2:HTTP:d80: IN=eth2 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305)
Jan 8 19:28:48 localhost kernel: R:IN:eth2:MARK-3.0 IN=eth2 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305)
Jan 8 19:28:48 localhost kernel: R:OUT:eth0:HTTP:d80: IN= OUT=eth0
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305) MARK=0x7
Jan 8 19:28:48 localhost kernel: R:IN:eth0:HTTP:d80: IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=62 ID=48079 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139AFDB0000000001030305)
Jan 8 19:28:49 localhost kernel: R:IN:eth2:HTTP:d80: IN=eth2 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305)
Jan 8 19:28:49 localhost kernel: R:IN:eth2:MARK-3.0 IN=eth2 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305)
Jan 8 19:28:49 localhost kernel: R:OUT:eth0:HTTP:d80: IN= OUT=eth0
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305) MARK=0x7
Jan 8 19:28:49 localhost kernel: R:IN:eth0:HTTP:d80: IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=62 ID=48080 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139B3C30000000001030305)
Jan 8 19:28:51 localhost kernel: R:IN:eth2:HTTP:d80: IN=eth2 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305)
Jan 8 19:28:51 localhost kernel: R:IN:eth2:MARK-3.0 IN=eth2 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305)
Jan 8 19:28:51 localhost kernel: R:OUT:eth0:HTTP:d80: IN= OUT=eth0
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305) MARK=0x7
Jan 8 19:28:51 localhost kernel: R:IN:eth0:HTTP:d80: IN=eth0 OUT=
SRC=192.168.3.3 DST=200.152.175.146 LEN=60 TOS=0x00 PREC=0x00 TTL=62 ID=48081 DF PROTO=TCP SPT=49268 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0139BB930000000001030305)
Paket mit ID=48079:
1. Kommt vom Host 192.168.3.3 zum eth2 des ROUTER.
2. Wird mit 0x7 markiert
. 3. Wird über eth0 des ROUTER zum DPI-PC weitergeleitet.
4. Kommt zum eth0 des DPI-PC (eingehend).
5. Wird mit 0x7 markiert.
6. Wird über eth0 des DPI-PC zurück zum ROUTER geleitet (ausgehend).
7. Kommt zurück zum eth0 des ROUTER
(Pakete werden nicht über eth3 geleitet und die Schritte werden mit einem neuen Paket mit ID=48080 wiederholt).
Sobald dieses Schema funktioniert, soll zwischen den Schritten 4 bis 6 eine Deep Packet Inspection durchgeführt werden.
Pakete müssen unbedingt vom ROUTER ZUM DPI-PC und vom DPI-PC zurück zum ROUTER geleitet werden, da ich später Squid auf dem DPI-PC verwenden werde.
Ich würde mich über jede Orientierung freuen,
Dank im Voraus
Antwort1
Höchstwahrscheinlich ist der RP-Filter am Routergerät am Werk.
Google: Linux-RP-Filter