Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__stack_chk_fail in PE files #120

Open
Artoria2e5 opened this issue Mar 15, 2023 · 1 comment
Open

__stack_chk_fail in PE files #120

Artoria2e5 opened this issue Mar 15, 2023 · 1 comment

Comments

@Artoria2e5
Copy link

Artoria2e5 commented Mar 15, 2023

Some of the "ELF" safety mechanisms are actually quite generic and found in other formats. Like PE, if you use GCC to compile an exe:

# This is MSYS2, "MSYS" environment.
printf '%s\n%s' '#include <stdio.h>' 'int main(){char e[64]; gets(e); puts(e);}' > 1.c
gcc -O2 -fstack-protector-all 1.c
nm a.exe | grep stack

You get:

0000000100403010 r .rdata$.refptr.__stack_chk_guard
0000000100403010 R .refptr.__stack_chk_guard
0000000100403010 R __fu0___stack_chk_guard
00000001004080e4 I __imp___stack_chk_fail
00000001004080ec I __imp___stack_chk_guard
00000001004080ec I __imp___stack_chk_guard
000000010040819c I __nm___stack_chk_guard
0000000000001000 A __size_of_stack_commit__
0000000000200000 A __size_of_stack_reserve__
00000001004010a0 T __stack_chk_fail

(Well, it's exactly one of the ELF mechanisms for now. But there are some not-yet-implemented things like SafeStack and selfrando that will also use simple symbol or section existence. Maybe clang CFI too...)

@Artoria2e5 Artoria2e5 changed the title __stack_chk_fail on PE files __stack_chk_fail in PE files Mar 15, 2023
@Artoria2e5
Copy link
Author

Artoria2e5 commented Mar 16, 2023

FORTIFY_SOURCE is surprisingly widespread. macOS libc have their independently implemented functions. So does the mingw-w64 libc. On other systems, the gcc "libssp", which is independent of the libc, can also provide that. Scanning the libc is going to provide an incomplete picture...

Why didn't I find it on MSYS2 binaries? Because gasp they turned it off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant