Skip to content

Advanced Web Shell Hunting, Memory Injection & Systemd Persistence Purge

Density:

Conducts exhaustive hunting for fileless and obfuscated web shells (PHP, JSP, ASPX, Python), identifies systemd service and timer persistence implants, terminates rogue worker processes, and applies immutable kernel filesystem attributes.

  • ๐Ÿ› ๏ธ YARA
  • ๐Ÿ› ๏ธ auditd
  • ๐Ÿ› ๏ธ chattr
  • ๐Ÿ› ๏ธ systemctl
  • ๐Ÿ› ๏ธ find
  1. Scan web root with comprehensive YARA rules and find recently altered executables
    Terminal window
    # Scan web root with YARA webshell repository
    yara -r /opt/rules/webshells.yar /var/www/html/ > /evidence/yara_hits.txt
    # Identify anomalous scripts modified in last 72h
    find /var/www/ -type f \( -name "*.php" -o -name "*.jsp" -o -name "*.phtml" \) -mtime -3 -ls >> /evidence/recent_scripts.txt
    Artifacts Preserved: Matched webshell files, File alteration timestamps
  1. Audit and purge rogue systemd services, timers, and crontab hooks
    Terminal window
    # Audit anomalous systemd unit files
    ls -lat /etc/systemd/system/ /lib/systemd/system/ | grep -v 'total'
    # Check user and system crontabs
    for u in $(cut -f1 -d: /etc/passwd); do crontab -u $u -l 2>/dev/null | grep -v '^#' && echo "User: $u"; done
    # Remove identified persistent dropper
    systemctl stop malicious_backdoor.service 2>/dev/null || true
    systemctl disable malicious_backdoor.service 2>/dev/null || true
    rm -f /etc/systemd/system/malicious_backdoor.service
    systemctl daemon-reload
    Artifacts Preserved: Malicious .service unit files, Crontab dumps
  1. Set immutable attribute on web server directories to prevent dropper re-creation
    Terminal window
    chattr -R +i /var/www/html/wp-includes/ /var/www/html/vendor/ 2>/dev/null || true
    lsattr -d /var/www/html/wp-includes/
    Artifacts Preserved: Filesystem attribute state

Webshell Scanner Verification

Inspection Method:

Terminal window
yara -r /opt/rules/webshells.yar /var/www/html/

Success Criteria: Zero rule matches detected in web directory.

Process Tree Validation

Inspection Method:

Terminal window
ps aux | grep -E 'sh|bash|nc|socat|python' | grep www-data

Success Criteria: No spawned shells or network listeners attached to web worker processes.

  • ๐Ÿ”’ Mount web upload directories with noexec, nosuid options.
  • ๐Ÿ”’ Harden PHP configuration with disable_functions=exec,passthru,shell_exec,system,proc_open,popen.
  • ๐Ÿ”’ Deploy WAF rules blocking suspicious multipart/form-data upload signatures.