Class: SSHScan::Client
- Inherits:
-
Object
- Object
- SSHScan::Client
- Defined in:
- lib/ssh_scan/client.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #get_kex_result(kex_init_raw = @kex_init_raw) ⇒ Object
-
#initialize(target, port) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(target, port) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ssh_scan/client.rb', line 7 def initialize(target, port) @target = target if @target.ip_addr? @ip = @target else @ip = @target.resolve_fqdn() end @port = port @client_protocol = SSHScan::Constants::DEFAULT_CLIENT_PROTOCOL @server_protocol = nil @kex_init_raw = SSHScan::Constants::DEFAULT_KEY_INIT_RAW end |
Instance Method Details
#connect ⇒ Object
22 23 24 25 26 |
# File 'lib/ssh_scan/client.rb', line 22 def connect() @sock = TCPSocket.new(@ip, @port) @server_protocol = @sock.gets.chomp @sock.puts(@client_protocol) end |
#get_kex_result(kex_init_raw = @kex_init_raw) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ssh_scan/client.rb', line 28 def get_kex_result(kex_init_raw = @kex_init_raw) @sock.write(kex_init_raw) resp = @sock.read(4) resp += @sock.read(resp.unpack("N").first) @sock.close kex_exchange_init = SSHScan::KeyExchangeInit.read(resp) # Assemble and print results result = {} result[:ssh_scan_version] = SSHScan::VERSION result[:hostname] = @target.fqdn? ? @target : "" result[:ip] = @ip result[:port] = @port result[:server_banner] = @server_protocol result.merge!(kex_exchange_init.to_hash) return result end |