# Detecting Bebloh(Shiotob, URLZone) for Volatility # # LICENSE # Please refer to the LICENSE.txt in the https://github.com/JPCERTCC/MalConfScan/ # # How to use: # 1. cd "Volatility Folder" # 2. mv beblohscan.py volatility/plugins/malware # 3. python vol.py beblohconfig -f images.mem --profile=Win7SP1x64 import volatility.plugins.taskmods as taskmods import volatility.win32.tasks as tasks import volatility.utils as utils import volatility.debug as debug import volatility.plugins.malware.malfind as malfind import re from struct import unpack, unpack_from from collections import OrderedDict try: import yara has_yara = True except ImportError: has_yara = False bebloh_sig = { 'namespace1' : 'rule Bebloh { \ strings: \ $crc32f = { b8 EE 56 0b ca } \ $dga = "qwertyuiopasdfghjklzxcvbnm123945678" \ $post1 = "&vcmd=" \ $post2 = "?tver=" \ condition: all of them}' } # RSA key header RSA_HEADER = b"\x06\x02\x00\x00\x00\xa4\x00\x00\x52\x53\x41\x31\x00\x04\x00\x00" # Config pattern CONFIG_PATTERNS = [re.compile("\x83\x45\x08\x02\xe8(....)", re.DOTALL)] class beblohConfig(taskmods.DllList): """Parse the Bebloh configuration""" @staticmethod def is_valid_profile(profile): return (profile.metadata.get('os', 'unknown') == 'windows'), profile.metadata.get('memory_model', '32bit') def get_vad_base(self, task, address): for vad in task.VadRoot.traverse(): if address >= vad.Start and address < vad.End: return vad.Start, vad.End return None def crc32(self, buf, value): table = [] for i in range(256): v = i for j in range(8): v = (0xEDB88320 ^ (v >> 1)) if(v & 1) == 1 else (v >> 1) table.append(v) for c in buf: value = value ^ ord(c) value = table[value & 0xFF] ^ (value >> 8) return value def sum_of_characters(self, domain): return sum([ord(d) for d in domain[:-3]]) def get_next_domain(self, domain, xor): qwerty = "qwertyuiopasdfghjklzxcvbnm123945678" sof = self.sum_of_characters(domain) ^ xor ascii_codes = [ord(d) for d in domain] + 100 * [0] old_hostname_length = len(domain) - 4 for i in range(0, 66): for j in range(0, 66): edi = j + i if edi < 65: p = (old_hostname_length * ascii_codes[j]) cl = p ^ ascii_codes[edi] ^ sof ascii_codes[edi] = cl & 0xFF """ calculate the new hostname length max: 255/16 = 15 min: 10 """ cx = ((ascii_codes[2] * old_hostname_length) ^ ascii_codes[0]) & 0xFF hostname_length = int(cx / 16) # at most 15 if hostname_length < 10: hostname_length = old_hostname_length """ generate hostname """ for i in range(hostname_length): index = int(ascii_codes[i] / 8) # max 31 --> last 3 chars of qwerty unreachable bl = ord(qwerty[index]) ascii_codes[i] = bl hostname = ''.join([chr(a) for a in ascii_codes[:hostname_length]]) """ append .net or .com (alternating) """ tld = '.com' if domain.endswith('.net') else '.net' domain = hostname + tld return domain def parse_config(self, data, base, rsa_key, dga_key): p_data = OrderedDict() p_data["RSA key"] = rsa_key.encode("hex") p_data["Sleep count"] = unpack_from("