linker - gcc -fno-stack-protector for linking not work -


my gcc version : gcc version 4.8.2 (ubuntu 4.8.2-19ubuntu1)

the following makefile

all : main.o utility.o                                                                                                                                                                                            gcc -fno-stack-protector -wl,-z,execstack -o binary main.o utility.o -lcrypto main : main.c     gcc -z execstack -fno-stack-protector main.c -c utility: utility.c     gcc  -z execstack -fno-stack-protector utility.c -c 

the file utility.o , main.o not have stack guard after linking there stack guard

objdump -d binary | grep chk 080488d0 <__stack_chk_fail@plt>:  8048e30:   e8 9b fa ff ff          call   80488d0 <__stack_chk_fail@plt>  80494dd:   e8 ee f3 ff ff          call   80488d0 <__stack_chk_fail@plt>  80498e2:   e8 e9 ef ff ff          call   80488d0 <__stack_chk_fail@plt>  8049b92:   e8 39 ed ff ff          call   80488d0 <__stack_chk_fail@plt>  8049c9e:   e8 2d ec ff ff          call   80488d0 <__stack_chk_fail@plt>  8049da2:   e8 29 eb ff ff          call   80488d0 <__stack_chk_fail@plt>  804a137:   e8 94 e7 ff ff          call   80488d0 <__stack_chk_fail@plt> 

how disable it?

the following makefile
gcc -z execstack -fno-stack-protector main.c -c

that command bogus; if should have -wl,-z,execstack. however, since that's linker option, , not linking here, best remove -z exestack completely.

but after linking there stack guard

the calls __stack_chk_fail must coming code linked binary. perhaps libcrypto.a, or libgcc.a. can see coming from, in 2 ways:

gcc -fno-stack-protector -wl,-z,execstack -o binary main.o utility.o \  -lcrypto -wl,-y,__stack_chk_fail 

will produce messages this:

/some/libfoo.a(bar.o): reference __stack_chk_fail  # care one! /usr/lib/libc.so.6: definition of __stack_chk_fail 

or can use binary built:

objdump -d binary | egrep '>:$|__stack_chk_fail' | grep -b1 __stack_chk_fail 

that should tell functions inside binary reference __stack_chk_fail, , should able guess these functions coming from.

p.s. unless studying buffer overflow exploitation techniques, disabling stack protector , linking -z,execstack really bad idea.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -