简体   繁体   中英

no response for a http packet using scapy

i have used the following code in order to send a HTTP GET request:

syn = IP(dst='www.google.com') / TCP(dport=80, flags='S')
syn_ack = sr1(syn)
getStr = 'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n'
request = IP(dst='www.google.com') / TCP(dport=80, sport=syn_ack[TCP].dport,seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1, flags='A') / getStr
reply = sr1(request)

and i am still waiting to receive a response packet from google

It might have something to do with the fact that you are not following proper TCP protocol. Reading you code it looks like you forgot the ACK in the 3-way handshake (SYN-SYN_ACK-ACK). So your sending it data, but its just going to ignore it because you have not finished setting up the connection. Try doing something like the following.

syn = IP(dst='www.google.com') / TCP(dport=80, flags='S')
syn_ack = sr1(syn)
ack = TCP(sport=syn.sport, dport=80, flags='A', seq=syn_ack.ack, ack=syn_ack.seq + 1)
ack_resp = sr1(ip/ack)

getStr = 'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n'
request = IP(dst='www.google.com') / TCP(sport=syn.sport, dport=80, flags='A', seq=ack_resp.ack, ack=ack_resp.seq $
reply = sr1(request)

I have not tested this so it may or may not work, but it definitely will not work without the last ACK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM