What Is a Web Shell? 7 Ways to Find One Hiding on Your Website (PHP and JSP)
A web shell is a small program file that an attacker quietly uploads to a web server. With it, the attacker can run commands through a browser, upload or delete files and pull data out of the database. PHP sites usually get .php web shells; Java (Tomcat) servers get .jsp ones.
How do web shells get in?
- A file upload form that accepts .php or .jsp files
- Flaws in the server software itself, such as PHP2Shell or Java4Shell
- Known flaws in outdated WordPress themes and plugins or other CMSs
- Leaked or weak admin and FTP passwords
- A public Tomcat Manager used to deploy a malicious WAR file
7 ways to check
- Executable files in upload folders: a .php, .jsp or .phtml file among images and attachments is almost certainly an intrusion
- Recently changed files: look for files with recent dates that nobody on your team changed
- Odd code: eval(base64_decode(…)), assert($_POST…), Runtime.getRuntime().exec and similar
- Suspicious names: look-alikes of normal files (index2.php, wp-conflg.php) or meaningless names (x.php, 1.jsp)
- Access logs: repeated POST requests to .php or .jsp addresses that never appeared before
- Accounts and scheduled tasks: new admin users, unfamiliar crontab entries or services
- Outbound connections: the web server user connecting to strange external addresses
# PHP: executable files inside upload folders
find /var/www -path '*upload*' \( -name '*.php' -o -name '*.phtml' \)
# JSP: recently changed files in Tomcat webapps
find /opt/tomcat/webapps -name '*.jsp' -mtime -30 -ls
# Suspicious code
grep -rlE 'eval\s*\(\s*base64_decode|assert\s*\(\s*\$_(POST|GET|REQUEST)' /var/www
If you find one
- Copy the file as evidence before deleting it; you need to know how it got in
- Restore the server from a clean backup or rebuild it; there is rarely just one web shell
- Find and close the way in (flaw, upload form, password)
- Change every password: database, admin, FTP, SSH
- If personal data may have leaked, report it to your national CERT or data protection authority
Keeping them out
- Keep PHP, Java, your CMS and plugins on current security releases
- Configure the web server so scripts can't run in upload folders
- Restrict admin screens and Tomcat Manager to trusted networks
- Use a web application firewall (WAF) to filter upload and command-execution attempts
- Keep regular backups and monitor file changes
The Safelight deep check can't see inside your server to find a web shell, but from outside it checks the usual ways in: outdated PHP and Tomcat versions, leftover installers, public admin screens and Tomcat Manager, missing WAF, and exposed debug pages.
Check a domain nowFree · 30 seconds · nothing stored