我尝试在Python中使用原始套接字并使用Scapy实现3-way-hadnshake。
代码是:
s=socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.IPPROTO_TCP)
ss=StreamSocket(s)
iph=IPheader()
syn = TCP(sport=TCP_SOURCE_PORT,dport=TCP_DESTINATION_PORT, flags="S")
synack = ss.sr1(iph/syn)
myack = iph/TCP(dport=synack[TCP].sport, sport=synack[TCP].dport, seq=synack[TCP].ack, ack=synack[TCP].seq+1, flags="A")
ss.send(myack)
IPheader()方法返回一个scapy IP头。
运行脚本时出现此错误:
ERROR: --- Error in child 3057
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 89, in sndrcv
pks.send(p)
File "/usr/lib/python2.7/dist-packages/scapy/supersocket.py", line 34, in send
return self.outs.send(sx)
error: [Errno 6] No such device or address
答案 0 :(得分:2)
我发现您的代码可能存在一些问题:
答案 1 :(得分:0)
设备没有响应您的SYN数据包,因为RAW套接字不这样做。您必须手动发送SYN-ACK。此外,Wireshark和TCP将序列号显示为RELATIVE。要显示ACTUAL号码,您必须关闭此选项。第三,您可以手动设置序列号或使用
随机化它TCP(sport = port1, dport = port2, flags="A", seq = random.getrandbits(32), ack = MY_ACK)
或
TCP(sport = port1, dport = port2, flags="A", seq = 01395, ack = MY_ACK)