• We just launched and are currently in beta. Join us as we build and grow the community.

Hack the Box Challenge: Sneaky Walkthrough

johncenamodz

User Retention Expert
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
101
Likes
137
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Hello friends!! Today we are going to solve another CTF challenge “Sneaky” which is available online for those who want to increase their skill in penetration testing and black box testing. Sneaky is retired vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level; they have the collection of vulnerable labs as challenges from beginners to Expert level.

Level: Intermediate

Task: find user.txt and root.txt file on victim’s machine.

Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.20 so let’s begin with nmap port enumeration.

Code:
nmap -sT -sU 10.10.10.20

From given below image, you can observe we found port 80 and 161 are open on target system.

1.png


As port 80 is running http we open it in our browser, the website shows that it’s under construction.

3.png


We initiate dirb to enumerate the directories hosted on the target machine.

Code:
dirb http://10.10.10.20/

2.png


We find a directory called /dev/ we open it in our browser and find a login screen.

4.png


We find the login page is vulnerable to sql injection; we use this vulnerability to bypass the login page using query ‘or 1=1—in username and password.

5.png


After logging in we find a link on the webpage.

6.png


We open the link and find a RSA private key. We download the key into our system.

7.png


Now the target machine is not running any ssh service so that we can use this to login through ssh.

To investigate further we enumerate SNMP protocol to gain more information.

Code:
msf > use auxiliary/scanner/snmp/snmp_enum
msf auxiliary(scanner/snmp/snmp_enum) > set rhosts 10.10.10.20
msf auxiliary(scanner/snmp/snmp_enum) > set threads 5
msf auxiliary(scanner/snmp/snmp_enum) > exploit

10.1.png


After enumerating the target machine we find that maybe ssh is running in ipv6.

10.2.png


We use a python script called Enyx to find the ipv6 address of the target machine. You can get the script from this link.

Code:
python enyx.py 2c public 10.10.10.20

10.png


After finding the ipv6 address of the target machine we login through ssh using the username and RSA Private key that we find after we login on the /dev/ page.

Code:
ssh -i key thrasivoulos@dead:beef:0000:0000:0250:56ff:fe8f:d853

12.png


After logging in through ssh we find a file called user.txt we open it and find our first flag. Now we try to find files with suid bit set.

Code:
find / -perm -4000 2>/dev/null

13.png


We find a binary file called chal in /usr/local/bin we open it in gdb and find there is a strcpy function.

(gdb) set disassembly-flavor intel

(gdb) disas main

Code:
pattern_create.rb -l 500

14.png


Now we try to check if we can overflow the memory through this strcpy function. First we create a 500 byte string using the patter create script in metasploit.

15.png


We run the file in gdb and find that the return address was overwritten with the characters in the string.

16.png


We check the size that is required to completely overwrite the return address by checking the location of the string that became the return address inside the pattern that we created. We use pattern offset tool to check the corresponding location.

Code:
pattern_offset.rb -q 316d4130 -l 500

17.png


We find that after 362 bytes the return address gets overwritten. Now we take a look at the stack to find a location for nop sled and shell code.

18.png


We picked the stack address 0xbffff510; you can change the stack pointer address and pick the shellcode according to your need. We use python script to create our exploit and pass the output as argument for the file. When we run the command below, we get a tty shell as root user. We move to /root/ directory and find a file called root.txt; we open the file and find our final flag.

19.png


uthor: Sayantan Bera is a technical writer at hacking articles and cyber security enthusiast. Contact Here
 

432,073

312,529

312,538

Top