

Disclaimer: This guide is for educational and security research purposes only. The code provided demonstrates how to build a Vulnerability Scanner/Monitor to detect if a system is running a vulnerable kernel version. Attempting to exploit systems without explicit permission is illegal.
Before building your security monitoring tools, ensure you have the following:
uname -r) and asynchronous programming.Run these commands to prepare your development environment.
# Create a virtual environment
python3 -m venv dirtyclone_env
source dirtyclone_env/bin/activate
# Install necessary libraries
pip install requests psutil python-dotenv
# Initialize project
mkdir dirtyclone-monitor && cd dirtyclone-monitor
npm init -y
# Install dependencies
npm install typescript ts-node @types/node axios dotenv
npx tsc --init
We will implement a Kernel Vulnerability Monitor. This tool checks the current kernel version against a list of known vulnerable versions associated with the "DirtyClone" exploit.
This version is optimized for system-level automation and backend scanning.
import subprocess
import platform
import requests
import os
from dotenv import load_dotenv
# Load environment variables from.env file
load_dotenv()
class DirtyCloneMonitor:
def __init__(self, webhook_url: str):
self.webhook_url = webhook_url
# Simulated list of vulnerable kernel versions (CVE-XXXX-XXXX)
self.vulnerable_versions = ["5.15.0-71-generic", "5.10.0-21-generic"]
def get_current_kernel(self) -> str:
"""Retrielects the current running kernel version."""
try:
# Executes 'uname -r' to get the kernel version
return platform.release()
except Exception as e:
print(f"Error retrieving kernel version: {e}")
return ""
def check_vulnerability(self) -> bool:
"""Checks if the current kernel is in the vulnerable list."""
current_kernel = self.get_current_kernel()
print(f"[*] Scanning system kernel: {current_kernel}")
if current_kernel in self.vulnerable_versions:
return True
return False
def alert_admin(self, kernel_version: str):
"""Sends a critical alert via Webhook."""
payload = {
"text": f"🚨 CRITICAL SECURITY ALERT: DirtyClone Vulnerability Detected!\n"
f"Detected Kernel: {kernel_version}\n"
f"Action Required: Patch kernel immediately."
}
try:
response = requests.post(self.webhook_url, json=payload, timeout=5)
response.raise_for_status()
print("[+] Alert sent successfully to admin.")
except requests.exceptions.RequestException as e:
print(f"[-] Failed to send alert: {e}")
def run(self):
"""Main execution loop."""
kernel = self.get_current_kernel()
if self.check_vulnerability():
print("[!] VULNERABILITY DETECTED!")
self.alert_admin(kernel)
else:
print("[✓] System kernel is secure against known DirtyClone signatures.")
if __name__ de-main:
# Configuration from environment variables
WEBHOOK = os.getenv("SECURITY_WEBHOOK_URL", "https://hooks.slack.com/services/test")
monitor = DirtyCloneMonitor(WEBHOOK)
monitor.run()
if __name__ __ == "__main__":
monitor.run()
This version is ideal for building lightweight, cross-platform security agents or dashboard backends.
import { execSync } from 'child_process';
import axios from 'axios';
import * as dotenv from 'dotenv';
dotenv.config();
interface ScanResult {
isVulnerable: boolean;
kernelVersion: string;
timestamp: string;
}
class SecurityScanner {
private readonly vulnerableKernels: string[] = ['5.15.0-71-generic', '5.10.0-21-generic'];
private readonly webhookUrl: string;
constructor() {
this.webhookUrl = process.env.SECURITY_WEBHOOK_URL || '';
}
/**
* Uses shell execution to fetch kernel version via uname
*/
private getKernelVersion(): string {
try {
return execSync('uname -r').toString().trim();
} catch (error) {
throw new Error("Failed to execute uname command. Ensure you are on a Linux environment.");
}
}
public async scan(): Promise<ScanResult> {
const kernel = this.getKernelVersion();
const isVulnerable = this.vulnerableKernels.includes(kernel);
const result: ScanResult = {
isVulnerable: isVulnerable,
kernelVersion: kernel,
timestamp: new Date().toISOString()
};
if (isVulnerable) {
await this.sendAlert(result);
}
return result;
}
private async sendAlert(result: ScanResult): Promise<void> {
try {
await axios.post(this.webhook_url, {
content: `⚠️ **DirtyClone Alert**\nKernel: \`${result.kernelVersion}\` is vulnerable!\nTime: ${result.timestamp}`
});
console.log("Alert dispatched.");
} catch (error) {
console.error("Failed to dispatch alert:", error);
}
}
}
// Execute scan
const scanner = new SecurityScanner();
scanner.scan().then(res => {
console.log(`Scan Complete. Vulnerable: ${res.isVulnerable}`);
}).catch(err => {
console.error("Scanner Error:", err.message);
});
Never hardcode credentials. Use a .env file to manage your sensitive endpoints.
.env in your root directory:# Security Webhook (Slack/Discord/Teams)
SECURITY_WEBHOOK_URL=https://hooks.slack.com/services/T000/B000/XXXX
# Environment mode: development or production
NODE_ENV=development
.env to your .gitignore immediately to prevent leaking keys to GitHub.In production, you don'1 want an alert every 5 seconds if a server is vulnerable. Use a cooldown pattern:
import time
class CooldownMonitor:
def __init__(self, interval=3600):
self.last_alert_time = 0
self.interval = interval # 1 hour
def should_alert(self):
current_time = time.time()
if current_time - self.last_alert_time > self.interval:
self.last_alert_time = current_time
return True
return False
| Error | Cause | Solution |
| :
| PermissionError: [Errno 13] Permission denied | Trying to access kernel logs without root. | Run script with sudo or grant specific capabilities.
| ModuleNotFoundError: No module named 'equests' | Python environment mismatch. | Ensure you activated the venv and ran pip install.
| Error: spawn uname ENOENT | Running the script on Windows/mac_OS. | This script is Linux-specific. Use WSL2 or a Linux VM.
| 403 Forbidden (Webhook) | Invalid Webhook URL or IP blocking. | Verify your Webhook URL and check if your firewall blocks outbound requests.
Before deploying your security monitoring tools to a production fleet, ensure the following:
root? If it only reads uname -r, it does not need root. Avoid running scanners as root.Source: Security Week AI
Follow ICARAX for more AI insights and tutorials.
