How to create HTTP GET request Scapy?

后端 未结 3 694
-上瘾入骨i
-上瘾入骨i 2020-12-11 21:14

I need to create HTTP GET request and save the data response. I tried to use this:

    syn = IP(dst=URL) / TCP(dport=80, flags=\'S\')
    syn_ack = sr1(syn)         


        
3条回答
  •  清歌不尽
    2020-12-11 21:49

    After setting the rule in your iptables as has been suggested above, you could do the following :

    from scapy.all import *
    
    seq = 12345
    sport = 1040
    dport = 80
    
    ip_packet = IP(dst='192.168.56.107')
    syn_packet = TCP(sport=sport, dport=dport, flags='S', seq=seq)
    
    packet = ip_packet/syn_packet
    synack_response = sr1(packet)
    
    next_seq = seq + 1
    my_ack = synack_response.seq + 1
    
    ack_packet = TCP(sport=sport, dport=dport, flags='A', seq=next_seq, ack=my_ack)
    
    send(ip_packet/ack_packet)
    
    payload_packet = TCP(sport=sport, dport=dport, flags='A', seq=next_seq, ack=my_ack)
    payload = "GET / HTTP/1.0\r\nHOST: 192.168.56.107\r\n\r\n"
    
    reply, error = sr(ip_packet/payload_packet/payload, multi=1, timeout=1)
    for r in reply:
        r[0].show2()
        r[1].show2()
    

    Hope this helps. Basically, the first response you get back does not really hold the HTTP response data. I tested the script against an INETSIM simulated HTTP server and in that case (at least) the first packet (after the 3-way TCP handshake) that the server responded with was a series of NULL (0x00) bytes. Hence using multi somehow did the stuff in my case.

提交回复
热议问题