26Kas
Can you perform a buffer overflow and a format string attack at the same time?
So I hope I'm phrasing this right. I'm trying to exploit a piece of c code which you can see below.
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int user_age;
void secretClub(){
if(user_age<18){
printf("Come back when your old enough!!");
}
else{
printf("Come on in.");
}
}
int main(){
char name[30];
user_age = 17;
gets(name);
printf("Hello there ");
printf(name);
}
What I'm trying to do here is call the secretClub function and to print "Come on in". So I know if I wanted to just call the secretClub function, I could just overflow the buffer enough with the memory address of the function at the end. And I know that I can use this programs string format vulnerability to modify the variable's value in memory.
What I'm wondering is how to do both in one line? Sorry if this seems like a stupid and obvious question, upon searching I couldn't find much. Any guidance would be greatly appreciated!