Analyzing Persistence Mechanisms in Linux
Overview
Adversaries establish persistence on Linux systems through crontab jobs, systemd service/timer units, LD_PRELOAD library injection, shell profile modifications (.bashrc, .profile), SSH authorized_keys backdoors, and init script manipulation. This skill scans for all known persistence vectors, checks file timestamps and integrity, and correlates findings with auditd logs to build a timeline of persistence installation.
When to Use
Trigger phrases:
"analyzing persistence mechanisms in linux"
"Detect and analyze Linux persistence mechanisms including crontab entries, syste"
When investigating security incidents that require analyzing persistence mechanisms in linux
When building detection rules or threat hunting queries for this domain
When SOC analysts need structured procedures for this analysis type
When validating security monitoring coverage for related attack techniques
Prerequisites
- Root or sudo access on target Linux system (or forensic image)
- auditd configured with file watch rules on persistence paths
- Python 3.8+ with standard library (os, subprocess, json)
- Optional: OSSEC/Wazuh agent for file integrity monitoring alerts
Steps
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Scan Crontab Entries — Enumerate all user crontabs, /etc/cron.d/, /etc/cron.daily/, and anacron jobs for suspicious commands
- Audit Systemd Units — Check /etc/systemd/system/ and ~/.config/systemd/user/ for non-package-managed service and timer units
- Detect LD_PRELOAD Hijacking — Check /etc/ld.so.preload and LD_PRELOAD environment variable for injected shared libraries
- Inspect Shell Profiles — Scan .bashrc, .bash_profile, .profile, /etc/profile.d/ for injected commands or reverse shells
- Check SSH Authorized Keys — Audit all authorized_keys files for unauthorized public keys with command restrictions
- Correlate Auditd Logs — Search auditd logs for file modification events on persistence paths to build an installation timeline
- Generate Persistence Report — Produce a risk-scored report of all discovered persistence mechanisms
Expected Output
- JSON report of all persistence mechanisms found with risk scores
- Timeline of persistence installation from auditd correlation
- MITRE ATT&CK technique mapping (T1053, T1543, T1574, T1546)
- Remediation commands for each detected persistence mechanism
When NOT to Use
- You need to perform the attack, not analyze it (use performing-* skills)
- Task is about detection, not analysis (use detecting-* skills)
- You need to implement controls (use implementing-* skills)
- Task is about threat hunting, not post-incident analysis (use hunting-* skills)
- You don't have access to the artifacts/logs to analyze
- Task requires real-time monitoring (use SOC tools)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Sharing sensitive findings or credentials in unencrypted communications
- Failing to properly scope and contain the assessment before starting
Process
- Scope — Define research questions, identify data sources, set time boundaries
- Gather — Collect data from primary sources, APIs, and public records
- Synthesize — Analyze findings, identify patterns, produce actionable report
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Results validated against known-good baselines or reference implementations
- Documentation complete enough for another analyst to reproduce findings
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: analyzing-persistence-mechanisms-in-linux3description: Use when detect and analyze Linux persistence mechanisms including crontab4 entries, systemd service units, LD_PRELOAD hijacking, bashrc modifications, and5 authorized_keys backdoors using auditd and file integrity monitoring. Use when detecting6 and analyze linux persistence mechanisms including crontab entries, systemd.7domain: cybersecurity8subdomain: threat-hunting9tags:10- linux-persistence11- crontab12- systemd13- ld-preload14- auditd15- threat-hunting16- incident-response17mitre_attack:18- T1053.00319- T1543.00220- T1574.00621- T1546.00422version: '1.0'23author: oyi7724license: Apache-2.025d3fend_techniques:26- Executable Denylisting27- Execution Isolation28- File Metadata Consistency Validation29- Process Termination30- Content Format Conversion31nist_csf:32- DE.CM-0133- DE.AE-0234- DE.AE-0735- ID.RA-0536category: cybersecurity37metadata:38 source: https://skillmd.com/skills/oyi77/analyzing-persistence-mechanisms-in-linux39---404142# Analyzing Persistence Mechanisms in Linux4344## Overview4546Adversaries establish persistence on Linux systems through crontab jobs, systemd service/timer units, LD_PRELOAD library injection, shell profile modifications (.bashrc, .profile), SSH authorized_keys backdoors, and init script manipulation. This skill scans for all known persistence vectors, checks file timestamps and integrity, and correlates findings with auditd logs to build a timeline of persistence installation.474849## When to Use50**Trigger phrases:**51- "analyzing persistence mechanisms in linux"52- "Detect and analyze Linux persistence mechanisms including crontab entries, syste"535455- When investigating security incidents that require analyzing persistence mechanisms in linux56- When building detection rules or threat hunting queries for this domain57- When SOC analysts need structured procedures for this analysis type58- When validating security monitoring coverage for related attack techniques5960## Prerequisites6162- Root or sudo access on target Linux system (or forensic image)63- auditd configured with file watch rules on persistence paths64- Python 3.8+ with standard library (os, subprocess, json)65- Optional: OSSEC/Wazuh agent for file integrity monitoring alerts6667## Steps6869```python70# Example: IOC detection71import re7273IOC_PATTERNS = {74 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",75 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",76 "hash_md5": r"\b[a-f0-9]{32}\b",77 "hash_sha256": r"\b[a-f0-9]{64}\b",78}7980def extract_iocs(text: str) -> dict:81 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}82```83841. **Scan Crontab Entries** — Enumerate all user crontabs, /etc/cron.d/, /etc/cron.daily/, and anacron jobs for suspicious commands852. **Audit Systemd Units** — Check /etc/systemd/system/ and ~/.config/systemd/user/ for non-package-managed service and timer units863. **Detect LD_PRELOAD Hijacking** — Check /etc/ld.so.preload and LD_PRELOAD environment variable for injected shared libraries874. **Inspect Shell Profiles** — Scan .bashrc, .bash_profile, .profile, /etc/profile.d/ for injected commands or reverse shells885. **Check SSH Authorized Keys** — Audit all authorized_keys files for unauthorized public keys with command restrictions896. **Correlate Auditd Logs** — Search auditd logs for file modification events on persistence paths to build an installation timeline907. **Generate Persistence Report** — Produce a risk-scored report of all discovered persistence mechanisms9192## Expected Output9394- JSON report of all persistence mechanisms found with risk scores95- Timeline of persistence installation from auditd correlation96- MITRE ATT&CK technique mapping (T1053, T1543, T1574, T1546)97- Remediation commands for each detected persistence mechanism98## When NOT to Use99100- You need to perform the attack, not analyze it (use performing-* skills)101- Task is about detection, not analysis (use detecting-* skills)102- You need to implement controls (use implementing-* skills)103- Task is about threat hunting, not post-incident analysis (use hunting-* skills)104- You don't have access to the artifacts/logs to analyze105- Task requires real-time monitoring (use SOC tools)106107108## Red Flags109110- Performing actions without explicit written authorization from the asset owner111- Testing against production systems without a defined scope and rules of engagement112- Sharing sensitive findings or credentials in unencrypted communications113- Failing to properly scope and contain the assessment before starting114115## Process1161171. **Scope** — Define research questions, identify data sources, set time boundaries1181. **Gather** — Collect data from primary sources, APIs, and public records1191. **Synthesize** — Analyze findings, identify patterns, produce actionable report120121## Verification122123- All steps executed successfully against a test environment before production use124- Output documented with screenshots or logs demonstrating expected behavior125- Results validated against known-good baselines or reference implementations126- Documentation complete enough for another analyst to reproduce findings127128## Anti-Rationalization Table129130| Rationalization | Reality |131|---|---|132| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |133| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |134| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |