-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathdecrypt_doublepulsar_traffic.py
43 lines (31 loc) · 1.84 KB
/
decrypt_doublepulsar_traffic.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
34
35
36
37
38
39
40
41
42
43
import argparse
from itertools import cycle, izip
from pcapng import FileScanner
from pcapng.blocks import EnhancedPacket
# Arguments
parser = argparse.ArgumentParser(description="Decrypt DOUBLEPULSAR network traffic from PCAP file. Supply a PCAPNG format file with just one command run for best results. Tested with DLL injection command.\n\nAuthor: Luke Jennings\nWebsite: https://countercept.com\nTwitter: @countercept", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--pcapng', help='File name of PCAPNG format packet capture to process', required=True)
parser.add_argument('--output', help="File name to write decrypted output too", required=True)
args = parser.parse_args()
pcap_filename = args.pcapng
write_filename = args.output
def xor_decrypt(message, key):
return ''.join(chr(ord(c) ^ ord(k)) for c, k in izip(message, cycle(key)))
xor_key = None
with open(pcap_filename, 'rb') as read_fp, open(write_filename, 'wb') as write_fp:
scanner = FileScanner(read_fp)
for block in scanner:
if isinstance(block, EnhancedPacket):
# Check for SMB packet signature and reserved word plus SESSION_SETUP bytes
if "\xffSMB" in block.packet_data and "\x00\x0e\x00" in block.packet_data:
offset = block.packet_data.index("\x00\x0e\x00") + 6
header = block.packet_data[offset:offset+12]
data = block.packet_data[offset+12:]
# Filter out blank ping packets
if header != "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00":
# Set XOR key based on NULL bytes revealing key in first header packet
if xor_key is None:
xor_key = header[8:12]
decrypted_data = xor_decrypt(data, xor_key)
write_fp.write(decrypted_data)
write_fp.close()