Skip to content

Instantly share code, notes, and snippets.

@jgamblin
Created May 15, 2015 21:01
Show Gist options
  • Save jgamblin/108108a697eec66a81a7 to your computer and use it in GitHub Desktop.
Save jgamblin/108108a697eec66a81a7 to your computer and use it in GitHub Desktop.
Run nikto from an ssh host.
#!/usr/bin/env python
# Name: niktome.py
# Purpose: Run Nikto From My Cloud.
# By: Jerry Gamblin
# Date: 15.05.15
# Modified 15.05.15
# Rev Level 0.5
# -----------------------------------------------
import sys
import time
import select
import paramiko
sys.stderr = open('/dev/null')
sys.stderr = sys.__stderr__
#Define the colors I am going to use.
def color(text, color_code):
if sys.platform == "win32" and os.getenv("TERM") != "xterm":
return text
return '\x1b[%dm%s\x1b[0m' % (color_code, text)
def red(text):
return color(text, 31)
def blink(text):
return color(text, 5)
def green(text):
return color(text, 32)
def blue(text):
return color(text, 34)
#Overly Dramatic Warning
print (red('This is probably illegal. Don"t Be Stupid. Prison Sucks.\n'))
#Set Host and Username
host = ''
name = ''
#Count Some Stuff.
t2retry = 1
#Get Host To Nikto
host2scan= raw_input(blue("What website do you want to run Nikto against?: "))
# Try to connect to the host.
# Retry a few times if it fails.
while True:
print "Trying to connect to %s (%i/30)" % (host, t2retry)
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,22,name)
print "Connected to %s" % host
break
except paramiko.AuthenticationException:
print "Authentication failed when connecting to %s" % host
sys.exit(1)
except:
print "Could not SSH to %s, waiting for it to start" % host
t2retry += 1
time.sleep(2)
# If we could not connect within time limit
if t2retry== 30:
print "Could not connect to %s. Giving up" % host
sys.exit(1)
# Send the command (non-blocking)
stdin, stdout, stderr = ssh.exec_command("nikto -h " + host2scan)
# Wait for the command to terminate
while not stdout.channel.exit_status_ready():
# Only print data if there is data to read in the channel
if stdout.channel.recv_ready():
rl, wl, xl = select.select([stdout.channel], [], [], 0.0)
if len(rl) > 0:
# Print data from stdout
print stdout.channel.recv(1024),
#
# Disconnect from the host
#
print (red("Nikto done, closing SSH connection"))
ssh.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment