0

I have visited this page, and unsuccessfully tried those solutions.

I'm running on Windows 10. I have this batch (cmd.exe) file for Arachni security scanner:

enter image description here

enter image description here

arachni ^
--audit-forms ^
--audit-jsons ^
--audit-links ^
--audit-ui-forms ^
--audit-ui-inputs ^
--audit-xmls ^
--browser-cluster-ignore-images ^
--browser-cluster-job-timeout=90 ^
--browser-cluster-pool-size=3 ^
--checks=trainer ^
--http-request-queue-size=100 ^
--http-request-redirect-limit=3 ^
--http-request-timeout=30000 ^
--http-response-max-size=500000 ^
--http-user-agent="PhantomJS / arachni v1.5.1-0.5.12-windows-x86_64" ^
--plugin=login_script:script=%~dp0\LoginScript.rb ^
https://www.example.com

The Login Script (penultimate line from the batch script above) helps me to login into the application and start the scan. Part of the Login Script (.rb extension) looks like below:

begin
browser.text_field(:id => 'myTextField').wait_until_present(60)
puts 'User successfully lands on MyWebSite home page with the URL ' + browser.url
rescue
puts 'Even after 60 seconds of waiting still unable to reach MyWebSite home page'
exit
end

As it can be seen from the rescue statement, I'm trying to terminate / close / finish / kill the entire batch job if certain element is not found (Watir WebDriver in the nutshell). I can clearly see that Even after 60 seconds of waiting still unable to reach MyWebSite home page message is displayed in the console, meaning rescue statement gets executed, but after that scan just continues further as nothing tries to stop it. Below are different variations what I tried to put instead of exit statement:

  1. exit 1
  2. abort('Aborting the scan')
  3. raise RuntimeError, 'Aborting the scan'
  4. system('exit')

None of them worked in my situation...

Is this ever possible to stop the scan (literally the batch job) from Ruby script?

TiredOfProgramming
  • 845
  • 2
  • 16
  • 41
  • None of your code is a Windows batch-file that I can tell. – Squashman Aug 09 '18 at 15:18
  • @Squashman added screenshot for clarification. The Login Script is the Ruby .rb file, I just pasted part of it into the question. But this script is being called from the batch job – TiredOfProgramming Aug 09 '18 at 15:21
  • You're only exiting the login script with `exit`. What happens if you exit the whole browser with `browser.quit` instead? – Casper Aug 09 '18 at 15:30
  • @Casper yes, browser.quit will work in this specific situation, but I rather was looking for more general solution within Ruby world.... – TiredOfProgramming Aug 09 '18 at 15:44
  • I looked at the source code of Arachni, and there is really no other way around it. Arachni will not even check the exit code of the login script. This is perhaps even worthy of opening a bug issue with the developers. But anyway, this is more of a logistics issue in the Arachni code than a Ruby issue. – Casper Aug 09 '18 at 16:04
  • Here's the code if you want to take a look: https://github.com/Arachni/arachni/blob/master/components/plugins/login_script.rb#L29 – Casper Aug 09 '18 at 16:09

1 Answers1

1

I'm not sure if I got the question right, but it's worth a try. Tried it on Windows 10 and it successfully killed any other running process before exiting the script.

begin   
    fail #lets test fail    
    puts 'User successfully lands on MyWebSite home page with the URL ' + browser.url
rescue
    puts 'Even after 60 seconds of waiting still unable to reach MyWebSite home page'

    success = `Taskkill /IM batch_name.bat /F`
    puts "Killed: #{success}"

    exit #not neccessery?
end

I assume you can also get the batch pid via tasklist and then kill it via /PID as described on link below.

`Taskkill /PID 26356 /F`

https://tweaks.com/windows/39559/kill-processes-from-command-prompt/

Hope it helps.

Luka Vladika
  • 76
  • 1
  • 5