Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
Created December 31, 2017 15:19
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 artem-smotrakov/9638c9a39e6968f19481d8ccf67aef5a to your computer and use it in GitHub Desktop.
Save artem-smotrakov/9638c9a39e6968f19481d8ccf67aef5a to your computer and use it in GitHub Desktop.
An example of global buffer overflow, see more on https://blog.gypsyengineer.com/fun/security/global-buffer-overflows.html
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char buffer[16];
int main(int argc, char **argv) {
if(argc < 2) {
printf("no parameters specified\n");
exit(-1);
}
char* allocated = malloc(32);
strcpy(allocated, "test");
printf("buffer address = %p\n", buffer);
printf("allocated address = %p\n", allocated);
printf("allocated address - buffer address = %lu\n", allocated - buffer);
printf("allocated (before) = %s\n", allocated);
// global buffer overflow may occur here
// if argv[1] has more than 16 symbols
strcpy(buffer, argv[1]);
printf("allocated (after) = %s\n", allocated);
free(allocated);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment