Module: Msf::Exploit::Remote::WDBRPC

Included in:
WDBRPC_Client
Defined in:
lib/msf/core/exploit/wdbrpc.rb

Overview

This module exposes methods for manipulating the WDRPC service

Instance Method Summary collapse

Instance Method Details

#wdbrpc_checksum(data) ⇒ Object


196
197
198
199
200
201
# File 'lib/msf/core/exploit/wdbrpc.rb', line 196

def wdbrpc_checksum(data)
  sum = 0
  data.unpack("n*").each {|c| sum += c }
  sum = (sum & 0xffff) + (sum >> 16)
  (~sum)
end

#wdbrpc_decode_arr(data, dtype) ⇒ Object


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/msf/core/exploit/wdbrpc.rb', line 219

def wdbrpc_decode_arr(data, dtype)
  return if data.length < 4
  res = []

  alen = data.slice!(0,4).unpack("N")[0]
  return res if alen == 0

  1.upto(alen) do |idx|
    case dtype
    when :int
      res << wdbrpc_decode_int(data)
    when :str
      res << wdbrpc_decode_str(data)
    when :bool
      res << wdbrpc_decode_bool(data)
    end
  end

  res
end

#wdbrpc_decode_bool(data) ⇒ Object


240
241
242
243
# File 'lib/msf/core/exploit/wdbrpc.rb', line 240

def wdbrpc_decode_bool(data)
  return if data.length < 4
  (data.slice!(0,4).unpack("N")[0] == 0) ? false : true
end

#wdbrpc_decode_int(data) ⇒ Object


214
215
216
217
# File 'lib/msf/core/exploit/wdbrpc.rb', line 214

def wdbrpc_decode_int(data)
  return if data.length < 4
  data.slice!(0,4).unpack("N")[0]
end

#wdbrpc_decode_str(data) ⇒ Object


203
204
205
206
207
208
209
210
211
212
# File 'lib/msf/core/exploit/wdbrpc.rb', line 203

def wdbrpc_decode_str(data)
  return if data.length < 4
  slen = data.slice!(0,4).unpack("N")[0]
  return "" if slen == 0
  while (slen % 4 != 0)
    slen += 1
  end

  data.slice!(0,slen).to_s.split("\x00")[0]
end

#wdbrpc_parse_connect_reply(buff) ⇒ Object


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/msf/core/exploit/wdbrpc.rb', line 130

def wdbrpc_parse_connect_reply(buff)
  info = {}
  head = buff.slice!(0,36)
  info[:agent_ver] = wdbrpc_decode_str(buff)
  info[:agent_mtu] = wdbrpc_decode_int(buff)
  info[:agent_mod] = wdbrpc_decode_int(buff)
  info[:rt_type]          = wdbrpc_decode_int(buff)
  info[:rt_vers]          = wdbrpc_decode_str(buff)
  info[:rt_cpu_type]      = wdbrpc_decode_int(buff)
  info[:rt_has_fpp]       = wdbrpc_decode_bool(buff)
  info[:rt_has_wp]        = wdbrpc_decode_bool(buff)
  info[:rt_page_size]     = wdbrpc_decode_int(buff)
  info[:rt_endian]        = wdbrpc_decode_int(buff)
  info[:rt_bsp_name]      = wdbrpc_decode_str(buff)
  info[:rt_bootline]      = wdbrpc_decode_str(buff)
  info[:rt_membase]       = wdbrpc_decode_int(buff)
  info[:rt_memsize]       = wdbrpc_decode_int(buff)
  info[:rt_region_count]  = wdbrpc_decode_int(buff)
  info[:rt_regions]       = wdbrpc_decode_arr(buff, :int)
  info[:rt_hostpool_base] = wdbrpc_decode_int(buff)
  info[:rt_hostpool_size] = wdbrpc_decode_int(buff)
  info
end

#wdbrpc_request(procedure, data) ⇒ Object


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/msf/core/exploit/wdbrpc.rb', line 154

def wdbrpc_request(procedure, data)
  pkt =
    [
      0x00000000, # XID (ignored by checksum and length)
      0x00000000,
      0x00000002,
      0x55555555, # Program
      0x00000001, # Version
      procedure,  # Procedure
      0x00000000,
      0x00000000,
      0x00000000,
      0x00000000
    ].pack("N*")

  pkt +=
    [
      0x00000000, # Checksum
      0x00000000, # Packet Size
      wdbrpc_request_seqno
    ].pack("N*")

  pkt += data

  # Length excludes the XID
  pkt[44, 4] = [ pkt.length - 4].pack("N")

  # Set the checksum flag and calculate the checksum
  pkt[42, 2] = [ wdbrpc_checksum(pkt) ].pack("n")
  pkt[40, 2] = [0xffff].pack("n")

  # Set the RPC XID
  pkt[ 0, 4] = [ rand(0x100000000) ].pack("N")

  pkt
end

#wdbrpc_request_connect(ip) ⇒ Object

WDB_TARGET_CONNECT


32
33
34
35
# File 'lib/msf/core/exploit/wdbrpc.rb', line 32

def wdbrpc_request_connect(ip)
  data = [ 0x00000002, 0x00000000, 0x00000000 ].pack("N*")
  wdbrpc_request(1, data)
end

#wdbrpc_request_connect2(ip) ⇒ Object

WDB_TARGET_CONNECT2


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/msf/core/exploit/wdbrpc.rb', line 14

def wdbrpc_request_connect2(ip)
  ip += "\x00"
  while(ip.length % 4 != 0)
    ip << "\x00"
  end

  data = 	[
    0x00000002,
    0x00000000,
    0x00000000,
    0x00000001,
    ip.length
  ].pack("N*") + ip

  wdbrpc_request(0x7a, data)
end

#wdbrpc_request_context_kill(ctx_type, ctx) ⇒ Object


116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/msf/core/exploit/wdbrpc.rb', line 116

def wdbrpc_request_context_kill(ctx_type, ctx)

  # WDB_CTX
  data = [
    ctx_type, # WDB_CTX_SYSTEM (3 for task)
    ctx,      # SYSTEM (or set for task)
  ].pack("N*")

  # options
  data << [ 0 ] .pack("N")

  wdbrpc_request(31, data)
end

#wdbrpc_request_disconnectObject

WDB_TARGET_DISCONNECT


38
39
40
41
# File 'lib/msf/core/exploit/wdbrpc.rb', line 38

def wdbrpc_request_disconnect
  data = [ 0x00000002, 0x00000000, 0x00000000 ].pack("N*")
  wdbrpc_request(2, data)
end

#wdbrpc_request_memread(offset = 0, length = 512, params = 0) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/msf/core/exploit/wdbrpc.rb', line 63

def wdbrpc_request_memread(offset=0, length=512, params=0)

  # WDB_MEM_REGION
  data = [
    offset, # baseAddress
    length, # numberOfBytes
    params, # params
  ].pack("N*")

  wdbrpc_request(10, data)
end

#wdbrpc_request_memscan(offset = 0, depth = 1024, buff = '', params = 0) ⇒ Object


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/msf/core/exploit/wdbrpc.rb', line 93

def wdbrpc_request_memscan(offset=0, depth=1024, buff='', params=0)
  # Make sure its DWORD aligned
  while(buff.length % 4 != 0)
    buff << "\x00"
  end

  # WDB_MEM_REGION
  data = [
    offset, # baseAddress
    depth,  # numberOfBytes
    params, # params
  ].pack("N*")

  # WDB_MEM_XFER
  data << [
    buff.length,
    0,
    buff.length
  ].pack("N*") + buff

  wdbrpc_request(11, data)
end

#wdbrpc_request_memwrite(offset = 0, buff = '', params = 0) ⇒ Object


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/msf/core/exploit/wdbrpc.rb', line 75

def wdbrpc_request_memwrite(offset=0, buff='', params=0)

  # Make sure its DWORD aligned
  while(buff.length % 4 != 0)
    buff << "\x00"
  end

  # WDB_MEM_XFER
  data = [
    buff.length,
    offset,      # target
    buff.length
  ].pack("N*") + buff

  wdbrpc_request(11, data)
end

#wdbrpc_request_regread(regset = 0, offset = 0, length = 512, params = 0) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/msf/core/exploit/wdbrpc.rb', line 43

def wdbrpc_request_regread(regset=0, offset=0, length=512, params=0)
  data = [ regset ].pack("N")

  # WDB_CTX
  data << [
    0, # WDB_CTX_SYSTEM (3 for task)
    0, # SYSTEM (or set for task)
  ].pack("N*")

  # WDB_MEM_REGION
  data << [
    offset, # baseAddress
    length, # numberOfBytes
    params, # params
  ].pack("N*")

  wdbrpc_request(40, data)
end

#wdbrpc_request_seqnoObject


191
192
193
194
# File 'lib/msf/core/exploit/wdbrpc.rb', line 191

def wdbrpc_request_seqno
  @wdbrpc_seqno ||= 0
  @wdbrpc_seqno += 1
end