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
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?
Here’s an old script I had used to randomize weak passwords. I
haven’t tried it for years, but I hope it helps:
I had some time and took a look at it. Net-SSH 2 no longer has the
API I had used in that old script, here is a rough update that appears
to work with NetSSH 2:
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 => password ) do
|session|
puts “\t\t\tBAD”
command = “passwd”
newword = “”
(rand(32) + 32).times do
newword << (rand(95) + 32).chr
end
session.exec( command ) do |channel,stream,data|
case stream
when :stderr
puts "E-> #{data}"
case data
when /\(current\) UNIX password:/
channel.send_data password + "\n"
puts "********"
when /New UNIX password:/
channel.send_data newword + "\n"
puts "********"
when /Retype new UNIX password:/
channel.send_data newword + "\n"
puts "********"
else
puts "DEATH!"
exit
end
when :stdout
puts "O-> #{data}"
end
end
end
rescue
puts "\t\t\tok (#{$!.message})"
end
end
hostnames.each do |hostname|
puts “\t#{hostname}”
usernames.each do |username|
puts “\t#{username}”
passwords.each do |password|
puts “\t\t#{passWord(hostname,username, password)}” end end end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.