Skip to content

Commit f78e767

Browse files
author
Dominik Muhs
committed
Add method validation
1 parent 53e9fcb commit f78e767

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
- session reassembly
22
- make the matches for things like "Host" more forgiving, at least case insensitive
33
- allow for HTTP traffic not on port 80
4-
- only allow valid "Methods"
54
- better URL validation
65
- Escape single quotes

pcap2curl.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,29 @@
44
from scapy.all import PcapReader, re, Raw, TCP
55

66

7+
VALID_METHODS = [
8+
"GET",
9+
"HEAD",
10+
"POST",
11+
"PUT",
12+
"DELETE",
13+
"CONNECT",
14+
"OPTIONS",
15+
"TRACE",
16+
"PATCH"
17+
] # see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
18+
19+
720
def payload2curl(p):
821
lines = re.compile("[\n\r]+").split(p.decode())
922
start_line = re.search("^([A-Z]+) ([^ ]+) (HTTP\/[0-9\/]+)", lines[0])
1023
method = start_line.group(1)
1124
url = start_line.group(2)
1225
version = start_line.group(3) # Never used
1326

27+
if method not in VALID_METHODS:
28+
return
29+
1430
del lines[0]
1531
headers = []
1632
for line in lines:
@@ -39,7 +55,9 @@ def main():
3955
for p in packets:
4056
if p.haslayer(TCP) and p.haslayer(Raw) and p[TCP].dport == 80:
4157
payload = p[Raw].load
42-
print(payload2curl(payload))
58+
cmd = payload2curl(payload)
59+
if cmd:
60+
print(cmd)
4361

4462

4563
if __name__ == "__main__":

0 commit comments

Comments
 (0)