How Detection Rules Work
Detection rules execute after Dr.Semu completes its analysis of a sample. Each rule:- Receives a
report_directorypath containing JSON analysis results - Analyzes static information (PE headers, imports, sections, etc.)
- Analyzes dynamic behavior (API calls, registry operations, file operations, etc.)
- Returns a detection verdict string or “CLEAN”
Rules run in a sandboxed environment and have access to utility functions for parsing analysis data.
Choosing Lua vs Python
Lua Rules
Best for:- Fast execution and low memory overhead
- Simple pattern matching and string operations
- Rules that need to be frequently updated
- Faster execution time
- Built-in JSON parsing with utilities
- Simpler syntax for common detection patterns
Python Rules
Best for:- Complex data analysis
- Rules requiring external libraries
- Advanced pattern matching with regex
- Full Python standard library access
- More familiar to security researchers
- Better for complex logic and data structures
Rule Directory Structure
Detection rules are stored in therun_detections/dr_rules_files/ directory:
Analysis Data Structure
Each analyzed sample produces JSON files in the report directory:- starter.json - Initial process information (image path, PID, SHA-256)
- .json - Dynamic behavior logs for each process
- .json - Static analysis results (PE info, imports, sections)
starter.json Format
Dynamic Behavior Format
Dynamic JSON files contain arrays of API calls with before/after states:Static Analysis Format
Static JSON files contain PE file analysis:Quick Start Example
- Lua
- Python
Next Steps
Lua Rules
Learn how to write Lua detection rules
Python Rules
Learn how to write Python detection rules
Rule Examples
See real-world detection rule examples
Best Practices
Learn rule development best practices