For a homework assignment i must perform a buffer overflow attack on a program of theirs. The code of that program is the following:
#include <stdio.h>
#include <string.h>
void vulnerable_function(char *input)
{
char buffer[256];
strcopy(buffer, input);
printf("buffer:%s\n", buffer);
}
int main(int argc, char **argv)
{
vulnerable_function(argv[1]);
}
So, when i execute this command on the terminal: perl -e 'print "A"x32' | ./opdr1_vuln i always get a segmentation fault, no matter how large we generate our input.
The program terminated with:
#0 0xb7f17f50 in strcopy () from /lib/tls/i686/cmov/libc.so.6
However, when i manually fill in many a's in the terminal as this:
./opdr1_vuln aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
it crashes at 260's a's, which is expected and when i debug this with gdb it gives another segmentation fault. It looks like if I'm generating input from another source than the terminal itself, it gives a segmentation fault with strcopy().
I compiled the program with:
# gcc opdr1_vuln.c -o opdr1_vuln
It's a Linux debian 2.6.18-4-686 i686 system.
I don't know why this happens, can someone help me?
vulnerable_function(argv[1]);you're not checking the argument count, and you're not passing any arguments... to be able to properly attack, you have to provide an argument, not a standard input.strcopyfunction .argv[]NULL-terminated? Asargv[0]is the own program name,argv[1]should beNULL: