Is it a joke or a command?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Is it a joke or a command?
# 1  
Old 05-01-2019
Is it a joke or a command?

Hello,
I have found some commands in a forum under "top ten unix commands" topic and I'd like to ask: what does below command do:
Could it really be a command or a joke?
Code:
:(){ :|:& };:


Thanks
Boris
# 2  
Old 05-01-2019
Hi, this is one of the most well known "fork bombs". The use of ":" as a function name will work in bash or zsh, but not in most other shells. It is an unlimited recursive function that keeps calling itself and spawning new processes until your computer runs out of resources.

Never run that, or your computer will come to a crawl and it will need to be rebooted if there are no provisions to limit your user processes.

Last edited by Scrutinizer; 05-02-2019 at 01:03 AM..
These 7 Users Gave Thanks to Scrutinizer For This Post:
# 3  
Old 05-02-2019
One of our developers unleashed this very fork bomb. On a development box. Fortunately developers did not have shell level access to production. There is a special account to fix prod problems. That account has a password change every 7 days, when on-call rotates to another user.

This why you do not let anyone except a special highly controlled account onto prod. We script-ed the account, just to be able to report to auditors what exactly each and every action against the prod db and files was. This included code pushes.

And no, it is not a joke. Never trust anything from that site again if they presented the forkbomb as something benign.
These 5 Users Gave Thanks to jim mcnamara For This Post:
# 4  
Old 05-02-2019
Hello,
Thank you all for your comment.
Here is another one, posted by the same person:

Code:
echo -e "#include <unistd.h>\nint main(void){while(1) {fork();}return 0;}" > x.c; gcc -o x x.c && ./x

creating c file, under gnu c compiler, doing something, convert it to x and run it.

Thank you
Boris
# 5  
Old 05-02-2019
Looks like another fork bomb.
Harden your system! For example, RedHat/Centos 7.x has
Code:
# grep '^[^#]*nproc' /etc/security/limits.conf /etc/security/limits.d/*
/etc/security/limits.d/20-nproc.conf:*          soft    nproc     4096
/etc/security/limits.d/20-nproc.conf:root       soft    nproc     unlimited

At login (generally: at every system access) this limit is set by PAM. Can be verified with
Code:
ulimit -a

Caution, even if the root account were not excepted, the PAM might not set the limit for UID=0 accounts. Another reason to not run suspicious code as root!
This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 05-02-2019
Hi fellas...

OO oriented programming lends itself to quick acting fork_bombing and memory eating.
Take this Python code deliberately held back:
Code:
# Works on any Python!
# OO programming eats memory like there's in no tomorrow!
text='Junk variable!'
for x in range(0,5,1):
    text=text+text
    print(text)
    print(id(text))

# A very basic fork bomb for Python, the print function holds it back:
# def _(): _()

def _(): print('_()'); print(id(_))
_()

Results OSX 10.14.3, default bash terminal calling Python 3.5.2.
Code:
Last login: Thu May  2 10:13:33 on ttys000
AMIGA:amiga~> cd Desktop/Code/Python
AMIGA:amiga~/Desktop/Code/Python> python3.5 OO_bomb.py
Junk variable! Junk variable! 
4328391264
Junk variable! Junk variable! Junk variable! Junk variable! 
4328477280
Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! 
4327568992
Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! 
4338181032
Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! Junk variable! 
4337054352
_()
4338198864
AMIGA:amiga~/Desktop/Code/Python> _

As one can see the fork bomb although not obfuscated is a single line of code and very dangerous.
Object Orientation OTOH is memory hungry and anyone with any knowledge can do that from Python interactive shell.
With only 2MB of memory on a stock AMIGA A1200 and Python this stood out only too well as soon my 2MB was gone.
These 2 Users Gave Thanks to wisecracker For This Post:
# 7  
Old 05-02-2019
Quote:
Originally Posted by baris35
Hello,
I have found some commands in a forum under "top ten unix commands" topic and I'd like to ask: what does below command do:
Could it really be a command or a joke?
Code:
:(){ :|:& };:

Thanks
Boris

If you consider : as True, NOP or Pass and use the 'True' meaning then I will rewrite in a method that is understandable.
Code:
# Create a function True(), ':()'.
True()
{
        # Call True ':' and Pipe '|' to itself True ':' in the Background '&'.
        True | True &
}
# Command separator ';', valid in shell scripts using a newline in its place.
# Call it.
True

Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. What is on Your Mind?

Post Your Favorite Joke! Laugh a Little!

Let's have a few laughs! Post your favorite joke! (no racist / racism jokes, please post in good taste, thanks!) (65 Replies)
Discussion started by: Neo
65 Replies
Login or Register to Ask a Question