Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions decrypt_darkshell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def decrypt_darkshell(cipherbytes, start_idx=0x04, stop_idx=0xA8):
"""
De-obfuscates Darkshell comms encoded using the following method:
cipherbyte = 0xDE - [plainbyte - (plainbyte & 0x10) << 1]
The obfuscation is reversed as follows:
intermediate = 0xDE - cipherbyte
plainbyte = intermediate + (intermediate & 0x10) << 1
"""
len_mesg = len(cipherbytes)
if len_mesg != 260:
raise RuntimeError("Darkshell bot-to-CnC comms are always 260 bytes")
plainbytes = []
for cipherbyte in cipherbytes[start_idx:stop_idx]:
intermediate= 0xDE - ord(cipherbyte)
plainbytes += [chr(intermediate + ((intermediate & 0x10) << 1))]
return cipherbytes[:start_idx] + ''.join(plainbytes) + cipherbytes[stop_idx:]