HackTheBox - Falafel - Retired
Recon
Let's use threader3000 for our recon scan. It's a threaded scanner written in python that does a super quick up/down scan on all TCP ports, then suggests a nmap scan based on the results. It will automatically save the nmap scan results as XML, then we can convert it to HTML
Not a whole lot to go on here just port 80 and 22, nmap does thinking it s a linux (Ubuntu) box
On most hackthebox machines port 22 SSH is just a means to connect and not an attack path so let's check out port 80 and see what we see
Falafellovers
There is just this page and a login page
Nmap said there was a robots.txt file too, let's check it out.
You don't want to index .txt files huh?
That really makes me want to look for .txt files.
-X with dirb let's you specify an extension or list of extensions to try
Well it only found the robots.txt file we already knew about.
Weird…. Why would that be in the robots.txt just to hide the robots.txt? Let's try another wordlist and see if we find anything.
Cyberlaw.txt?
Hmmm this note is interesting….
A user named Chris has alerted the admin that they can login as admin without knowing the password ( Sounds like SQLi to me). They also say they can abuse an image upload feature to take control of the website.
Running dirb with default options shows a couple of different folders
Most of them we don't have access to, yet
/uploads looks like it's pretty promising.
Let's pivot to the login page.
Let's try admin/admin for a login.
We get this interesting response from the server.
Wrong identification: admin
Is this leaking that admin is a valid login but just the wrong password?
Let's add some random gibberish to the end of admin for the username to see if we get a different response.
admin9646846589
It does, for non valid users we get "Try again.." but for valid users we get the "Wrong Identification" error.
So we know that admin is a valid username, let's capture that login again in burpsuite to see if we can get any more info
Exploit
Since we are thinking it might be sqli here, let's save this request out to a file called request.txt
If we try just a standard sqlmap we get back messages saying it might not be vulnerable, but we are pretty sure it is. So let's run this command with the string option to let sqlmap know what happens when you get the wrong password for a known account..
Here is a great little site which you can use to learn more about sqlmap
https://hackertarget.com/sqlmap-tutorial/
Now sqlmap can detect the vulnerability here.
Now we can run the same command and add --tables to get table information
Here we can see two Databases
Information_schema the default DB and a DB named falafel
Let's see what is the DB named falafel specifically
A table named users, let's dump the contents of that table.
By using --dump
Looks like we have two users account a normal user named chris ( they guy who alerted the admin to the sqli) and the admin, along with their hashses
Let's use hashid to try and figure out what type of hash this is
Could be an md5 let's use hashcat to try and break it.
0 is the mode for a md5 hash
Looks like Chris' password is juggling.
And we are now able to login as chris
I was hoping to see an upload area here, but I don't see anything… Obviously chris was able to put this in here, so there has to be a way to upload data…
Not seeing a super obvious path here, why are they talking about juggling?
Let's google "juggling pentest" to see if there is some path we don't know about yet.
The first result is on owasp
https://owasp.org/www-pdf-archive/PHPMagicTricks-TypeJuggling.pdf
Which talks about Type Juggling.
If a developer needed to compare the contents of two variables and they are different types, like for example compare the contents of an integer and a string.
In php in the background it attempts to make the contents of the variables the same type so it can process a comparison. So It might take a string and try to convert it to an integer. This is documented much better than I can explain it in the link above, so check it out.
Following down the rabbit holes that we do when researching new techniques you might stumble across something called magic hashes…..
https://www.whitehatsec.com/blog/magic-hashes/
These are known hashes that leverage php type juggling to hopefully equate to true even if it's not the same hash.
So the value of
Has a md5 hash of
Maybe we can use this to attack the admin account, which hopefully has access to the upload.php we found earlier.
So on the login screen if we do
Great that worked, we now have access to the upload feature to upload files via url, we found the /uploads/ folder earlier in our enumeration, which we assume will be the landing place for whatever we upload here… let's test that out first.
Let's serve up a png file using updog and see if it works.
First let's start updog in a directory with a png file ( I grabbed a copy of the HTB logo for testing)
Then we just need to tell the upload page where we are hosting it from
http://10.10.14.15:9090/HTB.png
Then we click upload and see this
So that is way too much info to let anyone see
We now know that they are using wget to download the file to /var/www/html/uploads and then saves it
And if we try to browse to http://falafel.htb/uploads/1027-1853_4ffebf20a38154c7/HTB.png
We see the logo that we uploaded.
Cool, so we can upload files. It doesn't rename them… and it tells us where we can find them.
Let's try uploading a php webshell.
It doesn't like it "Bad Extension"
Now we are up against it…. Since this isn't a direct upload, where we might capture the upload in burp and insert some php inside of the png in transit like we used on Popcorn
https://blog.circusmonkeysecurity.com/2020/09/hackthebox-retired-popcorn-updated.html
Or magic
https://blog.circusmonkeysecurity.com/2020/08/hacktheboxeu-retired-magic.html
Since we know that they are using wget to download the file let's see if we can find a vulnerability for it.
After a google search we might come across this post
Which basically says that wget will shorten a file name if the name is over 240 characters, which is more a mitigation of possible issues with saving super long file names in linux itself than really a vulnerability.
Let's give it a shot with my favorite php webshell
https://github.com/WhiteWinterWolf/wwwolf-php-webshell/blob/master/webshell.php
Let's write a little python script to pop out the amount of characters we need. Let's start by adding over the 240 amount to see if we see it rewrite the file name
I renamed the file with 240 a's inserted and put this into the upload function.
Cool, we can see it strip the file name so maybe we can get this down to what we want it to do.
Just a little trial and error here to figure out exactly what length of a file name is needed to have it finally save our webshell as .php.
So now if we go to
We hopefully see our webshell..
And we can see we are in as www-data
Let's use this to get a proper shell
Let's setup our listener on our kali box first
Then we put this in execution window on our web shell
No -e option with this version of netact, fine let's try mkfifo
And we have our first interactive shell
Poking around in the file system we find this connection.php file.
Looks like a db on this machine with a username and password..
Poking around we don't have access to either user folder on the mahine… but we have a copy of what might be moshe's password if they reused their login password for the DB.
Let's try to su as moshe.
Ok need to upgrade our shell… we can hopefully use python to upgrade it.
Ok what about python3
Cool now we can get the user.txt file
Now we need to figure out how to escalate….
Let's use our still running updog server to download a copy of linpeas.sh (linux privilege escalation script) to falafel.
Then give the script execution rights
It looks like moshe is a part of a group that we don't normally see in the results.
Moshe is a member of the video group.
And as always when we see something we are familiar with…. We google it
So googling "video group linux pentest"
One of the results is
https://book.hacktricks.xyz/linux-unix/privilege-escalation/interesting-groups-linux-pe
Which says member's of this group can access the screen output… and in our case
Yossi is currently logged in, and we can grab a file that should show us the content of their screen.
This could be saved as a file on the system in /dev/
In there we can see a file name fb0 which the video group has access to.
Let's make a copy into a temporary folder.
Then according to the blog we need to find of the terminal output so we know what size to open the file as.
Now let's use netcat to transfer the file to our kali box
First let's set up a new listener on our kali box
Then we can send the file over with netcat on falafel
The blog says to use GIMP to open the file
If you don't have it on your kali box you can install it with apt
After it is installed and opened. Choose open file
Find the screen.raw file and open Select file type and select the file and Raw Image Data
If we set the width to 1176 and height to 885 we can start to see something, If we start trying some different image types we find that RGB565 Big Endian let's us see more clearly
Here we can what looks like yossi attempting to change their password to
Let's see if we can ssh in as yossi now
Good new we can
No flag in the home directory for yossi, Let's run linpeas again as yossi to see if we can find our next step.
This time we see yossi has membership to the group disk...let's google that
Google "linux disk group privilege escalation"
We found this blog
https://reboare.gitbooks.io/booj-security/content/general-linux/privilege-escalation.html
It basically says members of this group have full read/write to a anything in the /dev folder which probably includes all disks like /dev/sda1
It mentions a program called debufs which I'm not familiar with… so guess what we do ? we google it.
If we google "debugfs pentest" we find this site https://www.cyberark.com/resources/threat-research-blog/how-i-hacked-play-with-docker-and-remotely-ran-code-on-the-host
Which says we can basically use this program to mount the drive and use ls and cd and whatever we want to read all the data.
So let's give it a try
The output looks alot like the list of the system files.
So now we can cd /root
Now if we ls again
Hopefully we can just cat out the root.txt file now
That is good and all but we want to get a real shell on this guy..
Let's see if there is anything in the /root folder that might help us out.
Look there is a .ssh folder maybe we can find roots private key in there.
Looks like there is a file name id_rsa, id_rsa.pub and authorized keys.
If we look at id_rsa.
That looks like it might be a private key. Let's copy the contents to a file on our kali box and name it id_rsa
After we have it saved, we need to change the permissions on the file or else ssh will yell about the permissions being to open and ignoring the file
Now we can try to log in as root with this key
And then
We are in as root.
Fun.
Comments
Post a Comment