Skip to content

Instantly share code, notes, and snippets.

@richarddun
Last active April 23, 2024 14:22
Show Gist options
  • Save richarddun/1bb11d32cafc394efbcb8f4a8b6cb130 to your computer and use it in GitHub Desktop.
Save richarddun/1bb11d32cafc394efbcb8f4a8b6cb130 to your computer and use it in GitHub Desktop.
scapy script to send http requests
#!/usr/bin/env python
"""
Script to open TCP connection and send 1 HTTP GET request containing
a specific string, and header
Usage:
./http.py <IP_of_target>
There is only one mandatory argument, which is the target IP address.
If other arguments are omitted, will send a preconfigured URL string
10 times
Optional arguments are :
./http.py <IP_of_target> |HTTP GET STRING| |Max requests|
e.g.
./http.py 10.10.10.10 'GET / HTTP/1.1\r\n' 100
"""
from scapy.all import *
import random
import sys
dest = sys.argv[1]
try:
if sys.argv[2]:
getStr = sys.argv[2]
except :
getStr = 'GET / HTTP/1.1\r\nHost:' + dest + '\r\nAccept-Encoding: gzip, deflate\r\n\r\n'
try:
if sys.argv[3]:
max = int(sys.arv[3])
except:
max = 10
counter = 0
while counter < max:
#SEND SYN
syn = IP(dst=dest) / TCP(sport=random.randint(1025,65500), dport=80, flags='S')
#GET SYNACK
syn_ack = sr1(syn)
#Send ACK
out_ack = send(IP(dst=dest) / TCP(dport=80, sport=syn_ack[TCP].dport,seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1, flags='A'))
#Send the HTTP GET
sr1(IP(dst=dest) / TCP(dport=80, sport=syn_ack[TCP].dport,seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1, flags='P''A') / getStr)
counter += 1
@sinawic
Copy link

sinawic commented Apr 23, 2024

Hey, I have problem getting this to work
when I run this it gets stuck in the first request taking for ever

Begin emission:
Finished sending 1 packets.
....*
Received 5 packets, got 1 answers, remaining 0 packets
.
Sent 1 packets.
Begin emission:
Finished sending 1 packets.
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

anything I'm doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment