Class: Arachni::Trainer
- Includes:
- ElementFilter, Module::Output, Utilities
- Defined in:
- lib/arachni/trainer.rb
Overview
Trainer class
Analyzes key HTTP responses looking for new auditable elements.
Constant Summary collapse
- MAX_TRAININGS_PER_URL =
25
Instance Method Summary collapse
-
#initialize(framework) ⇒ Trainer
constructor
A new instance of Trainer.
- #on_new_page(&block) ⇒ Object
-
#page=(page) ⇒ Object
(also: #init)
Sets the current working page and inits the element DB.
-
#push(res) ⇒ Object
Passes the response on for analysis.
Methods included from Utilities
#available_port, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #follow_protocol?, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #generate_token, #get_path, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #redundant_path?, #remove_constants, #seed, #skip_page?, #skip_path?, #skip_resource?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize
Methods included from ElementFilter
#cookie_in_jar?, #init_cookies, #init_db_from_page, #init_forms, #init_links, reset, #update_cookies, #update_forms, #update_links
Methods included from Module::Output
#fancy_name, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose
Methods included from UI::Output
#debug?, #debug_off, #debug_on, #disable_only_positives, #error_logfile, #flush_buffer, #log_error, #mute, #muted?, old_reset_output_options, #only_positives, #only_positives?, #print_bad, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_error_backtrace, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?, reset_output_options, #set_buffer_cap, #set_error_logfile, #uncap_buffer, #unmute, #verbose, #verbose?
Constructor Details
#initialize(framework) ⇒ Trainer
Returns a new instance of Trainer.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/arachni/trainer.rb', line 37 def initialize( framework ) @framework = framework @updated = false @on_new_page_blocks = [] @trainings_per_url = Hash.new( 0 ) # get us setup using the page that is being audited as a seed page framework.on_audit_page { |page| self.page = page } HTTP.add_on_complete do |response| next if !response.request.train? if response.redirection? && response.location.is_a?( String ) reference_url = @page ? @page.url : @framework.opts.url HTTP.get( to_absolute( response.location, reference_url ) ) do |res| push res end next end push response end end |
Instance Method Details
#on_new_page(&block) ⇒ Object
119 120 121 |
# File 'lib/arachni/trainer.rb', line 119 def on_new_page( &block ) @on_new_page_blocks << block end |
#page=(page) ⇒ Object Also known as: init
Sets the current working page and inits the element DB.
113 114 115 116 |
# File 'lib/arachni/trainer.rb', line 113 def page=( page ) init_db_from_page( page ) @page = page.deep_clone end |
#push(res) ⇒ Object
Passes the response on for analysis.
If the response contains new elements it creates a new page with those elements and pushes it a buffer.
These new pages can then be retrieved by flushing the buffer (#flush).
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/arachni/trainer.rb', line 72 def push( res ) if !@page print_debug 'No seed page assigned yet.' return end if @framework.link_count_limit_reached? print_verbose 'Link count limit reached, skipping analysis.' return false end @parser = Parser.new( res ) return false if !@parser.text? = nil if @trainings_per_url[@parser.url] >= MAX_TRAININGS_PER_URL = "Reached maximum trainings (#{MAX_TRAININGS_PER_URL})" elsif redundant_path?( @parser.url ) = 'Matched redundancy filters' elsif skip_resource?( res ) = 'Matched exclusion criteria' end if print_verbose "#{}, skipping: #{@parser.url}" return false end analyze( res ) true rescue => e print_error( e.to_s ) print_error_backtrace( e ) end |