Operator On The Wire
Join
← Back to Knowledge Base
BLUE TEAM / THREAT HUNT / LINUX / MALWARE

Webshell on Linux

This note documents detection patterns related to Webshell on Linux on Linux systems.


Direct Indicators

SourceGrep Pattern / ArtifactMeaningForensic ValueNotes
Web rootsystem(Command execution functionCriticalClassic PHP webshell indicator.
Web rootexec(Command executionCriticalCommon shell primitive.
Web rootshell_exec(Command executionCriticalStrong PHP shell signal.
Web rootpassthru(Raw command outputCriticalFrequent webshell primitive.
Web rootbase64_decode(Obfuscated payload logicCriticalVery common concealment pattern.
Web rooteval(Dynamic code executionCriticalOften chained with obfuscation.
Web rootassert(Alternate code executionHighCommon in stealth shells.
Web rootpreg_replace /eLegacy execution primitiveHighSeen in older shells.
Web rootcmd= parameter handlingInteractive shell parameterCriticalDirect webshell logic.
File timestampsrecently modified web fileShell insertion timingCriticalTimeline anchor.
Access logssuspicious POST/GET with command paramsWebshell usageCriticalRuntime evidence.
Error logsshell execution errorsRuntime clueHighUseful when shell malformed.
auditdweb process writing web rootFile write attributionCriticalBest attribution if enabled.
Process treeweb process spawning shellRuntime executionCriticalStrong compromise signal.

Indirect Indicators

IndicatorWhat To Look ForForensic ValueNotes
Tiny PHP file recently createdMinimal shell dropperCriticalCommon attacker pattern.
Legitimate page modified subtlyShell inserted into existing fileCriticalHarder to spot than new file.
Obfuscated one-linerEncoded payloadCriticalCommon stealth pattern.
Web request followed by shell spawnActive exploitationCriticalStrong runtime correlation.
File name mimics assetcache.php, db.php, img.phpHighCamouflage pattern.
Shell under upload dirUpload abuseCriticalVery common compromise route.
Multiple similar shell copiesRedundant access pathsHighOperator resilience.
Shell plus reverse shell commandFull operator pivotCriticalStrong intrusion chain.
Access from rare IPOperator accessHighUseful context.
Webshell plus temp payloadStage-to-shell chainCriticalCommon escalation path.

Common Tools

ToolUsage
Minimal PHP one-linersFast shell drop.
Obfuscated PHP shellsConcealed access.
Uploaded webshell kitsInteractive file managers / shells.
Existing page injectionHide shell in legit file.

Relevant Artifacts

ArtifactPath / CommandForensic ValueNotes
Web root/var/www, app directoriesCriticalPrimary shell location.
Access logsweb server access logsCriticalUsage evidence.
Error logsweb server error logsHighExecution clues.
File metadatastatCriticalTimeline truth.
File diffcompare with baselineCriticalDetect subtle injection.
Process treeweb process childrenCriticalRuntime shell proof.
Audit logs/var/log/audit/audit.logCriticalFile write attribution.
Temp paths/tmp, /dev/shmHighFollow-on payload staging.

MITRE ATT&CK References

  • T1505 Server Software Component
  • T1505.003 Web Shell
  • T1059 Command and Scripting Interpreter

Decision Tree

  1. Is suspicious server-side code present?

    • Search web roots for execution primitives.
  2. Is file new or modified?

    • Compare timestamps and baseline.
  3. Was shell accessed?

    • Inspect access logs and parameters.
  4. Did shell spawn OS commands?

    • Process tree, temp payloads, outbound sockets.
  5. Is persistence linked?

    • Cron, services, keys, startup.
  6. Pivot

    • File → code review.
    • Request → source IP.
    • Timestamp → intrusion chain.
  7. Confirm webshell

    • Execution primitive + suspicious access + runtime shell = strong webshell finding.

Example Detection Templates

Grep

grep -R "system(\|exec(\|shell_exec(\|passthru(\|base64_decode(\|eval(" /var/www 2>/dev/null
grep -R "cmd=\|assert(\|preg_replace" /var/www 2>/dev/null
find /var/www -type f -printf '%TY-%Tm-%Td %TT %p\n' 2>/dev/null | sort

Journalctl

journalctl | grep -E "apache|nginx|php"

File Inspection

find /var/www -type f -name "*.php" 2>/dev/null
stat suspicious.php

Sigma

title: Linux Webshell Indicators
id: linux-webshell-indicators
status: experimental
description: Detects suspicious server-side code patterns associated with webshells
logsource:
  product: linux
detection:
  selection_keywords:
    message|contains:
      - 'system('
      - 'exec('
      - 'shell_exec('
      - 'base64_decode('
  condition: selection_keywords
fields:
  - message
  - hostname
falsepositives:
  - Legitimate application code
level: high
tags:
  - attack.persistence
  - attack.t1505.003

Mitigation & Hardening

Control AreaMitigationEffectivenessNotes
File baselineBaseline web rootsCriticalUnknown file changes should stand out.
Upload controlsRestrict executable uploadsCriticalMajor prevention layer.
File monitoringWatch web root writesCriticalStrong invariant detection.
Least privilegeRestrict web process write rightsCriticalBlocks shell planting.
AuditdMonitor web root writesHighStrong attribution.
Web loggingPreserve access/error logsHighNeeded for shell use proof.

Fast Triage Checks

QuestionCommand / ArtifactWhy It Matters
Any execution primitives in web root?grep web rootImmediate shell check.
Which file changed recently?sort timestampsTimeline anchor.
Was shell accessed?access logsRuntime proof.
Did web process spawn shell?process treeStrong execution evidence.
Is temp payload linked?inspect temp dirsFollow-on staging.
Any outbound callback?sockets / logsOperator pivot clue.

High Value Grep Strings

PatternWhy It Matters
system(Core command execution primitive.
exec(Command execution.
shell_exec(Shell execution.
passthru(Raw output execution.
base64_decode(Obfuscation clue.
eval(Dynamic execution.
cmd=Interactive shell parameter.

Analyst Notes

ScenarioInterpretation
Tiny new PHP fileVery common shell drop.
Legit page slightly modifiedHidden shell insertion likely.
Webshell plus temp payloadOperator escalated beyond web layer.
Access log with cmd parameterDirect shell use evidence.
Web process spawns bashStrong runtime shell proof.
Multiple obfuscated copiesRedundant persistence.