Method: Uirusu::CLI::Application#scan_and_wait
- Defined in:
- lib/uirusu/cli/application.rb
#scan_and_wait(mod, resource, attempts) ⇒ Object
Submits a file/url and waits for analysis to be complete and returns the results.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/uirusu/cli/application.rb', line 221 def scan_and_wait(mod, resource, attempts) method = nil retries = attempts if mod.name == "Uirusu::VTFile" STDERR.puts "[*] Attempting to rescan #{resource}" if ['verbose'] method = ['rescan'] ? mod.method(:rescan_file) : mod.method(:scan_file) else STDERR.puts "[*] Attempting to upload file #{resource}" if ['verbose'] method = mod.method :scan_url end begin result = method.call(@config['virustotal']['api-key'], resource) rescue => e if ['rescan'] STDERR.puts "[!] An error has occurred with the rescan request. Retrying 60 seconds up #{retries} retries: #{e.message}\n" if ['verbose'] else STDERR.puts "[!] An error has occurred uploading the file. Retrying 60 seconds up #{retries} retries.\n" if ['verbose'] end if retries >= 0 sleep 60 retries = retries - 1 retry end end begin # Convert all single result replies to an array. This is because # rescan_file returns an array of results if more than one hash # is requested to be rescanned. result_array = result.is_a?(Array) ? result : [ result ] result_array.collect do |r| if r['response_code'] == 1 STDERR.puts "[*] Attempting to parse the results for: #{r['resource']}" if ['verbose'] results = mod.query_report(@config['virustotal']['api-key'], r['resource']) while results['response_code'] != 1 STDERR.puts "[*] File has not been analyized yet, waiting 60 seconds to try again" if ['verbose'] sleep 60 results = mod.query_report(@config['virustotal']['api-key'], r['resource']) end return r['resource'], results elsif r['response_code'] == 0 and ['rescan'] STDERR.puts "[!] Unknown Virustotal error for rescan of #{r['resource']}." if ['verbose'] next elsif r['response_code'] == -1 and ['rescan'] STDERR.puts "[!] Virustotal does not have a sample of #{r['resource']}." if ['verbose'] next elsif r['response_code'] == -2 STDERR.puts "[!] Virustotal limits exceeded, ***do not edit the timeout values.***" exit(1) else nil end end rescue => e STDERR.puts "[!] An error has occurred retrieving the report. Retrying 60 seconds up #{retries} retries. #{e.message}\n" if ['verbose'] if retries >= 0 sleep 60 retries = retries - 1 retry end end end |