From 11320928e3e88dcf9ba73e43fc92b3a011babaa2 Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Sat, 14 Mar 2026 18:40:35 +0000 Subject: [PATCH] Add content from: HTB: Gavel --- .../privilege-escalation/write-to-root.md | 21 +++++++++++++-- src/pentesting-web/command-injection.md | 19 +++++++++++++ src/pentesting-web/file-inclusion/README.md | 27 ++++++++++++++++++- src/pentesting-web/sql-injection/README.md | 24 +++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/src/linux-hardening/privilege-escalation/write-to-root.md b/src/linux-hardening/privilege-escalation/write-to-root.md index c4c06fb42a2..3f742390e02 100644 --- a/src/linux-hardening/privilege-escalation/write-to-root.md +++ b/src/linux-hardening/privilege-escalation/write-to-root.md @@ -43,6 +43,24 @@ TODO TODO +### Overwrite a restrictive `php.ini` used by a privileged PHP sandbox + +Some custom daemons validate user-supplied PHP by running `php` with a **restricted `php.ini`** (for example, `disable_functions=exec,system,...`). If the sandboxed code still has **any write primitive** (like `file_put_contents`) and you can reach the **exact `php.ini` path** used by the daemon, you can **overwrite that config** to lift restrictions and then submit a second payload that runs with elevated privileges. + +Typical flow: + +1. First payload overwrites the sandbox config. +2. Second payload executes code now that dangerous functions are re-enabled. + +Minimal example (replace the path used by the daemon): + +```php + [!TIP] > In the previous code, the final `+.txt` was added because the attacker needed a string that ended in `.txt`, so the string ends with it and after the b64 decode that part will return just junk and the real PHP code will be included (and therefore, executed). @@ -818,10 +843,10 @@ Tune the number of `../` segments until you escape the intended directory, then - [When Audits Fail: Four Critical Pre-Auth Vulnerabilities in TRUfusion Enterprise](https://www.rcesecurity.com/2025/09/when-audits-fail-four-critical-pre-auth-vulnerabilities-in-trufusion-enterprise/) - [Positive Technologies – Blind Trust: What Is Hidden Behind the Process of Creating Your PDF File?](https://swarm.ptsecurity.com/blind-trust-what-is-hidden-behind-the-process-of-creating-your-pdf-file/) - [HTB: Imagery (admin log download traversal + `/proc/self/environ` read)](https://0xdf.gitlab.io/2026/01/24/htb-imagery.html) +- [HTB: Gavel](https://0xdf.gitlab.io/2026/03/14/htb-gavel.html) {{#file}} EN-Local-File-Inclusion-1.pdf {{#endfile}} {{#include ../../banners/hacktricks-training.md}} - diff --git a/src/pentesting-web/sql-injection/README.md b/src/pentesting-web/sql-injection/README.md index 53ba19bf313..2bff71793e9 100644 --- a/src/pentesting-web/sql-injection/README.md +++ b/src/pentesting-web/sql-injection/README.md @@ -652,6 +652,29 @@ Mitigations: - Never concatenate identifiers from user input. Map allowed column names to a fixed allow-list and quote identifiers properly. - If dynamic table access is required, restrict to a finite set and resolve server-side from a safe mapping. +### ORDER BY / identifier-based SQLi (PDO limitation) + +Prepared statements **cannot bind identifiers** (column or table names). A common unsafe pattern is to take a user-controlled `sort` parameter and build `ORDER BY` using string concatenation, sometimes wrapping the input in backticks to “sanitize” it. This still enables SQLi because the identifier context is attacker-controlled. + +Vulnerable pattern: + +```php +$sort = $_POST['sort']; +$q = "SELECT id,item_name FROM items WHERE user_id=? ORDER BY `$sort`"; +$stmt = $pdo->prepare($q); +$stmt->execute([$user_id]); +``` + +Signals in traffic: + +- Sort parameter in **POST** (often `sort=column`), not a fixed allow-list. +- Changing `sort` breaks the query or alters output ordering. + +Mitigation: + +- Map user input to a **fixed allow-list** of column names and only interpolate mapped identifiers. +- Never rely on backticks as “sanitization” for identifiers. + ### WAF bypass suggester tools @@ -674,5 +697,6 @@ https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/sqli.txt ## References - [https://blog.sicuranext.com/vtenext-25-02-a-three-way-path-to-rce/](https://blog.sicuranext.com/vtenext-25-02-a-three-way-path-to-rce/) +- [HTB: Gavel](https://0xdf.gitlab.io/2026/03/14/htb-gavel.html) {{#include ../../banners/hacktricks-training.md}}