# Detecting SmokeLoader 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 smokeloaderscan.py volatility/plugins/malware # 3. python vol.py smokeloaderconfig -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 smokeloader_sig = { 'namespace1' : 'rule SmokeLoader { \ strings: \ $a1 = { B8 25 30 38 58 } \ $b1 = { 81 3D ?? ?? ?? ?? 25 00 41 00 } \ $c1 = { C7 ?? ?? ?? 25 73 25 73 } \ condition: $a1 and $b1 and $c1}' } # Config pattern CONFIG_PATTERNS = [re.compile("\x68\x58\x02\x00\x00\xFF(.....)\x4E\x75\xF2\x8B", re.DOTALL)] STRINGS_PATTERNS = [re.compile("\x57\xBB(....)\x8B(.)\x8B(.)", re.DOTALL)] class smokeloaderConfig(taskmods.DllList): """Parse the SmokeLoader 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 # RC4 def rc4(self, data, key): x = 0 box = range(256) for i in range(256): x = (x + box[i] + ord(key[i % len(key)])) % 256 box[i], box[x] = box[x], box[i] x = 0 y = 0 out = [] for char in data: x = (x + 1) % 256 y = (y + box[x]) % 256 box[x], box[y] = box[y], box[x] out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256])) return ''.join(out) def decode(self, data, keydata): url = [] key = 0xff for i in range(0, 4): key = key ^ (keydata >> (i * 8) & 0xff) for y in data: url.append(chr(ord(y) ^ key)) return "".join(url) def calculate(self): if not has_yara: debug.error("Yara must be installed for this plugin") addr_space = utils.load_as(self._config) os, memory_model = self.is_valid_profile(addr_space.profile) if not os: debug.error("This command does not support the selected profile.") rules = yara.compile(sources=smokeloader_sig) for task in self.filter_tasks(tasks.pslist(addr_space)): scanner = malfind.VadYaraScanner(task=task, rules=rules) for hit, address in scanner.scan(): vad_base_addr, end = self.get_vad_base(task, address) proc_addr_space = task.get_process_address_space() dll_data = proc_addr_space.zread(vad_base_addr, end - vad_base_addr) config_data = [] mz_magic = unpack_from("=2s", dll_data, 0x0)[0] nt_magic = unpack_from("