Sitemap

battery — TryHackMe — Writeup

6 min readJan 21, 2021

Hello. I’m Rahmos. Here is my battery — TryHackMe — Writeup. Check it out!

1/ Enumeration

First, deploy the machine and nmap for opened ports.

nmap -A -T4 -p- -v <ip>

Press enter or click to view image in full size
nmap
Press enter or click to view image in full size
nmap

There’re 2 ports opened: 22(SSH), and 80(HTTP). As port 80 is opened, let’s access the website.

Press enter or click to view image in full size
website

Page source(Ctrl+U):

page source

Well the page source does not help me much. Let’s find some hidden dirs using dirbuster:

After running dirbuster, I’ve found these hidden dirs:

Press enter or click to view image in full size
dirbuster
Press enter or click to view image in full size
dirbuster

After enumerate these folders(and files), I can only access /admin.php, /report.php and /scripts. All other folders need to be admin to access.

/forms.php
/acc.php

Ok so first let’s access /admin.php:

/admin.php

Well, looks like I can login here. But I haven’t got the credential yet! let’s register an account:

Press enter or click to view image in full size
register
register

Ok so now login using the account I’ve just registered:

Press enter or click to view image in full size
login

After login, I’ve been redirected to dashboard.php. In dashboard, I can access many hidden dirs above (/with.php(Withdraw Money), /depo.php(Deposit Money), /tra.php(Transfer Money)).

However, the most interesting folder is ‘Command’, which is /forms.php, can only be accessed by admin.

That’s everything I’ve got so far. Let’s access /report to see what’s in there:

report

It’s a binary file. Download it and use ghidra to decompile:

Press enter or click to view image in full size
main function
Press enter or click to view image in full size
main function
options function
update function
Press enter or click to view image in full size
users function

So here’s the explanation of the code:

First, I need to login. If I login as guest:guest, I will have 2 options to choose:

1/ List available username

2/ Change password. In order to change password, I need to enter email as:
admin@bank.a”. So I think that this is the username for the admin account.
I cannot “Add users” and “Delete users”, as they’re not available for guest account.

Now let’s register an account as “admin@bank.a”:

Well I cannot. So the php code has checked the username string, if it’s ‘admin@bank.a’, then it will reject and show this notification.

I need to bypass this by adding null byte to the string. It’s commonly seen vulnerability in PHP website. It’s called null byte injection. You can learn more about this vuln here.

Press enter or click to view image in full size
null byte injection

Here, I add “%00”, which is a null byte in url to the end of uname string. It will bypass the uname check, but still keep my username as ‘admin@bank.a’ And the response:

Now let’s login as admin@bank.a

Login

Navigate to ‘command’:

command (/forms.php)

Click ‘Send Message’ and use Burpsuite to catch the request:

Press enter or click to view image in full size

You may notice that, this website use XML Entity to represent data.

Press enter or click to view image in full size
XML Entities

So, it may be vulnerable to XXE (XML external entity) injection. You may learn more about it here.

I will modify the request like this to add read /etc/passwd file:

Press enter or click to view image in full size
request

And here’s the response:

Press enter or click to view image in full size
response

So I’ve got the /etc/passwd file! Looking at this, I know that there’re 3 users I can login: root, cyber, and yash

Keep using this vuln, I can read the source code of acc.php

Request:

Press enter or click to view image in full size
request

Response:

Press enter or click to view image in full size
response

Decode the string as base64, I’ve got cyber’s ssh credential:

Press enter or click to view image in full size
cyber’s credential

Now SSH as cyber!

2/ Base flag

Press enter or click to view image in full size
ssh

Get the Base flag:

flag1.txt

3/ User flag

Now I need to escalate to yash in order to see files inside his home:

Transfer LinEnum.sh to the machine using wget:

Press enter or click to view image in full size

Then move it to /tmp, chmod 777 and run:

Press enter or click to view image in full size
sudo permission

Well, cyber can run this python script as root without password needed! Let’s run this script as sudo:

Press enter or click to view image in full size
run script

Well it does not help much. And I can’t view or edit this file, due to permission.

file’s permission

So let’s find another way. This time, find Kernel’s version:

Press enter or click to view image in full size
Kernel’s version

This’s a very old kernel version. Search for exploit and I found this exploit on exploit-db. So, download the exploit code, compile and transfer to the target machine. Then ‘chmod +x’ and run the file:

Press enter or click to view image in full size
get root

Now I’m root! Get the 2 remained flags.

Press enter or click to view image in full size
user flag
Press enter or click to view image in full size
root flag

The end.

HAPPY HACKING

--

--

Responses (1)