2005-07-16 09:37:42 +00:00
|
|
|
module Rex
|
|
|
|
module Proto
|
2005-07-25 09:40:31 +00:00
|
|
|
module DCERPC
|
|
|
|
class Client
|
2005-07-17 08:24:30 +00:00
|
|
|
|
|
|
|
require 'rex/proto/dcerpc/uuid'
|
|
|
|
require 'rex/proto/dcerpc/response'
|
2005-12-13 06:08:40 +00:00
|
|
|
require 'rex/proto/dcerpc/exceptions'
|
2005-07-17 10:24:19 +00:00
|
|
|
require 'rex/text'
|
2005-12-13 06:08:40 +00:00
|
|
|
require 'rex/proto/smb/exceptions'
|
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
attr_accessor :handle, :socket, :options, :last_response, :context, :no_bind, :ispipe, :smb
|
|
|
|
|
|
|
|
# initialize a DCE/RPC Function Call
|
|
|
|
def initialize(handle, socket, useroptions = Hash.new)
|
|
|
|
self.handle = handle
|
|
|
|
self.socket = socket
|
2006-04-30 19:49:27 +00:00
|
|
|
self.options = {
|
|
|
|
'smb_user' => '',
|
|
|
|
'smb_pass' => '',
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
'smb_pipeio' => 'rw',
|
|
|
|
'smb_name' => nil,
|
|
|
|
'read_timeout' => 10,
|
|
|
|
'connect_timeout' => 5
|
2006-04-30 19:49:27 +00:00
|
|
|
}
|
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
self.options.merge!(useroptions)
|
2006-04-30 19:49:27 +00:00
|
|
|
|
|
|
|
# If the caller passed us a smb_client object, use it and
|
|
|
|
# and skip the connect/login/ipc$ stages of the setup
|
|
|
|
if (self.options['smb_client'])
|
|
|
|
self.smb = self.options['smb_client']
|
|
|
|
end
|
2006-01-27 05:29:06 +00:00
|
|
|
|
|
|
|
# we must have a valid handle, regardless of everything else
|
|
|
|
raise ArgumentError, 'handle is not a Rex::Proto::DCERPC::Handle' if !self.handle.is_a?(Rex::Proto::DCERPC::Handle)
|
|
|
|
|
|
|
|
# we do this in case socket needs setup first, ie, socket = nil
|
|
|
|
if !self.options['no_socketsetup']
|
|
|
|
self.socket_check()
|
|
|
|
end
|
|
|
|
|
|
|
|
raise ArgumentError, 'socket can not read' if !self.socket.respond_to?(:read)
|
|
|
|
raise ArgumentError, 'socket can not write' if !self.socket.respond_to?(:write)
|
|
|
|
|
|
|
|
if !self.options['no_autobind']
|
|
|
|
self.bind()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def socket_check()
|
|
|
|
if self.socket == nil
|
|
|
|
self.socket_setup()
|
|
|
|
end
|
|
|
|
|
|
|
|
case self.handle.protocol
|
|
|
|
when 'ncacn_ip_tcp'
|
|
|
|
if self.socket.type? != 'tcp'
|
|
|
|
raise "ack, #{self.handle.protocol} requires socket type tcp, not #{self.socket.type?}!"
|
|
|
|
end
|
|
|
|
when 'ncacn_np'
|
2006-04-26 16:59:44 +00:00
|
|
|
if self.socket.class == Rex::Proto::SMB::SimpleClient::OpenPipe
|
2006-01-27 05:29:06 +00:00
|
|
|
self.ispipe = 1
|
|
|
|
elsif self.socket.type? == 'tcp'
|
|
|
|
self.smb_connect()
|
|
|
|
else
|
|
|
|
raise "ack, #{self.handle.protocol} requires socket type tcp, not #{self.socket.type?}!"
|
|
|
|
end
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
# No support ncacn_ip_udp (is it needed now that its ripped from Vista?)
|
2006-01-27 05:29:06 +00:00
|
|
|
else
|
|
|
|
raise "Unsupported protocol : #{self.handle.protocol}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create the appropriate socket based on protocol
|
|
|
|
def socket_setup()
|
2009-10-20 17:24:33 +00:00
|
|
|
ctx = { 'Msf' => self.options['Msf'], 'MsfExploit' => self.options['MsfExploit'] }
|
2006-01-27 05:29:06 +00:00
|
|
|
self.socket = case self.handle.protocol
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
|
|
|
|
when 'ncacn_ip_tcp'
|
|
|
|
Rex::Socket.create_tcp(
|
|
|
|
'PeerHost' => self.handle.address,
|
|
|
|
'PeerPort' => self.handle.options[0],
|
|
|
|
'Context' => ctx,
|
|
|
|
'Timeout' => self.options['connect_timeout']
|
|
|
|
)
|
|
|
|
|
|
|
|
when 'ncacn_np'
|
2006-01-27 05:29:06 +00:00
|
|
|
begin
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
socket = Rex::Socket.create_tcp(
|
|
|
|
'PeerHost' => self.handle.address,
|
|
|
|
'PeerPort' => 445,
|
|
|
|
'Context' => ctx,
|
|
|
|
'Timeout' => self.options['connect_timeout']
|
|
|
|
)
|
2006-01-27 05:29:06 +00:00
|
|
|
rescue Timeout::Error, Rex::ConnectionRefused
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
socket = Rex::Socket.create_tcp(
|
|
|
|
'PeerHost' => self.handle.address,
|
|
|
|
'PeerPort' => 139,
|
|
|
|
'Context' => ctx,
|
|
|
|
'Timeout' => self.options['connect_timeout']
|
|
|
|
)
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
|
|
|
socket
|
|
|
|
else nil
|
|
|
|
end
|
2005-12-15 04:46:52 +00:00
|
|
|
|
|
|
|
# Add this socket to the exploit's list of open sockets
|
|
|
|
options['MsfExploit'].add_socket(self.socket) if (options['MsfExploit'])
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def smb_connect()
|
|
|
|
require 'rex/proto/smb/simpleclient'
|
2006-04-30 19:49:27 +00:00
|
|
|
|
|
|
|
if(not self.smb)
|
|
|
|
if self.socket.peerport == 139
|
|
|
|
smb = Rex::Proto::SMB::SimpleClient.new(self.socket)
|
|
|
|
else
|
|
|
|
smb = Rex::Proto::SMB::SimpleClient.new(self.socket, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
smb.login('*SMBSERVER', self.options['smb_user'], self.options['smb_pass'])
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
smb.connect("\\\\#{self.handle.address}\\IPC$")
|
2006-04-30 19:49:27 +00:00
|
|
|
self.smb = smb
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
self.smb.read_timeout = self.options['read_timeout']
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
2006-04-26 16:59:44 +00:00
|
|
|
|
2006-04-30 19:49:27 +00:00
|
|
|
f = self.smb.create_pipe(self.handle.options[0])
|
2006-04-26 16:59:44 +00:00
|
|
|
f.mode = self.options['smb_pipeio']
|
2006-01-27 05:29:06 +00:00
|
|
|
self.socket = f
|
|
|
|
end
|
|
|
|
|
|
|
|
def read()
|
2008-04-04 20:54:39 +00:00
|
|
|
|
2008-11-10 23:03:16 +00:00
|
|
|
max_read = self.options['pipe_read_max_size'] || 1024*1024
|
2008-04-04 20:54:39 +00:00
|
|
|
min_read = self.options['pipe_read_min_size'] || max_read
|
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
raw_response = ''
|
2008-04-04 20:54:39 +00:00
|
|
|
|
|
|
|
# Are we reading from a remote pipe over SMB?
|
|
|
|
if (self.socket.class == Rex::Proto::SMB::SimpleClient::OpenPipe)
|
2006-01-27 05:29:06 +00:00
|
|
|
begin
|
2008-11-10 23:03:16 +00:00
|
|
|
|
2008-12-11 03:50:30 +00:00
|
|
|
# Max SMB read is 65535, cap it at 64000
|
|
|
|
max_read = [64000, max_read].min
|
|
|
|
min_read = [64000, min_read].min
|
|
|
|
|
2008-11-10 23:03:16 +00:00
|
|
|
read_limit = nil
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
# Random read offsets will not work on Windows NT 4.0 (thanks Dave!)
|
|
|
|
|
|
|
|
read_cnt = (rand(max_read-min_read)+min_read)
|
|
|
|
if(read_limit)
|
|
|
|
if(read_cnt + raw_response.length > read_limit)
|
|
|
|
read_cnt = raw_response.length - read_limit
|
2008-04-04 21:15:55 +00:00
|
|
|
end
|
2008-11-10 23:03:16 +00:00
|
|
|
end
|
2008-12-11 03:50:30 +00:00
|
|
|
|
2008-11-10 23:03:16 +00:00
|
|
|
data = self.socket.read( read_cnt, rand(1024)+1)
|
2008-12-11 03:50:30 +00:00
|
|
|
break if not (data and data.length > 0)
|
2008-11-10 23:03:16 +00:00
|
|
|
raw_response += data
|
|
|
|
|
|
|
|
# Keep reading until we have at least the DCERPC header
|
|
|
|
next if raw_response.length < 10
|
|
|
|
|
|
|
|
# We now have to process the raw_response and parse out the DCERPC fragment length
|
|
|
|
# if we have read enough data. Once we have the length value, we need to make sure
|
|
|
|
# that we don't read beyond this amount, or it can screw up the SMB state
|
|
|
|
if (not read_limit)
|
|
|
|
begin
|
|
|
|
check = Rex::Proto::DCERPC::Response.new(raw_response)
|
|
|
|
read_limit = check.frag_len
|
|
|
|
rescue ::Rex::Proto::DCERPC::Exceptions::InvalidPacket
|
2008-04-04 21:15:55 +00:00
|
|
|
end
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
2008-11-10 23:03:16 +00:00
|
|
|
|
|
|
|
break if (read_limit and read_limit == raw_response.length)
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
2008-11-10 23:03:16 +00:00
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
rescue Rex::Proto::SMB::Exceptions::NoReply
|
|
|
|
# I don't care if I didn't get a reply...
|
|
|
|
rescue Rex::Proto::SMB::Exceptions::ErrorCode => exception
|
|
|
|
if exception.error_code != 0xC000014B
|
|
|
|
raise exception
|
|
|
|
end
|
|
|
|
end
|
2008-04-04 20:54:39 +00:00
|
|
|
# This must be a regular TCP or UDP socket
|
|
|
|
else
|
|
|
|
if (self.socket.type? == 'tcp')
|
2008-04-04 21:15:55 +00:00
|
|
|
if (false and max_read)
|
2006-01-27 05:29:06 +00:00
|
|
|
while (true)
|
2008-04-04 20:54:39 +00:00
|
|
|
data = self.socket.get_once((rand(max_read-min_read)+min_read), self.options['read_timeout'])
|
|
|
|
break if not data
|
|
|
|
break if not data.length
|
2006-01-27 05:29:06 +00:00
|
|
|
raw_response << data
|
|
|
|
end
|
|
|
|
else
|
2008-04-04 20:54:39 +00:00
|
|
|
# Just read the entire response in one go
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
raw_response = self.socket.get_once(-1, self.options['read_timeout'])
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
|
|
|
else
|
2008-04-04 20:54:39 +00:00
|
|
|
# No segmented read support for non-TCP sockets
|
2006-01-27 05:29:06 +00:00
|
|
|
raw_response = self.socket.read(0xFFFFFFFF / 2 - 1) # read max data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
raw_response
|
|
|
|
end
|
|
|
|
|
2008-04-04 20:54:39 +00:00
|
|
|
# Write data to the underlying socket, limiting the sizes of the writes based on
|
|
|
|
# the pipe_write_min / pipe_write_max options.
|
2006-01-27 05:29:06 +00:00
|
|
|
def write(data)
|
2006-04-26 16:59:44 +00:00
|
|
|
|
2008-04-04 20:54:39 +00:00
|
|
|
max_write = self.options['pipe_write_max_size'] || data.length
|
|
|
|
min_write = self.options['pipe_write_min_size'] || max_write
|
2008-04-04 21:15:55 +00:00
|
|
|
|
|
|
|
if(min_write > max_write)
|
|
|
|
max_write = min_write
|
|
|
|
end
|
|
|
|
|
2008-04-04 20:54:39 +00:00
|
|
|
idx = 0
|
|
|
|
|
|
|
|
if (self.socket.class == Rex::Proto::SMB::SimpleClient::OpenPipe)
|
|
|
|
while(idx < data.length)
|
|
|
|
bsize = (rand(max_write-min_write)+min_write).to_i
|
|
|
|
len = self.socket.write(data[idx, bsize], rand(1024)+1)
|
|
|
|
idx += bsize
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
2008-04-04 20:54:39 +00:00
|
|
|
else
|
|
|
|
self.socket.write(data)
|
2006-01-27 05:29:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
data.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def bind()
|
|
|
|
require 'rex/proto/dcerpc/packet'
|
|
|
|
bind = ''
|
|
|
|
context = ''
|
|
|
|
if self.options['fake_multi_bind']
|
2006-05-03 05:53:37 +00:00
|
|
|
|
|
|
|
args = [ self.handle.uuid[0], self.handle.uuid[1] ]
|
|
|
|
|
|
|
|
if (self.options['fake_multi_bind_prepend'])
|
|
|
|
args << self.options['fake_multi_bind_prepend']
|
|
|
|
end
|
|
|
|
|
|
|
|
if (self.options['fake_multi_bind_append'])
|
|
|
|
args << self.options['fake_multi_bind_append']
|
|
|
|
end
|
|
|
|
|
|
|
|
bind, context = Rex::Proto::DCERPC::Packet.make_bind_fake_multi(*args)
|
2006-01-27 05:29:06 +00:00
|
|
|
else
|
|
|
|
bind, context = Rex::Proto::DCERPC::Packet.make_bind(self.handle.uuid[0], self.handle.uuid[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
raise 'make_bind failed' if !bind
|
|
|
|
|
|
|
|
self.write(bind)
|
|
|
|
raw_response = self.read()
|
|
|
|
response = Rex::Proto::DCERPC::Response.new(raw_response)
|
|
|
|
self.last_response = response
|
|
|
|
if response.type == 12 or response.type == 15
|
|
|
|
if self.last_response.ack_result[context] == 2
|
|
|
|
raise "Could not bind to #{self.handle}"
|
|
|
|
end
|
|
|
|
self.context = context
|
|
|
|
else
|
|
|
|
raise "Could not bind to #{self.handle}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Perform a DCE/RPC Function Call
|
|
|
|
def call(function, data)
|
|
|
|
|
|
|
|
frag_size = data.length
|
|
|
|
if options['frag_size']
|
|
|
|
frag_size = options['frag_size']
|
|
|
|
end
|
2006-03-29 20:46:29 +00:00
|
|
|
object_id = ''
|
|
|
|
if options['object_call']
|
|
|
|
object_id = self.handle.uuid[0]
|
|
|
|
end
|
|
|
|
if options['random_object_id']
|
|
|
|
object_id = Rex::Proto::DCERPC::UUID.uuid_unpack(Rex::Text.rand_text(16))
|
|
|
|
end
|
2006-01-27 05:29:06 +00:00
|
|
|
|
2006-03-29 20:46:29 +00:00
|
|
|
call_packets = Rex::Proto::DCERPC::Packet.make_request(function, data, frag_size, self.context, object_id)
|
2006-01-27 05:29:06 +00:00
|
|
|
call_packets.each { |packet|
|
|
|
|
self.write(packet)
|
|
|
|
}
|
|
|
|
|
2007-02-21 03:58:44 +00:00
|
|
|
raw_response = ''
|
|
|
|
|
|
|
|
begin
|
|
|
|
raw_response = self.read()
|
|
|
|
rescue ::EOFError
|
2006-01-27 05:29:06 +00:00
|
|
|
raise Rex::Proto::DCERPC::Exceptions::NoResponse
|
|
|
|
end
|
2007-02-21 03:58:44 +00:00
|
|
|
|
|
|
|
if (raw_response == nil or raw_response.length == 0)
|
|
|
|
raise Rex::Proto::DCERPC::Exceptions::NoResponse
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
self.last_response = Rex::Proto::DCERPC::Response.new(raw_response)
|
|
|
|
|
|
|
|
if self.last_response.type == 3
|
|
|
|
e = Rex::Proto::DCERPC::Exceptions::Fault.new
|
|
|
|
e.fault = self.last_response.status
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
|
|
|
self.last_response.stub_data
|
|
|
|
end
|
2005-07-17 10:24:19 +00:00
|
|
|
|
|
|
|
# Process a DCERPC response packet from a socket
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
def self.read_response(socket, timeout=self.options['read_timeout'])
|
2005-07-17 23:28:28 +00:00
|
|
|
|
2005-11-16 17:56:07 +00:00
|
|
|
data = socket.get_once(-1, timeout)
|
|
|
|
|
|
|
|
# We need at least 10 bytes to find the FragLen
|
|
|
|
if (! data or data.length() < 10)
|
2005-07-16 09:37:42 +00:00
|
|
|
return
|
|
|
|
end
|
2005-07-17 23:28:28 +00:00
|
|
|
|
2005-11-16 17:56:07 +00:00
|
|
|
# Pass the first 10 bytes to the constructor
|
|
|
|
resp = Rex::Proto::DCERPC::Response.new(data.slice!(0, 10))
|
2005-07-16 09:37:42 +00:00
|
|
|
|
2005-11-16 17:56:07 +00:00
|
|
|
# Something went wrong in the parser...
|
2005-07-17 08:24:30 +00:00
|
|
|
if (! resp.frag_len)
|
2005-07-16 09:37:42 +00:00
|
|
|
return resp
|
|
|
|
end
|
2005-07-17 23:28:28 +00:00
|
|
|
|
2005-11-16 17:56:07 +00:00
|
|
|
# Do we need to read more data?
|
|
|
|
if (resp.frag_len > (data.length + 10))
|
|
|
|
begin
|
|
|
|
data << socket.timed_read(resp.frag_len - data.length - 10, timeout)
|
|
|
|
rescue Timeout::Error
|
|
|
|
end
|
2005-09-16 03:29:27 +00:00
|
|
|
end
|
2005-11-16 17:56:07 +00:00
|
|
|
|
|
|
|
# Still missing some data...
|
|
|
|
if (data.length() != resp.frag_len - 10)
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
# TODO: Bubble this up somehow
|
|
|
|
# $stderr.puts "Truncated DCERPC response :-("
|
2005-07-16 09:37:42 +00:00
|
|
|
return resp
|
|
|
|
end
|
2005-07-17 23:28:28 +00:00
|
|
|
|
2005-11-16 17:56:07 +00:00
|
|
|
resp.parse(data)
|
2005-07-16 09:37:42 +00:00
|
|
|
return resp
|
|
|
|
end
|
2005-07-17 10:24:19 +00:00
|
|
|
|
2005-07-16 09:37:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-11-03 09:17:08 +00:00
|
|
|
end
|