Safelight
English

What Is a Web Shell? 7 Ways to Find One Hiding on Your Website (PHP and JSP)

Column By Safelight Security Team ·

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?

7 ways to check

  1. Executable files in upload folders: a .php, .jsp or .phtml file among images and attachments is almost certainly an intrusion
  2. Recently changed files: look for files with recent dates that nobody on your team changed
  3. Odd code: eval(base64_decode(…)), assert($_POST…), Runtime.getRuntime().exec and similar
  4. Suspicious names: look-alikes of normal files (index2.php, wp-conflg.php) or meaningless names (x.php, 1.jsp)
  5. Access logs: repeated POST requests to .php or .jsp addresses that never appeared before
  6. Accounts and scheduled tasks: new admin users, unfamiliar crontab entries or services
  7. 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

  1. Copy the file as evidence before deleting it; you need to know how it got in
  2. Restore the server from a clean backup or rebuild it; there is rarely just one web shell
  3. Find and close the way in (flaw, upload form, password)
  4. Change every password: database, admin, FTP, SSH
  5. If personal data may have leaked, report it to your national CERT or data protection authority

Keeping them out

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

Sources

  1. watchTowr: PHP2Shell FAQ
  2. Tenable: Java4Shell FAQ
  3. Wikipedia: China Chopper (a well-known web shell)

Security news