File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 1
1
- session reassembly
2
2
- make the matches for things like "Host" more forgiving, at least case insensitive
3
3
- allow for HTTP traffic not on port 80
4
- - only allow valid "Methods"
5
4
- better URL validation
6
5
- Escape single quotes
Original file line number Diff line number Diff line change 4
4
from scapy .all import PcapReader , re , Raw , TCP
5
5
6
6
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
+
7
20
def payload2curl (p ):
8
21
lines = re .compile ("[\n \r ]+" ).split (p .decode ())
9
22
start_line = re .search ("^([A-Z]+) ([^ ]+) (HTTP\/[0-9\/]+)" , lines [0 ])
10
23
method = start_line .group (1 )
11
24
url = start_line .group (2 )
12
25
version = start_line .group (3 ) # Never used
13
26
27
+ if method not in VALID_METHODS :
28
+ return
29
+
14
30
del lines [0 ]
15
31
headers = []
16
32
for line in lines :
@@ -39,7 +55,9 @@ def main():
39
55
for p in packets :
40
56
if p .haslayer (TCP ) and p .haslayer (Raw ) and p [TCP ].dport == 80 :
41
57
payload = p [Raw ].load
42
- print (payload2curl (payload ))
58
+ cmd = payload2curl (payload )
59
+ if cmd :
60
+ print (cmd )
43
61
44
62
45
63
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments