This detection identifies potential command injection vulnerabilities in PHP web applications where untrusted user input is executed via backticks, a common indicator of an adversary establishing a persistent webshell for remote code execution. Proactive hunting for this behavior within Azure Sentinel is critical to rapidly identify and isolate compromised endpoints before attackers can leverage the webshell to pivot laterally or exfiltrate sensitive data from the organization’s cloud infrastructure.
rule WEBSHELL_PHP_Generic_Backticks_OBFUSC
{
meta:
description = "Generic PHP webshell which uses backticks directly on user input"
license = "Detection Rule License 1.1 https://github.com/Neo23x0/signature-base/blob/master/LICENSE"
author = "Arnim Rupp (https://github.com/ruppde)"
reference = "Internal Research"
score = 75
date = "2021/01/07"
modified = "2023-04-05"
hash = "23dc299f941d98c72bd48659cdb4673f5ba93697"
hash = "e3f393a1530a2824125ecdd6ac79d80cfb18fffb89f470d687323fb5dff0eec1"
hash = "1e75914336b1013cc30b24d76569542447833416516af0d237c599f95b593f9b"
hash = "8db86ad90883cd208cf86acd45e67c03f994998804441705d690cb6526614d00"
id = "5ecb329f-0755-536d-8bfa-e36158474a0b"
strings:
$s1 = /echo[\t ]{0,500}\(?`\$/ wide ascii
//strings from private rule capa_php_old_safe
$php_short = "<?" wide ascii
// prevent xml and asp from hitting with the short tag
$no_xml1 = "<?xml version" nocase wide ascii
$no_xml2 = "<?xml-stylesheet" nocase wide ascii
$no_asp1 = "<%@LANGUAGE" nocase wide ascii
$no_asp2 = /<script language="(vb|jscript|c#)/ nocase wide ascii
$no_pdf = "<?xpacket"
// of course the new tags should also match
// already matched by "<?"
$php_new1 = /<\?=[^?]/ wide ascii
$php_new2 = "<?php" nocase wide ascii
$php_new3 = "<script language=\"php" nocase wide ascii
condition:
filesize < 500 and (
(
(
$php_short in (0..100) or
$php_short in (filesize-1000..filesize)
)
and not any of ( $no_* )
)
or any of ( $php_new* )
)
and $s1
}
This YARA rule can be deployed in the following contexts:
This rule contains 10 string patterns in its detection logic.
Here are 4 specific false positive scenarios for the “Generic PHP webshell using backticks on user input” rule, tailored for an enterprise environment:
Scheduled System Health Monitoring via Cron
health_check.php) is executed by cron to gather server metrics. The script accepts a command-line argument (e.g., -n node-01) and uses backticks to execute system commands like df -h or uptime based on that input to generate a status report.192.168.10.5) and the User-Agent header matches the known monitoring tool signature (e.g., Cron-Job-Monitor), or filter based on the specific URL path /maintenance/health_check.php.Legacy Admin Dashboard “Run Command” Feature
admin_ops.php) that allows administrators to execute quick shell commands (e.g., restarting a service) directly from the UI. When an admin types systemctl restart nginx into the form, the backend PHP script wraps this input in backticks to execute it immediately.10.20.30.0/24) accessing the /admin/ops path, provided the HTTP method is POST and the payload size is under 5KB (typical for command entry).CI/CD Pipeline Artifact Verification
deploy_verify.php) to validate artifact integrity.