Skip to content

V3n0mSh3ll/themeguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ThemeGuard

Enterprise WordPress Threat Detection Engine
30 Modules β€’ 158 Signatures β€’ ML Classification β€’ Real-Time Protection β€’ Cross-File Correlation

Python Modules Tests License WordPress


⚑ What is ThemeGuard?

ThemeGuard is a WordPress-focused static and behavioral malware scanner with recursive payload decoding, confidence scoring, cross-file correlation, cloud threat intelligence, and real-time watch mode.

Unlike generic security tools, ThemeGuard understands WordPress internals - hooks, cron persistence, REST API backdoors, nonce bypasses, option table poisoning, and more.


πŸ”₯ Key Features

πŸ” Detection Engine

  • 158 detection signatures across 7 categories
  • 30 custom .tgr threat rules (WordPress-specific)
  • Aho-Corasick O(n) multi-pattern matching
  • Recursive payload decoder (8-depth: b64β†’hexβ†’chrβ†’rot13β†’gzinflate)
  • ML classifier - 26-feature statistical risk scoring

πŸ›‘οΈ WordPress Deep Analysis

  • Hook backdoor detection (add_action/add_filter)
  • Cron persistence detector
  • REST API unauthenticated endpoint scanner
  • Nonce/auth bypass detection
  • WP Core integrity check (WordPress.org API)

🧠 Intelligence Layer

  • Cross-file correlation - shared URLs, domains, campaigns
  • Malware family classification (WP-VCD, WSO, AnonymousFox, etc.)
  • Cloud threat intel - URLhaus + WPScan API integration
  • C2/phone-home communication detection
  • Infection timeline analysis

βš™οΈ Enterprise Features

  • Confidence scoring (separate from severity)
  • Finding deduplication with stable IDs
  • False positive suppression engine
  • SQLite evidence store with scan diff
  • Triage reports with actionable priorities
  • Real-time watch mode with debounce

πŸ“Š Detection Coverage

Category Signatures Examples
πŸ”΄ PHP Backdoors 48 eval/base64 chains, command injection, RCE, file write
🟠 Webshells 23 c99, r57, WSO, Alfa, b374k, China Chopper, reverse shells
🟑 Plugin Backdoors 30 AJAX exploits, REST API, license bypass, cron persistence
πŸ”΅ Crypto Miners 13 CoinHive, XMRig, CryptoLoot, mining pool URLs
🟣 SEO Spam 13 Hidden links, pharma hacks, doorway pages, cloaking
βšͺ Obfuscation 16 str_rot13, hex2bin, chr chains, strrev, error suppression
🟀 File Anomalies 15 Double extensions, WP-VCD, .htaccess abuse, nulled markers

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   SCAN PIPELINE                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Phase A: Prefilter                                  β”‚
β”‚    file_walker β†’ prefilter β†’ file_classifier         β”‚
β”‚                                                      β”‚
β”‚  Phase B: Per-File Analysis (parallel)               β”‚
β”‚    signatures β†’ obfuscation β†’ network β†’ integrity    β”‚
β”‚    β†’ PHP deep β†’ WP deep β†’ threat engine β†’ ML         β”‚
β”‚    β†’ recursive decoder β†’ cloud intel                 β”‚
β”‚                                                      β”‚
β”‚  Phase C: Directory Scans                            β”‚
β”‚    .htaccess β†’ wp-config β†’ polyglot β†’ timeline       β”‚
β”‚                                                      β”‚
β”‚  Phase D: Post-Processing                            β”‚
β”‚    dedup β†’ correlate β†’ score β†’ suppress β†’ filter     β”‚
β”‚                                                      β”‚
β”‚  Phase E: Output                                     β”‚
β”‚    evidence store β†’ triage report β†’ HTML/JSON/SARIF  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Installation

πŸ‰ Kali Linux

# Python3 comes pre-installed on Kali
sudo apt update && sudo apt install -y python3 python3-pip git

# Clone the repository
git clone https://github.com/V3n0mSh3ll/themeguard.git
cd themeguard

# Install dependencies
pip3 install -r requirements.txt

# Make executable (optional)
chmod +x themeguard.py

# Verify installation
python3 -m unittest tests.test_scanner tests.test_enterprise -v

πŸ“± Termux (Android)

# Initial setup
pkg update && pkg upgrade -y
pkg install -y python git

# Clone the repository
git clone https://github.com/V3n0mSh3ll/themeguard.git
cd themeguard

# Install dependencies
pip install -r requirements.txt

# Run ThemeGuard
python themeguard.py

# Scan files on device storage
# termux-setup-storage   (grant storage access first time)
python themeguard.py --path /sdcard/Download/theme-folder/

🐧 Ubuntu / Debian / Any Linux

sudo apt update && sudo apt install -y python3 python3-pip git
git clone https://github.com/V3n0mSh3ll/themeguard.git
cd themeguard
pip3 install -r requirements.txt
python3 themeguard.py

πŸͺŸ Windows

# Requires Python 3.8+ from python.org
git clone https://github.com/V3n0mSh3ll/themeguard.git
cd themeguard
pip install -r requirements.txt
python themeguard.py

πŸ“– Usage Guide

🎯 Interactive Menu (Easiest)

python3 themeguard.py

This launches the interactive menu - select an option and the scan starts:

╔══════════════════════════════════════════╗
β•‘         THEMEGUARD v1.0                  β•‘
β•‘   WordPress Threat Detection Engine      β•‘
╠══════════════════════════════════════════╣
β•‘  [1] Scan Theme                          β•‘
β•‘  [2] Scan Plugin                         β•‘
β•‘  [3] Scan Full wp-content                β•‘
β•‘  [4] Watch Mode (Real-time)              β•‘
β•‘  [5] View Scan History                   β•‘
β•‘  [6] Quarantine Management               β•‘
β•‘  [0] Exit                                β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ” Theme Scan

# Basic scan
python3 themeguard.py --path ~/Downloads/flavor/

# Deep scan (includes WP core integrity check)
python3 themeguard.py --path ~/Downloads/flavor/ --deep

# Show only high/critical findings
python3 themeguard.py --path ~/Downloads/flavor/ --severity high

πŸ”Œ Plugin Scan

python3 themeguard.py --path ~/Downloads/contact-form-7/ --type plugin

πŸ“‚ Full wp-content Scan

# Scan everything - themes, plugins, uploads, mu-plugins
python3 themeguard.py --path ~/Downloads/wp-content/ --type full

🌐 Network Analysis (Cloud Intel)

# Check URLs and hashes against URLhaus + WPScan API
python3 themeguard.py --path ~/Downloads/flavor/ --network

# Combine deep scan with network analysis
python3 themeguard.py --path ~/Downloads/flavor/ --deep --network

πŸ“Š Generating Reports

# HTML report
python3 themeguard.py --path ~/Downloads/flavor/ --report html

# JSON report
python3 themeguard.py --path ~/Downloads/flavor/ --report json

# Both formats
python3 themeguard.py --path ~/Downloads/flavor/ --report both

# SARIF format (for CI/CD integration)
python3 themeguard.py --path ~/Downloads/flavor/ --report sarif

Reports are saved in the reports/ directory.

πŸ‘οΈ Watch Mode (Real-Time Monitoring)

# Automatically scans any file changes in real time
python3 themeguard.py --path ~/Downloads/flavor/ --watch

Watch mode features:

  • Detects file changes (new, modified, deleted)
  • 3-second debounce to prevent scan flooding
  • Storm protection (throttles at 50+ changes per 10 seconds)
  • Auto-recovery on errors
  • Press Ctrl+C to stop

πŸ”’ Quarantine

When critical or high-severity threats are found, quarantine the infected files:

# Quarantine after scan
python3 themeguard.py --path ~/Downloads/flavor/ --quarantine

# List quarantined files
python3 themeguard.py --list-quarantine

# Restore a quarantined file (SHA-256 integrity verified)
python3 themeguard.py --restore infected-file.php

πŸ“œ Scan History

# View previous scans (stored in SQLite)
python3 themeguard.py --history

# Compare two scans (shows new vs resolved findings)
python3 themeguard.py --diff scan-id-1 scan-id-2

πŸ§ͺ Running Tests

# Run all 68 tests
python3 -m unittest tests.test_scanner tests.test_enterprise -v

# Enterprise module tests only
python3 -m unittest tests.test_enterprise -v

# Core scanner tests only
python3 -m unittest tests.test_scanner -v

⚑ Quick Examples - Real World Scenarios

# Scenario 1: Check a downloaded theme
python3 themeguard.py --path ~/Downloads/flavor/ --deep --report html

# Scenario 2: Monitor a theme folder for changes
python3 themeguard.py --path ~/Downloads/flavor/ --watch

# Scenario 3: Quick plugin check (Termux)
python3 themeguard.py --path /sdcard/Download/flavor/ --type plugin

# Scenario 4: CI/CD pipeline integration
python3 themeguard.py --path ./flavor/ --report sarif --severity high
# Exit code 0 = clean, 1 = high, 2 = critical

# Scenario 5: Full wp-content audit with network intel
python3 themeguard.py --path ~/Downloads/wp-content/ --type full --deep --network --report both

πŸ“‹ Scan Output

ThemeGuard produces triage-prioritized reports:

============================================================
  THEMEGUARD TRIAGE REPORT
============================================================
  Target:       ~/Downloads/flavor
  Scan time:    2.47s
  Files:        847
  Total finds:  12

  [!] IMMEDIATE ACTION REQUIRED - QUARANTINE
  ----------------------------------------
    functions.php:142
      eval(base64_decode(...)) with network callback
      Confidence: 95% | Severity: critical

  [?] MANUAL REVIEW RECOMMENDED
  ----------------------------------------
    includes/helper.php:89
      Dynamic function dispatch with user input
      Confidence: 62% | Severity: high

  CORRELATED THREATS (CAMPAIGNS)
  ----------------------------------------
    Same malicious URL in 3 files: http://evil.com/gate.php
      Files: functions.php, footer.php, admin.php

  RECOMMENDED NEXT STEPS
  ----------------------------------------
  1. Quarantine the files listed above IMMEDIATELY
  2. Check if the site has been compromised
  3. Reset all passwords and API keys
============================================================

πŸ§ͺ Tests

# Run all tests (68 tests)
python -m unittest tests.test_scanner tests.test_enterprise -v
Suite Tests Coverage
Core Scanner 14 Pattern engine, obfuscation, network, integrity
Enterprise 54 Dedup, scorer, decoder, classifier, correlation, evidence store, triage

πŸ“ Module Map

Module Purpose
pattern_engine.py Aho-Corasick + regex signature matching
threat_engine.py Custom .tgr rule engine
ml_classifier.py 26-feature statistical risk classifier
decoder_recursive.py 8-depth recursive payload decoder
correlation.py Cross-file campaign detection
scorer.py Confidence scoring with signal weights
deduper.py Finding dedup with stable IDs
evidence_store.py SQLite scan history & diff
cloud_intel.py URLhaus + WPScan API
wp_deep_scan.py WordPress hook/cron/REST analysis
php_deep_scan.py Taint flow, call graph, dead code
safe_io.py Robust I/O, regex DoS protection
watcher.py Real-time watch with debounce
quarantine.py SHA-256 verified quarantine/restore

Full list: 30 modules - see docs/architecture.md


πŸ”’ Security Properties

  • βœ… No eval() in analysis pipeline
  • βœ… Regex DoS protection (length + search limits)
  • βœ… Recursive decode depth limited (8 levels)
  • βœ… Decompression bomb protection
  • βœ… Symlink escape + path traversal protection
  • βœ… Quarantine hash verification on restore
  • βœ… Tamper detection in quarantine manifest
  • βœ… Atomic JSON writes (crash-safe)

πŸ“– Documentation

Document Description
architecture.md 5-phase pipeline, 30-module map, data flow
rule_format.md .tgr syntax, modifiers, conditions
known_limitations.md Honest coverage of all gaps

πŸ”’ Exit Codes

Code Meaning
0 Clean - no critical/high findings
1 High severity issues found
2 Critical threats detected

πŸ‘€ Author

Muhammad Abid (V3n0mSh3ll) Offensive Security Researcher β€’ AI Security β€’ Full-Stack Developer

GitHub


πŸ“„ License

MIT

About

WordPress threat detection engine. 30 scanning modules, 158 signatures, recursive payload decoding, ML risk scoring, cross-file correlation, real-time watch mode, and SQLite evidence store. Built for security researchers and WordPress administrators.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages