#!/usr/bin/env python

import argparse
from netaddr import *
import os

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)

# Nessus confiuration
parser.add_argument("--nusername",  default='admin',
                    help="Nessus user name (admin)")
parser.add_argument("--npassword",  default='',
                    help="Nessus password", required=True)
parser.add_argument("--nhost",  default='localhost',
                    help="Nessus host (localhost)")

# OpenVAS configuration
parser.add_argument("--ovusername",  default='admin',
                    help="OpenVAS user name (admin)")
parser.add_argument("--ovpassword",  default='',
                    help="OpenVAS password", required=True)
parser.add_argument("--ovhost",  default='localhost',
                    help="OpenVAS host (localhost)", )

#Client & Target information
parser.add_argument("--client",  default='',
                    help="Client name", required=True)
parser.add_argument("--target",  default='',
                    help="target to scan (hostname, ip address, ip range (CIDR)", required=True)

parser.description = """
Used to run multiple bash & python scripts to facilitate penetration testing by
removing the tedious parts like:
- Running Nessus
- Running OpenVAS
- Running Nikto (only on 80,443)
- Running SSL scanners (only on 443)
- Running Nmap (ports 0-65535)
- etc.

The results of the scans are put in the Raw-folder, created below the current
directory. Move this directory to your documentation directory when done.

Examples:
runall.py --nusername admin --npassword pass --nhost localhost --ovusername ovadmin --ovpassword pass --ovhost localhost --client clientname --target 192.168.1.0/24
runall.py --nusername admin --npassword pass --nhost localhost --ovusername ovadmin --ovpassword pass --ovhost localhost --client clientname --target 192.168.1.1
runall.py --nusername admin --npassword pass --nhost localhost --ovusername ovadmin --ovpassword pass --ovhost localhost --client clientname --target www.example.com

"""

args = parser.parse_args()

runNmap = "./nmap_scantarget.sh --client %s --target %s " % (args.client, args.target)
runNessus = "./nessus_scantarget.py --username %s --password %s --host %s --client %s --target %s" % (args.nusername, args.npassword, args.nhost, args.client, args.target)
runOpenVAS = "./openvas_scantarget.sh --username %s --password %s --host %s --client %s --target %s --scantype Northwave --format txt" % (args.ovusername, args.ovpassword, args.ovhost, args.client, args.target)

runNikto = "./nikto_scantarget.sh --client %s --target %s "
runSSL = "./ssl_scantarget.sh --client %s --target %s"
runCMSMap = "./cmsmap_scantarget.sh --client %s --target %s"
runWhois = "./whois_scantarget.sh --client %s --target %s" % (args.client, args.target)

# Run the scripts that can handle ranges and addresses

print("""

RunAll 0.1a

""")

print(runNmap)
os.system(runNmap)
print(runWhois)
os.system(runWhois)
# Now run the scripts that require single-addresses to work.

try:
    for ip in IPNetwork(args.target):
        niktorun = runNikto % (args.client, ip)
        sslrun = runSSL % (args.client, ip)
        print(niktorun)
        os.system(niktorun)
        print(sslrun)
        os.system(sslrun)
        print(runCMSMap)
        os.system(runCMSMap)
except AddrFormatError:
    niktorun = runNikto % (args.client, args.target)
    sslrun = runSSL % (args.client, args.target)
    print(niktorun)
    os.system(niktorun)
    print(sslrun)
    os.system(sslrun)
    print(runCMSMap)
    os.system(runCMSMap)


print(runNessus)
os.system(runNessus)
print(runOpenVAS)
os.system(runOpenVAS)
