Here's an old script I had used to randomize weak passwords. I
haven't tried it for years, but I hope it helps:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
usernames = ["username"]
passwords = ["password"]
hostnames = ["hostname"]
# For example:
# usernames = [ 'alice', 'bob', 'charlie' ]
# usernames = %qw{ alice bob charlie }
# passwords = [ 'password', 'baseball', 'apple', '123456' ]
# hostnames = [ 'alpha', 'beta' ]
srand
hostnames.each do |hostname|
puts hostname
usernames.each do |username|
puts "\t#{username}"
passwords.each do |password|
puts "\t\t#{password}"
begin
Net::SSH.start( hostname, username, password ) do |session|
puts "\t\t\tBAD"
command = "passwd"
newword = ""
(rand(32) + 32).times do
newword << (rand(95) + 32).chr
end
session.process.open( command ) do |shell|
shell.on_success do |p|
puts "process started"
end
shell.on_failure do |p|
puts "process failed to start"
end
shell.on_stderr do |p,data|
puts "E-> #{data}"
case data
when /\(current\) UNIX password:/
p.puts password
puts "********"
when /New UNIX password:/
p.puts newword
puts "********"
when /Retype new UNIX password:/
p.puts newword
puts "********"
else
puts "DEATH!"
exit
end
end
shell.on_stdout do |p,data|
puts "O-> #{data}"
end
shell.on_exit do |p, status|
puts "process finished with exit status: #{status}"
end
end
end
rescue
puts "\t\t\tok"
end
end
end
end
···
On Thu, May 20, 2010 at 9:28 AM, Tyler Smart <tyleresmart@gmail.com> wrote:
I am looking to execute a password change over Net-ssh...
I know the connection works because using a simple exec I can get the
output from ls on the remote server, but this hangs.
Any ideas?