Skip to content

Instantly share code, notes, and snippets.

@epcnt19 epcnt19/http.py

Last active Mar 28, 2019
Embed
What would you like to do?
#coding:utf-8
import random
from scapy.all import *
HOST = 'www.example.com'
PORT = 80
if __name__=='__main__':
sport = random.randint(50000,60000)
seq = random.randint(0,1000000)
#SYN
ip = IP(dst=HOST)
tcp = TCP(sport=sport,dport=PORT,seq=seq,flags='S')
recv = sr1(ip/tcp)
#ACK
seq = seq+1
ack = recv.seq+1
tcp = TCP(sport=sport,dport=PORT,seq=seq,ack=ack,flags='A')
send(ip/tcp)
#HTTP Request
req = b'GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n'
res = sr(ip/tcp/req,multi=1,timeout=0.1)
##res[0] : scapy.plist.PacketList
for packet in res[0]:
recv = packet[1]
if 'Raw' in recv:
break
#ACK
seq = seq+len(req)
ack = recv.seq+len(recv.load)
tcp = TCP(sport=sport,dport=PORT,seq=seq,ack=ack,flags='A')
recv = sr1(ip/tcp)
#ACK
ack = recv.seq+1
tcp = TCP(sport=sport,dport=PORT,seq=seq,ack=ack,flags='A')
send(ip/tcp)
#FIN
tcp = TCP(sport=sport,dport=PORT,seq=seq,ack=ack,flags='FA')
recv = sr1(ip/tcp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.