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.


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

def initialize(opts = {})
  self.host = opts[:host]
  self.port     = (opts[:port] || 88).to_i
  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


23
24
25
# File 'lib/rex/proto/kerberos/client.rb', line 23

def connection
  @connection
end

#contextHash

Returns The Msf context where the connection belongs to.

Returns:

  • (Hash)

    The Msf context where the connection belongs to


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

def context
  @context
end

#hostString

Returns The kerberos server host.

Returns:

  • (String)

    The kerberos server host


10
11
12
# File 'lib/rex/proto/kerberos/client.rb', line 10

def host
  @host
end

#portInteger

Returns The kerberos server port.

Returns:

  • (Integer)

    The kerberos server port


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

def port
  @port
end

#protocolString

Returns The transport protocol used (tcp/udp).

Returns:

  • (String)

    The transport protocol used (tcp/udp)


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

def protocol
  @protocol
end

#timeoutInteger

Returns The connect / read timeout.

Returns:

  • (Integer)

    The connect / read timeout


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

def timeout
  @timeout
end

Instance Method Details

#closeObject

Closes the connection


56
57
58
59
60
61
62
63
# File 'lib/rex/proto/kerberos/client.rb', line 56

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:


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rex/proto/kerberos/client.rb', line 40

def connect
  return connection if connection

  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


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rex/proto/kerberos/client.rb', line 94

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


118
119
120
121
122
123
# File 'lib/rex/proto/kerberos/client.rb', line 118

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:


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rex/proto/kerberos/client.rb', line 71

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