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

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

Overview

This module exposes methods for manipulating the WDRPC service

Instance Method Summary collapse

Instance Method Details

#wdbrpc_checksum(data) ⇒ Object



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

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



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

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



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

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



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

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

#wdbrpc_decode_str(data) ⇒ Object



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

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



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

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



153
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
# File 'lib/msf/core/exploit/remote/wdbrpc.rb', line 153

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



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

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

#wdbrpc_request_connect2(ip) ⇒ Object

WDB_TARGET_CONNECT2



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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