I probably shouldn't do your homework for you. But the basically:
You need to get a character buffer somewhere in memory to store the string you want to execute. Obviously, you can do this the same way you are getting the other functions called (i.e. you put the text on the stack as well). After you have that written, you need to write a pointer to it on to the stack in the location that the shell_code function expects to find its arguments.
The best way to figure this out without me doing all of the work for you is to write down your stack/memory contents on a piece of paper/whiteboard. Write down how it would look if you called shell_code normally from inside the program. Then write down what the stack looks like inside victum_func and figure out which things to change to get it to look like it would look "naturally" (of course keeping in mind some things are "don't cares" like the return address).
That's all the charity you're gonna get from me today! :-P
Answer from SoapBox on Stack OverflowStack Overflow Exploit in C
security - Exploit a backup program using C - Stack Overflow
buffer overflow - Exploiting vulnerabilities in the C code - Information Security Stack Exchange
using c++ instead of c for making exploits
Videos
I probably shouldn't do your homework for you. But the basically:
You need to get a character buffer somewhere in memory to store the string you want to execute. Obviously, you can do this the same way you are getting the other functions called (i.e. you put the text on the stack as well). After you have that written, you need to write a pointer to it on to the stack in the location that the shell_code function expects to find its arguments.
The best way to figure this out without me doing all of the work for you is to write down your stack/memory contents on a piece of paper/whiteboard. Write down how it would look if you called shell_code normally from inside the program. Then write down what the stack looks like inside victum_func and figure out which things to change to get it to look like it would look "naturally" (of course keeping in mind some things are "don't cares" like the return address).
That's all the charity you're gonna get from me today! :-P
SoapBox already did a great job of leading you in the right direction.
For more information; http://www.skullsecurity.org/wiki/index.php/Example_4
I am not a security expert, but the comment here
char buffer[3072]; /* 3K ought to be enough for anyone*/
is telling :-) So as you have guessed, there is a possibility for buffer overflow here. The buffer is in fact used to read the contents of the input file in. So try it with a file longer than 3K.
Now, since buffer is local, it is allocated on the stack. Thus by overflowing, you can overwrite the contents of the stack, including the return address and local variables within the caller stack frame. This is the theory as far as I know, I can't give you any more practical details though.
The format vulnerability is in
usage()- with thesprintf()andprintf()taking format strings that are generated fromargv[0], which an attacker can manipulate to contain whatever they want.The main buffer overflow is the one highlighted by Péter Török; when scanning code for security vulnerabilities, any unchecked buffer filling with blatant comments like that is a signpost asking for trouble.
The environment variable USER is used - it could be manipulated by the unscrupulous, but it is debatable whether it would really buy you anything. You could set it to say 'root', and the attempted 'chown' command would user the name it was told to use.
There's a race of sorts between the
chowncommand and thechmod()system call. It isn't immediately clear how you'd exploit that separately from the other issues - but it might give you something to leverage.
Including <sys/types.h> twice is redundant but otherwise harmless. With POSIX 2008, it isn't even needed in most places at all.
just want to know if theres is any difference or disadvantages of using c++ for making exploits, i dont have alot of exposure to c so cant say
I wanna be straight with you, i want to start learning "any" programming language but im also very interested in RE and finding exploits in software.
When i start gathering resources it come to my mind most experienced RE and exploit writers recommend learning C, but when you look at any exploit websites, they are just filled with Python, for example metasploit (also Rubby), and tools like mona.py.
Many of guides on internet are sligtly outdated, and i jsut don't want to start off wrong, learning things that are good for reversing old malware or good for developing windows 98 notepad exploit.
So sorry for uber noob question, please keep in mind i have very little knowledge in this field so for, but why learning C is so important to RE and exploit dev? Is it because software written in for example GO lang or python can be somehow reversed to C? I can see the difference between fuzzing code, debugging it, reversing, finding an bug and exploiting it, writing a payload in shellcode. But where in all this is place for C, and why it is mentioned in almost every RE/ExDev guide?
Thanks in advance!