---
# System prepended metadata

title: hello guys am alienkeric today
tags: ['https://tryhackme.com/room/gallery666']

---

# SIMPLE PENETRATION TESTING ON A TRYHACKME ROOM

 hello guys am alienkeric today we are going to have a walkthrough (pentesting) on a simple easy machine from tryhackme and here is a link.
 ![](https://hackmd.io/_uploads/B1CVKF3h2.png)

url:https://tryhackme.com/room/gallery666


**Description**: Gallery666 is a simple boot to root machine which is vulnerable to sql injection,rce,file upload vulnerability. 
time for work

![](https://hackmd.io/_uploads/S1bOTd2n2.png)


**STEP 1: ENUMERATION**
As we all know that enumeration is key of pentesting and hacking , so here am going to scan using nmap at the same time am going to browser to the IP to just see if i can find anything while my nmap is running

![](https://hackmd.io/_uploads/r15Dysj3h.png)

As we can see there were have just found to open ports 80,8080

If you browser to port 80 you will observer that is giving us a default apache2 page

![](https://hackmd.io/_uploads/Syaglsi32.png)

If u view the source code there is nothing useful there so lets move and next phase of enumeration which is directory searching 

And from here we can see the gallery directory lets take a look at it

![](https://hackmd.io/_uploads/rk5IWij3n.png)

And it redirect us to a login page , mhmmmm cool lets play with and see if we can bypass the login page

![](https://hackmd.io/_uploads/H1TzWoi23.png)

**STEP 2: FOOTHOLDING**

vuln1: sql injection

At case one i tried to check if i can bypass it with default creds such as admin:admin,admin:password but nothing i got from this creds so i tried with sql injection to see if i can bypass it.

![](https://hackmd.io/_uploads/H18tzosh3.png)

The payload i have highlight was the one which let me into the system(as admin), that was easy for sure(**admin' or 1=1#**) on both admin username and password



**STEP 3: GETTING A SHELL**
Time to snoop around and see what we can get from this admin 

![](https://hackmd.io/_uploads/HkG3mjs3n.png)

I came across this "id=2" parameter i tried to see if can get some LFI but i got nothing. But there is an upload section at the right hand side lets see if is filtered or not, if not there is a huge chance of getting a reverse shell.

Lets upload a reverse shell and see if we can get a shell from here.

![](https://hackmd.io/_uploads/HyWVSojh3.png)

finally i got a shell

![](https://hackmd.io/_uploads/ByM8Boinn.png)


The reason why we got a shell from the upload section is that, the site allows image uploading but there is not restriction that only image can be uploaded that why i was able to exploit it from that small issue.

**STEP 4:LATERAL MOVEMENT** 

**case 1:** upgrade a shell into a more interactive shell as pro hacker 

![](https://hackmd.io/_uploads/SJonLoj2n.png)

**case 2:** check for users we can interect with

![](https://hackmd.io/_uploads/B1MZDoin2.png)

as you can see from there, we have ,root,ubuntu,mike

**case 3:** Try to interact with each user if possible

![](https://hackmd.io/_uploads/r1AOviih3.png)

It seems we can't interact with user mike,ubuntu so lets try to find a way to login as mike if possible

![](https://hackmd.io/_uploads/Bk85qojnn.png)

Before i uploaded **linpeas** into this machine when i got a shell i saw something  in the /var/www/html but i didn't take into consideration so  its time to take a look at every file i saw 

into this initiatize.php there are some creds of msql mhmmmm

![](https://hackmd.io/_uploads/H1rUjson3.png)

and there are the mysql creds, so lets use them to login as mysql and finally u can get some creds to login into there system but for now, no use for them

![](https://hackmd.io/_uploads/rkt8nijhn.png)

and there is admin password hash

![](https://hackmd.io/_uploads/SJ0F2so2h.png)

Back again on mike there is a backups file lets see what we can get from it

![](https://hackmd.io/_uploads/By8SCishn.png)

the creds i get from this accounts they were not usefull at this time, as am looking a way to login as mike, i tried again to check the bash_history of in backups and find something very usefully for sure.


![](https://hackmd.io/_uploads/Byaqbhs3n.png)


and finally there we have login as mike 


**STEP 5:PRIVELEGE ESCALATION**

If we run sudo -l and we can see that there is a script that can be runned as root without no passwd, lets see what is content inside this script.

![](https://hackmd.io/_uploads/BkCYm2o3h.png)

Checking the executables called by this script against gtfobins, we’ll see that nano can be used to spawn a shell, and since the rootkit script will be running as root, we’ll have ourselves a root shell!

**how to get a shell**

1.sudo -u root /bin/bash /opt/rootkit.sh
2.Enter **read** when prompted to start nano.
3.Hit** Ctrl+R** followed by **Ctrl+X** — this will allow us to enter a single command to execute and will insert the output into the current file.
4.We don’t want that, so running reset; sh 1>&0 2>&0 will open a shell for us.
5.From there we can capture the root flag!

![](https://hackmd.io/_uploads/B1z-4K2n3.png)

Thank u, dont forget to leave a comment 