3 way handshake in Scapy

后端 未结 2 1569
孤街浪徒
孤街浪徒 2020-12-11 04:30

Im trying to build a 3 way handshake in Scapy. Using the following code,

#!/usr/local/bin/python

from scapy.all import *

sport = random.randint(1024,65535)         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-11 05:03

    I managed to fix this in the end by incrementing the final SEQ number of the ACK.

    from scapy.all import *
    
    sport = random.randint(1024,65535)
    
    # SYN
    ip=IP(src='172.16.120.5',dst='172.16.100.101')
    SYN=TCP(sport=sport,dport=443,flags='S',seq=1000)
    SYNACK=sr1(ip/SYN)
    
    # SYN-ACK
    ACK=TCP(sport=sport, dport=443, flags='A', seq=SYNACK.ack + 1, ack=SYNACK.seq + 1)
    send(ip/ACK)
    

    Heres a tcpdump showing the behaviour...

    20:47:54.226591 IP 172.16.120.5.55348 > 172.16.100.101.443: S 1000:1000(0) win 8192
    20:47:54.227220 IP 172.16.100.101.443 > 172.16.120.5.55348: S 4265040634:4265040634(0) ack 1001 win 18484 
    20:47:54.317452 IP 172.16.120.5.55348 > 172.16.100.101.443: . ack 4265040635 win 8192
    

提交回复
热议问题