Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ComsecStack/firstOverflow.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (34 sloc)
848 Bytes
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
int BUFFER=100; | |
void win(void){ | |
/*Win Condition | |
We Want to jump here | |
*/ | |
printf("\n ===== Win ===== \n\n"); | |
system("/bin/sh"); //Tradition to get a shell | |
} | |
void lose(void){ | |
/* Lose Condition */ | |
printf("Current Memory Address is %p\n",lose); | |
printf("Aim for %p\n", win); | |
printf("Lose :(\n"); | |
} | |
int main(int argc, char* argv[]){ | |
/* Main Function*/ | |
//Pointer to the lose function | |
void (*fp)(void) = lose; | |
char buffer[BUFFER]; | |
printf("Overflow the Buffer\n"); | |
if (argc != 2){ | |
printf("Overflow the buffer\n"); | |
printf("Hint! Try `python -c \"print 'A'*100\"`\n"); | |
return -1; | |
} | |
memcpy(buffer, argv[1], strlen(argv[1])); | |
printf("Off to %p\n",fp); | |
fp(); | |
return 0; | |
} |