Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 7721  / 2 Years ago, mon, march 14, 2022, 12:08:06

I just installed 12.04 (WUBI actually) and I wanted to learn a bit about buffer overflow. Unfortunately when I try to use a function like puts() and gets() in an incorrect manner (that is, to cause a buffer overflow), gcc tells me that it detected smashing the stack and terminate my program.



How do I enable stack overflow?



For more clarity, This is the program:



#include<stdio.h>

CanNeverExecute()
{
printf("I can never execute
");
exit(0);
}

GetInput()
{
char buffer[8];

gets(buffer);
puts(buffer);
}

main()
{
GetInput();

return 0;
}

More From » gcc

 Answers
1

I don't think what you are doing is a stack overflow. That is what happens when you recurse too deeply into a function, causing you to run out of stack frames.



int main(int argc, char *argv[]) {
return main(argc, argv);
}


What you are trying to achieve is a buffer overflow on the stack. I think you are hoping to write to the return address and then make it call CanNeverExecute.



Then you get stack smashing detected, from gcc's stack protector. You can disable it using gcc -fno-stack-protector. Of course, don't ever do that with programs you intend on running for production.


[#36205] Wednesday, March 16, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tocklftime

Total Points: 110
Total Questions: 109
Total Answers: 100

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
tocklftime questions
Wed, Feb 1, 23, 21:50, 1 Year ago
Tue, Oct 4, 22, 21:42, 2 Years ago
Sun, Jul 25, 21, 10:43, 3 Years ago
;