4
4
require 'rex/proto/dcerpc'
5
5
require 'rex/encoder/ndr'
6
6
7
-
8
7
module Msf
9
8
10
9
###
@@ -18,6 +17,9 @@ module Msf
18
17
19
18
module Exploit ::Remote ::SMB
20
19
20
+ require 'msf/core/exploit/smb/authenticated'
21
+ require 'msf/core/exploit/smb/psexec'
22
+
21
23
include Exploit ::Remote ::Tcp
22
24
include Exploit ::Remote ::NTLM ::Client
23
25
@@ -33,20 +35,6 @@ module Exploit::Remote::SMB
33
35
DCERPCUUID = Rex ::Proto ::DCERPC ::UUID
34
36
NDR = Rex ::Encoder ::NDR
35
37
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
-
50
38
def initialize ( info = { } )
51
39
super
52
40
@@ -90,6 +78,13 @@ def initialize(info = {})
90
78
register_autofilter_services ( %W{ netbios-ssn microsoft-ds } )
91
79
end
92
80
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)
93
88
def connect ( global = true )
94
89
95
90
disconnect ( ) if global
@@ -132,7 +127,12 @@ def unicode(str)
132
127
Rex ::Text . to_unicode ( str )
133
128
end
134
129
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]
136
136
def smb_login
137
137
simple . login (
138
138
datastore [ 'SMBName' ] ,
@@ -217,13 +217,55 @@ def splitname(uname)
217
217
end
218
218
end
219
219
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
+
220
262
221
263
#
222
264
# Fingerprinting methods
223
265
#
224
266
225
267
226
- # This method the EnumPrinters() function of the spooler service
268
+ # Calls the EnumPrinters() function of the spooler service
227
269
def smb_enumprinters ( flags , name , level , blen )
228
270
stub =
229
271
NDR . long ( flags ) +
@@ -632,10 +674,7 @@ def smb_fingerprint
632
674
fprint
633
675
end
634
676
635
- #
636
- # Accessors
637
- #
638
-
677
+ # @return [Rex::Proto::SMB::SimpleClient]
639
678
attr_accessor :simple
640
679
641
680
end
@@ -785,7 +824,6 @@ def smb_error(cmd, c, errorclass, esn = false)
785
824
c . put ( pkt . to_s )
786
825
end
787
826
788
-
789
827
end
790
828
791
829
0 commit comments