Last active
October 13, 2021 11:09
-
-
Save mishrasunny174/7e759d607967f0051b7840608f7f69c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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