Coder Social home page Coder Social logo

mwielgoszewski / jython-burp-api Goto Github PK

View Code? Open in Web Editor NEW
177.0 14.0 37.0 356 KB

Develop Burp extensions in Jython

Home Page: http://www.tssci-security.com/archives/2013/02/14/extending-burp-with-jython-burp-api/

License: ISC License

Python 48.67% Java 51.33%

jython-burp-api's Introduction

jython-burp-api

Jython-Burp-API is an ISC Licensed library, written in Jython, Java and Python.

Jython-Burp-API exposes a Jython interface to the popular Burp Suite web security testing tool, as an alternative to Buby for those testers who prefer Python over Ruby.

Dependencies

Installation / Running

  1. Install Jython 2.7+ as a standalone jar

  2. git clone git://github.com/mwielgoszewski/jython-burp-api.git

  3. cd jython-burp-api/

  4. Copy Burp Suite jar file(s) into current directory

  5. Compile BurpExtender files (Note: On Windows the classpath separator is a semi-colon):

    $ javac -cp jython.jar java/src/*.java java/src/burp/*.java

  6. Start Burp by executing the following Jython script, specifying location of Burp as the command line argument -B (note, -i and -d are set to enable interactive console and debug logging):,

    $ java -Xmx1g -jar jython.jar run.py -i -d -B burpsuite_pro_v1.5.03.jar

Features

By default, we monitor a list of registered menu items for any changes. If a file has changed (i.e., its last modification time was updated), the API will automatically attempt to reload it. This is great for active development and debugging of Burp extensions.

Examples

To start an interactive console, simply pass the -i command line argument when starting Burp. You can also click one or multiple items in Burp and assign them to the items local variable like so:

$ java -Xmx1g -jar jython.jar run.py -i -d -B burpsuite_pro_v1.5.03.jar

>>> Burp
<BurpExtender at 0x2>
>>> Burp.history
[<HttpRequest [/]>, ...]

>>> items
[<HttpRequest [/firefox/headlines.xml]>]
>>> request = items[0]
>>> request.headers
{'Accept-Language': 'en-us,en;q=0.5', ...}
>>> request.response
<HttpResponse [302]>
>>> len(request.response)
256

and many more!

Adding a simple menu item

Check out the ConsoleMenu class for an example of how to add menu items to Burp's context menu. Below is an example of how to use one in your code.

from gds.burp.menu import MenuItem

class MyMenuItem(MenuItem):
    CAPTION = 'my caption'
    
    def menuItemClicked(self, menuItemCaption, messageInfo):
        print('clicked %s' % (menuItemCaption, ))

To add your new menu (MyMenuItem) to Burp's context menu, specify it as an option under [menus] section in burp.ini and set it to enabled. If you wish to disable the built-in ConsoleMenu item that's registered, simply set it to disabled, like so:

[menus]
gds.burp.menu.console.ConsoleMenu = disabled
myplugins.MyMenuItem = enabled

Once Burp is loaded, the new menu item should be available in Burp. You can also register menu items at runtime by initializing them within the interactive console. Note however, menu items registered in the console cannot be reloaded since there is no actual file to watch for changes.

>>> class MyMenuItem(MenuItem):
...     CAPTION = 'my caption'
...     def menuItemClicked(self, menuItemCaption, messageInfo):
...         print('clicked %s' % (menuItemCaption, ))
... 
>>> MyMenuItem(Burp)

Also, keep in mind that in order to load the menu, we need to import it, thus requiring it to be in our class path. If you keep your plugins under the Lib/ directory, you should be good.

Processing HTTP requests/responses

One of the methods exposed by the Burp Extender interface is processHttpMessage. This method, according to the API documentation [..] is invoked whenever any of Burp's tools makes an HTTP or receives a response [..] For each request, the method is invoked after the request has been fully processed by the invoking tool and is about to be made on the network. For each response, the method is invoked after the response has been received from the network and before any processing is performed by the invoking tool. To write a plugin to hook into one of these requests or responses, implement one of the interfaces from gds.burp.api, such as IRepeaterRequestHandler, IProxyResponseHandler, and the like. For example, the following plugin would hook requests as they are sent via Intruder and Scanner, and responses that come in Proxy and Intruder.

from gds.burp.api import IIntruderRequestHandler, IScannerRequestHandler
from gds.burp.api import IProxyResponseHandler, IIntruderResponseHandler
from gds.burp.core import Component, implements

class ExamplePlugin(Component):

    implements(IIntruderRequestHandler, IIntruderResponseHandler,
               IScannerRequestHandler, IProxyResponseHandler)

    def processRequest(self, request):
        self.log.info("Request to %s sent through Intruder and Scanner",
                      request.url.geturl())

    def processResponse(self, request):
        self.log.info("This response from %s was received via Proxy and Intruder",
                      request.url.geturl())

To use this plugin, we need to first enable it under the [components] section within burp.ini, as well as add it to the list of options under [handlers] in the order in which we want it to be processed. Options in the [handlers] section can be a comma separated list, specifying the order in which a plugin will be called. This allows you to decouple tools and configure their use at different times. If you are familiar with or have experience with request filter chains, such as in Java web apps, this should be immediately clear.

[components]
testplugin.ExamplePlugin = enabled

[handlers]
intruder.request = ExamplePlugin
intruder.response = ExamplePlugin
proxy.request = ExamplePlugin
proxy.response = ExamplePlugin

Note, a plugin that implements an interface but is not enabled under [components] and/or is not listed in its respective option in the [handlers] configuration configuration, will not get called.

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository on Github to start making your changes in a separate branch.
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and bug the maintainer until it gets merged and published. :)

jython-burp-api's People

Contributors

jpasski avatar mwielgoszewski avatar nitrocode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jython-burp-api's Issues

Java runs out of memory after running Burp.history

How to avoid the java.lang.OutOfMemoryError: Java heap space?

Burp.history[0]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\bhatiar\git\jython-burp-api\Lib\burp_extender.py", line 341, in <lambda>
    history = property(lambda burp: list(burp.getProxyHistory()))
  File "C:\Users\bhatiar\git\jython-burp-api\Lib\burp_extender.py", line 339, in getProxyHistory
    yield HttpRequest(request, _burp=self)
  File "C:\Users\bhatiar\git\jython-burp-api\Lib\gds\burp\models.py", line 58, in __init__
    self.response = HttpResponse(getattr(messageInfo, 'response', None),
  File "C:\Users\bhatiar\git\jython-burp-api\Lib\gds\burp\models.py", line 324, in __init__
    self.version, self.status_code, self.reason, self._headers, self.body = \
java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3236)
    at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
    at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
    at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:135)
    at java.io.DataOutputStream.writeByte(DataOutputStream.java:153)
    at org.python.core.PyArray.toStream(PyArray.java:1831)

ImportError: No module named burp_extender

Hi,

i've downloaded your package and tried to get it work. First I've compiled the sources:

$ javac -cp ../jython.jar java/src/.java java/src/burp/.java

Afterwards I tried to star burp by:

$ java -jar ../jython.jar run.py -B burpsuite_pro.jar -i
Traceback (most recent call last):
File "run.py", line 117, in
start_burp(opt, *args)
File "run.py", line 15, in start_burp
from burp_extender import BurpExtender as MyBurpExtender, ConsoleThread
ImportError: No module named burp_extender

As you see there is "no module named burp_extender". Any ideas?!

Cheers,

Victor

Compiling jython.jar

java -jar ../jython.jar -Dpython.path=Lib/:java/ run.py --file=state_empy -B burpsuite_pro_v1.6.08.jar
Traceback (most recent call last):
File "run.py", line 117, in
start_burp(opt, *args)
File "run.py", line 16, in start_burp
from burp_extender import StartBurp
ImportError: cannot import name StartBurp

why does this happen?

AttributeError on Burp startup

Hello,
I have been trying to run jython-burp-api, however I am getting the following error on Burp startup in the "Alerts" tab:

BurpExtender threw exception: Traceback (most recent call last):
File "Lib/BurpExtender.py", line 22, in from gds.burp import HttpRequest
File "Lib/gds/burp/init.py", line 9, in from .models import HttpRequest, HttpResponse
File "Lib/gds/burp/models.py", line 21, in class HttpRequest(object):
File "Lib/gds/burp/models.py", line 156, in HttpRequest @raw.setter AttributeError: 'property' object has no attirbute 'setter'

Burp 1.4.01
Python 2.7.3
Jython 2.5.2
Windows 7

null pointer when launching interpretter from the command line

Command:

java -Xmx1g -jar ..\..\Downloads\jython-standalone-2.7.0.jar -Dpython.path=Lib/ run.py -i -d -B ..\..\Downloads\burp_suite_pro.jar

Then when Burp loads I select to use a temporary project and use Burp defaults. After I click on Start Burp that's when it shows me:

An error occurred when starting a project with the selected options.

Failed to create Burp project: NullPointerException

Nothing else is outputted but this seems to be a good workaround:

  1. Load Burp

    java -Xmx1g -jar ..\..\Downloads\burp_suite_pro.jar
    
  2. Navigate to Extender and manually load Lib/burp_extender.py

TypeError: 'org.python.util.JLineConsole(): expected 1 args; got 0'

Using Burp 1.7, Jython 2.7.0, and Python 2.7.10 on Windows 10

Compiled:

cd jython-burp-api
javac.exe -cp ..\..\Downloads\jython-standalone-2.7.0.jar java\src\*.java java\src\burp\*.java

Command:

cd jython-burp-api
java.exe -Xmx1g -jar ..\..\Downloads\jython-standalone-2.7.0.jar -Dpython.path=Lib/ run.py -i -d -B ..\..\Downloads\burp_suite_pro.jar

Full exception:

git\jython-burp-api>java.exe -Xmx1g -jar ..\..\Downloads\jython-standalone-2.7.0.jar -Dpython.path=Lib/ run.py -i -d -B ..\..\Downloads\burp_suite_pro.jar
Traceback (most recent call last):
  File "run.py", line 117, in <module>
    start_burp(opt, *args)
  File "run.py", line 65, in start_burp
    Burp.console = console = JLineConsole()
TypeError: org.python.util.JLineConsole(): expected 1 args; got 0
2016-10-19 13:40:45,936 - BurpExtender - ERROR - Could not load console tab
Traceback (most recent call last):
  File "\git\jython-burp-api\Lib\burp_extender.py", line 181, in registerExtenderCallbacks
    from gds.burp.ui import ConsoleTab
  File "\git\jython-burp-api\Lib\gds\burp\ui.py", line 12, in <module>
    from .console import Console
  File "\git\jython-burp-api\Lib\gds\burp\console\__init__.py", line 12, in <module>
    from console import Console
  File "\git\jython-burp-api\Lib\gds\burp\console\console.py", line 24, in <module>
    class Console(object):
  File "\git\jython-burp-api\Lib\gds\burp\console\console.py", line 25, in Console
    PS1 = sys.ps1
AttributeError: '<reflected field public org.python.core.PyObject o' object has no attribute 'ps1'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.