Skip to content

Instantly share code, notes, and snippets.

@ryankurte
Last active May 1, 2018 01:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ryankurte/cfbf8a88322bafcc0ce059bd3b187e26 to your computer and use it in GitHub Desktop.
Buffer overflow example in C
// 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