Last active
March 28, 2019 19:55
-
-
Save epcnt19/5217883e91304ab55774600b27cd3139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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