@@ -99,9 +99,9 @@ def execute_command(text, bat)
99
99
print_status ( "Executing the command..." )
100
100
begin
101
101
return psexec ( execute )
102
- rescue Rex ::Proto ::DCERPC ::Exceptions ::Error , Rex ::Proto ::SMB ::Exceptions ::Error => exec_command_error
102
+ rescue Rex ::Proto ::DCERPC ::Exceptions ::Error , Rex ::Proto ::SMB ::Exceptions ::Error => e
103
103
elog ( "#{ e . class } #{ e . message } \n #{ e . backtrace * "\n " } " , 'rex' , LEV_3 )
104
- print_error ( "Unable to execute specified command: #{ exec_command_error } " )
104
+ print_error ( "Unable to execute specified command: #{ e } " )
105
105
return false
106
106
end
107
107
end
@@ -136,8 +136,13 @@ def get_output(file)
136
136
137
137
# check if our process is done using these files
138
138
def exclusive_access ( *files )
139
+ begin
139
140
simple . connect ( "\\ \\ #{ @ip } \\ #{ @smbshare } " )
140
- files . each do |file |
141
+ rescue Rex ::Proto ::SMB ::Exceptions ::ErrorCode => accesserror
142
+ print_status ( "Unable to get handle: #{ accesserror } " )
143
+ return false
144
+ end
145
+ files . each do |file |
141
146
begin
142
147
print_status ( "checking if the file is unlocked" )
143
148
fd = smb_open ( file , 'rwo' )
@@ -154,7 +159,12 @@ def exclusive_access(*files)
154
159
155
160
# Removes files created during execution.
156
161
def cleanup_after ( *files )
157
- simple . connect ( "\\ \\ #{ @ip } \\ #{ @smbshare } " )
162
+ begin
163
+ simple . connect ( "\\ \\ #{ @ip } \\ #{ @smbshare } " )
164
+ rescue Rex ::Proto ::SMB ::Exceptions ::ErrorCode => accesserror
165
+ print_error ( "Unable to connect for cleanup: #{ accesserror } . Maybe you'll need to manually remove #{ files . join ( ", " ) } from the target." )
166
+ return
167
+ end
158
168
print_status ( "Executing cleanup..." )
159
169
files . each do |file |
160
170
begin
0 commit comments