Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

docs(case-study): agentic per-call audit + escaper-injection & class-based sinks

Xerj Squad A13caa4719a40
diff --git a/docs/case-studies/wordpress-security-audit/FINDINGS.md b/docs/case-studies/wordpress-security-audit/FINDINGS.md
index 6b09c4411..d5a55cec6 100644
--- a/docs/case-studies/wordpress-security-audit/FINDINGS.md
+++ b/docs/case-studies/wordpress-security-audit/FINDINGS.md
@@ -5,13 +5,19 @@
| # | finding | class | severity | status |
|---|---|---|---|---|
| 1 | `wp_http_validate_url` allows `169.254.0.0/16` (cloud metadata) | SSRF (incomplete deny-list) | Medium (known-class) | **Real, verified, reachable** |
+| 2 | `class-snoopy.php` curl build: `escapeshellarg($URI)` after flags, no `--` | option injection (escaper ≠ injection defense) | Medium (legacy, if URI attacker-set) | **Real pattern instance** |
+| 3 | `class-wp-image-editor-imagick.php` parses uploaded image content | ImageTragick (image-rce-ssrf) | Medium (deploy-dependent) | **Real surface** |
| — | AJAX / REST / admin authorization | IDOR / privesc | — | Verified **clean** (object-scoped) |
| — | SQL double-`prepare` de-escape | SQLi | — | Verified **safe** (placeholder_escape) |
| — | sanitizer composition (escape→de-escape) | XSS/SQLi | — | Verified **safe** (escaper-last) |
-Only finding #1 is a real weakness. The rest are documented negatives — core is
-hardened — and each was confirmed by reading the real implementation, not by a
-pattern match.
+Findings 1–3 are real (2 and 3 are known-class / deploy-dependent, stated
+honestly); the rest are documented negatives — core is hardened — each confirmed
+by reading the real implementation, not a pattern match. Findings 2 and 3 came
+from the **agentic per-call audit**: the agent read each flagged call
+(`escapeshellarg`, `Imagick::readImage`, `ZipArchive`) and wrote a verdict back to
+`wpsinks` — proving the escaper-injection and class-based-sink classes are now
+covered.
---
@@ -76,6 +82,33 @@ re-check the IP at request time (mitigates DNS-rebinding TOCTOU).
---
+## Finding 2 — `escapeshellarg` option injection (class: escaper-is-not-injection-protection)
+
+`wp-includes/class-snoopy.php` (legacy vendored HTTP lib) builds a curl command:
+```php
+$cmdline_params = '-k -D '.escapeshellarg($headerfile).' -H '.escapeshellarg($header)...
+exec($this->curl_path.' '.$cmdline_params.' '.escapeshellarg($URI), ...);
+```
+`$URI` is `escapeshellarg`-escaped but placed **after the flags with no `--`
+separator**. `escapeshellarg` prevents shell *command* breakout — it does **not**
+prevent curl from parsing the value as an **option**. If `$URI` is
+attacker-controlled and starts with `-`, e.g. `-o/var/www/html/x.php` (file write →
+RCE) or `-K /etc/passwd`, curl obeys it. **Honest scope:** Snoopy is legacy and
+core rarely routes attacker URLs to it; the point is the *class* — an escaper that
+is not injection protection. **Fix:** insert a literal `--` before `$URI`; reject
+leading `-`; use argv-form. This is the pattern `option-injection` in the guide.
+
+## Finding 3 — Imagick processes uploaded image content (class: image-rce-ssrf)
+
+`wp-includes/class-wp-image-editor-imagick.php` calls `Imagick::readImage($this->file)`
+/ `readImageBlob(file_get_contents($this->file))` on **attacker-uploaded** images.
+This is the ImageTragick surface (CVE-2016-3714 and kin): a crafted MVG/MSL/SVG
+image can make an unpatched/mis-configured ImageMagick perform SSRF or command
+execution via delegates. **Honest scope:** mitigated by a modern ImageMagick +
+a restrictive `policy.xml`, which WP relies on the host to provide; WP checks file
+type first but the content is still parsed. **Fix (deploy):** patched ImageMagick;
+`policy.xml` disabling `MVG/MSL/URL/EPHEMERAL/HTTPS` coders.
+
## Verified-clean negatives (the honest majority)
### Authorization / IDOR — clean
diff --git a/docs/case-studies/wordpress-security-audit/sink-census/PHP-DANGEROUS-FUNCTIONS.md b/docs/case-studies/wordpress-security-audit/sink-census/PHP-DANGEROUS-FUNCTIONS.md
index df4ca7a65..cffdca0a8 100644
--- a/docs/case-studies/wordpress-security-audit/sink-census/PHP-DANGEROUS-FUNCTIONS.md
+++ b/docs/case-studies/wordpress-security-audit/sink-census/PHP-DANGEROUS-FUNCTIONS.md
@@ -1,6 +1,6 @@
# The PHP dangerous-function map (full reference)
-275 potentially-vulnerable PHP built-ins/constructs across 28 categories. Generated from `php_dangerous_functions.json`. `arg` = the taint-relevant argument (0-indexed; `cb:N`=callable at N; `recv`=receiver/URL-set-elsewhere; `self`=construct operand; `ret`=return is the sink).
+287 functions across 30 categories.
## command-exec — RCE-command
| function | kind | arg | note |
@@ -264,6 +264,9 @@
| `open` | method | 0 | XMLReader::open |
| `libxml_set_external_entity_loader` | call | cb:0 | |
| `transformToXml` | method | 0 | XSLTProcessor + registerPHPFunctions => RCE |
+| `loadHTML` | method | 0 | DOMDocument::loadHTML — HTML parse; entity/xxe surface |
+| `setEntityLoader` | method | cb:0 | libxml external entity loader |
+| `setParserProperty` | method | 0 | XMLReader — can enable DTD/entity loading |
## xss-output — XSS
*raw output of unescaped data; escape per context*
@@ -425,3 +428,24 @@
| `strncmp` | call | 0 | |
| `hash_equals` | call | 0 | SAFE — the correct constant-time compare |
+## archive-extraction — zip-slip-path-traversal
+*extracting an archive writes entry paths; a `../` entry escapes the target dir (Zip Slip). Also symlink entries.*
+
+| function | kind | arg | note |
+|---|---|---|---|
+| `extractTo` | method | 0 | ZipArchive/PharData::extractTo — writes each entry; ../ escapes dir |
+| `addFile` | method | 0 | path added to archive |
+| `addFromString` | method | 0 | entry name is attacker-influenced |
+| `buildFromDirectory` | method | 0 | PharData |
+| `convertToExecutable` | method | * | PharData -> executable phar |
+
+## image-processing — image-rce-ssrf
+*Imagick reads by URL (SSRF) and historically had delegate RCE (ImageTragick, MVG/MSL); GD from-URL is SSRF.*
+
+| function | kind | arg | note |
+|---|---|---|---|
+| `readImage` | method | 0 | Imagick::readImage — URL => SSRF; format abuse |
+| `readImageBlob` | method | 0 | |
+| `readImageFile` | method | 0 | |
+| `setImageFormat` | method | 0 | |
+
diff --git a/docs/case-studies/wordpress-security-audit/sink-census/PHP-SECURITY-GUIDE.md b/docs/case-studies/wordpress-security-audit/sink-census/PHP-SECURITY-GUIDE.md
index 99dded3a7..16dccbf94 100644
--- a/docs/case-studies/wordpress-security-audit/sink-census/PHP-SECURITY-GUIDE.md
+++ b/docs/case-studies/wordpress-security-audit/sink-census/PHP-SECURITY-GUIDE.md
@@ -3,7 +3,7 @@
A whitebox PHP audit has **two axes**, and both must be covered to claim
completeness:
-1. **Dangerous functions (sinks)** — 275 built-ins/constructs, one call = one
+1. **Dangerous functions (sinks)** — 287 built-ins/constructs, one call = one
candidate. Enumerable and *provable* by AST census. See
[`PHP-DANGEROUS-FUNCTIONS.md`](PHP-DANGEROUS-FUNCTIONS.md) /
`php_dangerous_functions.json`.
@@ -16,7 +16,7 @@ completeness:
> **Rule of thumb:** a sink tells you *where danger can happen*; a pattern tells
> you *how safe-looking code is actually exploitable*. You need both.
-Measured on WordPress core: **11,191 sink sites** (proven 0-gap) + **2,077
+Measured on WordPress core: **11,223 sink sites** (proven 0-gap) + **2,077
pattern hits** across 10 AST-detectable patterns, + the manual/semantic classes
below that require reasoning.
@@ -24,8 +24,8 @@ below that require reasoning.
## Part 1 — Dangerous functions (the sink axis)
-Full table in [`PHP-DANGEROUS-FUNCTIONS.md`](PHP-DANGEROUS-FUNCTIONS.md). 275
-functions across 28 categories, each with vuln class, safe/unsafe recipe, and the
+Full table in [`PHP-DANGEROUS-FUNCTIONS.md`](PHP-DANGEROUS-FUNCTIONS.md). 287
+functions across 30 categories, each with vuln class, safe/unsafe recipe, and the
taint-relevant argument: command/code exec, dynamic callables (`array_map`,
`preg_replace_callback`), `unserialize`, include loaders, file read/write/delete/
perms, directory, SSRF, SQL drivers, LDAP, XXE, variable-injection, ReDoS/ereg,
@@ -55,6 +55,30 @@ process-control, reflection-invoke, type-juggle functions, output/XSS. Coverage
- **Non-constant-time secret compare** (`timing-compare`) — `$mac == $expected`
leaks timing *and* juggles. **Safe:** `hash_equals`. *(WP core: 56.)*
+### A2. Escaper / defense that is NOT a defense
+- **`escapeshellarg` does not stop argument/option injection** (`option-injection`)
+ — it quotes a value so it can't start a *new command*, but the value can still
+ be read as an **option**. `exec('tar '.escapeshellarg($f))` with
+ `$f='--checkpoint-action=exec=sh'` runs a command; `curl … escapeshellarg($url)`
+ with `$url='-o/var/www/x.php'` writes a file (RCE). **Found in WP** `class-snoopy.php`
+ — `$URI` escaped but placed after curl flags with no `--`. **Safe:** literal `--`
+ before user args; reject leading `-`; argv-form `proc_open`.
+- **`escapeshellcmd` is weaker than `escapeshellarg`** (`escapeshellcmd-weak`) —
+ escapes command metachars but leaves argument splitting/quoting; misused as if
+ it quoted an argument.
+
+### A3. Class-based sinks (danger inside methods, not free functions)
+- **Zip Slip** (`zip-slip`) — `ZipArchive/PharData::extractTo($dir)` writes each
+ entry by its own path; a `../` entry escapes `$dir` → arbitrary write (RCE). WP
+ core avoids this by hand-rolling extraction with path checks in `unzip_file`.
+- **ImageMagick / Imagick** (`image-rce-ssrf`) — `Imagick::readImage`/`readImageBlob`
+ on attacker-uploaded content → ImageTragick (MVG/MSL/SVG delegate) SSRF/RCE if
+ ImageMagick is unpatched or `policy.xml` missing. **Found in WP** `class-wp-image-editor-imagick.php`.
+- **phar:// via any file op** (`phar-wrapper-op`) — a benign `file_exists`/
+ `getimagesize` on `phar://x.jpg` triggers `unserialize` of Phar metadata.
+- The census catalogues these as method/ctor sinks (`extractTo`, `loadHTML`,
+ `readImage`, `new ZipArchive`, `new Imagick`, …) so they're enumerated too.
+
### B. Input shape (the `?param[]=` family)
- **Array injection** (`array-injection`) — sending `login[]=a` makes
`$_POST['login']` an **array**. It breaks every string-typed sink:
diff --git a/docs/case-studies/wordpress-security-audit/sink-census/enrich_pipeline.py b/docs/case-studies/wordpress-security-audit/sink-census/enrich_pipeline.py
index a4c5b60da..fa7ec65bd 100644
--- a/docs/case-studies/wordpress-security-audit/sink-census/enrich_pipeline.py
+++ b/docs/case-studies/wordpress-security-audit/sink-census/enrich_pipeline.py
@@ -16,7 +16,10 @@ X = "http://127.0.0.1:9200"
# ── Agent verdicts, keyed by file:line (reachable / guarded / severity / note) ──
V = {
# RCE-command
- "wp-includes/class-snoopy.php:1018": ("server-http-lib","escapeshellarg(URI)","low","URI escaped; Snoopy is legacy vendored HTTP lib"),
+ "wp-includes/class-snoopy.php:1018": ("server-http-lib-if-URI-attacker","escapeshellarg-NOT-option-safe","medium","OPTION INJECTION: $URI placed after curl flags with NO `--` separator; escapeshellarg stops command breakout but not curl option parsing -> $URI=\"-o/path\" writes a file (RCE) / -K reads. Snoopy legacy. Fix: add `--` before $URI."),
+ "wp-includes/block-template-utils.php:1494": ("theme-export","ziparchive-CREATE-not-extract","low","ZipArchive::open(CREATE|OVERWRITE) builds an export zip; addFile/addFromString add content -> NOT zip-slip (that is on extractTo). WP extraction (unzip_file) hand-rolls path checks, avoiding extractTo."),
+ "wp-includes/class-wp-image-editor-imagick.php:158": ("image-editor-uploaded-content","imagemagick-policy-dependent","medium","Imagick::readImage($this->file) parses attacker-UPLOADED image content -> ImageTragick/MVG/MSL/SVG delegate abuse (SSRF/RCE) if ImageMagick unpatched or policy.xml missing. WP checks file type first; content is still parsed."),
+ "wp-includes/class-wp-image-editor-imagick.php:156": ("image-editor-uploaded-content","imagemagick-policy-dependent","medium","Imagick::readImageBlob(file_get_contents($this->file)) — same ImageTragick surface on uploaded content."),
"wp-includes/ID3/getid3.lib.php:1806": ("media-analysis","fixed-binary+internal","medium","$commandline built from configured binary paths; confirm filenames are escaped"),
"wp-includes/ID3/getid3.php:484": ("media-analysis","fixed-binary+internal","medium","same getID3 external-tool path"),
"wp-includes/ID3/getid3.php:1824": ("media-analysis","fixed-binary+internal","medium","same"),
@@ -57,7 +60,7 @@ def post(path, body, ct="application/json"):
# pull every must-review site (the high-risk classes) and enrich — size covers all
q = {"query": {"terms": {"class": ["RCE-command","RCE-code","deserialization","SSRF","SQLi",
"file-write","file-read","XXE","variable-injection",
- "dynamic-invoke","LDAP-injection"]}},
+ "dynamic-invoke","LDAP-injection","zip-slip-path-traversal","image-rce-ssrf"]}},
"size": 5000, "_source": ["file","line","fn","class"]}
hits = post("wpsinks/_search", json.dumps(q))["hits"]["hits"]
reviewed = updates = 0
diff --git a/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_functions.json b/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_functions.json
index ab85ffa85..d5d2d82ca 100644
--- a/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_functions.json
+++ b/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_functions.json
@@ -1,202 +1,1440 @@
{
"meta": {
"title": "Comprehensive PHP dangerous-function map",
- "purpose": "The full reference of potentially-vulnerable PHP built-ins/constructs, by category and vuln class, with the taint-relevant argument. Superset of php_sink_catalog.json. Drives the coverage census — coverage = 'every call to a catalogued function enumerated'.",
+ "purpose": "The full reference of potentially-vulnerable PHP built-ins/constructs, by category and vuln class, with the taint-relevant argument. Superset of php_sink_catalog.json. Drives the coverage census \u2014 coverage = 'every call to a catalogued function enumerated'.",
"arg_field": "sink_arg: 0-indexed dangerous argument, '*'=any, 'ret'=return is the sink, 'recv'=method receiver/URL set elsewhere, 'self'=language construct operand, 'cb:N'=argument N is a callable (second-order RCE if attacker-controlled)",
- "sources": ["RIPS sinks", "Psalm taint sinks", "exakat security", "PHPCS-Security-Audit", "Semgrep php", "OWASP PHP dangerous functions", "php.ini disable_functions guidance"]
+ "sources": [
+ "RIPS sinks",
+ "Psalm taint sinks",
+ "exakat security",
+ "PHPCS-Security-Audit",
+ "Semgrep php",
+ "OWASP PHP dangerous functions",
+ "php.ini disable_functions guidance"
+ ]
},
"categories": {
- "command-exec": {"class": "RCE-command", "kind": "call", "fns": [
- {"fn":"exec","arg":0},{"fn":"shell_exec","arg":0},{"fn":"system","arg":0},
- {"fn":"passthru","arg":0},{"fn":"proc_open","arg":0},{"fn":"popen","arg":0},
- {"fn":"pcntl_exec","arg":0},{"fn":"expect_popen","arg":0},{"fn":"ssh2_exec","arg":1},
- {"fn":"ssh2_shell","arg":0},{"fn":"dl","arg":0,"note":"loads a native extension"},
- {"fn":"w32api_invoke_function","arg":0}
- ]},
- "backtick-operator": {"class": "RCE-command", "kind": "construct", "fns": [
- {"fn":"shell_command_expression","arg":"self","note":"`...` backtick executes a shell command"}
- ]},
- "code-eval": {"class": "RCE-code", "kind": "call", "fns": [
- {"fn":"eval","arg":0},{"fn":"assert","arg":0,"note":"string arg eval'd pre-8.0"},
- {"fn":"create_function","arg":1,"note":"eval-backed; removed 8.0"},
- {"fn":"preg_replace","arg":0,"note":"/e modifier eval's replacement (removed 7.0); user pattern=ReDoS"},
- {"fn":"mb_ereg_replace","arg":3,"note":"'e' option evals"},
- {"fn":"mb_eregi_replace","arg":3,"note":"'e' option evals"},
- {"fn":"ReflectionFunction","arg":0,"note":"->invoke() runs an arbitrary function"}
- ]},
- "dynamic-callable": {"class": "RCE-code-callable", "kind": "call", "note": "arbitrary function/method call if the callable is attacker-controlled (second-order)", "fns": [
- {"fn":"call_user_func","arg":"cb:0"},{"fn":"call_user_func_array","arg":"cb:0"},
- {"fn":"call_user_method","arg":"cb:0"},{"fn":"call_user_method_array","arg":"cb:0"},
- {"fn":"forward_static_call","arg":"cb:0"},{"fn":"forward_static_call_array","arg":"cb:0"},
- {"fn":"array_map","arg":"cb:0"},{"fn":"array_filter","arg":"cb:1"},
- {"fn":"array_walk","arg":"cb:1"},{"fn":"array_walk_recursive","arg":"cb:1"},
- {"fn":"array_reduce","arg":"cb:1"},{"fn":"array_diff_uassoc","arg":"cb:2"},
- {"fn":"usort","arg":"cb:1"},{"fn":"uasort","arg":"cb:1"},{"fn":"uksort","arg":"cb:1"},
- {"fn":"preg_replace_callback","arg":"cb:1"},{"fn":"preg_replace_callback_array","arg":"cb:0"},
- {"fn":"register_shutdown_function","arg":"cb:0"},{"fn":"register_tick_function","arg":"cb:0"},
- {"fn":"set_error_handler","arg":"cb:0"},{"fn":"set_exception_handler","arg":"cb:0"},
- {"fn":"spl_autoload_register","arg":"cb:0"},{"fn":"ob_start","arg":"cb:0"},
- {"fn":"iterator_apply","arg":"cb:1"},{"fn":"filter_var","arg":2,"note":"FILTER_CALLBACK option runs a callable"},
- {"fn":"header_register_callback","arg":"cb:0"},{"fn":"stream_filter_register","arg":1}
- ]},
- "deserialization": {"class": "deserialization", "kind": "call", "note": "PHP Object Injection via magic methods (POP chains)", "fns": [
- {"fn":"unserialize","arg":0},{"fn":"yaml_parse","arg":0},{"fn":"yaml_parse_file","arg":0},
- {"fn":"yaml_parse_url","arg":0},{"fn":"igbinary_unserialize","arg":0},
- {"fn":"msgpack_unserialize","arg":0},{"fn":"wddx_deserialize","arg":0},
- {"fn":"session_decode","arg":0,"note":"deserializes into $_SESSION"}
- ]},
- "file-include": {"class": "LFI-RFI", "kind": "construct", "note": "includes AND executes the path; RFI if allow_url_include", "fns": [
- {"fn":"include","arg":"self"},{"fn":"include_once","arg":"self"},
- {"fn":"require","arg":"self"},{"fn":"require_once","arg":"self"},
- {"fn":"virtual","arg":0,"kind":"call","note":"Apache subrequest"}
- ]},
- "file-read": {"class": "file-read", "kind": "call", "note": "arbitrary file read / path traversal; several also accept URL wrappers (SSRF)", "fns": [
- {"fn":"file_get_contents","arg":0,"note":"URL => SSRF; php://filter => source disclosure"},
- {"fn":"file","arg":0},{"fn":"fopen","arg":0,"note":"URL wrappers => SSRF"},
- {"fn":"readfile","arg":0},{"fn":"fpassthru","arg":0},{"fn":"fgets","arg":0},
- {"fn":"fgetc","arg":0},{"fn":"fread","arg":0},{"fn":"fscanf","arg":0},
- {"fn":"parse_ini_file","arg":0},{"fn":"parse_ini_string","arg":0},
- {"fn":"highlight_file","arg":0},{"fn":"show_source","arg":0},
- {"fn":"readlink","arg":0},{"fn":"realpath","arg":0},
- {"fn":"gzfile","arg":0},{"fn":"gzopen","arg":0},{"fn":"readgzfile","arg":0},
- {"fn":"bzopen","arg":0},{"fn":"bzread","arg":0},{"fn":"zip_open","arg":0},
- {"fn":"exif_read_data","arg":0},{"fn":"exif_thumbnail","arg":0},
- {"fn":"getimagesize","arg":0,"note":"URL => SSRF"},{"fn":"getimagesizefromstring","arg":0},
- {"fn":"finfo_file","arg":1},{"fn":"mime_content_type","arg":0},
- {"fn":"imagecreatefromjpeg","arg":0,"note":"URL => SSRF"},{"fn":"imagecreatefrompng","arg":0},
- {"fn":"imagecreatefromgif","arg":0},{"fn":"imagecreatefromwebp","arg":0},
- {"fn":"SplFileObject","arg":0,"kind":"method"},{"fn":"md5_file","arg":0},{"fn":"sha1_file","arg":0},
- {"fn":"hash_file","arg":1},{"fn":"stat","arg":0},{"fn":"lstat","arg":0},{"fn":"fileperms","arg":0}
- ]},
- "file-write": {"class": "file-write", "kind": "call", "note": "write/overwrite; RCE if attacker controls path+content of a .php", "fns": [
- {"fn":"file_put_contents","arg":0},{"fn":"fwrite","arg":0,"note":"handle arg"},
- {"fn":"fputs","arg":0},{"fn":"fputcsv","arg":0},{"fn":"move_uploaded_file","arg":1},
- {"fn":"copy","arg":1,"note":"URL src => SSRF; dest => write"},{"fn":"rename","arg":1},
- {"fn":"link","arg":1},{"fn":"symlink","arg":1},{"fn":"touch","arg":0},
- {"fn":"mkdir","arg":0},{"fn":"tempnam","arg":0},{"fn":"tmpfile","arg":"ret"},
- {"fn":"ftruncate","arg":0},{"fn":"vfprintf","arg":0},{"fn":"fprintf","arg":0}
- ]},
- "file-delete": {"class": "file-delete", "kind": "call", "fns": [
- {"fn":"unlink","arg":0},{"fn":"rmdir","arg":0}
- ]},
- "file-perms": {"class": "file-perms", "kind": "call", "note": "privilege/ownership changes on a path", "fns": [
- {"fn":"chmod","arg":0},{"fn":"chown","arg":0},{"fn":"chgrp","arg":0},
- {"fn":"lchown","arg":0},{"fn":"lchgrp","arg":0},{"fn":"umask","arg":0}
- ]},
- "directory": {"class": "dir-listing-traversal", "kind": "call", "fns": [
- {"fn":"scandir","arg":0},{"fn":"opendir","arg":0},{"fn":"readdir","arg":0},
- {"fn":"glob","arg":0,"note":"glob:// wrapper"},{"fn":"dir","arg":0},
- {"fn":"chdir","arg":0},{"fn":"chroot","arg":0}
- ]},
- "ssrf-network": {"class": "SSRF", "kind": "call", "note": "outbound request to an attacker-chosen host; block link-local/metadata/private", "fns": [
- {"fn":"fsockopen","arg":0},{"fn":"pfsockopen","arg":0},
- {"fn":"stream_socket_client","arg":0},{"fn":"stream_socket_server","arg":0},
- {"fn":"curl_exec","arg":"recv","note":"URL set via curl_setopt CURLOPT_URL"},
- {"fn":"curl_multi_exec","arg":"recv"},{"fn":"curl_setopt","arg":2,"note":"CURLOPT_URL"},
- {"fn":"get_headers","arg":0},{"fn":"http_get","arg":0},{"fn":"http_post_data","arg":0},
- {"fn":"gethostbyname","arg":0},{"fn":"gethostbynamel","arg":0},
- {"fn":"dns_get_record","arg":0},{"fn":"checkdnsrr","arg":0},{"fn":"getmxrr","arg":0},
- {"fn":"SoapClient","arg":0,"kind":"method","note":"WSDL URL => SSRF/XXE"},
- {"fn":"stream_context_create","arg":0,"note":"can set follow_location/proxy"}
- ]},
- "sql": {"class": "SQLi", "kind": "call", "note": "raw SQL — use parameterized queries", "fns": [
- {"fn":"mysqli_query","arg":1},{"fn":"mysqli_multi_query","arg":1},
- {"fn":"mysqli_real_query","arg":1},{"fn":"mysqli_prepare","arg":1,"note":"unsafe if concatenated"},
- {"fn":"mysql_query","arg":0},{"fn":"mysql_unbuffered_query","arg":0},
- {"fn":"mysql_db_query","arg":1},{"fn":"pg_query","arg":1},
- {"fn":"pg_send_query","arg":1},{"fn":"sqlite_query","arg":1},
- {"fn":"sqlite_unbuffered_query","arg":1},{"fn":"sqlsrv_query","arg":1},
- {"fn":"oci_parse","arg":1},{"fn":"odbc_exec","arg":1},{"fn":"odbc_prepare","arg":1},
- {"fn":"db2_exec","arg":1},{"fn":"ibase_query","arg":1},{"fn":"mssql_query","arg":0},
- {"fn":"maxdb_query","arg":1},{"fn":"ingres_query","arg":1},
- {"fn":"query","arg":0,"kind":"method","note":"PDO::query / mysqli::query"},
- {"fn":"exec","arg":0,"kind":"method","note":"PDO::exec (method form)"}
- ]},
- "ldap": {"class": "LDAP-injection", "kind": "call", "fns": [
- {"fn":"ldap_search","arg":2},{"fn":"ldap_list","arg":2},{"fn":"ldap_read","arg":2},
- {"fn":"ldap_bind","arg":1,"note":"auth bypass via crafted DN/empty pw"},
- {"fn":"ldap_add","arg":2},{"fn":"ldap_modify","arg":2},{"fn":"ldap_delete","arg":1}
- ]},
- "xxe-xml": {"class": "XXE", "kind": "call", "note": "external entity expansion => file read/SSRF; disable entities", "fns": [
- {"fn":"simplexml_load_string","arg":0},{"fn":"simplexml_load_file","arg":0},
- {"fn":"xml_parse","arg":1},{"fn":"xml_parse_into_struct","arg":1},
- {"fn":"loadXML","arg":0,"kind":"method","note":"DOMDocument::loadXML"},
- {"fn":"load","arg":0,"kind":"method","note":"DOMDocument::load path/URL"},
- {"fn":"loadHTMLFile","arg":0,"kind":"method"},
- {"fn":"open","arg":0,"kind":"method","note":"XMLReader::open"},
- {"fn":"libxml_set_external_entity_loader","arg":"cb:0"},
- {"fn":"transformToXml","arg":0,"kind":"method","note":"XSLTProcessor + registerPHPFunctions => RCE"}
- ]},
- "xss-output": {"class": "XSS", "kind": "construct", "note": "raw output of unescaped data; escape per context", "fns": [
- {"fn":"echo","arg":"self"},{"fn":"print","arg":"self"}
- ]},
- "xss-output-call": {"class": "XSS-or-info", "kind": "call", "fns": [
- {"fn":"printf","arg":0,"note":"user format-string bug"},{"fn":"vprintf","arg":0},
- {"fn":"print_r","arg":0,"note":"outputs unless 2nd arg true"},
- {"fn":"var_dump","arg":"*"},{"fn":"var_export","arg":0,"note":"outputs unless 2nd arg true"},
- {"fn":"exit","arg":0},{"fn":"die","arg":0},
- {"fn":"htmlspecialchars_decode","arg":0,"note":"UNDOES escaping"},
- {"fn":"html_entity_decode","arg":0,"note":"UNDOES escaping"}
- ]},
- "header-redirect": {"class": "header-injection-open-redirect", "kind": "call", "fns": [
- {"fn":"header","arg":0,"note":"Location: => open redirect; CRLF pre-5.1.2"},
- {"fn":"setcookie","arg":1},{"fn":"setrawcookie","arg":1},
- {"fn":"session_set_cookie_params","arg":0}
- ]},
- "variable-injection": {"class": "variable-injection", "kind": "call", "note": "imports attacker keys into scope (register_globals-style)", "fns": [
- {"fn":"extract","arg":0},{"fn":"parse_str","arg":0,"note":"1-arg form pollutes caller scope"},
- {"fn":"mb_parse_str","arg":0},{"fn":"import_request_variables","arg":0},
- {"fn":"compact","arg":"*","note":"info leak if keys tainted"}
- ]},
- "regex-redos": {"class": "ReDoS-or-injection", "kind": "call", "note": "catastrophic backtracking with a user pattern; deprecated ereg", "fns": [
- {"fn":"preg_match","arg":0,"note":"user PATTERN => ReDoS"},{"fn":"preg_match_all","arg":0},
- {"fn":"preg_split","arg":0},{"fn":"preg_grep","arg":0},
- {"fn":"ereg","arg":0},{"fn":"eregi","arg":0},{"fn":"ereg_replace","arg":0},
- {"fn":"eregi_replace","arg":0},{"fn":"mb_ereg","arg":0}
- ]},
- "mail-injection": {"class": "mail-header-injection", "kind": "call", "fns": [
- {"fn":"mail","arg":3,"note":"additional_headers => header injection"},
- {"fn":"mb_send_mail","arg":3},{"fn":"imap_mail","arg":3},{"fn":"ezmlm_hash","arg":0}
- ]},
- "weak-crypto": {"class": "weak-crypto", "kind": "call", "note": "fast/broken for passwords/tokens/integrity", "fns": [
- {"fn":"md5","arg":0},{"fn":"sha1","arg":0},{"fn":"crc32","arg":0},
- {"fn":"crypt","arg":0,"note":"weak without proper salt/algo"},
- {"fn":"hash","arg":1,"note":"md5/sha1 for secrets"},
- {"fn":"mcrypt_encrypt","arg":0,"note":"deprecated, ECB default"},
- {"fn":"mcrypt_decrypt","arg":0}
- ]},
- "weak-random": {"class": "weak-random", "kind": "call", "note": "predictable; unfit for tokens/nonces/passwords", "fns": [
- {"fn":"rand","arg":"ret"},{"fn":"mt_rand","arg":"ret"},{"fn":"mt_srand","arg":0},
- {"fn":"srand","arg":0},{"fn":"uniqid","arg":"ret"},{"fn":"lcg_value","arg":"ret"},
- {"fn":"str_shuffle","arg":0},{"fn":"array_rand","arg":0},{"fn":"shuffle","arg":0}
- ]},
- "info-disclosure": {"class": "info-disclosure", "kind": "call", "fns": [
- {"fn":"phpinfo","arg":"*"},{"fn":"debug_zval_refcount","arg":0},
- {"fn":"debug_backtrace","arg":"ret"},{"fn":"debug_print_backtrace","arg":"*"},
- {"fn":"getenv","arg":0},{"fn":"get_cfg_var","arg":0},{"fn":"ini_get_all","arg":"ret"},
- {"fn":"get_defined_vars","arg":"ret"},{"fn":"getmypid","arg":"ret"},
- {"fn":"posix_getpwuid","arg":0},{"fn":"posix_getgrgid","arg":0},{"fn":"posix_getpwnam","arg":0}
- ]},
- "runtime-config": {"class": "config-tamper", "kind": "call", "note": "changes PHP/security settings at runtime", "fns": [
- {"fn":"ini_set","arg":0},{"fn":"ini_alter","arg":0},{"fn":"ini_restore","arg":0},
- {"fn":"putenv","arg":0},{"fn":"set_include_path","arg":0},{"fn":"apache_setenv","arg":0},
- {"fn":"error_reporting","arg":0},{"fn":"assert_options","arg":0},{"fn":"setlocale","arg":1}
- ]},
- "process-control": {"class": "process-control", "kind": "call", "note": "signal/priv/process manipulation", "fns": [
- {"fn":"posix_kill","arg":0},{"fn":"posix_setuid","arg":0},{"fn":"posix_setgid","arg":0},
- {"fn":"posix_seteuid","arg":0},{"fn":"pcntl_fork","arg":"*"},{"fn":"pcntl_signal","arg":"cb:1"},
- {"fn":"proc_nice","arg":0},{"fn":"proc_terminate","arg":0},{"fn":"apache_child_terminate","arg":"*"}
- ]},
- "reflection-invoke": {"class": "dynamic-invoke", "kind": "method", "note": "instantiate/invoke arbitrary class/method (gadget reach)", "fns": [
- {"fn":"newInstance","arg":"*","note":"ReflectionClass::newInstance"},
- {"fn":"newInstanceArgs","arg":"*"},{"fn":"invoke","arg":"*","note":"Reflection*::invoke"},
- {"fn":"invokeArgs","arg":"*"},{"fn":"setAccessible","arg":0,"note":"bypasses visibility"}
- ]},
- "type-juggling": {"class": "auth-bypass-type-juggle", "kind": "call", "note": "loose comparison / magic-hash / non-strict search => auth bypass", "fns": [
- {"fn":"in_array","arg":2,"note":"non-strict (3rd arg false) => 0==string"},
- {"fn":"array_search","arg":2,"note":"non-strict"},
- {"fn":"strcmp","arg":0,"note":"array arg returns NULL, NULL==0 true"},
- {"fn":"strcasecmp","arg":0},{"fn":"strncmp","arg":0},{"fn":"hash_equals","arg":0,"note":"SAFE — the correct constant-time compare"}
- ]}
+ "command-exec": {
+ "class": "RCE-command",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "exec",
+ "arg": 0
+ },
+ {
+ "fn": "shell_exec",
+ "arg": 0
+ },
+ {
+ "fn": "system",
+ "arg": 0
+ },
+ {
+ "fn": "passthru",
+ "arg": 0
+ },
+ {
+ "fn": "proc_open",
+ "arg": 0
+ },
+ {
+ "fn": "popen",
+ "arg": 0
+ },
+ {
+ "fn": "pcntl_exec",
+ "arg": 0
+ },
+ {
+ "fn": "expect_popen",
+ "arg": 0
+ },
+ {
+ "fn": "ssh2_exec",
+ "arg": 1
+ },
+ {
+ "fn": "ssh2_shell",
+ "arg": 0
+ },
+ {
+ "fn": "dl",
+ "arg": 0,
+ "note": "loads a native extension"
+ },
+ {
+ "fn": "w32api_invoke_function",
+ "arg": 0
+ }
+ ]
+ },
+ "backtick-operator": {
+ "class": "RCE-command",
+ "kind": "construct",
+ "fns": [
+ {
+ "fn": "shell_command_expression",
+ "arg": "self",
+ "note": "`...` backtick executes a shell command"
+ }
+ ]
+ },
+ "code-eval": {
+ "class": "RCE-code",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "eval",
+ "arg": 0
+ },
+ {
+ "fn": "assert",
+ "arg": 0,
+ "note": "string arg eval'd pre-8.0"
+ },
+ {
+ "fn": "create_function",
+ "arg": 1,
+ "note": "eval-backed; removed 8.0"
+ },
+ {
+ "fn": "preg_replace",
+ "arg": 0,
+ "note": "/e modifier eval's replacement (removed 7.0); user pattern=ReDoS"
+ },
+ {
+ "fn": "mb_ereg_replace",
+ "arg": 3,
+ "note": "'e' option evals"
+ },
+ {
+ "fn": "mb_eregi_replace",
+ "arg": 3,
+ "note": "'e' option evals"
+ },
+ {
+ "fn": "ReflectionFunction",
+ "arg": 0,
+ "note": "->invoke() runs an arbitrary function"
+ }
+ ]
+ },
+ "dynamic-callable": {
+ "class": "RCE-code-callable",
+ "kind": "call",
+ "note": "arbitrary function/method call if the callable is attacker-controlled (second-order)",
+ "fns": [
+ {
+ "fn": "call_user_func",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "call_user_func_array",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "call_user_method",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "call_user_method_array",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "forward_static_call",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "forward_static_call_array",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "array_map",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "array_filter",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "array_walk",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "array_walk_recursive",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "array_reduce",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "array_diff_uassoc",
+ "arg": "cb:2"
+ },
+ {
+ "fn": "usort",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "uasort",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "uksort",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "preg_replace_callback",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "preg_replace_callback_array",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "register_shutdown_function",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "register_tick_function",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "set_error_handler",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "set_exception_handler",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "spl_autoload_register",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "ob_start",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "iterator_apply",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "filter_var",
+ "arg": 2,
+ "note": "FILTER_CALLBACK option runs a callable"
+ },
+ {
+ "fn": "header_register_callback",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "stream_filter_register",
+ "arg": 1
+ }
+ ]
+ },
+ "deserialization": {
+ "class": "deserialization",
+ "kind": "call",
+ "note": "PHP Object Injection via magic methods (POP chains)",
+ "fns": [
+ {
+ "fn": "unserialize",
+ "arg": 0
+ },
+ {
+ "fn": "yaml_parse",
+ "arg": 0
+ },
+ {
+ "fn": "yaml_parse_file",
+ "arg": 0
+ },
+ {
+ "fn": "yaml_parse_url",
+ "arg": 0
+ },
+ {
+ "fn": "igbinary_unserialize",
+ "arg": 0
+ },
+ {
+ "fn": "msgpack_unserialize",
+ "arg": 0
+ },
+ {
+ "fn": "wddx_deserialize",
+ "arg": 0
+ },
+ {
+ "fn": "session_decode",
+ "arg": 0,
+ "note": "deserializes into $_SESSION"
+ }
+ ]
+ },
+ "file-include": {
+ "class": "LFI-RFI",
+ "kind": "construct",
+ "note": "includes AND executes the path; RFI if allow_url_include",
+ "fns": [
+ {
+ "fn": "include",
+ "arg": "self"
+ },
+ {
+ "fn": "include_once",
+ "arg": "self"
+ },
+ {
+ "fn": "require",
+ "arg": "self"
+ },
+ {
+ "fn": "require_once",
+ "arg": "self"
+ },
+ {
+ "fn": "virtual",
+ "arg": 0,
+ "kind": "call",
+ "note": "Apache subrequest"
+ }
+ ]
+ },
+ "file-read": {
+ "class": "file-read",
+ "kind": "call",
+ "note": "arbitrary file read / path traversal; several also accept URL wrappers (SSRF)",
+ "fns": [
+ {
+ "fn": "file_get_contents",
+ "arg": 0,
+ "note": "URL => SSRF; php://filter => source disclosure"
+ },
+ {
+ "fn": "file",
+ "arg": 0
+ },
+ {
+ "fn": "fopen",
+ "arg": 0,
+ "note": "URL wrappers => SSRF"
+ },
+ {
+ "fn": "readfile",
+ "arg": 0
+ },
+ {
+ "fn": "fpassthru",
+ "arg": 0
+ },
+ {
+ "fn": "fgets",
+ "arg": 0
+ },
+ {
+ "fn": "fgetc",
+ "arg": 0
+ },
+ {
+ "fn": "fread",
+ "arg": 0
+ },
+ {
+ "fn": "fscanf",
+ "arg": 0
+ },
+ {
+ "fn": "parse_ini_file",
+ "arg": 0
+ },
+ {
+ "fn": "parse_ini_string",
+ "arg": 0
+ },
+ {
+ "fn": "highlight_file",
+ "arg": 0
+ },
+ {
+ "fn": "show_source",
+ "arg": 0
+ },
+ {
+ "fn": "readlink",
+ "arg": 0
+ },
+ {
+ "fn": "realpath",
+ "arg": 0
+ },
+ {
+ "fn": "gzfile",
+ "arg": 0
+ },
+ {
+ "fn": "gzopen",
+ "arg": 0
+ },
+ {
+ "fn": "readgzfile",
+ "arg": 0
+ },
+ {
+ "fn": "bzopen",
+ "arg": 0
+ },
+ {
+ "fn": "bzread",
+ "arg": 0
+ },
+ {
+ "fn": "zip_open",
+ "arg": 0
+ },
+ {
+ "fn": "exif_read_data",
+ "arg": 0
+ },
+ {
+ "fn": "exif_thumbnail",
+ "arg": 0
+ },
+ {
+ "fn": "getimagesize",
+ "arg": 0,
+ "note": "URL => SSRF"
+ },
+ {
+ "fn": "getimagesizefromstring",
+ "arg": 0
+ },
+ {
+ "fn": "finfo_file",
+ "arg": 1
+ },
+ {
+ "fn": "mime_content_type",
+ "arg": 0
+ },
+ {
+ "fn": "imagecreatefromjpeg",
+ "arg": 0,
+ "note": "URL => SSRF"
+ },
+ {
+ "fn": "imagecreatefrompng",
+ "arg": 0
+ },
+ {
+ "fn": "imagecreatefromgif",
+ "arg": 0
+ },
+ {
+ "fn": "imagecreatefromwebp",
+ "arg": 0
+ },
+ {
+ "fn": "SplFileObject",
+ "arg": 0,
+ "kind": "method"
+ },
+ {
+ "fn": "md5_file",
+ "arg": 0
+ },
+ {
+ "fn": "sha1_file",
+ "arg": 0
+ },
+ {
+ "fn": "hash_file",
+ "arg": 1
+ },
+ {
+ "fn": "stat",
+ "arg": 0
+ },
+ {
+ "fn": "lstat",
+ "arg": 0
+ },
+ {
+ "fn": "fileperms",
+ "arg": 0
+ }
+ ]
+ },
+ "file-write": {
+ "class": "file-write",
+ "kind": "call",
+ "note": "write/overwrite; RCE if attacker controls path+content of a .php",
+ "fns": [
+ {
+ "fn": "file_put_contents",
+ "arg": 0
+ },
+ {
+ "fn": "fwrite",
+ "arg": 0,
+ "note": "handle arg"
+ },
+ {
+ "fn": "fputs",
+ "arg": 0
+ },
+ {
+ "fn": "fputcsv",
+ "arg": 0
+ },
+ {
+ "fn": "move_uploaded_file",
+ "arg": 1
+ },
+ {
+ "fn": "copy",
+ "arg": 1,
+ "note": "URL src => SSRF; dest => write"
+ },
+ {
+ "fn": "rename",
+ "arg": 1
+ },
+ {
+ "fn": "link",
+ "arg": 1
+ },
+ {
+ "fn": "symlink",
+ "arg": 1
+ },
+ {
+ "fn": "touch",
+ "arg": 0
+ },
+ {
+ "fn": "mkdir",
+ "arg": 0
+ },
+ {
+ "fn": "tempnam",
+ "arg": 0
+ },
+ {
+ "fn": "tmpfile",
+ "arg": "ret"
+ },
+ {
+ "fn": "ftruncate",
+ "arg": 0
+ },
+ {
+ "fn": "vfprintf",
+ "arg": 0
+ },
+ {
+ "fn": "fprintf",
+ "arg": 0
+ }
+ ]
+ },
+ "file-delete": {
+ "class": "file-delete",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "unlink",
+ "arg": 0
+ },
+ {
+ "fn": "rmdir",
+ "arg": 0
+ }
+ ]
+ },
+ "file-perms": {
+ "class": "file-perms",
+ "kind": "call",
+ "note": "privilege/ownership changes on a path",
+ "fns": [
+ {
+ "fn": "chmod",
+ "arg": 0
+ },
+ {
+ "fn": "chown",
+ "arg": 0
+ },
+ {
+ "fn": "chgrp",
+ "arg": 0
+ },
+ {
+ "fn": "lchown",
+ "arg": 0
+ },
+ {
+ "fn": "lchgrp",
+ "arg": 0
+ },
+ {
+ "fn": "umask",
+ "arg": 0
+ }
+ ]
+ },
+ "directory": {
+ "class": "dir-listing-traversal",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "scandir",
+ "arg": 0
+ },
+ {
+ "fn": "opendir",
+ "arg": 0
+ },
+ {
+ "fn": "readdir",
+ "arg": 0
+ },
+ {
+ "fn": "glob",
+ "arg": 0,
+ "note": "glob:// wrapper"
+ },
+ {
+ "fn": "dir",
+ "arg": 0
+ },
+ {
+ "fn": "chdir",
+ "arg": 0
+ },
+ {
+ "fn": "chroot",
+ "arg": 0
+ }
+ ]
+ },
+ "ssrf-network": {
+ "class": "SSRF",
+ "kind": "call",
+ "note": "outbound request to an attacker-chosen host; block link-local/metadata/private",
+ "fns": [
+ {
+ "fn": "fsockopen",
+ "arg": 0
+ },
+ {
+ "fn": "pfsockopen",
+ "arg": 0
+ },
+ {
+ "fn": "stream_socket_client",
+ "arg": 0
+ },
+ {
+ "fn": "stream_socket_server",
+ "arg": 0
+ },
+ {
+ "fn": "curl_exec",
+ "arg": "recv",
+ "note": "URL set via curl_setopt CURLOPT_URL"
+ },
+ {
+ "fn": "curl_multi_exec",
+ "arg": "recv"
+ },
+ {
+ "fn": "curl_setopt",
+ "arg": 2,
+ "note": "CURLOPT_URL"
+ },
+ {
+ "fn": "get_headers",
+ "arg": 0
+ },
+ {
+ "fn": "http_get",
+ "arg": 0
+ },
+ {
+ "fn": "http_post_data",
+ "arg": 0
+ },
+ {
+ "fn": "gethostbyname",
+ "arg": 0
+ },
+ {
+ "fn": "gethostbynamel",
+ "arg": 0
+ },
+ {
+ "fn": "dns_get_record",
+ "arg": 0
+ },
+ {
+ "fn": "checkdnsrr",
+ "arg": 0
+ },
+ {
+ "fn": "getmxrr",
+ "arg": 0
+ },
+ {
+ "fn": "SoapClient",
+ "arg": 0,
+ "kind": "method",
+ "note": "WSDL URL => SSRF/XXE"
+ },
+ {
+ "fn": "stream_context_create",
+ "arg": 0,
+ "note": "can set follow_location/proxy"
+ }
+ ]
+ },
+ "sql": {
+ "class": "SQLi",
+ "kind": "call",
+ "note": "raw SQL \u2014 use parameterized queries",
+ "fns": [
+ {
+ "fn": "mysqli_query",
+ "arg": 1
+ },
+ {
+ "fn": "mysqli_multi_query",
+ "arg": 1
+ },
+ {
+ "fn": "mysqli_real_query",
+ "arg": 1
+ },
+ {
+ "fn": "mysqli_prepare",
+ "arg": 1,
+ "note": "unsafe if concatenated"
+ },
+ {
+ "fn": "mysql_query",
+ "arg": 0
+ },
+ {
+ "fn": "mysql_unbuffered_query",
+ "arg": 0
+ },
+ {
+ "fn": "mysql_db_query",
+ "arg": 1
+ },
+ {
+ "fn": "pg_query",
+ "arg": 1
+ },
+ {
+ "fn": "pg_send_query",
+ "arg": 1
+ },
+ {
+ "fn": "sqlite_query",
+ "arg": 1
+ },
+ {
+ "fn": "sqlite_unbuffered_query",
+ "arg": 1
+ },
+ {
+ "fn": "sqlsrv_query",
+ "arg": 1
+ },
+ {
+ "fn": "oci_parse",
+ "arg": 1
+ },
+ {
+ "fn": "odbc_exec",
+ "arg": 1
+ },
+ {
+ "fn": "odbc_prepare",
+ "arg": 1
+ },
+ {
+ "fn": "db2_exec",
+ "arg": 1
+ },
+ {
+ "fn": "ibase_query",
+ "arg": 1
+ },
+ {
+ "fn": "mssql_query",
+ "arg": 0
+ },
+ {
+ "fn": "maxdb_query",
+ "arg": 1
+ },
+ {
+ "fn": "ingres_query",
+ "arg": 1
+ },
+ {
+ "fn": "query",
+ "arg": 0,
+ "kind": "method",
+ "note": "PDO::query / mysqli::query"
+ },
+ {
+ "fn": "exec",
+ "arg": 0,
+ "kind": "method",
+ "note": "PDO::exec (method form)"
+ }
+ ]
+ },
+ "ldap": {
+ "class": "LDAP-injection",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "ldap_search",
+ "arg": 2
+ },
+ {
+ "fn": "ldap_list",
+ "arg": 2
+ },
+ {
+ "fn": "ldap_read",
+ "arg": 2
+ },
+ {
+ "fn": "ldap_bind",
+ "arg": 1,
+ "note": "auth bypass via crafted DN/empty pw"
+ },
+ {
+ "fn": "ldap_add",
+ "arg": 2
+ },
+ {
+ "fn": "ldap_modify",
+ "arg": 2
+ },
+ {
+ "fn": "ldap_delete",
+ "arg": 1
+ }
+ ]
+ },
+ "xxe-xml": {
+ "class": "XXE",
+ "kind": "call",
+ "note": "external entity expansion => file read/SSRF; disable entities",
+ "fns": [
+ {
+ "fn": "simplexml_load_string",
+ "arg": 0
+ },
+ {
+ "fn": "simplexml_load_file",
+ "arg": 0
+ },
+ {
+ "fn": "xml_parse",
+ "arg": 1
+ },
+ {
+ "fn": "xml_parse_into_struct",
+ "arg": 1
+ },
+ {
+ "fn": "loadXML",
+ "arg": 0,
+ "kind": "method",
+ "note": "DOMDocument::loadXML"
+ },
+ {
+ "fn": "load",
+ "arg": 0,
+ "kind": "method",
+ "note": "DOMDocument::load path/URL"
+ },
+ {
+ "fn": "loadHTMLFile",
+ "arg": 0,
+ "kind": "method"
+ },
+ {
+ "fn": "open",
+ "arg": 0,
+ "kind": "method",
+ "note": "XMLReader::open"
+ },
+ {
+ "fn": "libxml_set_external_entity_loader",
+ "arg": "cb:0"
+ },
+ {
+ "fn": "transformToXml",
+ "arg": 0,
+ "kind": "method",
+ "note": "XSLTProcessor + registerPHPFunctions => RCE"
+ },
+ {
+ "fn": "loadHTML",
+ "arg": 0,
+ "kind": "method",
+ "note": "DOMDocument::loadHTML \u2014 HTML parse; entity/xxe surface"
+ },
+ {
+ "fn": "setEntityLoader",
+ "arg": "cb:0",
+ "kind": "method",
+ "note": "libxml external entity loader"
+ },
+ {
+ "fn": "setParserProperty",
+ "arg": 0,
+ "kind": "method",
+ "note": "XMLReader \u2014 can enable DTD/entity loading"
+ }
+ ]
+ },
+ "xss-output": {
+ "class": "XSS",
+ "kind": "construct",
+ "note": "raw output of unescaped data; escape per context",
+ "fns": [
+ {
+ "fn": "echo",
+ "arg": "self"
+ },
+ {
+ "fn": "print",
+ "arg": "self"
+ }
+ ]
+ },
+ "xss-output-call": {
+ "class": "XSS-or-info",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "printf",
+ "arg": 0,
+ "note": "user format-string bug"
+ },
+ {
+ "fn": "vprintf",
+ "arg": 0
+ },
+ {
+ "fn": "print_r",
+ "arg": 0,
+ "note": "outputs unless 2nd arg true"
+ },
+ {
+ "fn": "var_dump",
+ "arg": "*"
+ },
+ {
+ "fn": "var_export",
+ "arg": 0,
+ "note": "outputs unless 2nd arg true"
+ },
+ {
+ "fn": "exit",
+ "arg": 0
+ },
+ {
+ "fn": "die",
+ "arg": 0
+ },
+ {
+ "fn": "htmlspecialchars_decode",
+ "arg": 0,
+ "note": "UNDOES escaping"
+ },
+ {
+ "fn": "html_entity_decode",
+ "arg": 0,
+ "note": "UNDOES escaping"
+ }
+ ]
+ },
+ "header-redirect": {
+ "class": "header-injection-open-redirect",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "header",
+ "arg": 0,
+ "note": "Location: => open redirect; CRLF pre-5.1.2"
+ },
+ {
+ "fn": "setcookie",
+ "arg": 1
+ },
+ {
+ "fn": "setrawcookie",
+ "arg": 1
+ },
+ {
+ "fn": "session_set_cookie_params",
+ "arg": 0
+ }
+ ]
+ },
+ "variable-injection": {
+ "class": "variable-injection",
+ "kind": "call",
+ "note": "imports attacker keys into scope (register_globals-style)",
+ "fns": [
+ {
+ "fn": "extract",
+ "arg": 0
+ },
+ {
+ "fn": "parse_str",
+ "arg": 0,
+ "note": "1-arg form pollutes caller scope"
+ },
+ {
+ "fn": "mb_parse_str",
+ "arg": 0
+ },
+ {
+ "fn": "import_request_variables",
+ "arg": 0
+ },
+ {
+ "fn": "compact",
+ "arg": "*",
+ "note": "info leak if keys tainted"
+ }
+ ]
+ },
+ "regex-redos": {
+ "class": "ReDoS-or-injection",
+ "kind": "call",
+ "note": "catastrophic backtracking with a user pattern; deprecated ereg",
+ "fns": [
+ {
+ "fn": "preg_match",
+ "arg": 0,
+ "note": "user PATTERN => ReDoS"
+ },
+ {
+ "fn": "preg_match_all",
+ "arg": 0
+ },
+ {
+ "fn": "preg_split",
+ "arg": 0
+ },
+ {
+ "fn": "preg_grep",
+ "arg": 0
+ },
+ {
+ "fn": "ereg",
+ "arg": 0
+ },
+ {
+ "fn": "eregi",
+ "arg": 0
+ },
+ {
+ "fn": "ereg_replace",
+ "arg": 0
+ },
+ {
+ "fn": "eregi_replace",
+ "arg": 0
+ },
+ {
+ "fn": "mb_ereg",
+ "arg": 0
+ }
+ ]
+ },
+ "mail-injection": {
+ "class": "mail-header-injection",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "mail",
+ "arg": 3,
+ "note": "additional_headers => header injection"
+ },
+ {
+ "fn": "mb_send_mail",
+ "arg": 3
+ },
+ {
+ "fn": "imap_mail",
+ "arg": 3
+ },
+ {
+ "fn": "ezmlm_hash",
+ "arg": 0
+ }
+ ]
+ },
+ "weak-crypto": {
+ "class": "weak-crypto",
+ "kind": "call",
+ "note": "fast/broken for passwords/tokens/integrity",
+ "fns": [
+ {
+ "fn": "md5",
+ "arg": 0
+ },
+ {
+ "fn": "sha1",
+ "arg": 0
+ },
+ {
+ "fn": "crc32",
+ "arg": 0
+ },
+ {
+ "fn": "crypt",
+ "arg": 0,
+ "note": "weak without proper salt/algo"
+ },
+ {
+ "fn": "hash",
+ "arg": 1,
+ "note": "md5/sha1 for secrets"
+ },
+ {
+ "fn": "mcrypt_encrypt",
+ "arg": 0,
+ "note": "deprecated, ECB default"
+ },
+ {
+ "fn": "mcrypt_decrypt",
+ "arg": 0
+ }
+ ]
+ },
+ "weak-random": {
+ "class": "weak-random",
+ "kind": "call",
+ "note": "predictable; unfit for tokens/nonces/passwords",
+ "fns": [
+ {
+ "fn": "rand",
+ "arg": "ret"
+ },
+ {
+ "fn": "mt_rand",
+ "arg": "ret"
+ },
+ {
+ "fn": "mt_srand",
+ "arg": 0
+ },
+ {
+ "fn": "srand",
+ "arg": 0
+ },
+ {
+ "fn": "uniqid",
+ "arg": "ret"
+ },
+ {
+ "fn": "lcg_value",
+ "arg": "ret"
+ },
+ {
+ "fn": "str_shuffle",
+ "arg": 0
+ },
+ {
+ "fn": "array_rand",
+ "arg": 0
+ },
+ {
+ "fn": "shuffle",
+ "arg": 0
+ }
+ ]
+ },
+ "info-disclosure": {
+ "class": "info-disclosure",
+ "kind": "call",
+ "fns": [
+ {
+ "fn": "phpinfo",
+ "arg": "*"
+ },
+ {
+ "fn": "debug_zval_refcount",
+ "arg": 0
+ },
+ {
+ "fn": "debug_backtrace",
+ "arg": "ret"
+ },
+ {
+ "fn": "debug_print_backtrace",
+ "arg": "*"
+ },
+ {
+ "fn": "getenv",
+ "arg": 0
+ },
+ {
+ "fn": "get_cfg_var",
+ "arg": 0
+ },
+ {
+ "fn": "ini_get_all",
+ "arg": "ret"
+ },
+ {
+ "fn": "get_defined_vars",
+ "arg": "ret"
+ },
+ {
+ "fn": "getmypid",
+ "arg": "ret"
+ },
+ {
+ "fn": "posix_getpwuid",
+ "arg": 0
+ },
+ {
+ "fn": "posix_getgrgid",
+ "arg": 0
+ },
+ {
+ "fn": "posix_getpwnam",
+ "arg": 0
+ }
+ ]
+ },
+ "runtime-config": {
+ "class": "config-tamper",
+ "kind": "call",
+ "note": "changes PHP/security settings at runtime",
+ "fns": [
+ {
+ "fn": "ini_set",
+ "arg": 0
+ },
+ {
+ "fn": "ini_alter",
+ "arg": 0
+ },
+ {
+ "fn": "ini_restore",
+ "arg": 0
+ },
+ {
+ "fn": "putenv",
+ "arg": 0
+ },
+ {
+ "fn": "set_include_path",
+ "arg": 0
+ },
+ {
+ "fn": "apache_setenv",
+ "arg": 0
+ },
+ {
+ "fn": "error_reporting",
+ "arg": 0
+ },
+ {
+ "fn": "assert_options",
+ "arg": 0
+ },
+ {
+ "fn": "setlocale",
+ "arg": 1
+ }
+ ]
+ },
+ "process-control": {
+ "class": "process-control",
+ "kind": "call",
+ "note": "signal/priv/process manipulation",
+ "fns": [
+ {
+ "fn": "posix_kill",
+ "arg": 0
+ },
+ {
+ "fn": "posix_setuid",
+ "arg": 0
+ },
+ {
+ "fn": "posix_setgid",
+ "arg": 0
+ },
+ {
+ "fn": "posix_seteuid",
+ "arg": 0
+ },
+ {
+ "fn": "pcntl_fork",
+ "arg": "*"
+ },
+ {
+ "fn": "pcntl_signal",
+ "arg": "cb:1"
+ },
+ {
+ "fn": "proc_nice",
+ "arg": 0
+ },
+ {
+ "fn": "proc_terminate",
+ "arg": 0
+ },
+ {
+ "fn": "apache_child_terminate",
+ "arg": "*"
+ }
+ ]
+ },
+ "reflection-invoke": {
+ "class": "dynamic-invoke",
+ "kind": "method",
+ "note": "instantiate/invoke arbitrary class/method (gadget reach)",
+ "fns": [
+ {
+ "fn": "newInstance",
+ "arg": "*",
+ "note": "ReflectionClass::newInstance"
+ },
+ {
+ "fn": "newInstanceArgs",
+ "arg": "*"
+ },
+ {
+ "fn": "invoke",
+ "arg": "*",
+ "note": "Reflection*::invoke"
+ },
+ {
+ "fn": "invokeArgs",
+ "arg": "*"
+ },
+ {
+ "fn": "setAccessible",
+ "arg": 0,
+ "note": "bypasses visibility"
+ }
+ ]
+ },
+ "type-juggling": {
+ "class": "auth-bypass-type-juggle",
+ "kind": "call",
+ "note": "loose comparison / magic-hash / non-strict search => auth bypass",
+ "fns": [
+ {
+ "fn": "in_array",
+ "arg": 2,
+ "note": "non-strict (3rd arg false) => 0==string"
+ },
+ {
+ "fn": "array_search",
+ "arg": 2,
+ "note": "non-strict"
+ },
+ {
+ "fn": "strcmp",
+ "arg": 0,
+ "note": "array arg returns NULL, NULL==0 true"
+ },
+ {
+ "fn": "strcasecmp",
+ "arg": 0
+ },
+ {
+ "fn": "strncmp",
+ "arg": 0
+ },
+ {
+ "fn": "hash_equals",
+ "arg": 0,
+ "note": "SAFE \u2014 the correct constant-time compare"
+ }
+ ]
+ },
+ "archive-extraction": {
+ "class": "zip-slip-path-traversal",
+ "kind": "method",
+ "note": "extracting an archive writes entry paths; a `../` entry escapes the target dir (Zip Slip). Also symlink entries.",
+ "fns": [
+ {
+ "fn": "extractTo",
+ "arg": 0,
+ "note": "ZipArchive/PharData::extractTo \u2014 writes each entry; ../ escapes dir"
+ },
+ {
+ "fn": "addFile",
+ "arg": 0,
+ "note": "path added to archive"
+ },
+ {
+ "fn": "addFromString",
+ "arg": 0,
+ "note": "entry name is attacker-influenced"
+ },
+ {
+ "fn": "buildFromDirectory",
+ "arg": 0,
+ "kind": "method",
+ "note": "PharData"
+ },
+ {
+ "fn": "convertToExecutable",
+ "arg": "*",
+ "kind": "method",
+ "note": "PharData -> executable phar"
+ }
+ ]
+ },
+ "image-processing": {
+ "class": "image-rce-ssrf",
+ "kind": "method",
+ "note": "Imagick reads by URL (SSRF) and historically had delegate RCE (ImageTragick, MVG/MSL); GD from-URL is SSRF.",
+ "fns": [
+ {
+ "fn": "readImage",
+ "arg": 0,
+ "note": "Imagick::readImage \u2014 URL => SSRF; format abuse"
+ },
+ {
+ "fn": "readImageBlob",
+ "arg": 0
+ },
+ {
+ "fn": "readImageFile",
+ "arg": 0
+ },
+ {
+ "fn": "setImageFormat",
+ "arg": 0
+ }
+ ]
+ }
}
-}
+}
\ No newline at end of file
diff --git a/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_patterns.json b/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_patterns.json
index 7608538ad..87da3d6d7 100644
--- a/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_patterns.json
+++ b/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_patterns.json
@@ -1,129 +1,286 @@
{
"meta": {
"title": "PHP dangerous PATTERNS (non-function vulnerability classes)",
- "purpose": "Language-level, input-shape, and semantic vulnerabilities that are NOT a single dangerous function call — the half a sink catalog misses. Each pattern says HOW to detect it (ast=node pattern, regex, query=XERJ, manual=reasoning) so the audit can claim coverage of patterns too.",
- "detect_kinds": {"ast":"tree-sitter node pattern", "regex":"exact source regex", "query":"XERJ index query over facts", "manual":"needs agent reasoning / schema / runtime"}
+ "purpose": "Language-level, input-shape, and semantic vulnerabilities that are NOT a single dangerous function call \u2014 the half a sink catalog misses. Each pattern says HOW to detect it (ast=node pattern, regex, query=XERJ, manual=reasoning) so the audit can claim coverage of patterns too.",
+ "detect_kinds": {
+ "ast": "tree-sitter node pattern",
+ "regex": "exact source regex",
+ "query": "XERJ index query over facts",
+ "manual": "needs agent reasoning / schema / runtime"
+ }
},
"patterns": [
- {"id":"loose-eq","class":"type-juggling","title":"Loose == / != comparison",
- "attack":"'0e123'==<'0e456' (magic hash), '0'==false, null==0, '1abc'==1, 'abc'==0 (pre-PHP8). Auth bypass when comparing secrets/hashes/tokens with == instead of ===.",
- "detect":"ast: binary_expression operator in {==,!=,<>}. Flag when either side is a hash()/md5()/sha1() call, a token/password/hmac variable, or a request value.",
- "safe":"=== / !== ; hash_equals() for secrets; password_verify() for passwords."},
- {"id":"switch-loose","class":"type-juggling","title":"switch() uses loose comparison",
- "attack":"switch($_GET['role']){case 0: admin...} — '0abc' or true loosely matches case 0.",
- "detect":"ast: switch_statement whose condition is a request value or unhashed string.",
- "safe":"match(true){...} (strict) or cast+validate the switch value first."},
- {"id":"magic-hash","class":"type-juggling","title":"Magic-hash comparison (0e...)",
- "attack":"md5('240610708')=='0e462097431906509019562988736854'; two 0e-prefixed hashes are equal under ==. Password/token bypass.",
- "detect":"ast+manual: == between two hash outputs, or hash compared to a user value with ==.",
- "safe":"hash_equals(); never == on hashes."},
- {"id":"strcmp-array","class":"type-juggling","title":"strcmp/strcasecmp/strncmp with array arg returns NULL",
- "attack":"?pw[]=x makes $_GET['pw'] an array; strcmp(array,$secret) returns NULL (+warning); if(strcmp(...)==0) => NULL==0 => TRUE => bypass.",
- "detect":"ast+query: strcmp-family call where an argument traces to a request value with no is_string()/is_scalar() guard.",
- "safe":"validate is_string() first; use hash_equals; check ===0 not ==0."},
- {"id":"in-array-loose","class":"type-juggling","title":"in_array/array_search without strict=true",
- "attack":"in_array('1abc',[1,2,3]) is TRUE loosely; in_array(0,['a','b']) TRUE pre-PHP8. Allow-list bypass.",
- "detect":"ast: in_array/array_search call with <3 args (strict omitted) or 3rd arg falsey.",
- "safe":"in_array($x,$arr,true)."},
- {"id":"array-injection","class":"input-shape","title":"Array injection via param[]=",
- "attack":"?login[]=a or login[]=a in POST makes $_POST['login'] an ARRAY. Breaks string-typed sinks: preg_match(returns false), strcmp/hash(NULL), sql (Array->'Array'), and bypasses is_string()-less checks. Also DoS/logic.",
- "detect":"query+manual: request params used by string functions/SQL/regex without a preceding is_string()/is_scalar()/(string) cast or (array) normalisation.",
- "safe":"cast/validate every request param to the expected type; reject arrays where scalars expected."},
- {"id":"sql-truncation","class":"sql-semantic","title":"SQL column truncation (silent, non-STRICT mode)",
- "attack":"Register user 'admin<55 spaces>x'; MySQL (non-strict) truncates to column length -> stored as 'admin' -> duplicate/overwrite admin account.",
- "detect":"manual+schema: INSERT/UPDATE of a user-controlled string into a VARCHAR(N) unique column without an explicit length check; requires column lengths.",
- "safe":"validate max length before insert; STRICT_ALL_TABLES; unique+trim checks."},
- {"id":"charset-sqli","class":"sql-semantic","title":"Multibyte charset SQLi (addslashes/GBK bypass)",
- "attack":"In GBK/Big5, 0xbf27 + addslashes -> 0xbf5c27 which is a valid multibyte char + a free quote -> breaks out. Defeats addslashes/manual escaping.",
- "detect":"manual: manual escaping (addslashes/mysql_real_escape_string) with a connection charset set to a multibyte set instead of set_charset('utf8mb4').",
- "safe":"parameterized queries; mysqli::set_charset('utf8mb4')."},
- {"id":"order-by-inj","class":"sql-semantic","title":"ORDER BY / LIMIT / identifier injection",
- "attack":"ORDER BY $_GET['sort'] — identifiers can't be bound with placeholders; direct concat = injection.",
- "detect":"regex+query: ORDER BY/GROUP BY/LIMIT/table/column built from a request value (prepare can't bind these).",
- "safe":"allow-list of column names; map input->fixed identifier."},
- {"id":"second-order","class":"injection-flow","title":"Second-order injection (stored then used raw)",
- "attack":"Value stored safely, later read from DB and concatenated into SQL/HTML/cmd without re-escaping. Taint 'launders' through storage.",
- "detect":"manual: a value read from DB/option/meta reaching a sink; the taint graph must treat storage reads as tainted for stored-then-used flows.",
- "safe":"escape at every sink, not just at input; treat DB reads as untrusted."},
- {"id":"mass-assignment","class":"input-shape","title":"Mass assignment / register_globals emulation",
- "attack":"extract($_REQUEST) or foreach($_POST as $k=>$v){$$k=$v;} or $obj->fill($_POST) overwrites vars/columns (e.g. is_admin).",
- "detect":"ast: extract() / parse_str(1-arg) / variable_variable assignment ($$k) fed by a request array; object hydration from a raw request array.",
- "safe":"explicit allow-list of fields; never bulk-assign request data."},
- {"id":"var-variable","class":"input-shape","title":"Variable variables $$x",
- "attack":"$$key where key is request-controlled -> arbitrary variable overwrite / info leak.",
- "detect":"ast: variable_name whose name is itself a variable (dynamic_variable_name) fed by request.",
- "safe":"array lookups with an allow-list, not $$."},
- {"id":"null-byte","class":"input-shape","title":"Null-byte / poison-byte truncation",
- "attack":"?file=secret.php%00.jpg truncates at NUL in include/file ops (pre-5.3.4); also %00 in strings splitting validators.",
- "detect":"manual+regex: file/path/validator using a request value without an explicit NUL/`\\0` rejection; older PHP targets.",
- "safe":"reject \\0; PHP>=5.3.4; realpath+allow-list."},
- {"id":"path-traversal","class":"input-shape","title":"Path traversal encodings",
- "attack":"../, ..%2f, %2e%2e%2f, ....//, absolute-path override, unicode dot. Escapes an intended base dir.",
- "detect":"query+manual: file op / include with a request-derived path lacking realpath()-under-base or basename()+allow-list.",
- "safe":"realpath() then verify str_starts_with(base); basename+allow-list."},
- {"id":"phar-deser","class":"deserialization","title":"phar:// deserialization",
- "attack":"phar://attacker.jpg triggers unserialize of the Phar metadata via ANY file op (file_exists/getimagesize/fopen) on an attacker-controlled path -> POP chain.",
- "detect":"query+manual: any file op whose path can start with a user-controlled wrapper/scheme; combined with a gadget class present.",
- "safe":"validate/deny wrappers; Phar::interceptFileFuncs; check scheme."},
- {"id":"toctou","class":"race","title":"TOCTOU file race (check-then-use)",
- "attack":"is_writable($f)/file_exists($f) then fopen/unlink($f) — attacker swaps the path (symlink) between check and use.",
- "detect":"ast+manual: a file predicate on a path followed by an operation on the same path in a privileged context.",
- "safe":"operate on fds (O_NOFOLLOW), atomic ops, avoid predictable temp paths."},
- {"id":"timing-compare","class":"crypto-logic","title":"Non-constant-time secret comparison",
- "attack":"if($mac == $expected) leaks byte-by-byte timing -> MAC/token forgery; also juggling.",
- "detect":"ast: == / != / strcmp on a variable named mac/sig/hmac/token/hash/nonce.",
- "safe":"hash_equals($known,$user)."},
- {"id":"is-numeric-bypass","class":"type-confusion","title":"is_numeric / intval / filter_var bypass",
- "attack":"is_numeric('0x1A'|'1e3'|' 12'|'+9') can be TRUE; (int)'123abc'=123; filter_var URL/EMAIL accepts javascript:, unusual hosts; is_numeric hex opens ID confusion.",
- "detect":"ast+manual: is_numeric/ctype_digit/intval/(int)/filter_var used as the ONLY validation on a security-relevant value.",
- "safe":"ctype_digit for digit-strings; FILTER + explicit flags; compare after cast+re-render."},
- {"id":"loose-empty-isset","class":"logic","title":"empty()/isset() logic pitfalls",
- "attack":"empty('0') and empty(0) are TRUE -> a legit '0' input treated as missing; isset() true for null-coalesced; == in guards.",
- "detect":"manual: empty()/! on a value where '0'/0/'' are valid, in an auth/authorization/branch decision.",
- "safe":"=== '' / array_key_exists / isset with explicit checks."},
- {"id":"regex-anchor-bypass","class":"regex","title":"Regex anchor / multiline / dot bypass",
- "attack":"preg_match('/^allowed$/',$x) — $ matches before a trailing \\n; with /m, ^/$ per line; . doesn't match \\n so payload on a second line bypasses. Also \\A\\z vs ^$.",
- "detect":"regex+manual: a validation preg_match using ^...$ (not \\A...\\z) on a request value; check for /m and missing /s or /D.",
- "safe":"\\A...\\z anchors; /D; reject newlines."},
- {"id":"pcre-backtrack","class":"regex","title":"PCRE returns false on backtrack-limit (not 0)",
- "attack":"On catastrophic backtracking preg_match returns FALSE, not 0; if(preg_match($bad,$x)) treats false as no-match, but code checking ==1 or !==false differs -> validator bypass + ReDoS.",
- "detect":"ast+manual: preg_match result used in a boolean/auth branch without ===1 / preg_last_error() check; user-influenced pattern or subject length.",
- "safe":"check ===1; bound input length; pcre.backtrack_limit."},
- {"id":"session-fixation","class":"auth-session","title":"Session fixation (no regenerate on auth)",
- "attack":"Attacker sets victim's session id pre-login; app doesn't session_regenerate_id(true) after auth -> session hijack.",
- "detect":"query+manual: a login/privilege-elevation path with no session_regenerate_id(true) after establishing identity.",
- "safe":"session_regenerate_id(true) on every privilege change."},
- {"id":"cookie-flags","class":"auth-session","title":"Missing cookie security flags",
- "attack":"setcookie without HttpOnly/Secure/SameSite -> XSS theft / CSRF / MITM.",
- "detect":"ast: setcookie/setrawcookie/session_set_cookie_params with options lacking httponly|secure|samesite.",
- "safe":"set HttpOnly+Secure+SameSite=Lax/Strict."},
- {"id":"csrf-absence","class":"auth-logic","title":"State change without CSRF/nonce",
- "attack":"A state-changing handler reachable without a verified nonce/token -> CSRF.",
- "detect":"query: entry point performing a state change with NO nonce/token verification on the path (absence property — see the authz graph).",
- "safe":"verify a per-user, per-action nonce/CSRF token on every state change."},
- {"id":"xss-context","class":"xss","title":"Wrong-context / incomplete output escaping",
- "attack":"htmlspecialchars without ENT_QUOTES inside an attribute; esc_html on a value placed in JS/URL/CSS context; double-encoding; json in <script> without JSON_HEX_TAG.",
- "detect":"manual: an escaper whose context (HTML text/attr/JS/URL/CSS) does not match the output position.",
- "safe":"context-correct escaper (attr vs html vs js vs url); ENT_QUOTES; JSON_HEX_* in <script>."},
- {"id":"open-redirect","class":"redirect","title":"Open redirect",
- "attack":"header('Location: '.$_GET['next']) or redirect($url) to //evil.com, \\evil, javascript:.",
- "detect":"ast+query: header('Location'..)/redirect with a request-derived target lacking an allow-list/same-host check.",
- "safe":"allow-list hosts; wp_safe_redirect; strip scheme/host."},
- {"id":"host-header","class":"trust-boundary","title":"Host / X-Forwarded trust",
- "attack":"Using $_SERVER['HTTP_HOST'] / X-Forwarded-For / X-Forwarded-Host for links, password-reset URLs, or IP allow-lists -> poisoning/spoof.",
- "detect":"regex: $_SERVER['HTTP_HOST'|'HTTP_X_FORWARDED_*'] used in a URL, email, or access decision.",
- "safe":"fixed site URL config; trust only vetted proxies."},
- {"id":"error-suppression","class":"footgun","title":"@ error suppression hiding failures",
- "attack":"@unserialize / @file_get_contents / @$_GET hides errors that mask a security-relevant failure or type issue.",
- "detect":"ast: error_suppression_expression (@) on a security-relevant call.",
- "safe":"handle errors explicitly."},
- {"id":"upload-exec","class":"file-upload","title":"Unrestricted file upload -> exec",
- "attack":"Attacker uploads shell.php / .phtml / double-ext shell.php.jpg / MIME-spoofed / .htaccess; served from an executable dir.",
- "detect":"manual+query: move_uploaded_file/write into a web-served dir with extension/MIME derived from the upload and no allow-list / non-exec storage.",
- "safe":"random name; extension+content allow-list; store outside web root / non-exec."},
- {"id":"user-enum","class":"info-leak","title":"User enumeration (distinct response/timing)",
- "attack":"Login/reset returns different message or timing for valid vs invalid users -> account enumeration.",
- "detect":"manual: auth/reset flows with user-existence-dependent branches in message or timing.",
- "safe":"uniform responses and timing."}
+ {
+ "id": "loose-eq",
+ "class": "type-juggling",
+ "title": "Loose == / != comparison",
+ "attack": "'0e123'==<'0e456' (magic hash), '0'==false, null==0, '1abc'==1, 'abc'==0 (pre-PHP8). Auth bypass when comparing secrets/hashes/tokens with == instead of ===.",
+ "detect": "ast: binary_expression operator in {==,!=,<>}. Flag when either side is a hash()/md5()/sha1() call, a token/password/hmac variable, or a request value.",
+ "safe": "=== / !== ; hash_equals() for secrets; password_verify() for passwords."
+ },
+ {
+ "id": "switch-loose",
+ "class": "type-juggling",
+ "title": "switch() uses loose comparison",
+ "attack": "switch($_GET['role']){case 0: admin...} \u2014 '0abc' or true loosely matches case 0.",
+ "detect": "ast: switch_statement whose condition is a request value or unhashed string.",
+ "safe": "match(true){...} (strict) or cast+validate the switch value first."
+ },
+ {
+ "id": "magic-hash",
+ "class": "type-juggling",
+ "title": "Magic-hash comparison (0e...)",
+ "attack": "md5('240610708')=='0e462097431906509019562988736854'; two 0e-prefixed hashes are equal under ==. Password/token bypass.",
+ "detect": "ast+manual: == between two hash outputs, or hash compared to a user value with ==.",
+ "safe": "hash_equals(); never == on hashes."
+ },
+ {
+ "id": "strcmp-array",
+ "class": "type-juggling",
+ "title": "strcmp/strcasecmp/strncmp with array arg returns NULL",
+ "attack": "?pw[]=x makes $_GET['pw'] an array; strcmp(array,$secret) returns NULL (+warning); if(strcmp(...)==0) => NULL==0 => TRUE => bypass.",
+ "detect": "ast+query: strcmp-family call where an argument traces to a request value with no is_string()/is_scalar() guard.",
+ "safe": "validate is_string() first; use hash_equals; check ===0 not ==0."
+ },
+ {
+ "id": "in-array-loose",
+ "class": "type-juggling",
+ "title": "in_array/array_search without strict=true",
+ "attack": "in_array('1abc',[1,2,3]) is TRUE loosely; in_array(0,['a','b']) TRUE pre-PHP8. Allow-list bypass.",
+ "detect": "ast: in_array/array_search call with <3 args (strict omitted) or 3rd arg falsey.",
+ "safe": "in_array($x,$arr,true)."
+ },
+ {
+ "id": "array-injection",
+ "class": "input-shape",
+ "title": "Array injection via param[]=",
+ "attack": "?login[]=a or login[]=a in POST makes $_POST['login'] an ARRAY. Breaks string-typed sinks: preg_match(returns false), strcmp/hash(NULL), sql (Array->'Array'), and bypasses is_string()-less checks. Also DoS/logic.",
+ "detect": "query+manual: request params used by string functions/SQL/regex without a preceding is_string()/is_scalar()/(string) cast or (array) normalisation.",
+ "safe": "cast/validate every request param to the expected type; reject arrays where scalars expected."
+ },
+ {
+ "id": "sql-truncation",
+ "class": "sql-semantic",
+ "title": "SQL column truncation (silent, non-STRICT mode)",
+ "attack": "Register user 'admin<55 spaces>x'; MySQL (non-strict) truncates to column length -> stored as 'admin' -> duplicate/overwrite admin account.",
+ "detect": "manual+schema: INSERT/UPDATE of a user-controlled string into a VARCHAR(N) unique column without an explicit length check; requires column lengths.",
+ "safe": "validate max length before insert; STRICT_ALL_TABLES; unique+trim checks."
+ },
+ {
+ "id": "charset-sqli",
+ "class": "sql-semantic",
+ "title": "Multibyte charset SQLi (addslashes/GBK bypass)",
+ "attack": "In GBK/Big5, 0xbf27 + addslashes -> 0xbf5c27 which is a valid multibyte char + a free quote -> breaks out. Defeats addslashes/manual escaping.",
+ "detect": "manual: manual escaping (addslashes/mysql_real_escape_string) with a connection charset set to a multibyte set instead of set_charset('utf8mb4').",
+ "safe": "parameterized queries; mysqli::set_charset('utf8mb4')."
+ },
+ {
+ "id": "order-by-inj",
+ "class": "sql-semantic",
+ "title": "ORDER BY / LIMIT / identifier injection",
+ "attack": "ORDER BY $_GET['sort'] \u2014 identifiers can't be bound with placeholders; direct concat = injection.",
+ "detect": "regex+query: ORDER BY/GROUP BY/LIMIT/table/column built from a request value (prepare can't bind these).",
+ "safe": "allow-list of column names; map input->fixed identifier."
+ },
+ {
+ "id": "second-order",
+ "class": "injection-flow",
+ "title": "Second-order injection (stored then used raw)",
+ "attack": "Value stored safely, later read from DB and concatenated into SQL/HTML/cmd without re-escaping. Taint 'launders' through storage.",
+ "detect": "manual: a value read from DB/option/meta reaching a sink; the taint graph must treat storage reads as tainted for stored-then-used flows.",
+ "safe": "escape at every sink, not just at input; treat DB reads as untrusted."
+ },
+ {
+ "id": "mass-assignment",
+ "class": "input-shape",
+ "title": "Mass assignment / register_globals emulation",
+ "attack": "extract($_REQUEST) or foreach($_POST as $k=>$v){$$k=$v;} or $obj->fill($_POST) overwrites vars/columns (e.g. is_admin).",
+ "detect": "ast: extract() / parse_str(1-arg) / variable_variable assignment ($$k) fed by a request array; object hydration from a raw request array.",
+ "safe": "explicit allow-list of fields; never bulk-assign request data."
+ },
+ {
+ "id": "var-variable",
+ "class": "input-shape",
+ "title": "Variable variables $$x",
+ "attack": "$$key where key is request-controlled -> arbitrary variable overwrite / info leak.",
+ "detect": "ast: variable_name whose name is itself a variable (dynamic_variable_name) fed by request.",
+ "safe": "array lookups with an allow-list, not $$."
+ },
+ {
+ "id": "null-byte",
+ "class": "input-shape",
+ "title": "Null-byte / poison-byte truncation",
+ "attack": "?file=secret.php%00.jpg truncates at NUL in include/file ops (pre-5.3.4); also %00 in strings splitting validators.",
+ "detect": "manual+regex: file/path/validator using a request value without an explicit NUL/`\\0` rejection; older PHP targets.",
+ "safe": "reject \\0; PHP>=5.3.4; realpath+allow-list."
+ },
+ {
+ "id": "path-traversal",
+ "class": "input-shape",
+ "title": "Path traversal encodings",
+ "attack": "../, ..%2f, %2e%2e%2f, ....//, absolute-path override, unicode dot. Escapes an intended base dir.",
+ "detect": "query+manual: file op / include with a request-derived path lacking realpath()-under-base or basename()+allow-list.",
+ "safe": "realpath() then verify str_starts_with(base); basename+allow-list."
+ },
+ {
+ "id": "phar-deser",
+ "class": "deserialization",
+ "title": "phar:// deserialization",
+ "attack": "phar://attacker.jpg triggers unserialize of the Phar metadata via ANY file op (file_exists/getimagesize/fopen) on an attacker-controlled path -> POP chain.",
+ "detect": "query+manual: any file op whose path can start with a user-controlled wrapper/scheme; combined with a gadget class present.",
+ "safe": "validate/deny wrappers; Phar::interceptFileFuncs; check scheme."
+ },
+ {
+ "id": "toctou",
+ "class": "race",
+ "title": "TOCTOU file race (check-then-use)",
+ "attack": "is_writable($f)/file_exists($f) then fopen/unlink($f) \u2014 attacker swaps the path (symlink) between check and use.",
+ "detect": "ast+manual: a file predicate on a path followed by an operation on the same path in a privileged context.",
+ "safe": "operate on fds (O_NOFOLLOW), atomic ops, avoid predictable temp paths."
+ },
+ {
+ "id": "timing-compare",
+ "class": "crypto-logic",
+ "title": "Non-constant-time secret comparison",
+ "attack": "if($mac == $expected) leaks byte-by-byte timing -> MAC/token forgery; also juggling.",
+ "detect": "ast: == / != / strcmp on a variable named mac/sig/hmac/token/hash/nonce.",
+ "safe": "hash_equals($known,$user)."
+ },
+ {
+ "id": "is-numeric-bypass",
+ "class": "type-confusion",
+ "title": "is_numeric / intval / filter_var bypass",
+ "attack": "is_numeric('0x1A'|'1e3'|' 12'|'+9') can be TRUE; (int)'123abc'=123; filter_var URL/EMAIL accepts javascript:, unusual hosts; is_numeric hex opens ID confusion.",
+ "detect": "ast+manual: is_numeric/ctype_digit/intval/(int)/filter_var used as the ONLY validation on a security-relevant value.",
+ "safe": "ctype_digit for digit-strings; FILTER + explicit flags; compare after cast+re-render."
+ },
+ {
+ "id": "loose-empty-isset",
+ "class": "logic",
+ "title": "empty()/isset() logic pitfalls",
+ "attack": "empty('0') and empty(0) are TRUE -> a legit '0' input treated as missing; isset() true for null-coalesced; == in guards.",
+ "detect": "manual: empty()/! on a value where '0'/0/'' are valid, in an auth/authorization/branch decision.",
+ "safe": "=== '' / array_key_exists / isset with explicit checks."
+ },
+ {
+ "id": "regex-anchor-bypass",
+ "class": "regex",
+ "title": "Regex anchor / multiline / dot bypass",
+ "attack": "preg_match('/^allowed$/',$x) \u2014 $ matches before a trailing \\n; with /m, ^/$ per line; . doesn't match \\n so payload on a second line bypasses. Also \\A\\z vs ^$.",
+ "detect": "regex+manual: a validation preg_match using ^...$ (not \\A...\\z) on a request value; check for /m and missing /s or /D.",
+ "safe": "\\A...\\z anchors; /D; reject newlines."
+ },
+ {
+ "id": "pcre-backtrack",
+ "class": "regex",
+ "title": "PCRE returns false on backtrack-limit (not 0)",
+ "attack": "On catastrophic backtracking preg_match returns FALSE, not 0; if(preg_match($bad,$x)) treats false as no-match, but code checking ==1 or !==false differs -> validator bypass + ReDoS.",
+ "detect": "ast+manual: preg_match result used in a boolean/auth branch without ===1 / preg_last_error() check; user-influenced pattern or subject length.",
+ "safe": "check ===1; bound input length; pcre.backtrack_limit."
+ },
+ {
+ "id": "session-fixation",
+ "class": "auth-session",
+ "title": "Session fixation (no regenerate on auth)",
+ "attack": "Attacker sets victim's session id pre-login; app doesn't session_regenerate_id(true) after auth -> session hijack.",
+ "detect": "query+manual: a login/privilege-elevation path with no session_regenerate_id(true) after establishing identity.",
+ "safe": "session_regenerate_id(true) on every privilege change."
+ },
+ {
+ "id": "cookie-flags",
+ "class": "auth-session",
+ "title": "Missing cookie security flags",
+ "attack": "setcookie without HttpOnly/Secure/SameSite -> XSS theft / CSRF / MITM.",
+ "detect": "ast: setcookie/setrawcookie/session_set_cookie_params with options lacking httponly|secure|samesite.",
+ "safe": "set HttpOnly+Secure+SameSite=Lax/Strict."
+ },
+ {
+ "id": "csrf-absence",
+ "class": "auth-logic",
+ "title": "State change without CSRF/nonce",
+ "attack": "A state-changing handler reachable without a verified nonce/token -> CSRF.",
+ "detect": "query: entry point performing a state change with NO nonce/token verification on the path (absence property \u2014 see the authz graph).",
+ "safe": "verify a per-user, per-action nonce/CSRF token on every state change."
+ },
+ {
+ "id": "xss-context",
+ "class": "xss",
+ "title": "Wrong-context / incomplete output escaping",
+ "attack": "htmlspecialchars without ENT_QUOTES inside an attribute; esc_html on a value placed in JS/URL/CSS context; double-encoding; json in <script> without JSON_HEX_TAG.",
+ "detect": "manual: an escaper whose context (HTML text/attr/JS/URL/CSS) does not match the output position.",
+ "safe": "context-correct escaper (attr vs html vs js vs url); ENT_QUOTES; JSON_HEX_* in <script>."
+ },
+ {
+ "id": "open-redirect",
+ "class": "redirect",
+ "title": "Open redirect",
+ "attack": "header('Location: '.$_GET['next']) or redirect($url) to //evil.com, \\evil, javascript:.",
+ "detect": "ast+query: header('Location'..)/redirect with a request-derived target lacking an allow-list/same-host check.",
+ "safe": "allow-list hosts; wp_safe_redirect; strip scheme/host."
+ },
+ {
+ "id": "host-header",
+ "class": "trust-boundary",
+ "title": "Host / X-Forwarded trust",
+ "attack": "Using $_SERVER['HTTP_HOST'] / X-Forwarded-For / X-Forwarded-Host for links, password-reset URLs, or IP allow-lists -> poisoning/spoof.",
+ "detect": "regex: $_SERVER['HTTP_HOST'|'HTTP_X_FORWARDED_*'] used in a URL, email, or access decision.",
+ "safe": "fixed site URL config; trust only vetted proxies."
+ },
+ {
+ "id": "error-suppression",
+ "class": "footgun",
+ "title": "@ error suppression hiding failures",
+ "attack": "@unserialize / @file_get_contents / @$_GET hides errors that mask a security-relevant failure or type issue.",
+ "detect": "ast: error_suppression_expression (@) on a security-relevant call.",
+ "safe": "handle errors explicitly."
+ },
+ {
+ "id": "upload-exec",
+ "class": "file-upload",
+ "title": "Unrestricted file upload -> exec",
+ "attack": "Attacker uploads shell.php / .phtml / double-ext shell.php.jpg / MIME-spoofed / .htaccess; served from an executable dir.",
+ "detect": "manual+query: move_uploaded_file/write into a web-served dir with extension/MIME derived from the upload and no allow-list / non-exec storage.",
+ "safe": "random name; extension+content allow-list; store outside web root / non-exec."
+ },
+ {
+ "id": "user-enum",
+ "class": "info-leak",
+ "title": "User enumeration (distinct response/timing)",
+ "attack": "Login/reset returns different message or timing for valid vs invalid users -> account enumeration.",
+ "detect": "manual: auth/reset flows with user-existence-dependent branches in message or timing.",
+ "safe": "uniform responses and timing."
+ },
+ {
+ "id": "option-injection",
+ "class": "argument-injection",
+ "title": "escapeshellarg does NOT stop argument/option injection",
+ "attack": "escapeshellarg only quotes a value so it can't start a NEW command \u2014 it does NOT stop the value being read as an OPTION. e.g. exec('tar '.escapeshellarg($f)) with $f='--checkpoint=1 --checkpoint-action=exec=sh evil' => tar runs a command. Same: rsync -e, mysql --, curl -o/-K, ffmpeg -f, git --upload-pack, find -exec, zip -T -TT, wget -O.",
+ "detect": "ast+manual: an exec-family call whose arg is escapeshellarg($x) BUT $x is placed where the program accepts options (no `--` separator before it, or the value can begin with `-`) and $x is request-derived.",
+ "safe": "place a literal `--` before user args; validate the value doesn't start with `-`; use array-form proc_open/exec with explicit argv; allow-list."
+ },
+ {
+ "id": "escapeshellcmd-weak",
+ "class": "argument-injection",
+ "title": "escapeshellcmd is weaker than escapeshellarg",
+ "attack": "escapeshellcmd escapes shell metacharacters of a whole COMMAND but leaves spaces/quotes so arguments still split; it also lets option injection and unbalanced-quote tricks. Often misused as if it quoted an argument.",
+ "detect": "ast: escapeshellcmd wrapping a value that is then used as an argument (not the whole command).",
+ "safe": "escapeshellarg per-argument; argv-form; never escapeshellcmd for an argument."
+ },
+ {
+ "id": "zip-slip",
+ "class": "path-traversal",
+ "title": "Archive extraction path traversal (Zip Slip)",
+ "attack": "ZipArchive::extractTo($dir) / PharData / tar writes each entry using the entry's own path; an entry named ../../wp-config.php or /etc/... escapes $dir -> arbitrary write/overwrite (RCE if a .php lands in webroot). Symlink entries read/write outside too.",
+ "detect": "query+manual: extractTo / archive extraction of an attacker-supplied archive without validating each entry path stays under the target (realpath prefix check).",
+ "safe": "iterate entries, reject absolute/`..`/symlink names, realpath-under-base each before write."
+ },
+ {
+ "id": "phar-wrapper-op",
+ "class": "deserialization",
+ "title": "phar:// via a file op on a user path (already-catalogued file ops)",
+ "attack": "Any file op (file_exists/getimagesize/fopen/is_file/md5_file) on phar://uploaded.jpg triggers unserialize of Phar metadata -> POP chain. The 'safe-looking' file op is the trigger.",
+ "detect": "query: file-read/exists ops whose path can carry a user-controlled stream wrapper (no scheme allow-list).",
+ "safe": "validate scheme; Phar::interceptFileFuncs(); deny phar://."
+ }
]
-}
+}
\ No newline at end of file
diff --git a/docs/case-studies/wordpress-security-audit/sink-census/sink_census.py b/docs/case-studies/wordpress-security-audit/sink-census/sink_census.py
index 3ae212f20..d76a042cb 100644
--- a/docs/case-studies/wordpress-security-audit/sink-census/sink_census.py
+++ b/docs/case-studies/wordpress-security-audit/sink-census/sink_census.py
@@ -59,7 +59,9 @@ NONCODE_NODES = {"string", "encapsed_string", "comment", "heredoc", "nowdoc", "t
# classes whose `new C(...)` construction is a sink
CTOR_SINKS = {"ReflectionFunction": "dynamic-invoke", "ReflectionMethod": "dynamic-invoke",
"ReflectionClass": "dynamic-invoke", "ReflectionObject": "dynamic-invoke",
- "SoapClient": "SSRF", "SplFileObject": "file-read", "SimpleXMLElement": "XXE"}
+ "SoapClient": "SSRF", "SplFileObject": "file-read", "SimpleXMLElement": "XXE",
+ "ZipArchive": "zip-slip-path-traversal", "PharData": "zip-slip-path-traversal",
+ "Phar": "deserialization", "Imagick": "image-rce-ssrf", "DOMDocument": "XXE"}
def scan_file(path, rel):
src = open(path, "rb").read()
root = parser.parse(src).root_node