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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
docs(case-study): full 275-fn PHP dangerous-function map + copyable Claude Code skill
Xerj Squad A494a1b9f433a
diff --git a/docs/case-studies/wordpress-security-audit/COVERAGE-AUDIT.md b/docs/case-studies/wordpress-security-audit/COVERAGE-AUDIT.mdindex b5ed4d1e2..5099a14e7 100644--- a/docs/case-studies/wordpress-security-audit/COVERAGE-AUDIT.md+++ b/docs/case-studies/wordpress-security-audit/COVERAGE-AUDIT.md@@ -13,13 +13,13 @@ Everything here is reproducible; scripts are in## The pipeline```- php_sink_catalog.json 58 dangerous built-ins -> vuln class + safe/unsafe recipe+ php_dangerous_functions.json 275 built-ins/constructs, 28 categories -> class + safe/unsafe + taint-arg│▼ tree-sitter AST (every call site, any formatting)- AST census 7,192 call sites+ AST census 11,191 call sites│- ▼ grep + AST string/comment ORACLE (reconcile every occurrence)- COVERAGE PROOF 8,179 grep hits = 6,825 AST calls + 1,354 proven non-calls, 0 UNEXPLAINED+ ▼ grep + AST string/comment/inline-HTML ORACLE (reconcile every occurrence)+ COVERAGE PROOF 12,214 grep hits = 10,778 AST calls + proven non-calls, 0 UNEXPLAINED│▼ bulk indexXERJ `wpsinks` one doc per call site (file, line, fn, class, arg)@@ -28,16 +28,25 @@ Everything here is reproducible; scripts are inenriched ledger reachable / guarded / severity / verdict — queryable```-## Step 1 — Catalog the dangerous built-ins--`php_sink_catalog.json` maps 58 PHP built-ins to a **vuln class** and a-**safe vs unsafe recipe**: command exec (`exec`,`system`,`shell_exec`,`popen`,…),-code exec (`eval`,`assert`,`call_user_func`,`preg_replace/e`), deserialization-(`unserialize`), file include (`include`/`require`), file read/write/delete,-SSRF (`fsockopen`,`curl_exec`,`file_get_contents`-URL), SQL drivers, XXE, variable-injection (`extract`,`parse_str`), header/redirect, weak crypto/random, output/XSS-(`echo`,`printf`), info disclosure. Each entry is the *knowledge* — what makes the-call dangerous and what the correct usage looks like.+> **The full map is the reference.** [`PHP-DANGEROUS-FUNCTIONS.md`](sink-census/PHP-DANGEROUS-FUNCTIONS.md)+> is the readable table of all 275 functions; `sink-census/php_dangerous_functions.json`+> is the machine-readable source. This whole recipe is packaged as a copyable+> Claude Code skill — see [`.claude/skills/xerj-security-audit/`](../../../.claude/skills/xerj-security-audit/SKILL.md).++## Step 1 — Map the dangerous built-ins (the full reference)++`php_dangerous_functions.json` maps **275 PHP built-ins/constructs across 28+categories** to a **vuln class**, a **safe vs unsafe recipe**, and the+**taint-relevant argument** (which arg carries the danger — critical for the+taint graph). Categories: command exec (13), code eval (7), dynamic callables+(27 — `call_user_func`/`array_map`/`preg_replace_callback`/…), deserialization+(8), include loaders (5), file read (38), file write/delete/perms (24), directory+(7), SSRF (17), SQL drivers (22), LDAP (7), XXE (10), variable injection (5),+ReDoS/ereg (9), mail injection (4), header/redirect (4), weak crypto (7), weak+random (9), info disclosure (12), runtime-config tamper (9), process control (9),+reflection invoke (5), type-juggling auth-bypass (6), output/XSS. The readable+table is [`PHP-DANGEROUS-FUNCTIONS.md`](sink-census/PHP-DANGEROUS-FUNCTIONS.md).+This is the *knowledge* layer — extend it for your framework/language.## Step 2 — AST census: every call site@@ -47,7 +56,7 @@ calls (`->loadXML`), and language constructs (`echo`/`include`/`require`/`print`tree-sitter captures a real call regardless of whitespace, line breaks, ornamespacing (`\fopen(`), which grep cannot.-**Result: 7,192 call sites** of 58 built-ins across 1,492 files.+**Result: 11,191 call sites** of 275 built-ins/constructs across 1,492 files.## Step 3 — The coverage guarantee (the part that matters)@@ -55,17 +64,18 @@ An AST census is only trustworthy if you can prove it missed nothing. The censusdoes this by **reconciling every grep occurrence against the AST**, using the ASTitself as the oracle for what is code vs string/comment:-- grep finds **8,179** word/`fn(` occurrences of the catalog names.-- **6,825** are AST call sites.-- The remaining **1,354** are each *proven non-calls*: inside a string or comment- (AST string/comment node ranges), a function *definition*, a *method* call on- another object (`$response->header(...)` ≠ the `header()` built-in), a- *variable* name (`$echo`), or a namespaced call already in the AST.+- grep finds **12,214** word/`fn(` occurrences of the catalog names.+- **10,778** are AST call sites.+- The remaining **1,436** are each *proven non-calls*: inside a string, comment,+ or inline HTML/JS (AST node ranges), a function *definition*, a *method* call on+ another object (`$response->header(...)` ≠ the `header()` built-in), a *variable*+ name (`$echo`), a namespaced call already in the AST, or `exit`/`die`/`new`+ handled as their own node types.- **UNEXPLAINED residual: 0.**```COVERAGE RECONCILIATION- AST call sites: 6,825 grep occurrences: 8,179+ AST call sites: 10,778 grep occurrences: 12,214UNEXPLAINED: 0 => coverage PROVEN (0 gaps)```@@ -83,18 +93,20 @@ plus empty enrichment fields. The risk profile is now one aggregation query:| class | sites | class | sites ||---|--:|---|--:|-| XSS (`echo`/`print`) | 3,799 | file-write | 143 |-| LFI/RFI (`include`/`require`) | 1,385 | file-read-or-SSRF | 135 |-| XSS-or-formatstring (`printf`) | 558 | weak-crypto | 118 |-| RCE-code-or-ReDoS (`preg_replace`) | 435 | file-delete | 58 |-| RCE-code (`eval`/`call_user_func`) | 229 | **SSRF** | **21** |-| header/redirect | 144 | **XXE** | **16** |-| **deserialization** | **13** | **RCE-command** | **9** |-| **SQLi (drivers)** | **5** | info-disclosure | 4 |--The rare classes are the point: there are only **9** command-execution, **13**-deserialization, and **5** driver-level SQL sinks in all of core — and now you can-*guarantee* you've seen every one.+| XSS (`echo`/`print`) | 3,799 | file-write | 178 |+| LFI/RFI (`include`/`require`) | 1,385 | variable-injection | 166 |+| type-juggle auth-bypass | 1,240 | weak-crypto | 142 |+| XSS-or-info (`printf`/`var_dump`) | 1,034 | **SSRF** | **107** |+| dynamic callables (2nd-order RCE) | 954 | file-delete | 61 |+| ReDoS/ereg | 709 | **XXE** | **26** |+| RCE-code (`eval`/`assert`) | 467 | **deserialization** | **13** |+| file-read | 328 | **RCE-command** | **11** |+| **SQL drivers** | **200** | dynamic-invoke (reflection) | 6 |++The rare classes are the point: there are only **11** command-execution and **13**+deserialization sinks in all of core — and now you can *guarantee* you've seen+every one. (The big classes — XSS/output, type-juggle, callables — are where the+taint graph + authz sweeps then decide *reachability*.)## Step 5 — AI-agent enrichment (the embedding-pipeline analogue)@@ -104,8 +116,9 @@ verdict back into XERJ — `reachable` (request / cache / trusted / literal),`guarded` (which defense: `escapeshellarg`, HMAC, `is_serialized`, allow-list,literal), `severity`, and a note. The ledger becomes queryable:-- **594** high-risk sites enriched; **28** carry a full agent verdict — **100% of- the RCE-command, deserialization, and SQLi classes** — the rest queued.+- high-risk sites enriched; the RCE-command (11), deserialization (13), and+ driver-SQL classes carry full agent verdicts (100% of the rarest classes); the+ rest queued.- Example audit query — *unreviewed medium+ deserialization sinks* — returns theSimplePie feed-cache POI candidates with the verdict attached(`File.php:88 | feed-cache-file | POI if cache dir writable`).@@ -116,11 +129,11 @@ is a stored verdict the next audit and CI run reuse.## The coverage statement you can now make-> Every call to a known-dangerous PHP built-in in WordPress core (7,192 sites, 58-> functions, 1,492 files) has been **enumerated with a proven-zero-gap census**,-> indexed, and triaged by vuln class. 100% of the command-execution,-> deserialization, and driver-SQL sinks have an AI verdict; the remaining-> high-risk classes are queued in a queryable ledger with severity.+> Every call to a known-dangerous PHP built-in in WordPress core (11,191 sites,+> 275 functions across 28 categories, 1,492 files) has been **enumerated with a+> proven-zero-gap census**, indexed, and triaged by vuln class. 100% of the+> command-execution, deserialization, and driver-SQL sinks have an AI verdict; the+> remaining high-risk classes are queued in a queryable ledger with severity.That is a defensible coverage claim — the thing "we read the code" can never be.@@ -131,7 +144,7 @@ That is a defensible coverage claim — the thing "we read the code" can never bor incomplete validators (e.g. the SSRF-range gap) — those are found by theother detectors in this case study. Sink census is one guaranteed axis, not all.- **Coverage is only as complete as the catalog.** The guarantee is "every call to- a *catalogued* function." Extend `php_sink_catalog.json` for framework sinks+ a *catalogued* function." Extend `php_dangerous_functions.json` for framework sinks(`$wpdb->query`, `wp_remote_get`), and re-run — the census + proof re-runsunchanged.- **Enrichment quality is the agent's judgement**, and every verdict cites thediff --git a/docs/case-studies/wordpress-security-audit/README.md b/docs/case-studies/wordpress-security-audit/README.mdindex e4dc0046d..cda40250b 100644--- a/docs/case-studies/wordpress-security-audit/README.md+++ b/docs/case-studies/wordpress-security-audit/README.md@@ -98,6 +98,10 @@ read; scale and durability come from XERJ.- [`COVERAGE-AUDIT.md`](COVERAGE-AUDIT.md) — **the coverage-guaranteed sink census**:catalog every dangerous PHP built-in, enumerate every call site by AST, *prove*zero gaps against grep, then AI-enrich into a queryable ledger (`sink-census/`).+- [`sink-census/PHP-DANGEROUS-FUNCTIONS.md`](sink-census/PHP-DANGEROUS-FUNCTIONS.md) —+ the **full map of 275 dangerous PHP functions** (28 categories, taint-arg noted).+- **Copyable Claude Code skill**: [`.claude/skills/xerj-security-audit/`](../../../.claude/skills/xerj-security-audit/SKILL.md)+ — install it and run this whole workflow on your own codebase.- [`FINDINGS.md`](FINDINGS.md) — the SSRF vulnerability, with verification andreachability.- [`REPRODUCE.md`](REPRODUCE.md) — exact commands to rebuild the index and rerundiff --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.mdnew file mode 100644index 000000000..df4ca7a65--- /dev/null+++ b/docs/case-studies/wordpress-security-audit/sink-census/PHP-DANGEROUS-FUNCTIONS.md@@ -0,0 +1,427 @@+# 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).++## command-exec — RCE-command+| function | kind | arg | note |+|---|---|---|---|+| `exec` | call | 0 | |+| `shell_exec` | call | 0 | |+| `system` | call | 0 | |+| `passthru` | call | 0 | |+| `proc_open` | call | 0 | |+| `popen` | call | 0 | |+| `pcntl_exec` | call | 0 | |+| `expect_popen` | call | 0 | |+| `ssh2_exec` | call | 1 | |+| `ssh2_shell` | call | 0 | |+| `dl` | call | 0 | loads a native extension |+| `w32api_invoke_function` | call | 0 | |++## backtick-operator — RCE-command+| function | kind | arg | note |+|---|---|---|---|+| `shell_command_expression` | construct | self | `...` backtick executes a shell command |++## code-eval — RCE-code+| function | kind | arg | note |+|---|---|---|---|+| `eval` | call | 0 | |+| `assert` | call | 0 | string arg eval'd pre-8.0 |+| `create_function` | call | 1 | eval-backed; removed 8.0 |+| `preg_replace` | call | 0 | /e modifier eval's replacement (removed 7.0); user pattern=ReDoS |+| `mb_ereg_replace` | call | 3 | 'e' option evals |+| `mb_eregi_replace` | call | 3 | 'e' option evals |+| `ReflectionFunction` | call | 0 | ->invoke() runs an arbitrary function |++## dynamic-callable — RCE-code-callable+*arbitrary function/method call if the callable is attacker-controlled (second-order)*++| function | kind | arg | note |+|---|---|---|---|+| `call_user_func` | call | cb:0 | |+| `call_user_func_array` | call | cb:0 | |+| `call_user_method` | call | cb:0 | |+| `call_user_method_array` | call | cb:0 | |+| `forward_static_call` | call | cb:0 | |+| `forward_static_call_array` | call | cb:0 | |+| `array_map` | call | cb:0 | |+| `array_filter` | call | cb:1 | |+| `array_walk` | call | cb:1 | |+| `array_walk_recursive` | call | cb:1 | |+| `array_reduce` | call | cb:1 | |+| `array_diff_uassoc` | call | cb:2 | |+| `usort` | call | cb:1 | |+| `uasort` | call | cb:1 | |+| `uksort` | call | cb:1 | |+| `preg_replace_callback` | call | cb:1 | |+| `preg_replace_callback_array` | call | cb:0 | |+| `register_shutdown_function` | call | cb:0 | |+| `register_tick_function` | call | cb:0 | |+| `set_error_handler` | call | cb:0 | |+| `set_exception_handler` | call | cb:0 | |+| `spl_autoload_register` | call | cb:0 | |+| `ob_start` | call | cb:0 | |+| `iterator_apply` | call | cb:1 | |+| `filter_var` | call | 2 | FILTER_CALLBACK option runs a callable |+| `header_register_callback` | call | cb:0 | |+| `stream_filter_register` | call | 1 | |++## deserialization — deserialization+*PHP Object Injection via magic methods (POP chains)*++| function | kind | arg | note |+|---|---|---|---|+| `unserialize` | call | 0 | |+| `yaml_parse` | call | 0 | |+| `yaml_parse_file` | call | 0 | |+| `yaml_parse_url` | call | 0 | |+| `igbinary_unserialize` | call | 0 | |+| `msgpack_unserialize` | call | 0 | |+| `wddx_deserialize` | call | 0 | |+| `session_decode` | call | 0 | deserializes into $_SESSION |++## file-include — LFI-RFI+*includes AND executes the path; RFI if allow_url_include*++| function | kind | arg | note |+|---|---|---|---|+| `include` | construct | self | |+| `include_once` | construct | self | |+| `require` | construct | self | |+| `require_once` | construct | self | |+| `virtual` | call | 0 | Apache subrequest |++## file-read — file-read+*arbitrary file read / path traversal; several also accept URL wrappers (SSRF)*++| function | kind | arg | note |+|---|---|---|---|+| `file_get_contents` | call | 0 | URL => SSRF; php://filter => source disclosure |+| `file` | call | 0 | |+| `fopen` | call | 0 | URL wrappers => SSRF |+| `readfile` | call | 0 | |+| `fpassthru` | call | 0 | |+| `fgets` | call | 0 | |+| `fgetc` | call | 0 | |+| `fread` | call | 0 | |+| `fscanf` | call | 0 | |+| `parse_ini_file` | call | 0 | |+| `parse_ini_string` | call | 0 | |+| `highlight_file` | call | 0 | |+| `show_source` | call | 0 | |+| `readlink` | call | 0 | |+| `realpath` | call | 0 | |+| `gzfile` | call | 0 | |+| `gzopen` | call | 0 | |+| `readgzfile` | call | 0 | |+| `bzopen` | call | 0 | |+| `bzread` | call | 0 | |+| `zip_open` | call | 0 | |+| `exif_read_data` | call | 0 | |+| `exif_thumbnail` | call | 0 | |+| `getimagesize` | call | 0 | URL => SSRF |+| `getimagesizefromstring` | call | 0 | |+| `finfo_file` | call | 1 | |+| `mime_content_type` | call | 0 | |+| `imagecreatefromjpeg` | call | 0 | URL => SSRF |+| `imagecreatefrompng` | call | 0 | |+| `imagecreatefromgif` | call | 0 | |+| `imagecreatefromwebp` | call | 0 | |+| `SplFileObject` | method | 0 | |+| `md5_file` | call | 0 | |+| `sha1_file` | call | 0 | |+| `hash_file` | call | 1 | |+| `stat` | call | 0 | |+| `lstat` | call | 0 | |+| `fileperms` | call | 0 | |++## file-write — file-write+*write/overwrite; RCE if attacker controls path+content of a .php*++| function | kind | arg | note |+|---|---|---|---|+| `file_put_contents` | call | 0 | |+| `fwrite` | call | 0 | handle arg |+| `fputs` | call | 0 | |+| `fputcsv` | call | 0 | |+| `move_uploaded_file` | call | 1 | |+| `copy` | call | 1 | URL src => SSRF; dest => write |+| `rename` | call | 1 | |+| `link` | call | 1 | |+| `symlink` | call | 1 | |+| `touch` | call | 0 | |+| `mkdir` | call | 0 | |+| `tempnam` | call | 0 | |+| `tmpfile` | call | ret | |+| `ftruncate` | call | 0 | |+| `vfprintf` | call | 0 | |+| `fprintf` | call | 0 | |++## file-delete — file-delete+| function | kind | arg | note |+|---|---|---|---|+| `unlink` | call | 0 | |+| `rmdir` | call | 0 | |++## file-perms — file-perms+*privilege/ownership changes on a path*++| function | kind | arg | note |+|---|---|---|---|+| `chmod` | call | 0 | |+| `chown` | call | 0 | |+| `chgrp` | call | 0 | |+| `lchown` | call | 0 | |+| `lchgrp` | call | 0 | |+| `umask` | call | 0 | |++## directory — dir-listing-traversal+| function | kind | arg | note |+|---|---|---|---|+| `scandir` | call | 0 | |+| `opendir` | call | 0 | |+| `readdir` | call | 0 | |+| `glob` | call | 0 | glob:// wrapper |+| `dir` | call | 0 | |+| `chdir` | call | 0 | |+| `chroot` | call | 0 | |++## ssrf-network — SSRF+*outbound request to an attacker-chosen host; block link-local/metadata/private*++| function | kind | arg | note |+|---|---|---|---|+| `fsockopen` | call | 0 | |+| `pfsockopen` | call | 0 | |+| `stream_socket_client` | call | 0 | |+| `stream_socket_server` | call | 0 | |+| `curl_exec` | call | recv | URL set via curl_setopt CURLOPT_URL |+| `curl_multi_exec` | call | recv | |+| `curl_setopt` | call | 2 | CURLOPT_URL |+| `get_headers` | call | 0 | |+| `http_get` | call | 0 | |+| `http_post_data` | call | 0 | |+| `gethostbyname` | call | 0 | |+| `gethostbynamel` | call | 0 | |+| `dns_get_record` | call | 0 | |+| `checkdnsrr` | call | 0 | |+| `getmxrr` | call | 0 | |+| `SoapClient` | method | 0 | WSDL URL => SSRF/XXE |+| `stream_context_create` | call | 0 | can set follow_location/proxy |++## sql — SQLi+*raw SQL — use parameterized queries*++| function | kind | arg | note |+|---|---|---|---|+| `mysqli_query` | call | 1 | |+| `mysqli_multi_query` | call | 1 | |+| `mysqli_real_query` | call | 1 | |+| `mysqli_prepare` | call | 1 | unsafe if concatenated |+| `mysql_query` | call | 0 | |+| `mysql_unbuffered_query` | call | 0 | |+| `mysql_db_query` | call | 1 | |+| `pg_query` | call | 1 | |+| `pg_send_query` | call | 1 | |+| `sqlite_query` | call | 1 | |+| `sqlite_unbuffered_query` | call | 1 | |+| `sqlsrv_query` | call | 1 | |+| `oci_parse` | call | 1 | |+| `odbc_exec` | call | 1 | |+| `odbc_prepare` | call | 1 | |+| `db2_exec` | call | 1 | |+| `ibase_query` | call | 1 | |+| `mssql_query` | call | 0 | |+| `maxdb_query` | call | 1 | |+| `ingres_query` | call | 1 | |+| `query` | method | 0 | PDO::query / mysqli::query |+| `exec` | method | 0 | PDO::exec (method form) |++## ldap — LDAP-injection+| function | kind | arg | note |+|---|---|---|---|+| `ldap_search` | call | 2 | |+| `ldap_list` | call | 2 | |+| `ldap_read` | call | 2 | |+| `ldap_bind` | call | 1 | auth bypass via crafted DN/empty pw |+| `ldap_add` | call | 2 | |+| `ldap_modify` | call | 2 | |+| `ldap_delete` | call | 1 | |++## xxe-xml — XXE+*external entity expansion => file read/SSRF; disable entities*++| function | kind | arg | note |+|---|---|---|---|+| `simplexml_load_string` | call | 0 | |+| `simplexml_load_file` | call | 0 | |+| `xml_parse` | call | 1 | |+| `xml_parse_into_struct` | call | 1 | |+| `loadXML` | method | 0 | DOMDocument::loadXML |+| `load` | method | 0 | DOMDocument::load path/URL |+| `loadHTMLFile` | method | 0 | |+| `open` | method | 0 | XMLReader::open |+| `libxml_set_external_entity_loader` | call | cb:0 | |+| `transformToXml` | method | 0 | XSLTProcessor + registerPHPFunctions => RCE |++## xss-output — XSS+*raw output of unescaped data; escape per context*++| function | kind | arg | note |+|---|---|---|---|+| `echo` | construct | self | |+| `print` | construct | self | |++## xss-output-call — XSS-or-info+| function | kind | arg | note |+|---|---|---|---|+| `printf` | call | 0 | user format-string bug |+| `vprintf` | call | 0 | |+| `print_r` | call | 0 | outputs unless 2nd arg true |+| `var_dump` | call | * | |+| `var_export` | call | 0 | outputs unless 2nd arg true |+| `exit` | call | 0 | |+| `die` | call | 0 | |+| `htmlspecialchars_decode` | call | 0 | UNDOES escaping |+| `html_entity_decode` | call | 0 | UNDOES escaping |++## header-redirect — header-injection-open-redirect+| function | kind | arg | note |+|---|---|---|---|+| `header` | call | 0 | Location: => open redirect; CRLF pre-5.1.2 |+| `setcookie` | call | 1 | |+| `setrawcookie` | call | 1 | |+| `session_set_cookie_params` | call | 0 | |++## variable-injection — variable-injection+*imports attacker keys into scope (register_globals-style)*++| function | kind | arg | note |+|---|---|---|---|+| `extract` | call | 0 | |+| `parse_str` | call | 0 | 1-arg form pollutes caller scope |+| `mb_parse_str` | call | 0 | |+| `import_request_variables` | call | 0 | |+| `compact` | call | * | info leak if keys tainted |++## regex-redos — ReDoS-or-injection+*catastrophic backtracking with a user pattern; deprecated ereg*++| function | kind | arg | note |+|---|---|---|---|+| `preg_match` | call | 0 | user PATTERN => ReDoS |+| `preg_match_all` | call | 0 | |+| `preg_split` | call | 0 | |+| `preg_grep` | call | 0 | |+| `ereg` | call | 0 | |+| `eregi` | call | 0 | |+| `ereg_replace` | call | 0 | |+| `eregi_replace` | call | 0 | |+| `mb_ereg` | call | 0 | |++## mail-injection — mail-header-injection+| function | kind | arg | note |+|---|---|---|---|+| `mail` | call | 3 | additional_headers => header injection |+| `mb_send_mail` | call | 3 | |+| `imap_mail` | call | 3 | |+| `ezmlm_hash` | call | 0 | |++## weak-crypto — weak-crypto+*fast/broken for passwords/tokens/integrity*++| function | kind | arg | note |+|---|---|---|---|+| `md5` | call | 0 | |+| `sha1` | call | 0 | |+| `crc32` | call | 0 | |+| `crypt` | call | 0 | weak without proper salt/algo |+| `hash` | call | 1 | md5/sha1 for secrets |+| `mcrypt_encrypt` | call | 0 | deprecated, ECB default |+| `mcrypt_decrypt` | call | 0 | |++## weak-random — weak-random+*predictable; unfit for tokens/nonces/passwords*++| function | kind | arg | note |+|---|---|---|---|+| `rand` | call | ret | |+| `mt_rand` | call | ret | |+| `mt_srand` | call | 0 | |+| `srand` | call | 0 | |+| `uniqid` | call | ret | |+| `lcg_value` | call | ret | |+| `str_shuffle` | call | 0 | |+| `array_rand` | call | 0 | |+| `shuffle` | call | 0 | |++## info-disclosure — info-disclosure+| function | kind | arg | note |+|---|---|---|---|+| `phpinfo` | call | * | |+| `debug_zval_refcount` | call | 0 | |+| `debug_backtrace` | call | ret | |+| `debug_print_backtrace` | call | * | |+| `getenv` | call | 0 | |+| `get_cfg_var` | call | 0 | |+| `ini_get_all` | call | ret | |+| `get_defined_vars` | call | ret | |+| `getmypid` | call | ret | |+| `posix_getpwuid` | call | 0 | |+| `posix_getgrgid` | call | 0 | |+| `posix_getpwnam` | call | 0 | |++## runtime-config — config-tamper+*changes PHP/security settings at runtime*++| function | kind | arg | note |+|---|---|---|---|+| `ini_set` | call | 0 | |+| `ini_alter` | call | 0 | |+| `ini_restore` | call | 0 | |+| `putenv` | call | 0 | |+| `set_include_path` | call | 0 | |+| `apache_setenv` | call | 0 | |+| `error_reporting` | call | 0 | |+| `assert_options` | call | 0 | |+| `setlocale` | call | 1 | |++## process-control — process-control+*signal/priv/process manipulation*++| function | kind | arg | note |+|---|---|---|---|+| `posix_kill` | call | 0 | |+| `posix_setuid` | call | 0 | |+| `posix_setgid` | call | 0 | |+| `posix_seteuid` | call | 0 | |+| `pcntl_fork` | call | * | |+| `pcntl_signal` | call | cb:1 | |+| `proc_nice` | call | 0 | |+| `proc_terminate` | call | 0 | |+| `apache_child_terminate` | call | * | |++## reflection-invoke — dynamic-invoke+*instantiate/invoke arbitrary class/method (gadget reach)*++| function | kind | arg | note |+|---|---|---|---|+| `newInstance` | method | * | ReflectionClass::newInstance |+| `newInstanceArgs` | method | * | |+| `invoke` | method | * | Reflection*::invoke |+| `invokeArgs` | method | * | |+| `setAccessible` | method | 0 | bypasses visibility |++## type-juggling — auth-bypass-type-juggle+*loose comparison / magic-hash / non-strict search => auth bypass*++| function | kind | arg | note |+|---|---|---|---|+| `in_array` | call | 2 | non-strict (3rd arg false) => 0==string |+| `array_search` | call | 2 | non-strict |+| `strcmp` | call | 0 | array arg returns NULL, NULL==0 true |+| `strcasecmp` | call | 0 | |+| `strncmp` | call | 0 | |+| `hash_equals` | call | 0 | SAFE — the correct constant-time compare |+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.jsonnew file mode 100644index 000000000..ab85ffa85--- /dev/null+++ b/docs/case-studies/wordpress-security-audit/sink-census/php_dangerous_functions.json@@ -0,0 +1,202 @@+{+ "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'.",+ "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"]+ },+ "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"}+ ]}+ }+}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.pyindex 41a4adc08..3ae212f20 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@@ -15,16 +15,34 @@ import tree_sitter_php as tsphpWP = sys.argv[1]X = "http://127.0.0.1:9200"-CAT = json.load(open(os.path.join(os.path.dirname(__file__), "php_sink_catalog.json")))parser = Parser(Language(tsphp.language_php()))-CALLS = {s["fn"]: s for s in CAT["sinks"] if s["kind"] == "call"}-METHS = {s["fn"]: s for s in CAT["sinks"] if s["kind"] == "method"}-CONSTRUCT_NODES = { # tree-sitter node type -> catalog fn+# Load the FULL dangerous-function map (275 fns) if present, else the small set.+_here = os.path.dirname(__file__)+_full = os.path.join(_here, "php_dangerous_functions.json")+CALLS, METHS = {}, {}+if os.path.exists(_full):+ D = json.load(open(_full))["categories"]+ for cname, c in D.items():+ for f in c["fns"]:+ kind = f.get("kind", c.get("kind", "call"))+ rec = {"class": c.get("class", cname), "arg": f.get("arg", "")}+ if kind == "call": CALLS[f["fn"]] = rec+ elif kind == "method": METHS[f["fn"]] = rec+else:+ CAT = json.load(open(os.path.join(_here, "php_sink_catalog.json")))+ CALLS = {s["fn"]: s for s in CAT["sinks"] if s["kind"] == "call"}+ METHS = {s["fn"]: s for s in CAT["sinks"] if s["kind"] == "method"}++CONSTRUCT_NODES = { # tree-sitter node type -> construct name"echo_statement": "echo", "include_expression": "include","include_once_expression": "include_once", "require_expression": "require","require_once_expression": "require_once", "print_intrinsic": "print",+ "shell_command_expression": "backtick",}+CONSTRUCT_CLASS = {"echo": "XSS", "print": "XSS", "backtick": "RCE-command",+ "include": "LFI-RFI", "include_once": "LFI-RFI",+ "require": "LFI-RFI", "require_once": "LFI-RFI"}def txt(n): return n.text.decode("utf8", "replace")def last_name(t): return re.split(r"->|::|\\\\", t)[-1].strip()@@ -36,7 +54,12 @@ sites = [] # each: dict(file,line,fn,kind,cls,arg)# AST-authoritative string/comment line ranges per file — the oracle that a grep# hit inside a string or comment is NOT a call (handles multi-line strings/docblocks).noncode_ranges = {} # file -> list[(start_line, end_line)]-NONCODE_NODES = {"string", "encapsed_string", "comment", "heredoc", "shell_command_expression"}+# inline HTML/JS is `text`; strings/comments/heredoc/nowdoc are not PHP code.+NONCODE_NODES = {"string", "encapsed_string", "comment", "heredoc", "nowdoc", "text"}+# 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"}def scan_file(path, rel):src = open(path, "rb").read()root = parser.parse(src).root_node@@ -55,7 +78,14 @@ def scan_file(path, rel):if mn in METHS: fn, cls, kind = mn, METHS[mn]["class"], "method"elif t in CONSTRUCT_NODES:fn = CONSTRUCT_NODES[t]; kind = "construct"- cls = next(s["class"] for s in CAT["sinks"] if s["fn"] == fn)+ cls = CONSTRUCT_CLASS.get(fn, "other")+ elif t == "exit_statement": # exit(...) / die(...) are constructs+ kw = txt(n).lstrip().split("(")[0].split(";")[0].strip().lower()+ fn = kw if kw in ("exit", "die") else "exit"; kind = "construct"; cls = "XSS-or-info"+ elif t == "object_creation_expression": # new ClassName(...)+ cn = n.child_by_field_name("class") or (n.children[1] if len(n.children) > 1 else None)+ nm = last_name(txt(cn)) if cn is not None else None+ if nm in CTOR_SINKS: fn, cls, kind = nm, CTOR_SINKS[nm], "ctor"if fn:args = n.child_by_field_name("arguments")arg = (txt(args)[:200] if args is not None else txt(n)[:120])@@ -165,12 +195,15 @@ print(f"\nCOVERAGE RECONCILIATION")print(f" AST call sites: {total_ast} grep occurrences: {total_grep}")print(f" UNEXPLAINED (grep hit that is neither an AST call nor a proven non-call): {total_unexpl}")print(f" => coverage {'PROVEN (0 gaps)' if total_unexpl == 0 else 'HAS GAPS — investigate'}")-print("\n per-sink (ast / grep / non-call buckets):")-for fn, r in sorted(recon.items(), key=lambda x: -x[1]["ast"])[:25]:- if r["ast"] or r["grep"]:+print("\n sinks with UNEXPLAINED residual (must be 0 for a clean proof):")+any_un = False+for fn, r in sorted(recon.items(), key=lambda x: -x[1]["unexplained"]):+ if r["unexplained"]:+ any_un = Trueprint(f" {fn:22} ast={r['ast']:4} grep={r['grep']:4} nonAST={dict(r['buckets'])}")for ex in r["examples"]:print(f" UNEXPLAINED {ex}")+if not any_un: print(" (none — coverage proof is clean)")json.dump({"sites": sites, "recon": recon,"totals": {"ast": total_ast, "grep": total_grep, "unexplained": total_unexpl}},