lib/arachni/session.rb in arachni-1.4 vs lib/arachni/session.rb in arachni-1.5
- old
+ new
@@ -1,7 +1,7 @@
=begin
- Copyright 2010-2016 Tasos Laskos <tasos.laskos@arachni-scanner.com>
+ Copyright 2010-2017 Sarosys LLC <http://www.sarosys.com>
This file is part of the Arachni Framework project and is subject to
redistribution and commercial restrictions. Please see the Arachni Framework
web site for more information on licensing and terms of use.
=end
@@ -199,24 +199,24 @@
print_bad 'The scanner has been logged out.'
print_info 'Trying to re-login...'
LOGIN_TRIES.times do |i|
- break if !login.response.timed_out? rescue Error
+ self.login
+ if self.logged_in?
+ print_ok 'Logged-in successfully.'
+ return true
+ end
+
print_bad "Login attempt #{i+1} failed, retrying after " <<
"#{LOGIN_RETRY_WAIT} seconds..."
sleep LOGIN_RETRY_WAIT
end
- if logged_in?
- print_ok 'Logged-in successfully.'
- true
- else
- print_bad 'Could not re-login.'
- false
- end
+ print_bad 'Could not re-login.'
+ false
end
# @param [Block] block
# Login sequence. Must return the resulting {Page}.
#
@@ -254,12 +254,12 @@
shutdown_browser
end
# @param [Block] block
# Block to be passed the {#browser}.
- def with_browser( &block )
- block.call browser
+ def with_browser( *args, &block )
+ block.call browser, *args
end
# @param [Hash] http_options
# HTTP options to use for the check.
# @param [Block] block
@@ -345,11 +345,11 @@
form = find_login_form(
# We need to reparse the body in order to override the scope
# and thus extract even out-of-scope forms in case we're dealing
# with a Single-Sign-On situation.
- forms: forms_from_document( page.url, page.body, true ),
+ forms: forms_from_parser( page.parser, true ),
inputs: configuration[:inputs].keys
)
if !form
print_debug_level_2 page.body
@@ -377,10 +377,29 @@
print_debug "Updated form inputs: #{form.inputs}"
page = nil
if has_browser?
print_debug 'Submitting form.'
- form.submit { |p| page = p }
+
+ click_button = configuration[:inputs].
+ find { |k, _| form.parent.details_for( k )[:type] == :submit }
+
+ if click_button
+ click_button = click_button.first
+
+ transitions = []
+ transitions << browser.fire_event( form.locate, :fill, inputs: form.inputs )
+ transitions << browser.fire_event( Browser::ElementLocator.new(
+ tag_name: :input,
+ attributes: form.parent.details_for( click_button )
+ ), :click )
+
+ page = browser.to_page
+ page.dom.transitions += transitions
+ else
+ form.submit { |p| page = p }
+ end
+
print_debug 'Form submitted.'
else
page = form.submit(
mode: :sync,
follow_location: false,