Which versions of GCC, or flags, should I use when

2020-07-10 09:01发布

问题:

Recently, I've been studying buffer overflows as an undergraduate student in Computer Engineering. Simply out of interest, I began researching and studying buffer overflows, but have gotten stuck when attempting to implement them in my own C programs on my computer, compiled with GCC 4.9.1 (in Debian Jessie).

I've heard that there are sorts of stack overflow protection in newer compilers, so I'm thinking that my issue is that my compiler version is too new. Either that, or I'm not compiling with the correct flags (none).

So are there good versions of GCC for me to obtain to test buffer overflows? Or should I use a particular flag to prevent stack protection and canaries?

Thank you for your time.

回答1:

Use -zexecstack -fno-stack-protector to disable stack frame protection and non-executable stack with gcc.

On your Linux system, you also have to disable address randomization (ASLR) using:

echo 0 > /proc/sys/kernel/randomize_va_space


回答2:

Use -fno-stack-protector option in gcc to disable stack smashing protection.



回答3:

Most recent versions of GCC (>= 4.8) have included AddressSanitizer, by -fsanitize=address option. From 4.8 Realease Notes:

AddressSanitizer , a fast memory error detector, has been added and can be enabled via -fsanitize=address. Memory access instructions will be instrumented to detect heap-, stack-, and global-buffer overflow as well as use-after-free bugs. To get nicer stacktraces, use -fno-omit-frame-pointer. The AddressSanitizer is available on IA-32/x86-64/x32/PowerPC/PowerPC64 GNU/Linux and on x86-64 Darwin.

GCC 4.9 added its support on ARM platform.