Skip to content

Instantly share code, notes, and snippets.

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 mishrasunny174/7e759d607967f0051b7840608f7f69c6 to your computer and use it in GitHub Desktop.
Save mishrasunny174/7e759d607967f0051b7840608f7f69c6 to your computer and use it in GitHub Desktop.
// gcc lab2.c -o BufferOverflow -fno-stack-protector -z execstack -no-pie
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/personality.h>
#include <sys/mman.h>
__attribute__((constructor)) void init() {
setvbuf(stdout, NULL, _IONBF, 0);
char *argv[] = {"/home/lab2/BufferOverflow", NULL};
const int old_personality = personality(ADDR_NO_RANDOMIZE);
if (!(old_personality & ADDR_NO_RANDOMIZE)) {
const int new_personality = personality(ADDR_NO_RANDOMIZE);
if (new_personality & ADDR_NO_RANDOMIZE) {
execv(argv[0], argv);
}
}
}
int main(int argc, char** argv) {
char buffer[24];
printf("Enter your name: ");
gets(buffer);
printf("Hello %s", buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment