Replies: 1 comment
-
-fstack-protector, -fstack-protector-all, -fstack-protector-strong, -fno-stack-protectorCheck toolhttps://github.com/slimm609/checksec.sh DefaultThe default is Syntax
ParametersNone OperationThe prologue of a function stores a guard variable onto the stack frame. Before returning from the function, the function epilogue checks the guard variable to make sure that it has not been overwritten. A guard variable that is overwritten indicates a buffer overflow, and the checking code alerts the run-time environment.
When a vulnerable function is called with stack protection enabled, the initial value of its guard variable is taken from a global variable: void *__stack_chk_guard; You must provide this variable with a suitable value. For example, a suitable implementation might set this variable to a random value when the program is loaded, and before the first protected function is entered. The value must remain unchanged during the life of the program. When the checking code detects that the guard variable on the stack has been modified, it notifies the run-time environment by calling the function: void __stack_chk_fail(void); You must provide a suitable implementation for this function. Normally, such a function terminates the program, possibly after reporting a fault. Optimizations can affect the stack protection. The following are simple examples:
Example: Stack protectionCreate the following // main.c
#include <stdio.h>
#include <stdlib.h>
void *__stack_chk_guard = (void *)0xdeadbeef;
void __stack_chk_fail(void)
{
fprintf(stderr, "Stack smashing detected.\n");
exit(1);
}
void get_input(char *data);
int main(void)
{
char buffer[6];
get_input(buffer);
return buffer[0];
} // get.c
#include <string.h>
void get_input(char *data)
{
strcpy(data, "012345678");
} When
Running the image displays the following message:
Stack checking
No stack checking
Reference |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions