How to crash Linux

There are a number of dangerous commands that can be executed to crash a Linux system. You may find a nefarious user executing these commands on a system you manage, or someone may send you a seemingly harmless command, hoping that you will run it and crash your computer.

It is important for system administrators to be aware of these commands, and run them on their own systems to ensure that they have taken the proper measures to prevent these attacks. Then again, maybe you are just a curious user and you want to crash your virtual machine for fun. That is fine, too.

Just be careful about executing these commands on production systems and computers that you do not own. Crashing someone else’s system can land you in trouble, so exercise caution when running the commands covered below. In this tutorial, we show several different methods that can be used to crash a Linux system.

In this tutorial you will learn:

  • How to crash Linux
  • How to prevent Linux crashes
How to crash Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to crash a Linux system



WARNING
Be sure to only test this code on a test machine or virtual machine. Using it on another system, even for testing purposes, will make you look like an attacker that is trying to crash the system. And, in some cases, you might succeed.
  1. The following line of code is a short and sweet fork bomb for the Bash shell. A fork bomb is effective because it is able to spawn an unlimited number of processes. Eventually, your system can’t process all of them, and will crash. One big advantage of a fork bomb is that you do not need root permissions to execute it and get the desired effect.
    $ :(){ :|:& };:
    

    Check out our guide on Linux fork bombs to learn how they work and how you can prevent them from crashing your system.

  2. Here is another fork bomb, but this time it is written in Perl. This is just as effective as the Bash fork bomb. Try running both to see how your test system responds (or doesn’t respond).
    $ perl -e "fork while fork" &
    
  3. You can delete your entire root directory with a simple rm command. This will be hard to recover from, and a simple reboot is not going to fix it, so run it with caution.
    $ sudo rm -rf / --no-preserve-root
    rm: it is dangerous to operate recursively on '/'
    rm: use --no-preserve-root to override this failsafe
    

    As you can see, our system is smart enough to warn us about this command. Let’s ignore the warning and kiss our virtual machine goodbye.

    $ sudo rm -rf / --no-preserve-root
    
  4. We can also write zeros to our entire hard drive with a simple dd command. This one is especially nasty because it can overwrite data on other partitions, outside of your Linux environment. And, even worse, we don’t get any kind of warning about the dangers of the command, or a confirmation prompt.
    $ sudo dd if=/dev/zero of=/dev/sda5
    

    Replace /dev/sda5 with the device or partition that you wish to obliterate. It only took our test system a few seconds to shut down and be irrecoverable after executing this command.

How to prevent Linux crashes

Fork bombs work by spawning endless processes. Therefore, we can prevent fork bomb crashes by just limiting the number of open processes that a user or group of users can have open simultaneously. Check out our guide on Linux fork bombs to learn how they work and how you can prevent them from crashing your system.

For other commands, such as those where tons of system files are deleted, or the hard drive partition is overwritten, there is no easy way to prevent all of these outside of restricting root access to only trusted users. On top of that, your users need to have secure passwords, and you should put proper file permissions on important files.

Still, people are always susceptible to phishing and social engineering. If someone gains access to the root account, there will be little that you can do to prevent them from taking down the system. In that case, you better have a backup.

Closing Thoughts




In this tutorial, we saw several different methods to crash a Linux system, as well as some advice on how to prevent these exploits in the first place. Every system administrator should be familiar with such commands, as its their job to defend against them. Apart from that, it’s just plain fun to execute some of these on test systems and virtual machines.


Comments and Discussions