# Nmap 7.94SVN scan initiated Fri Nov 1 20:51:24 2024 as: nmap -p22,80,33060 -sCV -oN targeted 10.129.148.205Nmap scan report for academy.htb (10.129.148.205)Host is up (0.10s latency).PORT STATE SERVICE VERSION22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)| ssh-hostkey:| 3072 c0:90:a3:d8:35:25:6f:fa:33:06:cf:80:13:a0:a5:53 (RSA)| 256 2a:d5:4b:d0:46:f0:ed:c9:3c:8d:f6:5d:ab:ae:77:96 (ECDSA)|_ 256 e1:64:14:c3:cc:51:b2:3b:a6:28:a7:b1:ae:5f:45:35 (ED25519)80/tcp open http Apache httpd 2.4.41 ((Ubuntu))|_http-title: Hack The Box Academy|_http-server-header: Apache/2.4.41 (Ubuntu)33060/tcp open mysqlx?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.94SVN%I=7%D=11/1%Time=67253147%P=x86_64-pc-linux-gnu%SF:r(GenericLines,9,"\x05\0\0\0\x0b\x08\x05\x1a\0");Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelService detection performed. Please report any incorrect results at https://nmap.org/submit/ .# Nmap done at Fri Nov 1 20:54:20 2024 -- 1 IP address (1 host up) scanned in 176.38 seconds
OS Version (Codename)
In Linux Systems, the Operative System Version could be extracted through Launchpad
According to the Version Column Data of the Comprehensive Scan, proceed as follows β
No information related to the Service running in 33060 Port is displayed
Letβs move into the next for the moment
80 - HTTP
General Information
Banner Grabbing
Academy/scans
nc -v 10.129.148.205 80 <<< ""
Command Output
Academy/scans
10.129.148.205: inverse host lookup failed: Unknown host(UNKNOWN) [10.129.148.205] 80 (http) openHTTP/1.1 400 Bad RequestDate: Sat, 02 Nov 2024 07:10:31 GMTServer: Apache/2.4.41 (Ubuntu)Content-Length: 301Connection: closeContent-Type: text/html; charset=iso-8859-1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>400 Bad Request</title></head><body><h1>Bad Request</h1><p>Your browser sent a request that this server could not understand.<br /></p><hr><address>Apache/2.4.41 (Ubuntu) Server at 127.0.1.1 Port 80</address></body></html>
The Web Server is an Apache, if a Local File Inclusion arises in the Web Application, we can start thinking about Apacheβs Default Logs Paths to achieve an RCE via Log Poisoning
Server HTTP Response Headers
Academy/scans
curl --silent --request GET --location --head "http://10.129.148.205"
# Nmap 7.94SVN scan initiated Sat Nov 2 08:05:11 2024 as: nmap -p80 --script http-enum -oN simpleWebScan 10.129.148.205Nmap scan report for academy.htb (10.129.148.205)Host is up (0.053s latency).PORT STATE SERVICE80/tcp open http| http-enum:| /admin.php: Possible admin folder|_ /login.php: Possible admin folder# Nmap done at Sat Nov 2 08:05:23 2024 -- 1 IP address (1 host up) scanned in 11.43 seconds
Two interesting resources are extracted, a Login Panel and one related to web administration
Furthermore, the above resources are PHP Scripts, therefore, we know that the Server side Language Programming is PHP
So, if a Command Injection or an RCE occurs, we can start thinking in several php functions to run commands in the system such as exec(), shell_exec(), system()
Web Technologies #1
Once you access the website, letβs check again the Web Technologies reported by Wappalyzer
Zoom In
PHP as Programming Languages again
Browser-Based Web Revision
The following is displayed as a Home Page β
Zoom In
There is a Login section which corresponds to the above found login.php resource
The other one is a Register section, related to a register.php file
Login.php
Zoom In
Trying to spray common credentials such as admin:admin, guest:guest or similar does not work
We can run this script to generate a dictionary (like Cewl does) and try to bruteforce the Login Panel
Since this website seems to be a custom one i.e. not a known CMS, we cannot find any default credentials
Therefore, letβs try to check the registration funcionality in the register.php and create a valid user if It allows it
Register.php
Zoom In
We intercept with a HTTP Proxy, such as Burpsuite, the HTTP request and send it to the Repeater section
Zoom In
A POST Parameter that we could not be able to see it before in the Register Panel draws our attention
Its name is roleid and It seems such as Boolen or Integer Parameter. Its default value is 0
We can interpret that the default value, 0, is related to an Standard User default Role
Letβs see what happens if we change that Parameter value to 1
Zoom In
A 301 HTTP Status Code followed by a 200 one appears in the HTTP Server Responses
It seems that our user has been created, letβs log in in the login.php resource and see what happens
The following web page appears after log in β home.php
Zoom In
If we take a look to the website, there is nothing interesting there according to certain functionalities. It is a fairly static website
Remember that we found earlier an admin.php resource
Admin.php
Zoom In
Another login panel
It is not too much reasonable to think that we can log in with a Standard Username
But we altered the default Register Process modifying the roleid parameter
Thus, letβs see if we can log in
And weβre in!
Exploitation
RCE via Insecure Object Deserialization
An admin-page.php is displayed with the following content in the Admin.php resource
Zoom In
Some sensitive information is leaked
Some Potential System or Web Application Users β cry0l1t3 and mrb3n
A subdomain β dev-staging-01.academy.htb
According to what It appears, It seems that the above subdomain is related to another Web Application with a issue to fix
Letβs add the corresponding line in the /etc/hosts file and check it
In this case, this Laravel Application has Debug Mode enabled since one issue, with the application, has been reported as we saw earlier
Note that, when Laravel Debug Mode is set, some interesting information is leaked such as the Web Application System Path, Enviroment Parameters and other juicy data
But, amongs all this information, the following stands out β
Zoom In
APP_KEY
Database Credentials
Since we tried before to connect to the 33060 Port related to a MySQLx service but we couldnβt, letβs store this credentials for later use
In the other hand, we have the APP_KEY value, Normally, this APP_KEY is used by the Laravel Application to encrypt some authentication or session objects
This prevents those objects from being modified on the Client-Side. Therefore, no malicious payload crafting or modification of those objects can be performed
But, if the Laravel APP_KEY is leaked and the Object Deserialization performed in the Server-Side is not sanitized correctly, an attacker could craft a malicious payload to perform some Code Execution when the payload is deserialized
The above situation arise in certain Laravel versions, being these ones vulnerables, as mentioned here
Error opening config file (Permission denied)NOTE - using built-in logs: /var/log/audit/audit.log1. 08/12/2020 02:28:10 83 0 ? 1 sh "su mrb3n",<nl\>2. 08/12/2020 02:28:13 84 0 ? 1 su "mrb3n_Ac@d3my!",<nl\>
The data which appears in the second line seems like a Password and It contains mrb3n, an existent System User
Letβs try to log in as mrb3n using the above string
and Boom Again!
We have been able to migrate to the mrb3n user
Sudo Privileges
If we list the Sudo Privileges of the current user β
sudo -l
Command Ouput
[sudo] password for mrb3n:Matching Defaults entries for mrb3n on academy: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/binUser mrb3n may run the following commands on academy: (ALL) /usr/bin/composer
The current user can run as ANY USER the /usr/bin/composer binary, i.e. we can run this binary as Root
So, if we are able to spawn a shell through this binary, we can spawn it as Root