Module: Arachni::Utilities
- Extended by:
- Utilities
- Included in:
- Element::Base, Element::Capabilities::Auditable, Framework, HTTP, HTTP::CookieJar, Mixins::Observable, Module::Base, Module::Base, Module::Manager, Module::Trainer, Module::Utilities, Parser, Plugin::Manager, Plugin::Manager, RPC::Server::Dispatcher, RPC::Server::Framework, RPC::Server::Instance, Report::Manager, Report::Manager, Session, Spider, Arachni::UI::CLI, Arachni::UI::RPC, Arachni::UI::Web::Server, URI, URI, Utilities
- Defined in:
- lib/arachni/utilities.rb
Overview
Includes some useful methods for the system, the modules etc…
Instance Method Summary collapse
- #cookie_encode(*args) ⇒ Object
- #cookies_from_document(*args) ⇒ Object
- #cookies_from_file(*args) ⇒ Object
- #cookies_from_response(*args) ⇒ Object
-
#exception_jail(raise_exception = true, &block) ⇒ Object
Wraps the “block” in exception handling code and runs it.
-
#exclude_path?(url) ⇒ Bool
Decides whether the given
urlmatches any framework exclusion rules. -
#extract_domain(url) ⇒ String
Domain name.
- #form_decode(*args) ⇒ Object
- #form_encode(*args) ⇒ Object
- #form_parse_request_body(*args) ⇒ Object (also: #parse_request_body)
- #forms_from_document(*args) ⇒ Object
- #forms_from_response(*args) ⇒ Object
-
#get_path(url) ⇒ String
Path full URL up to the path component (no resource, query etc.).
-
#hash_keys_to_str(hash) ⇒ Hash
Recursively converts a Hash’s keys to strings.
- #html_decode(str) ⇒ Object (also: #html_unescape)
- #html_encode(str) ⇒ Object (also: #html_escape)
-
#include_path?(url) ⇒ Bool
Decides whether the given
urlmatches any framework inclusion rules. - #links_from_document(*args) ⇒ Object
- #links_from_response(*args) ⇒ Object
- #normalize_url(url) ⇒ Object
- #page_from_response(*args) ⇒ Object
- #page_from_url(*args, &block) ⇒ Object
- #parse_query(*args) ⇒ Object
- #parse_set_cookie(*args) ⇒ Object
- #parse_url_vars(*args) ⇒ Object
-
#path_in_domain?(url, reference = Options.url) ⇒ Bool
Compares 2 urls in order to decide whether or not they belong to the same domain.
-
#path_too_deep?(url) ⇒ Bool
trueis the path exceeds the framework limit,falseotherwise. - #remove_constants(mod, skip = [], children_only = true) ⇒ Object
-
#seed ⇒ String
Random HEX (SHA2) string.
-
#skip_path?(path) ⇒ Bool
Decides whether or not the provided
pathshould be skipped based on: * #include_path? * #exclude_path? * #path_too_deep? * #path_in_domain?. - #to_absolute(relative_url, reference_url = Options.instance.url.to_s) ⇒ Object
- #uri_decode(url) ⇒ Object
- #uri_encode(string, bad_characters = nil) ⇒ Object
- #uri_parse(url) ⇒ Object
-
#uri_parser ⇒ URI::Parser
Cached URI parser.
- #url_sanitize(url) ⇒ Object
Instance Method Details
#cookie_encode(*args) ⇒ Object
99 100 101 |
# File 'lib/arachni/utilities.rb', line 99 def ( *args ) Cookie.encode( *args ) end |
#cookies_from_document(*args) ⇒ Object
85 86 87 |
# File 'lib/arachni/utilities.rb', line 85 def ( *args ) Cookie.from_document( *args ) end |
#cookies_from_file(*args) ⇒ Object
94 95 96 |
# File 'lib/arachni/utilities.rb', line 94 def ( *args ) Cookie.from_file( *args ) end |
#cookies_from_response(*args) ⇒ Object
80 81 82 |
# File 'lib/arachni/utilities.rb', line 80 def ( *args ) Cookie.from_response( *args ) end |
#exception_jail(raise_exception = true, &block) ⇒ Object
Wraps the “block” in exception handling code and runs it.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/arachni/utilities.rb', line 275 def exception_jail( raise_exception = true, &block ) block.call rescue Exception => e begin print_error e.inspect print_error_backtrace e print_error print_error 'Parent:' print_error self.class.to_s print_error print_error 'Block:' print_error block.to_s print_error print_error 'Caller:' ::Kernel.caller.each { |l| print_error l } print_error '-' * 80 rescue end raise e if raise_exception end |
#exclude_path?(url) ⇒ Bool
Decides whether the given url matches any framework exclusion rules.
212 213 214 |
# File 'lib/arachni/utilities.rb', line 212 def exclude_path?( url ) uri_parse( url ).exclude?( Options.exclude ) end |
#extract_domain(url) ⇒ String
Returns domain name.
175 176 177 |
# File 'lib/arachni/utilities.rb', line 175 def extract_domain( url ) uri_parse( url ).domain end |
#form_decode(*args) ⇒ Object
51 52 53 |
# File 'lib/arachni/utilities.rb', line 51 def form_decode( *args ) Form.decode( *args ) end |
#form_encode(*args) ⇒ Object
46 47 48 |
# File 'lib/arachni/utilities.rb', line 46 def form_encode( *args ) Form.encode( *args ) end |
#form_parse_request_body(*args) ⇒ Object Also known as: parse_request_body
56 57 58 |
# File 'lib/arachni/utilities.rb', line 56 def form_parse_request_body( *args ) Form.parse_request_body( *args ) end |
#forms_from_document(*args) ⇒ Object
41 42 43 |
# File 'lib/arachni/utilities.rb', line 41 def forms_from_document( *args ) Form.from_document( *args ) end |
#forms_from_response(*args) ⇒ Object
36 37 38 |
# File 'lib/arachni/utilities.rb', line 36 def forms_from_response( *args ) Form.from_response( *args ) end |
#get_path(url) ⇒ String
Returns path full URL up to the path component (no resource, query etc.).
164 165 166 |
# File 'lib/arachni/utilities.rb', line 164 def get_path( url ) uri_parse( url ).up_to_path end |
#hash_keys_to_str(hash) ⇒ Hash
Recursively converts a Hash’s keys to strings
260 261 262 263 264 265 266 267 |
# File 'lib/arachni/utilities.rb', line 260 def hash_keys_to_str( hash ) nh = {} hash.each_pair do |k, v| nh[k.to_s] = v nh[k.to_s] = hash_keys_to_str( v ) if v.is_a? Hash end nh end |
#html_decode(str) ⇒ Object Also known as: html_unescape
112 113 114 |
# File 'lib/arachni/utilities.rb', line 112 def html_decode( str ) ::CGI.unescapeHTML( str.to_s ) end |
#html_encode(str) ⇒ Object Also known as: html_escape
117 118 119 |
# File 'lib/arachni/utilities.rb', line 117 def html_encode( str ) ::CGI.escapeHTML( str.to_s ) end |
#include_path?(url) ⇒ Bool
Decides whether the given url matches any framework inclusion rules.
223 224 225 |
# File 'lib/arachni/utilities.rb', line 223 def include_path?( url ) uri_parse( url ).include?( Options.include ) end |
#links_from_document(*args) ⇒ Object
67 68 69 |
# File 'lib/arachni/utilities.rb', line 67 def links_from_document( *args ) Link.from_document( *args ) end |
#links_from_response(*args) ⇒ Object
62 63 64 |
# File 'lib/arachni/utilities.rb', line 62 def links_from_response( *args ) Link.from_response( *args ) end |
#normalize_url(url) ⇒ Object
148 149 150 |
# File 'lib/arachni/utilities.rb', line 148 def normalize_url( url ) URI.normalize( url ) end |
#page_from_response(*args) ⇒ Object
104 105 106 |
# File 'lib/arachni/utilities.rb', line 104 def page_from_response( *args ) Page.from_response( *args ) end |
#page_from_url(*args, &block) ⇒ Object
108 109 110 |
# File 'lib/arachni/utilities.rb', line 108 def page_from_url( *args, &block ) Page.from_url( *args, &block ) end |
#parse_query(*args) ⇒ Object
75 76 77 |
# File 'lib/arachni/utilities.rb', line 75 def parse_query( *args ) Link.parse_query_vars( *args ) end |
#parse_set_cookie(*args) ⇒ Object
89 90 91 |
# File 'lib/arachni/utilities.rb', line 89 def ( *args ) Cookie.( *args ) end |
#parse_url_vars(*args) ⇒ Object
72 73 74 |
# File 'lib/arachni/utilities.rb', line 72 def parse_url_vars( *args ) Link.parse_query_vars( *args ) end |
#path_in_domain?(url, reference = Options.url) ⇒ Bool
Compares 2 urls in order to decide whether or not they belong to the same domain.
201 202 203 |
# File 'lib/arachni/utilities.rb', line 201 def path_in_domain?( url, reference = Options.url ) uri_parse( url ).in_domain?( !Options.follow_subdomains, reference ) end |
#path_too_deep?(url) ⇒ Bool
Returns true is the path exceeds the framework limit, false otherwise.
186 187 188 |
# File 'lib/arachni/utilities.rb', line 186 def path_too_deep?( url ) uri_parse( url ).too_deep?( Options.depth_limit ) end |
#remove_constants(mod, skip = [], children_only = true) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/arachni/utilities.rb', line 296 def remove_constants( mod, skip = [], children_only = true ) return if skip.include?( mod ) return if !(mod.is_a?( Class ) || !mod.is_a?( Module )) || !mod.to_s.start_with?( 'Arachni' ) parent = Object mod.to_s.split( '::' )[0..-2].each do |ancestor| parent = parent.const_get( ancestor.to_sym ) end mod.constants.each { |m| mod.send( :remove_const, m ) } return if children_only parent.send( :remove_const, mod.to_s.split( ':' ).last.to_sym ) end |
#seed ⇒ String
Returns random HEX (SHA2) string.
31 32 33 |
# File 'lib/arachni/utilities.rb', line 31 def seed @@seed ||= Digest::SHA2.hexdigest( srand( 1000 ).to_s ) end |
#skip_path?(path) ⇒ Bool
Decides whether or not the provided path should be skipped based on:
238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/arachni/utilities.rb', line 238 def skip_path?( path ) return true if !path parsed = uri_parse( path ) begin return true if !include_path?( parsed ) return true if exclude_path?( parsed ) return true if path_too_deep?( parsed ) return true if !path_in_domain?( parsed ) false rescue true end end |
#to_absolute(relative_url, reference_url = Options.instance.url.to_s) ⇒ Object
143 144 145 |
# File 'lib/arachni/utilities.rb', line 143 def to_absolute( relative_url, reference_url = Options.instance.url.to_s ) URI.to_absolute( relative_url, reference_url ) end |
#uri_decode(url) ⇒ Object
138 139 140 |
# File 'lib/arachni/utilities.rb', line 138 def uri_decode( url ) URI.decode( url ) end |
#uri_encode(string, bad_characters = nil) ⇒ Object
133 134 135 |
# File 'lib/arachni/utilities.rb', line 133 def uri_encode( string, bad_characters = nil ) URI.encode( string, bad_characters ) end |
#uri_parse(url) ⇒ Object
128 129 130 |
# File 'lib/arachni/utilities.rb', line 128 def uri_parse( url ) URI.parse( url ) end |
#uri_parser ⇒ URI::Parser
Returns cached URI parser.
123 124 125 |
# File 'lib/arachni/utilities.rb', line 123 def uri_parser URI.parser end |
#url_sanitize(url) ⇒ Object
153 154 155 |
# File 'lib/arachni/utilities.rb', line 153 def url_sanitize( url ) normalize_url( url ) end |