/buby

A JRuby implementation of the BurpExtender interface for PortSwigger Burp Suite.

Primary LanguageJava

buby

by Eric Monti, Timur Duehr
http://tduehr.github.com/buby

DESCRIPTION:

Buby is a mashup of JRuby with the popular commercial web security testing tool Burp Suite from PortSwigger. Burp is driven from and tied to JRuby with a Java extension using the BurpExtender API. This extension aims to add Ruby scriptability to Burp Suite with an interface comparable to the Burp’s pure Java extension interface.

FEATURES/PROBLEMS:

  • Intercept and log proxied requests and responses via Burp into Ruby and perform arbitrary processing on them.

  • Modify requests and responses in-line using Ruby scripts.

  • Pass requests and other information from JRuby to various sub-interfaces in Burp

  • Use the Burp framework for active and passive scanning using arbitrary requests and responses.

  • Use the Burp framework for making arbitrary HTTP requests

Buby is implemented using an abstract Ruby event handler and interface class. The Buby Ruby class is back-ended with a minimal BurpExtender class implemented in Java. The java code is required to conform to nuances in the Burp extension interface and while it’s in the pure Java runtime, it acts as ‘glue’ where deemed appropriate, but otherwise tries to stay out of the way.

The java BurpExtender included with Buby is an implementation of IBurpExtender which is the interface API supplied by PortSwigger for writing extensions to Burp Suite. It mostly acts as a method proxy between Ruby and Java, doing very little except event handler proxying between the java and ruby runtimes with run-time type conversion as needed.

REQUIREMENTS:

  • JRuby - jruby.org Burp is Java based and the extension is developed specifically around JRuby. The C version of ruby will not work.

  • Burp (pro or free version): Buby is useless without a copy of Burp. Buby has been tested successfully with Burp 1.2.x.

BUILD/INSTALL:

Gem

You should be able to get up and running with just the gem and a copy of Burp. I’ve packaged up a pre-built buby.jar file containing the required classes minus ofcourse, Burp itself.

(sudo)? jruby -S gem install buby --source=http://gemcutter.org
  • IMPORTANT: The buby gem doesn’t include a copy of Burp! See manual step #5 below. For best results, you’ll still want to make your burp.jar available in the ruby runtime library path.

Manual

Here are manual instructions if you want or need to build things yourself:

Step 1. Download buby from github

git clone git://github.com/tduehr/buby.git

Step 2. Compile BurpExtender.java. Include jruby.jar in the classpath:

cd buby/java/src
javac -classpath (.../jruby/root)/lib/jruby.jar:. BurpExtender.java

Step 3. Create a new java/buby.jar

jar cvf ../buby.jar .

Step 4. Build a local gem and install it

cd ../../
jruby -S gem build buby.gemspec
jruby -S gem install --local buby-*.gem

Step 5.

The last part is a bit tricky. Burp Suite itself is obviously not included with buby. You’ll want to somehow put your ‘burp.jar’ in a place where it is visible in the JRuby RUBY-LIB paths. There are a few other ways of pulling in Burp during runtime, but this method probably involves the least amount of hassle in the long run.

JRuby usually gives you a ‘java’ lib directory for this kind of thing. Here’s a quick way to see jruby’s runtime lib-path:

jruby -e 'puts $:'

There is usually a ‘…/jruby/lib/1.8/java’ directory reference in there, though the actual directory may need to be created.

Here’s how I do it. I have my jruby installation under my home directory. Your configuration details can be substituted below.

mkdir ~/jruby-1.1.5/lib/ruby/1.8/java
ln -s ~/tools/burp.jar ~/jruby-1.1.5/lib/ruby/1.8/java/burp.jar

Now everything should be ready to go. Try at least the first few parts of the test below to confirm everything is set up.

TEST AND USAGE EXAMPLE:

The gem includes a command-line executable called ‘buby’. You can use this to test your Buby set-up and try out a few features.

$ buby -h
Usage: buby [options]
    -i, --interactive          Start IRB
    -d, --debug                Debug info
    -B, --load-burp=PATH       Load Burp Jar from PATH
    -s, --state=FILE           Restore burp state file on startup
    -r, --require=LIB          load a ruby lib (or jar) after Burp loads
    -e, --extend=MOD           Extend Buby with a module (loaded via -r?)
    -h, --help                 Show this help message

$ buby -i -d
[:got_extender, #<Java::Default::BurpExtender:0x80 ...>]
Global $burp is set to #<Buby:0x78de07 @burp_callbacks=#<#<Class:...>
[:got_callbacks, #<#<Class:01x38ba04>:0x90 ...>]
irb(main):001:0>

Once Burp is running, click on the alerts tab.

You should see now something like the following in alerts:

2:46:01 PM  suite   method BurpExtender.processProxyMessage() found
2:46:01 PM  suite   method BurpExtender.registerExtenderCallbacks() found
2:46:01 PM  suite   method BurpExtender.setCommandLineArgs() found
2:46:01 PM  suite   method BurpExtender.applicationClosing() found
2:46:01 PM  proxy   proxy service started on port 8080
2:46:01 PM  suite   [BurpExtender] registering JRuby handler callbacks
2:46:01 PM  suite   [JRuby::Buby] registered callback

Here are some simple test examples using Buby through the IRB shell:

To confirm you are connected back to Burp in IRB, you can try writing to the alerts panel with something like the following:

$burp.alert("hello Burp!")

Which should produce a new alert:

2:47:00 PM  suite   hello Burp!

Next, try making an HTTP request through the proxy. We’ll use Net:HTTP right in IRB for illustration purposes. However, you can just as easily perform this test through a browser configured to use Burp as its proxy.

require 'net/http'
p = Net::HTTP::Proxy("localhost", 8080).start("www.example.com")
p.get("/")

With $DEBUG = true, you should see the debugging output from Ruby as the proxy passes your request back to your HTTP client/browser.

It will look something like the following in IRB:

>> p.get("/")   
[:got_proxy_request,
 [:msg_ref, 1],
 [:is_req, true],
 [:rhost, "www.example.com"],
 [:rport, 80],
 [:is_https, false],
 [:http_meth, "GET"],
 [:url, "/"],
 [:resourceType, nil],
 [:status, nil],
 [:req_content_type, nil],
 [:message, "GET / HTTP/1.1\r\nAccept:..."],
 [:action, 0]]

You may also see the response right away depending on your intercept settings in Burp. Back the in Burp proxy’s intercept window, turn off interception if it hasn’t already been disabled. Now you should definitely see the response in IRB as it passes back through the Burp proxy.

[:got_proxy_response,
 [:msg_ref, 1],
 [:is_req, false],
 [:rhost, "www.example.com"],
 [:rport, 80],
 [:is_https, false],
 [:http_meth, "GET"],
 [:url, "/"],
 [:resourceType, nil],
 [:status, "200"],
 [:req_content_type, "text/html; charset=utf-8"],
 [:message, "HTTP/1.1 200 OK\r\n..."],
 [:action, 0]]
=> #<Net::HTTPOK 200 OK readbody=true>
>>

Note also, the Net::HTTP request should have returned the same result as shown in the proxy.

Now, lets try something mildly interesting with the proxy. This contrived example will implement a proxy request manipulator to do HTTP request verb tampering on every GET request that goes through the proxy.

# Note: I'm using 'instance_eval' here only to stay with the flow of the
# existing IRB session. Normally, you'd probably want to implement this as
# an override in your Buby-derived class.

$burp.instance_eval do

  def evt_proxy_message(*param)
    msg_ref, is_req, rhost, rport, is_https, http_meth, url, resourceType, 
    status, req_content_type, message, action = param

    if is_req and http_meth=="GET"
      # Change the HTTP request verb to something silly
      message[0,3] = "PET"

      # Forcibly disable interception in the Burp UI
      action[0] = Buby::ACTION_DONT_INTERCEPT

      # Return a new instance and still get $DEBUG info
      return super(*param).dup
    else
      # Just get $DEBUG info for all other requests
      return super(*param)
    end
  end

end

# Now, make another request using the Net::HTTP client
p.get("/")

This should produce a request that looks like the following in IRB:

[:got_proxy_request,
 ...
 [:message,
  "PET / HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Ruby..."],
  [:action, 2]]

And, assuming ‘www.example.com’ checks for valid request verbs, you should see something like the following response:

[:got_proxy_response,
 ...
 [:http_meth, "PET"],
 [:url, "/"],
 [:resourceType, nil],
 [:status, "400"],
 ...
 [:message,
  "HTTP/1.1 400 Bad Request\r\nContent-Type:..."],
 [:action, 0]]
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true>

CREDIT:

  • Burp and Burp Suite are trademarks of PortSwigger(ltd) Copyright 2011 PortSwigger Ltd. All rights reserved. See portswigger.net for license terms.

  • This ruby library and the accompanying BurpExtender.java implementation was originally written by Eric Monti @ Matasano Security. This ruby library is currently maintained by Timur Duehr @ Matasano Security.Matasano Security claims no professional or legal affiliation with PortSwigger LTD.

    However, the authors would like to express their personal and professional respect and admiration to Burp’s authors and appreciation to PortSwigger for the availability of the IBurpExtender extension API.

    The availability of this interface goes a long way to helping make Burp Suite a truly first-class application.

LICENSE:

  • Burp and Burp Suite are trademarks of PortSwigger Ltd. Copyright 2011 PortSwigger Ltd. All rights reserved. See portswigger.net for license terms.

  • The Buby Ruby library and its accompanying BurpExtender implementation are both freely available under the terms of the MIT public license:

(The MIT License)

Copyright © 2009 Eric Monti, Matasano Security Copyright © 2010-2011 Timur Duehr, Matasano Security

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.