(40 points) This problem asks you to extend the buffer overflow attack from the last homework assignment. In the Resources area of SmartSite (or the Homework area of the nob.cs.ucdavis.edu class web site) is a program realbad.c (also see below). This program contains a buffer overflow vulnerability; see the call to gets(3) at line 13. Your job is to exploit the overflow by providing input to the running process that will cause the program to invoke the function runcom and cause the system(3) function to be executed with a command embedded in the input you have given. You must pass in a parameter that is a Linux command, which the program will then execute. (I recommend the command id(1).)
Please turn in the following:
- A hex dump of the input you use. Please also show where the parameter to trap() is in your input.
- A screenshot of the program’s output for that input.
realbad.c
This is a listing of realbad.c.
\lstset{numbers=left,numberstyle=\tiny,language=c,xleftmargin=3ex}
#include <stdio.h>
#include <stdlib.h>
void runcom(char *cmd)
{
system(cmd);
exit(0);
}
int getstr(void)
{
char buf[12];
gets(buf);
return(1);
}
int main(void)
{
getstr();
runcom("echo Overflow failed");
return(1);
}