Skip to content

Instantly share code, notes, and snippets.

@jwilkins
Created April 17, 2013 19:42
Show Gist options
  • Save jwilkins/5407143 to your computer and use it in GitHub Desktop.
Save jwilkins/5407143 to your computer and use it in GitHub Desktop.
scan for ssh supported auth methods (track down any hosts that still support passwords instead of keys)
require 'net/ssh'
require 'debugger'
require 'net/ssh/transport/session'
require 'net/ssh/authentication/methods/password'
require 'net/ssh/authentication/session'
options = {
:user => 'root',
:config => nil,
:password => 'incorrect_password',
:auth_methods => ['password']
}
def conn(host, options)
begin
transport = Net::SSH::Transport::Session.new(host, options)
auth = Net::SSH::Authentication::Session.new(transport, options)
auth.authenticate("ssh-connection", options[:user], options[:password])
puts "CHECKED,#{auth.transport.host}:#{auth.transport.port},#{auth.allowed_auth_methods.join('|')}," \
"(#{auth.transport.server_version.version})"
#puts "#{host} allows password auth" if auth.allowed_auth_methods.include?("password")
rescue SocketError => e
puts "ERROR,#{host},#{e}"
rescue => e
end
end
hosts = [] << ARGV
hosts.flatten!
hosts.each { |host|
conn(host, options)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment