@@ -53,8 +53,8 @@ def initialize(info = {})
53
53
54
54
register_advanced_options ( [
55
55
OptString . new ( 'FILEPREFIX' , [ false , 'Add a custom prefix to the temporary files' , '' ] ) ,
56
- OptInt . new ( 'DELAY' , [ true , 'Wait this many seconds before reading output and cleaning up' , 1 ] ) ,
57
- OptInt . new ( 'RETRY' , [ true , 'Retry this many times to check if the process is complete' , 10 ] ) ,
56
+ OptInt . new ( 'DELAY' , [ true , 'Wait this many seconds before reading output and cleaning up' , 0 ] ) ,
57
+ OptInt . new ( 'RETRY' , [ true , 'Retry this many times to check if the process is complete' , 0 ] ) ,
58
58
OptPath . new ( 'LOGDIR' , [ false , 'File to log output' , nil ] ) ,
59
59
] , self . class )
60
60
@@ -82,16 +82,16 @@ def run_host(ip)
82
82
end
83
83
res = execute_command ( text , bat )
84
84
85
- for i in 0 ..( datastore [ 'RETRY' ] )
86
- sleep datastore [ 'DELAY' ]
87
- # if the output file is still locked then the program is still likely running
88
- if ( exclusive_access ( text ) )
89
- break
90
- elsif ( i == datastore [ 'RETRY' ] )
91
- print_error ( "Command seems to still be executing. Try increasing RETRY and DELAY" )
92
- end
93
- end
94
85
if res
86
+ for i in 0 ..( datastore [ 'RETRY' ] )
87
+ Rex . sleep ( datastore [ 'DELAY' ] )
88
+ # if the output file is still locked then the program is still likely running
89
+ if ( exclusive_access ( text ) )
90
+ break
91
+ elsif ( i == datastore [ 'RETRY' ] )
92
+ print_error ( "Command seems to still be executing. Try increasing RETRY and DELAY" )
93
+ end
94
+ end
95
95
get_output ( text )
96
96
end
97
97
@@ -129,27 +129,20 @@ def get_output(file)
129
129
log_dir = ::File . join ( Msf ::Config . log_directory , 'scripts' , 'psexec_command' )
130
130
::FileUtils . mkdir_p ( log_dir )
131
131
132
- # Define log filename
133
- timestamp = ::Time . now . strftime ( '%Y%m%d:%H%M%S' )
134
- filename = "#{ datastore [ 'RHOSTS' ] } _#{ timestamp } "
135
- if ( datastore [ 'LOGDIR' ] . nil? )
136
- log_file = ::File . join ( log_dir , "#{ filename } .txt" )
137
- else
138
- log_file = ::File . join ( datastore [ 'LOGDIR' ] , "#{ filename } .txt" )
139
- end
140
-
132
+ # Report output
141
133
print_good ( "#{ peer } - Command completed successfuly!" )
142
- print_status ( "Logging output to #{ log_file } ." )
143
- output = "# CMD: #{ datastore [ 'COMMAND' ] } " + output
144
-
145
- fd = ::File . new ( log_file , 'w+' )
146
- fd . write ( output )
147
- fd . close ( )
148
-
149
- if datastore [ "VERBOSE" ]
150
- print_status ( "Output:" )
134
+ if datastore [ 'VERBOSE' ]
135
+ print_status ( "Output for \" #{ datastore [ 'COMMAND' ] } \" :" )
151
136
print_line ( "#{ output } " )
152
137
end
138
+
139
+ report_note (
140
+ :host => datastore [ 'RHOSTS' ] ,
141
+ :type => "psexec_command" ,
142
+ :name => datastore [ 'COMMAND' ] ,
143
+ :data => output
144
+ )
145
+
153
146
end
154
147
155
148
#check if our process is done using these files
@@ -164,6 +157,7 @@ def exclusive_access(*files)
164
157
print_status ( "#{ peer } - Unable to get handle: #{ accesserror } " )
165
158
return false
166
159
end
160
+ simple . disconnect ( "\\ \\ #{ @ip } \\ #{ @smbshare } " )
167
161
end
168
162
return true
169
163
end
0 commit comments