SQL Dialect Quick Reference#
Allowed Functions#
String Functions#
Function Description Example LENGTH(str)String length LENGTH(command_line)SUBSTR(str, start, length)Substring extraction SUBSTR(executable_path, 1, 10)INSTR(str, substr)Find substring position INSTR(command_line, 'malicious')LIKE patternPattern matching name LIKE '%suspicious%'
Encoding Functions#
Function Description Example HEX(data)Convert to hexadecimal HEX(executable_hash)UNHEX(hex)Convert from hexadecimal UNHEX('deadbeef')
Mathematical Functions#
Function Description Example COUNT(*)Count rows COUNT(*) as process_countSUM(expr)Sum values SUM(memory_usage)AVG(expr)Average values AVG(cpu_usage)MAX(expr)Maximum value MAX(memory_usage)MIN(expr)Minimum value MIN(start_time)
Banned Functions#
Security-Critical (Always Banned)#
load_extension() - SQLite extension loading
eval() - Code evaluation
exec() - Command execution
system() - System calls
shell() - Shell execution
File System Operations (Not Applicable)#
readfile() - File reading
writefile() - File writing
edit() - File editing
glob() - Glob patterns
regexp() - Regular expressions
match() - Pattern matching
Mathematical Functions (Not Applicable)#
abs() - Absolute value
random() - Random numbers
randomblob() - Random binary data
quote() - SQL quoting
printf() - String formatting
format() - String formatting
char() - Character conversion
unicode() - Unicode functions
soundex() - Soundex algorithm
difference() - String difference
Process Data Schema#
Copy
CREATE TABLE processes (
id INTEGER PRIMARY KEY ,
scan_id INTEGER NOT NULL ,
collection_time INTEGER NOT NULL ,
pid INTEGER NOT NULL ,
ppid INTEGER ,
name TEXT NOT NULL ,
executable_path TEXT ,
command_line TEXT ,
start_time INTEGER ,
cpu_usage REAL ,
memory_usage INTEGER ,
status TEXT ,
executable_hash TEXT ,
hash_algorithm TEXT ,
user_id INTEGER ,
group_id INTEGER ,
accessible BOOLEAN ,
file_exists BOOLEAN ,
environment_vars TEXT ,
metadata TEXT ,
platform_data TEXT
) ;
Common Query Patterns#
Basic Detection#
Copy
SELECT * FROM processes WHERE name = 'suspicious-process' ;
SELECT * FROM processes WHERE name LIKE '%malware%' ;
Resource Analysis#
Copy
SELECT * FROM processes WHERE cpu_usage > 80.0 ;
SELECT * FROM processes WHERE memory_usage > 2147483648 ;
Hash-Based Detection#
Copy
SELECT * FROM processes
WHERE executable_hash = 'a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef' ;
Command Line Analysis#
Copy
SELECT * FROM processes
WHERE command_line LIKE '%nc -l%'
OR command_line LIKE '%wget%'
OR LENGTH( command_line) > 1000 ;
Path-Based Detection#
Copy
SELECT * FROM processes
WHERE executable_path LIKE '/tmp/%'
OR executable_path LIKE '/var/tmp/%'
OR executable_path IS NULL ;
Use Indexes#
Time-based queries: WHERE collection_time > ?
Process ID queries: WHERE pid = ?
Name queries: WHERE name = ?
Limit Result Sets#
Copy
SELECT * FROM processes WHERE name LIKE '%test%' LIMIT 100 ;
Avoid Complex Operations#
Copy
WHERE name = 'process' AND pid > 1000 ;
WHERE LENGTH( SUBSTR( command_line, 1 , 100 ) ) > 50 ;
Security Best Practices#
Use Parameterized Queries#
Copy
SELECT * FROM processes WHERE name = ?;
SELECT * FROM processes WHERE name = '" + user_input + "' ;
Always validate user-provided SQL fragments
Use only approved functions
Check for banned function usage
Watch for queries that consume excessive resources
Use query timeouts
Monitor memory usage