Security

Webshell: what it is, how it works and how to block it

Marco Artese 7 min read Updated on:

Webshell: what it is, how it works and how to block it
In this guide (6)
  1. 1What a webshell technically is
  2. 2How a webshell is installed
  3. 3How it is hidden
  4. 4Why WordPress security plugins are not enough
  5. 5How to block a webshell before it reaches the server
  6. 6What to do if you suspect a webshell is already installed

A webshell is one of the most dangerous tools an attacker can install on your site — and one of the hardest to detect.

It's not a virus in the traditional sense of the word. It doesn't slow down the site, doesn't show messages, doesn't encrypt files. A webshell sits silently on the server, invisible to users and often to security plugins, waiting for the attacker to decide to use it.

This article explains what a webshell technically is, how it gets installed, how it's hidden, and what is architecturally needed to block it before it reaches the server.

What a webshell technically is

A webshell is a file — typically PHP, but also ASP, JSP or Python — uploaded to a website's server that allows the attacker to execute commands on the underlying operating system through the browser.

In practice: the attacker opens a browser, navigates to the URL of the installed webshell file (for example https://yoursite.com/uploads/image.php), and gets an interface from which they can execute commands on the server as if they had direct access to the command line. They can read files, modify them, exfiltrate data, install other tools, create administrator accounts, use the server as a relay to attack other systems.

The simplest possible webshell in PHP is literally one line:

<?php system($_GET['cmd']); ?>

This file, if uploaded to the server and reachable via browser, allows any operating system command to be executed by passing it as a URL parameter. Real webshells are much more sophisticated — full interfaces with file management, database access, reverse shell, all obfuscated to avoid detection.

How a webshell is installed

A webshell does not install itself. It requires the attacker to have already found an entry point into the system. There are three most common vectors.

File upload without proper validation

The most frequent vector on WordPress is uploading files through forms or upload areas that do not correctly validate the content. A plugin that only checks the file extension — verifying that it's named .jpg instead of .php — can be tricked with a file that has a seemingly innocuous extension but contains PHP code in the body.

The most sophisticated technique is the polyglot file: a file that has valid magic bytes (the first bytes that identify the format — in the case of JPEG they start with FF D8 FF) but contains PHP code embedded in the rest of the content. The browser interprets it as an image, the server executes it as PHP if the configuration allows it.

A recent and documented case of compromise that leads to full control of the site is the PHP2Shell (CVE-2026-109618/109619) vulnerability: the dedicated guide explains who is at risk and what to do right away.

SQL injection with file write

If a SQL injection attack is successful and the database has write permissions on the filesystem, the attacker can use MySQL's SELECT INTO OUTFILE function to write a PHP file directly to the server. An upload form isn't even needed — a malicious SQL query that isn't blocked is enough.

Vulnerabilities in plugins or themes

Unpatched WordPress plugins with Remote Code Execution (RCE) or Local File Inclusion (LFI) allow the attacker to upload or execute arbitrary code on the server. Vulnerabilities of this kind are discovered and published regularly — and between the moment of publication and the moment the administrator updates the plugin, the site is exposed.

How it is hidden

A skilled attacker does not leave the webshell in an obvious location. The most common concealment techniques are those that make detection difficult even for those who know what to look for.

Code obfuscation

The webshell code is encoded in Base64, broken up into multiple variables, concatenated with string functions, or compressed — so that the file does not contain recognizable strings such as system, exec or passthru. An antivirus or scanner looking for these strings finds nothing.

Example of basic obfuscation:

<?php
$a = base64_decode('c3lzdGVt');
$a($_GET['c']);
?>

The decoded code executes system($_GET['c']) — but none of the dangerous strings appear in plain text in the file.

Deceptive file extensions and names

The webshell is renamed with names that seem innocuous: config.php, cache.php, wp-options.php, thumb.php. In a WordPress installation with hundreds of PHP files spread across dozens of folders, one extra file is practically invisible without a systematic scan.

Falsified timestamps

Attackers modify the timestamp of the webshell file to make it look like a pre-existing file — the modification date appears identical to the other files in the same folder. Those who check the modification date to identify recently added files find no anomalies.

Iframes and injection into existing files

Instead of creating a new file, the attacker can inject the webshell code into already existing PHP files — modifying functions.php, index.php or any file already present. The resulting file is legitimate in structure but contains additional code hidden at the bottom or fragmented in the body.

Free check

Suspect your site has already been compromised?

In most cases a compromise stays invisible for months: the site works, but it sends spam, steals data from forms or is used to attack other sites.

We check your site for free and tell you what we found:

  • Recently modified files and suspicious code
  • Components and libraries with known vulnerabilities
  • Exposed surface and open access points
  • Presence of the site on blacklists and spam lists
Request a security check →

Response within 24 hours. If it's urgent, call 0835 239514

Why WordPress security plugins are not enough

Wordfence and similar tools scan files looking for known webshell signatures. This approach has structural limitations that are important to understand.

Signatures are updated after the discovery of new webshells — not before. A new or sufficiently obfuscated webshell doesn't match any signature in the database and is not detected. Wordfence free receives signature updates 30 days later than the premium version — a window during which new webshells go unidentified.

Moreover, scanning happens after the file is already on the server. The problem isn't detecting the webshell once it's installed — it's blocking it before it arrives. A periodic scan that finds the webshell three days after installation means three days of open access to the server.

The correct architectural solution is to block malicious file uploads at the moment of upload — not to scan the filesystem looking for what has already gotten through.

How to block a webshell before it reaches the server

Effective blocking requires analysis of the file's content at the moment of upload, not just its extension or name. The six checks that separate a secure upload system from a vulnerable one are the ones KeideaCMS applies natively to every uploaded file.

1. File name validation

Null bytes, double extensions (shell.php.jpg), control characters, and 80+ dangerous extensions blocked: not just .php, but also .phtml, .phar, .php5, .pht, .shtml and all the variants that PHP can execute.

2. PHP code detection in the content

Binary analysis of the file content looking for PHP tags (<?php, short tag <?, ASP tag <%) and dangerous functions (eval, system, exec, passthru, base64_decode) in files that shouldn't contain them. A .jpg file that contains <?php is blocked regardless of its extension.

3. Known webshell signatures

A database of signatures for the most widespread webshells: c99, r57, b374k, WSO, FilesMan, Alfa Shell, AnonymousFox, p0wny, weevely and 15+ others. The file is compared against these signatures before being accepted.

4. Shannon entropy analysis

Obfuscated code has statistically anomalous entropy compared to a legitimate file of the same type. Shannon entropy analysis — with a threshold at 7.2 on an 8.0 scale — identifies files with suspicious byte distribution, typical of compressed or encrypted code hidden in the content.

5. Base64 payload decoding

Base64 blocks embedded in the file content are searched for and recursively decoded. A payload obfuscated across multiple layers — Base64 inside Base64 inside an image file — is unmasked before the file is accepted.

6. Polyglot file detection

Verification that the file's magic bytes match the declared format and that the binary content doesn't contain PHP code embedded after the legitimate header. This is the most sophisticated check — and the one that blocks the hardest-to-detect attack technique.

These six checks are built into the core of KeideaCMS — they aren't an additional plugin that someone has to remember to update. KeideaCMS's complete security architecture, including the file scanning system, is documented here.

When a compromise happens again months later, the problem is rarely the single attack: it's the site's architecture that keeps exposing the same weak points. Cleaning up and putting the same system back online just means postponing the next incident. In those cases, rebuilding the site on different foundations costs less than years of emergency interventions.

What to do if you suspect a webshell is already installed

If the site has experienced unusual access, if you find PHP files in folders where they shouldn't be, if the server is consuming resources inexplicably, or if Google has flagged unusual content in indexed pages — the priority is containment, not diagnosis.

Immediate steps: isolate the site by taking it offline or restricting access by IP, make a complete backup of the current state (including the compromised site — needed for forensic analysis), and compare the filesystem with a backup from before the compromise, looking for added or modified files. Don't trust timestamps — use MD5 or SHA-256 hashes to compare files.

If the site handles personal data — and almost all business sites do — a compromise that allowed access to the database or files is a GDPR breach with an obligation to notify the Data Protection Authority within 72 hours. We've written an in-depth guide on WAF and structural protection that explains why prevention is the only effective response.

Request Your Free Security Audit →

Frequently Asked Questions

The less obvious signs are often the most significant: anomalous server CPU or memory resource consumption, emails sent from the domain that end up in spam, new PHP files in upload or media folders, administrator users created that you don't recognize, strange requests in server logs toward URLs that don't exist on public pages. The obvious signs — redirects to other sites, foreign content on pages — appear when the attacker decides to actively use the access, often weeks after the initial compromise. The only reliable way to detect a webshell in the silent phase is to compare the filesystem with a previous backup using cryptographic hashes, not timestamps.
Yes. The upload vector is the most frequent, but not the only one. SQL injection with filesystem write permissions, Remote Code Execution in vulnerable plugins, Local File Inclusion that allows including and executing remote files — all of these techniques can result in the installation of a webshell without a file ever being uploaded through a form. Effective protection requires a WAF that blocks these vectors at the application level, not just upload validation.
It depends on the level of obfuscation. Wordfence uses a signature database to identify known webshells — if the webshell matches a signature in the database, it gets detected. If it's sufficiently obfuscated, fragmented into variables, or encoded in a non-standard way, it may not match any signature and go unnoticed. The free version of Wordfence receives signature updates with a 30-day delay — a window during which new webshells aren't identified. And in any case, scanning happens after the file is already on the server: late detection doesn't prevent access during the hours or days between installation and discovery.
It depends on the server configuration. Preventing PHP execution in upload folders is a useful measure but not sufficient as a primary defense. Configuration errors, server updates, or vulnerabilities in path handling can undermine this protection. Correctly configuring NGINX or Apache to block PHP execution in /uploads is a valid defense layer — but it doesn't replace validating the file's content at the time of upload.
It depends on the objective. Automated attacks — crawlers that look for vulnerabilities and install webshells at scale — tend to use them immediately to install additional tools or exfiltrate credentials. Targeted attacks on specific sites often maintain silent access for weeks or months before acting, to avoid detection and to understand the environment. This means discovering the webshell on the same day it was installed is rare without an active filesystem monitoring system — and that by the time the damage becomes visible, the access has existed for much longer than you'd think.

You might also be interested in...

Do you need an e-commerce store or a website redesign?

Let's talk
  • Specialised consultation
  • Tailor-made solutions
  • Concrete results

Everythingin a singleSoftware

Talk to us for real

Our phone support is available every day from 09:00 to 18:00

+39 0835 239 514 Call us

Not your usual Web Agency

We follow you and always meet you halfway, even on spreading out your investment

Our projects

Need help

For information, quotes, or support, write to us

info@keideacms.it