Academy is an easy-rated Linux machine from HackTheBox, created by egre55 and mrb3n. In the current post, my IP is 10.10.14.44, and the target IP is 10.129.167.56
This machine features an apache server hosting a PHP website. The website doesn't look special until you intercept the registration process, where you can change a obvious parameter to change your privileges to that account, then when you fuzz the website, you find an admin login url. In that URL there is an sub-domain with error logs from Laravel, revealing in the process the API_KEY used for an exploit for RCE. Inside the machine, there are a lot of techniques used to pivot between users and the change your user to root.
Recon
The first steps are about getting basic information about the target, by using nmap and searching information from the website.
$nmap-sCV-p22,80,3306010.129.167.56-oNTargetNmapscanreportfor10.129.167.56Hostisup (0.15s latency).PORTSTATESERVICEVERSION22/tcpopensshOpenSSH8.2p1Ubuntu4ubuntu0.1 (Ubuntu Linux; protocol2.0)|ssh-hostkey:|3072c0:90:a3:d8:35:25:6f:fa:33:06:cf:80:13:a0:a5:53 (RSA)|2562a:d5:4b:d0:46:f0:ed:c9:3c:8d:f6:5d:ab:ae:77:96 (ECDSA)|_256e1:64:14:c3:cc:51:b2:3b:a6:28:a7:b1:ae:5f:45:35 (ED25519)80/tcpopenhttpApachehttpd2.4.41 ((Ubuntu))|_http-server-header:Apache/2.4.41 (Ubuntu)|_http-title:Didnotfollowredirecttohttp://academy.htb/33060/tcpopenmysqlx?1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port33060-TCP:V=7.92%I=7%D=6/6%Time=647F44D8%P=i686-pc-windows-windows%SF:r(GenericLines,9,"\x05\0\0\0\x0b\x08\x05\x1a\0");ServiceInfo:OS:Linux; CPE:cpe:/o:linux:linux_kernelServicedetectionperformed.Pleasereportanyincorrectresultsathttps://nmap.org/submit/.Nmapdone:1IPaddress (1 hostup) scanned in 176.95 seconds
If you search for "OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 launchpad", you can find the specific machine type, in this case the result was: "Ubuntu Focal". It could be useful to find an vulnerability for a certain version.
Information that we have now: It's a website (port 80) that use Apache/2.4.41, with an open mysqlx (port 33060), there is no response for now.
Because of the following message "Did not follow redirect to http://academy.htb/" we have to add the IP to /etc/hosts/
The website shows a Laravel error, maybe it could be vulnerable to something, search it at exploit-db.com. I tried the CVE-2021-3129 but it doesn't work. And the CVE-2018-15133 requieres metasploit, but there are alternatives at github.
And you are in! Close the CVE Interactive Terminal and do a Bash Upgrade at the other terminal
User Pivoting [cry0l1t3]
Target Terminal [www-data]
www-data@academy:/var/www/html$iduid=33(www-data) gid=33(www-data) groups=33(www-data)www-data@academy:/var/www/html$ls-latotal20drwxr-xr-x4rootroot4096Aug132020.drwxr-xr-x3rootroot4096Aug72020..drwxr-xr-x12www-datawww-data4096Aug132020academydrwxr-xr-x12rootroot4096Aug132020htb-academy-dev-01-rw-r--r--1www-datawww-data50Aug92020index.php# We are at -dev-, is a good idea to check the current working files at academywww-data@academy:/var/www/html$cdacademy/www-data@academy:/var/www/html/academy$ls-latotal280drwxr-xr-x12www-datawww-data4096Aug132020.drwxr-xr-x4rootroot4096Aug132020..-rw-r--r--1www-datawww-data706Aug132020.env-rw-r--r--1www-datawww-data651Feb72018.env.example-rw-r--r--1www-datawww-data111Feb72018.gitattributes-rw-r--r--1www-datawww-data155Feb72018.gitignoredrwxr-xr-x6www-datawww-data4096Feb72018app-rwxr-xr-x1www-datawww-data1686Feb72018artisan<...>
There is an interesting hidden file called .env, type cat .env
Usually the logs located at /var/log/audit/ are important, but they have a LOT of information, a good alternative is to use "grep" to find relevant data.
Target Terminal [cry0l1t3]
$cd/var/log/audit/# Remember that our current uid is 1002, so we need another one.$grep-r"uid=1001"|grep"cmd"audit.log:type=USER_CMD msg=audit(1612880564.224:115): pid=1336 uid=1001 auid=1001 ses=1 msg='cwd="/home/mrb3n" cmd=636F6D706F736572202D2D776F726B696E672D6469723D2F746D702F746D702E6F4A4833443269514D322072756E2D7363726970742078 terminal=tty1 res=success'
audit.log:type=USER_CMD msg=audit(1612880564.412:119): pid=1353 uid=0 auid=1001 ses=1 msg='cwd="/tmp/tmp.oJH3D2iQM2" cmd=7375646F202D4B terminal=tty1 res=success'
audit.log:type=USER_CMD msg=audit(1612880607.016:128): pid=1788 uid=0 auid=1001 ses=1 msg='cwd="/tmp/tmp.oJH3D2iQM2" cmd=2F7573722F62696E2F656469746F72202D2D202F terminal=tty1 res=success'
<...># From here, we want:# 2F7573722F62696E2F656469746F72202D2D202F# Between "cmd=" and "terminal=
From here, we want a hash like "2F7573722F62696E2F656469746F72202D2D202F" between cmd= and Terminal=, to apply xxd -ps -r