Skip to content

Commit 94c13a6

Browse files
authored
Create pcap2curl.py
1 parent 8c63cc9 commit 94c13a6

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pcap2curl.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
from scapy.all import *
5+
6+
7+
if len(sys.argv) != 2:
8+
print "I need an input file. Usage ./pcap2curl.py inputfilename"
9+
exit()
10+
11+
infile = sys.argv[1]
12+
13+
packets=rdpcap(infile)
14+
15+
def payload2curl(p):
16+
lines=re.compile("[\n\r]+").split(p)
17+
startline=re.search('^([A-Z]+) ([^ ]+) (HTTP\/[0-9\/]+)',lines[0])
18+
curl='curl ';
19+
method=startline.group(1)
20+
url=startline.group(2)
21+
version=startline.group(3)
22+
23+
del lines[0]
24+
headers=[]
25+
for line in lines:
26+
if ":" in line:
27+
headers.append("-H '"+line+"'")
28+
if "Host:" in line:
29+
hostheader=re.search("^Host: (.*)",line)
30+
hostname=hostheader.group(1)
31+
32+
if hostname not in url:
33+
url='http://'+hostname+'/'+url
34+
curl=curl+' '+"'"+url+"' \\\n"
35+
curl=curl+'-X'+method+" \\\n"
36+
curl=curl+" \\\n".join(headers)
37+
return curl
38+
39+
for p in packets:
40+
payload=''
41+
if p.haslayer(TCP) and p.haslayer(Raw) and p[TCP].dport == 80:
42+
payload=p[Raw].load
43+
print payload2curl(payload)

0 commit comments

Comments
 (0)