Detection philosophy
From README.md:25-29:
After terminating the process, based on Dr.Semu rules we receive if the executable is detected as malware or not.
Dr.Semu Rules/Detections
Dr.Semu focuses on behavior-based detection rather than signatures:
- ✅ Behavioral patterns - What the malware does
- ✅ API call sequences - How the malware interacts with Windows
- ✅ File operations - Where the malware writes files
- ❌ Static signatures - Byte patterns (not the primary focus)
- Polymorphic malware (changes signature each time)
- Packed malware (code is encrypted until runtime)
- Living-off-the-land attacks (uses legitimate system tools)
Rule languages
Lua and Python support
From README.md:31-33:They are written inPythonorLUA(located underdr_rules) and use dynamic information from the interception and static information about the sample. It’s trivial to add support of other languages.
- Lua
- Python
Advantages:
- Lightweight and fast
- Easy to sandbox
- Simple syntax for quick rules
- Low memory footprint
- Quick pattern matching
- Simple detection logic
- Community contributions
Rule structure
Basic rule template
Every rule must implement acheck() function:
Return values
Rules return a verdict string:"CLEAN"orb"CLEAN"- No malicious behavior detected"DetectionName"- Malware detected, classification provided
"Win32.Ransomware.WannaCry""Trojan.Downloader.Generic""Backdoor.RemoteAccess"
Data sources
Rules have access to three types of data:1. Starter information
Contains metadata about the analysis session:2. Dynamic behavior
JSON logs of all intercepted system calls, one file per process: Filename:{pid}.json
Contents: Array of system call objects
3. Static analysis
PE file analysis including imports, exports, sections, and resources: Filename:{sha256}.json
Contents: Static file properties
Detection workflow
Sample execution completes
The target process and all child processes terminate. JSON reports are written to the report directory.
Detection engine launches
run_detections.exe is started with the report directory path (LauncherCLI.cpp:438-466).Example detections
WannaCry kill switch detection
Fromwannacry_url.lua:7-21:
- Load dynamic behavior for the first process
- Iterate through all system calls
- Find
InternetOpenUrlWcalls - Check if URL matches WannaCry kill switch domain
- Return classification if matched
EICAR test detection
Fromdr_semu_eicar.py:8-23:
- Extract starter details (path, PID, hash)
- Load dynamic behavior JSON
- Look for process creation calls
- Check if created process name contains “eicar”
- Return detection if matched
Common detection patterns
Ransomware indicators
Credential theft
Process injection
Persistence mechanisms
Detection rule best practices
Be specific
Avoid false positives by checking multiple indicators, not just one suspicious action.
Use thresholds
Count operations (e.g., “100+ file writes”) rather than detecting single events.
Check context
Consider the full behavior sequence, not isolated actions.
Test thoroughly
Run rules against clean software and known malware to tune detection.
Community rules
Dr.Semu supports community-contributed rules:Official rule repository: DrSemu-Detections
-
Clone the repository:
-
Copy rules to Dr.Semu:
- Run analysis - rules are automatically loaded
Verdict reporting
The final verdict is communicated via mailslot:Performance considerations
Rule execution overhead
- Lua: ~10-50ms per rule
- Python: ~50-200ms per rule (interpreter startup)
- Total: Usually completes in < 1 second for typical rule sets
Optimization strategies
- Quick checks first - Put fast string checks before expensive operations
- Early return - Return as soon as malware is detected
- Lazy loading - Only parse JSON when needed
- Cache data - Store frequently accessed values in variables
See also
Writing Lua rules
Complete Lua rule development guide
Writing Python rules
Complete Python rule development guide
Rule examples
Real-world detection examples
JSON schema
Behavior report format reference