I am trying to complete a buffer overflow challenge. The code I am trying to exploit is below. I can only use the command line in a Linux environment.
I understand that writing more than 100 characters into "userString" will start to overwrite "command". My guess is that I need to somehow overwrite command with "/bin/sh" to launch into shell. I don't know exactly how to do that.
I've tried exceeding the input buffer to see what happens and I get this error:
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
Segmentation fault
Here is the code:
#include <stdlib.h>
#include <stdio.h>
int main() {
char command[100];
char userString[100];
printf("Input a string to echo: ");
gets(userString);
snprintf(command, sizeof(command), "echo \"%s\"", userString);
setresuid(502,502,502);
system(command);
return 0;
}