Nmap
Let's start this off with an Nmap scan:
![](https://static.wixstatic.com/media/eb0517_c71064ff493947379bf21c61e8384f21~mv2.png/v1/fill/w_747,h_181,al_c,q_85,enc_auto/eb0517_c71064ff493947379bf21c61e8384f21~mv2.png)
Looking at the Nmap scan, we can see that there are only two ports open, Port 22 and Port 80.
As with most HTB boxes, SSH is not normally exploitable until credentials are gained to connect, so let's start with Port 80.
Enumeration
When looking at Port 80, I like to run recon in the background while I enumerate the website manually. So at this point I have ran the following tools before visiting the website:
- Feroxbuster
- GoBuster
- wfuzz
- nikto
While these are running lets view the website being hosted on Port 80:
![](https://static.wixstatic.com/media/eb0517_28bee718569643d3a77145a4b620f1fe~mv2.png/v1/fill/w_714,h_534,al_c,q_90,enc_auto/eb0517_28bee718569643d3a77145a4b620f1fe~mv2.png)
The website looks like it is for a team of Bug Bounty hunters or Pen testers.
While enumerating the website manually, two input form areas were identified, that could each be tested.
The first was a message form on the main page:
![](https://static.wixstatic.com/media/eb0517_4cbf5d3aaf454851a5694060922eee50~mv2.png/v1/fill/w_711,h_357,al_c,q_85,enc_auto/eb0517_4cbf5d3aaf454851a5694060922eee50~mv2.png)
The second, a form titled 'Bounty Report System - Beta', in the /log_submit.php directory (found after trying to attempt to access the Portal Page, then selecting ''here'):
![](https://static.wixstatic.com/media/eb0517_821b7327592d49fdb352e688bee72630~mv2.png/v1/fill/w_592,h_200,al_c,q_85,enc_auto/eb0517_821b7327592d49fdb352e688bee72630~mv2.png)
With the second form being in supposed 'Beta', this was more than likely our foothold into this box.
Foothold
So lets see how it processes and stores the information we give it.
First I entered in random information into each input field and clicked Submit, which outputted the following:
![](https://static.wixstatic.com/media/eb0517_db5702cebb564153a622412b5908e583~mv2.png/v1/fill/w_313,h_136,al_c,q_85,enc_auto/eb0517_db5702cebb564153a622412b5908e583~mv2.png)
Now lets look at this deeper with Burp Suite.
Sending another identical request, the following is shown in Burp:
![](https://static.wixstatic.com/media/eb0517_2a36c6d245874ccebeb746b6dad4bba9~mv2.png/v1/fill/w_460,h_369,al_c,q_85,enc_auto/eb0517_2a36c6d245874ccebeb746b6dad4bba9~mv2.png)
The above request holds the data in one data string, and can be presumed to be base64, once URL decoded.
Using an online Base64 Encoder and Decoder (https://www.base64encode.org/), the above data held in the 'data' variable is decoded as the following XML data:
![](https://static.wixstatic.com/media/eb0517_73b742dccc9e490a9cc353e18bcb4532~mv2.png/v1/fill/w_560,h_186,al_c,q_85,enc_auto/eb0517_73b742dccc9e490a9cc353e18bcb4532~mv2.png)
It is clear from this that we are looking at some kind of XML External Entities (XML) vulnerability. And so the first thing to do is see if we can maliciously change this XML data to reveal sensitive data. In order for the web server to understand it, we must keep the same format as the original data (including the fact that in the request it is base64 encoded, and then URL encoded).
An example of a malicious XXE payload we could use, and in the correct format, is:
![](https://static.wixstatic.com/media/eb0517_a4e75c4e1e7047069b27b147c055cf9f~mv2.png/v1/fill/w_288,h_195,al_c,q_85,enc_auto/eb0517_a4e75c4e1e7047069b27b147c055cf9f~mv2.png)
The above attempts to read the /etc/passwd file of the machine. While it is important to enumerate the users on this machine, this is mainly to see if we can read files on the system, via this attack vector.
After base64 encoding, then URL encoding that output, and then placing this data into the 'data' variable within the web request, the web server replies with the following:
![](https://static.wixstatic.com/media/eb0517_342e5c4c79a74391924adf43e85f15fa~mv2.png/v1/fill/w_926,h_471,al_c,q_90,enc_auto/eb0517_342e5c4c79a74391924adf43e85f15fa~mv2.png)
Success! The web server replies with the contents of the /etc/passwd file, showing us the users on the system. (We should note these down for later SSH enumeration)
Now we have the ability to read internal files, lets see if we can view the source of any sub directories found from our background directory busting scans (we ran from the start).
Looking through the results of Feroxbuster, one subdirectory has a very interesting name:
![](https://static.wixstatic.com/media/eb0517_f397d3a3d4a2465db086043ef8cac75c~mv2.png/v1/fill/w_599,h_23,al_c,q_85,enc_auto/eb0517_f397d3a3d4a2465db086043ef8cac75c~mv2.png)
DB, usually standing for Database, should light up any pentesters eyes, as these normally contain very sensitive data, such as credentials.
Now lets see if we can read it using the same XXE vulnerability as before.
The following payload was again Base64 encoded, then URL encoded:
![](https://static.wixstatic.com/media/eb0517_cf83c0e81c72440bb6edfa74571d85c1~mv2.png/v1/fill/w_610,h_159,al_c,q_85,enc_auto/eb0517_cf83c0e81c72440bb6edfa74571d85c1~mv2.png)
And when entered into the 'data' variable, and sent to the web server, we got the following output:
![](https://static.wixstatic.com/media/eb0517_2ac7a8d5551f47a29360b3a26505f645~mv2.png/v1/fill/w_946,h_401,al_c,q_90,enc_auto/eb0517_2ac7a8d5551f47a29360b3a26505f645~mv2.png)
Now the response may look like a load of 'nada', but based on the last character being an '=' sign, this may indicate that this also, is base64 encoded.
Lets throw it in the base64 decoder and see what we get as output:
![](https://static.wixstatic.com/media/eb0517_a5757a4701634a1a84da5c898f61b16a~mv2.png/v1/fill/w_328,h_150,al_c,q_85,enc_auto/eb0517_a5757a4701634a1a84da5c898f61b16a~mv2.png)
Just like that, we are given credentials!
SSH Login
Now we have a password, we can match this password with users found from the /etc/passwd contents found earlier, and try and login in via SSH (Port 22).
First we should try the most likely username - development.
![](https://static.wixstatic.com/media/eb0517_24a030af9bd64c54a885328f8080d7db~mv2.png/v1/fill/w_544,h_65,al_c,q_85,enc_auto/eb0517_24a030af9bd64c54a885328f8080d7db~mv2.png)
![](https://static.wixstatic.com/media/eb0517_58e2674d65f844fdb85c3391f0c7725c~mv2.png/v1/fill/w_465,h_47,al_c,q_85,enc_auto/eb0517_58e2674d65f844fdb85c3391f0c7725c~mv2.png)
(If the credentials didn't work for this user, you could create a text file full of the enumerated username, and then use an SSH brute force attack, specifying the password found)
Great! You have now logged in using those credentials.
(This is your chance to go and grab that user.txt file and submit your first flag for this box)
Privilege Escalation
Looking at the file /home/development/contract.txt, you can see that the development user has been set permissions to 'test' something related to ticket submission and validation. Seeing the word permission should be a good indicator to use the sudo -l command, to view our current permissions as this user:
![](https://static.wixstatic.com/media/eb0517_a943b066287f4d0e8cf14dd6ac94aa97~mv2.png/v1/fill/w_848,h_143,al_c,q_85,enc_auto/eb0517_a943b066287f4d0e8cf14dd6ac94aa97~mv2.png)
As you can see from the output, we have permissions to run a ticketvalidator.py script via python3.8 as root. This is very likely our way to escalate privileges, so lets look at the script contents, to understand what it is doing:
![](https://static.wixstatic.com/media/eb0517_158e2af343be49989862a388be940ae2~mv2.png/v1/fill/w_596,h_815,al_c,q_90,enc_auto/eb0517_158e2af343be49989862a388be940ae2~mv2.png)
Before looking too much into the code, lets see if we have permissions to edit the file, to execute a quick win:
![](https://static.wixstatic.com/media/eb0517_6a06433014dd465e9df605bca5411837~mv2.png/v1/fill/w_632,h_36,al_c,q_85,enc_auto/eb0517_6a06433014dd465e9df605bca5411837~mv2.png)
Unfortunately no quick win today! We only have permission to read the file (and execute via python3.8)
Looking at the first section of the code, it asks the user to provide a file to read (the ticket). This is always great, as if we can make this file malicious, then get this script to run as root, we can elevate privileges.
In order for this file we create to be ran correctly, there are a number of requirements that need to be met, to 'validate the ticket', based off the code.
Requirements:
- Must have the 'md extension'
- First 3 lines must read:
# Skytrain Inc
## Ticket to
__Ticket Code:__
- The following lines after TicketCode must start with **
- Any text after ** and before the first '+' sign must be an integer that has a remainder of 4 when divided by 7
- Only when all the above conditions are met will the ** be removed and the line will be run
To help with this, you can find a few invalid tickets in the /opt/skytrain_inc/invalid_tickets directory:
![](https://static.wixstatic.com/media/eb0517_cfe8b1314c294a069b5bdbfe441683bc~mv2.png/v1/fill/w_570,h_47,al_c,q_85,enc_auto/eb0517_cfe8b1314c294a069b5bdbfe441683bc~mv2.png)
Using one of these as an example, we can copy one and alter it to make them valid, with an additional appended piece of malicious code.
The original ticket is:
![](https://static.wixstatic.com/media/eb0517_37aedad804f243019cdcbdcd7152ffb2~mv2.png/v1/fill/w_222,h_122,al_c,q_85,enc_auto/eb0517_37aedad804f243019cdcbdcd7152ffb2~mv2.png)
However, after altering it to make it valid (Changing T and C to capitals) it becomes:
![](https://static.wixstatic.com/media/eb0517_83ee114f4c654772917836b5b42731ed~mv2.png/v1/fill/w_196,h_122,al_c,q_85,enc_auto/eb0517_83ee114f4c654772917836b5b42731ed~mv2.png)
Running the script and providing it this ticket, the output is that the ticket is now valid.
Now we can just add an 'and' statement to append a reverse shell:
![](https://static.wixstatic.com/media/eb0517_9763c78592ec4b8e8950c540703fc6fd~mv2.png/v1/fill/w_551,h_121,al_c,q_85,enc_auto/eb0517_9763c78592ec4b8e8950c540703fc6fd~mv2.png)
Lets run the ticketValidator.py script using sudo, and provide our malicious .md file (ticket):
![](https://static.wixstatic.com/media/eb0517_ba0cb5963388468a969f2951f3e281b2~mv2.png/v1/fill/w_980,h_105,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/eb0517_ba0cb5963388468a969f2951f3e281b2~mv2.png)
Success!!! We have now pwned this machine, now go grab that root flag to finish the box!!
Thank you for reading, please be sure to like the blog if it was helpful, or message me any feedback!
Comentarios