I have an excersise of making a buffer flow exploit for directing a function insinde another function without calling it. First I need to print "now inside entrance()" then print "now inside secret()"

I was able to print "now inside secret()" by overflowing the buffer via assingning above address of doNotTouch which is return address of entrance function. But now I am getting a segmentation fault, which I shouldn't have.

I am doing this exercise on a x86_64 Debian system and gcc verison 4.9. I am prohibited to call any function or editing outside the given area in entrance(). I also shouldn't compile with compile options.

Thanks in advance

 #include <stdio.h>

void secret()
    printf("now inside secret()!\n");

void entrance()
int doNotTouch[4];
// can only modify this section BEGIN
// cant call secret(), maybe use secret (pointer to function)

*(doNotTouch + 6) = &secret;

// can only modify this section END
printf("now inside entrance()!\n");


int main (int argc, char *argv[])
    return 0;
New contributor
karpatylviv is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • If you had it working before, what did you change that made it break? What do you mean about compile options? – multithr3at3d Nov 22 at 15:21
  • So you've modified the stack so that entrance(), instead of returning to main, jumps to secret instead. But now what happens when secret returns? Where will it return to? – brhans Nov 23 at 3:40

Your Answer

karpatylviv is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.