Class: Rex::Proto::Kerberos::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/kerberos/client.rb

Overview

This class is a representation of a kerberos client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



33
34
35
36
37
38
39
40
# File 'lib/rex/proto/kerberos/client.rb', line 33

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] || {}
end

Instance Attribute Details

#connectionIO

Returns The connection established through Rex sockets.

Returns:

  • (IO)

    The connection established through Rex sockets



28
29
30
# File 'lib/rex/proto/kerberos/client.rb', line 28

def connection
  @connection
end

#contextHash

Returns The Msf context where the connection belongs to.

Returns:

  • (Hash)

    The Msf context where the connection belongs to



31
32
33
# File 'lib/rex/proto/kerberos/client.rb', line 31

def context
  @context
end

#hostString

Returns The kerberos server host.

Returns:

  • (String)

    The kerberos server host



12
13
14
# File 'lib/rex/proto/kerberos/client.rb', line 12

def host
  @host
end

#portInteger

Returns The kerberos server port.

Returns:

  • (Integer)

    The kerberos server port



15
16
17
# File 'lib/rex/proto/kerberos/client.rb', line 15

def port
  @port
end

#protocolString

Returns The transport protocol used (tcp/udp).

Returns:

  • (String)

    The transport protocol used (tcp/udp)



25
26
27
# File 'lib/rex/proto/kerberos/client.rb', line 25

def protocol
  @protocol
end

#proxiesString?

Returns The proxy directive to use for the socket.

Returns:

  • (String, nil)

    The proxy directive to use for the socket



18
19
20
# File 'lib/rex/proto/kerberos/client.rb', line 18

def proxies
  @proxies
end

#timeoutInteger

Returns The connect / read timeout.

Returns:

  • (Integer)

    The connect / read timeout



21
22
23
# File 'lib/rex/proto/kerberos/client.rb', line 21

def timeout
  @timeout
end

Instance Method Details

#closeObject

Closes the connection



62
63
64
65
66
67
68
69
# File 'lib/rex/proto/kerberos/client.rb', line 62

def close
  if connection
    connection.shutdown
    connection.close unless connection.closed?
  end

  self.connection = nil
end

#connectRex::Socket::Tcp

Creates a connection through a Rex socket

Returns:

  • (Rex::Socket::Tcp)

Raises:

  • (RuntimeError)

    if the connection can not be created



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rex/proto/kerberos/client.rb', line 46

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

Returns:

Raises:

  • (RuntimeError)

    if the connection isn't established, the transport protocol is unknown, not supported or the response can't be parsed

  • (NotImplementedError)

    if the transport protocol isn't supported



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rex/proto/kerberos/client.rb', line 100

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

  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

Parameters:

Returns:

Raises:

  • (RuntimeError)

    if the transport protocol is unknown or the response can't be parsed.

  • (NotImplementedError)

    if the transport protocol isn't supported



124
125
126
127
128
129
# File 'lib/rex/proto/kerberos/client.rb', line 124

def send_recv(req)
  send_request(req)
  res = recv_response

  res
end

#send_request(req) ⇒ Integer

Sends a kerberos request through the connection

Parameters:

Returns:

  • (Integer)

    the number of bytes sent

Raises:

  • (RuntimeError)

    if the transport protocol is unknown

  • (NotImplementedError)

    if the transport protocol isn't supported



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rex/proto/kerberos/client.rb', line 77

def send_request(req)
  connect

  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