使用 hping 将数据包注入 TCP netcat 连接



我在服务器和客户端之间打开了一个netcat连接,我正在尝试使用hping在客户端上打印文本来制作数据包。

我的问题是我能够制作一个与所需数据包非常相似的数据包,但我缺少通过 netcat 从服务器发送到客户端的数据包中的 TCP 选项。

这是我的 HPING 命令

hping3 -A -y  -M 717766814 -L 3830111434 -N 37033 -w 227 -b  -p 55526 -s 5555 -P 192.168.0.116 -c 1 -d 8 -E task4.txt

这是我制作的包

11:16:45.116157 00:a0:98:64:9f:40 > 00:a0:98:36:c8:07, ethertype IPv4 (0x0800), length 62: (tos 0x0, ttl 64, id 37033, offset 0, flags [DF], proto TCP (6), length 48)
192.168.0.216.5555 > 192.168.0.116.55526: Flags [P.], cksum 0x5600 (incorrect -> 0x0355), seq 717766814:717766822, ack 3830111434, win 227, length 8
0x0000:  4500 0030 90a9 4000 4006 2782 c0a8 00d8  E..0..@.@.'.....
0x0010:  c0a8 0074 15b3 d8e6 2ac8 409e e44a dcca  ...t....*.@..J..
0x0020:  5018 00e3 5600 0000 4243 4445 4647 410a  P...V...BCDEFGA.

我需要制作的实际数据包

11:16:52.352624 00:a0:98:64:9f:40 > 00:a0:98:36:c8:07, ethertype IPv4 (0x0800), length 74: (tos 0x0, ttl 64, id 38493, offset 0, flags [DF], proto TCP (6), length 60)
192.168.0.216.5555 > 192.168.0.116.55526: Flags [P.], cksum 0x82cb (incorrect -> 0x0ce8), seq 717766814:717766822, ack 3830111434, win 227, options [nop,nop,TS val 1099353487 ecr 208117467], length 8
0x0000:  4500 003c 965d 4000 4006 21c2 c0a8 00d8  E..<.]@.@.!.....
0x0010:  c0a8 0074 15b3 d8e6 2ac8 409e e44a dcca  ...t....*.@..J..
0x0020:  8018 00e3 82cb 0000 0101 080a 4186 cd8f  ............A...
0x0030:  0c67 9edb 4142 4344 4546 470a            .g..ABCDEFG.

数据包是相同的,只是缺少选项和校验和

如何将选项添加到我构建的数据包中,或者是否有其他方法可以使用 hping 在客户端上显示测试?

如您所见,hping3不提供开箱即用地设置TCP选项的方法。 但是,好消息是TCP选项就在数据包中的TCP有效负载旁边。因此,您可以在数据前面添加 TCP 选项:

  1. 不要只是数据,而是将TCP选项+数据放在您提供给hping3的文件中:

    echo "0101080a4186cd8f0c679edb414243444546470a" | python3 -c "import sys, binascii; sys.stdout.buffer.write(binascii.unhexlify(input().strip()))" > /tmp/task4.txt
    
  2. 使用hping3发送,您需要将数据大小更改为20并将数据偏移量设置为8(默认数据偏移量532 位字(,以正确识别添加的TCP选项:

    -O --tcpoff
    Set fake tcp data offset. Normal data offset is tcphdrlen / 4.
    
    hping3 -A -y  -M 717766814 -L 3830111434 -N 37033 -w 227 -b  -p 55526 -s 5555 -P 192.168.134.161 -c 1 -d 20 -O 8 -E task4.txt
    

生成的构建数据包:

08:27:07.956095 IP (tos 0x0, ttl 64, id 37033, offset 0, flags [DF], proto TCP (6), length 60)
192.168.134.142.5555 > 192.168.134.161.55526: Flags [P.], cksum 0x5451 (incorrect -> 0x0104), seq 0:8, ack 1, win 227, options [nop,nop,TS val 1099353487 ecr 208117467], length 8
0x0000:  4500 003c 90a9 4000 4006 1b92 c0a8 868e  E..<..@.@.......
0x0010:  c0a8 86a1 15b3 d8e6 2ac8 409e e44a dcca  ........*.@..J..
0x0020:  8018 00e3 5451 0000 0101 080a 4186 cd8f  ....TQ......A...
0x0030:  0c67 9edb 4142 4344 4546 470a            .g..ABCDEFG.

最新更新