diff --git a/Week8_Canaries/Forks/forking.c b/Week8_Canaries/Forks/forking.c new file mode 100644 index 0000000..e8e4a72 --- /dev/null +++ b/Week8_Canaries/Forks/forking.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +int processData(void){ + printf("Please Enter Data >"); + char data[128]; + gets(data); + printf(data); + return 1; +} + +int main(int argc, char *argv){ + printf("Smash the Forking Stack\n"); + + while(1){ + int pid = fork(); + if(pid == 0){ + //Child Deals with data + processData(); + printf("Child Returns\n"); + return 0; + } + else{ + //Parent gets on with Life + printf("Parent Waits on Child\n"); + wait(NULL); + + } + } +} + diff --git a/Week8_Canaries/Forks/makefile b/Week8_Canaries/Forks/makefile new file mode 100644 index 0000000..1334c53 --- /dev/null +++ b/Week8_Canaries/Forks/makefile @@ -0,0 +1,7 @@ +CC = gcc +FLAGS = -no-pie -g + +forking: forking.c + $(CC) $(FLAGS) forking.c -o forking + +all: forking diff --git a/Week8_Canaries/Fstrings/forking b/Week8_Canaries/Fstrings/forking new file mode 100755 index 0000000..d19bcc8 Binary files /dev/null and b/Week8_Canaries/Fstrings/forking differ diff --git a/Week8_Canaries/Fstrings/forking.c b/Week8_Canaries/Fstrings/forking.c new file mode 100644 index 0000000..5a6a17d --- /dev/null +++ b/Week8_Canaries/Fstrings/forking.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +int processData(void){ + printf("Please Enter Data >"); + char data[32]; + gets(data); + printf(data); + return 1; +} + +int main(int argc, char *argv){ + printf("Smash the Forking Stack\n"); + + while(1){ + int pid = fork(); + if(pid == 0){ + //Child Deals with data + processData(); + printf("Child Returns\n"); + return 0; + } + else{ + //Parent gets on with Life + printf("Parent Waits on Child\n"); + wait(NULL); + + } + } +} + diff --git a/Week8_Canaries/Fstrings/makefile b/Week8_Canaries/Fstrings/makefile new file mode 100644 index 0000000..1334c53 --- /dev/null +++ b/Week8_Canaries/Fstrings/makefile @@ -0,0 +1,7 @@ +CC = gcc +FLAGS = -no-pie -g + +forking: forking.c + $(CC) $(FLAGS) forking.c -o forking + +all: forking diff --git a/Week8_Canaries/Static/makefile b/Week8_Canaries/Static/makefile new file mode 100644 index 0000000..bfd7335 --- /dev/null +++ b/Week8_Canaries/Static/makefile @@ -0,0 +1,7 @@ +CC = gcc +FLAGS = -fno-stack-protector -no-pie -g --static + +static: static.c + $(CC) $(FLAGS) static.c -o static + +all: static diff --git a/Week8_Canaries/Static/static.c b/Week8_Canaries/Static/static.c new file mode 100644 index 0000000..e83009c --- /dev/null +++ b/Week8_Canaries/Static/static.c @@ -0,0 +1,38 @@ +#include +#include +#include + + +// We Use a Sruct as it means we can be sure that the memory layout stays the same + +struct staticMemory { + char buffer[20]; + int canary; +}; + + +int win(){ + system("/bin/sh"); +} + +int main(int argc, char *argv){ + + //Initilise our memory + struct staticMemory myMemory; + + //And the Canary + myMemory.canary = 0xDEADBEEF; + + printf("Enter your String\n"); + gets(myMemory.buffer); + + + //And Do our check + if (myMemory.canary != 0xDEADBEEF){ + printf("Stack Smashing Detected!!!\n"); + exit(-1); + } + + return 1; + +}