Using the command TRAP to protect Root account

If you are as crazy about information security as me, you’ll find this very cool. We can create a trap to protect root account using the command TRAP! How cool is that?!

First of all, you need to open the file /root/.bashrc:

# vi /root/.bashrc

Add the script below to it:

 < A NAME="note" HREF="#textnote">< SUP> end of file we'll add the lines below
 extrasecurity()
 {
 echo "Corolla is car from what company?"
 trap extrasecurity 2 20
 read -s resp
 if [ "$resp" != "Toyota" ]; then
 echo "Wrong"
 logout
 fi
 }
 extrasecurity
 < A NAME="note" HREF="#textnote">< SUP>## end of file .bashrc

Explanation:

  1. Whenever a user attempts to logon with user root, the file /root/.bashrc will be executed
  2. The line extrasecurity will execute the function extrasecurity(), if the user answers to the question wrongly, he will get the message “Wrong” and will be logged out of root’s account.
  3. The coolest thing here is that experienced users might be thinking “I can issue CTRL+C or CTRL+Z and I will stop this script”. Well, not this time! Thanks to our friend trap which will get these signals and use them to just call the function over and over.

Now you should protect the file against unauthorized changes, avoiding this way other users to see the answer:

# chmod 700 /root/.bashrc

For even more security, you can disable the root account to logon through ssh, avoiding changes from scp.
To list the code numbers of signals you can use:

# trap -l

Credits:

The original post (in Portuguese) belongs to Altemir Braz Dantas Junior, you can read it on http://www.Dicas-L.com.br/dicas-l/20110208.php

 

Advertisements

About Bruno Carvalho

Coffee addicted tech guy.
This entry was posted in Scripts and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s