Handshake schlägt mit RST nach Änderung der Zieladresse von TCP-Paketen in Netfilter-Hooks fehlLinux

Linux verstehen
Anonymous
 Handshake schlägt mit RST nach Änderung der Zieladresse von TCP-Paketen in Netfilter-Hooks fehl

Post by Anonymous »

Ich implementieren ein Ziel-NAT-ähnliches Verhalten, indem ich mich an NF_INET_PRE_ROUTING und NF_INET_LOCAL_OUT anschließe, um die Ziel-IP-Adresse zu ändern und die Prüfsummen neu zu berechnen.

Code: Select all

nf_tracer_handler(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{
if (!skb) return NF_ACCEPT;

struct iphdr *iph = ip_hdr(skb);
if (iph->daddr != LOCAL_HOST) {
iph->daddr = RELAY_HOST;
check_ipv4(skb);
return NF_ACCEPT;
}
// ...
}

Testumgebung:
  • Host 1 (10.10.10.5): Ausführen eines TCP-Servers über nc -l -p 8080.
  • Host 2 (10.10.10.10): Ausführen des Kernelmoduls und Initiieren einer Verbindung über nc -t 10.10.10.6 8080.
Beobachtungen:
  • Paketfluss: Wireshark bestätigt, dass die Zieladresse korrekt auf 10.10.10.5 geändert wurde und das Paket am Ziel ankommt. Sowohl IP- als auch Transportprüfsummen sind gültig.
  • TCP-Handshake: Host 2 sendet ein SYN und Host 1 antwortet mit einem SYN-ACK. Allerdings beendet Host 2 die Verbindung sofort mit einem RST, nachdem er den SYN-ACK erhalten hat.
  • Conntrack-Status: Ich habe Probleme bei der Verbindungsverfolgung erwartet, aber conntrack -L zeigt einen einzelnen Eintrag im CLOSE-Status an:

    Code: Select all

    tcp 6 9 CLOSE src=10.10.10.10 dst=10.10.10.5 sport=37468 dport=8080 src=10.10.10.5 dst=10.10.10.10 ...
Wenn die Verbindung nicht korrekt verfolgt würde, erwarte ich einen zusätzlichen Eintrag für 10.10.10.10, der im Status SYN_SENT hängen bleibt.
Wireshark-Protokollhost 10.10.10.10:

Code: Select all

   1 0.000000000      0.0.0.0 → 255.255.255.255 DHCP 342 DHCP Discover - Transaction ID 0x6c442f0
2 26.367068797   10.10.10.1 → 10.10.10.255 UDP 571 58448 → 21027 Len=529
3 56.376734983   10.10.10.1 → 10.10.10.255 UDP 571 58448 → 21027 Len=529
4 60.941376698  10.10.10.10 → 10.10.10.5   TCP 82 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209803624 TSecr=0 WS=128
5 60.941613346   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392257184 TSecr=4209803624 WS=128
6 60.941680424  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
7 61.949928609  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209804633 TSecr=0 WS=128
8 61.950178934   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392258193 TSecr=4209804633 WS=128
9 61.950245741  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
10 62.973919724  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209805657 TSecr=0 WS=128
11 62.974132086   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392259217 TSecr=4209805657 WS=128
12 62.974201258  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
13 63.997919964  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209806681 TSecr=0 WS=128
14 63.998155591   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392260241 TSecr=4209806681 WS=128
15 63.998221636  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
16 64.264727672      0.0.0.0 → 255.255.255.255 DHCP 342 DHCP Discover - Transaction ID 0x6c442f0
17 65.021922528  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209807705 TSecr=0 WS=128
18 65.022250690   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392261265 TSecr=4209807705 WS=128
19 65.022320573  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
20 66.045929552  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209808729 TSecr=0 WS=128
21 66.046154349   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392262289 TSecr=4209808729 WS=128
22 66.046219432  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
23 66.063722230 Microsoft_01:2b:12 → Microsoft_01:2b:1b ARP 42 Who has 10.10.10.10? Tell 10.10.10.5
24 66.063735135 Microsoft_01:2b:1b → Microsoft_01:2b:12 ARP 42 10.10.10.10 is at 00:15:5d:01:2b:1b
25 66.173881749 Microsoft_01:2b:1b → Microsoft_01:2b:12 ARP 42 Who has 10.10.10.5? Tell 10.10.10.10
26 66.174172247 Microsoft_01:2b:12 → Microsoft_01:2b:1b ARP 42 10.10.10.5 is at 00:15:5d:01:2b:12
27 68.061926226  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209810745 TSecr=0 WS=128
28 68.062171270   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392264305 TSecr=4209810745 WS=128
29 68.062235732  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
30 72.317899140  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209815001 TSecr=0 WS=128
31 72.318118656   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN,  ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392268561 TSecr=4209815001 WS=128
32 72.318190462  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
Host 10.10.10.5:

Code: Select all

    1 0.000000000 Microsoft_01:2b:1b → Microsoft_01:2b:12 ARP 42 Who has 10.10.10.5? Tell 10.10.10.10
2 0.000014919 Microsoft_01:2b:12 → Microsoft_01:2b:1b ARP 42 10.10.10.5 is at 00:15:5d:01:2b:12
3 5.988567085   10.10.10.1 → 10.10.10.255 UDP 571 58448 → 21027 Len=529
4 9.598251551      0.0.0.0 → 255.255.255.255 DHCP 342 DHCP Discover - Transaction ID 0x6c442f0
5 35.965300200   10.10.10.1 → 10.10.10.255 UDP 571 58448 → 21027 Len=529
6 65.975071061   10.10.10.1 → 10.10.10.255 UDP 571 58448 → 21027 Len=529
7 70.539862907  10.10.10.10 → 10.10.10.5   TCP 82 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209803624 TSecr=0 WS=128
8 70.539892082   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392257184 TSecr=4209803624 WS=128
9 70.540101560  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
10 71.548430169  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209804633 TSecr=0 WS=128
11 71.548457170   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392258193 TSecr=4209804633 WS=128
12 71.548653143  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
13 72.572391291  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209805657 TSecr=0 WS=128
14 72.572418313   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392259217 TSecr=4209805657 WS=128
15 72.572622919  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
16 73.596385390  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209806681 TSecr=0 WS=128
17 73.596413684   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392260241 TSecr=4209806681 WS=128
18 73.596637237  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
19 73.863233515      0.0.0.0 → 255.255.255.255 DHCP 342 DHCP Discover - Transaction ID 0x6c442f0
20 74.620402452  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209807705 TSecr=0 WS=128
21 74.620430786   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392261265 TSecr=4209807705 WS=128
22 74.620758068  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
23 75.644405613  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209808729 TSecr=0 WS=128
24 75.644433025   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392262289 TSecr=4209808729 WS=128
25 75.644642912  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
26 75.661996779 Microsoft_01:2b:12 → Microsoft_01:2b:1b ARP 42 Who has 10.10.10.10? Tell 10.10.10.5
27 75.662208298 Microsoft_01:2b:1b → Microsoft_01:2b:12 ARP 42 10.10.10.10 is at 00:15:5d:01:2b:1b
28 75.772430745 Microsoft_01:2b:1b → Microsoft_01:2b:12 ARP 42 Who has 10.10.10.5? Tell 10.10.10.10
29 75.772446946 Microsoft_01:2b:12 → Microsoft_01:2b:1b ARP 42 10.10.10.5 is at 00:15:5d:01:2b:12
30 77.660423402  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209810745 TSecr=0 WS=128
31 77.660459380   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392264305 TSecr=4209810745 WS=128
32 77.660667227  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
33 81.916385722  10.10.10.10 → 10.10.10.5   TCP 82 [TCP Port numbers reused] 50492 → 8080 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=4209815001 TSecr=0 WS=128
34 81.916413625   10.10.10.5 → 10.10.10.10  TCP 74 8080 → 50492 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=392268561 TSecr=4209815001 WS=128
35 81.916637949  10.10.10.10 → 10.10.10.5   TCP 62 50492 → 8080 [RST] Seq=1 Win=0 Len=0
Vollständiger verwendeter Code: https://github.com/yan3ku/osprojekt/blo ... etfilter.c
Build mit make und dann insmod netfilter.ko
Was mir fehlt, um TCP einzurichten Verbindung?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post