Class: Rex::Proto::Kerberos::Client
- Inherits:
-
Object
- Object
- Rex::Proto::Kerberos::Client
- Defined in:
- lib/rex/proto/kerberos/client.rb
Overview
This class is a representation of a kerberos client.
Instance Attribute Summary collapse
-
#connection ⇒ IO
The connection established through Rex sockets.
-
#context ⇒ Hash
The Msf context where the connection belongs to.
-
#host ⇒ String
The kerberos server host.
-
#port ⇒ Integer
The kerberos server port.
-
#protocol ⇒ String
The transport protocol used (tcp/udp).
-
#proxies ⇒ String?
The proxy directive to use for the socket.
-
#subscriber ⇒ Rex::Proto::Kerberos::KerberosSubscriber
Subscriber used for tracing Kerberos.
-
#timeout ⇒ Integer
The connect / read timeout.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the connection.
-
#connect ⇒ Rex::Socket::Tcp
Creates a connection through a Rex socket.
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#recv_response ⇒ <Rex::Proto::Kerberos::Model::KrbError, Rex::Proto::Kerberos::Model::KdcResponse>
Receives a kerberos response through the connection.
-
#send_recv(req) ⇒ <Rex::Proto::Kerberos::Model::KrbError, Rex::Proto::Kerberos::Model::KdcResponse>
Sends a kerberos request, and reads the response through the connection.
-
#send_request(req) ⇒ Integer
Sends a kerberos request through the connection.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
37 38 39 40 41 42 43 44 45 |
# File 'lib/rex/proto/kerberos/client.rb', line 37 def initialize(opts = {}) self.host = opts[:host] self.port = (opts[:port] || 88).to_i self.proxies = opts[:proxies] self.timeout = (opts[:timeout] || 10).to_i self.protocol = opts[:protocol] || 'tcp' self.context = opts[:context] || {} self.subscriber = opts[:subscriber] || KerberosSubscriber.new end |
Instance Attribute Details
#connection ⇒ IO
Returns The connection established through Rex sockets.
29 30 31 |
# File 'lib/rex/proto/kerberos/client.rb', line 29 def connection @connection end |
#context ⇒ Hash
Returns The Msf context where the connection belongs to.
32 33 34 |
# File 'lib/rex/proto/kerberos/client.rb', line 32 def context @context end |
#host ⇒ String
Returns The kerberos server host.
13 14 15 |
# File 'lib/rex/proto/kerberos/client.rb', line 13 def host @host end |
#port ⇒ Integer
Returns The kerberos server port.
16 17 18 |
# File 'lib/rex/proto/kerberos/client.rb', line 16 def port @port end |
#protocol ⇒ String
Returns The transport protocol used (tcp/udp).
26 27 28 |
# File 'lib/rex/proto/kerberos/client.rb', line 26 def protocol @protocol end |
#proxies ⇒ String?
Returns The proxy directive to use for the socket.
19 20 21 |
# File 'lib/rex/proto/kerberos/client.rb', line 19 def proxies @proxies end |
#subscriber ⇒ Rex::Proto::Kerberos::KerberosSubscriber
Returns Subscriber used for tracing Kerberos.
35 36 37 |
# File 'lib/rex/proto/kerberos/client.rb', line 35 def subscriber @subscriber end |
#timeout ⇒ Integer
Returns The connect / read timeout.
22 23 24 |
# File 'lib/rex/proto/kerberos/client.rb', line 22 def timeout @timeout end |
Instance Method Details
#close ⇒ Object
Closes the connection
67 68 69 70 71 72 73 74 |
# File 'lib/rex/proto/kerberos/client.rb', line 67 def close if connection connection.shutdown connection.close unless connection.closed? end self.connection = nil end |
#connect ⇒ Rex::Socket::Tcp
Creates a connection through a Rex socket
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rex/proto/kerberos/client.rb', line 51 def connect return connection if connection raise ArgumentError, 'Missing remote address' unless self.host && self.port case protocol when 'tcp' self.connection = create_tcp_connection when 'udp' raise ::NotImplementedError, 'Kerberos Client: UDP not supported' else raise ::RuntimeError, 'Kerberos Client: unknown transport protocol' end connection end |
#recv_response ⇒ <Rex::Proto::Kerberos::Model::KrbError, Rex::Proto::Kerberos::Model::KdcResponse>
Receives a kerberos response through the connection
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rex/proto/kerberos/client.rb', line 106 def recv_response if connection.nil? raise ::RuntimeError, 'Kerberos Client: connection not established' end res = nil case protocol when 'tcp' res = recv_response_tcp when 'udp' res = recv_response_udp else raise ::RuntimeError, 'Kerberos Client: unknown transport protocol' end subscriber.on_response(res) res end |
#send_recv(req) ⇒ <Rex::Proto::Kerberos::Model::KrbError, Rex::Proto::Kerberos::Model::KdcResponse>
Sends a kerberos request, and reads the response through the connection
131 132 133 134 135 136 |
# File 'lib/rex/proto/kerberos/client.rb', line 131 def send_recv(req) send_request(req) res = recv_response res end |
#send_request(req) ⇒ Integer
Sends a kerberos request through the connection
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rex/proto/kerberos/client.rb', line 82 def send_request(req) connect subscriber.on_request(req) sent = 0 case protocol when 'tcp' sent = send_request_tcp(req) when 'udp' sent = send_request_udp(req) else raise ::RuntimeError, 'Kerberos Client: unknown transport protocol' end sent end |