Last active
May 1, 2018 01:13
Star
You must be signed in to star a gist
Buffer overflow example in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Demo 1 | |
// clang -fno-stack-protector -fno-sanitize=safe-stack -D_FORTIFY_SOURCE=0 -m32 -Wl,-no_pie -O0 -g demo2.c -o demo2.o | |
#include <stdio.h> | |
#include <string.h> | |
char password[] = "password"; | |
int get_password() { | |
int auth_ok = 0; | |
char buff[16]; | |
printf("Enter password: "); | |
scanf("%s", buff); | |
if(strncmp(buff, password, sizeof(password)) == 0) | |
auth_ok = 1; | |
return auth_ok; | |
} | |
void success() { | |
printf("Success!\n"); | |
} | |
int main(int argc, char** argv) { | |
int res = get_password(); | |
if (res == 0) { | |
printf("Failure\n"); | |
return 0; | |
} | |
success(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment