Skip to content
Permalink
Browse files
Forking Version added (#14)
* Forking Version added

* Fstrings Version Addd
  • Loading branch information
aa9863 committed Mar 6, 2023
1 parent 2e84ec9 commit 8b8334dabe96bf7c4460efafbd7da38d64895e0d
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 0 deletions.
@@ -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);

}
}
}

@@ -0,0 +1,7 @@
CC = gcc
FLAGS = -no-pie -g

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

all: forking
Binary file not shown.
@@ -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);

}
}
}

@@ -0,0 +1,7 @@
CC = gcc
FLAGS = -no-pie -g

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

all: forking
@@ -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
@@ -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;

}

0 comments on commit 8b8334d

Please sign in to comment.