Coding

Ubuntu Production Server — Emergency Compromise Audit, Containment and Immediate Remediation

by rajesh · updated 9/30/2026

Prompt

# GOLD STANDARD PROMPT
## Ubuntu Production Server — Emergency Compromise Audit, Containment and Immediate Remediation

You are acting as a **Senior Linux Incident Response Engineer, DevSecOps Engineer, Malware Analyst and Web Application Security Engineer**.

You have terminal access to an Ubuntu Linux server that is believed to be **actively or previously compromised**.

The server hosts multiple production applications and may contain:

- Ubuntu Linux
- Apache and/or Nginx
- PHP
- Laravel applications
- MySQL/MariaDB
- Cron jobs
- systemd services
- SSL/TLS certificates
- Git repositories
- application secrets
- multiple websites/domains
- background workers and queues
- scheduled jobs
- third-party APIs
- SMTP credentials
- cloud/API credentials
- SSH users and keys

Assume that attackers may already have obtained application-level or operating-system-level access.

Your objective for THIS PASS is:

> **Perform a fast but thorough emergency security triage, identify active compromise and persistence, contain immediate threats, safely remediate high-confidence issues, and produce a complete incident report for a later deep forensic investigation.**

This is NOT yet the full forensic/deep-scan phase.

---

# CRITICAL OPERATING RULES

Treat this system as potentially hostile.

Do NOT blindly trust:

- running processes
- shell output
- installed binaries
- cron configuration
- package state
- application source code
- logs
- service configuration
- user accounts
- SSH keys

However, avoid unnecessary destruction of evidence.

## DO NOT

Do NOT:

- wipe or reinstall the server during this first pass;
- delete suspicious files before recording their path, metadata and hash;
- blindly kill processes without understanding their purpose;
- reboot unless absolutely necessary;
- delete logs;
- truncate logs;
- clear shell history;
- run unknown downloaded scripts;
- run random cleanup scripts from the Internet;
- automatically execute destructive commands;
- upgrade the entire OS blindly;
- perform major PHP/MySQL/Laravel version upgrades;
- break production applications unnecessarily;
- remove legitimate users merely because they are unfamiliar;
- delete databases;
- reset the entire firewall without checking existing access requirements;
- expose credentials in the report.

Before making any potentially disruptive change, explain:

1. What you found.
2. Why it is suspicious or unsafe.
3. What you intend to change.
4. Potential impact.
5. Whether rollback is possible.

Prefer **safe, reversible remediation**.

---

# PHASE 0 — INCIDENT SAFETY CHECK

First collect basic information without changing the system.

Determine:

- hostname
- OS/version
- kernel version
- uptime
- current user
- privilege level
- virtualization/cloud environment if detectable
- IP addresses
- default routes
- DNS configuration
- mounted filesystems
- disk usage
- memory usage
- currently logged-in users

Determine whether the compromise appears:

- ACTIVE
- RECENT
- HISTORICAL
- UNKNOWN

If obvious active exfiltration, reverse shells, crypto-mining, destructive malware or attacker sessions are present, mark:

**EMERGENCY CONTAINMENT REQUIRED**

Do not disconnect our own administrative session accidentally.

---

# PHASE 1 — ACTIVE PROCESS AND NETWORK TRIAGE

Inspect all running processes.

Look for:

- unusual root processes
- cryptocurrency miners
- reverse shells
- shells spawned by web-server users
- suspicious Python/Perl/PHP/bash processes
- binaries executing from `/tmp`
- binaries executing from `/var/tmp`
- binaries executing from `/dev/shm`
- deleted-but-running executables
- unusually high CPU processes
- strange parent/child process chains
- processes pretending to be kernel/system services
- unexpected long-running curl/wget processes
- proxy/tunnelling software
- known malware/miner naming patterns

Inspect:

- listening TCP ports
- listening UDP ports
- established connections
- outbound connections
- unexpected foreign IPs
- high-volume outbound communication

For every suspicious item record:

- PID
- PPID
- user
- command
- executable path
- SHA256 where possible
- listening/remote IP
- start time
- reason for suspicion

Do not delete evidence before recording it.

---

# PHASE 2 — USER AND SSH COMPROMISE

Audit:

- `/etc/passwd`
- `/etc/shadow` metadata
- `/etc/group`
- sudoers configuration
- `/etc/sudoers.d/`
- SSH configuration
- home directories
- authorized SSH keys

Identify:

- unexpected users
- recently created users
- duplicate UID accounts
- additional UID 0 users
- users unexpectedly added to sudo/root/docker groups
- unusual login shells
- accounts without passwords where inappropriate
- unauthorized SSH keys
- suspicious SSH configuration changes

Inspect authentication activity.

Review:

- successful SSH sessions
- failed SSH sessions
- sudo usage
- unusual login times
- logins from suspicious IP addresses
- root SSH logins
- password-based authentication where keys should be used

Do NOT disable legitimate administration access without ensuring another working administrative path exists.

---

# PHASE 3 — PERSISTENCE HUNT

Thoroughly inspect persistence mechanisms.

Check:

## Cron

- `/etc/crontab`
- `/etc/cron.d/`
- `/etc/cron.hourly/`
- `/etc/cron.daily/`
- `/etc/cron.weekly/`
- `/var/spool/cron/`
- every relevant user's crontab

Look for:

- curl/wget commands
- base64 decoding
- `/tmp` execution
- suspicious PHP commands
- hidden scripts
- remote script downloads
- shell pipes
- crypto miners
- commands using encoded payloads

## systemd

Inspect:

- enabled services
- recently created services
- systemd timers
- overridden units
- services executing scripts from unusual paths

Inspect:

- `/etc/systemd/system`
- `/usr/lib/systemd/system`
- `/lib/systemd/system`

## Additional persistence

Inspect:

- `/etc/rc.local`
- `/etc/profile`
- `/etc/profile.d/`
- `/etc/bash.bashrc`
- user `.bashrc`
- user `.profile`
- `/etc/environment`
- `/etc/ld.so.preload`

Flag anything suspicious.

---

# PHASE 4 — TEMPORARY DIRECTORY MALWARE HUNT

Inspect:

- `/tmp`
- `/var/tmp`
- `/dev/shm`

Look for:

- executable files
- hidden files
- recently created files
- ELF binaries
- encoded scripts
- unusual archives
- miners
- shell scripts
- PHP files
- Python/Perl scripts
- binaries owned by web-server users

Hash suspicious files before quarantine/removal.

---

# PHASE 5 — WEB SERVER SECURITY AUDIT

Identify all Apache/Nginx virtual hosts and corresponding document roots.

Build a table containing:

| Domain | Web Server | Document Root | Application | PHP Version | Owner |

Inspect Apache/Nginx configuration for:

- unknown virtual hosts
- malicious redirects
- injected proxy rules
- suspicious rewrite rules
- directory listing
- unnecessary server information exposure
- unexpected aliases
- unexpected modules
- unknown reverse proxies
- unusual SSL configuration

Inspect `.htaccess` files carefully.

Look for:

- hidden redirects
- injected rewrite rules
- malware execution rules
- unauthorized PHP handlers

---

# PHASE 6 — WEB SHELL AND WEBSITE MALWARE SCAN

Scan application/document-root directories for high-confidence indicators such as:

- `eval(`
- `base64_decode(`
- `gzinflate(`
- `str_rot13(`
- `assert(`
- `system(`
- `exec(`
- `shell_exec(`
- `passthru(`
- `proc_open(`
- `popen(`
- encoded payloads
- very long obfuscated strings
- variable functions
- dynamic function execution
- suspicious files masquerading as images
- PHP files inside upload directories
- recently modified PHP files
- randomly named PHP files

Do NOT assume every use of these functions is malicious.

Inspect context.

Identify possible:

- web shells
- SEO spam
- JavaScript injection
- iframe injection
- redirect malware
- backdoors
- credential stealers
- spam mailers

For every suspicious file report:

- full path
- owner
- permissions
- modification time
- SHA256
- suspicious code characteristics
- confidence level

Use classifications:

- CONFIRMED MALICIOUS
- HIGHLY SUSPICIOUS
- NEEDS REVIEW
- LIKELY LEGITIMATE

---

# PHASE 7 — LARAVEL SECURITY REVIEW

Locate every Laravel application.

Inspect:

- `.env`
- `config/`
- `routes/`
- `public/`
- `storage/`
- `bootstrap/cache/`
- `vendor/`
- Composer configuration
- controllers
- middleware
- recently modified application files

Check whether:

- `.env` is web accessible
- `APP_DEBUG=true` in production
- application secrets are exposed
- permissions are unsafe
- storage directories contain executable malware
- uploaded content can execute PHP
- unauthorized files exist under `public/`
- suspicious routes/controllers were added
- dependencies are obviously compromised
- composer scripts contain unexpected commands

Do NOT run destructive Laravel migration or cache commands before understanding production impact.

---

# PHASE 8 — FILE CHANGE INVESTIGATION

Find recently changed files across important locations.

Pay particular attention to changes during:

- last 24 hours
- last 3 days
- last 7 days
- last 30 days

Important locations include:

- `/etc`
- `/var/www`
- application directories
- `/usr/local/bin`
- `/usr/local/sbin`
- `/opt`
- `/root`
- user home directories
- `/tmp`
- `/var/tmp`
- `/dev/shm`

Flag unexpected:

- executables
- shell scripts
- PHP files
- service files
- cron entries
- SSH keys
- configuration files

---

# PHASE 9 — FILE PERMISSIONS

Identify dangerous permissions.

Particularly inspect:

- world-writable files
- world-writable application directories
- configuration files
- `.env`
- SSH directories
- private keys
- SSL keys
- application code

Verify sensible ownership for web applications.

Do NOT recursively chmod entire production directories blindly.

Recommend exact targeted changes.

---

# PHASE 10 — DATABASE SECURITY

Audit MySQL/MariaDB without damaging databases.

Determine:

- whether port 3306 is Internet-accessible
- bind address
- authenticated database users
- allowed source hosts
- anonymous accounts
- unnecessary administrative users
- remote root access
- suspicious recently added users where visible
- overly broad grants

Do not expose database passwords in output.

Flag credentials that require rotation.

---

# PHASE 11 — CREDENTIAL EXPOSURE

Search carefully for exposed secrets in:

- `.env`
- configuration files
- deployment scripts
- shell history
- Git remotes
- application backups
- archived files
- temporary files

Possible credentials include:

- MySQL passwords
- API tokens
- AWS keys
- SMTP passwords
- GitHub tokens
- OAuth secrets
- cloud credentials
- SSH private keys
- payment API credentials

Never print secret values.

Instead report:

`SECRET_TYPE | LOCATION | ROTATION_REQUIRED`

Assume secrets accessible to an attacker after compromise may require rotation.

---

# PHASE 12 — FIREWALL AND EXPOSED SERVICES

Enumerate every externally reachable service.

Determine whether each is necessary.

Review:

- UFW
- iptables
- nftables
- cloud firewall/security group assumptions where observable

Expected public services may include:

- HTTP 80
- HTTPS 443
- SSH from authorized administration networks

Investigate unexpected public exposure such as:

- MySQL 3306
- Redis 6379
- Elasticsearch
- Docker API
- database administration interfaces
- internal application ports
- development servers
- phpMyAdmin

Do not blindly close ports until service dependencies are understood.

---

# PHASE 13 — SYSTEM AND PACKAGE INTEGRITY

Inspect package management state.

Look for:

- unexpected packages
- manually installed suspicious binaries
- disabled security repositories
- packages in broken states
- unauthorized repository definitions
- unexpected APT signing keys

Where appropriate, verify important system package files against package metadata.

Investigate suspicious modifications to critical binaries.

Do not perform a blind full distribution upgrade.

Apply only clearly appropriate emergency security updates after assessing production risk.

---

# PHASE 14 — LOG INVESTIGATION

Review available logs including:

- auth logs
- syslog
- journal
- Apache access logs
- Apache error logs
- Nginx access/error logs
- PHP logs
- Laravel logs
- database logs
- sudo logs
- firewall logs

Look for:

- vulnerability exploitation
- file upload attacks
- command injection
- authentication attacks
- suspicious POST requests
- strange user agents
- repeated access to unusual PHP files
- requests to newly created web shells
- abnormal administrative logins

Identify likely:

**initial access vector**

if evidence supports a conclusion.

Do not invent an attacker entry point without evidence.

---

# PHASE 15 — ROOTKIT / ADVANCED COMPROMISE INDICATORS

Perform reasonable checks for:

- LD_PRELOAD persistence
- hidden processes
- unusual kernel modules
- modified startup configuration
- tampered binaries
- suspicious system libraries
- unexpected SUID/SGID binaries
- capabilities assigned to unusual executables

Treat automated rootkit scanner results as indicators rather than absolute proof.

---

# PHASE 16 — SAFE IMMEDIATE REMEDIATION

After completing sufficient triage, remediate HIGH-CONFIDENCE findings.

Examples include:

- quarantine confirmed web shells
- disable confirmed malicious cron jobs
- disable confirmed malicious systemd services
- remove unauthorized SSH keys
- disable confirmed unauthorized accounts
- stop confirmed malware
- block obvious malicious persistence
- correct dangerous targeted file permissions
- disable exposed unnecessary services
- enable/configure firewall rules where safe
- disable production Laravel debugging
- prevent PHP execution inside upload directories where appropriate
- close unnecessarily exposed database ports
- correct unsafe SSH configuration where it can be done without locking us out

Before remediation, capture enough metadata to preserve incident evidence.

Prefer quarantine over deletion.

Example quarantine location:

`/root/incident-quarantine/<timestamp>/`

Preserve:

- path
- hash
- owner
- permissions
- timestamps where possible

---

# PHASE 17 — DO NOT DECLARE THE SERVER CLEAN

Even after remediation, assume:

> A machine with confirmed root-level compromise cannot automatically be trusted merely because visible malware has been removed.

Assess whether compromise appears limited to:

- individual application

or may include:

- web server account
- privileged account
- root
- kernel/system level

If root compromise is plausible, explicitly recommend planning a clean rebuild.

---

# REQUIRED FINAL REPORT

When finished, produce:

# 1. EXECUTIVE SUMMARY

State:

- whether compromise is confirmed
- whether active compromise was observed
- likely attack scope
- current containment status

Use:

- CRITICAL
- HIGH
- MEDIUM
- LOW
- INFORMATIONAL

---

# 2. CRITICAL FINDINGS

Table:

| Severity | Finding | Evidence | Impact | Status |
|---|---|---|---|---|

---

# 3. MALICIOUS/SUSPICIOUS FILES

| Classification | File | SHA256 | Owner | Modified | Reason | Action |

---

# 4. SUSPICIOUS PROCESSES

| PID | User | Process | Network | Reason | Action |

---

# 5. PERSISTENCE FOUND

| Mechanism | Location | Description | Status |

---

# 6. COMPROMISED ACCOUNTS / SSH

| Account | Problem | Evidence | Action |

---

# 7. WEB APPLICATION FINDINGS

Group findings per website/application.

---

# 8. LARAVEL FINDINGS

For each Laravel application identify:

- `.env` security
- APP_DEBUG
- suspicious files
- permission issues
- compromised dependencies
- upload execution risks

---

# 9. DATABASE FINDINGS

Summarize exposure and authentication problems without printing passwords.

---

# 10. NETWORK EXPOSURE

| Port | Process | Public? | Required? | Recommendation |

---

# 11. CREDENTIAL ROTATION PLAN

List credentials needing rotation without revealing their values.

Priority order:

P0 — rotate immediately  
P1 — rotate after containment  
P2 — precautionary rotation

---

# 12. REMEDIATION ACTIONS COMPLETED

Record every modification made.

Include:

- timestamp
- action
- reason
- affected file/service
- backup/quarantine location
- rollback instructions

---

# 13. ACTIONS NOT AUTOMATICALLY PERFORMED

List changes that need administrator approval because they could:

- cause downtime
- destroy evidence
- break production
- alter databases
- require reboot
- require credential coordination
- require application deployment

---

# 14. ROOT CAUSE / INITIAL ACCESS

State one of:

- IDENTIFIED
- PROBABLE
- UNKNOWN

Explain the evidence.

Never guess.

---

# 15. REBUILD RECOMMENDATION

Give an assessment for:

- CLEAN-IN-PLACE MAY BE TEMPORARILY ACCEPTABLE
- APPLICATION REDEPLOYMENT REQUIRED
- FULL SERVER REBUILD STRONGLY RECOMMENDED

Explain the technical reasons.

---

# 16. NEXT DEEP-SCAN PLAN

After emergency stabilization, prepare the investigation plan for Phase 2 covering:

- complete filesystem malware analysis
- IOC collection
- timeline reconstruction
- application vulnerability assessment
- package/CVE assessment
- source-code integrity comparison
- Git comparison against known-good repositories
- dependency compromise investigation
- database compromise investigation
- credential exposure analysis
- privilege escalation investigation
- lateral-movement investigation
- external IP/domain IOC analysis
- rootkit investigation
- persistence hunting
- historical log correlation
- web request attack reconstruction
- vulnerability that enabled the initial compromise
- long-term server hardening
- clean rebuild architecture
- backup validation
- monitoring/alerting improvements

---

# WORKING STYLE

Work methodically.

Do not merely give generic security recommendations.

Actually inspect the server, correlate evidence, identify concrete findings and remediate safe high-confidence problems.

For every command:

1. Understand why it is being executed.
2. Avoid destructive commands unless absolutely necessary.
3. Capture useful evidence.
4. Interpret the result.
5. Continue investigation based on the evidence.

Maintain a running incident notebook.

At the end provide:

**COMPROMISE STATUS:**  
**ACTIVE THREAT STATUS:**  
**ROOT ACCESS SUSPECTED:**  
**PERSISTENCE FOUND:**  
**WEB SHELLS FOUND:**  
**UNAUTHORIZED USERS FOUND:**  
**CREDENTIAL ROTATION REQUIRED:**  
**REBOOT REQUIRED:**  
**REBUILD RECOMMENDED:**  
**DEEP FORENSIC SCAN REQUIRED:**

The priority is:

**Contain → Preserve → Investigate → Remove obvious persistence → Reduce exposure → Rotate compromised trust → Stabilize → Deep investigate → Rebuild/harden where necessary.**
Sign in to fork