forked from John-Lin/malware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkt_reconstruct.py
33 lines (28 loc) · 1.2 KB
/
pkt_reconstruct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import argparse
from malware import utils
parser = argparse.ArgumentParser(description='''This is a packet reconstruct
tool to help reconstruct
the packet payload.''')
parser.add_argument("-d", "--directory", type=str,
help="Specify a path which place pcap file")
args = parser.parse_args()
def get_pcap_list(path):
pcap_list = []
dirs = os.listdir(path)
dirs.sort()
for item in dirs:
# if item.split('.')[-1] == 'pcap':
pcap_list.append(item)
return pcap_list
if __name__ == '__main__':
pcap_list = get_pcap_list(args.directory)
for pcap in pcap_list:
save_path = './{log}/{path}/'.format(log=args.directory,
path=pcap)
pcap_path = './{log}/{path}/{path2}.pcap'.format(log=args.directory,
path=pcap, path2=pcap)
connection = utils.follow_tcp_stream(pcap_path)
utils.dump_tcp_stream_content(connection, save_path, True)
udp_connection = utils.follow_udp_stream(pcap_path)
utils.dump_udp_stream_content(udp_connection, save_path, True)