Created
August 25, 2016 10:05
-
-
Save llandeilocymro/99e5e695d9f835dd906369b4b3cd69ae to your computer and use it in GitHub Desktop.
Threaded py script to quickly identify hosts with weak tomcat credetials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# EDW - looks for default tomcat and ssh creds. | |
import logging | |
import paramiko | |
import os, sys | |
import optparse | |
import threading | |
from socket import * | |
try: | |
import requests | |
except: | |
logging.fatal("Please install requests: python - m pip install requests") | |
p = optparse.OptionParser("usage: %prog port username password range type", version="%prog 0.2") | |
p.add_option("-p", "--port", dest="port", type="int", default=8080, help="port number, default is 8080") | |
p.add_option("-u", "--user", dest="user", type="str", default="admin", help="username, default is admin") | |
p.add_option("-P", "--password", dest="password", type="str", default="admin", help="password, default is admin") | |
p.add_option("-r", "--range", dest="net_range", type="str", help="class c range to scan") | |
p.add_option("-t", "--type", dest="type", type="str", help="type of test, options are ssh and tomcat") | |
(options, args) = p.parse_args() | |
port = options.port | |
user = options.user | |
password = options.password | |
net_range = options.net_range | |
function_call = options.type | |
def tomcat(ipadd): | |
url = 'http://'+ip+':'+str(port)+'/host-manager/html' | |
try: | |
r = requests.get(url, auth=(user, password)) | |
if r.status_code == 200: | |
print url, r.status_code, user, password | |
else: | |
print url, r.status_code | |
except requests.exceptions.ConnectionError as e: | |
pass | |
def ssh(ipadd): | |
sk = socket (AF_INET, SOCK_STREAM) | |
res = sk.connect_ex ((ip, port)) | |
if (res == 0): | |
print "%s open on %s" % (str(port),str(ip)) | |
sk.close() | |
try: | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect(ip,username=user,password=password,port=port) | |
ssh.close() | |
except paramiko.BadAuthenticationType, e: | |
print e | |
sys.exit(1) | |
except paramiko.SSHException,e: | |
pass | |
else: | |
print '%s:%s:%s' % (user, password, str(ip)) | |
ssh.close() | |
s = net_range.split(".") | |
if options.type == "ssh": | |
for x in range(0, 255): | |
ip = "%s.%s.%s.%d" % (s[0],s[1],s[2],x) | |
try: | |
t = threading.Thread(target=ssh, args=(ip, )) | |
t.start() | |
except: | |
print ip+" threading error" | |
else: | |
s = net_range.split(".") | |
for x in range(0, 255): | |
ip = "%s.%s.%s.%d" % (s[0],s[1],s[2],x) | |
try: | |
t = threading.Thread(target=tomcat, args=(ip, )) | |
t.start() | |
except: | |
print ip+" threading error" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment