Why a cleaned site gets infected again
What an intrusion usually leaves behind
wp-config.php or a .env file, they now have the database password and possibly API keys or SMTP credentials. Deleting the webshell doesn't revoke any of that.
Capture evidence before you clean
BASH
mkdir -p /root/ir-notes
ps auxf > /root/ir-notes/processes.txt
ss -tunap > /root/ir-notes/sockets.txt
last -F > /root/ir-notes/logins.txt
lastb -F > /root/ir-notes/failed-logins.txt 2>/dev/nullFind the entry point, not only the payload
BASH
find /home/*/public_html -type f -name '*.php' -ctime -14 -printf '%CY-%Cm-%Cd %CH:%CM %p
' | sorttouch so their file looks as old as its neighbours. Ordinary tools cannot set ctime directly, so it usually reflects when the file actually appeared or changed. Adjust the path for your layout. A file in an uploads folder, or a core file changed outside any update window, is worth a closer look.
Once you have a suspicious file and its time, go to the web server access logs around that time and look at which scripts received POST requests. Webshells are typically driven by POST, and a PHP file that suddenly receives many POSTs from a few IPs stands out.
BASH
awk '6 ~ /POST/ {print7}' /path/to/access.log | grep -i 'php' | sort | uniq -c | sort -rn | head -20- Patch or remove the vulnerable component.
- Rotate every credential the attacker could have read, including database passwords, CMS admin accounts, application secrets, API keys, and SSH keys.
- Restore clean files, or rebuild from known-good sources.
- Watch the logs for the same pattern over the following days.
