avatarKesk -*-

Summary

This article provides an overview of 11 dangerous Linux Bash commands that can lead to significant system damage or data loss if used improperly, emphasizing the importance of careful command usage.

Abstract

The article "11 Evil Bash Linux Commands Explained" serves as a cautionary guide to Linux users by detailing a set of powerful and potentially destructive Bash commands. These commands range from deleting disk partitions, disabling root command rights, to inducing kernel panic. The author, while not advocating for malicious use, aims to educate users about the potential risks associated with these commands. The article underscores the necessity of understanding the full impact of commands before executing them, especially when dealing with system administration tasks. It also provides insights into how these commands function and the irreversible consequences they can have, such as the permanent loss of data. The article concludes by reminding readers that with great power comes great responsibility and encourages them to use the knowledge gained wisely.

Opinions

  • The author believes that knowledge of these commands should be used responsibly and that they have the potential to be both useful and dangerous.
  • There is an underlying tone of warning against the careless use of powerful commands, particularly in the context of system administration.
  • The article implies that users should be well-informed about the commands they are using, especially when those commands can lead to catastrophic outcomes like data destruction or system inoperability.
  • The author suggests that accidental misuse of commands, such as using crontab -r instead of -e, can have severe consequences, highlighting the need for vigilance.
  • By providing examples of how these commands can be abused, the author indirectly criticizes those who might use this knowledge for harmful purposes.
  • The inclusion of a "Final thoughts" section indicates the author's hope that the series of posts will be helpful while also reminding readers of their responsibility in how they apply this knowledge.

11 Evil Bash Linux commands Explained

If you want to be ba evil with this, you have it easy

Photo by Mikhail Nilov

With this post, I want to share some “useful” but dangerous commands that you should use carefully. My goal is to end for the moment the series of posts I have written focused on Linux bash.

You will find the links to the rest of the post at the end.

Without wanting to keep you any longer, let’s get started.

1. Delete a disk partition

A faster way than using the typical: “urandom” to fill the hard disk with random data and leave it unusable is to run OpenSSL AES in parallel mode.

$ sudo openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero > /dev/sda1

2. Disable Root Command Rights

Suppose you want to make the administration of your Linux system practically impossible and piss off more than one person. In that case, you can delete the “sudo” and “su” commands, and no one will be able to run anything in administrator mode anymore.

$ sudo rm -f /usr/bin/sudo
$ rm -f /bin/su

3. Downloads and Runs a Script

A “sh script” can have good or destructive code; this is subjective. With “wget,” you can download the script, and with the “sh” command, you can execute it. You can always program it in the cron so that a script is downloaded from a URL at a specific time for running it.

$ sudo wget URL/script.sh -O- | sh 
  • “|” Pipe (send) the output of the “wget” command directly to another command, in this case, “sh.”
  • “sh”: executes the bash script.

4. Format the block ‘sda1’

The above command will create a new ext4 file system on the device. sda1 specifies a partition on the hard drive. Then, it simply formats the block ‘sda1’ and resets the hard drive.

$ sudo Mkfs.ext4 /dev/sda1
  • mkfs.ext4: Creates a new ext4 file system on the following device.
  • /dev/sda1: Specifies the first partition on the first hard drive, which is probably in use.

5. > File

This command is often used to clear the contents of a file. But be careful, the original file cannot be restored, and the data recovery software may not be able to help you.

$ > File

6. shred /dev/sda

With no possible solution, this much less known command can delete all files from a hard drive.

“Shred” is a tool that does not erase: it destroys. That is, it is not limited to removing a file from the file table but overwrites physical space dozens of times that it occupies, making it impossible to recover.

$ shred /dev/sda

7. Kernel Panic

Although hardware problems usually cause these crashes, there are ways to simulate them. Running any of those commands will result in a kernel panic, forcing you to reboot your system.

When you encounter a kernel panic, you have no choice but to reboot the system to get back to work. Depending on where you run it, this can be just a nuisance or a big problem.

$ echo 1 > /proc/sys/kernel/panic
$ cat /dev/port
$ cat /dev/zero > /dev/mem

8. Be bad

If an evil person adds this alias and then you use “cat” command to show a file, you will quickly notice strange behavior.

$ nano ~/.bashrc
 #Add the following content to the file:
 alias cat = 'rm -rf'

Add the command to “~/.bashrc” and reload with “source ~/.bashrc”

  • “alias” declares shortcuts for bash commands.
  • “cat” is the alias name and the same as the cat command.
  • The original “cat” command shows the content of a file.

Now, when the innocent user runs “cat” it will run instead of cat “rm -rf” which will force the deletion of files without asking for confirmation.

$ cat file.txt

9. Delete the boot directory

Deleting this directory will disable any system startup and thereby crash Linux. Very simple and effective

$ sudo rm -rf /boot

10. Destroy an encrypted disk

The “fsck” command is used to detect and fix file system problems and does not usually have any adverse consequences except if your system is encrypted. In this case, “fsck” will attempt to correct it, wrecking it. Remember only to check your file system after it has been unlocked.

$ sudo fsck -y /dev/sda
  • The “-y” flag will attempt to fix any detected filesystem corruption automatically.

11. crontab -r

This command is used to automate tasks keeping all cron jobs in a single crontab file, which can be removed by specifying the “-r flag.” Unfortunately, you can do this by mistake when you want to set the -e flag and accidentally enter -r. Beware because there is no confirmation prompt before removing the file.

$ crontab -r 
  • On Ubuntu/Debian, if your task has run before, try to grep CRON /var/log/syslog to recover it.

Final thoughts

I hope you have found this series of posts about the Linux shell helpful. But, of course, the your use of what is shown here is your responsibility.

Other super useful Linux commands:

Linux
Bash
Command Line
Shell
Linux Security
Recommended from ReadMedium