Created
February 24, 2012 22:17
-
-
Save Zapotek/1904148 to your computer and use it in GitHub Desktop.
Arachni scripting example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# You need to grab the latest code from: | |
# https://github.com/Zapotek/arachni/tree/experimental | |
# | |
# for this to work. | |
# | |
# require_relative '../lib/arachni/ui/cli/output' | |
# require_relative '../lib/arachni' | |
require 'arachni/ui/cli/output' | |
require 'arachni' | |
# shut the system up | |
Arachni::UI::Output.mute! | |
# get an instance of the options class | |
opts = Arachni::Options.instance | |
# this is the seed URL | |
opts.url = 'http://testfire.net' | |
http = Arachni::HTTP.instance | |
sync_http_opts = { async: false, remove_id: true } | |
# | |
# First approach, fetch the whole page and work with its elements | |
# | |
# get the response for page that has the elements you want to test | |
response = http.get( opts.url.to_s, sync_http_opts ).response | |
# create a new page from the response | |
# | |
# the page now has links, forms, cookies, response and request headers, a list of all paths | |
# and other stuff | |
# | |
page = Arachni::Parser::Page.from_http_response( response, opts ) | |
# | |
# you can then go through: | |
# * page.links | |
# * page.forms | |
# * page.cookies | |
# * page.headers | |
# | |
# and find the element you wish to test or create your own element to test | |
# like so: | |
# | |
# first we need an auditor to provide some stuff all Auditable elements need | |
# | |
class Auditor | |
include Arachni::Module::Auditor | |
def http; Arachni::HTTP.instance end | |
def self.info; { name: 'Auditor' } end | |
end | |
# create the element you want to test | |
search_form = Arachni::Parser::Element::Form.new( | |
# used as an action | |
opts.url.to_s + '/search.aspx', | |
method: 'get', | |
# obvious | |
inputs: { 'txtSearch' => 'Search for me!' } | |
) | |
# assign an auditor | |
search_form.auditor = Auditor.new | |
# submit the element asynchronously, that way you get better performance | |
# when performing multiple requests | |
search_form.submit.on_complete { | |
|res| | |
# get the response | |
ap res.body | |
} | |
# run the scheduled HTTP requests | |
http.run | |
# or perform the request synchronously to avoid callback spagheti code | |
ap search_form.submit( sync_http_opts ).response | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment