Skip to content

Instantly share code, notes, and snippets.

@hotpxl
Last active August 29, 2015 14:07
Show Gist options
  • Save hotpxl/412bbcd4cba8e9dd902d to your computer and use it in GitHub Desktop.
Save hotpxl/412bbcd4cba8e9dd902d to your computer and use it in GitHub Desktop.
from scapy.all import *
from random import randint
payload = 'GET /proxy.org HTTP/1.1\r\nUser-Agent: curl/7.35.0\r\nHost: mit.edu\r\n\r\n'
ip = '23.66.32.128'
sport = randint(30000, 50000)
if __name__ == '__main__':
print 'Using port ', sport
syn = IP(dst=ip) / TCP(sport=sport, dport=80, flags='S')
syn_ack = sr1(syn)
ack = send(IP(dst=ip) / TCP(sport=sport, dport=80, flags='A', seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1))
rst = IP(dst=ip, ttl=40) / TCP(sport=sport, dport=80, flags='R', seq=2333, ack=21)
send(rst)
reply = sr(IP(dst=ip) / TCP(sport=sport, dport=80, flags='PA', seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1) / payload)
pkts = sniff(filter="tcp and host 59.66.135.76 and port {}".format(sport), count=5, prn=lambda x : x.sprintf('{IP:%IP.src% -> %IP.dst%\n}{Raw:%Raw.load%\n}'))
content = pkts[-1]
send(IP(dst=ip) / TCP(sport=sport, dport=80, flags='A', seq=content[TCP].ack, ack=content[TCP].seq + len(content) - 54))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment