Skip to content

Instantly share code, notes, and snippets.

@msm-code
msm-code / paper.python.de82eb5882f08c4bdbd882bd1eac058f
Created October 21, 2016 09:53
paper.python.de82eb5882f08c4bdbd882bd1eac058f
if hash == self.CFG_URL: # '48c2026b':
parsed['urls'] += [{'url': append_http(x)} for x in filter(None, map(get_domainc, raw.split(';')))]
elif hash == self.CFG_DGA_HASH: # 'd9aea02a':
parsed['dga_hash'] = [uint32(h) for h in chunks(raw, 4)]
elif hash == self.CFG_DOMAINS: # '095d4b1d':
parsed['domains'] += map(lambda x: {'cnc': x}, filter(None, map(get_domainc, raw.split(';'))))
elif hash == self.CFG_ENC_KEY: # '510be622':
parsed['encryption_key'] = raw
...
@msm-code
msm-code / paper.python.1031ab8a4a6a2b4e14c5b02e0ef66078
Created October 21, 2016 09:53
paper.python.1031ab8a4a6a2b4e14c5b02e0ef66078
def parse_static_config(blob):
i = 0
while i < len(blob):
chunk_type = blob[i:i+4] # chunk type, also called "hash" or "chunk hash" in this article
chunk_len = from_uint32(blob[i+4:i+8])
chunk_content = blob[i+8:i+8+chunk_len]
process_chunk(chunk_type, chunk_content) # this function should process every type of chunk
i += 8 + chunk_len
@msm-code
msm-code / paper.cpp.9649ca87fd3cc81af5e9d904e348f143
Created October 21, 2016 09:53
paper.cpp.9649ca87fd3cc81af5e9d904e348f143
struct chunk {
uint32_t type;
uint32_t length;
char data[chunk_length];
}
@msm-code
msm-code / paper.python.216d5b6e2e17f913cd9d692ad17a7f4a
Created October 21, 2016 09:53
paper.python.216d5b6e2e17f913cd9d692ad17a7f4a
def nymaim_config_crypt(self, mem, ndx):
"""decrypt final config (read keys and length and decrypt raw data)"""
key0 = mem.dword(ndx)
key1 = mem.dword(ndx+4)
len = mem.dword(ndx+8)
raw = mem.read(ndx + 12, len)
prev_chr = 0
result = ''
for i, c in enumerate(raw):
@msm-code
msm-code / paper.python.3c816792f60044320ba90ebb036db304
Created October 21, 2016 09:53
paper.python.3c816792f60044320ba90ebb036db304
def nymaim_decrypt(self, raw, from_raw, length):
from_va = from_raw + self.image_base
xsize = from_va - self.off
cur_key = self.key
if xsize < 0:
raise RuntimeError("raw too small - min is " + hex(self.off - self.image_base))
for _ in range(xsize / 4):
cur_key = (cur_key + self.xstep) & 0xffffffff
r = ''
@msm-code
msm-code / paper.cpp.9fe969957d8333124adfd59d98c59b29
Created October 21, 2016 09:53
paper.cpp.9fe969957d8333124adfd59d98c59b29
void encrypted_memcpy(char *to, char *from, int len) {
if (is_in_encrypted_section(to)) {
if (is_in_encrypted_section(from)) {
memcpy(to, from, len);
} else {
memcpy_and_encrypt(to, from, len);
}
} else {
if (is_in_encrypted_section(from)) {
memcpy_and_decrypt(to, from, len);
@msm-code
msm-code / paper.asm.c8f22939397ddba9457ab4384c76379b
Created October 21, 2016 09:53
paper.asm.c8f22939397ddba9457ab4384c76379b
jz loc_4381B4
xchg eac, [ebp-0Ch]
; nops
push ebx
; nops
push eax
call sub_428b51
; nops
mov eax, 25h
mov ecx, [ebp-0Ch]
@msm-code
msm-code / paper.asm.9f309c5f45c3c13cc5004490647f08fd
Created October 21, 2016 09:53
paper.asm.9f309c5f45c3c13cc5004490647f08fd
jz loc_4381B4
xchg eac, [ebp-0Ch]
push 053h
call push_cpu_register ; push ebx
push 050h
call push_cpu_register ; push eax
push edx
push 8AB4BF9Eh
push 754A35C1h
call detour_1 ; call f(8AB4BF9Eh, 754A35C1h)
@msm-code
msm-code / paper.asm.64ca36263ef4107022aa090a54c67161
Created October 21, 2016 09:53
paper.asm.64ca36263ef4107022aa090a54c67161
push 0x40404040
push 0x02020202
jmp detour
detour:
pop eax ; oversimplification, detour can never spoil registers
pop ebx
add eax, ebx ; or xor, or sub, or add
jmp eax
@msm-code
msm-code / paper.asm.d8e2b049f81c1c7c57f717b042db6bed
Created October 21, 2016 09:53
paper.asm.d8e2b049f81c1c7c57f717b042db6bed
jmp 0x42424242