This is my first walkthrough post ever. I decided to write this series of posts about exploitation of machines available on CTF or other platform like Hack The Box. This time the taget was SOCCER machine.
My goal is to describe the methodology and track the general process used to reach the goal: obtain a root shell on the machines.
initial footprint
Initial footprint is the phase where we try to get as much information as possible using a multiple methods: from google search (or osint in general), DNS query, etc.
On HTB machine this process is not required because we already have a target well defines in terms of IP target and we can start to enumerate services directly.
Usually hacking HTB boxes require a black-box methodology: no information is provided by the platform except the name of the machine… which sometime it gives some hints about the the journey to root.
The scope of initial footprint is to have an idea of which services are exposed by a machine to figure out its entry points, the attack surface, and in general how we can interact with that.
I like to perform three types of service scan:
quick scan over the most common TCP ports
full TCP scan
UDP scan
quick Scan
To obtain quickly some information, usually I start with basic port scan. Bby default namp will scan the top 1000 most common ports.
nmap -sV 10.10.11.194 -oG soccer.quick.nmap
After the initial scan I proceed with full scan and udp scan:
nmap -sV 10.10.11.194 -p- -oS soccer.full.nmap
Initial quick scan alreay provided all the infomation in very few second (20sec!!!). Full scan didn’t give much more information as the machine just have ports 22, 80, 9091 opened… so I just omitted the results of full scan.
service enumeration
Looking at the service exposed by the machine, two services capture our attention: port 80 and 9091.
We leave port 22 as last chance as usually it doesn’t provide possibility to attack the box in a simple way due:
encrypted traffic
auth required - brute force is time consuming
very common and tested service - so not common exploit
80/tcp open http nginx 1.18.0 (Ubuntu)
HTTP service with related website/webapplication usually is more likely to expose wider attack surface so it’s a good target to focus on during a pentest. When we try to access a HTTP/HTTPS server we should take in consideration, the possibility of having multiple VHOST on the same server.
On HTB platform, every machine have a FQDNs like the box name in htb domain: in this case we have soccer.htb. Be careful… this is just a rule of thumb and more FQDN migth be assigned to same machine. Additional discovery/enumeration provess is suggested like:
check subject alternative names (SAN) in the certificate (if the service is in TLS)
check hosts file in the server as soon we have access on it
check the reverse proxy and/or webserver/application-server VHOST configuration
After having added the box FQDN into pentest machine hosts file, we can start the HTTP service enumeration.
The first and basic way is to use a standard browser to check in easy way if we can access the website, if we can recognize of-the-shelf product, etc.
Using our preferred browser we can see the soccer webpage….but doesn’t see to have any real features other than some static code.
Probably the basic page could be a sort of rabbit-hole just to waste our time on that. I decided to perfom a website enumeration to detect other hidden pages (not linked direcly to the homepage).
To perform webpage enumeration we could use several tool (dirb, burp, etc.) or custom scripts. At the moment, my preferred tool is Gobuster for its very good performances, good visualization capabilities.
Our fuzzer found additiona page called /tiny who respond with HTTP 301 message which indicate a redirect to different page (i.e. to an authentication page).
Checking again with our browser we will be in front to Tiny File Manager login page!
Facing a login page, we should try to identify a way to access or bypass the login process and this would require multiple tests to identify how the login process works, if some security measures are in place like anti-brute force, MFA, etc. I.e some possible tests could be:
check default credentiala
bruteforce
looking/searching for authentication bug/vulnerability
steal some credential (in real scenario)
Searching on Internet some info about tiny file manager, we could find its opensource project, hosted in GitHub. Let’s try to see if default credential exists on documentation: searching in Tiny File Manager documentaion we can easely find this information.
admin/admin@123user/12345
Using default credentials we were able to access the filemanager.
Tiny File Manager is a web application which provide basic file management capability to our server using a browser. Having access to the web application we can user used to download and upload files on the webserver.
We can try to upload some webshell and check if there are any restriction on file type and if we can execute the webshell code.
I simly tryed to upload a basic php webshell and I used the browser to open it…
After opening xabaras.php the php code is executed and shell is opened in the attacker machine.
We obtained a shell on the system, but with low privileges (www-data). Now it’s time to enumerate more to do a privilege escalation. We can now enumerate more: looking for additional services listening on the machine, additional vhosts, additional users, etc.
Let’s try to see if other websites are hosted on same box.
There is additional website soc-player.soccer.htb.
A login page is displayed and there is a registration and login form. In this case seems possible to register for an account and login the the website.
After login to the application, a page with a form used to check ticket number. In case we insert the correct number it’s ok if not an error message is displayed… Very strange and CTF style application :)
Using browser developer tools I tryed to figure out which type of mechanism is behind the form… reading the javascript code I saw a websocket request!!! That the little hint of the box name SOCcer… I suppose analyzing the websocket should be the correct way to solve the machine.
I started to learn more on WS: how to enumerate more, on type of attacks, etc. Considering that ticket-id could be placed on an internal database I tryed to use sqlmap which have some parameters to test WS services. The WS seems to be SQL-injectable and I was able to dump all the DB and tables.
Looking on the results I can find my new user&password and also other entries!
When we found password we can try simple password-reuse technics to see if the same password is used for multiple users/services, etc.
:) Additional and more powerful shell obtained with a the user-flag!
To complete the box we should escalate our privileges to root - let’s try to find setuid executables to see which command expose enougth attack surface.
A specific program has attracted my attention: DOAS. It’s not as common as sudo. So I decided to check its configuration.
Se I can run /usr/bin/dstat with root privileges without the need to use password. Loocking on the Net I found a DSTAT priv-escalation exploit.
The exploit is very simple: DSTAT use external python modules to perform additional data/stats computation - we just need to create an evil module, place it in correct folder and run the DSTAT command like root using DOAS.
Let’s run the exploit:
conclusion
This machine is an easy machine but it would require some additional information on WebSocket enumeration. The exploit porcess was straightforward with every steps clear and not rabbit-hole.
About
Luigi Vezzoso
Security professional with more than 15 year of experience in multiple aspects of cyber security - In my the spare time I like to train dogs.