-- From wannacry_url.lua:27-31if win_func.InternetOpenUrlA and win_func.InternetOpenUrlA.before.url then local url = win_func.InternetOpenUrlA.before.url:lower() if url == "http://www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" then return "Win32.WannaCry.DR" -- Stop immediately endend
# From dr_semu_eicar.py:17-21for win_func in dynamic_info: if "NtCreateUserProcess" in win_func: image_path = win_func["NtCreateUserProcess"]["before"]["image_path"] if image_path.lower().endswith("drsemu_eicar.exe"): return b"Win32.EICAR.Dr" # Stop immediately
Always check for nil/None before accessing nested fields:
Lua
Python
-- From sample_rule.lua:17-20local is_x86 = falseif first_static ~= nil then is_x86 = first_static.generic.is_x86end
# Validate before processingimage_path, pid, sha_256 = dr_semu_utils.get_starter_details(report_directory)if image_path is None: return b"CLEAN" # No data available
-- From wannacry_url.lua:28local url = win_func.InternetOpenUrlA.before.url:lower()-- Now reuse 'url' instead of calling :lower() multiple times
# Cache case conversionimage_path_lower = image_path.lower()if "cmd.exe" in image_path_lower or "powershell.exe" in image_path_lower: # Use cached value pass
-- Always verify success before using resultsif win_func.NtCreateUserProcess.success == true then local target_PID = win_func.NtCreateUserProcess.after.proc_id -- Safe to use proc_idendif win_func.NtCreateKey and win_func.NtCreateKey.success == true then -- Safe to access key_path if win_func.NtCreateKey.before.key_path:find("malicious_key") then return "Dr.Semu!TEST" endend
-- Check field exists before using string methodsif win_func.NtCreateUserProcess.before.image_path ~= nil then if win_func.NtCreateUserProcess.before.image_path:find("whoami") then return "WHOAMI!EXE" endend
-- From wannacry_url.lua:27-31if win_func.InternetOpenUrlA and win_func.InternetOpenUrlA.before.url then local url = win_func.InternetOpenUrlA.before.url:lower() if url == "http://www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" then return "Win32.WannaCry.DR" -- Kill switch URL is definitive endend
The WannaCry kill switch URL is a perfect strong indicator - it’s unique and specific to WannaCry.
-- Analyze child processesif win_func.NtCreateUserProcess then if win_func.NtCreateUserProcess.success == true then local target_PID = win_func.NtCreateUserProcess.after.proc_id local decoded_json = utils.get_json_pid(report_directory, target_PID) if not decoded_json.empty then -- enumerate a json of the child process for index, child_func in pairs(decoded_json) do -- Analyze child behavior recursively end end endend
Process tree analysis is powerful for detecting multi-stage malware and living-off-the-land attacks.
From sample_rule.lua:13-15 and sample_rule.lua:28-29:
-- -- your code starts from here-- -- get information from a call, e.g. if the call is NtCreateUserProcessif win_func.NtCreateUserProcess then -- Get a PID of a new process, with PID we can enumerate calls from a new process
-- Bad: Will crash if field is nilif win_func.NtCreateUserProcess.before.image_path:find("malware") then return "Detected"end-- Good: Check nil first (from sample_rule.lua:39)if win_func.NtCreateUserProcess.before.image_path ~= nil then if win_func.NtCreateUserProcess.before.image_path:find("malware") then return "Detected" endend