<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zapotek&#039;s train of thought...</title>
	<atom:link href="http://trainofthought.segfault.gr/feed/" rel="self" type="application/rss+xml" />
	<link>http://trainofthought.segfault.gr</link>
	<description>Stretching the boundaries of logic &#38; rationality...</description>
	<lastBuildDate>Wed, 16 May 2012 00:24:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Roundabout &#8211; A high-performance, distributed crawler</title>
		<link>http://trainofthought.segfault.gr/2012/05/16/roundabout-a-high-performance-distributed-crawler/</link>
		<comments>http://trainofthought.segfault.gr/2012/05/16/roundabout-a-high-performance-distributed-crawler/#comments</comments>
		<pubDate>Wed, 16 May 2012 00:24:43 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[crawl]]></category>
		<category><![CDATA[distributed]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[high performance]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[workload]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=2083</guid>
		<description><![CDATA[When I started development on the Arachni high-performance grid my focus was on the audit part, i.e. find a way to distribute the audit of batches of individual elements across multiple nodes and avoid duplication of effort amongst them. It was a bit tricky to get right but it turned out to be quite do-able [...]]]></description>
			<content:encoded><![CDATA[<p>When I started development on the Arachni high-performance grid my focus was on the audit part, i.e. find a way to distribute the audit of batches of individual elements across multiple nodes and avoid duplication of effort amongst them.<br />
It was a bit tricky to get right but it turned out to be quite do-able and worthwhile.</p>
<p>However, the crawl was done the old fashioned way, the master instance would crawl the targeted website and once completed it would then analyze all the pages it found and spread the workload.<br />
I always intended to try out my hand on something similar but aimed towards the crawling process but it wasn&#8217;t a high priority.<br />
But, as you can see from my last post, I did sort of figure it out, although I hadn&#8217;t had a chance to implement it until now.</p>
<p>This is tricky to do because there&#8217;s no way of knowing the workload before hand as it is basically a freaking labyrinth and precious information (new paths) can be hidden behind walls and walls of crap.</p>
<p>On the other hand, since when running Arachni in HPG mode you already have a few nodes up and running in the first place, why not utilize them a bit more &#8212; even if it turns out to be only slightly faster than a single crawler.</p>
<p>With that in mind, I yesterday started to implement that sort of a crawler, and <a href="https://github.com/Zapotek/Roundabout">here it is</a>.<br />
Its sole existence is that of a toy, a fun experiment, and not as a stable system. I may, in the future, put some more effort into it but my main reason for doing this is to explore this idea and eventually port it over to Arachni.</p>
<p>If you find this interesting, want to help out in researching or have any sort of feedback or just want to get in touch don&#8217;t hesitate to do so.</p>
<p>Cheers,<br />
Tasos L.</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2012/05/16/roundabout-a-high-performance-distributed-crawler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Distributing the crawl</title>
		<link>http://trainofthought.segfault.gr/2012/01/19/distributing-the-crawl/</link>
		<comments>http://trainofthought.segfault.gr/2012/01/19/distributing-the-crawl/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 10:06:28 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[crawl]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[grid]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=2031</guid>
		<description><![CDATA[This one had been bugging me since I first started work on the HPG. The gain you get from distributed computing is directly related to how efficient the workload distribution is &#8212; which makes sense. The crawling process though doesn&#8217;t consist of a workload per se but rather looks for the workload. Also, the difficulty [...]]]></description>
			<content:encoded><![CDATA[<p>This one had been bugging me since I first started work on the HPG.<br />
The gain you get from distributed computing is directly related to how efficient the workload distribution is &#8212; which makes sense.<br />
The crawling process though doesn&#8217;t consist of a <em>workload</em> per se but rather <em>looks</em> for the workload.<br />
Also, the difficulty of the crawl doesn&#8217;t lie in parsing or following the paths but actually finding the paths, this is because new paths are hidden behind old ones and as you progress new paths become sparser and sparser.<br />
So the more work you do the less productive you become &#8212; these are grim prospects.</p>
<p>So here&#8217;s our problem, how the hell do you distribute something when you don&#8217;t know:</p>
<ul>
<li>where it is</li>
<li>what it is</li>
<li>how big it is</li>
</ul>
<p>Truthfully, in a single node setup this can be done quite easily and there are lots of ways to go about it<br />
A basic crawling algorithm is actually one of the simplest around, it only has one rule: <em>Follow <strong>every</strong> path but <strong>only once</strong> &#8212; when there are no more new paths you&#8217;re done.</em></p>
<p>In the most basic of implementations what you&#8217;d need to do this is a look-up table to help you keep track of the paths you&#8217;ve already followed in order not to go over them again.<br />
Or you can amend the previous model by going the multi-threaded way and put the new paths in a queue, have workers pop paths from the queue, follow them and then report the new paths they find back to their coordinator for de-duplication and then put everything that passes filtering back to the queue and so the story goes&#8230;</p>
<p>When you do this on a single machine these approaches are good enough (and when you use async requests for the first/simplest approach it becomes more efficient than the latter one as well).<br />
Thing is, these work well because you have the benefit of a multi Gbps bandwidth and close-to-zero latency pipe, your Front-Side Bus (or whatever computers have nowadays, haven&#8217;t kept up with h/w design).</p>
<p>So you can check if something is in the lookup table in something close to 0s, actually in Ruby the look-up time of a Set with 1,000,000 URLs in it is <em>9.735e-06</em> (<em>0.000009735</em>) seconds on my machine.<br />
Which is effectively no time at all, you spend <em>0.000009735</em> seconds waiting for a decision before following each URL &#8212; ooooh scary.</p>
<p>However, when you need to do this over the network these response times take a dive &#8212; off a cliff.<br />
You see, when distributing work you play with gain/cost ratios; if the ratio is good you go ahead, if not you go back to the drawing board.</p>
<p>Such a naive implementation deserves picking up the multi-colored markers again because:</p>
<p>Let&#8217;s say every worker communicates via an RPC protocol and the master worker maintains the look-up table and the work Queue.<br />
Assuming that an RPC call costs about the same as an HTTP request and 25% of the paths contained in most pages are identical (nav menu, css, js, images, links to new blog posts etc.) this means that each <em>follow</em> operation will cost, per work unit:<br />
1 RPC call to pop a path from the Queue +</p>
<ul>
<li>25% of the amount of links found by following the path * 1 RPC &#8212; for paths that are common and have already been visited from the get go</li>
<li>75% of the amount of links found by following the path * 1 RPC call + 1 HTTP request &#8212; for new paths which aren&#8217;t in the lookup table and must be visited</li>
</ul>
<p>So you&#8217;ll be spending most of your time waiting for permission rather than doing actual work and suddenly the cost of doing the work doubles.<br />
There has to be a better way&#8230;</p>
<p>Annoyingly, it took me a couple of days to figure this out and it turned out what I needed was a relaxing shower and the answer come to me on its own &#8212; <em>gooood answer *pat**pat*</em>.</p>
<p>In all honesty, I had bits and pieces of the answer from the begging and I knew that the final algorithm would have to be a composite of models &#8212; a piece from the producer-consumer there, a bit of a policy-enforcer here sprinkled with some delegation across the board &#8212; but the problem was putting them in the right order to form a unified model that would:</p>
<ul>
<li>Avoid any sort of blocking (no look-ups or waiting for decisions)</li>
<li>Automate load balancing</li>
<li>Prevent crawling redundant URLs (more than one worker following the same path)</li>
</ul>
<p>Tricky stuff right?</p>
<p>And here&#8217;s what I came up with:</p>
<ol>
<li>The master scopes out the place (follows 10 paths or so) and deduces the webapp structure &#8212; it will, most certainly, be incomplete but it doesn&#8217;t matter as we just want some seeds to get us going.</li>
<li>The master creates a per directory policy and assigns dirs to workers AND sends that policy to them as well.</li>
<li>Workers perform the crawl as usual but also implement that policy for URLs that don&#8217;t match their own policy rules i.e. send URLs that are out of their scope to the appropriate peer and let him handle it &#8212; the peer will ignore it if he has already visited it or put it in his queue.</li>
<li>If no policy matches a URL then it is sent back to the master; the master creates a new policy(ies), stores the work in a Queue and then sends an announcement to the workers (&#8220;There&#8217;s some work up for grabs!&#8221; ).</li>
<li>Busy workers ignore it; idling workers try to pull it and the work is assigned first-come/first-serve along with the updated policy.</li>
<li>Go to 3</li>
</ol>
<p>If at any point a worker becomes idle he sends the paths he has discovered back to the master for storage/further processing/whatever and tries to pull some new work.</p>
<p>Also, the master will be a worker too &#8212; why waste a node, right?</p>
<p>Let&#8217;s go back to our list of requirements and see how we did:</p>
<ul>
<li>Avoid any sort of blocking (no look-ups or waiting for decisions) &#8212; <strong>✓</strong> Instead of waiting for permission to do something, we delegate to the appropriate authority and forget about it</li>
<li>Automate load balancing &#8212; <strong>✓</strong> Workers pull work when they are good and ready</li>
<li>Prevent crawling redundant URLs (no more than one worker following the same path) &#8212; <strong>✓</strong> A local look-up table and item #1 take care of that quite nicely</li>
</ul>
<p>In addition, the policy can use any sort of criteria (directories were just an example), which means that we can achieve very granular distribution if we are a bit clever with it.</p>
<p>I think that this serves as a decent starting point, there&#8217;s still the issue of how to efficiently group the new URLs that are fed back to the master (because they don&#8217;t match any of the initial policy rules) but I&#8217;ll have to see this working under real world conditions in order to get a better feel for it first.<br />
I&#8217;ve got some stuff in mind, we&#8217;ll see&#8230;</p>
<p>Please do comment if you have a suggestion of have spotted a fault somewhere.</p>
<p> &#8211; Tasos</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2012/01/19/distributing-the-crawl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arachni is moving away from GPLv2 and towards Apache License v2.0</title>
		<link>http://trainofthought.segfault.gr/2012/01/12/arachni-is-moving-away-from-gplv2-and-towards-apache-license-v2-0/</link>
		<comments>http://trainofthought.segfault.gr/2012/01/12/arachni-is-moving-away-from-gplv2-and-towards-apache-license-v2-0/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 15:40:22 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache license 2.0]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[asf]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[gplv2]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=2012</guid>
		<description><![CDATA[Yes, it&#8217;s true&#8230; As of now the code in the experimental branch has been converted to use the Apache License Version 2.0. If you&#8217;re interested in why this happened here&#8217;s the deal: There are currently a few companies that use Arachni internally and a few others that actually provide SaaS security services using Arachni&#8217;s distributed [...]]]></description>
			<content:encoded><![CDATA[<p>Yes, it&#8217;s true&#8230;<br />
As of now the code in the <a href="https://github.com/Zapotek/arachni/tree/experimental">experimental branch</a> has been converted to use the Apache License Version 2.0.</p>
<p>If you&#8217;re interested in why this happened here&#8217;s the deal:<br />
There are currently a few companies that use Arachni internally and a few others that actually provide SaaS security services using Arachni&#8217;s distributed features.<br />
Thing is though, a lot of companies can&#8217;t touch GPL code (not that I blame them) which isn&#8217;t good for them nor Arachni as neither of us gets what he wants.<br />
It makes sense, surely, but it was about a month ago that it really clicked as I were reading the comments of a Slashdot article.<br />
Lots of people were agreeing on the same subject, the money-men don&#8217;t like GPL which kind of sucked for the project.</p>
<p>At this point I started researching alternative licenses and started asking around a bit.</p>
<p>As fate would have it &#8212; although more due to the increasing userbase I guess &#8212; a few people told me that the GPL was a deal-braker for them and I even had one guy tell me that he couldn&#8217;t include Arachni in his book because of it (I&#8217;ll spare him his blushes and not say his name).</p>
<p>Now that the project is gaining some momentum these technicalities become more and more important.</p>
<p>So after a bit of research I settled on Apache License 2.0 mainly because of its trademark and patent grants (because who the hell wants to deal with that bureaucratic crap?) and the requirement to redistribute a visible copy of the original work&#8217;s <em>NOTICE</em> file (if it includes one) which is nice since hard work must be properly credited.<br />
You know, you can use my work for free (and I hope you do <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) but mention that &#8220;this product contains some code from that Arachni thingy written by this bloke with the funny name&#8221;.</p>
<p>So that&#8217;s the reason, I&#8217;m hoping that a more permissive license will increase adoption and make everybody&#8217;s life easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2012/01/12/arachni-is-moving-away-from-gplv2-and-towards-apache-license-v2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arachni v0.4.0.2 HOTFIX</title>
		<link>http://trainofthought.segfault.gr/2012/01/09/arachni-v0-4-0-2-hotfix/</link>
		<comments>http://trainofthought.segfault.gr/2012/01/09/arachni-v0-4-0-2-hotfix/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:23:08 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[audit]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[crawler]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[vulnerability scanner]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[webapp]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=2005</guid>
		<description><![CDATA[Hi guys, A couple of days ago I proudly released v0.4 and, as luck would have it, I later had to swallow some of that pride due to a couple of intermittent bugs that I hadn&#8217;t spotted. Well, worry no more as I&#8217;m writing this post to announce a rush hotfix version of Arachni, v0.4.0.2. [...]]]></description>
			<content:encoded><![CDATA[<p>Hi guys,</p>
<p>A couple of days ago I proudly released v0.4 and, as luck would have it, I later had to swallow some of that pride due to a couple of intermittent bugs that I hadn&#8217;t spotted.<br />
Well, worry no more as I&#8217;m writing this post to announce a rush hotfix version of Arachni, v0.4.0.2.</p>
<p>If you installed the previous version via &#8220;gem install&#8221; or have downloaded the previous Cygwin package then all you need to do is issue:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem install arachni</div></td></tr></tbody></table></div>
<p>If not, you can find links and instructions for all available packages at: <a href="http://arachni-scanner.com/latest">http://arachni-scanner.com/latest</a></p>
<p>Enjoy <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2012/01/09/arachni-v0-4-0-2-hotfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arachni v0.4 is out</title>
		<link>http://trainofthought.segfault.gr/2012/01/07/arachni-v0-4-is-out/</link>
		<comments>http://trainofthought.segfault.gr/2012/01/07/arachni-v0-4-is-out/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 06:48:43 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[audit]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[crawler]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[v0.4]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[vulnerability scanner]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[webapp]]></category>
		<category><![CDATA[xmlrpc]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=1930</guid>
		<description><![CDATA[Yes, yes&#8230;the time has finally come and there are boons for everyone. This release features the most impressive ChangeLog yet and the first (and coolest) thing in this long list is the brand new High Performance Grid implementation &#8212; which has been discussed extensively in the past. Let&#8217;s review the big points. New RPC infrastructure [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://zapotek.github.com/arachni/logo.png" alt="" /><br />
Yes, yes&#8230;the time has finally come and there are boons for everyone.<br />
This release features the most impressive <a href="http://arachni.segfault.gr/latest#v0.4">ChangeLog</a> yet and the first (and coolest) thing in this long list is the brand new <a href="https://github.com/Zapotek/arachni/wiki/RPC-server#wiki-grid">High Performance Grid implementation</a> &#8212; which has been <a href="http://trainofthought.segfault.gr/?s=grid">discussed extensively</a> in the past.</p>
<p>Let&#8217;s review the big points.</p>
<h2><a href="https://github.com/Arachni/arachni-rpc">New RPC infrastructure</a></h2>
<p>Ruby&#8217;s XMLRPC has been ditched (as initially discussed in these two [<a href="http://trainofthought.segfault.gr/2011/09/11/ruby-rpc-hurdles/">1</a>, <a href="http://trainofthought.segfault.gr/2011/09/29/grid-sitrep-and-the-new-arachni-rpc-library/">2</a>] posts) in favor of <a href="https://github.com/Arachni/arachni-rpc">Arachni-RPC</a>.<br />
Arachni-RPC is lightweight, simple and fast which makes it ideal for large Grid deployments and makes it easy for 3rd parties to interoperate with Arachni&#8217;s servers.</p>
<p><strong>Notice:</strong> If you were using the old XMLRPC interface please update your code to use the new <a href="https://github.com/Zapotek/arachni/wiki/RPC-API">RPC API</a>.</p>
<h2><a href="https://github.com/Zapotek/arachni/wiki/RPC-server#wiki-grid">High Performance Grid</a></h2>
<p>I&#8217;ve been talking about this one so much that I&#8217;ve actually grown a bit sick of it &#8212; joking aside though this is one of Arachni&#8217;s most important features.<br />
It allows you to connect multiple nodes into a Grid and use them to perform lightning-fast scans.</p>
<p>This is due to the way Arachni distributes the workload, which is finely grained down to individual page elements to ensure fair and optimal distribution; because workload distribution is so fluid it effectively becomes a sort of bandwidth and CPU aggregation.</p>
<p>To put this in simple(-istic) terms:<br />
If you have 2 Amazon instances and you need to scan one site, by utilising the HPG you&#8217;ll be able to cut the scan time down to approximately half of what it would take by using a single node (plus the initial crawl time).</p>
<p>And if you have a huge site you can use 50 nodes and so the story goes&#8230;</p>
<p>This feature was an imaginary, almost unattainable, milestone back when I added the initial client/server implementation and I didn&#8217;t really think that I&#8217;d ever be able to make it happen.<br />
Luckily, I was wrong and I&#8217;m proud to present you with the first Open Source High Performance Grid web application security scanner!<br />
(By the way, does anyone know of a commercial scanner that can do this?)</p>
<p><strong>Notice:</strong> With the WebUI&#8217;s updated AutoDeploy add-on you&#8217;ll be able to go into World domination mode by performing point and click Grid deployments!<br />
<strong>Another notice:</strong> Use responsibly, don&#8217;t DDoS people.<br />
<strong>Yet another notice:</strong> It&#8217;s still considered experimental so <a href="https://github.com/Zapotek/arachni/issues">let me know</a> if you come across a bug. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2><a href="https://github.com/Zapotek/arachni/wiki/Web-user-interface">Updated WebUI</a></h2>
<p>The WebUI now contains a few context-sensitive help dialogs to help out the newcomers and it has been updated to use the Thin webserver to send responses asynchronously in order to increase performance and feel &#8220;snappier&#8221;.<br />
It also supports HTTP basic auth just in case you want some simple password protection <strong>and</strong> has been updated to provide access to the brand new HPG goodies.</p>
<h2>Spider improvements</h2>
<p>There was a bug with redirections that prevented the spider from achieving optimal coverage which has now been resolved.<br />
More than that, the scope of the crawl can now be either extended or restricted by supplying newline-separated lists of URLs which should help you import 3rd party sitemaps.</p>
<h2>Plugins</h2>
<p>The plugin API has been extended in order to allow plugins to let the framework know if they can be distributed across HPG Instances and, if so, how to merge their results for the final report.</p>
<p>Another big (although invisible to the end-user) change is the conversion of all meta-modules to full-fledged plugins to simplify management and Grid distribution.</p>
<p>And these new plugins have been added:</p>
<ul>
<li>    ReScan &#8212; It uses the AFR report of a previous scan to extract the sitemap in order to avoid a redundant crawl.</li>
<li>    BeepNotify &#8212; Beeps when the scan finishes.</li>
<li>    LibNotify &#8212; Uses the libnotify library to send notifications for each discovered issue and a summary at the end of the scan.</li>
<li>    EmailNotify &#8212; Sends a notification (and optionally a report) over SMTP at the end of the scan.</li>
<li>    Manual verification &#8212; Flags issues that require manual verification as untrusted in order to reduce the signal-to-noise ratio.</li>
<li>    Resolver &#8212; Resolves vulnerable hostnames to IP addresses.</li>
</ul>
<h2>Modules</h2>
<p>I&#8217;ve got both good and bad news for this&#8230;.<br />
In an attempt to cleanup and optimise pattern matching in v0.3 I inadvertently broke some aspects of it which crippled the XSS (xss), SQL injection (sqli) and Path Traversal (path_traversal) modules &#8211;I sincerely apologise, mea culpa.</p>
<p>The good news is that I&#8217;ve made things right, cleaned up the API and the existing modules and improved their accuracy.</p>
<h2>Reports</h2>
<p>The HTML report has waved goodbye to Highcharts due to licensing reasons and now uses <a href="http://www.jqplot.com/">jqPlot</a> for all its charting and graphing needs.<br />
I&#8217;ve also removed the &#8220;report false-positive&#8221; button since a part of that process required RSA encryption which for some reason caused segfaults on Mac OSX.<br />
Good news is that the HTML reports will be <strong>significantly</strong> smaller in size from now on.</p>
<p>Moreover, the following new report formats have been added:</p>
<ul>
<li>    JSON &#8212; Exports the audit results as a JSON serialized Hash.</li>
<li>    Marshal &#8212; Exports the audit results as a Marshal serialized Hash.</li>
<li>    YAML &#8212; Exports the audit results as a YAML serialized Hash.</li>
</ul>
<h2>Cygwin package for Windows</h2>
<p>About time indeed, Windows users can now enjoy Arachni&#8217;s features &#8212; albeit via a preconfigured Cygwin environment.<br />
The important point is that you no longer have to manually hassle to install Arachni via MinGW or Cygwin yourselves or use a VM and what have you&#8230;<br />
Simply download and run the self-extracting archive, double click the &#8220;Cygwin&#8221; batch file and lo and behold: you&#8217;ve got a bash shell ready to execute Arachni&#8217;s scripts.</p>
<p>Unfortunately, there&#8217;s a performance penalty involved when running Arachni in Cygwin but until I port it to run natively on Windows it&#8217;ll have to do.</p>
<p>Before I forget, the <a href="https://github.com/Zapotek/arachni/wiki">Wiki</a> has been cleaned up and brought up to date so if you need to go through the documentation that should be your first stop.</p>
<p>Go ahead and enjoy this new release everyone, download links and instructions here: <a href="http://arachni.segfault.gr/latest">http://arachni.segfault.gr/latest</a>.</p>
<p>Cheers,<br />
Tasos L.</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2012/01/07/arachni-v0-4-is-out/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Playing around with DOM XSS (Demo included)</title>
		<link>http://trainofthought.segfault.gr/2011/12/12/playing-around-with-dom-xss-demo-included/</link>
		<comments>http://trainofthought.segfault.gr/2011/12/12/playing-around-with-dom-xss-demo-included/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 00:21:42 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[cross site scripting]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[therubyracer]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=1918</guid>
		<description><![CDATA[I&#8217;ve caught a bug it seems and because I can&#8217;t just sit on my ass all day I figured why not play around with my latest toy. I&#8217;ve updated the code to make the process more streamlined and allow for fuzzing (or at least altering) some possible input vectors. Things will be very very simple [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve caught a bug it seems and because I can&#8217;t just sit on my ass all day I figured why not play around with <a href="https://github.com/Zapotek/dom-js-experiment">my latest toy</a>.</p>
<p>I&#8217;ve updated the code to make the process more streamlined and allow for fuzzing (or at least altering) some possible input vectors.<br />
Things will be very very simple for now as I&#8217;m merely trying to demo that with appropriate effort invested this can become a viable solution &#8212; eventually.</p>
<p>To the point, I&#8217;ll showcase a DOM XSS vulnerability that will take place purely on the client-side.<br />
Unfortunately, there are a lot of DOM interfaces/vectors that I haven&#8217;t yet implemented so let&#8217;s stick to one I have &#8212; <em>navigator.userAgent</em>.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'init'</span><br />
<br />
html = <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOHTML<br />
&lt;html&gt;<br />
&nbsp; &nbsp; &lt;head&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;My title!&lt;/title&gt;<br />
&nbsp; &nbsp; &lt;/head&gt;<br />
<br />
&nbsp; &nbsp; &lt;body&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write( navigator.userAgent );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/body&gt;<br />
&lt;/html&gt;<br />
EOHTML</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># the second param sets 'dont_eval_js' to true</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># we want to do that ourselves later on after we've prepared the vectors</span><br />
<span style="color:#008000; font-style:italic;"># (navigator.userAgent in this case)</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
window = <span style="color:#6666ff; font-weight:bold;">DOM::Window</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> html, <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># we'll inject this fictional tag and look for it in the DOM structure later on</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># if found, then we have an XSS vuln</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
seed_tag = <span style="color:#996600;">'myinjectedtag'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># our XSS vector</span><br />
window.<span style="color:#9900CC;">navigator</span>.<span style="color:#9900CC;">userAgent</span> = <span style="color:#996600;">&quot;&lt;#{seed_tag}&gt;blah blah blah&lt;/#{seed_tag}&quot;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this will show the HTML as is (Ref. #1)</span><br />
<span style="color:#008000; font-style:italic;"># puts window.document.to_html</span><br />
<span style="color:#008000; font-style:italic;"># puts '-' * 80</span><br />
<br />
<span style="color:#008000; font-style:italic;"># execute the JS</span><br />
window.<span style="color:#9900CC;">instance_eval</span> <span style="color:#006600; font-weight:bold;">&#123;</span> exec_js! <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this one will show the updated HTML i.e. including our tag &nbsp;(Ref. #2)</span><br />
<span style="color:#008000; font-style:italic;"># puts window.document.to_html</span><br />
<br />
<span style="color:#008000; font-style:italic;"># look for the tag in the DOM structure</span><br />
<span style="color:#9966CC; font-weight:bold;">if</span> window.<span style="color:#9900CC;">document</span>.<span style="color:#9900CC;">getElementsByTagName</span><span style="color:#006600; font-weight:bold;">&#40;</span> seed_tag <span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'Vulnerable to XSS!'</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><strong>Ref. #1</strong><br />
This is what the code looks like at this point:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=US-ASCII&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>My title!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write( navigator.userAgent );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Pretty much what we passed&#8230;</p>
<p><strong>Ref. #2</strong><br />
And now that the JS has been executed:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=US-ASCII&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>My title!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write( navigator.userAgent );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;myinjectedtag&gt;</span>blah blah blah<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>myinjectedtag&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Yes I know, <em>document.write()</em> should have written inside the parent of the <em>script</em> tag, the <em>div</em> in this case.<br />
I can&#8217;t be bothered to take care of this right now, this is just a prototype&#8230;a prototype of a prototype of the prototype actually.</p>
<p><strong>End result</strong><br />
Since we can see that the injection was clearly successful, the inevitable message shall appear:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Vulnerable to XSS!</div></td></tr></tbody></table></div>
<p><strong>Conclusion</strong><br />
Yeah it&#8217;s really basic and simplistic and not a big deal but it&#8217;s fun to see things working &#8212; barely but still, heh.</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2011/12/12/playing-around-with-dom-xss-demo-included/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experimentng with DOM and JavaScript support for Ruby</title>
		<link>http://trainofthought.segfault.gr/2011/12/05/experimentng-with-dom-and-javascript-support-for-ruby/</link>
		<comments>http://trainofthought.segfault.gr/2011/12/05/experimentng-with-dom-and-javascript-support-for-ruby/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 01:33:34 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nokogiri]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[taka]]></category>
		<category><![CDATA[therubyracer]]></category>
		<category><![CDATA[v8]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=1898</guid>
		<description><![CDATA[One of the things everyone is taking for granted nowadays for every browser and website is decent support for AJAX. Naturally, scanner devs have been trying to find a decent way to automatically audit that side of the fence or at least provide decent coverage for JS-heavy webapps. Thing is though&#8230; this is a bitch [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things everyone is taking for granted nowadays for every browser and website is decent support for AJAX.<br />
Naturally, scanner devs have been trying to find a decent way to automatically audit that side of the fence or at least provide decent coverage for JS-heavy webapps.</p>
<p>Thing is though&#8230; this is a <strong>bitch</strong> to get right.<br />
And never mind getting it <i>right</i>, it&#8217;s hard enough getting the damn thing to work to begin with.</p>
<p>There are 3 things that need to be integrated in order to achieve that sort of functionality:</p>
<ol>
<li>a <a href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a></li>
<li>a <a href="http://en.wikipedia.org/wiki/List_of_ECMAScript_engines">JS interpreter</a></li>
<li>a <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">AJAX extension</a> to JS</li>
</ol>
<h2>DOM</h2>
<p>The static parts of the DOM can easily be built on top of tested and proven XML parsers like libxml.<br />
The DOM has tricky parts too though, which are where the money is, like timers and events.</p>
<p>It&#8217;s alright though, a little bit of smart thread scheduling and clean collections of callbacks will sustain you at the beginning.</p>
<h2>JS</h2>
<p>JS integration difficulty depends on your language of choice.<br />
Thankfully, more and more bindings for several different JS engines are being released so you can have your pick.<br />
The interfaces can be a bit dodgy though at times which can defeat the whole purpose.</p>
<h2>AJAX</h2>
<p>AJAX functionality will have to fall on your shoulders but if you managed to get the first 2 parts working this won&#8217;t be much of a challenge.<br />
You simply write an AJAX API in your language of choice and make that interface available to the JS code.</p>
<h2>Where I&#8217;m going with this&#8230;</h2>
<p>It&#8217;s certainly possible to get these working together (without being a multi-million dollar corporation even) but it&#8217;ll be <strong>a lot</strong> of work.<br />
Which is the reason there&#8217;s no open source scanner that supports AJAX or even basic JS scripting.</p>
<p>Arachni is no exception, not to mention that due to the young age of the system there had been far more important and basic things to be worked out first.</p>
<p>Luckily, a lot of things have changed in very little time.<br />
The project still has a few bugs but it has been stable enough for a few businesses to build some of their infrastructure on it.<br />
And the v0.4 version if pretty much ready, which takes care of another big feature I could not wait to implement &#8212; the High Performance Grid.</p>
<p>Next stop: AJAX</p>
<p>Some time ago I was contacted by a CompSci student who had chosen to add AJAX support to Arachni as his final-year project, nice guy and seems motivated so I&#8217;m pretty sure that this is gonna happen.</p>
<p>And since he mentioned it I decided to start looking into the subject matter myself with this:<br />
<a href="https://github.com/Zapotek/dom-js-experiment">https://github.com/Zapotek/dom-js-experiment</a></p>
<p>It&#8217;s based on <a href="https://github.com/tenderlove/taka">Taka</a> (for the static parts of the DOM) and the <a href="http://code.google.com/p/v8/">V8 JS engine</a> as provided by <a href="https://github.com/cowboyd/therubyracer">TheRubyRacer</a>.</p>
<p>I&#8217;ve managed to make this work with some simple stuff, JQuery loads without errors and kind of works (I haven&#8217;t had much time to test it).<br />
I haven&#8217;t had time to implement timers and events yet but they&#8217;re coming&#8230;<br />
I don&#8217;t want to finish this thing on my own though, the other guy will need to work on it for his project.</p>
<p>Point is&#8230;AJAX support is coming to Arachni; it will of course take time but it&#8217;s going to happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2011/12/05/experimentng-with-dom-and-javascript-support-for-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programatically scanning using Arachni (Part 5)</title>
		<link>http://trainofthought.segfault.gr/2011/12/04/programatically-scanning-using-arachni-part-5/</link>
		<comments>http://trainofthought.segfault.gr/2011/12/04/programatically-scanning-using-arachni-part-5/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 03:03:41 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[audit]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[crawler]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[differential analysis]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[pattern matching]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rdiff]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[timing attacck]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[vulnerability scanner]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=1839</guid>
		<description><![CDATA[As promised, part 5. Not that anyone&#8217;s reading this crap, once I&#8217;m done with the series though I&#8217;ll be able to gather them into a nice developer&#8217;s guide so I might as well keep going. As always, keep your installation to up date with the experimental branch before continuing. These articles have forced me to [...]]]></description>
			<content:encoded><![CDATA[<p>As promised, part 5.<br />
Not that anyone&#8217;s reading this crap, once I&#8217;m done with the series though I&#8217;ll be able to gather them into a nice developer&#8217;s guide so I might as well keep going.</p>
<p>As always, keep your installation to up date with the experimental branch before continuing.<br />
These articles have forced me to see Arachni from a completely different perspective and so I keep improving the API to make it more developer friendly.</p>
<p>This time we&#8217;ll focus on auditing individual elements and also work on a per page scope.</p>
<p>Let me paint you a picture:</p>
<blockquote><p>You have a Rails (or some other such framework) web application.<br />
You need to audit it in a consistent manner.<br />
You wish you could simply add security tests to your existing test suite next to your units/functional/integration/etc. tests.<br />
Your webapp framework already keeps track of pretty much all inputs (and if not you can override helper methods like <i>link_to</i> and <i>form_for</i> to keep track of them).<br />
The only thing missing is a system to which you can feed that data and audit those inputs.</p></blockquote>
<p>You see where I&#8217;m going with this, right?</p>
<p>The Arachni framework can easily handle this in a number of ways, some of which I&#8217;ll demonstrate here.<br />
<span id="more-1839"></span></p>
<h2>Scripted element audits</h2>
<p>Let&#8217;s start from the outside and move inwards.<br />
The framework feeds pages to modules &#8211;> modules audit pages &#8211;> pages include elements &#8211;> modules inherit from <i>Arachni::Module::Base</i> &#8211;> <i>Arachni::Module::Base</i> includes <i>Arachni::Module::Auditor</i> and <i>Arachni::Module::Output</i>.</p>
<p>And everything&#8217;s at its place, modules live under &#8220;/modules&#8221; and everyone&#8217;s happy.</p>
<p>I&#8217;ve already showed how to script an audit but what if you want a narrower scope?<br />
What if you have a list of elements you want to audit?<br />
What if you want to pass a custom page to be audited?<br />
And more importantly, how can you do that without needing to work with the framework, the module manager and without needing to write a full blown module?<br />
What if you just want the functionality without the hassle?</p>
<p>Obviously that&#8217;s possible, otherwise I wouldn&#8217;t have gone through that sales pitch.<br />
What we need to do is create our own Auditor at runtime&#8230; better yet, let&#8217;s create our own Module so that way we&#8217;ll have access to some utilities and other toys as well.<br />
Through that Auditor we&#8217;ll be able to submit, fuzz, audit, analyze elements and server responses.</p>
<p>Time to go through the 2 cleanest ways to do that.</p>
<p>First of all, this will be our Auditor, it&#8217;ll serve as a proxy to the functionality enjoyed by regular framework modules.<br />
<strong>auditor.rb</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># This class is capable of providing module-like functionality to 3rd party objects.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># This is the same as a regular module but instead of including callbacks like:</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;* prepare</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;* run</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;* clean_up</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># to perform its job, its functionality is exploited by other classes.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> Auditor <span style="color:#006600; font-weight:bold;">&lt;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Base<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># If the parameter is a Arachni::Parser::Page that's going to be the</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># reference page of the auditor.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># If the param is a string it'll be treated like a URL and a new page</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># will be created for it.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span> page_or_url <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># setup a minimal page to have as a reference</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !page_or_url.<span style="color:#9900CC;">is_a</span>? <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> page_or_url.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span> page_or_url<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">info</span>; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'My auditor'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Each Auditor <strong>must</strong> have a page as a reference if only to know the current URL, so a page with at least a URL assigned must be available at all times.</p>
<h3>Per element</h3>
<p>This approach deals with auditing individual, user created, elements, which is the finest grained of controls possible.<br />
Talk is cheap though, let&#8217;s test a few examples.</p>
<h4>Pattern matching</h4>
<p>Simple enough, inject a string and see if it appears in the response:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testfire.net'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># the owner is supposed to be the URL of the page containing the element</span><br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's create a link element to audit</span><br />
link = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># action, to which URL to send the data</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/notfound.aspx'</span>,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># auditable inputs, these will be fuzzed/audited/whatever</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'aspxerrorpath'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># seed to inject</span><br />
injection_str = <span style="color:#996600;">'&lt;xss /&gt;'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># some audit options</span><br />
audit_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># the existence of this substring in the response will verify the issue</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># :substring =&gt; injection_str,</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># is this is a string it'll be converted to a regexp</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:regexp</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> injection_str,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># controls the format of the injected string,</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># this one means: inject as is</span><br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get an auditor and pass it the seed URL, it'll also be used as the page URL</span><br />
auditor = Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># the name is a dead give-away</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># the 1st param is an array of elements to audit</span><br />
<span style="color:#008000; font-style:italic;"># the 2nd one is the string to inject</span><br />
<span style="color:#008000; font-style:italic;"># the 3rd one is a hash with audit options</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># if a server response contains the :substring (or matches a :regexp)</span><br />
<span style="color:#008000; font-style:italic;"># then an issue will be logged automatically</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
auditor.<span style="color:#9900CC;">audit_elems</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link<span style="color:#006600; font-weight:bold;">&#93;</span>, injection_str, audit_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this fires the queued requests and blocks until all responses have arrived</span><br />
auditor.<span style="color:#9900CC;">http</span>.<span style="color:#9900CC;">run</span><br />
<br />
<span style="color:#008000; font-style:italic;"># grab any logged issues/results</span><br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
auditor.<span style="color:#9900CC;">print_info</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<p>This time we don&#8217;t mute the output, and why should we? Let&#8217;s admire our handy work. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But what if you don&#8217;t want the auditor to log the the issue automatically based on an expression or substring?</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">audit_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># if you pass a block you get full control over how to analyze the audit responses</span><br />
auditor.<span style="color:#9900CC;">audit_elems</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link<span style="color:#006600; font-weight:bold;">&#93;</span>, injection_str, audit_opts <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>response, options, element<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># full HTTP response</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pp response</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># expanded options</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># ap options</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># updated element</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pp element</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># perform your own analysis and logging</span><br />
&nbsp; &nbsp; auditor.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#40;</span> options, response <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> response.<span style="color:#9900CC;">body</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> injection_str <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<h4>Differential analysis</h4>
<p>The Auditor module contains helpers that perform differential analysis for you using Arachni&#8217;s own <a href="http://trainofthought.segfault.gr/?s=rdiff">rDiff algorithm</a>.</p>
<p>See this SQL injection example for instance:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testphp.vulnweb.com/artists.php'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># the owner is supposed to be the URL of the page containing the element</span><br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's create a link element to audit</span><br />
link = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># action, to which URL to send the data</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># auditable inputs, these will be fuzzed/audited/whatever</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'artist'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1'</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get an auditor and pass it the seed URL, it'll also be used as the page URL</span><br />
auditor = Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
rdiff_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># fault injection seeds</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># these must generate an exceptional condition or</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># general error when appended to an SQL query</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:faults</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'<span style="color:#000099;">\'</span>&quot;`'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># boolean injection seeds</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># these values should not affect the behavior of the page when evaluated</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># as part of the SQL query</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:bools</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">' and 1+1 = 2'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># rDiff precision</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Specifies the amount of rdiff iterations,</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># more iterations =&gt; more refined/accurate result</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># default is 2 but what the hell...</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># analyze and log</span><br />
auditor.<span style="color:#9900CC;">audit_rdiff_elem</span><span style="color:#006600; font-weight:bold;">&#40;</span> link, rdiff_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this fires the queued requests and blocks until all responses have arrived</span><br />
auditor.<span style="color:#9900CC;">http</span>.<span style="color:#9900CC;">run</span><br />
<br />
<span style="color:#008000; font-style:italic;"># grab any logged issues/results</span><br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
auditor.<span style="color:#9900CC;">print_info</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<p>Again, if you want to perform your own analysis and logging:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">auditor.<span style="color:#9900CC;">audit_rdiff_elem</span><span style="color:#006600; font-weight:bold;">&#40;</span> link, rdiff_opts <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>injection_string, element, original_response_body, bool_response, fault_response_body<span style="color:#006600; font-weight:bold;">|</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># injected string</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># p injection_string</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># updated audited element element</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pp element</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># body of the original/vanilla page</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pp original_response_body</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># full HTTP response for the boolean injection</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pp bool_response</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># body of the fault injection response</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pp fault_response_body</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<h4>Time-out/delay attacks</h4>
<p>Yes, timing attacks are of course part of the repertoire but are not available on a per-element basis.<br />
Don&#8217;t worry though, there&#8217;s an alternative way to perform them as we&#8217;ll see shortly.</p>
<h3>Per page</h3>
<p>The per-page approach is slightly different and requires some commitment as you have to you properly configure a page object with elements and feed that page object to the module.<br />
The module then audits those elements in batch.</p>
<h4>Pattern matching</h4>
<p>Let&#8217;s see what the pattern matching example looks like when adjusted for this approach:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testfire.net'</span><br />
<br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
link = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/notfound.aspx'</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'aspxerrorpath'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># create our page and assign it the link</span><br />
page = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:url</span> &nbsp; <span style="color:#006600; font-weight:bold;">=&gt;</span> owner.<span style="color:#9900CC;">to_s</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:links</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link<span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get an auditor and pass it the page</span><br />
auditor = Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> page <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
injection_str = <span style="color:#996600;">'&lt;xss /&gt;'</span><br />
audit_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:regexp</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> injection_str,<br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
auditor.<span style="color:#9900CC;">audit</span><span style="color:#006600; font-weight:bold;">&#40;</span> injection_str, audit_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
auditor.<span style="color:#9900CC;">http</span>.<span style="color:#9900CC;">run</span><br />
<br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
auditor.<span style="color:#9900CC;">print_info</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<p>I&#8217;ve removed most of the comments this time since they were identical to the first example.</p>
<p>I just had an idea, let&#8217;s add an <i>audit</i> method to the page object itself and see if it&#8217;s any easier to work with.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testfire.net'</span><br />
<br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> audit!<span style="color:#006600; font-weight:bold;">&#40;</span> injection_str, opts, run = <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#006600; font-weight:bold;">&amp;</span>block <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; auditor = Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">self</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; auditor.<span style="color:#9900CC;">audit</span><span style="color:#006600; font-weight:bold;">&#40;</span> injection_str, opts, <span style="color:#006600; font-weight:bold;">&amp;</span>block <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; auditor.<span style="color:#9900CC;">http</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">if</span> run<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
link = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/notfound.aspx'</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'aspxerrorpath'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># create our page and assign it the link</span><br />
page = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:url</span> &nbsp; <span style="color:#006600; font-weight:bold;">=&gt;</span> owner.<span style="color:#9900CC;">to_s</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:links</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link<span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
injection_str = <span style="color:#996600;">'&lt;xss /&gt;'</span><br />
audit_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:regexp</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> injection_str,<br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
page.<span style="color:#9900CC;">audit</span>!<span style="color:#006600; font-weight:bold;">&#40;</span> injection_str, audit_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<p>Huh, seems kinda nice&#8230; <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>Differential analysis</h4>
<p>Should be a familiar sight:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testphp.vulnweb.com/artists.php'</span><br />
<br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
link = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'artist'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1'</span>,<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
page = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">&#41;</span><br />
page.<span style="color:#9900CC;">links</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> link<br />
<br />
auditor = Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> page <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
rdiff_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:faults</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'<span style="color:#000099;">\'</span>&quot;`'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:bools</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">' and 1+1 = 2'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
auditor.<span style="color:#9900CC;">audit_rdiff</span><span style="color:#006600; font-weight:bold;">&#40;</span> rdiff_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
auditor.<span style="color:#9900CC;">http</span>.<span style="color:#9900CC;">run</span><br />
<br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
auditor.<span style="color:#9900CC;">print_info</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<h4>Time-out/delay attacks</h4>
<p>And now it&#8217;s time to check out some timing attacks.<br />
Actually, since timing attacks are wildly unreliable Arachni doesn&#8217;t simply perform a time-out check.<br />
It performs a few time-out checks with different delay tolerances and waits for the server to normalize in between and it also does some other weird stuff to make sure that false positives are a rare occasion.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testphp.vulnweb.com/artists.php'</span><br />
<br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
link = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'artist'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1'</span>,<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
page = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">&#41;</span><br />
page.<span style="color:#9900CC;">links</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> link<br />
<br />
auditor = Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> page <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
timeout_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># set first stage timeout to 4 seconds</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># the rest of the stages are based on this value</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:timeout</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4000</span>,<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># different platforms expect different time representations,</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># some expect seconds and others milliseconds.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># __TIME__ in the injection string will be replaced with:</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;:timeout / :timeout_divider</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># optional and defaults to 1</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:timeout_divider</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1000</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
auditor.<span style="color:#9900CC;">audit_timeout</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'sleep(__TIME__)#'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>, timeout_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># timing attacks are a bit different and are scheduled to be run at the end</span><br />
<span style="color:#008000; font-style:italic;"># of a full audit</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># that's why simply firing up the queued HTTP requests (like with the other methods)</span><br />
<span style="color:#008000; font-style:italic;"># isn't enough</span><br />
Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor.<span style="color:#9900CC;">timeout_audit_run</span><br />
<br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
auditor.<span style="color:#9900CC;">print_info</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<p>Simple as pie.</p>
<h3>Page delegation</h3>
<p>Let&#8217;s investigate this idea a bit further, shall we?<br />
Having audit functionality built-into the page objects would surely be helpful!</p>
<p>Time to monkey-patch the Page class I reckon so update your <strong>auditor.rb</strong> file to this:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># This class is capable of providing module-like functionality to 3rd party objects.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># This is the same as a regular module but instead of including callbacks like:</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;* prepare</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;* run</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;* clean_up</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># to perform its job, its functionality is exploited by other classes.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> Auditor <span style="color:#006600; font-weight:bold;">&lt;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Base<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># If the parameter is a Arachni::Parser::Page that's going to be the</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># reference page of the auditor.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># If the param is a string it'll be treated like a URL and a new page</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># will be created for it.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span> page_or_url <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># setup a minimal page to have as a reference</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !page_or_url.<span style="color:#9900CC;">is_a</span>? <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> page_or_url.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span> page_or_url<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">info</span>; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'My auditor'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Trap any called methods that don't exist in the page class</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># and send them to the Auditor class if they are audit methods.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span> sym, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; tokens = sym.<span style="color:#9900CC;">to_s</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'_'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> tokens.<span style="color:#9900CC;">first</span> != <span style="color:#996600;">'audit'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">NoMethodError</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;Undefined method '#{sym.to_s}'.&quot;</span>, sym, args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@auditor</span> <span style="color:#006600; font-weight:bold;">||</span>= ::Auditor.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">self</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@auditor</span>.<span style="color:#9900CC;">method</span><span style="color:#006600; font-weight:bold;">&#40;</span> sym <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># check for a :run flag explicitly since we may need to queue up</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># a number of audits</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; opts = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; args.<span style="color:#9900CC;">flatten</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>arg<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; opts.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span> arg <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> arg.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC00FF; font-weight:bold;">Hash</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#9966CC; font-weight:bold;">if</span> !opts<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:run</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> tokens.<span style="color:#9900CC;">last</span> != <span style="color:#996600;">'timeout'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@auditor</span>.<span style="color:#9900CC;">http</span>.<span style="color:#9900CC;">run</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ::Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor.<span style="color:#9900CC;">timeout_audit_run</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>And from that point on you can simply audit pages like so:</p>
<h4>Audit combo</h4>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'auditor'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">audit_forms</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testphp.vulnweb.com/'</span><br />
<br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
page = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Vulnerable to SQL injection and will be flagged by rDiff and timeout attacks.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
page.<span style="color:#9900CC;">links</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'artists.php'</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'artist'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1'</span>,<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Vulnerable to XSS.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
page.<span style="color:#9900CC;">forms</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Form</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'search.php'</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:method</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'searchFor'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># rDiff audit</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Just queue the requests, don't run them yet.</span><br />
<span style="color:#008000; font-style:italic;"># It's better if we combine these requests with the pattern matching audit</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
rdiff_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:faults</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'<span style="color:#000099;">\'</span>&quot;`'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:bools</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">' and 1+1 = 2'</span> <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
page.<span style="color:#9900CC;">audit_rdiff</span><span style="color:#006600; font-weight:bold;">&#40;</span> rdiff_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Pattern matching</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Will submit the queued HTTP requests.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
injection_str = <span style="color:#996600;">'&lt;xss /&gt;'</span><br />
audit_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:regexp</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> injection_str,<br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:run</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
page.<span style="color:#9900CC;">audit</span><span style="color:#006600; font-weight:bold;">&#40;</span> injection_str, audit_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Timing attack</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># It's better to run it at the end of the audit on its own .</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
timeout_opts = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; :<span style="color:#CC0066; font-weight:bold;">format</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Auditor::<span style="color:#CC0066; font-weight:bold;">Format</span>::STRAIGHT <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:timeout</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4000</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:timeout_divider</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1000</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:run</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
page.<span style="color:#9900CC;">audit_timeout</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'sleep(__TIME__)#'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>, timeout_opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<h3>Running all modules</h3>
<p>We may have gone a little bit too deep it seems&#8230;<br />
You may not want to perform the audit yourself&#8230;<br />
You may want to specify a narrow scope, on a per-element basis, but use the existing modules to audit them.<br />
How do you do that?</p>
<p>First of all, you can&#8217;t give Arachni&#8217;s modules individual elements&#8230;you have to give them pages.<br />
That&#8217;s alright though since as we&#8217;ve seen today creating pages containing elements of our choosing is no big deal.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_links</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#996600;">'http://testfire.net'</span><br />
<br />
owner = opts.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
<br />
page = <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Page</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> &nbsp; <span style="color:#006600; font-weight:bold;">=&gt;</span> owner.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
page.<span style="color:#9900CC;">links</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Parser::Element::Link</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> owner, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> owner <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/notfound.aspx'</span>,<br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:inputs</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'aspxerrorpath'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
modules = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># doesn't make sense to load recon modules in this case</span><br />
modules.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'audit/*'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
modules.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span> page <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">Arachni::HTTP</span>.<span style="color:#9900CC;">instance</span>.<span style="color:#9900CC;">run</span><br />
<br />
results = Arachni::<span style="color:#9966CC; font-weight:bold;">Module</span>::Manager.<span style="color:#9900CC;">results</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> results.<span style="color:#9900CC;">count</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; matches.&quot;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s all for now, I hope you that found this post interesting &#8212; I certainly did.</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2011/12/04/programatically-scanning-using-arachni-part-5/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Programatically scanning using Arachni (Part 4)</title>
		<link>http://trainofthought.segfault.gr/2011/12/02/programatically-scanning-using-arachni-part-4/</link>
		<comments>http://trainofthought.segfault.gr/2011/12/02/programatically-scanning-using-arachni-part-4/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 00:10:44 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[audit]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[crawler]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[vulnerability scanner]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[webapp]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=1785</guid>
		<description><![CDATA[Since last time we discussed documentation (boring) this post will be about something functional (cool). And that coolness will in the form of a user interface, beginning with a simple progress output and moving to a full blown console environment &#8212; which also means scripting too. By the way, don&#8217;t forget to grab and install [...]]]></description>
			<content:encoded><![CDATA[<p>Since last time we discussed documentation (boring) this post will be about something functional (cool).<br />
And that coolness will in the form of a user interface, beginning with a simple progress output and moving to a full blown console environment &#8212; which also means scripting too. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>By the way, don&#8217;t forget to grab and install the code of the <a href="https://github.com/Zapotek/arachni/tree/experimental">experimental branch</a> and remember to keep it updated before going through each article.</p>
<h2>Creating a User Interface</h2>
<p>Let&#8217;s start simple, just a script that performs a scan like the ones we&#8217;ve seen so far:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/rpc/server/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get an instance of the options class</span><br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_forms</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this is the seed URL</span><br />
opts.<span style="color:#9900CC;">url</span> = <span style="color:#996600;">'http://testfire.net/'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># instantiate the framework</span><br />
framework = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load just the xss module</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load default plugins</span><br />
framework.<span style="color:#9900CC;">plugins</span>.<span style="color:#9900CC;">load_defaults</span>!<br />
<br />
framework.<span style="color:#9900CC;">run</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> framework.<span style="color:#9900CC;">audit_store</span>.<span style="color:#9900CC;">issues</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> i.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">', '</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>Nothing fancy, this will scan <a href="http://testfire.net">http://testfire.net</a>, audit all forms for XSS vulnerabilities and then print the names of the issues it found &#8212; XSS obviously, 2 of them.</p>
<h3>Helpers</h3>
<p>If we are to have a decent interface we&#8217;ll need some toys to make it more informative and appealing.<br />
Remember the <i>show_progress()</i> method from <a href="http://trainofthought.segfault.gr/2011/11/29/programatically-scanning-using-arachni-part-2/">Part 2</a>? Let&#8217;s take it up a notch.<br />
Let&#8217;s abstract the terminal related behavior and put it in its own module to remove duplication and ease re-use.</p>
<p><strong>terminal.rb</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Terminal manipulation methods</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> Terminal<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Clears the line before printing using 'puts'</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[String] &nbsp; &nbsp;str &nbsp;string to output</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> reputs<span style="color:#006600; font-weight:bold;">&#40;</span> str = <span style="color:#996600;">''</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reprint str <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Clears the line before printing</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[String] &nbsp; &nbsp;str &nbsp;string to output</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> reprint<span style="color:#006600; font-weight:bold;">&#40;</span> str = <span style="color:#996600;">''</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[0K&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> str<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Clear the bottom of the screen</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> clear_screen!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[2J&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Moves cursor top left to its home</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> move_to_home!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[H&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Flushes the STDOUT buffer</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> flush!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stdout</span>.<span style="color:#9900CC;">flush</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Check it out:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'terminal'</span><br />
<span style="color:#9966CC; font-weight:bold;">include</span> Terminal<br />
<br />
<span style="color:#008000; font-style:italic;"># clear the screen</span><br />
clear_screen!<br />
<br />
MAX = <span style="color:#006666;">5000</span><br />
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>..<span style="color:#9900CC;">MAX</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># move the cursor to its home, top-left of the screen.</span><br />
&nbsp; &nbsp; move_to_home!<br />
<br />
&nbsp; &nbsp; prog = &nbsp;i <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#CC0066; font-weight:bold;">Float</span><span style="color:#006600; font-weight:bold;">&#40;</span> MAX <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">100</span><br />
<br />
&nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Counting to #{MAX}...&quot;</span><br />
&nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Progress: &nbsp; #{prog}%&quot;</span><br />
&nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Current: &nbsp; &nbsp;#{i}&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># make sure that everything is sent out on time</span><br />
&nbsp; &nbsp; flush!<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">0.003</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>Let&#8217;s stick a progressbar and ETA in there:<br />
<strong>progress_bar.rb</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Progress bar and ETA methods</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> ProgressBar<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Formats elapsed time to hour:min:sec</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> format_time<span style="color:#006600; font-weight:bold;">&#40;</span> t <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; t = t.<span style="color:#9900CC;">to_i</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sec = t <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">60</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; min = <span style="color:#006600; font-weight:bold;">&#40;</span> t <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006666;">60</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">60</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hour = t <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006666;">3600</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sprintf</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;%02d:%02d:%02d&quot;</span>, hour, min, sec <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Calculates ETA (Estimated Time of Arrival) based on current progress</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># and the start time of the operation.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Float] &nbsp; prog &nbsp; &nbsp; &nbsp; &nbsp; current progress percentage</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Time] &nbsp; start_time &nbsp; &nbsp;start time of the operation</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @return &nbsp; [String] &nbsp; &nbsp;ETA: hour:min:sec</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> eta<span style="color:#006600; font-weight:bold;">&#40;</span> prog, start_time <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@last_prog</span> <span style="color:#006600; font-weight:bold;">||</span>= prog<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@last_eta</span> &nbsp;<span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;ETA: --:--:--&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@last_prog</span> != prog<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elapsed = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> start_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eta &nbsp; &nbsp; = elapsed <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">100</span> <span style="color:#006600; font-weight:bold;">/</span> prog <span style="color:#006600; font-weight:bold;">-</span> elapsed<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eta_str = <span style="color:#996600;">&quot;ETA: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> format_time<span style="color:#006600; font-weight:bold;">&#40;</span> eta <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eta_str = <span style="color:#0066ff; font-weight:bold;">@last_eta</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prog = <span style="color:#0066ff; font-weight:bold;">@last_prog</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@last_prog</span> = prog<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@last_eta</span> &nbsp;= eta_str<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Returns an ASCII progress bar based on the current progress percentage</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Float] &nbsp; &nbsp; prog_percentage &nbsp; &nbsp; progress percentage</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @return &nbsp; [String] &nbsp; &nbsp;70% [=======&gt; &nbsp;] 100%</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> progress_bar<span style="color:#006600; font-weight:bold;">&#40;</span> prog_percentage <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; prog &nbsp;= prog_percentage.<span style="color:#9900CC;">ceil</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">1</span> ? <span style="color:#006666;">1</span> : prog_percentage.<span style="color:#9900CC;">ceil</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; bar = <span style="color:#996600;">'='</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006600; font-weight:bold;">&#40;</span>prog <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'&gt;'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; space = <span style="color:#006666;">100</span> <span style="color:#006600; font-weight:bold;">-</span> prog<br />
&nbsp; &nbsp; &nbsp; &nbsp; bar <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">' '</span> <span style="color:#006600; font-weight:bold;">*</span> space<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;#{prog_percentage}% [#{bar}] 100% &quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>&#8230;and update our simple example:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'terminal'</span><br />
require_relative <span style="color:#996600;">'progress_bar'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">include</span> Terminal<br />
<span style="color:#9966CC; font-weight:bold;">include</span> ProgressBar<br />
<br />
<span style="color:#008000; font-style:italic;"># clear the screen</span><br />
clear_screen!<br />
<br />
start_time = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span><br />
<br />
MAX = <span style="color:#006666;">5000</span><br />
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>..<span style="color:#9900CC;">MAX</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># move the cursor to its home, top-left of the screen.</span><br />
&nbsp; &nbsp; move_to_home!<br />
<br />
&nbsp; &nbsp; prog = &nbsp;i <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#CC0066; font-weight:bold;">Float</span><span style="color:#006600; font-weight:bold;">&#40;</span> MAX <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">100</span><br />
<br />
&nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Counting to #{MAX}...&quot;</span><br />
&nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Progress: &nbsp; #{prog}%&quot;</span><br />
&nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Current: &nbsp; &nbsp;#{i}&quot;</span><br />
<br />
&nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; reprint eta<span style="color:#006600; font-weight:bold;">&#40;</span> prog, start_time <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; &nbsp; &nbsp;&quot;</span><br />
&nbsp; &nbsp; reputs progress_bar<span style="color:#006600; font-weight:bold;">&#40;</span> prog.<span style="color:#9900CC;">ceil</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># make sure that everything is sent out on time</span><br />
&nbsp; &nbsp; flush!<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">0.003</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now that we&#8217;ve got our screen manipulation cleaned up and our widgets ready to go it&#8217;s time break down the old <i>show_progress()</i> method and update it to utilise our new resources.</p>
<p><strong>progress_helper.rb</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">require_relative <span style="color:#996600;">'terminal'</span><br />
require_relative <span style="color:#996600;">'progress_bar'</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Methods to help with progress presentation</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Requires the Terminal and ProgressBar modules to work.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> ProgressHelper<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Terminal<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> ProgressBar<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Show an auto refreshing progress screen</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_progress<span style="color:#006600; font-weight:bold;">&#40;</span> framework <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># reset the cursor to the home position</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; move_to_home!<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># the true flag updates the timer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stats = framework.<span style="color:#9900CC;">stats</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># the true flag forces the auditstore to refresh</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># instead of returning the cached object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; auditstore = framework.<span style="color:#9900CC;">audit_store</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; issues = auditstore.<span style="color:#9900CC;">issues</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">'Auditing '</span> <span style="color:#006600; font-weight:bold;">+</span> framework.<span style="color:#9900CC;">opts</span>.<span style="color:#9900CC;">url</span>.<span style="color:#9900CC;">to_s</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;====================================&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_progress_bar<span style="color:#006600; font-weight:bold;">&#40;</span> stats, framework.<span style="color:#9900CC;">opts</span>.<span style="color:#9900CC;">start_datetime</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_current_operation<span style="color:#006600; font-weight:bold;">&#40;</span> stats <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_modules<span style="color:#006600; font-weight:bold;">&#40;</span> framework.<span style="color:#9900CC;">modules</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_plugins<span style="color:#006600; font-weight:bold;">&#40;</span> framework.<span style="color:#9900CC;">plugins</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_statistics<span style="color:#006600; font-weight:bold;">&#40;</span> stats <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_issues<span style="color:#006600; font-weight:bold;">&#40;</span> issues <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs<br />
&nbsp; &nbsp; &nbsp; &nbsp; show_output<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#6666ff; font-weight:bold;">Arachni::UI::Output</span>.<span style="color:#9900CC;">flush_buffer</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; flush!<br />
&nbsp; &nbsp; &nbsp; &nbsp; framework.<span style="color:#9900CC;">running</span>?<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Outputs a progress bar and an ETA</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_progress_bar<span style="color:#006600; font-weight:bold;">&#40;</span> stats, start_time <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;# Scan progress&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;#{eta( stats[:progress], start_time )}&quot;</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot; &nbsp; &nbsp; &nbsp; #{progress_bar( stats[:progress] )}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Outputs the current operation, either:</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp;* 'Crawling' -- with the additional info of how many pages have been crawled, or</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp;* 'Currently auditing' -- and the page which is being audited</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_current_operation<span style="color:#006600; font-weight:bold;">&#40;</span> stats <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> stats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_page</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !stats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_page</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Currently auditing: #{stats[:current_page]}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> stats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:sitemap_size</span><span style="color:#006600; font-weight:bold;">&#93;</span> != <span style="color:#006666;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = stats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:sitemap_size</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#006666;">1</span> ? <span style="color:#996600;">''</span> : <span style="color:#996600;">'s'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plural = <span style="color:#996600;">&quot;#{stats[:sitemap_size]} page#{s} and counting!&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plural = <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Crawling...&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> plural<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Shows all loaded modules</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Arachni::ModuleManager] &nbsp; &nbsp;modules</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_modules<span style="color:#006600; font-weight:bold;">&#40;</span> modules <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;# Loaded modules&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs modules.<span style="color:#9900CC;">keys</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;, &quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Shows all running plugins</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Arachni::PluginManager] &nbsp; &nbsp;plugins</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_plugins<span style="color:#006600; font-weight:bold;">&#40;</span> plugins <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;# Running plugins&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#006600; font-weight:bold;">&#40;</span> plugins.<span style="color:#9900CC;">busy</span>? ? plugins.<span style="color:#9900CC;">job_names</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;, &quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#996600;">'None'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Shows a few output messages</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Array&lt;Hash&gt;] &nbsp; messages</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Integer] &nbsp; &nbsp; &nbsp; max &nbsp; &nbsp; &nbsp; &nbsp; maximum amount to output</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_output<span style="color:#006600; font-weight:bold;">&#40;</span> messages, max = <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;# Scanner output&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;------------------------------------&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># show a few messages at a time just to make the user feels in the loop</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; max.<span style="color:#9900CC;">times</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> msg_line = messages<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>msg = msg_line.<span style="color:#9900CC;">values</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">empty</span>?<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reputs msg<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">'.'</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">50</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Outputs some basic stats</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Hash] &nbsp;stats</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_statistics<span style="color:#006600; font-weight:bold;">&#40;</span> stats <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;# Statistics&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Sent #{stats[:requests]} requests.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;Received and analyzed #{stats[:responses]} responses.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">'In '</span> <span style="color:#006600; font-weight:bold;">+</span> stats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:time</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">'Average: '</span> <span style="color:#006600; font-weight:bold;">+</span> stats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:avg</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">' requests/second.'</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Outputs a summary of issues</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[Array&lt;Arachni::Issue&gt;] &nbsp; &nbsp; issues</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show_issues<span style="color:#006600; font-weight:bold;">&#40;</span> issues <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; plural = issues.<span style="color:#9900CC;">count</span> == <span style="color:#006666;">1</span> ? <span style="color:#996600;">''</span> : <span style="color:#996600;">'s'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;# #{issues.count} issue#{plural} found&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reputs <span style="color:#996600;">&quot;------------------------------------&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; issues.<span style="color:#9900CC;">each</span>.<span style="color:#9900CC;">with_index</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>issue, i<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;[#{i + 1}] #{issue.name} at #{issue.url} in&quot;</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot; #{issue.elem} input `#{issue.var}` using #{issue.method}.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<h3>Audit monitoring interface</h3>
<p>Combining all of these together we get:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/rpc/server/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
require_relative <span style="color:#996600;">'progress_helper'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">include</span> ProgressHelper<br />
<br />
<span style="color:#008000; font-style:italic;"># get an instance of the options class</span><br />
opts = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
<br />
opts.<span style="color:#9900CC;">audit_forms</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this is the seed URL</span><br />
opts.<span style="color:#9900CC;">url</span> = <span style="color:#996600;">'http://testfire.net/'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># instantiate the framework</span><br />
framework = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load just the xss module</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load default plugins</span><br />
framework.<span style="color:#9900CC;">plugins</span>.<span style="color:#9900CC;">load_defaults</span>!<br />
<br />
<span style="color:#008000; font-style:italic;"># put the scan operation in its own thread</span><br />
<span style="color:#008000; font-style:italic;"># so that we can do stuff while it's running -- like show progress data..</span><br />
scan = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> framework.<span style="color:#9900CC;">run</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
clear_screen!<br />
<br />
<span style="color:#008000; font-style:italic;"># show progress every 0.3 seconds while the scan is running</span><br />
show_progress<span style="color:#006600; font-weight:bold;">&#40;</span> framework <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">while</span> scan.<span style="color:#9900CC;">alive</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">0.3</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># the scan is finished, wait for the thread to return cleanly</span><br />
scan.<span style="color:#9900CC;">join</span></div></td></tr></tbody></table></div>
<p>And now you have a decent output interface to monitor your scripted scans. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
In case you can&#8217;t be bothered to run the examples and are just reading these articles out of curiosity this is what the output would be:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Auditing http://testfire.net/<br />
====================================<br />
<br />
# Scan progress<br />
------------------------------------<br />
ETA: 00:00:51 &nbsp; &nbsp; &nbsp; 20.31% [====================&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ] 100% <br />
<br />
Currently auditing: http://testfire.net/default.aspx?content=personal_deposit.htm<br />
<br />
# Loaded modules<br />
------------------------------------<br />
xss<br />
<br />
# Running plugins<br />
------------------------------------<br />
healthmap, timing_attacks, discovery, manual_verification, uniformity, content_types, autothrottle<br />
<br />
# Statistics<br />
------------------------------------<br />
Sent 85 requests.<br />
Received and analyzed 84 responses.<br />
In 00:00:12<br />
Average: 6 requests/second.<br />
<br />
# 1 issue found<br />
------------------------------------<br />
[1] Cross-Site Scripting (XSS) at http://testfire.net/search.aspx in form input `txtSearch` using GET.<br />
<br />
# Scanner output<br />
------------------------------------<br />
Auditing: [HTTP: 200] http://testfire.net/default.aspx?content=personal_deposit.htm<br />
Harvesting HTTP responses...<br />
Depending on server responsiveness and network conditions this may take a while.<br />
Harvesting HTTP responses...<br />
Depending on server responsiveness and network conditions this may take a while.<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................</div></td></tr></tbody></table></div>
<h3>Building the Console</h3>
<p>First off, the Console will have a dependency, <i>readline</i> which can be a bitch to install sometimes which is why we&#8217;ll use the pure Ruby implementation <i>rb-readline</i>:</p>
<pre>gem install rb-readline</pre>
<p>Readline helps with&#8230;reading lines, duh!<br />
It does a little more than that though, it can provide us with a smart prompt which can keep history allow shortcuts, interpret escape sequences, provide auto-completion etc.</p>
<p>Try this <a href="https://github.com/luislavena/rb-readline/blob/master/examples/example_readline_with_completion.rb">example</a> to see it in action.</p>
<p>To the point&#8230;<br />
Ruby makes this sort of thing a pleasure, Consoles, DSLs etc. feel natural.</p>
<p>Our Console will operate under a single premise: <i>The prompt will simply provide access to the methods of class.</i><br />
And to be more specific, the Console will initiate the prompt which will provide access to all its <strong>declared</strong> and <strong>public</strong> methods.</p>
<p>This will allow us to easily extend our console class to accommodate any specialised needs, like creating a console for Arachni.</p>
<h4>Base class</h4>
<p>The whole thing is easier than you might think, just a few lines and bam!<br />
<strong>console.rb</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'readline'</span><br />
require_relative <span style="color:#996600;">'terminal'</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Basic Console with a readline prompt.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Extend it and it will provide access to the explicitly declared</span><br />
<span style="color:#008000; font-style:italic;"># and public methods of your class.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># This means no private method and no parent methods.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> Console<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Terminal<br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Initializes the Console and starts the prompt.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># The Console will use the IO interfaces you specify,</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># however Readline will not so your best bet is to override</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># $stdout and $stdin in order to redirect the streams.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[IO] &nbsp; &nbsp;stdout &nbsp;output stream</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># @param &nbsp; &nbsp;[IO] &nbsp; &nbsp;stdin &nbsp; input stream</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span> stdout = <span style="color:#ff6633; font-weight:bold;">$stdout</span>, stdin = <span style="color:#ff6633; font-weight:bold;">$stdin</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stdout</span> = <span style="color:#0066ff; font-weight:bold;">@stdout</span> = stdout<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stdin</span> &nbsp;= <span style="color:#0066ff; font-weight:bold;">@stdin</span> &nbsp;= stdin<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># combine the methods of self (which may be a child) with the methods</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># of the Console</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; methods = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">instance_methods</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">|</span> Console.<span style="color:#9900CC;">instance_methods</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># make a list of all available public methods/commands</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@cmd_list</span> = methods.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span> m.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">sort</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># setup auto-completion params</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; comp = <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#0066ff; font-weight:bold;">@cmd_list</span>.<span style="color:#9900CC;">grep</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#008000; font-style:italic;">#{Regexp.escape( s )}/) }</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">Readline</span>.<span style="color:#9900CC;">completion_append_character</span> = <span style="color:#996600;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">Readline</span>.<span style="color:#9900CC;">completion_proc</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = comp<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> out = banner<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> out<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># loop until someone requests an exit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line = <span style="color:#CC0066; font-weight:bold;">Readline</span>::<span style="color:#CC0066; font-weight:bold;">readline</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'&gt; '</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">empty</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">break</span> <span style="color:#9966CC; font-weight:bold;">if</span> line =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#CC0066; font-weight:bold;">exit</span><span style="color:#006600; font-weight:bold;">|</span>quit<span style="color:#006600; font-weight:bold;">/</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">Readline</span>::HISTORY.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span> line <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># tokenize the line based whitespace</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># the first token will be the command name and the rest of the tokens</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># will be the arguments for that command</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; meth, <span style="color:#006600; font-weight:bold;">*</span>args = <span style="color:#006600; font-weight:bold;">*</span>line.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">/</span>\s<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># make sure that the command exists</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !@cmd_list.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> meth <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'Unknown command: '</span> <span style="color:#006600; font-weight:bold;">+</span> meth <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;Valid commands: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> commands<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># extract an unbound method so that we can check for arity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; meth = method<span style="color:#006600; font-weight:bold;">&#40;</span> meth.<span style="color:#9900CC;">to_sym</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># if arity doesn't match the provided arguments pass them as an array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = <span style="color:#006600; font-weight:bold;">&#40;</span> meth.<span style="color:#9900CC;">arity</span> != args.<span style="color:#9900CC;">count</span> <span style="color:#006600; font-weight:bold;">&#41;</span> ? meth.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span> args <span style="color:#006600; font-weight:bold;">&#41;</span> : meth.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">*</span>args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># return the result of the command</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> res.<span style="color:#9900CC;">is_a</span>? <span style="color:#CC0066; font-weight:bold;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> res<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> res.<span style="color:#9900CC;">inspect</span> <span style="color:#9966CC; font-weight:bold;">if</span> res<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> e.<span style="color:#9900CC;">to_s</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> e.<span style="color:#9900CC;">backtrace</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># to be overriden by children</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> banner<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># add this empty exit method just so that it'll auto-complete</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#CC0066; font-weight:bold;">exit</span>; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> <span style="color:#ff3333; font-weight:bold;">:quit</span> :<span style="color:#CC0066; font-weight:bold;">exit</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># returns all available commands</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> commands<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@cmd_list</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">' &nbsp; &nbsp; '</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># loads and evaluates a console script</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> source<span style="color:#006600; font-weight:bold;">&#40;</span> file_path <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; instance_eval<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span> file_path.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># clears the screen</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> clear<br />
&nbsp; &nbsp; &nbsp; &nbsp; clear_screen!<br />
&nbsp; &nbsp; &nbsp; &nbsp; move_to_home!<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; private<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> force_string<span style="color:#006600; font-weight:bold;">&#40;</span> arg <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> arg.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">' '</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> arg.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC0066; font-weight:bold;">Array</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; arg.<span style="color:#9900CC;">to_s</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span> str = <span style="color:#996600;">''</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">print</span> str<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#CC0066; font-weight:bold;">print</span><span style="color:#006600; font-weight:bold;">&#40;</span> str = <span style="color:#996600;">''</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@stdout</span>.<span style="color:#CC0066; font-weight:bold;">print</span> str<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Console.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">__FILE__</span> == $0</div></td></tr></tbody></table></div>
<p>Let&#8217;s take it for a spin, shall we?</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ruby console.rb <br />
&gt; &lt;tab&gt;&lt;tab&gt;<br />
banner &nbsp; &nbsp;clear &nbsp; &nbsp; commands &nbsp;exit &nbsp; &nbsp; &nbsp;quit &nbsp; &nbsp; &nbsp;source &nbsp; &nbsp;<br />
&gt; commands <br />
banner &nbsp; &nbsp; clear &nbsp; &nbsp; commands &nbsp; &nbsp; exit &nbsp; &nbsp; quit &nbsp; &nbsp; source<br />
&gt; exit</div></td></tr></tbody></table></div>
<p>Doesn&#8217;t do much, yet&#8230;let&#8217;s extend it to do something more interesting.</p>
<h5>Console demo &#8211; The Jukebox</h5>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/rpc/server/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
require_relative <span style="color:#996600;">'console'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> Jukebox <span style="color:#006600; font-weight:bold;">&lt;</span> Console<br />
<br />
&nbsp; &nbsp; VERSION = <span style="color:#996600;">'0.1'</span><br />
<br />
&nbsp; &nbsp; SONGS &nbsp; = <span style="color:#006600; font-weight:bold;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Dream Theater'</span>, <span style="color:#996600;">'A Change of Seasons'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Iron Maiden'</span>, <span style="color:#996600;">'Paschendale'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Pain of Salvation'</span>, <span style="color:#996600;">'Fandango'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Steve Vai'</span>, <span style="color:#996600;">'For the love of god'</span> <span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Joe Satriani'</span>, <span style="color:#996600;">'Andalusia'</span> <span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> banner<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;#{self.class} v#{VERSION}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> list<br />
&nbsp; &nbsp; &nbsp; &nbsp; SONGS.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>song<span style="color:#006600; font-weight:bold;">|</span> format_song<span style="color:#006600; font-weight:bold;">&#40;</span> song <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> play<span style="color:#006600; font-weight:bold;">&#40;</span> title <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; title = force_string<span style="color:#006600; font-weight:bold;">&#40;</span> title <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">downcase</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; song = find_by_title<span style="color:#006600; font-weight:bold;">&#40;</span> title <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'Song does not exist.'</span> <span style="color:#9966CC; font-weight:bold;">if</span> !song<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@now_playing</span> = song<br />
&nbsp; &nbsp; &nbsp; &nbsp; now_playing<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> now_playing<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Now playing: #{format_song( @now_playing )}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; private<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> format_song<span style="color:#006600; font-weight:bold;">&#40;</span> song <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;#{song[0]} - #{song[1]}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> find_by_title<span style="color:#006600; font-weight:bold;">&#40;</span> title <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SONGS.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>song<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> song <span style="color:#9966CC; font-weight:bold;">if</span> song<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">downcase</span> == title.<span style="color:#9900CC;">downcase</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">nil</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Jukebox.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">__FILE__</span> == $0</div></td></tr></tbody></table></div>
<p>And run it:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Jukebox v0.1<br />
&gt; list <br />
Dream Theater - A Change of Seasons<br />
Iron Maiden - Paschendale<br />
Pain of Salvation - Fandango<br />
Steve Vai - For the love of god<br />
Joe Satriani - Andalusia<br />
&gt; play andalusia<br />
Now playing: Joe Satriani - Andalusia<br />
&gt; now_playing <br />
Now playing: Joe Satriani - Andalusia<br />
&gt; exit</div></td></tr></tbody></table></div>
<p>There&#8217;s one feature we haven&#8217;t touched yet though, the <i>source</i> command, something familiar to *nix users.<br />
That command will allow us to load and run Console scripts.<br />
These scripts are not limited by the syntax restrictions of the prompt and are evaluated under the namespace of the console.<br />
So you can write vanilla Ruby code and take advantage of the Console&#8217;s functionality at the same time.</p>
<p><strong>shuffle.jukescript</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SONGS.<span style="color:#9900CC;">shuffle</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>song<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; play song<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Jukebox v0.1<br />
&gt; source shuffle.jukescript<br />
Now playing: Pain of Salvation - Fandango<br />
Now playing: Dream Theater - A Change of Seasons<br />
Now playing: Joe Satriani - Andalusia<br />
Now playing: Steve Vai - For the love of god<br />
Now playing: Iron Maiden - Paschendale<br />
&gt;</div></td></tr></tbody></table></div>
<h3>The Arachni Console</h3>
<p>Since you&#8217;re already somewhat familiar with the framework and the Console is quite simple I won&#8217;t explain everything beat-by-beat this time.<br />
Instead, I&#8217;m gonna just paste the ArachniConsole code and play with it a bit.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/rpc/server/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
require_relative <span style="color:#996600;">'console'</span><br />
require_relative <span style="color:#996600;">'progress_helper'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Console</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Console<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> ProgressHelper<br />
<br />
&nbsp; &nbsp; VERSION = <span style="color:#996600;">'0.1'</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<br />
&nbsp; &nbsp; &nbsp; &nbsp; reset<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># returns shows a banner</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> banner<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;Arachni - Web Application Security Scanner Framework v#{@framework.version}<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;Console v#{VERSION}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># executes a shell/OS command</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;sh ls -la *</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> sh<span style="color:#006600; font-weight:bold;">&#40;</span> cmd <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">`#{force_string( cmd )}`</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># performs a demo scan</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;demo</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;demo silent</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> demo<span style="color:#006600; font-weight:bold;">&#40;</span> opt = <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set <span style="color:#996600;">'url'</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#996600;">'http://testfire.net/'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># set 'link_count_limit', '1'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'modules'</span>, <span style="color:#996600;">'*'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'report'</span>, &nbsp;<span style="color:#996600;">'json'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; audit <span style="color:#996600;">'forms'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; audit <span style="color:#996600;">'links'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; audit <span style="color:#996600;">'cookies'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; run opt<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># sets exclude patterns</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;exclude test \.pdf$ \.exe$</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> exclude<span style="color:#006600; font-weight:bold;">&#40;</span> regexps <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">exclude</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>regexps<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">flatten</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>regexp<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> regexp <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># sets include patterns</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;include test \.html$</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span> regexps <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9966CC; font-weight:bold;">include</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>regexps<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">flatten</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>regexp<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> regexp <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># resets all settings</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> reset<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span> = <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">reset</span>!<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># instantiate the framework</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span> = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@opts</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">plugins</span>.<span style="color:#9900CC;">load_defaults</span>!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'Done!'</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># assigns val to opt</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;set url http://testfire.net</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;set link_count_limit 10</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> set<span style="color:#006600; font-weight:bold;">&#40;</span> opt, val <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;#{opt}=&quot;</span>.<span style="color:#9900CC;">to_sym</span>, cast<span style="color:#006600; font-weight:bold;">&#40;</span> opt, val <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># unsets an option</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;unset url</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;unset link_count_limit</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> unset<span style="color:#006600; font-weight:bold;">&#40;</span> opt <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<span style="color:#006600; font-weight:bold;">&#40;</span> opt, <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># shows an option</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;show url</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;show link_count_limit</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show<span style="color:#006600; font-weight:bold;">&#40;</span> opt <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'Expects argument.'</span> <span style="color:#9966CC; font-weight:bold;">if</span> opt.<span style="color:#9900CC;">empty</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;#{opt}&quot;</span>.<span style="color:#9900CC;">to_sym</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># imports an AFR report and sets it as the default audistore</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;import my_report.afr</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> import<span style="color:#006600; font-weight:bold;">&#40;</span> path_to_afr <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; path_to_afr = path_to_afr.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">' '</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> path_to_afr.<span style="color:#9900CC;">is_a</span>? <span style="color:#CC0066; font-weight:bold;">Array</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@auditstore</span> = <span style="color:#6666ff; font-weight:bold;">Arachni::AuditStore</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> path_to_afr <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;Loaded audit for #{@auditstore.options['url']} performed on&quot;</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot; #{@auditstore.start_datetime} with #{@auditstore.issues.count} issues.&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># exports the auditstore in 'type' format in file 'outfile'</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;export html my_report.html</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;export json my_json_report.json</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[...]</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> export<span style="color:#006600; font-weight:bold;">&#40;</span> type, outfile <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; auditstore = <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">audit_store</span> <span style="color:#9966CC; font-weight:bold;">if</span> !<span style="color:#006600; font-weight:bold;">&#40;</span> auditstore = <span style="color:#0066ff; font-weight:bold;">@auditstore</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">reports</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">reports</span><span style="color:#006600; font-weight:bold;">&#91;</span>type<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">reports</span><span style="color:#006600; font-weight:bold;">&#91;</span>type<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'outfile'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = outfile <span style="color:#9966CC; font-weight:bold;">if</span> outfile<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">reports</span>.<span style="color:#9900CC;">run_one</span><span style="color:#006600; font-weight:bold;">&#40;</span> type, auditstore <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># load components by type and name</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; load modules xss*,sqli*</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; load plugins defaults/*</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; load report json,txt</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> type, names <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; names = force_string<span style="color:#006600; font-weight:bold;">&#40;</span> names <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">','</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">case</span> type<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'module'</span>, <span style="color:#996600;">'modules'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">modules</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> names <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'plugin'</span>, <span style="color:#996600;">'plugins'</span>, <span style="color:#996600;">'plug-ins'</span>, <span style="color:#996600;">'plug-in'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">plugins</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> names <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'report'</span>, <span style="color:#996600;">'reports'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">reports</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reps = <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">reports</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> names <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reps.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rep<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">reports</span><span style="color:#006600; font-weight:bold;">&#91;</span>rep<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'Unknown component type: '</span> <span style="color:#006600; font-weight:bold;">+</span> type.<span style="color:#9900CC;">to_s</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># sets elements to audit</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;audit links</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;audit forms</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;audit cookies</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;audit headers</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> audit<span style="color:#006600; font-weight:bold;">&#40;</span> types <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; valid = <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'links'</span>, <span style="color:#996600;">'forms'</span>, <span style="color:#996600;">'cookies'</span>, <span style="color:#996600;">'headers'</span> <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>types<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">flatten</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>type<span style="color:#006600; font-weight:bold;">|</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !valid.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> type <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'Invalid element type: '</span> <span style="color:#006600; font-weight:bold;">+</span> type.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'Valid types: '</span> <span style="color:#006600; font-weight:bold;">+</span> valid.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;, &quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">break</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set <span style="color:#996600;">'audit_'</span> <span style="color:#006600; font-weight:bold;">+</span> type, <span style="color:#996600;">'true'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># runs the audit</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;run</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;run silent</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> run<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">*</span>args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@job</span> = run_in_thread<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#9966CC; font-weight:bold;">if</span> silent?<span style="color:#006600; font-weight:bold;">&#40;</span> args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; progress<br />
&nbsp; &nbsp; &nbsp; &nbsp; clear_screen!<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># attach to running scan</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> attach<br />
&nbsp; &nbsp; &nbsp; &nbsp; progress<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># show progress of running scan</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;progress</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;progress glimpse</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> progress<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">*</span>args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'No scan running.'</span> <span style="color:#9966CC; font-weight:bold;">if</span> !running?<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; clear_screen!<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> glimpse?<span style="color:#006600; font-weight:bold;">&#40;</span> args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; show_progress<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@framework</span> &nbsp;<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">0.3</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">while</span> show_progress<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@framework</span> &nbsp;<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; show_progress<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@framework</span> &nbsp;<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@job</span>.<span style="color:#9900CC;">join</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'Done!'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># pauses running scan</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> pause<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">pause</span>!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'Will pause as soon as possible...'</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># resumes running scan</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> resume<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">resume</span>!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'Resuming!'</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># kills/aborts running scan</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> kill<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">clean_up</span>!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@job</span>.<span style="color:#CC0066; font-weight:bold;">exit</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> <span style="color:#ff3333; font-weight:bold;">:abort</span> <span style="color:#ff3333; font-weight:bold;">:kill</span><br />
<br />
&nbsp; &nbsp; private<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> running?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@job</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#0066ff; font-weight:bold;">@job</span>.<span style="color:#9900CC;">alive</span>?<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> glimpse?<span style="color:#006600; font-weight:bold;">&#40;</span> args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; includes_modifier?<span style="color:#006600; font-weight:bold;">&#40;</span> args, <span style="color:#ff3333; font-weight:bold;">:glimpse</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> silent?<span style="color:#006600; font-weight:bold;">&#40;</span> args <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; includes_modifier?<span style="color:#006600; font-weight:bold;">&#40;</span> args, <span style="color:#ff3333; font-weight:bold;">:silent</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> includes_modifier?<span style="color:#006600; font-weight:bold;">&#40;</span> args, modifier <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; args.<span style="color:#9900CC;">flatten</span>!<br />
&nbsp; &nbsp; &nbsp; &nbsp; args.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> modifier <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> args.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> modifier.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> run_in_thread<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#0066ff; font-weight:bold;">@framework</span>.<span style="color:#9900CC;">run</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> cast<span style="color:#006600; font-weight:bold;">&#40;</span> opt, val <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; default = <span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;@#{opt}&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">case</span> default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC00FF; font-weight:bold;">Fixnum</span>, <span style="color:#CC0066; font-weight:bold;">Integer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_i</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">Float</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_f</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">String</span>, <span style="color:#CC00FF; font-weight:bold;">URI</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_s</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC00FF; font-weight:bold;">TrueClass</span>, <span style="color:#CC00FF; font-weight:bold;">FalseClass</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">downcase</span> == <span style="color:#996600;">'true'</span> ? <span style="color:#0000FF; font-weight:bold;">true</span> : <span style="color:#0000FF; font-weight:bold;">false</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_a</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC00FF; font-weight:bold;">Hash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_h</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val.<span style="color:#9900CC;">to_s</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">Arachni::Console</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">__FILE__</span> == $0</div></td></tr></tbody></table></div>
<p>Let&#8217;s jump in!</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Arachni - Web Application Security Scanner Framework v0.4<br />
Console v0.1<br />
&gt; demo</div></td></tr></tbody></table></div>
<p>Ah, that&#8217;s a familiar sight, it&#8217;s the progress screen from a couple of chapters ago. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To detach and return to the prompt hit Ctrl-C, don&#8217;t worry about the error messages the scan won&#8217;t die.<br />
Say you want to take a glimpse of the running scan while detached:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt; progress glimpse<br />
Auditing http://testfire.net/<br />
====================================<br />
<br />
# Scan progress<br />
------------------------------------<br />
ETA: 00:14:13 &nbsp; &nbsp; &nbsp; 13.07% [=============&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;] 100% <br />
<br />
Currently auditing: http://testfire.net/default.aspx?content=inside.htm<br />
<br />
# Loaded modules<br />
------------------------------------<br />
interesting_responses, common_files, mixed_resource, xst, http_put, webdav, directory_listing, allowed_methods, htaccess_limit, ssn, private_ip, emails, credit_card, cvs_svn_users, captcha, html_objects, unencrypted_password_forms, backdoors, backup_files, common_directories, trainer, os_cmd_injection, sqli, xss_script_tag, sqli_blind_rdiff, path_traversal, xss_event, xss_uri, sqli_blind_timing, code_injection, rfi, xss_tag, response_splitting, csrf, os_cmd_injection_timing, ldapi, code_injection_timing, xss_path, xpath, unvalidated_redirect, xss<br />
<br />
# Running plugins<br />
------------------------------------<br />
healthmap, timing_attacks, discovery, manual_verification, uniformity, content_types, autothrottle<br />
<br />
# Statistics<br />
------------------------------------<br />
Sent 5873 requests.<br />
Received and analyzed 5725 responses.<br />
In 00:01:29<br />
Average: 44 requests/second.<br />
<br />
# 7 issues found<br />
------------------------------------<br />
[1] Cross-Site Scripting (XSS) at http://testfire.net/search.aspx in form input `txtSearch` using GET.<br />
[2] Path Traversal at http://testfire.net/default.aspx in link input `content` using GET.<br />
[3] Allowed HTTP methods at HTTP://testfire.net in server input `` using OPTIONS.<br />
[4] Interesting server response. at http://testfire.net/admin/ in server input `` using GET.<br />
[5] Interesting server response. at http://testfire.net/default.aspx in server input `` using GET.<br />
[6] Found an HTML object. at http://testfire.net/default.aspx in body input `` using GET.<br />
[7] Interesting server response. at http://testfire.net/default.aspx/%3Carachni_xss_uri_7b063a2cf51c145d46e218f8b1697adb21339ba91fd57912bd5057b8d485a684 in server input `` using GET.<br />
<br />
# Scanner output<br />
------------------------------------<br />
PathTraversal: Analyzing response #5726...<br />
PathTraversal: Analyzing response #5727...<br />
PathTraversal: Analyzing response #5711...<br />
PathTraversal: Analyzing response #5728...<br />
PathTraversal: Analyzing response #5714...<br />
PathTraversal: Analyzing response #5729...<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
&gt;</div></td></tr></tbody></table></div>
<p>And say you want to attach to the running scan and monitor its progress:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt; attach</div></td></tr></tbody></table></div>
<p>Hint: <i>progress</i> without the <i>glimpse</i> argument would do the same&#8230;</p>
<p>Now lets say you want to get a preliminary report while the scan is running:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt; export html myreport.html<br />
&gt; sh ls *.html<br />
myreport.html<br />
<br />
&gt; sh firefox myreport.html</div></td></tr></tbody></table></div>
<p>Aha! The report contained what we were looking for, kill the scan!</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt; kill<br />
#&lt;Thread:0x000000023f9588 aborting&gt;<br />
&gt; kill<br />
#&lt;Thread:0x000000023f9588 dead&gt;</div></td></tr></tbody></table></div>
<p>And if the fucker won&#8217;t die you can skip the clean up process by:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt; kill force<br />
#&lt;Thread:0x000000023f9588 dead&gt;</div></td></tr></tbody></table></div>
<p>And if you want to import a previous report:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt; sh ls *.afr<br />
2011-12-02 01.26.32 +0200.afr<br />
<br />
&gt; import 2011-12-02 01.26.32 +0200.afr<br />
Loaded audit for http://testfire.net/ performed on Fri Dec &nbsp;2 01:25:50 2011 with 7 issues.<br />
&gt; export json report.json<br />
&gt; sh ls *.json<br />
report.json<br />
<br />
&gt;</div></td></tr></tbody></table></div>
<p>And of course&#8230;scripting:<br />
<strong>testfire</strong></p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">set <span style="color:#996600;">'url'</span>, <span style="color:#996600;">'http://testfire.net/'</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'modules'</span>, <span style="color:#996600;">'*'</span><br />
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'plugins'</span>, <span style="color:#996600;">'defaults/*'</span><br />
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'report'</span>, &nbsp;<span style="color:#996600;">'json'</span><br />
<br />
audit <span style="color:#996600;">'forms'</span><br />
audit <span style="color:#996600;">'links'</span><br />
audit <span style="color:#996600;">'cookies'</span><br />
<br />
run <span style="color:#ff3333; font-weight:bold;">:silent</span><br />
progress <span style="color:#ff3333; font-weight:bold;">:glimpse</span></div></td></tr></tbody></table></div>
<p>Output:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Arachni - Web Application Security Scanner Framework v0.4<br />
Console v0.1<br />
&gt; source testfire<br />
<br />
Auditing http://testfire.net/<br />
====================================<br />
<br />
# Scan progress<br />
------------------------------------<br />
ETA: --:--:-- &nbsp; &nbsp; &nbsp; 0.0% [&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ] 100% <br />
<br />
Crawling...<br />
<br />
# Loaded modules<br />
------------------------------------<br />
interesting_responses, common_files, mixed_resource, xst, http_put, webdav, directory_listing, allowed_methods, htaccess_limit, ssn, private_ip, emails, credit_card, cvs_svn_users, captcha, html_objects, unencrypted_password_forms, backdoors, backup_files, common_directories, trainer, os_cmd_injection, sqli, xss_script_tag, sqli_blind_rdiff, path_traversal, xss_event, xss_uri, sqli_blind_timing, code_injection, rfi, xss_tag, response_splitting, csrf, os_cmd_injection_timing, ldapi, code_injection_timing, xss_path, xpath, unvalidated_redirect, xss<br />
<br />
# Running plugins<br />
------------------------------------<br />
healthmap, timing_attacks, discovery, manual_verification, uniformity, content_types, autothrottle<br />
<br />
# Statistics<br />
------------------------------------<br />
Sent 0 requests.<br />
Received and analyzed 0 responses.<br />
In 00:00:00<br />
Average: 0 requests/second.<br />
<br />
# 0 issues found<br />
------------------------------------<br />
<br />
# Scanner output<br />
------------------------------------<br />
Waiting for plugins to settle...<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
..................................................<br />
&gt;</div></td></tr></tbody></table></div>
<p>Quite a long post this one but it was well worth the effort&#8230;barely, heh.<br />
Anyways, that&#8217;s all for now, the next part will be a lot more hardcore and will demonstrate a highly specialised audit that will be customisable down to the individual element.</p>
<p>See ya then&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2011/12/02/programatically-scanning-using-arachni-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programatically scanning using Arachni (Part 3)</title>
		<link>http://trainofthought.segfault.gr/2011/12/01/programatically-scanning-using-arachni-part-3/</link>
		<comments>http://trainofthought.segfault.gr/2011/12/01/programatically-scanning-using-arachni-part-3/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 00:57:09 +0000</pubDate>
		<dc:creator>Zapotek</dc:creator>
				<category><![CDATA[Arachni]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[arachni]]></category>
		<category><![CDATA[audit]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[crawler]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[manager]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[vulnerability scanner]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://trainofthought.segfault.gr/?p=1747</guid>
		<description><![CDATA[Managing components Time to leave the framework for now and get back to some basics since after seeing things as a whole you&#8217;ll better appreciate these important details. All components (modules, reports, plugins and the unappreciated path extractors) are handled by the ComponentManager. The manager&#8217;s job is simple and can be described as: Given the [...]]]></description>
			<content:encoded><![CDATA[<h2>Managing components</h2>
<p>Time to leave the framework for now and get back to some basics since after seeing things as a whole you&#8217;ll better appreciate these important details.</p>
<p>All components (modules, reports, plugins and the unappreciated path extractors) are handled by the ComponentManager.<br />
The manager&#8217;s job is simple and can be described as:</p>
<blockquote><p>Given the path to a library and the namespace of the components it allows manipulation and organization of said components.</p></blockquote>
<p>For example, the library of the Arachni modules is <em>/modules</em> and all modules live under the namespace of the <em>Arachni::Modules</em> module.<br />
Unless you want to create your own components you won&#8217;t have to deal with that manager directly, you&#8217;ll only deal with its children:</p>
<ol>
<li>ModuleManager</li>
<li>ReportManager</li>
<li>PluginManager</li>
</ol>
<p>(The path extractors don&#8217;t get their own manager because they&#8217;re quite simple in nature.)</p>
<p>These managers extend the ComponentManager and because the ComponentManager extends the Hash class working with them will feel quite natural.<br />
Finally, the Framework provides you with access to all the discussed managers and they, in turn, provide you with access to the components they manage.</p>
<p>By convention, all components have the following methods:</p>
<ol>
<li><em>prepare</em> &#8212; <strong>Optional</strong>, allows them to prepare their environment</li>
<li><em>run</em> &#8212; <strong>Mandatory</strong>, executes the main payload.</li>
<li><em>clean_up</em> &#8212; <strong>Optional</strong>, gives them a chance to clean up after themselves.</li>
<li><em>self.info</em> &#8212; <strong>Mandatory</strong>, returns general info like version number, name, author, etc.. Actual format depends on component type.</li>
</ol>
<p>Let&#8217;s see how these manager work and what they can do. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-1747"></span></p>
<h3>Component manager by example</h3>
<p>Let&#8217;s use the ModuleManager as a working ComponentManager to discover what it can actually do.<br />
The following demonstrated functionality is shared amongst all component managers and is not ModuleManagement specific.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get the module manager</span><br />
modules = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span> <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">modules</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's see what it holds</span><br />
ap modules<br />
<span style="color:#008000; font-style:italic;"># =&gt; {}</span><br />
<span style="color:#008000; font-style:italic;"># so pretty much nothing...</span><br />
<br />
<span style="color:#008000; font-style:italic;"># however, it allows us to do this:</span><br />
ap modules<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'xss'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">info</span><br />
<br />
<span style="color:#008000; font-style:italic;"># the module manager will look for the 'xss' module and load it for you</span><br />
<span style="color:#008000; font-style:italic;"># if it't not already loaded, see:</span><br />
ap modules<br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># {</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;&quot;xss&quot; =&gt; Arachni::Modules::XSS &lt; Arachni::Module::Base</span><br />
<span style="color:#008000; font-style:italic;"># }</span><br />
<br />
<span style="color:#008000; font-style:italic;"># see all available modules by name</span><br />
ap modules.<span style="color:#9900CC;">available</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 0] &quot;interesting_responses&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 1] &quot;common_files&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 2] &quot;mixed_resource&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 3] &quot;xst&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 4] &quot;http_put&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 5] &quot;webdav&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 6] &quot;directory_listing&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp;[ 7] &quot;allowed_methods&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp;[...and many more...]</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load all available modules using the wildcard</span><br />
modules.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'*'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's see what the manager holds now</span><br />
ap modules<br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># {</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;xss&quot; =&gt; Arachni::Modules::XSS &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;interesting_responses&quot; =&gt; Arachni::Modules::InterestingResponses &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;common_files&quot; =&gt; Arachni::Modules::CommonFiles &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;mixed_resource&quot; =&gt; Arachni::Modules::MixedResource &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;xst&quot; =&gt; Arachni::Modules::XST &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;http_put&quot; =&gt; Arachni::Modules::HTTP_PUT &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;webdav&quot; =&gt; Arachni::Modules::WebDav &lt; Arachni::Module::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; [...etc...]</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's parse module names including wildcards and modifiers</span><br />
<span style="color:#008000; font-style:italic;"># to see to which modules they actually correspond</span><br />
ap modules.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'*'</span>, <span style="color:#996600;">'-xss_*'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># this one returns all modules by name while excluding the XSS ones</span><br />
<br />
<span style="color:#008000; font-style:italic;"># obvious what this does...</span><br />
ap modules.<span style="color:#9900CC;">wilcard_to_names</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'xss_*'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [0] &quot;xss_script_tag&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [1] &quot;xss_event&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [2] &quot;xss_uri&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [3] &quot;xss_tag&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [4] &quot;xss_path&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [5] &quot;xss&quot;</span><br />
<span style="color:#008000; font-style:italic;"># ]</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's say you want to find the path of a module</span><br />
ap modules.<span style="color:#9900CC;">name_to_path</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/audit/xss.rb&quot;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># and the exact opposite:</span><br />
ap modules.<span style="color:#9900CC;">path_to_name</span><span style="color:#006600; font-weight:bold;">&#40;</span> modules.<span style="color:#9900CC;">name_to_path</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; &quot;xss&quot;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># and say that you want to find the paths of all modules</span><br />
ap modules.<span style="color:#9900CC;">paths</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 0] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/interesting_responses.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 1] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/common_files.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 2] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/mixed_resource.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 3] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/xst.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 4] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/http_put.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 5] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/webdav.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [ 6] &quot;/home/zapotek/.rvm/gems/ruby-1.9.3-p0/gems/arachni-0.4/modules/recon/directory_listing.rb&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp;[...]</span></div></td></tr></tbody></table></div>
<h3>The ModuleManager</h3>
<p>Let&#8217;s see the extra stuff that the module manager let&#8217;s us do in a live scenario:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">Arachni::UI::Output</span>.<span style="color:#9900CC;">mute</span>!<br />
<br />
opts &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
opts.<span style="color:#9900CC;">audit_forms</span> &nbsp; &nbsp; &nbsp;= <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#996600;">'http://testfire.net/'</span><br />
opts.<span style="color:#9900CC;">link_count_limit</span> = <span style="color:#006666;">1</span><br />
<br />
framework = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># this block will be called every time the modules register any issues</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># careful though, these issues won't have any variations prepared</span><br />
<span style="color:#008000; font-style:italic;"># like the ones in the AuditStore</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Some modules register each result as they discover it and others prefer to</span><br />
<span style="color:#008000; font-style:italic;"># build an array of results and register them all at once or in batches.</span><br />
<span style="color:#008000; font-style:italic;"># What I mean is, don't count on a fixed behavior...</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#9900CC;">on_register_results</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>issues<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> issues.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>issue<span style="color:#006600; font-weight:bold;">|</span> issue.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;, &quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># you can prevent the issues from being stored if you'd rather</span><br />
<span style="color:#008000; font-style:italic;"># use the callback to manage them yourself</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># that's how the Grid slaves operate actually, they send their results to the</span><br />
<span style="color:#008000; font-style:italic;"># master directly instead of storing them locally.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#9900CC;">do_not_store</span>!<br />
<br />
<span style="color:#008000; font-style:italic;"># perform the audit</span><br />
framework.<span style="color:#9900CC;">run</span><br />
<br />
<span style="color:#008000; font-style:italic;"># this contains all stored issues (none in this case because none will be stored)</span><br />
ap framework.<span style="color:#9900CC;">modules</span>.<span style="color:#9900CC;">results</span><br />
<br />
<span style="color:#008000; font-style:italic;"># won't have any results because we ordered the manager not to store them</span><br />
framework.<span style="color:#9900CC;">audit_store</span>.<span style="color:#9900CC;">issues</span>.<span style="color:#9900CC;">each</span>.<span style="color:#9900CC;">with_index</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">|</span>issue, i<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; &nbsp; &nbsp;[#{i + 1}] #{issue.name} at #{issue.url} in #{issue.elem} input `#{issue.var}` using #{issue.method}.&quot;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Lastly, you can register results/issues.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># I'm showing this just for completeness' sake,</span><br />
<span style="color:#008000; font-style:italic;"># avoid registering your own issues directly.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># Always use modules to do the identification and logging!</span><br />
<span style="color:#008000; font-style:italic;"># They have helpers that will pass the proper data to instantiate Issues</span><br />
<span style="color:#008000; font-style:italic;"># and will try to fill-in as much info as possible.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
issue = <span style="color:#6666ff; font-weight:bold;">Arachni::Issue</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'My Issue'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#9900CC;">register_results</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>issue<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<h3>The PluginManager</h3>
<p>The PluginManager is more concerned with job scheduling.<br />
It runs each plugin in its own thread and provides methods to manipulate the threads.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">Arachni::UI::Output</span>.<span style="color:#9900CC;">mute</span>!<br />
<br />
opts &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
opts.<span style="color:#9900CC;">audit_forms</span> &nbsp; &nbsp; &nbsp;= <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#996600;">'http://testfire.net/'</span><br />
opts.<span style="color:#9900CC;">link_count_limit</span> = <span style="color:#006666;">1</span><br />
<br />
framework = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get the plugin manager...</span><br />
plugins = framework.<span style="color:#9900CC;">plugins</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># There are some plugins that gather very useful information while</span><br />
<span style="color:#008000; font-style:italic;"># introducing very little or no overhead at all.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># These are put under the /plugins/defaults directory and can be loaded like this:</span><br />
plugins.<span style="color:#9900CC;">load_defaults</span>!<br />
<br />
<span style="color:#008000; font-style:italic;"># which is the same as:</span><br />
<span style="color:#008000; font-style:italic;"># plugins.load( Arachni::Plugin::Manager::DEFAULT )</span><br />
<br />
<span style="color:#008000; font-style:italic;"># that's a simple wildcard</span><br />
<span style="color:#008000; font-style:italic;"># ap Arachni::Plugin::Manager::DEFAULT</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [0] &quot;defaults/*&quot;</span><br />
<span style="color:#008000; font-style:italic;"># ]</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's see what we loaded</span><br />
ap plugins<br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># {</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;healthmap&quot; =&gt; Arachni::Plugins::HealthMap &lt; Arachni::Plugin::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;timing_attacks&quot; =&gt; Arachni::Plugins::TimingAttacks &lt; Arachni::Plugin::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;discovery&quot; =&gt; Arachni::Plugins::Discovery &lt; Arachni::Plugin::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &quot;manual_verification&quot; =&gt; Arachni::Plugins::ManualVerification &lt; Arachni::Plugin::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;uniformity&quot; =&gt; Arachni::Plugins::Uniformity &lt; Arachni::Plugin::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content_types&quot; =&gt; Arachni::Plugins::ContentTypes &lt; Arachni::Plugin::Base,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;autothrottle&quot; =&gt; Arachni::Plugins::AutoThrottle &lt; Arachni::Plugin::Base</span><br />
<span style="color:#008000; font-style:italic;"># }</span><br />
<br />
<span style="color:#008000; font-style:italic;"># some plugins depend on certain gems and because gems can be platform</span><br />
<span style="color:#008000; font-style:italic;"># dependent they may not be available for some platforms</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># in order to streamline the process plugins can declare any gem dependencies</span><br />
<span style="color:#008000; font-style:italic;"># they may have and this is how you perform the check:</span><br />
ap plugins.<span style="color:#9900CC;">sane_env</span>?<span style="color:#006600; font-weight:bold;">&#40;</span> plugins<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'healthmap'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; true</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># If the environment isn't sane you'll get a hash with some details.</span><br />
<span style="color:#008000; font-style:italic;"># In such a case plugins.run will raise an exception and print some details.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<br />
<span style="color:#008000; font-style:italic;"># ap plugins.sane_env?( plugins['libnotify'] )</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># {</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; :gem_errors =&gt; [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; &nbsp; &nbsp; [0] &quot;libnotify&quot;</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; ]</span><br />
<span style="color:#008000; font-style:italic;"># }</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># that means that the plugin can't run without the &quot;libnotify&quot; gem.</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># this is how you get the options of a plugin</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># ap plugins['content_types'].info[:options]</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [0] #&lt;Arachni::OptString:0x00000001ec1ae8 @name=&quot;exclude&quot;, @required=false, @desc=&quot;Exclude content-types that match this regular expression.&quot;, @default=&quot;text&quot;, @enums=[]&gt;</span><br />
<span style="color:#008000; font-style:italic;"># ]</span><br />
<br />
<span style="color:#008000; font-style:italic;"># let's set some options now, shall we?</span><br />
opts.<span style="color:#9900CC;">plugins</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># this plugin is meant to match only interesting content-types</span><br />
&nbsp; &nbsp; <span style="color:#996600;">'content_types'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># let's undo that, heh...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'exclude'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># put this in its own thread so that we can inspect the plugins in the meantime</span><br />
scan = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># This will run all loaded plugins, each in its own thread:</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># plugins.run</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># however you shouldn't need to run this manually because</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># framework.run takes care of running the plugins and setting certain</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># framework parameters which are essential to them</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; framework.<span style="color:#9900CC;">run</span><br />
<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># This waits for plugins to finish and as soon as each one finishes</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># it's removed from the job list.</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># It's also handled by framework.run...</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># plugins.block!</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># true if there are any running plugins</span><br />
ap plugins.<span style="color:#9900CC;">busy</span>?<br />
<span style="color:#008000; font-style:italic;"># =&gt; true</span><br />
<br />
<span style="color:#008000; font-style:italic;"># returns the names of the running plugins</span><br />
ap plugins.<span style="color:#9900CC;">job_names</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [0] &quot;healthmap&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [1] &quot;timing_attacks&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [2] &quot;discovery&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [3] &quot;manual_verification&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [4] &quot;uniformity&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [5] &quot;content_types&quot;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [6] &quot;autothrottle&quot;</span><br />
<span style="color:#008000; font-style:italic;"># ]</span><br />
<br />
<br />
<span style="color:#008000; font-style:italic;"># returns the threads of the plugins</span><br />
ap plugins.<span style="color:#9900CC;">jobs</span><br />
<span style="color:#008000; font-style:italic;"># =&gt;</span><br />
<span style="color:#008000; font-style:italic;"># [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [0] #&lt;Thread:0x00000001fcdb80 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [1] #&lt;Thread:0x00000001fcd810 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [2] #&lt;Thread:0x00000001fcd630 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [3] #&lt;Thread:0x00000001fd5100 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [4] #&lt;Thread:0x00000001fd4ea8 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [5] #&lt;Thread:0x00000001fd4cf0 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [6] #&lt;Thread:0x00000001fb3b40 dead&gt;</span><br />
<span style="color:#008000; font-style:italic;"># ]</span><br />
<br />
<br />
<span style="color:#008000; font-style:italic;"># get's the thread of a plugin by name</span><br />
ap plugins.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'healthmap'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; #&lt;Thread:0x00000001fcdb80 sleep&gt;</span><br />
<br />
<br />
<span style="color:#008000; font-style:italic;"># that's an easy one...</span><br />
ap plugins.<span style="color:#9900CC;">kill</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'healthmap'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; #&lt;Thread:0x00000001fcdb80 aborting&gt;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># the first one (the healthmap) will have died...</span><br />
ap plugins.<span style="color:#9900CC;">jobs</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; [</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [0] #&lt;Thread:0x00000001fcdb80 dead&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [1] #&lt;Thread:0x00000001fcd810 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [2] #&lt;Thread:0x00000001fcd630 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [3] #&lt;Thread:0x00000001fd5100 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [4] #&lt;Thread:0x00000001fd4ea8 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [5] #&lt;Thread:0x00000001fd4cf0 sleep&gt;,</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; &nbsp; [6] #&lt;Thread:0x00000001fb3b40 dead&gt;</span><br />
<span style="color:#008000; font-style:italic;"># ]</span><br />
<br />
<span style="color:#008000; font-style:italic;"># you'll see the list getting smaller once the scan finishes</span><br />
plugin_inspector = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">while</span> scan.<span style="color:#9900CC;">alive</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'Rrunning plugins: '</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span> plugins.<span style="color:#9900CC;">busy</span>? ? plugins.<span style="color:#9900CC;">job_names</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;, &quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#996600;">'None'</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">0.3</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
scan.<span style="color:#9900CC;">join</span><br />
plugin_inspector.<span style="color:#9900CC;">join</span><br />
<br />
<span style="color:#008000; font-style:italic;"># and this is how you get any results the plugins might have stored</span><br />
ap framework.<span style="color:#9900CC;">audit_store</span>.<span style="color:#9900CC;">plugins</span></div></td></tr></tbody></table></div>
<h3>The ReportManager</h3>
<p>The report manager is <strong>boring</strong>, the only functionality it provides is a couple of methods for running reports but it can be helpful under certain circumstances.<br />
The framework has the tendency to run the AFR report whether you asked for it or not and there&#8217;s a very good reason for that.<br />
That&#8217;s the yardstick, the default report, the main audit DB; once you have that report you can convert the scan results to the other formats.</p>
<p>But you may not want to allow the framework to run it, or you may want to run the reports yourself or whatever.<br />
Let&#8217;s get to it:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni/ui/cli/output'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'arachni'</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">Arachni::UI::Output</span>.<span style="color:#9900CC;">mute</span>!<br />
<br />
opts &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#6666ff; font-weight:bold;">Arachni::Options</span>.<span style="color:#9900CC;">instance</span><br />
opts.<span style="color:#9900CC;">audit_forms</span> &nbsp; &nbsp; &nbsp;= <span style="color:#0000FF; font-weight:bold;">true</span><br />
opts.<span style="color:#9900CC;">url</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#996600;">'http://testfire.net/'</span><br />
opts.<span style="color:#9900CC;">link_count_limit</span> = <span style="color:#006666;">1</span><br />
<br />
framework = <span style="color:#6666ff; font-weight:bold;">Arachni::Framework</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts <span style="color:#006600; font-weight:bold;">&#41;</span><br />
framework.<span style="color:#9900CC;">modules</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'xss'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get the plugin manager...</span><br />
reports = framework.<span style="color:#9900CC;">reports</span><br />
<br />
<span style="color:#008000; font-style:italic;"># if we loaded the reports before running the framework then it'd take care of</span><br />
<span style="color:#008000; font-style:italic;"># running the reports itself, but we don't want to do that here....</span><br />
framework.<span style="color:#9900CC;">run</span><br />
<br />
<span style="color:#008000; font-style:italic;"># get the audit-store</span><br />
audit = framework.<span style="color:#9900CC;">audit_store</span><br />
<br />
<span style="color:#008000; font-style:italic;"># you have to preconfigure their options here</span><br />
opts.<span style="color:#9900CC;">reports</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#996600;">'json'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'outfile'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'audit.json'</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color:#996600;">'html'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">'outfile'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'audit.html'</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load the reports we specified</span><br />
reports.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span> opts.<span style="color:#9900CC;">reports</span>.<span style="color:#9900CC;">keys</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># run the loaded reports</span><br />
reports.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span> audit <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># run the loaded reports but not the AFR report unless specifically told</span><br />
reports.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span> audit, <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># load and run a single report</span><br />
reports.<span style="color:#9900CC;">run_one</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'html'</span>, audit <span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>Goodie, we got some technicalities out of the way in this post.<br />
The next part will feature a nice little interface that will allow us to monitor a few aspects of the scan including progress, status messages and general statistics. <img src='http://trainofthought.segfault.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
See you then.</p>
]]></content:encoded>
			<wfw:commentRss>http://trainofthought.segfault.gr/2011/12/01/programatically-scanning-using-arachni-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

