Skip to content

Instantly share code, notes, and snippets.

@msm-code
msm-code / paper.unk.40194f6deb5d679ccdd66f7885ad3281
Created October 21, 2016 09:54
paper.unk.40194f6deb5d679ccdd66f7885ad3281
<d2bf6f4a> >>> [+] [ 62 bytes]:
state information:
data field 0: 0x263
data field 1: 0x23426908
data field 2: 0x0
data field 3: 0x0 <- injects version
data field 4: 0x0
data field 5: 0x0
data field 6: 0x0 <- webfilters version
data field 7: 0x0
@msm-code
msm-code / paper.python.fd38e71c7996d21488ca07737dd4dc15
Created October 21, 2016 09:54
paper.python.fd38e71c7996d21488ca07737dd4dc15
def inner_decrypt(raw, rsa_key):
encrypted_header, encrypted_data = raw[-0x40:], raw[:-0x40]
decrypted_data = rsa_decrypt(encrypted_header, rsa_key)
md5 = decrypted_data[0:16]
blob = decrypted_data[16:32]
length = from_uint32(decrypted_data[32:36])
serpent_decrypted = crypto.s_decrypt(encrypted_data, blob)[:length]
assert md5 == hashlib.md5(serpent_decrypted).digest()
@msm-code
msm-code / paper.python.9791eab6a92fd95aff480029c993e429
Created October 21, 2016 09:54
paper.python.9791eab6a92fd95aff480029c993e429
def parse_message(blob):
i = 0
while i < len(blob):
chunk_type = blob[i:i+4]
chunk_len = from_uint32(blob[i+4:i+8])
chunk_content = blob[i+8:i+8+chunk_len]
process_chunk(chunk_type, chunk_content)
i += 8 + chunk_len
@msm-code
msm-code / paper.python.aff86e72b5462bf8d858196af5f88ea2
Created October 21, 2016 09:54
paper.python.aff86e72b5462bf8d858196af5f88ea2
def nymaim_decrypt(key, raw_bytes):
nibble0 = raw_bytes[0] & 0xF
nibble1 = raw_bytes[1] & 0xF
salt = raw_bytes[2:2+nibble0]
password = key + salt
data = raw_bytes[2+nibble0:len(raw_bytes)-nibble1]
decrypted = rc4_decrypt(password, body)
decrypted_len = struct.unpack('&lt;I', decrypted[:4])[0]
assert decrypted_len == len(decrypted - 4)
@msm-code
msm-code / paper.unk.b15cdefe7c7ddf047ea537cc68fd66a5
Created October 21, 2016 09:54
paper.unk.b15cdefe7c7ddf047ea537cc68fd66a5
╰─$ strings decrypted_nymaim | grep -E "nginx" -B 4
HTTP/1.1 200 OK
Connection: close
Content-Length: %u
Content-Type: application/octet-stream
Server: nginx/1.9.4
@msm-code
msm-code / paper.unk.36ceda36e9be4e2c33450c45cca7dd3e
Created October 21, 2016 09:54
paper.unk.36ceda36e9be4e2c33450c45cca7dd3e
╰─$ strings decrypted_nymaim | grep -E "PortMap|upnp"
DeletePortMapping
urn:schemas-upnp-org:service:WANPPPConnection:1
urn:schemas-upnp-org:device:InternetGatewayDevice:1
GetSpecificPortMappingEntry
upnp:rootdevice
AddPortMapping
AddAnyPortMapping
urn:schemas-upnp-org:service:WANIPConnection:1
NewPortMappingDescription
@msm-code
msm-code / paper.unk.c546fcbd77a890eb64e329abe31b673a
Created October 21, 2016 09:54
paper.unk.c546fcbd77a890eb64e329abe31b673a
╰─$ strings decrypted_nymaim | grep -E "#!#|Firewall"
#!#*|Action=Allow|#*
#!#*|Action=Block|#*
#!#*|Active=TRUE|#*
#!#*|Active=FALSE|#*
#!#*|Dir=In|#*
#!#*|Dir=Out|#*
#!#*|Profile=Private|#*
#!#*|Profile=Public|#*
#!#*|LPort=#*
@msm-code
msm-code / paper.python.b29d1255e212fce3077bc026a860e2cf
Created October 21, 2016 09:54
paper.python.b29d1255e212fce3077bc026a860e2cf
def dga_single(self, state):
name = ''
len = self.getbyte(state, 8) + 5
for i in range(len):
r = self.getbyte(state, 0xFFFFFFFF)
c = self.getbyte(state, 26) + 0x61
name += chr(c)
n = 0
while n == 0:
n = self.getbyte(state, 5)
@msm-code
msm-code / paper.python.de82eb5882f08c4bdbd882bd1eac058f
Created October 21, 2016 09:54
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:54
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