1 year ago
#128755
Sn.S
How to use a buffer overflow to call another program?
I want to create a program exploit that calls testme.c
to perform a buffer overflow operation which should call another program myname.c
.
The code for the testme.c
program:
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv){
char a[100], b[100], c[100], d[100];
// Call the exploitable function
exploitable(argv[1]);
return(0);
}
int exploitable(char *arg){
// Make stack space of 10 bytes
char buffer[10];
// Copy input to buffer
strcpy(buffer, arg);
printf("The buffer says .. [%s/%p].\n", buffer, &buffer);
return(0);
}
The code for the myname.c
program:
#include <stdio.h>
#include <time.h>
int main(){
printf("Name: SNS\n");
printf("Location: 41.13957, -104.81815\n");
time_t t;
time(&t);
printf("Date and time: %s\n",ctime(&t));
}
I have disabled address randomization and compiled both programs with -fno-stack-protector. Using gdb I can see that in testme.c
, the return address after calling the exploitable function is 0x00000000000011a0
:
testmemain
I need this to change to 0x00000000000011a9
, which is the address of the main function of the myname.c
program:
mynamemain
I know how to overflow the buffer variable in the exploitable function by giving a long enough string input to get a segmentation fault, but I cannot proceed any further than this. I have checked other tutorials in which the next step is to show how to spawn a shell, but I want testme.c
to call myname.c
through a buffer overflow. I am doing this on a 64-bit Ubuntu virtual machine.
c
security
assembly
buffer-overflow
stack-smash
c
security
assembly
buffer-overflow
stack-smash
0 Answers
Your Answer