TwoMillion Machine
Full Linux compromise through JS deobfuscation, API enumeration, command injection, lateral movement via credential reuse, and CVE-2023-0386 kernel exploitation
About Target
TwoMillion is an Easy difficulty Linux box that was released to celebrate
reaching 2 million users on HackTheBox. The box features an old version of the HackTheBox
platform that includes the old hackable invite code. After hacking the invite code, an account
can be created on the platform. The account can be used to enumerate various API endpoints,
one of which can be used to elevate the user to an Administrator. With administrative access,
the user can perform a command injection in the admin VPN generation endpoint, thus gaining
a system shell. A .env file is found to contain database credentials and due to
password reuse, the attacker can login as user admin on the box. The system kernel
is found to be outdated and CVE-2023-0386 can be used to gain a root shell.
Attack Chain
- Phase 1 Reconnaissance & Host Setup
- Phase 2 Path Discovery & JS Deobfuscation
- Phase 3 Invite Code Generation & Registration
- Phase 4 API Enumeration & Vertical Escalation
- Phase 5 OS Command Injection & Reverse Shell
- Phase 6 Lateral Movement via Credential Reuse
- Phase 7 Kernel Exploitation (CVE-2023-0386)
Phase 1 Reconnaissance
I performed an initial active reconnaissance using nmap scanning on the target IP
address to identify open ports and running services.
Scan Results
| Port | Service | Details |
|---|---|---|
| 22/tcp | SSH | OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | HTTP | nginx 2million.htb |
Host Setup
I added 2million.htb to my /etc/hosts file:
$ sudo echo "10.129.227.172 2million.htb" >> /etc/hosts
Phase 2 Path Discovery
I performed a path discovery across 2million.htb using gobuster.
During enumeration, I discovered the /invite endpoint.
After navigating to the /invite page:
While inspecting the page, I noticed it loaded a JavaScript file named
inviteapi.min.js containing obfuscated code:
eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return '\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('...',24,24,'...'.split('|'),0,{}))
Phase 3 JS Deobfuscation
I deobfuscated the code using de4js, which produced the following readable JavaScript:
function verifyInviteCode(code) {
var formData = {
"code": code
};
$.ajax({
type: "POST",
dataType: "json",
data: formData,
url: '/api/v1/invite/verify',
success: function (response) {
console.log(response)
},
error: function (response) {
console.log(response)
}
})
}
function makeInviteCode() {
$.ajax({
type: "POST",
dataType: "json",
url: '/api/v1/invite/how/to/generate',
success: function (response) {
console.log(response)
},
error: function (response) {
console.log(response)
}
})
}
makeInviteCode() → Generates a new invite codeverifyInviteCode(code) → Checks if a code is valid
To better understand the API, I intercepted the verification request:
The API uses JSON responses.
Generating Invite Code and ROT13 Decryption
I went to the browser console and executed makeInviteCode():
I noticed that data were encrypted in ROT13 cipher:
After decryption, I found the endpoint /api/v1/invite/generate:
Base64 Decryption
2F4BN-YI8OH-B0SCL-L8OE6
Phase 4 Account Registration
The key was inserted and accepted successfully:
After registration, I gained access to the platform:
API Endpoints Enumeration
I uploaded a VPN file by clicking on the Connection Pack button and intercepted
the GET request:
I then executed a curl request with verbose and silent options to enumerate
available API endpoints:
The server responded with a JSON list of API endpoints. The admin had
3 API endpoints with GET, POST, and PUT
methods.
When I attempted to generate an admin key with the admin endpoint
/api/v1/admin/vpn/generate, the key was not generated due to insufficient privileges.
The first admin endpoint /api/v1/admin/auth confirmed this:
Phase 6 Vertical Privilege Escalation
After discovering the correct PUT request format with
Content-Type: application/json and the required parameters, I successfully
escalated my user to an administrator.
is_admin: 0 → 1
Phase 7 OS Command Injection
I injected ;whoami; into the username field. My suspicion fell on the
exec() or system() PHP functions, which are common in admin-only
features and often lack proper sanitization.
For example, the vulnerable code probably looked something like this:
$username = $json->username;
exec("/usr/bin/cat /var/www/html/VPN/user/$username.ovpn");
The endpoint POST /api/v1/admin/vpn/generate was vulnerable, and
OS Command Injection was performed successfully.
Reverse Shell via OS Command Injection (Base64 Bypass)
Since the application had restrictions that prevented special characters, I encoded the reverse shell payload in base64 to bypass this restriction.
I injected the payload into the username parameter, piping it to base64 -d | bash for decoding and execution:
Netcat Listener
www-data user
Phase 8 Lateral Movement
I attempted lateral movement from www-data user to the
admin user using various techniques.
While inspecting the /var/www/html directory, I discovered a .env file
containing database credentials:
DB_USERNAME=adminDB_PASSWORD=SuperDuperPass123
The discovered password was successfully reused to authenticate via SSH and MySQL:
SSH Authentication
MySQL Authentication
admin user via SSH
Phase 9 OS Privilege Escalation
After gaining initial access as the admin user, I performed system enumeration to
identify potential privilege escalation vectors.
I tried common privilege escalation techniques like SUID binaries, capabilities, sudo rights,
and cron jobs—nothing worked. I then checked environment variables for PATH
hijacking or sensitive variables, and I found a MAIL variable pointing to
/var/mail/admin.
I checked the mail content and noticed that the admin had been warned to patch the kernel against an OverlayFS/FUSE vulnerability:
Kernel Version Enumeration
OS Version Enumeration
5.15.70-051570-generic is vulnerable
to CVE-2023-0386 (OverlayFS/FUSE local privilege escalation).
Exploit Execution
With the vulnerability confirmed, I proceeded to obtain a public POC exploit:
$ git clone https://github.com/sxlmnwb/CVE-2023-0386
$ cd CVE-2023-0386
$ make
$ ./fuse & & ./exp
I cloned the POC, transferred it to the target machine, and executed it successfully:
Complete Attack Chain
| Phase | Technique | Target | Result |
|---|---|---|---|
| 1. Recon | Port Scan | 22 (SSH), 80 (HTTP) | Service discovery |
| Path Discovery | /invite |
Invite page found | |
| JS Deobfuscation | inviteapi.min.js |
API endpoints exposed | |
| 2. Initial Access | Invite Generation | POST /api/v1/invite/generate |
Valid invite code |
| Registration | POST /api/v1/user/register |
Standard user created | |
| 3. Web Privesc | API Enumeration | GET /api/v1 |
Admin endpoints discovered |
| Vertical Escalation | PUT /api/v1/admin/settings/update |
is_admin: 0 → 1 |
|
| 4. System Access | Command Injection | POST /api/v1/admin/vpn/generate |
username=test;id; |
| Reverse Shell | Base64 encoded payload | www-data shell |
|
| 5. Lateral Movement | File Discovery | /var/www/html/.env |
admin:SuperDuperPass123 |
| SSH Reuse | ssh admin@2million.htb |
admin user access |
|
| 6. Root Escalation | Kernel Enumeration | uname -r → 5.15.70 |
CVE-2023-0386 identified |
| Email Warning | /var/mail/admin |
OverlayFS/FUSE confirmed | |
| Exploit Execution | ./fuse && ./exp |
Root shell |