Class: Rex::Proto::SunRPC::Client

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

Overview

XXX: CPORT!

Constant Summary collapse

AUTH_NULL =
0
AUTH_UNIX =
1
PMAP_PROG =
100000
PMAP_VERS =
2
PMAP_GETPORT =
3
CALL =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Returns a new instance of Client.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rex/proto/sunrpc/client.rb', line 35

def initialize(opts)
  self.rhost   = opts[:rhost]
  self.rport   = opts[:rport]
  self.program = opts[:program]
  self.version = opts[:version]
  self.timeout = opts[:timeout] || 20
  self.context = opts[:context] || {}
  self.proto   = opts[:proto]

  if self.proto.downcase !~ /^(tcp|udp)$/
    raise ::Rex::ArgumentError, 'Protocol is not "tcp" or "udp"'
  end

  @pport = nil

  @auth_type = AUTH_NULL
  @auth_data = ''

  @call_sock = nil
end

Instance Attribute Details

#call_sockObject

Returns the value of attribute call_sock.



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

def call_sock
  @call_sock
end

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

#pportObject

Returns the value of attribute pport.



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

def pport
  @pport
end

#programObject

Returns the value of attribute program.



30
31
32
# File 'lib/rex/proto/sunrpc/client.rb', line 30

def program
  @program
end

#protoObject

Returns the value of attribute proto.



30
31
32
# File 'lib/rex/proto/sunrpc/client.rb', line 30

def proto
  @proto
end

#rhostObject

Returns the value of attribute rhost.



30
31
32
# File 'lib/rex/proto/sunrpc/client.rb', line 30

def rhost
  @rhost
end

#rportObject

Returns the value of attribute rport.



30
31
32
# File 'lib/rex/proto/sunrpc/client.rb', line 30

def rport
  @rport
end

#should_fragmentObject

Returns the value of attribute should_fragment.



33
34
35
# File 'lib/rex/proto/sunrpc/client.rb', line 33

def should_fragment
  @should_fragment
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#versionObject

Returns the value of attribute version.



30
31
32
# File 'lib/rex/proto/sunrpc/client.rb', line 30

def version
  @version
end

Instance Method Details

#authnull_createObject



97
98
99
100
# File 'lib/rex/proto/sunrpc/client.rb', line 97

def authnull_create
  @auth_type = AUTH_NULL
  @auth_data = ''
end

#authunix_create(host, uid, gid, groupz) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/rex/proto/sunrpc/client.rb', line 102

def authunix_create(host, uid, gid, groupz)
  raise ::Rex::ArgumentError, 'Hostname length is too long' if host.length > 255
# 10?
  raise ::Rex::ArgumentError, 'Too many groups' if groupz.length > 10

  @auth_type = AUTH_UNIX
  @auth_data =
    Rex::Encoder::XDR.encode(0, host, uid, gid, groupz) # XXX: TIME! GROUPZ?!
end

#call(procedure, buffer, maxwait = self.timeout) ⇒ Object



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

def call(procedure, buffer, maxwait = self.timeout)
  buf =
    Rex::Encoder::XDR.encode(CALL, 2, @program, @version, procedure,
      @auth_type, [@auth_data, 400], AUTH_NULL, '')+
    buffer

  if ! @call_sock
    @call_sock = make_rpc(@proto, @rhost, @pport)
  end

  send_rpc(@call_sock, buf)
  recv_rpc(@call_sock, maxwait)
end

#createObject

XXX: Add optional parameter to have proto be something else



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rex/proto/sunrpc/client.rb', line 57

def create()
  proto_num = 0
  if @proto.eql?('tcp')
    proto_num = 6
  elsif @proto.eql?('udp')
    proto_num = 17
  end

  buf =
    Rex::Encoder::XDR.encode(CALL, 2, PMAP_PROG, PMAP_VERS, PMAP_GETPORT,
      @auth_type, [@auth_data, 400], AUTH_NULL, '',
      @program, @version, proto_num, 0)

  sock = make_rpc(@proto, @rhost, @rport)
  send_rpc(sock, buf)
  ret = recv_rpc(sock)
  close_rpc(sock)

  return ret
end

#destroyObject



92
93
94
95
# File 'lib/rex/proto/sunrpc/client.rb', line 92

def destroy
  close_rpc(@call_sock) if @call_sock
  @call_sock = nil
end

#portmap_req(host, port, rpc_vers, procedure, buffer) ⇒ Object

XXX: Dirty, integrate some sort of request system into create/call?



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rex/proto/sunrpc/client.rb', line 113

def portmap_req(host, port, rpc_vers, procedure, buffer)
  buf = Rex::Encoder::XDR.encode(CALL, 2, PMAP_PROG, rpc_vers, procedure,
    AUTH_NULL, '', AUTH_NULL, '') + buffer

  sock = make_rpc('tcp', host, port)
  send_rpc(sock, buf)
  ret = recv_rpc(sock)
  close_rpc(sock)

  return ret
end