Skip to content

Instantly share code, notes, and snippets.

@cedriczirtacic
Last active July 3, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedriczirtacic/a58a224408e4e2fbf9593e3680a546e2 to your computer and use it in GitHub Desktop.
Save cedriczirtacic/a58a224408e4e2fbf9593e3680a546e2 to your computer and use it in GitHub Desktop.
// gcc -O1 -fstack-protector-all -o main main.c
#include <stdio.h>
#include <linux/types.h>
#ifndef uint64_t
typedef unsigned long uint64_t;
#endif
uint64_t get_canary() {
uint64_t a;
__asm__(
"leaq 0x8(%%rsp), %0\n\t"
: "=r" (a)
);
printf("canary_address: %p\n", a);
return(a);
}
int main(int argc, char *argv[]) {
uint64_t *v = get_canary();
return printf("canary_value: %p\n", *v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment