65
Burp Plugin Development for Java n00bs 44Con 2012 www.7elements.co.uk | blog.7elements.co.uk | @7elements

Burp plugin development for java n00bs (44 con)

Embed Size (px)

DESCRIPTION

Introduction to using BurpExtender to write plugins for Web application assessment tool Burp Suite. Aimed at testers who have never coded Java before.

Citation preview

Page 1: Burp plugin development for java n00bs (44 con)

  

Burp Plugin Development for Java n00bs

44Con 2012

www.7elements.co.uk | blog.7elements.co.uk | @7elements

Page 2: Burp plugin development for java n00bs (44 con)

  

/me

• Marc Wickenden• Principal Security Consultant at 7 Elements• Love coding (particularly Ruby)• @marcwickenden on the Twitterz• Most importantly though…..

www.7elements.co.uk | blog.7elements.co.uk | @7elements

Page 3: Burp plugin development for java n00bs (44 con)

  

I am a Java n00b

Page 4: Burp plugin development for java n00bs (44 con)

  

If you already know Java

You’re either:• In the wrong room• About to be really offended!

Page 5: Burp plugin development for java n00bs (44 con)

  

Agenda

• The problem• Getting ready• Introduction to the Eclipse IDE• Burp Extender Hello World!• Manipulating runtime data• Decoding a custom encoding scheme• “Shelling out” to other scripts• Limitations of Burp Extender• Really cool Burp plugins already out there to fire your

imagination

Page 6: Burp plugin development for java n00bs (44 con)

  

Oh…..and there’ll be cats

Page 7: Burp plugin development for java n00bs (44 con)

  

Page 8: Burp plugin development for java n00bs (44 con)

  

The problem

• Burp Suite is awesome• De facto web app tool• Open source alternatives don’t compare IMHO• Tools available/cohesion/protocol support• Burp Extender

Page 9: Burp plugin development for java n00bs (44 con)

  

The problem

Page 10: Burp plugin development for java n00bs (44 con)

  

I wrote a plugin

Coding by Google FTW!

Page 11: Burp plugin development for java n00bs (44 con)

  

How? - Burp Extender

• “allows third-party developers to extend the functionality of Burp Suite”

• “Extensions can read and modify Burp’s runtime data and configuration”

• “initiate key actions”• “extend Burp’s user interface”

http://portswigger.net/burp/extender/

Page 12: Burp plugin development for java n00bs (44 con)

  

Burp Extender

• Achieves this via 6 interfaces:– IBurpExtender– IBurpExtenderCallbacks– IHttpRequestResponse– IScanIssue– IScanQueueItem– IMenuItemHander

Page 13: Burp plugin development for java n00bs (44 con)

  

Java 101

• Java source is compiled to bytecode (class file)• Runs on Java Virtual Machine (JVM)• Class-based• OO• Write once, run anywhere (WORA)• Two distributions: JRE and JDK

Page 14: Burp plugin development for java n00bs (44 con)

  

Java 101 continued…

• Usual OO stuff applies: objects, classes, methods, properties/variables

• Lines end with ;

Page 15: Burp plugin development for java n00bs (44 con)

  

Java 101 continued…

• Source files must be named after the public class they contain

• public keyword denotes method can be called from code in other classes or outside class hierarchy

Page 16: Burp plugin development for java n00bs (44 con)

  

Java 101 continued…

• class hierarchy defined by directory structure:• uk.co.sevenelements.HelloWorld =

uk/co/sevenelements/HelloWorld.class• JAR file is essentially ZIP file of

classes/directories

Page 17: Burp plugin development for java n00bs (44 con)

  

Java 101 continued…

• void keyword indicates method will not return data to the caller

• main method called by Java launcher to pass control to the program

• main must accept array of String objects (args)

Page 18: Burp plugin development for java n00bs (44 con)

  

Java 101 continued…

• Java loads class (specified on CLI or in JAR META-INF/MANIFEST.MF) and starts public static void main method

• You’ve seen this already with Burp:– java –jar burpsuite_pro_v1.4.12.jar

Page 19: Burp plugin development for java n00bs (44 con)

  

Enough 101

Page 20: Burp plugin development for java n00bs (44 con)

  

Page 21: Burp plugin development for java n00bs (44 con)

  

Let’s write some codez

Page 22: Burp plugin development for java n00bs (44 con)

  

First we need some tools

• Eclipse IDE – de facto free dev tool for Java• Not necessarily the best or easiest thing to use• Alternatives to consider:– Jet Brains IntelliJ (my personal favourite)– NetBeans (never used)– Jcreator (again, never used)– Terminal/vim/javac < MOAR L33T

Page 23: Burp plugin development for java n00bs (44 con)

  

Download Eclipse Classic

Or install from your USB drive

Page 25: Burp plugin development for java n00bs (44 con)

  

Java JDK

• Used to be bundled with Eclipse• Due to licensing (I think) this is no longer the

case• Grab from Sun Oracle’s website:• http://

download.oracle.com/otn-pub/java/jdk/7u7-b11/jdk-7u7-windows-x64.exe?AuthParam=1347522941_2b61ee3cd1f38a0abd1be312c3990fe5

Page 26: Burp plugin development for java n00bs (44 con)

  

Welcome to Eclipse

Page 27: Burp plugin development for java n00bs (44 con)

  

Create a Java Project

• File > New > Java Project• Project Name: Burp Hello World!• Leave everything else as default• Click Next

Page 28: Burp plugin development for java n00bs (44 con)

  

Page 29: Burp plugin development for java n00bs (44 con)

  

Java Settings

• Click on Libraries tab• Add External JARs• Select your burpsuite.jar

• Click Finish

Page 30: Burp plugin development for java n00bs (44 con)

  

Create a new package

• File > New > Package• Enter burp as the name• Click Finish

Page 31: Burp plugin development for java n00bs (44 con)

  

Create a new file

• Right-click burp package > New > File• Accept the default location of src• Enter BurpExtender.java as the filename• Click Finish

Page 32: Burp plugin development for java n00bs (44 con)

  

Page 33: Burp plugin development for java n00bs (44 con)

  

We’re ready to type

Page 34: Burp plugin development for java n00bs (44 con)

  

Loading external classes

• We need to tell Java about external classes– Ruby has require– PHP has include or require– Perl has require– C has include– Java uses import

Page 35: Burp plugin development for java n00bs (44 con)

  

Where is Burp?

• We added external JARs in Eclipse• Only helps at compilation• Need to tell our code about classes– import burp.*;

Page 36: Burp plugin development for java n00bs (44 con)

  

IBurpExtender

• Available at http://portswigger.net/burp/extender/burp/IBurpExtender.html

– “ Implementations must be called BurpExtender, in the package burp, must be declared public, and must provide a default (public, no-argument) constructor”

Page 37: Burp plugin development for java n00bs (44 con)

  

In other words

public class BurpExtender{

}

• Remember, Java makes you name files after the class so that’s why we named it BurpExtender.java

Page 38: Burp plugin development for java n00bs (44 con)

  

Add thispackage burp;

import burp.*;

public class BurpExtender{ public void processHttpMessage( String toolName, boolean messageIsRequest, IHttpRequestResponse messageInfo) throws Exception { System.out.println("Hello World!"); }}

Page 39: Burp plugin development for java n00bs (44 con)

  

Run the program

• Run > Run• First time we do this it’ll ask what to run as• Select Java Application

Page 40: Burp plugin development for java n00bs (44 con)

  

Select Java Application

• Under Matching items select StartBurp – burp• Click OK

Page 41: Burp plugin development for java n00bs (44 con)

  

Burp runs

• Check Alerts tab• View registration of BurpExtender class

Page 42: Burp plugin development for java n00bs (44 con)

  

Console output

• The console window shows output from the application

• Note the “Hello World!”s

Page 43: Burp plugin development for java n00bs (44 con)

  

Congratulations

Page 44: Burp plugin development for java n00bs (44 con)

  

Page 45: Burp plugin development for java n00bs (44 con)

  

What’s happening?

• Why is it spamming “Hello World!” to the console?

• We defined processHttpMessage()• http://

portswigger.net/burp/extender/burp/IBurpExtender.html– “This method is invoked whenever any of Burp's

tools makes an HTTP request or receives a response”

Page 46: Burp plugin development for java n00bs (44 con)

  

Burp Suite Flow

Page 47: Burp plugin development for java n00bs (44 con)

  

processProxyMessage

RepeatAfterMeClient.exe

processHttpMessage

http://wcfbox/RepeaterService.svc

Burp Suite

Page 48: Burp plugin development for java n00bs (44 con)

  

Page 49: Burp plugin development for java n00bs (44 con)

  

We’ve got to do a few things

• Split the HTTP Headers from FI body• Decode FI body• Display in Burp• Re-encode modified version• Append to headers• Send to web server• Then the same in reverse

Page 50: Burp plugin development for java n00bs (44 con)

  

Page 51: Burp plugin development for java n00bs (44 con)

  

• Right-click Project > Build Path > Add External Archives

• Select FastInfoset.jar• Note that imports are now yellow

Page 52: Burp plugin development for java n00bs (44 con)

  

Decoding the Fastinfoset to console

Page 53: Burp plugin development for java n00bs (44 con)

  

First: we get it wrong

• Burp returns message body as byte[]• Hmm, bytes are hard, let’s convert to String• Split on \r\n\r\n

Page 54: Burp plugin development for java n00bs (44 con)

  

Page 55: Burp plugin development for java n00bs (44 con)

  

Then we do it right

• Fastinfoset is a binary encoding• Don’t try and convert it to a String• Now things work

Page 56: Burp plugin development for java n00bs (44 con)

  

Page 57: Burp plugin development for java n00bs (44 con)

  

Decoding Fastinfoset through Proxy

Page 58: Burp plugin development for java n00bs (44 con)

  

Page 59: Burp plugin development for java n00bs (44 con)

  

We’re nearly there……

Page 60: Burp plugin development for java n00bs (44 con)

  

Page 61: Burp plugin development for java n00bs (44 con)

  

Running outside of Eclipse

• Plugin is working nicely, now what?• Export to JAR• Command line to run is:

• java –jar yourjar.jar;burp_pro_v1.4.12.jar burp.startBurp

Page 62: Burp plugin development for java n00bs (44 con)

  

Limitations

• We haven’t coded to handle/decode the response

• Just do the same in reverse• processHttpMessage fires before

processProxyMessage so we can’t alter then re-encode message

• Solution: chain two Burp instances together

Page 63: Burp plugin development for java n00bs (44 con)

  

Attribution

• All lolcatz courtesy of lolcats.com• No cats were harming in the making of this

workshop• Though some keyboards were….

Page 64: Burp plugin development for java n00bs (44 con)

  

Questions

?

www.7elements.co.uk | blog.7elements.co.uk | @7elements

Page 65: Burp plugin development for java n00bs (44 con)

  

www.7elements.co.uk | blog.7elements.co.uk | @7elements