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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rex/proto/sunrpc/client.rb', line 46

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.



42
43
44
# File 'lib/rex/proto/sunrpc/client.rb', line 42

def call_sock
  @call_sock
end

#contextObject

Returns the value of attribute context.



42
43
44
# File 'lib/rex/proto/sunrpc/client.rb', line 42

def context
  @context
end

#pportObject

Returns the value of attribute pport.



42
43
44
# File 'lib/rex/proto/sunrpc/client.rb', line 42

def pport
  @pport
end

#programObject

Returns the value of attribute program.



41
42
43
# File 'lib/rex/proto/sunrpc/client.rb', line 41

def program
  @program
end

#protoObject

Returns the value of attribute proto.



41
42
43
# File 'lib/rex/proto/sunrpc/client.rb', line 41

def proto
  @proto
end

#rhostObject

Returns the value of attribute rhost.



41
42
43
# File 'lib/rex/proto/sunrpc/client.rb', line 41

def rhost
  @rhost
end

#rportObject

Returns the value of attribute rport.



41
42
43
# File 'lib/rex/proto/sunrpc/client.rb', line 41

def rport
  @rport
end

#should_fragmentObject

Returns the value of attribute should_fragment.



44
45
46
# File 'lib/rex/proto/sunrpc/client.rb', line 44

def should_fragment
  @should_fragment
end

#timeoutObject

Returns the value of attribute timeout.



42
43
44
# File 'lib/rex/proto/sunrpc/client.rb', line 42

def timeout
  @timeout
end

#versionObject

Returns the value of attribute version.



41
42
43
# File 'lib/rex/proto/sunrpc/client.rb', line 41

def version
  @version
end

Instance Method Details

#authnull_createObject



108
109
110
111
# File 'lib/rex/proto/sunrpc/client.rb', line 108

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

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

Raises:

  • (::Rex::ArgumentError)


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

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



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rex/proto/sunrpc/client.rb', line 89

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rex/proto/sunrpc/client.rb', line 68

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



103
104
105
106
# File 'lib/rex/proto/sunrpc/client.rb', line 103

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?



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rex/proto/sunrpc/client.rb', line 124

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