Skip to content

Instantly share code, notes, and snippets.

@secrary
Created July 11, 2017 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save secrary/98c563688fa6cea1fd517170f97988ab to your computer and use it in GitHub Desktop.
Save secrary/98c563688fa6cea1fd517170f97988ab to your computer and use it in GitHub Desktop.
Extract payload from Upatre (sample: 1b893ca3b782679b1e5d1afecb75be7bcc145b5da21a30f6c18dbddc9c6de4e7)
import ctypes
import binascii
input_ = input("Upatre sample: ")
with open(input_, 'rb+') as file:
data = file.read()[0x66d: 0x66d + 0xe40]
uncompressed = ctypes.create_string_buffer(0x1200)
final_size = ctypes.c_ulong(0)
decoded = binascii.a2b_base64(data)
list_ = []
for i, n in enumerate(decoded):
list_.append(decoded[i] ^ 0x4C)
ctypes.windll.ntdll.RtlDecompressBuffer(2, uncompressed, 0x1200, ctypes.c_char_p(bytes(list_)), 0x1200,
ctypes.byref(
final_size))
with open(input_ + ".extr.exe", "wb") as outfile:
for n in list(uncompressed):
outfile.write(n)
@secrary
Copy link
Author

secrary commented Jul 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment