Possible Duplicate:
Stack Overflow Exploit in C
I need to write a program to exploit the stack overflow vulnerability of the following program. I have never done anything of this sort. I understand how it works in theory both the stack and the overflow. But I'm clueless about the implementation in C. Please help me with this. I just need a clear understanding of the steps to be taken in order to overflow the stack and generate the shell code.
#include <stdio.h>
int myprint(char* argv1)
{
printf("%s", argv1);
}
void foo(char* argv1, char* argv2)
{
int (*fptr)(char*) = myprint;
char buf[12];
strcpy(buf, argv1);
fptr(argv2);
}
int main(int argc, char **argv)
{
if (argc < 3)
{
printf("error\n");
return;
}
foo(argv[1], argv[2]);
}
Thanks