Module: Msf::Exploit::Remote::WDBRPC_Client

Includes:
Auxiliary::Report, WDBRPC
Defined in:
lib/msf/core/exploit/remote/wdbrpc_client.rb

Overview

This module exposes methods for talking to WDBRPC daemons

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Auxiliary::Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Methods included from WDBRPC

#wdbrpc_checksum, #wdbrpc_decode_arr, #wdbrpc_decode_bool, #wdbrpc_decode_int, #wdbrpc_decode_str, #wdbrpc_parse_connect_reply, #wdbrpc_request, #wdbrpc_request_connect, #wdbrpc_request_connect2, #wdbrpc_request_context_kill, #wdbrpc_request_disconnect, #wdbrpc_request_memread, #wdbrpc_request_memscan, #wdbrpc_request_memwrite, #wdbrpc_request_regread, #wdbrpc_request_seqno

Instance Attribute Details

#udp_sockObject

Returns the value of attribute udp_sock.



15
16
17
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 15

def udp_sock
  @udp_sock
end

#wdbrpc_infoObject

Returns the value of attribute wdbrpc_info.



15
16
17
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 15

def wdbrpc_info
  @wdbrpc_info
end

Instance Method Details

#initialize(info = {}) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 17

def initialize(info = {})
  super
  register_options(
    [
      Opt::RHOST,
      Opt::RPORT(17185),
    ], Msf::Exploit::Remote::WDBRPC_Client)
end

#rhostObject



208
209
210
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 208

def rhost
  datastore['RHOST']
end

#rportObject



212
213
214
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 212

def rport
  datastore['RPORT'].to_i
end

#wdbrpc_client_connectObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 27

def wdbrpc_client_connect
  self.wdbrpc_info = {}

  wdbrpc_client_disconnect()

  self.udp_sock = Rex::Socket::Udp.create(
    {
      'Context' => {'Msf' => framework, 'MsfExploit' => self}
    }
  )
  add_socket(self.udp_sock)

  wdbrpc_client_send_disconnect()

  udp_sock.sendto(wdbrpc_request_connect(rhost), rhost, rport, 0)
  res,src = udp_sock.recvfrom(65535, 5)
  if not res
    print_error("No response to TARGET_CONNECT (WDB4)")
    return
  end


  if res.length > 0 and res.length < 80
    print_status("#{rhost}: Unknown response: '#{res.unpack("H*")[0]}'")
    return
  end

  if res.empty?
    print_error("#{rhost}: No response from the target")
    return
  end

  self.wdbrpc_info = wdbrpc_parse_connect_reply(res)
  print_status("#{rhost} Connected to #{self.wdbrpc_info[:rt_vers]} - #{self.wdbrpc_info[:rt_bsp_name]} (#{self.wdbrpc_info[:rt_bootline]})")

  report_note(
    :host   => rhost,
    :port   => rport,
    :proto  => 'udp',
    :type   => 'vxworks.target_info',
    :data   => res,
    :update => :unique
  )
end

#wdbrpc_client_connect2Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 72

def wdbrpc_client_connect2
  self.wdbrpc_info = {}

  wdbrpc_client_disconnect()

  self.udp_sock = Rex::Socket::Udp.create(
    {
      'Context' => {'Msf' => framework, 'MsfExploit' => self}
    }
  )
  add_socket(self.udp_sock)

  wdbrpc_client_send_disconnect()

  udp_sock.sendto(wdbrpc_request_connect2(rhost), rhost, rport, 0)
  res,src = udp_sock.recvfrom(65535, 5)
  if not res
    print_error("No response to TARGET_CONNECT2")
    return
  end

  if res.length < 80
    print_status("#{rhost}: Unknown response: '#{res.unpack("H*")[0]}'")
    return
  end

  self.wdbrpc_info = wdbrpc_parse_connect_reply(res)
  print_status("#{rhost} Connected to #{self.wdbrpc_info[:rt_vers]} - #{self.wdbrpc_info[:rt_bsp_name]} (#{self.wdbrpc_info[:rt_bootline]})")

  report_note(
    :host   => rhost,
    :port   => rport,
    :proto  => 'udp',
    :type   => 'vxworks.target_info',
    :data   => res,
    :update => :unique
  )
end

#wdbrpc_client_context_kill(ctx_type = 0, ctx = 0) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 170

def wdbrpc_client_context_kill(ctx_type=0, ctx=0)
  pkt = wdbrpc_request_context_kill(ctx_type, ctx)
  res = nil

  begin
    udp_sock.sendto(pkt, rhost, rport, 0)
    res,src = udp_sock.recvfrom(65535, 0.5)

  rescue ::Interrupt
    raise $!
  rescue ::Exception
  end
  res
end

#wdbrpc_client_disconnectObject



198
199
200
201
202
203
204
205
206
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 198

def wdbrpc_client_disconnect
  wdbrpc_client_send_disconnect

  if self.udp_sock
    self.udp_sock.close rescue nil
  end
  self.udp_sock = nil

end

#wdbrpc_client_memread(offset, length, params = 0) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 111

def wdbrpc_client_memread(offset, length, params=0)
  pkt = wdbrpc_request_memread(offset, length, params)
  cnt = 0
  res = nil

  begin
    udp_sock.sendto(pkt, rhost, rport, 0)
    res,src = udp_sock.recvfrom(65535, 0.5)
    if not res and src
      raise RuntimeError, "no reply"
    end

    if res.length <= 48
      raise RuntimeError, "short read"
    end

  rescue ::Interrupt
    raise $!
  rescue ::Exception
    if cnt < 120
      cnt += 1
      retry
    end
  end

  res[48,res.length-48]
end

#wdbrpc_client_memscan(offset, depth, buffer, params = 0) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 154

def wdbrpc_client_memscan(offset, depth, buffer, params=0)
  pkt = wdbrpc_request_memscan(offset, depth, buffer, params)
  cnt = 0
  res = nil

  udp_sock.sendto(pkt, rhost, rport, 0)
  res,src = udp_sock.recvfrom(65535, 5.0)

  if not res and src
    raise RuntimeError, "no reply"
  end
  p res
  res
end

#wdbrpc_client_memwrite(offset, buffer, params = 0) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 139

def wdbrpc_client_memwrite(offset, buffer, params=0)
  pkt = wdbrpc_request_memwrite(offset, buffer, params)
  cnt = 0
  res = nil

  udp_sock.sendto(pkt, rhost, rport, 0)
  res,src = udp_sock.recvfrom(65535, 5.0)

  if not res and src
    raise RuntimeError, "no reply"
  end
  res[-4,4].unpack("N")[0]
end

#wdbrpc_client_send_disconnectObject



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/msf/core/exploit/remote/wdbrpc_client.rb', line 185

def wdbrpc_client_send_disconnect
  pkt = wdbrpc_request_disconnect
  begin
    if self.udp_sock
      self.udp_sock.sendto(pkt, rhost, rport, 0)
      self.udp_sock.recvfrom(65535, 5)
    end
  rescue ::Interrupt
    raise $!
  rescue ::Exception
  end
end