EvilChicken!
08-03-2008, 09:14 PM
A FORK BOMB IN MULTIPLE LANGUAGES
Hi, and welcome to my tutorial about fork bombs. Thanks for clicking on it, and I hope you enjoy reading it as much as you did clicking on the link that directed you here.
Table of contents:
I - Disclaimer
--- Read this before continuing
II - What are fork bombs?
--- A brief intro and explanation
III - Fork bombs in theory
--- Construction of the different types of fork bombs
IV - Fork bomb examples in other languages
--- Perl, Python, PHP, x86, Haskell..
V - Prevention
--- What to do to avoid these baddies?
VI - Links to other info
--- External links
VII - Final notes
--- Final words of this tutorial
I - Disclaimer
Before reading any other section of this tutorial, read this first:
Although fork bombs are pretty much harmless, you should still be cautious while experimenting with them. I, EvilChicken!, the author of this tutorial, is not responsible for any thing that should happen with you or your surroundings before, during or after reading this tutorial, no matter what.
This tutorial was written for learning and protection purposes only.
II - What is a fork bomb?
A fork bomb is a mostly harmless form of an wabbit (http://en.wikipedia.org/wiki/Wabbit) attack towards a computer system, where a running fork (http://en.wikipedia.org/wiki/Fork_%28computing%29) process can create another process, which can create another, and it could theoretically go on like this for infinity. But, on a real computer, those fork bombs would eventually use up all system resources and your computer would freeze, leaving you no option but to restart.
And that example is just one of the fork bombs available.
III - Fork bombs in theory
As I feel I haven't fully concluded the last chapter, I will now let you experience the effect of a harmless fork bomb variant for yourself to fully grasp the harmlessness of these. Why try it with any other compiler other than the one you are most used to?
Exactly, the first piece of code for a fork bomb is to be ran in no other program than SCAR itself!
Here is the code.
Paste it in SCAR, press run and see what happens.
(Small tip: press CTRL + ALT + DEL first..)
label
D;
begin
D: // 1
WriteLn('Same effect as a repeat loop..');
goto D; // 2
end.
This type of fork bomb is absolutely not harmful, since the same effect can be achieved with an endless loop. (Repeat until false.) This will, in most cases make the program freeze. Only thing you have to do is to press CTRL + ALT + DEL, go to the processes tab, highlight scar.exe and terminate the process.
I understand that this is boring stuff, but this is the basic concept for a common type of fork bombs, and if I don't explain it, .. Why would I even bother to make this tutorial then? :rolleyes:
Anyway, in the 8 lines of code posted above, there are two comment marks, "//1" and "//2". They mark the most two most important commands in the "script". After declaring the label (done in line 1 and 2) and the "begin" identifier which states the start of the mainloop, "//1" is found. This is where we declare the label. You can think that a label has a similar function as a bookmark, if you want. There is nothing more to it. (There is an available tutorial on labels found here (http://www.villavu.com/forum/showthread.php?t=3890?t=4659&highlight=label) made by Freddy1990, the creator of SCAR.)
Continuing, between the "//1" and "//2" comments, we simply put whatever we want SCAR to do every time it browses this loop. And finally, "//2" is where we tell SCAR to go back to our bookmark, which I chose to call "D". For the record, the label can be called anything you want to.
Next programming language up is the versatile Batch programming language (http://en.wikipedia.org/wiki/Batch_file) (please check it out, you won't regret it if you're interested in programming). In addition to being extremely simple to learn while remaining efficient, it is also fun and leet. Very leet. In this tutorial, I will show you the variant of batch programming which I know how to code in; MS-DOS batch files. Thats right, the good ol' DOS (http://en.wikipedia.org/wiki/Batch_file#DOS).
DOS batch files are Windows-only, but they support almost all Windows versions (http://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions) from the ancient Windows 3.1 (http://en.wikipedia.org/wiki/Windows_3.1) to the Windows XP of today. I am not sure if Vista (that crap doesn't deserve a link) supports DOS batch files, not do I care - because Vista is only a "graphical" OS, with minor so-called "security features" added since XP, which EATS system resources so badly that you'll be fine without fork bombs. (You don't need them when you're running one as an OS.) It is worth mentioning here that Microsoft is making a new Windows, which currently goes under the name "Windows 7". It will probably be out in 2010, so Google it if you want to, because I really need to get back on topic.
Back to DOS batch files: The fork bomb you can make with batch files are somewhat more "powerful". The first for is harmless and won't require you to do anything except for terminating it in Task Management, (CTRL + ALT + DEL) but the second fork will most likely require you to restart your PC due to all the lag. (At least I had to..) So beware - but I swear (hoi, rhymes) that it is worth it if you haven't tried it before. The sight of 50 DOS windows popping up per second is quite entertaining.
Once again I present you the code: (Ta-da-daaaa)
%0|%0
Tadaaa. Yep, five chars. I don't think it'll get easier than this.
Open notepad, paste in those five chars, press CTRL + S or go to File -> Save as.. and name the file lolz.bat
http://img140.imageshack.us/img140/1111/utennavnmi5.png
@1: Name file with the file extension .bat, @2: Select "All files", @3: If not set to ANSI, set it to be so. @4: Save. Tadaa!
If you're a true genius, you already understand that anything except the file extension can be named after preference.
Ready to run the code? Good. But read the following first: First, open up Task Manager (http://pauillac.inria.fr/~xleroy/stuff/ctrl-alt-del.jpeg). (I'm, done posting that world famous shortcut for good.)
This is the most important note for you to avoid unnecessary reboot: whenever you get the batch running, hundreds of processes will appear in the process list tab in the process manager. (http://blogs.thesitedoctor.co.uk/tim/img/UsernamelessTaskManager.jpg) Ignore those, just go to the "Applications" tab and terminate the batch that is running. I'm not sure if that'll work for you, but it did for me, so it should do the same for you. Just remember that selecting and opening that god damn task manager could take a while. (I wonder why though.. :rolleyes: )
After reading those notes, run the batch you just created.
After a couple of seconds, a small hell will break loose. (You will most likely remain calm, since this was initiated intentionally, but think about your poor computer?) Do as instructed in the notes (couple lines up) to terminate the batch. I'm guessing that it is pointless to write anything else, because I don't think you'll have too much time left to read this while your fork is running before the entire computer freezes.
What do you think? Weak, you say? Well, here is a more powerful one. To run it, follow the same steps for creating/saving as listed above.
:hoi
START %0
GOTO :hoi
But please, do bookmark this tutorial and reopen it once you've rebooted your computer. Furthermore, save all your data, close any running programs, and get ready to switch off the PC using the power switch.
This one was better, eh? It wasn't? Well, this is the closest you'll get to making non-harmful malware. I must once again remind that this tutorial was created for learning, prevention and protection use only. Prevention and protection of your data, that is.
Fork bombs in other languages: (Most code is taken from Wikipedia)
Perl: (http://en.wikipedia.org/wiki/Perl)
#!/usr/bin/perl
fork while 1
Haskell: (http://en.wikipedia.org/wiki/Haskell_%28programming_language%29)
import Control.Monad
import System.Posix.Process
forkBomb = forever $ forkProcess forkBomb
The beloved Python (http://en.wikipedia.org/wiki/Python_programming_language):
import os
while True:
os.fork()
The popular C (http://en.wikipedia.org/wiki/C_%28programming_language%29):
#include <unistd.h>
int main(int argc, char* args[])
{
while(1)
fork();
return 0;
}
PHP (http://en.wikipedia.org/wiki/PHP):
while(1)
pcntl_fork();
x86 (http://en.wikipedia.org/wiki/X86):
format ELF executable
entry start
start:
push 0x2 ; Linux fork system call
pop eax ;
int 0x80 ; Call to the kernel
jmp start ; Loop back to the start
V - Prevention
Is this question even worth asking? Are they even harmful?
The answer is yes. Kinda. On servers that are running 24-7, this is a serious thread. Aw, come on guys, I know all of you have at least five of those! :p
But, no - fork bombs are usually harmless, unless they gain access to your registry to tweak it to launch the fork bomb(s) at windows startup, so beware.
VI - Links
- http://www.cyberciti.biz/faq/understanding-bash-fork-bomb/
- http://en.wikipedia.org/wiki/Fork_bomb
- www.google.com
Only links you'll need, the last two are especially helpful.
VII - Final notes
I thank you once again for reading my tutorial. If you want to do something in return, please post response and request for what more I could add, and lend me a RS member account for me to finish my flax spinner.
Remember:
- CTRL + ALT + DEL to open up Task Manager.
- CTRL + F to search for (a) specific keyword(s).
- CTRL + mouse scrolling wheel to increase or decrease font size.
A final note to all moderators and administrators: In addition to the disclaimers and the notices about this tutorial's purpose, I would like to most humbly not remove this tutorial, due to three reasons:
1. Fork bombs are in 99,98% of all cases harmless, and have to be manually launched for the forking process to begin.
2. This tutorial covers slightly more than just fork bombs, and people who do not find programming interesting can still hopefully enjoy it.
3. I spent a good amount of time writing this tutorial, honestly. I would say about 4 hours.
Hi, and welcome to my tutorial about fork bombs. Thanks for clicking on it, and I hope you enjoy reading it as much as you did clicking on the link that directed you here.
Table of contents:
I - Disclaimer
--- Read this before continuing
II - What are fork bombs?
--- A brief intro and explanation
III - Fork bombs in theory
--- Construction of the different types of fork bombs
IV - Fork bomb examples in other languages
--- Perl, Python, PHP, x86, Haskell..
V - Prevention
--- What to do to avoid these baddies?
VI - Links to other info
--- External links
VII - Final notes
--- Final words of this tutorial
I - Disclaimer
Before reading any other section of this tutorial, read this first:
Although fork bombs are pretty much harmless, you should still be cautious while experimenting with them. I, EvilChicken!, the author of this tutorial, is not responsible for any thing that should happen with you or your surroundings before, during or after reading this tutorial, no matter what.
This tutorial was written for learning and protection purposes only.
II - What is a fork bomb?
A fork bomb is a mostly harmless form of an wabbit (http://en.wikipedia.org/wiki/Wabbit) attack towards a computer system, where a running fork (http://en.wikipedia.org/wiki/Fork_%28computing%29) process can create another process, which can create another, and it could theoretically go on like this for infinity. But, on a real computer, those fork bombs would eventually use up all system resources and your computer would freeze, leaving you no option but to restart.
And that example is just one of the fork bombs available.
III - Fork bombs in theory
As I feel I haven't fully concluded the last chapter, I will now let you experience the effect of a harmless fork bomb variant for yourself to fully grasp the harmlessness of these. Why try it with any other compiler other than the one you are most used to?
Exactly, the first piece of code for a fork bomb is to be ran in no other program than SCAR itself!
Here is the code.
Paste it in SCAR, press run and see what happens.
(Small tip: press CTRL + ALT + DEL first..)
label
D;
begin
D: // 1
WriteLn('Same effect as a repeat loop..');
goto D; // 2
end.
This type of fork bomb is absolutely not harmful, since the same effect can be achieved with an endless loop. (Repeat until false.) This will, in most cases make the program freeze. Only thing you have to do is to press CTRL + ALT + DEL, go to the processes tab, highlight scar.exe and terminate the process.
I understand that this is boring stuff, but this is the basic concept for a common type of fork bombs, and if I don't explain it, .. Why would I even bother to make this tutorial then? :rolleyes:
Anyway, in the 8 lines of code posted above, there are two comment marks, "//1" and "//2". They mark the most two most important commands in the "script". After declaring the label (done in line 1 and 2) and the "begin" identifier which states the start of the mainloop, "//1" is found. This is where we declare the label. You can think that a label has a similar function as a bookmark, if you want. There is nothing more to it. (There is an available tutorial on labels found here (http://www.villavu.com/forum/showthread.php?t=3890?t=4659&highlight=label) made by Freddy1990, the creator of SCAR.)
Continuing, between the "//1" and "//2" comments, we simply put whatever we want SCAR to do every time it browses this loop. And finally, "//2" is where we tell SCAR to go back to our bookmark, which I chose to call "D". For the record, the label can be called anything you want to.
Next programming language up is the versatile Batch programming language (http://en.wikipedia.org/wiki/Batch_file) (please check it out, you won't regret it if you're interested in programming). In addition to being extremely simple to learn while remaining efficient, it is also fun and leet. Very leet. In this tutorial, I will show you the variant of batch programming which I know how to code in; MS-DOS batch files. Thats right, the good ol' DOS (http://en.wikipedia.org/wiki/Batch_file#DOS).
DOS batch files are Windows-only, but they support almost all Windows versions (http://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions) from the ancient Windows 3.1 (http://en.wikipedia.org/wiki/Windows_3.1) to the Windows XP of today. I am not sure if Vista (that crap doesn't deserve a link) supports DOS batch files, not do I care - because Vista is only a "graphical" OS, with minor so-called "security features" added since XP, which EATS system resources so badly that you'll be fine without fork bombs. (You don't need them when you're running one as an OS.) It is worth mentioning here that Microsoft is making a new Windows, which currently goes under the name "Windows 7". It will probably be out in 2010, so Google it if you want to, because I really need to get back on topic.
Back to DOS batch files: The fork bomb you can make with batch files are somewhat more "powerful". The first for is harmless and won't require you to do anything except for terminating it in Task Management, (CTRL + ALT + DEL) but the second fork will most likely require you to restart your PC due to all the lag. (At least I had to..) So beware - but I swear (hoi, rhymes) that it is worth it if you haven't tried it before. The sight of 50 DOS windows popping up per second is quite entertaining.
Once again I present you the code: (Ta-da-daaaa)
%0|%0
Tadaaa. Yep, five chars. I don't think it'll get easier than this.
Open notepad, paste in those five chars, press CTRL + S or go to File -> Save as.. and name the file lolz.bat
http://img140.imageshack.us/img140/1111/utennavnmi5.png
@1: Name file with the file extension .bat, @2: Select "All files", @3: If not set to ANSI, set it to be so. @4: Save. Tadaa!
If you're a true genius, you already understand that anything except the file extension can be named after preference.
Ready to run the code? Good. But read the following first: First, open up Task Manager (http://pauillac.inria.fr/~xleroy/stuff/ctrl-alt-del.jpeg). (I'm, done posting that world famous shortcut for good.)
This is the most important note for you to avoid unnecessary reboot: whenever you get the batch running, hundreds of processes will appear in the process list tab in the process manager. (http://blogs.thesitedoctor.co.uk/tim/img/UsernamelessTaskManager.jpg) Ignore those, just go to the "Applications" tab and terminate the batch that is running. I'm not sure if that'll work for you, but it did for me, so it should do the same for you. Just remember that selecting and opening that god damn task manager could take a while. (I wonder why though.. :rolleyes: )
After reading those notes, run the batch you just created.
After a couple of seconds, a small hell will break loose. (You will most likely remain calm, since this was initiated intentionally, but think about your poor computer?) Do as instructed in the notes (couple lines up) to terminate the batch. I'm guessing that it is pointless to write anything else, because I don't think you'll have too much time left to read this while your fork is running before the entire computer freezes.
What do you think? Weak, you say? Well, here is a more powerful one. To run it, follow the same steps for creating/saving as listed above.
:hoi
START %0
GOTO :hoi
But please, do bookmark this tutorial and reopen it once you've rebooted your computer. Furthermore, save all your data, close any running programs, and get ready to switch off the PC using the power switch.
This one was better, eh? It wasn't? Well, this is the closest you'll get to making non-harmful malware. I must once again remind that this tutorial was created for learning, prevention and protection use only. Prevention and protection of your data, that is.
Fork bombs in other languages: (Most code is taken from Wikipedia)
Perl: (http://en.wikipedia.org/wiki/Perl)
#!/usr/bin/perl
fork while 1
Haskell: (http://en.wikipedia.org/wiki/Haskell_%28programming_language%29)
import Control.Monad
import System.Posix.Process
forkBomb = forever $ forkProcess forkBomb
The beloved Python (http://en.wikipedia.org/wiki/Python_programming_language):
import os
while True:
os.fork()
The popular C (http://en.wikipedia.org/wiki/C_%28programming_language%29):
#include <unistd.h>
int main(int argc, char* args[])
{
while(1)
fork();
return 0;
}
PHP (http://en.wikipedia.org/wiki/PHP):
while(1)
pcntl_fork();
x86 (http://en.wikipedia.org/wiki/X86):
format ELF executable
entry start
start:
push 0x2 ; Linux fork system call
pop eax ;
int 0x80 ; Call to the kernel
jmp start ; Loop back to the start
V - Prevention
Is this question even worth asking? Are they even harmful?
The answer is yes. Kinda. On servers that are running 24-7, this is a serious thread. Aw, come on guys, I know all of you have at least five of those! :p
But, no - fork bombs are usually harmless, unless they gain access to your registry to tweak it to launch the fork bomb(s) at windows startup, so beware.
VI - Links
- http://www.cyberciti.biz/faq/understanding-bash-fork-bomb/
- http://en.wikipedia.org/wiki/Fork_bomb
- www.google.com
Only links you'll need, the last two are especially helpful.
VII - Final notes
I thank you once again for reading my tutorial. If you want to do something in return, please post response and request for what more I could add, and lend me a RS member account for me to finish my flax spinner.
Remember:
- CTRL + ALT + DEL to open up Task Manager.
- CTRL + F to search for (a) specific keyword(s).
- CTRL + mouse scrolling wheel to increase or decrease font size.
A final note to all moderators and administrators: In addition to the disclaimers and the notices about this tutorial's purpose, I would like to most humbly not remove this tutorial, due to three reasons:
1. Fork bombs are in 99,98% of all cases harmless, and have to be manually launched for the forking process to begin.
2. This tutorial covers slightly more than just fork bombs, and people who do not find programming interesting can still hopefully enjoy it.
3. I spent a good amount of time writing this tutorial, honestly. I would say about 4 hours.