Skip to content

Commit 24c0da0

Browse files
committed
Merge branch 'rapid7' into doc/cleanup-peparsey
2 parents 3acccd7 + ca43900 commit 24c0da0

File tree

14 files changed

+659
-563
lines changed

14 files changed

+659
-563
lines changed

lib/msf/core/exploit/dcerpc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Exploit::Remote::DCERPC
2121
DCERPCPacket = Rex::Proto::DCERPC::Packet
2222
DCERPCClient = Rex::Proto::DCERPC::Client
2323
DCERPCResponse = Rex::Proto::DCERPC::Response
24-
DCERPCUUID = Rex::Proto::DCERPC::UUID
24+
DCERPCUUID = Rex::Proto::DCERPC::UUID
2525
NDR = Rex::Encoder::NDR
2626

2727

lib/msf/core/exploit/file_dropper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def on_new_session(session)
5656
#
5757
# Record file as needing to be cleaned up
5858
#
59-
# @param [Array<String>] files List of paths on the target that should
59+
# @param files [Array<String>] List of paths on the target that should
6060
# be deleted during cleanup. Each filename should be either a full
6161
# path or relative to the current working directory of the session
6262
# (not necessarily the same as the cwd of the server we're
@@ -95,7 +95,9 @@ def cleanup
9595
true
9696
#rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE, ::Rex::Post::Meterpreter::RequestError => e
9797
rescue ::Exception => e
98-
vprint_error("Failed to delete #{file}: #{e.to_s}")
98+
vprint_error("Failed to delete #{file}: #{e}")
99+
elog("Failed to delete #{file}: #{e.class}: #{e}")
100+
elog("Call stack:\n#{e.backtrace.join("\n")}")
99101
false
100102
end
101103
end

lib/msf/core/exploit/psexec.rb

Lines changed: 0 additions & 201 deletions
This file was deleted.

lib/msf/core/exploit/smb.rb

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'rex/proto/dcerpc'
55
require 'rex/encoder/ndr'
66

7-
87
module Msf
98

109
###
@@ -18,6 +17,9 @@ module Msf
1817

1918
module Exploit::Remote::SMB
2019

20+
require 'msf/core/exploit/smb/authenticated'
21+
require 'msf/core/exploit/smb/psexec'
22+
2123
include Exploit::Remote::Tcp
2224
include Exploit::Remote::NTLM::Client
2325

@@ -33,20 +35,6 @@ module Exploit::Remote::SMB
3335
DCERPCUUID = Rex::Proto::DCERPC::UUID
3436
NDR = Rex::Encoder::NDR
3537

36-
# Mini-mixin for making SMBUser/SMBPass/SMBDomain regular options vs advanced
37-
# Included when the module needs credentials to function
38-
module Authenticated
39-
def initialize(info = {})
40-
super
41-
register_options(
42-
[
43-
OptString.new('SMBUser', [ false, 'The username to authenticate as', '']),
44-
OptString.new('SMBPass', [ false, 'The password for the specified username', '']),
45-
OptString.new('SMBDomain', [ false, 'The Windows domain to use for authentication', 'WORKGROUP']),
46-
], Msf::Exploit::Remote::SMB::Authenticated)
47-
end
48-
end
49-
5038
def initialize(info = {})
5139
super
5240

@@ -90,6 +78,13 @@ def initialize(info = {})
9078
register_autofilter_services(%W{ netbios-ssn microsoft-ds })
9179
end
9280

81+
# Override {Exploit::Remote::Tcp#connect} to setup an SMB connection
82+
# and configure evasion options
83+
#
84+
# Also populates {#simple}.
85+
#
86+
# @param (see Exploit::Remote::Tcp#connect)
87+
# @return (see Exploit::Remote::Tcp#connect)
9388
def connect(global=true)
9489

9590
disconnect() if global
@@ -132,7 +127,12 @@ def unicode(str)
132127
Rex::Text.to_unicode(str)
133128
end
134129

135-
# This method establishes a SMB session over the default socket
130+
# Establishes an SMB session over the default socket and connects to
131+
# the IPC$ share.
132+
#
133+
# You should call {#connect} before calling this
134+
#
135+
# @return [void]
136136
def smb_login
137137
simple.login(
138138
datastore['SMBName'],
@@ -217,13 +217,55 @@ def splitname(uname)
217217
end
218218
end
219219

220+
# Whether a remote file exists
221+
#
222+
# @param file [String] Path to a file to remove, relative to the
223+
# most-recently connected share
224+
# @raise [Rex::Proto::SMB::Exceptions::ErrorCode]
225+
def smb_file_exist?(file)
226+
begin
227+
fd = simple.open(file, 'ro')
228+
rescue XCEPT::ErrorCode => e
229+
# If attempting to open the file results in a "*_NOT_FOUND" error,
230+
# then we can be sure the file is not there.
231+
#
232+
# Copy-pasted from smb/exceptions.rb to avoid the gymnastics
233+
# required to pull them out of a giant inverted hash
234+
#
235+
# 0xC0000034 => "STATUS_OBJECT_NAME_NOT_FOUND",
236+
# 0xC000003A => "STATUS_OBJECT_PATH_NOT_FOUND",
237+
# 0xC0000225 => "STATUS_NOT_FOUND",
238+
error_is_not_found = [ 0xC0000034, 0xC000003A, 0xC0000225 ].include?(e.error_code)
239+
# If the server returns some other error, then there was a
240+
# permissions problem or some other difficulty that we can't
241+
# really account for and hope the caller can deal with it.
242+
raise e unless error_is_not_found
243+
found = !error_is_not_found
244+
else
245+
# There was no exception, so we know the file is openable
246+
fd.close
247+
found = true
248+
end
249+
250+
found
251+
end
252+
253+
# Remove remote file
254+
#
255+
# @param file (see #smb_file_exist?)
256+
# @return [void]
257+
def smb_file_rm(file)
258+
fd = smb_open(file, 'ro')
259+
fd.delete
260+
end
261+
220262

221263
#
222264
# Fingerprinting methods
223265
#
224266

225267

226-
# This method the EnumPrinters() function of the spooler service
268+
# Calls the EnumPrinters() function of the spooler service
227269
def smb_enumprinters(flags, name, level, blen)
228270
stub =
229271
NDR.long(flags) +
@@ -632,10 +674,7 @@ def smb_fingerprint
632674
fprint
633675
end
634676

635-
#
636-
# Accessors
637-
#
638-
677+
# @return [Rex::Proto::SMB::SimpleClient]
639678
attr_accessor :simple
640679

641680
end
@@ -785,7 +824,6 @@ def smb_error(cmd, c, errorclass, esn = false)
785824
c.put(pkt.to_s)
786825
end
787826

788-
789827
end
790828

791829

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf
4+
5+
# Mini-mixin for making SMBUser/SMBPass/SMBDomain regular options vs advanced
6+
# Included when the module needs credentials to function
7+
module Exploit::Remote::SMB::Authenticated
8+
9+
include Msf::Exploit::Remote::SMB
10+
11+
def initialize(info = {})
12+
super
13+
register_options(
14+
[
15+
OptString.new('SMBUser', [ false, 'The username to authenticate as', '']),
16+
OptString.new('SMBPass', [ false, 'The password for the specified username', '']),
17+
OptString.new('SMBDomain', [ false, 'The Windows domain to use for authentication', 'WORKGROUP']),
18+
], Msf::Exploit::Remote::SMB::Authenticated)
19+
end
20+
end
21+
22+
end

0 commit comments

Comments
 (0)