Jump to content
Sign in to follow this  
Deepy

Windows + Unix/linux Forkbomb

Recommended Posts

Windows version

#include <stdio.h>
int fish(void) {
 fish();
 fish();
 printf("Hest");
 return 0;
}
int main(int argc, char *argv[])
{
fish();
return 0;
}

starts itself twice and then says Hest.

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>

typedef enum {MODE_SLEEP,MODE_LOOP,MODE_FORK, MODE_FORKSHELL} MODE;


static void forkbomb_userfork (MODE mode)
{
pid_t pid = fork();
if (pid==-1){
fprintf (stderr,"Fork failed (%s)\n",strerror(errno));
}else if (pid == 0){
if (mode == MODE_SLEEP){
sleep(20);
}else if (mode == MODE_LOOP){
int k=0;
while (1) k++;
}else if (mode == MODE_FORKSHELL){
system ("/bin/false");
}
_exit (0);
}
}


int main (int argc, char *argv[])
{
if (argc != 4){
fprintf (stderr,"formboom 2 2 mode\n"
);
}else{
MODE mode;
int i;
if (strcmp(argv[3],"sleep")==0){
mode = MODE_SLEEP;
}else if (strcmp(argv[3],"loop")==0){
mode = MODE_LOOP;
}else if (strcmp(argv[3],"fork")==0){
mode = MODE_FORK;
}else if (strcmp(argv[3],"forkshell")==0){
mode = MODE_FORKSHELL;
}else{
fprintf (stderr,"Invalid mode\n");
exit (-1);
}
for (i=0; i<atoi(argv[2]); i++){
if (fork()==0){
if (setuid (i+1)==-1){
fprintf (stderr,"Can't setuid to uid %d (%s)\n",i+1
,strerror(errno));
}else{
       int j;
for (j=0; j<atoi(argv[1]); j++){
forkbomb_userfork (mode);
}
if (mode == MODE_FORK || mode == MODE_FORKSHELL){

int status;
while (wait(&status)!=-1) forkbomb_userfork(mode);
}
}
_exit (0);
}
}
system ("ps ax | wc -l");
printf ("All the process are running now\n");
printf ("Exit to end all processes\n");
system ("/bin/sh");
system ("killall forkbomb");
}
return 0;
}

UNIX compatible forkbomb, with helpfile to exit it easily :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...