root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat knife.md
// writeups

Knife

22 May 2021 · 9 min read · root access
Knife - maquina de Hack The Box

Executive summary — Knife is an Easy Linux box built around two very clean pieces of offensive security: the server exposes a development build of PHP (8.1.0-dev) carrying a real backdoor planted during a supply-chain compromise of the PHP project's own infrastructure, giving RCE with a single crafted HTTP header; and privilege escalation abuses knife (Chef's Ruby CLI), authorized via passwordless sudo, whose exec subcommand runs arbitrary Ruby as root. Path: PHP backdoor → direct RCE as james → sudo knife exec → root.

PlatformHack The Box
Operating systemLinux
DifficultyEasy
StatusRetired
Target IP10.129.23.191

Attack map

[80] Apache · PHP 8.1.0-dev (backdoored development build)
   │  source backdoor → «User-Agentt: zerodium ...» header runs PHP code
   ▼
[SHELL]  james  (direct RCE, no www-data hop) → user.txt
   │  sudo -l → (root) NOPASSWD: /usr/bin/knife
   ▼
[ROOT]  knife exec (arbitrary Ruby script) as root → root.txt

1. Reconnaissance

Before anything else, we run a full port scan rather than the default top-1000: on CTF boxes the interesting service is often on a high port, and limiting the scan can blind us to half the attack surface.

nmap -p- --open -n -T5 -v 10.129.23.191
PORT   STATE SERVICE REASON         VERSION
22/tcp open  ssh     syn-ack ttl 63  OpenSSH 8.2p1 Ubuntu 4ubuntu0.2
80/tcp open  http    syn-ack ttl 63  Apache httpd 2.4.41 ((Ubuntu))

Minimal surface: only SSH (22) and HTTP (80). The web page itself shows nothing remarkable at first glance — the clue is hiding in the response headers, so we inspect them with Burp Suite or the browser's DevTools:

X-Powered-By: PHP/8.1.0-dev

The golden clue: 8.1.0-dev is not a stable release, it's an internal development build of PHP — it should never reach a production server. And that specific version happens to carry one of the most talked-about backdoors in PHP's recent history.

🔒 Clearance required

This content is Root Access only. Everything else on the site — the free tier, the whole public library — stays open.

See Root Access plans

No account? Create one free then upgrade from your console.