Skip to content

Forking Version added #14

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Week8_Canaries/Forks/forking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <string.h>

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);

}
}
}

7 changes: 7 additions & 0 deletions Week8_Canaries/Forks/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CC = gcc
FLAGS = -no-pie -g

forking: forking.c
$(CC) $(FLAGS) forking.c -o forking

all: forking
Binary file added Week8_Canaries/Fstrings/forking
Binary file not shown.
35 changes: 35 additions & 0 deletions Week8_Canaries/Fstrings/forking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <string.h>

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);

}
}
}

7 changes: 7 additions & 0 deletions Week8_Canaries/Fstrings/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CC = gcc
FLAGS = -no-pie -g

forking: forking.c
$(CC) $(FLAGS) forking.c -o forking

all: forking
7 changes: 7 additions & 0 deletions Week8_Canaries/Static/makefile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions Week8_Canaries/Static/static.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


// 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;

}