I'm experimenting with Buffer overflow basics, I'm trying to call the shell function without modifying the code. So far I've managed to call it but I can't find a way to give it the right parameter (which is exec_string)
Here is the code :
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
* compiled with:
* gcc -O0 -fno-stack-protector lab2B.c -o lab2B -m32
*/
char* exec_string = "/bin/sh";
void shell(char* cmd)
{
system(cmd);
}
void print_name(char* input)
{
char buf[15];
strcpy(buf, input);
printf("Hello %s\n", buf);
}
int main(int argc, char** argv)
{
if(argc != 2)
{
printf("usage:\n%s string\n", argv[0]);
return EXIT_FAILURE;
}
print_name(argv[1]);
return EXIT_SUCCESS;
}
I run it with./lab2B $(python -c 'print "A"*27 + "\x8D\x55\x55\x56"')
which seems to enable me to get into shell, according to gdb.
Thanks in advance for your help
\x8D\x55\x55\x56
string reference? Is this an address that points to aJMP ESP
command?exec_string
is in the stack, and call that after the return address. You will likely want some nops in-between, though.