#!/bin/sh

# Die Farben anpassen
setterm -foreground green -background black

# Den Programm-Header ausgeben
echo
echo "  |\      _,,,---,,_       Catwalk 3.0"
echo "  /,\`.-'\`'    -.  ;-;;,_"
echo " |,@,  ) )-,_. , \ ( \`'-'  Auswertungs-Utility"
echo "'---''(_/--\'  \`-'\_)      marc.ruef-at-computec.ch"
echo "                           http://www.computec.ch"
echo
echo "Catwalk ist ein open-source Utility fuer das einfache und effiziente umsetzen"
echo "von Security Audits, Assessments und Penetration Tests. Durch einen einfachen"
echo "Aufruf des Tools  koennen mehrere andere Utilities genutzt und auf eine Ziel-"
echo "umgebung angesetzt werden. Innert weniger Minuten lassen sich so die grund-"
echo "legenden Netzwerkdaten zusammengetragen und ein Ueberblick verschaffen."
echo

# Abbruch
abbruchcmd() {
setterm -foreground red -background black
echo "Der Prozess wurde wurde abgebrochen - Try again ..."
setterm -foreground green -background black
}

# Fehlermeldung
fehlercmd() {
echo "Syntax von Catwalk: catwalk <optionen> <hostfile.txt>"
echo
echo "Die moeglichen Optionen fuer den Scanmodus sind folgende:"
echo
echo -e "-al\t--alle\t\t\tAlle Optionen\t\tfast alle"
echo -e "-sc\t--scip\t\t\tEin typ. scip AG Scan\tfast alle u. schnell"
echo -e "-up\t--update\t\tDebian-Update\t\tapt-get"
echo -e "-wo\t--whois\t\t\twhois\t\t\twhois"
echo -e "-ho\t--host\t\t\thost\t\t\thost"
echo -e "-ps\t--pingsuchlauf\t\tPing-Suchlauf\t\tnmap"
echo -e "-pe\t--broadcastping255\tBroadcast-Ping 255\tping"
echo -e "-p0\t--broadcastping0\tBroadcast-Ping 0\tping"
echo -e "-pr\t--arping\t\tARP-Ping\t\tarping"
echo -e "-pn\t--ping\t\t\tPing\t\t\tping"
echo -e "-pa\t--icmpaddressmask\tICMP address mask\thping3"
echo -e "-ti\t--tracerouteicmp\tICMP Traceroute\t\ttraceroute"
echo -e "-tu\t--tracerouteudp\t\tUDP Traceroute\t\ttraceroute"
echo -e "-tt\t--traceroutetcp\t\tTCP Traceroute\t\ttcptraceroute"
echo -e "-st\t--tcpportscan\t\tTCP-Portscan\t\tnmap"
echo -e "-ss\t--halfopenportscan\thalf-open Portscan\tnmap"
echo -e "-sf\t--finportscan\t\tFIN-Portscan\t\tnmap"
echo -e "-sx\t--xmasportscan\t\tXMas-Portscan\t\tnmap"
echo -e "-sn\t--nullportscan\t\tNull-Portscan\t\tnmap"
echo -e "-sa\t--ackportscan\t\tACK-Portscan\t\tnmap"
echo -e "-sw\t--windowportscan\tWindow-Portscan\t\tnmap"
echo -e "-su\t--udpportscan\t\tUDP-Portscan\t\tnmap"
echo -e "-si\t--icmpos\t\tICMP OS Fingerprinting\txprobe2"
echo -e "-sp\t--protocolscan\t\tProtocolscan\t\tnmap"
echo -e "-ms\t--snmpstatus\t\tSNMP-Status-Scan\tsnmpstatus"
echo -e "-mw\t--snmpwalk\t\tSNMP-Walking\t\tsnmpwalk"
echo -e "-nf\t--nfs\t\t\tNFS-Shares\t\tshowmount"
echo -e "-nb\t--netbios\t\tNetBIOS-Shares\t\tsmbclient"
echo -e "-rp\t--rpcinfo\t\tRPCinfo\t\t\trpcinfo"
echo -e "-fi\t--finger\t\tFinger\t\t\tfinger"
echo -e "-ba\t--bannergrabbing\tBanner-Grabbing\t\tnc"
echo -e "-at\t--amap\t\t\tTCP Application Mapping\tamap"
echo -e "-au\t--amap\t\t\tUDP Application Mapping\tamap"
echo -e "-ws\t--webscab\t\tCGI-Scanning\t\tnikto"
echo -e "-ra\t--raccess\t\tRaccess\t\t\traccess"
echo -e "-ne\t--nessus\t\tNessus Scan\t\tnessus"
echo
echo "Beispiel: $0 -pn -st -am targets.txt"
echo
setterm -default
exit
}

# Das Update mit apt-get umsetzen
case $@ in *"-al "|*-up*|*"--update "*|*"--upgrade "*|*"--aptget "*|*"--apt-get "*|*"--install "*)
    echo "Suche nach apt-get ..."
    if [ `which apt-get` ]
    then
        echo "apt-get wurde gefunden."
        echo "Aktualisiere die Software-Elemente mit der Hilfe von apt-get ..."
        apt-get update && apt-get install hping2 arping traceroute tcptraceroute host nmap amap xprobe netcat finger smbclient raccess nessus nessusd && "Software-Elemente wurden erfolgreich aktualisiert."
    else
	echo "Der Befehl apt-get konnte nicht gefunden werden."
	echo "Bitte installieren Sie apt-get, bevor Sie diese Funktion nutzen."
	abbruchcmd
    fi
esac

# Auswerten, ob die Eingabe okay und wir das Hostfile lesen koennen
if [ $# -gt 1 ]
then
    echo "Das Hostfile wird eingelesen ..."
    TARGETFILE=`echo $@|rev |awk '{print $1}' |rev`
    TARGETSKOMMA=`cat $TARGETFILE` # Diese Kommaformatierungen brauchen wir zum Beispiel fuer nmap
    TARGETS=`echo "$TARGETSKOMMA" |sed "s/,/ /g"`
    if [ -z "$TARGETS" ]
    then
	fehlercmd
    else
	echo "Datei $TARGETFILE erfolgreich eingelesen und umgewandelt."
	echo "Folgende Systeme werden getestet: $TARGETS."

	# Die Report-Verzeichnisse erstellen
	echo "Erstelle die Verzeichnis-Struktur fuer die Ausgaben ..."
	REPORT=`echo $TARGETS |awk 'BEGIN{FS="."}{print $1"."$2"."$3"."0}'`
	mkdir $REPORT && echo "Das Report-Verzeichnis $REPORT wurde erfolgreich erstellt."

	# Die Scanning Host Details speichern
	echo "Speichere die Grunddaten dieses Auditsystems ..."
	date | tee $REPORT/scanstart.txt
	uname -a | tee $REPORT/uname.txt
	users | tee $REPORT/users.txt
        hostname | tee $REPORT/hostname.txt
	ifconfig -a | tee $REPORT/ifconfig.txt
	route | tee $REPORT/route.txt
	cat /etc/resolv.conf | tee $REPORT/resolv-conf.txt
    fi
else
    fehlercmd
fi

###
### Hier beginnen die eigentlichen Checks
###

whoiscmd() {
echo "Suche nach whois ..."
if [ `which whois` ]
then
    echo "whois wurde gefunden."
    whois --version | tee $REPORT/whois-version.txt

    echo "Lege Verzeichnis $REPORT/whois an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/whois && echo "Verzeichnis erfolgreich angelegt."
    echo "Spezifiere das Ziel fuer unsere whois-Abfrage ..."
    WHOISTARGET=`echo $TARGETS |awk 'BEGIN{FS=" "}{print $1}'`
    echo "Ziel erfolgreich umgewandelt."
    echo "Starte whois-Abfrage auf $WHOISTARGET ..."
    whois $WHOISTARGET |tee $REPORT/whois/whois-$WHOISTARGET.txt && echo "whois-Abfrage auf $WHOISTARGET erfolgreich durchgefuehrt."
else
    echo "Der Befehl whois konnte nicht gefunden werden."
    echo "Bitte installieren Sie whois, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

hostcmd() {
echo "Suche nach host ..."
if [ `which host` ]
then
    echo "host wurde gefunden."
    host --version | tee $REPORT/host-version.txt

    echo "Lege Verzeichnis $REPORT/host an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/host && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte host-Abfrage auf $TARGET ..."
        host $TARGET |tee $REPORT/host/host-host-$TARGET.txt && echo "Host-Abfrage auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl host konnte nicht gefunden werden."
    echo "Bitte installieren Sie host, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

pingsuchlaufcmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/ping an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/ping && echo "Verzeichnis erfolgreich angelegt."
    echo "Starte Ping-Suchlauf fuer $REPORT ..."
    nmap -sP $TARGETS -vv |tee $REPORT/ping/pingsuchlauf.txt && echo "Ping-Suchlauf auf $REPORT erfolgreich."
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

broadcastping255cmd() {
echo "Suche nach ping ..."
if [ `which ping` ]
then
    echo "ping wurde gefunden."
    echo "Lege Verzeichnis $REPORT/ping an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/ping && echo "Verzeichnis erfolgreich angelegt."
    echo "Starte Broadcast-Ping fuer $REPORT ..."
    ping -b -c 3 255.255.255.255 |tee $REPORT/ping/broadcastping-255.255.255.255.txt && echo "Broadcast-Ping auf $REPORT erfolgreich."
else
    echo "Der Befehl ping konnte nicht gefunden werden."
    echo "Bitte installieren Sie ping, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

broadcastping0cmd() {
echo "Suche nach ping ..."
if [ `which ping` ]
then
    echo "ping wurde gefunden."
    echo "Lege Verzeichnis $REPORT/ping an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/ping && echo "Verzeichnis erfolgreich angelegt."
    echo "Starte Broadcast-Ping fuer $REPORT ..."
    ping -c 3 $REPORT |tee $REPORT/ping/broadcastping-$REPORT.txt && echo "Broadcast-Ping auf $REPORT erfolgreich."
else
    echo "Der Befehl ping konnte nicht gefunden werden."
    echo "Bitte installieren Sie ping, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

arpingcmd() {
echo "Suche nach arping ..."
if [ `which arping` ]
then
    echo "arping wurde gefunden."
    echo "Lege Verzeichnis $REPORT/arping an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/arping && echo "Verzeichnis erfolgreich angelegt."
    PACKETS=5
    for TARGET in $TARGETS
    do
	echo "Starte ARP-Ping auf $TARGET ..."
    arping -c $PACKETS $TARGET |tee $REPORT/arping/arping-$TARGET.txt && echo "ARP-Ping auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl arping konnte nicht gefunden werden."
    echo "Bitte installieren Sie arping, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

pingcmd() {
echo "Suche nach ping ..."
if [ `which ping` ]
then
    echo "ping wurde gefunden."
    echo "Lege Verzeichnis $REPORT/ping an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/ping && echo "Verzeichnis erfolgreich angelegt."
    PACKETS=5
    for TARGET in $TARGETS
    do
	echo "Starte Ping auf $TARGET ..."
    ping -c $PACKETS $TARGET |tee $REPORT/ping/ping-$TARGET.txt && echo "Ping auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl ping konnte nicht gefunden werden."
    echo "Bitte installieren Sie ping, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

icmpaddressmaskcmd() {
echo "Suche nach hping3 ..."
if [ `which hping3` ]
then
    echo "hping3 wurde gefunden."
    hping3 -v | tee $REPORT/hping3-version.txt

    echo "Lege Verzeichnis $REPORT/icmpaddressmask an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/icmpaddressmask && echo "Verzeichnis erfolgreich angelegt."
    PACKETS=3
    for TARGET in $TARGETS
    do
	echo "Starte ICMP address mask request auf $TARGET ..."
    hping3 -c $PACKETS --icmp-addr $TARGET |tee $REPORT/icmpaddressmask/icmpaddressmask-$TARGET.txt && echo "ICMP address mask request auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl hping3 konnte nicht gefunden werden."
    echo "Bitte installieren Sie hping3, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

udptraceroutecmd() {
echo "Suche nach traceroute ..."
if [ `which traceroute` ]
then
    echo "traceroute wurde gefunden."
    traceroute | tee $REPORT/traceroute-version.txt

    echo "Lege Verzeichnis $REPORT/traceroute an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/traceroute && echo "Verzeichnis erfolgreich angelegt."
    UDPPORT=53
    for TARGET in $TARGETS
    do
	echo "Starte Traceroute mittels UDP$UDPPORT auf $TARGET ..."
	traceroute -w 2 -m 20 -p $UDPPORT -v $TARGET |tee $REPORT/traceroute/traceroute-udp$UDPPORT-$TARGET.txt && echo "Traceroute auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl traceroute konnte nicht gefunden werden."
    echo "Bitte installieren Sie traceroute, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

icmptraceroutecmd() {
echo "Suche nach traceroute ..."
if [ `which traceroute` ]
then
    echo "traceroute wurde gefunden."
    traceroute | tee $REPORT/traceroute-version.txt

    echo "Lege Verzeichnis $REPORT/traceroute an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/traceroute && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Traceroute mittels ICMP auf $TARGET ..."
        traceroute -I -w 2 -m 20 -v $TARGET |tee $REPORT/traceroute/traceroute-icmp-$TARGET.txt && echo "Traceroute auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl traceroute konnte nicht gefunden werden."
    echo "Bitte installieren Sie traceroute, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

tcptraceroutecmd() {
echo "Suche nach tcptraceroute ..."
if [ `which tcptraceroute` ]
then
    echo "tcptraceroute wurde gefunden."
    tcptraceroute | tee $REPORT/tcptraceroute-version.txt

    echo "Lege Verzeichnis $REPORT/traceroute an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/traceroute && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Traceroute mittels TCP auf $TARGET ..."
        tcptraceroute -w 2 -m 20 $TARGET |tee $REPORT/traceroute/traceroute-tcp-$TARGET.txt && echo "Traceroute auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl tcptraceroute konnte nicht gefunden werden."
    echo "Bitte installieren Sie tcptraceroute, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

tcpportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte TCP-Portscan auf $TARGET ..."
        nmap -sT -sR -P0 -O -sV -v $TARGET|tee $REPORT/portscans/tcp-portscan-$TARGET.txt && echo "TCP-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

halfopenportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte half-open Portscan auf $TARGET ..."
        nmap -sS -P0 -O -sV -oG $REPORT/portscans/halfopen-portscan-og-$TARGET.txt -v $TARGET |tee $REPORT/portscans/halfopen-portscan-$TARGET.txt && echo "Half-open Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

finportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte FIN-Portscan auf $TARGET ..."
        nmap -sF -P0 -O -sV -v $TARGET |tee $REPORT/portscans/fin-portscan-$TARGET.txt && echo "FIN-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

xmasportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Xmas-Portscan auf $TARGET ..."
        nmap -sX -P0 -O -sV -v $TARGET |tee $REPORT/portscans/xmas-portscan-$TARGET.txt && echo "Xmas-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

nullportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Null-Portscan auf $TARGET ..."
        nmap -sN -P0 -O -sV -v $TARGET |tee $REPORT/portscans/null-portscan-$TARGET.txt && echo "Null-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

ackportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte ACK-Portscan auf $TARGET ..."
        nmap -sA -P0 -O -sV -v $TARGET |tee $REPORT/portscans/ack-portscan-$TARGET.txt && echo "ACK-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

windowportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Window-Portscan auf $TARGET ..."
        nmap -sW -P0 -O -v $TARGET |tee $REPORT/portscans/window-portscan-$TARGET.txt && echo "Window-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

udpportscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/portscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/portscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte UDP-Portscan auf $TARGET ..."
        nmap -sU -P0 -O -sV -oG $REPORT/portscans/udp-portscan-og-$TARGET.txt -v $TARGET |tee $REPORT/portscans/udp-portscan-$TARGET.txt && echo "UDP-Portscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

icmposfingerprintingcmd() {
echo "Suche nach xprobe2 ..."
if [ `which xprobe2` ]
then
    echo "xprobe2 wurde gefunden."
    xprobe2 | tee $REPORT/xprobe2-version.txt

    echo "Lege Verzeichnis $REPORT/xprobe2 an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/xprobe2 && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte ICMP OS Fingerprinting auf $TARGET ..."
        xprobe2 $TARGET |tee $REPORT/xprobe2/xprobe2-$TARGET.txt && echo "ICMP OS Fingerprinting auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl xprobe2 konnte nicht gefunden werden."
    echo "Bitte installieren Sie xprobe2, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

protocolscancmd() {
echo "Suche nach nmap ..."
if [ `which nmap` ]
then
    echo "nmap wurde gefunden."
    nmap | tee $REPORT/nmap-version.txt

    echo "Lege Verzeichnis $REPORT/protocolscans an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/protocolscans && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Protocolscan auf $TARGET ..."
        nmap -sO -v $TARGET |tee $REPORT/protocolscans/protocolscan-$TARGET.txt && echo "Protocolscan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nmap konnte nicht gefunden werden."
    echo "Bitte installieren Sie nmap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

netbiossharescmd() {
echo "Suche nach smbclient ..."
if [ `which smbclient` ]
then
    echo "smbclient wurde gefunden."
    smbclient | tee $REPORT/smbclient-version.txt

    echo "Lege Verzeichnis $REPORT/netbios an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/netbios && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte NetBIOS-Abfrage auf $TARGET ..."
        smbclient -N -L $TARGET |tee $REPORT/netbios/netbios-$TARGET.txt && echo "smbclient auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl smbclient konnte nicht gefunden werden."
    echo "Bitte installieren Sie smbclient, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

snmpstatuscmd() {
echo "Suche nach snmpstatus ..."
if [ `which snmpstatus` ]
then
    echo "snmpstatus wurde gefunden."
    snmpstatus |tee $REPORT/snmpstatus-version.txt

    echo "Lege Verzeichnis $REPORT/snmp an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/snmp && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
        for COMMUNITY in public private cisco
	do
	    echo "Starte SNMP-Abfrage auf $COMMUNITY@$TARGET ..."
    	    snmpstatus -c $COMMUNITY -v 1 $TARGET |tee $REPORT/snmp/snmp-status-$COMMUNITY-$TARGET.txt && echo "Snmpstatus auf $TARGET erfolgreich."
	done
    done
else
    echo "Der Befehl snmpstatus konnte nicht gefunden werden."
    echo "Bitte installieren Sie snmpstatus, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

snmpwalkcmd() {
echo "Suche nach snmpwalk ..."
if [ `which snmpwalk` ]
then
    echo "snmpwalk wurde gefunden."
    snmpwalk |tee $REPORT/snmpwalk-version.txt

    echo "Lege Verzeichnis $REPORT/snmp an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/snmp && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
        for COMMUNITY in public private cisco
	do
	    echo "Starte snmpwalk auf $COMMUNITY@$TARGET ..."
    	    snmpwalk -c $COMMUNITY -v 1 $TARGET |tee $REPORT/snmp/snmp-walk-$COMMUNITY-$TARGET.txt && echo "Snmpstatus auf $TARGET erfolgreich."
	done
    done
else
    echo "Der Befehl snmpwalk konnte nicht gefunden werden."
    echo "Bitte installieren Sie snmpwalk, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

nfssharescmd() {
echo "Suche nach showmount ..."
if [ `which showmount` ]
then
    echo "showmount wurde gefunden."
    showmount -v | tee $REPORT/showmount-version.txt

    echo "Lege Verzeichnis $REPORT/nfs an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/nfs && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte NFS-Abfrage auf $TARGET ..."
        showmount --all $TARGET |tee $REPORT/nfs/nfs-$TARGET.txt && echo "Showmount auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl showmount konnte nicht gefunden werden."
    echo "Bitte installieren Sie showmount, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

rpcinfocmd() {
echo "Suche nach rpcinfo ..."
if [ `which rpcinfo` ]
then
    echo "rpcinfo wurde gefunden."
    echo "Lege Verzeichnis $REPORT/rpcinfo an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/rpcinfo && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte RPCinfo auf $TARGET ..."
        rpcinfo -p $TARGET |tee $REPORT/rpcinfo/rpcinfo-$TARGET.txt && echo "RPCinfo auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl rpcinfo konnte nicht gefunden werden."
    echo "Bitte installieren Sie rpcinfo, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

fingercmd() {
echo "Suche nach finger ..."
if [ `which finger` ]
then
    echo "finger wurde gefunden."
    echo "Lege Verzeichnis $REPORT/finger an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/finger && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte finger auf $TARGET ..."
        for USER in root adm admin administrator test guest
	do
	    echo "Fingere Benutzer $USER des Systems $TARGET ..."
	    finger -s $USER@$TARGET |tee $REPORT/finger/finger-$USER-$TARGET.txt && echo "Benutzer gefingert."
	done
    done
else
    echo "Der Befehl finger konnte nicht gefunden werden."
    echo "Bitte installieren Sie raccess, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

bannergrabbingcmd() {
echo "Suche nach nc (NetCat) ..."
if [ `which nc` ]
then
    echo "nc wurde gefunden."
    nc -h | tee $REPORT/netcat-version.txt

    echo "Lege Verzeichnis $REPORT/banners an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/banners && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Versuche die offenen TCP-Ports von $TARGET zu erkennen ..."
	if [ -s $REPORT/portscans/tcp-portscan-$TARGET.txt ]
	then
	    OPENTCPPORT=`cat $REPORT/portscans/tcp-portscan-$TARGET.txt |grep "Discovered open port " |awk 'BEGIN{FS=" "}{print $4}' |awk 'BEGIN{FS="/"}{print $1}'` && echo "Offene TCP-Ports erkannt: $OPENTCPPORT"
	    for TCPPORT in $OPENTCPPORT
	    do
		echo "Greife Banner von TCP-Port $TCPPORT des Hosts $TARGET ab ..."
		if [ $TCPPORT -eq 19  ]
		then
		    echo "Banner von TCP-Port $TCPPORT (chargen) wird nicht abgegriffen, weil DoS-Gefahr." |tee $REPORT/banners/banner-grabbing-$TARGET-tcp$TCPPORT.txt
		elif [ $TCPPORT -eq 21 -o $TCPPORT -eq 110 ]
		then
	    	    echo -e "QUIT\n" |nc -vv -w 5 $TARGET $TCPPORT |tee $REPORT/banners/banner-grabbing-$TARGET-tcp$TCPPORT.txt
		elif [ $TCPPORT -eq 25 ]
		then
	    	    echo -e "help\nquit\n" |nc -vv -w 5 $TARGET $TCPPORT |tee $REPORT/banners/banner-grabbing-$TARGET-tcp$TCPPORT.txt
		elif [ $TCPPORT -eq 80 -o $TCPPORT -eq 443 -o $TCPPORT -eq 800 -o $TCPPORT -eq 8000 -o $TCPPORT -eq 8080 ]
		then
		    echo -e "HEAD / HTTP/1.0\n\n" |nc -vv -w 5 $TARGET $TCPPORT |tee $REPORT/banners/banner-grabbing-$TARGET-tcp$TCPPORT.txt
		else
	    	    echo -e "test\ntest\n" |nc -vv -i 3 -w 5 $TARGET $TCPPORT |tee $REPORT/banners/banner-grabbing-$TARGET-tcp$TCPPORT.txt
		fi
		# Ueberpruefung und Ausgabe, ob das Banner-Grabbing erfolgreich war
		if [ -s $REPORT/banners/banner-grabbing-$TARGET-tcp$TCPPORT.txt ]
		then
	    	    echo "Banner von TCP-Port $TCPPORT erfolgreich abgegriffen."
		else
		    echo "Es konnte keine anstaendige Banner-Ausgabe von TCP-Port $TCPPORT provoziert werden."
		fi
	    done
	else
	    echo "Offene TCP-Ports des Systems $TARGET konnten nicht ermittelt werden."
	    echo "Starten Sie zuerst einen TCP-Portscan auf das Ziel."
	    echo "Wollen Sie einen solchen jetzt durchfuehren? (j/n)"
	    read -e PORTSCANQ
	    if [ j == $PORTSCANQ ]
	    then
	        tcpportscancmd && bannergrabbingcmd && break
	    else
	        abbruchcmd
	    fi
	fi
    done
else
    echo "Der Befehl nc (NetCat) konnte nicht gefunden werden."
    echo "Bitte installieren Sie nc (NetCat), bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

tcpapplicationmappingcmd() {
echo "Suche nach amap ..."
if [ `which amap` ]
then
    echo "amap wurde gefunden."
    amap | tee $REPORT/amap-version.txt

    echo "Lege Verzeichnis $REPORT/amap an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/amap && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte TCP Application Mapping auf $TARGET ..."
        amap -b -i $REPORT/portscans/halfopen-portscan-og-$TARGET.txt |tee $REPORT/amap/amap-tcp-$TARGET.txt && echo "TCP Application Mapping auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl amap konnte nicht gefunden werden."
    echo "Bitte installieren Sie amap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

udpapplicationmappingcmd() {
echo "Suche nach amap ..."
if [ `which amap` ]
then
    echo "amap wurde gefunden."
    amap | tee $REPORT/amap-version.txt

    echo "Lege Verzeichnis $REPORT/amap an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/amap && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte UDP Application Mapping auf $TARGET ..."
        amap -u -b -i $REPORT/portscans/udp-portscan-og-$TARGET.txt |tee $REPORT/amap/amap-udp-$TARGET.txt && echo "UDP Application Mapping auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl amap konnte nicht gefunden werden."
    echo "Bitte installieren Sie amap, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

webserverscancmd() {
echo "Suche nach nikto ..."
if [ `which nikto` ]
then
    echo "nikto wurde gefunden."
    nikto | tee $REPORT/nikto-version.txt

    echo "Lege Verzeichnis $REPORT/nikto an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/nikto && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte Webserver-Scan auf $TARGET ..."
        nikto -h $TARGET |tee $REPORT/nikto/nikto-$TARGET.txt && echo "Webserver-Scan auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl nikto konnte nicht gefunden werden."
    echo "Bitte installieren Sie nikto, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

raccesscmd() {
echo "Suche nach raccess ..."
if [ `which raccess` ]
then
    echo "raccess wurde gefunden."
    raccess | tee $REPORT/raccess-version.txt

    echo "Lege Verzeichnis $REPORT/raccess an, um die Ausgaben zu speichern ..."
    mkdir $REPORT/raccess && echo "Verzeichnis erfolgreich angelegt."
    for TARGET in $TARGETS
    do
	echo "Starte raccess auf $TARGET ..."
        raccess -o $TARGET |tee $REPORT/raccess/raccess-check-$TARGET.txt && echo "Raccess auf $TARGET erfolgreich."
    done
else
    echo "Der Befehl raccess konnte nicht gefunden werden."
    echo "Bitte installieren Sie raccess, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

nessuscmd() {
NESSUSHOST='127.0.0.1'
NESSUSPORT='1241'
NESSUSUSER='maru'
NESSUSPASS='53241'

echo "Suche nach pstree ..."
if [ `which pstree` ]
then
    echo "Suche mittels pstree nach einem laufenden Nessus Daemon ..."
    if [ !`pstree | grep nessusd` ]
    then
        echo "Es konnte kein laufender Nessus Daemon (nessusd) gefunden werden."
	echo "Der Nessus Daemon wird nun im Hintergrund gestartet ..."
	nessusd -D
    fi
    
    if [ `which nessus` ]
    then
    	nessus -v | tee $REPORT/nessus-version.txt
    	nessusd -v | tee $REPORT/nessusd-version.txt

        echo "Nessus und die erforderlichen komponenten wurden gefunden."
	echo "Lege Verzeichnis $REPORT/nessus an, um die Ausgaben zu speichern ..."
	mkdir $REPORT/nessus && echo "Verzeichnis erfolgreich angelegt."
        
	echo "Speichere die geladenen Nessus Plugins in die Datei $REPORT/nessus/nessus-plugins.txt ..."
	date > $REPORT/nessus/nessus-plugins.txt
	nessus -q -p $NESSUSHOST $NESSUSPORT $NESSUSUSER $NESSUSPASS >> $REPORT/nessus/nessus-plugins.txt
	echo "Die geladenen Nessus Plugins wurden erfolgreich in $REPORT/nessus/nessus-plugins.txt gespeichert."
	
	for TARGET in $TARGETS
	do
	    echo "$TARGET" > $REPORT/nessus/nessustarget-$TARGET.txt
            echo "Nessus Scan auf $TARGET wird durchgefuehrt ..."
	    nessus -q -T html_graph -V $NESSUSHOST $NESSUSPORT $NESSUSUSER $NESSUSPASS $REPORT/nessus/nessustarget-$TARGET.txt $REPORT/nessus/$TARGET
            echo "Nessus Scan auf $TARGET ist erfolgreich beendet."
	done

        echo "Bitte beenden Sie den Nessus Daemon (nessusd) auf ihrem System manuell!"
    else
        echo "Der BefehlnNessus konnte nicht gefunden werden."
	echo "Bitte installieren Sie nessus, bevor Sie diese Funktion nutzen."
	abbruchcmd
    fi
else
    echo "Der Befehl pstree konnte nicht gefunden werden."
    echo "Bitte installieren Sie pstree, bevor Sie diese Funktion nutzen."
    abbruchcmd
fi
}

##
## Ende der eigentlichen Checks
##

# Parametereingabe ueberpruefen und die entsprechenden Checks starten
case $@ in *"-wh "*|*"--whois "*|*--al*|*-sc*)
    whoiscmd |tee -a $REPORT/logfile.txt
esac

case $@ in *-ho*|*-ns*|*-dig*|*--al*|*-sc*)
    hostcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-ps "*|*"--pingsuchlauf "*|*"--pingsweep "*|*"-sP "*|*--al*|*-sc*)
    pingsuchlaufcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-pe "*|*"--broadcastping255 "*|*"--smurfping255 "*|*"-sP "*|*-al*|*-sc*)
    broadcastping255cmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-p0 "*|*"--broadcastping0 "*|*"--smurfping0 "*|*"-sP "*|*-al*|*-sc*)
    broadcastping0cmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-pr "*|*"--arp"*|*"-PR "*|*-al*|*-sc*)
    arpingcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-pn "*|*"--ping "*|*--icmpechorequest*|*"-sP "*|*-al*|*-sc*)
    pingcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-pa "*|*--icmpaddress*|*--addressmask*|*--icmp-ad*|*-al*|*-sc*)
    icmpaddressmaskcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-tu "*|*--udptrace*|*"-p "*|*-al*|*-sc*)
    udptraceroutecmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-ti "*|*--icmptrace*|*"-I "*|*-al*|*-sc*)
    icmptraceroutecmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-tt "*|*--tcptrace*|*-al*|*-sc*)
    tcptraceroutecmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-st "*|*--tcpport*|*"-sT "*|*-al*)
    tcpportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-ss "*|*"-sh "*|*--halfopen*|*--stealthportscan*|*"-sS "*|*-al*|*-sc*)
    halfopenportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-sf "*|*--finport*|*-"sF "*|*-al*)
    finportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-sx "*|*--xmasport*|*"-sX "*|*-al*)
    xmasportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-sn "*|*--nullport*|*"-sN "*|*-al*)
    nullportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-sa "*|*--ackport*|*"-sA "*|*-al*)
    ackportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-sw "*|*--windowport*|*"-sW "*|*-al*)
    windowportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-su "*|*--udpport*|*"-sU "*|*-al*|*-sc*)
    udpportscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-si "*|*--icmpos*|*"-sO "*|*-al*|*-sc*)
    icmposfingerprintingcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-sp "*|*--protocolscan*|*"-sO "*|*-al*|*-sc*)
    protocolscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-ms "*|*"--snmps"*|*-sc*|*-al*)
    snmpstatuscmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-mw "*|*"--snmpw"*|*-sc*|*-al*)
    snmpwalkcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-nb "*|*--netbios*|*"--smb"*|*-al*|*-sc*)
    netbiossharescmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-nf "*|*"--nfs "*|*"--showmount "*|*-al*)
    nfssharescmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-rp "*|*--rpcinfo*|*"-sr "*|*"-sR "*|*-al*)
    rpcinfocmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-fi "*|*--finger*|*--lesbi*|*-al*)
    fingercmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-ba "*|*--ban*|*-al*)
    bannergrabbingcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *-am*|*-at*|*-al*|*-sc*)
    tcpapplicationmappingcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *-am*|*-au*|*-al*|*-sc*)
    udpapplicationmappingcmd |tee -a $REPORT/logfile.txt
esac

case $@ in *-ws*|*-hs*|*--web*|*-al*|*-sc*)
    webserverscancmd |tee -a $REPORT/logfile.txt
esac

case $@ in *"-ra "*|*--raccess*)
    raccesscmd |tee -a $REPORT/logfile.txt
esac

case $@ in *-ne*)
    nessuscmd |tee -a $REPORT/logfile.txt
esac

echo "Catwalk auf die Systeme $TARGETS innerhalb $SECONDS Sekunden beendet."
echo -e "Der Report und das Logfile wurden in $PWD/$REPORT geschrieben.\n"
setterm -default