Hii all ,
Am using Net/TELNET to connect to remote host trying to run su
command in order to get root privilage this is how i doing
require ‘net/telnet’
localhost = Net::Telnet::new(“Host” => “192.147.217.27”,
“Timeout” => 50,
“Prompt” => /[$%#>] \z/n)
localhost.login(“dvsdkrp”, “dvsdkvrp”) { |c| print c }
localhost.cmd(“cd /home/dvsdkrp/workdir/smruti”) { |c| print c }
localhost.cmd(“su”) { |c| print c }
localhost.puts(“passwd”){ |c| print c }
But am getting this error
Password: C:/Ruby/lib/ruby/1.8/net/telnet.rb:552:in waitfor': timed out while waiting for more data (Timeout::Error) from C:/Ruby/lib/ruby/1.8/net/telnet.rb:679:incmd’
from tel.rb:7
localhost.cmd(“cd /home/dvsdkrp/workdir/smruti”) { |c| print c }
What should i do??
I want to think that the problem here is that the su program expects to
have a terminal so that it can disable echoing what you type for your
password and then directly read that password. Driving a telnet session
like this does not emulate a terminal and could cause problems for su.
I would expect su to error out rather than cause a timeout though.
Are you able to configure sudo on that host? If so you can configure it
to allow your account to run the desired command(s) without a password
and then invoke sudo instead of su.
Are you able to configure sudo on that host? If so you can configure it
}
localhost.cmd(“passwd”)
Now its working fine
Actually, your solution of looking for su’s prompt and then sending the
password as a “command” proves that my assertion was mostly incorrect,
but I’m glad you found what you were looking for.
localhost.cmd(“cd /home/dvsdkrp/workdir/smruti”) { |c| print c }
What should i do??
I want to think that the problem here is that the su program expects to
have a terminal so that it can disable echoing what you type for your
password and then directly read that password. Driving a telnet session
like this does not emulate a terminal and could cause problems for su.
I would expect su to error out rather than cause a timeout though.
Are you able to configure sudo on that host? If so you can configure it
to allow your account to run the desired command(s) without a password
and then invoke sudo instead of su.
-Jeremy
Hi Jeremy
You are right this is how i solved it
su_prompt = "Password: "
localhost.cmd(“String” => “su”, “Match” => /#{su_prompt}/) { |c| print
}
localhost.cmd(“passwd”)
Now its working fine
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.