# Sorcerer

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FNzZbRo315F3dUJF52AeG%2Fimage.png?alt=media&#x26;token=253ccd67-1722-4950-899d-af3ca27eb456" alt=""><figcaption></figcaption></figure>

## Sorcerer

### Nmap

```
sudo nmap 192.168.150.100 -p- -sS -sV                                                                                                                                                                                              1 ⨯

PORT      STATE SERVICE  VERSION
22/tcp    open  ssh      OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
80/tcp    open  http     nginx
111/tcp   open  rpcbind  2-4 (RPC #100000)
2049/tcp  open  nfs_acl  3 (RPC #100227)
7742/tcp  open  http     nginx
8080/tcp  open  http     Apache Tomcat 7.0.4
43329/tcp open  nlockmgr 1-4 (RPC #100021)
45519/tcp open  mountd   1-3 (RPC #100005)
54375/tcp open  mountd   1-3 (RPC #100005)
55683/tcp open  mountd   1-3 (RPC #100005)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

### HTTP

We have HTTP running on ports 80,8080 and 7742. I set to work running `feroxbuster` against all three ports before manually browsing them.

```
./feroxbuster -u http://192.168.150.100:<port> -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
```

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FJAjSI0XM0iN3TiPuMIrP%2Fimage.png?alt=media&#x26;token=b12f386d-c647-4f9b-a9a9-2a15f0dcc5c9" alt=""><figcaption></figcaption></figure>

Port 80 shows a page with only '404 not found' displayed. Port 8080 takes us to Apache Tomcat/7.04.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FUZTwZGcTjTvb8FHZhnVi%2Fimage.png?alt=media&#x26;token=3c555015-a22a-4eaf-a5ec-b13e81559670" alt=""><figcaption></figcaption></figure>

The link for the Manager App did not ask for authentication credentials like it normally does. It does provide us with an Access Denied page and also displays the Tomcat default credentials of `tomcat:s3cret`.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FG9c3Hkrm6sxEBPe4Tibv%2Fimage.png?alt=media&#x26;token=818512ab-8dd7-4555-b234-21cba78662e9" alt=""><figcaption></figcaption></figure>

We can store these later and possibly run these credentials against `nikto` or `gobuster` to see if we can enumerate further directories if required.

Port 7742 takes us to the following login page which contains no identifying information apart from the name 'SORCERER' in the browser tab.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FVxY6b4Gf4BdnsyRNq81P%2Fimage.png?alt=media&#x26;token=deb029cb-d998-412b-bd56-95074cff444d" alt=""><figcaption></figcaption></figure>

Soon after `feroxbuster` picks up the /zipfiles/ directory. On browsing to this, we find the following files.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FBP4DI9fwuPCajGGIOazd%2Fimage.png?alt=media&#x26;token=a6554e91-4b7f-4729-8198-b54325c22927" alt=""><figcaption></figcaption></figure>

I downloaded the zip files which are not encrypted and browsed through each with the GUI. The max.zip folder contained the most interesting information.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FVZPEWB9RqP17bBd6DVx6%2Fimage.png?alt=media&#x26;token=028a9fa7-2d67-4934-b7fc-c734b43ac63e" alt=""><figcaption></figcaption></figure>

The Tomcat files contain credentials for Tomcat.

```
  <role rolename="manager-gui"/>
  <user username="tomcat" password="VTUD2XxJjf5LPmu6" roles="manager-gui"/>
</tomcat-users>
```

We also have `SSH` keys for Max.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FE77CcJlGIzqxmBZZA46d%2Fimage.png?alt=media&#x26;token=f99f5339-678d-409f-b215-99b9d031e2c9" alt=""><figcaption></figcaption></figure>

I changed the permissions of the id\_rsa file to 600 so we can use it for SSH.

```
chmod 600 id_rsa 
```

Looking at the authorized keys files we can see that the file scp\_wrapper.sh is being used as a force command when a user connecting to `SSH`.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2Fy0nzmtOpqTFiaw98uc7l%2Fimage.png?alt=media&#x26;token=224b07c2-ed2f-4611-b518-6affae115a06" alt=""><figcaption></figcaption></figure>

The contents of scp\_wrapper.sh

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FGjJDTUqohHpXI5HFm2BV%2Fimage.png?alt=media&#x26;token=30bea595-c7e7-46eb-b1fc-6a87fb4b8107" alt=""><figcaption></figcaption></figure>

This means when connecting as the user max to SSH we can only execute commands that start with 'scp'. As `SCP` runs over `SSH` we can use id\_rsa file from Max to connect and overwrite the wrapper file with something more useful such as 'bash' instead of 'scp'.

I edited the scp\_wrapper.sh file to include the command 'bash' and changed the error message for troubleshooting purposes.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FEk0MLyFN3BjjNLoGwAtM%2Fimage.png?alt=media&#x26;token=549e395d-1f5f-403f-b62a-47f0057bf106" alt=""><figcaption></figcaption></figure>

I then moved Max's 'id\_rsa' key into my SSH folder on /home/kali/.ssh/ in preparation for connecting to SCP.

Once completed connect by SCP and transfer over the wrapper file on our desktop.

```
scp /home/kali/Desktop/scp_wrapper.sh max@192.168.196.100:/home/max/scp_wrapper.sh
```

We can then SSH in as max and will have a bash shell.

```
ssh max@192.168.196.100  
```

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FjrFxRzg4fpxG1O7tpRQn%2Fimage.png?alt=media&#x26;token=548362be-f7c5-4d67-bc78-a0d4d8ef6dc9" alt=""><figcaption></figcaption></figure>

Upgrade the shell:

```
/usr/bin/script -qc /bin/bash /dev/null
```

Straight away I uploaded `linpeas.sh` it after starting  `Python SimpleHTTPServer` on my attacking machine and executed once downloaded.

`Linpeas` soon picks up the SUID bit being set on /usr/sbin/start-stop-daemon.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FOwMwS51IjMhaexm76TpN%2Fimage.png?alt=media&#x26;token=cc3a2e9b-6f32-4e74-8e35-71bcfec4e5c7" alt=""><figcaption></figcaption></figure>

A search on[ GTFObins](https://gtfobins.github.io/gtfobins/start-stop-daemon/) shows we can spawn a root shell.

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2FQ2kSrIjWzNvODr3TVkIm%2Fimage.png?alt=media&#x26;token=79922e73-d72c-48fd-a2ed-81aa6cdf8d51" alt=""><figcaption></figcaption></figure>

Exploit syntax:

```
/usr/sbin/start-stop-daemon -n $RANDOM -S -x /bin/sh -- -p
```

<figure><img src="https://3374622158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE6qr56iNnQWIFa0iLTZX%2Fuploads%2F2htFczsLGtdwSAP5CcWc%2Fimage.png?alt=media&#x26;token=9537acae-c1af-41c8-bdf3-ed3f243fb475" alt=""><figcaption></figcaption></figure>
