From cd393ae59af4302c63b2660e43d0018d29b1f2ab Mon Sep 17 00:00:00 2001 From: Dan Goldsmith Date: Wed, 18 Nov 2020 16:11:46 +0000 Subject: [PATCH] First set of Overflows added --- firstOverflow.c | 43 +++++++++++++++++++++++++++++++++++++++++++ hello.c | 13 +++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 firstOverflow.c create mode 100644 hello.c diff --git a/firstOverflow.c b/firstOverflow.c new file mode 100644 index 0000000..fc462f7 --- /dev/null +++ b/firstOverflow.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +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; +} diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..0895eb8 --- /dev/null +++ b/hello.c @@ -0,0 +1,13 @@ +#include + +int add(int var1, int var2){ + //Add two numbers + int total; + total = var1+var2; +} + +void main(int argv, char* argc){ + //Function call + int total = add(10, 20); + printf("Total is %d \n", total); +}