Tille - I can see you, read those man pages!   Tille's Site

Let's make some propaganda!

Here is the web server check script:

#!/bin/bash
# This script checks which WWW server a machine is running.
# If it's M$ IIS, send a note to the webmaster of that site.
# You may not want to do this in real life if you want to keep your Internet
# access.  The author of this document is not responsible for anything YOU do.

# First, check that we have a server to check:

if [ $# -ne 1 ]; then
	echo "Usage: apache_propaganda.sh {serverIP|servername}"
	exit
fi

# If the user has passed the dummy phase, put the first argument in a variable.
# This is not necessary, but is done for better readability of your script.

SERVER=$1

# This is the function which checks whether something is worth checking.
# The $1 we use here is the argument to the function, not the first argument 
# to the script.
# The port number is also put in a variable, for improved readability and
# flexibility.
# The echo at the beginning of the RESULT line sends two enters to the telnet
# process, so that it breaks off.

checkport() {
        PORT=$1
        echo "I will check your machine on port $PORT."
        RESULT=$(echo "\n\n" | telnet $SERVER $PORT | head -10 | grep -i connected)
}

checkport 80

# If the RESULT variable is empty, no further actions are taken.

if [ -z $RESULT ]; then
        echo "Nothing is running on $SERVER:$PORT"
        exit

# If the RESULT variable is not empty, there are two possibilities: either this
# machine runs something good, or something evil.  First check on evil, since 
# this case contains a clue to search for, while not evil might be anything.

else
        echo "Something is running here, I will further inspect.."
        VERSION=$(lynx -dump -head http://$SERVER/ | grep '^Server' | grep -i microsoft)
fi

# Same as earlier, if the VERSION variable is empty, then everything is OK, if
# not, we have to do something about it.

if [ -z $VERSION ]; then
        OK=$(lynx -dump -head http://$SERVER/ | grep '^Server' | cut -d" " -f2-)        echo "$SERVER is safe, running $OK."
else
        echo "alert!!  Found evil $VERSION! running on $SERVER"
        echo "Taking appropriate measures"
        echo "World's best WWW server available for free from http://apache.org" | mail -s "your web server" webmaster@$SERVER
fi

When run, the script outputs information similar to that below:

prompt> ./apache-propaganda.sh www.apache.org
I will check your machine on port 80.
Connection closed by foreign host.
./apache-propaganda.sh: [: too many arguments
Something is running here, I will further inspect..
www.apache.org is safe, running Apache/2.0.41-dev (Unix).

prompt> ./apache-propaganda.sh blubber
I will check your machine on port 80.
telnet: connect to address 192.168.42.15: Connection refused
Nothing is running on blubber:80

prompt> ./apache-propaganda.sh www.eunet.be
I will check your machine on port 80.
Connection closed by foreign host.
./apache-propaganda.sh: [: too many arguments
Something is running here, I will further inspect..
./apache-propaganda.sh: [: Server:: binary operator expected
alert!!  Found evil Server: Microsoft-IIS/5.0! running on www.eunet.be
Taking appropriate measures

Yeah, things are not like they used to be...

BTW don't worry about the "too many arguments" messages, this is because we use telnet instead of an appropriate scripting tool (e.g. netcat). I used telnet because everybody knows it and has it installed.

Home
© 1995-2010 Machtelt Garrels - tille - Powered by vIm - Best viewed with your eyes - Validated by W3C - Last update 20100511