Last active
August 4, 2017 01:06
-
-
Save hasherezade/17583b17ae7c9660b87aa22cbc20bc23 to your computer and use it in GitHub Desktop.
Script for IDA Pro decoding Latent Bot's strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """latent_dec.py: Script for IDA Pro decoding Latent Bot's strings""" | |
| __author__ = "hasherezade" | |
| import idautils | |
| lookup_table = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x00\x00\x3F\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x00\x00\x00\x00\x00\x00\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | |
| def transform_chunk(chunk, chunk_size): | |
| if chunk_size > 4: | |
| chunk_size = 4 | |
| result = 0 | |
| for i in range(0, chunk_size): | |
| mchar = ord(chunk[i]) | |
| val = ord(lookup_table[mchar]) | |
| val = val << (0x6 * i) | |
| result = result + val | |
| return result | |
| def append_transformed(o, val): | |
| for i in range(0, 3): | |
| bval = (val >> (i * 8)) & 0XFF | |
| o.append(bval) | |
| def process_chunks(s): | |
| o = [] | |
| while s: | |
| chunk = s[:4] | |
| val = transform_chunk(chunk, len(chunk)) | |
| append_transformed(o, val) | |
| s = s[4:] | |
| return o | |
| def is_in_charset(str1): | |
| for c in str1: | |
| cval = ord(c) | |
| if (cval in range(ord('a'), ord('z')+1)): | |
| continue | |
| if (cval in range(ord('A'), ord('Z')+1)): | |
| continue | |
| if (cval in range(ord('0'), ord('9')+1)): | |
| continue | |
| if (cval == ord('+')): | |
| continue | |
| if (cval == ord('/')): | |
| continue | |
| else: | |
| return False | |
| return True | |
| def isprint(cval): | |
| if (cval in range(32,127)): | |
| return True | |
| return False | |
| def xordec(data, modifier): | |
| out_str = [] | |
| data_size = len(data) | |
| for i in range(0, data_size): | |
| result = (data[i] ^ (modifier >> 8)) & 0xFF | |
| if isprint(result) == False: | |
| break | |
| out_str.append(chr(result)) | |
| modifier += data[i] | |
| modifier *= 0x0CE6D | |
| modifier += 0x058BF | |
| return "".join(out_str) | |
| def latent_decode(str1): | |
| try: | |
| data = process_chunks(str1) | |
| dec_str = xordec(data, 0xBB8) | |
| return dec_str | |
| except : | |
| print "Decoding failed" | |
| return None | |
| #main: | |
| sc = idautils.Strings() | |
| for s in sc: | |
| if is_in_charset(str(s)) == False: | |
| continue | |
| decoded_string = latent_decode(str(s)) | |
| if decoded_string is not None and len(decoded_string) > 0: | |
| print "%x: '%s' -> '%s'" % (s.ea, str(s), decoded_string) | |
| MakeRptCmt(s.ea, decoded_string) #set the decoded as a comment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment