Search This Blog

Wednesday, September 15, 2010

How to Hide Username/Passwords in shell scripts

Please refer to this article for more details on this.

I have lot of shell scripts where I have to store my username and passwords for accessing the data. This is a big security rish as my passwords are exposed.

I need some executable which can convert my shell script to exe so that it will be difficult for the people to get my password.

Download the sources from http://www.datsi.fi.upm.es/%7Efrosal/sources/shc-3.8.6.tgz

Extract the tar file

tar xvfz shc-3.8.6.tgz

Make the executable

cd shc-3.8.6
make

cp shc to /usr/bin directory

I have a shell script which fetches some password protected pages , here
there is no other option for me other then embedding the password as the wget does
not support encrypted passwords

for example ,

cat getcookie.sh

#!/bin/ksh
/usr/bin/wget --keep-session-cookies --save-cookies=/home/ias/cookie.txt  -O /home/ias/dd.txt   --input-file=/home/ias/urls.txt --http-user=xx.xxx@test.com --http-password=xxxxxxx > /dev/null
cat /home/ias/cookie.txt  | grep test  | cut --fields=7 > /home/ias/cookie.txt

with the shc script I can convert the shell script as executable so that the passwords are hidden
from the people who has access to my unix system.

Run the shc command

shc -f getcookie.sh

This creates the getcookie.sh.c and getcookie.sh.x where .c is the c source file and .x is the executable.

Now run the getcookie.sh.x executable and change the password from the original getcookie.sh script.

Please refer to the http://blogs.koolwal.net/2009/01/20/howto-encrypting-a-shell-script-on-a-linux-or-unix-based-system/
for more details on this.

No comments: