Code
Walkthrough and writeup how I pwned Code machine on Hack The Box
Last updated
Walkthrough and writeup how I pwned Code machine on Hack The Box
Last updated
As usual I do the nmap
to recon the available open port in this server
From the nmap
output we can see that only 2 port exists, which is port 22
and port 5000
, so we can assume that the initial foothold is come from the port 5000
When I visit the port 5000
in the browser the result is python editor, so at this point I assume that we can gain shell access from here
But, when I try the traditional shell access the app is response with the some restriction, so we can assume in the server code has the some blacklist keyword, so this challenge is like the python jail
, and we must bypass it to get the shell access
The bypass is so simple and not as complicated like the pyjail
as usual.
Here is the python code to bypass the restriction, from here we can try to make reverse shell and gain the full shell access
Actually we can just read the user flag from the python editor before, but for the next exploitation we can use reverse shell to get the full shell access.
Listen for ping-back reverse shell connection
Then, update the python code above to trigger the ping-back connection and get the shell
Cool, next get the user flag
This server has 2 user available, we can proof it when list the home
folder
I assume is we must login as martin
user first then into root
user.
We know that the python editor before has the database instance because the website has login and register feature, and we also confirm from the app source code
Let's deep dive to see the database
We got something here, the output is listed the martin's credential, let's try to crack the password if applicable, I use crackstation for this job
Fire, we got the password, try to login using the ssh
Nice success.
Then what? of course we must login into root
user, let's see if martin
user have sudoers access
There are available program that can fully run as root or sudo in the martin user, because this is the custom program we should try to analyze how to program is works.
This is backy.sh
bash script program
At the end of program this program run the backy
program, which is the open source backup cli program, you can see here
From the bash script and the backy cli above we know that we can't execute some shell, but because it has the backup logic we can move the /root/root.txt
as the backup to retrieve the flag, but the problem is the program validate the allowed path in the value of directories_to_archive
which must startswith /var
or /home/
Then how we can bypass the restriction? oke focus from this logic below
The logic is try to remove the ../
character if the exists in the directories_to_archive
value, so the purpose is to prevent the path traversal
, but you know what we can do simple bypass for it.
We can just input something like this ..././
then it will convert to ../
, but why? yeah because the logic only replace or delete exact ../
pattern, and not make the recursive check, then we can do like this to bypass
So, the final json payload is like this
Then if the exploit success we will get the bz2 tar file, let's try to unarchive this
That's it, thank you!!!