This Lua rule detects WannaCry ransomware by identifying its kill switch URL.File:run_detections/dr_rules_files/wannacry_url.lua
utils = require "utils"function check(report_directory) local status = "CLEAN" -- open the first json file and read content local first_dynamic = utils.get_first_process_json(report_directory) local first_static = utils.get_first_static(report_directory) -- static information local is_x86 = false if first_static ~= nil then is_x86 = first_static.generic.is_x86 end -- dynamic information if first_dynamic ~= nil then -- enumerate json for index, win_func in pairs(first_dynamic) do if 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" end end end end return statusend
This rule demonstrates network behavior analysis by monitoring InternetOpenUrlA API calls for the specific kill switch domain used by WannaCry.
This comprehensive Lua template demonstrates multiple detection techniques.File:run_detections/dr_rules_files/sample_rule.lua
utils = require "utils"function check(report_directory) local status = "CLEAN" -- open the first json file and read content local first_dynamic = utils.get_first_process_json(report_directory) local first_static = utils.get_first_static(report_directory) -- static information local is_x86 = false if first_static ~= nil then is_x86 = first_static.generic.is_x86 end -- dynamic information if first_dynamic ~= nil then -- enumerate json for index, win_func in pairs(first_dynamic) do -- get information from a call, e.g. if the call is NtCreateUserProcess if win_func.NtCreateUserProcess then -- Get a PID of a new process, with PID we can enumerate calls from a new process 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 end end -- and check the new process parameters if win_func.NtCreateUserProcess.before.image_path ~= nil then if win_func.NtCreateUserProcess.before.image_path:find("whoami") then return "WHOAMI!EXE" end end end -- other check for reg key creation if win_func.NtCreateKey and win_func.NtCreateKey.success == true then if win_func.NtCreateKey.before.key_path:find("malicious_key_for_dr_semu") then return "Dr.Semu!TEST" end end end end return statusend
This template showcases multiple detection patterns including child process analysis, registry monitoring, and path-based detection.
-- From wannacry_url.luaif 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" endend
# Network IOC detection patternfor win_func in dynamic_info: if "InternetOpenUrlA" in win_func: url = win_func["InternetOpenUrlA"]["before"]["url"].lower() if url == "http://malicious-domain.com": return b"Win32.Malware.DR"
-- From sample_rule.luaif win_func.NtCreateUserProcess then if win_func.NtCreateUserProcess.before.image_path ~= nil then if win_func.NtCreateUserProcess.before.image_path:find("whoami") then return "WHOAMI!EXE" end endend
# From dr_semu_eicar.pyfor 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"
-- From sample_rule.luaif win_func.NtCreateKey and win_func.NtCreateKey.success == true then if win_func.NtCreateKey.before.key_path:find("malicious_key_for_dr_semu") then return "Dr.Semu!TEST" endend
# Registry persistence detectionfor win_func in dynamic_info: if "NtCreateKey" in win_func: if win_func["NtCreateKey"]["success"]: key_path = win_func["NtCreateKey"]["before"]["key_path"] if "Run" in key_path or "RunOnce" in key_path: return b"Win32.Persistence.Registry"
-- From sample_rule.luaif 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 end end endend
# Child process analysisfor win_func in dynamic_info: if "NtCreateUserProcess" in win_func: if win_func["NtCreateUserProcess"]["success"]: child_pid = win_func["NtCreateUserProcess"]["after"]["proc_id"] child_json = dr_semu_utils.get_json_from_file( report_directory + b"\\" + str(child_pid).encode() + b".json" ) if child_json: for child_func in child_json: # Analyze child behavior pass
utils = require "utils"function check(report_directory) local status = "CLEAN" local first_dynamic = utils.get_first_process_json(report_directory) if first_dynamic ~= nil then local created_suspicious_file = false local accessed_kill_switch = false for index, win_func in pairs(first_dynamic) do -- Check for kill switch URL (WannaCry pattern) if win_func.InternetOpenUrlA and win_func.InternetOpenUrlA.before.url then local url = win_func.InternetOpenUrlA.before.url:lower() if url:find("iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea") then accessed_kill_switch = true end end -- Check for file creation with suspicious extensions if win_func.NtCreateFile then local file_path = win_func.NtCreateFile.before.file_path if file_path and file_path:find("\.wncry$") then created_suspicious_file = true end end end if accessed_kill_switch and created_suspicious_file then return "Win32.WannaCry.DR" end end return statusend
import dr_semu_utilsdef check(report_directory): verdict = b"CLEAN" image_path, pid, sha_256 = dr_semu_utils.get_starter_details(report_directory) dynamic_info = dr_semu_utils.get_json_from_file( report_directory + b"\\" + str(pid).encode() + b".json" ) if not dynamic_info: return verdict spawned_recon = False accessed_credentials = False for win_func in dynamic_info: # Check for reconnaissance tools (from sample_rule pattern) if "NtCreateUserProcess" in win_func: img = win_func["NtCreateUserProcess"]["before"]["image_path"].lower() if "whoami" in img or "ipconfig" in img or "netstat" in img: spawned_recon = True # Check for credential file access if "NtCreateFile" in win_func: file_path = win_func["NtCreateFile"]["before"]["file_path"].lower() if "credential" in file_path or "passwords" in file_path: accessed_credentials = True if spawned_recon and accessed_credentials: return b"Win32.InfoStealer.DR" return verdict