Hackthebox released a new machine called awkward. On this machine, we got the web server where there is a JS file which gives us a route and manipulating the token gives access to the dashboard and also reveals the api endpoints which give the user info and ssrf through ssrf. We got the bean user. After that, abuse the sed command to get the www-data user, then to root abuse the mail command.
Nmap
Nmap tell us there are two open ports 22 ssh and 80 http and HTTP port redirect to http://hat-valley.htb/
Let’s quickly add this in our /etc/hosts file.
Port-80
Simple web page nothing interesting there
Checking the source code of the web page got the app.js file
The code inside app.js file is too messy, so I use online beautifier
In the code found a useful link which goes to /hr page
On the /hr page, it’s required creads to login
But if we see the cookies of the website, there is a token which is set to guest
Let’s change that to admin
After refreshing the page, we are inside the dashboard
But if you see there is a section for staff details which is empty and the status of the store is down
Let’s check the network tab to find where they fetch this details
And we found two useful links
/api/staff-details
/api/store-status
Going over to /api/staff-details we got the error called jwt malformed
Let’s delete the cookie and then see what error we got
Information Disclosure
After removing the cookie, we got the all user details as well as password for each user
I use crack station to crack that hashes because it’s look like it is sha256 hash
and one of the hash is cracked
Creads for Christopher - username: christopher.jones - password: chris123
I log in with these creads in /hr page
And got the JWT token, let’s try to crack the JWT secret
Cracking JWT Secret
I am using the official jwt2john python script
Convert the token into john format
And got the secret of the JWT
Secret of JWT - 123beany123
I create the JWT token with the username which we found, but there is nothing on the /dashboard page
So let’s move further with another api endpoint which we found /api/store-status
Server-side request forgery (SSRF)
The API endpoint is required a URL to check his status of that we can try SSRF on that
First, I try localhost URL with 80 port, and it is redirecting to http://hat-valley.htb/
So it’s conform that it is vulnerable to SSRF Now let’s try to enumerate the ports which is running on the internal network
And we got 3 ports running internally, let’s check them one by one
8080 port require JavaScript to run
3002 port give us the all API endpoints routes as well as their source code
Local File Inclusion (LFI)
Found an endpoint which is vulnerable to LFI
The AWK command is vulnerable, now the box name make sense
The AWK command passing the user variable which has the decoded JWT token username value which we can change anything we want
Because we have the JWT token secret, and we can create the token with any username or any fields we want
If we pass this as username /' /etc/passwd ' we got our desired output
And we can try this in our own machine as shown in the picture
Let’s go to jwt.io and generate the custom username token
And we got the /etc/passwd file
We got the 2 users
Bean
Christine
Let’s check the christine ssh key
Username field look like this
But we got no luck
Let’s check the bean user ssh key
Still no luck
Then I try to check the .bashrc file of bean user
And this time it’s works
We got the backup script path, let’s try to check that
alias backup_home=‘/bin/bash /home/bean/Documents/backup_home.sh’
And got the bean_backup_final.tar.gz file path, let’s get that file in our box
Path of the file is /home/bean/Documents/backup/bean_backup_final.tar.gz
Save the output inside the bean_backup_final.zip file
Extract that with file manager
And we got the home directory of bean user
Found a password of bean user inside .config/xpad/content-DS1ZS1
Creads of bean user - username: bean - password: 014mrbeanrules!#P
Let’s try to ssh in with that creads
Privilege Escalation
I run the linpeas but nothing found there, so I check the /etc/hosts file and I found a new vhost called store.hat-valley.htb
Let’s add that in our /etc/hosts file and check what’s running on that
But it’s required username and password
The website using nginx and the username and password prompt is coming from nginx because of .htaccess file which can usually be found inside /etc/nginx/conf.d/ directory
Got the Username, but the password is not crackable so let’s reuse the bean password on the prompt
Creads
username: admin
password: 014mrbeanrules!#P
And we successfully log in
And also we have the source code of the website inside /var/www/store
Reading the README.md will tell us about
They don’t use any database till now
They’re using the files to store data inside these directories
/product-details which store the details of the products
/cart which store the user items
They verify their product with first header line which looks like ***Hat Valley Cart***
Checking the cart_actions.php file
Remote Code Execution (RCE)
While checking the file, I notice this sed command to use to delete the cart file data, which we can use to get RCE
As you see in the GTFO bins, we use sed to execute our command, but they are using -n flag which run the command, but we can’t use that because of the Bad character detected
This loop will not allow us to get rev shell
So we can use -e flag which is given in the help of sed command, this allows us to pass the script where we can write our rev shell code
So let’s talk about how to abuse that sed command
First our input look like this ' -e "1e /tmp/shell.sh" /tmp/shell.sh '
Which will be replaced by $item_id
After replacing it’s look like this which close the SUFFIX and add a new flag -e which execute our script
So let’s prepare for that, first let’s create the shell.sh file which give us rev shell
After that, add a product in the cart
Checking that product in the cart/ directory, where the file name is same as our userId which will generate randomly
After that we need to remove the file because we can't edit that file
Then create the same user ID file with same content but with one change which is our item_id parameter which execute our script
Now you may ask why we need to add that content into cart file we just add that content while we’re deleting the cart item inside burp suite
The answer is pretty simple, we want to do this extra step because it will check the item_id in the file.
If this is the same as the user input item parameter, then it will move further. Otherwise, it gives us an error.
That’s the reason we want to take that extra step.
Before deleting the cart item, check your netcat is listening
Now click on delete and capture the request inside the burp
Change the item parameter like this
Send the request
And we got the shell as www-data
Now let’s run pspy
And we can see that inotifywait is monitoring a file called leave_requests.csv inside /var/www/private/
Let’s add something in the file and see the behavior
And we can see its using mail command with root privilege
GTFO bins give us the syntax which we can use to run commands with root privilege
Let’s create a file called priv.sh and add the content which will give the /bin/bash binary suid bit privilege
Add the --exec flag inside the leave_requests.csv file