Here we'll show some SSH using ruby. We'll need to install net-ssh gem for that.
Install net-ssh gem
gem install net-ssh
Simple SSH command execution
This is a very basic SSH client which sends and executes commands on a remote system
#!/usr/bin/env ruby# KING SABRI | @KINGSABRIrequire'net/ssh'@hostname ="localhost"@username ="root"@password ="password"@cmd =ARGV[0]begin ssh =Net::SSH.start(@hostname, @username, :password => @password) res = ssh.exec!(@cmd) ssh.closeputs resrescueputs"Unable to connect to #{@hostname} using #{@username}/#{@password}"end
SSH Client with PTY shell
Here a simple SSH client which give you an interactive PTY
#!/usr/bin/env ruby# KING SABRI | @KINGSABRIrequire'net/ssh'@hostname ="localhost"@username ="root"@password ="password"Net::SSH.start(@hostname, @username, :password => @password, :auth_methods => ["password"]) do|session|# Open SSH channel session.open_channel do|channel|# Requests that a pseudo-tty (or "pty") for interactive application-like (e.g vim, sudo, etc) channel.request_pty do|ch, success|raise"Error requesting pty"unless success# Request channel type shell ch.send_channel_request("shell") do|ch, success|raise"Error opening shell"unless successSTDOUT.puts"[+] Getting Remote Shell\n\n"if successendend# Print STDERR of the remote host to my STDOUT channel.on_extended_data do|ch, type, data|STDOUT.puts"Error: #{data}\n"end# When data packets are received by the channel channel.on_data do|ch, data|STDOUT.print data cmd =gets channel.send_data( "#{cmd}" )trap("INT") {STDOUT.puts"Use 'exit' or 'logout' command to exit the session"}end channel.on_eof do|ch|puts"Exiting SSH Session.."end session.loopendend
Now SSH from the SSH Server to localhost on the localhost's SSH port then connect from your localhost to your localhost on port 3333 via your RDP client, you'll be prompt for the WebServer's RDP log-in screen