Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Build the first overflow target | ||
|
||
CC = gcc | ||
CFLAGS = -m32 -g -z execstack | ||
|
||
|
||
ret2winOne: ret2winOne.c | ||
|
||
$(CC) $(CFLAGS) ret2winOne.c -o ret2winOne | ||
|
||
|
||
all: ret2winOne | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int BUFFER=150; | ||
|
||
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; | ||
} |