Out of necessity, I wrote a Burp Extension that would decode raw protobuf
messages even when a .proto was not available. After loading a .proto, the
extension features the ability to modify and tamper with protobuf messages.
In my extension, you can also manually specify what message type to
deserialize a given protobuf message as. You can download my extension at

The following set of screenshots should give you a quick overview of what
it's capable of:

We start off with a view of what a simple, raw protobuf message looks like
in Burp. If you've ever tried to tamper this right here, you'd probably
find yourself reading and re-reading protocol buffer encoding.

Here's what that message looks like when decoded using protoc --decode_raw:

Another request that looks to be adding a serialized user object. Note,
the burp-protobuf-decoder extension identifies protobuf messages by an HTTP
Content-Type request or response header equal toapplication/x-protobuf.
If the application you're looking at does things a bit differently, have
a look at modifyingisEnabled(),getMessage()andsetMessage()ofprotoburp.py.

And again, what it looks like after protoc --decode_raw:

If we're lucky enough to have a .proto that defines what this message looks
like, we can load it from here:

We can then manually deserialize the message as a Person. Next time a
request comes through, the extension will automatically deserialize the
message. Note, an attempt will be made to deserialize as all types until one
is found to deserialize with all required fields initialized (this could
result in some false positives).

That looks much better...

But wait, how about we tamper it?

The extension will reserialize our message and we can send it on its way. If
any errors occur (such as required fields missing), an alert dialog will pop
up letting you know.

And the response from the server confirms our message was tampered succesfully.

Hopefully my extension will make testing protobuf based applications much
easier from now on.

It's not uncommon for developers to accidentally (or purposefully) commit
passwords or other information supposed to remain secret into revision
control. It's also not uncommon to see RSA private keys indexed by Google,
and GitHub made it even easier to find secrets in the code with their new
search features. These same search features make it easy to grep the web
for all kinds of insecure code patterns, especially insecure cryptographic
constructions. For example, a simple search for AES.new( in Python code
repositories revealed to me the web2py project was using the encryption key
as the initialization vector (IV), which is the focus of this blog post.

Why is this bad? Well, in an email to the sci.crypt mailing list back
in 1996, David Wagner explains why you should never do this.

Let's take a look at the insecure construction in web2py's gluon.utils
module prior to merging my pull request that fixed this issue.

From an attacker's perspective (in short), if we can control the ciphertext
being fed to this function, and see the output of this function (the decrypted)
text, we can easily deduce the key used to perform the encryption. The
following code demonstrates this:

KEY='testtesttesttest'PTEXT='The quick brown fox jumped over the lazy dog.The quick brown fox'defxor(a,b):returnbytearray(x^yforx,yinzip(a,b))defexploit():# ciphertext produced by web2pyctext=bytearray(AES_new(KEY).encrypt(PTEXT))# our (malformed) ciphertext we plan to feed to web2pymtext=ctext[:16]*4mtext[16:32]=[0x0]*16# if at any point we identify what the decrypted data isptext=bytearray(AES_new(KEY).decrypt(str(mtext)))# we can easily recover the secret key used:print('KEY: %r'%(str(xor(ptext[:16],ptext[32:48])),))

Running this exploit returns the following (I've included hexdumps at each
step of the way):

Is web2py vulnerable?

In short, no. The manner in which AES_new was used across web2py's
codebase did not appear to be exploitable. web2py was using this to encrypt
pickled session data in a cookie in secure_dumps, and authenticated with
an HMAC (which coincidentally was also vulnerable to a timing attack).
However, applications that use AES_new as a convenience function for
decrypting data provided by the user are most likely vulnerable, amongst
other vulnerabilities that tend to crop up when rolling your own crypto.

If you've been keeping up with web2py's master, my merged pull request
patches the AES_new function to return a random IV anytime it is invoked
and utilizes the more secure, constant-time compare function to validate
HMAC's.

Last year, I released the Jython Burp API,
a plugin framework to Burp that allows running multiple plugins simultaneously,
exposes an interactive Jython console, provides Filter-like
functionality, and eases developing plugins at runtime by providing more
Pythonic APIs and automatic code reloading for when code or configurations
are updated. I presented an overview of my framework at an iSec Partners Forum
in NYC last year. Others have released similar frameworks that also provide the
ability to write Burp extensions in Jython.

Since then, PortSwigger released a new Burp Extender API, allowing users
to develop all sorts of plugins and extend Burp's various tools in a myriad
of ways. Regardless, I still find my framework and others like Buby still
have their place. I'd like to take the next few paragraphs to guide users
on setting up the Jython Burp API in their environment.

Getting Jython

First, we'll need to get the latest 2.7+ standalone version of Jython.
At the time of this writing, the latest version is Jython 2.7beta1.
Once you download Jython, configure Burp's Python Environment.

Loading the Jython Burp API

If you haven't already done so, download the Jython Burp API. Then, all
you need to do (provided you're running Burp 1.5.04 or later), is add
jython-burp-api/Lib/burp_extender.py as a Python extension to Burp:

After you've clicked next, you should see the extension among the list of other
currently loaded extensions (if any).

An additional feature you may find useful is an interactive Jython console
tab, that allows you to interact with the Burp Extender object and any other
variables in the local namespace. I find it useful to iterate over requests in
Burp's Proxy History, collecting various information or highlighting/commenting
requests that may contain a specific header or string in the response body.

I added a right-click context menu item so you could select specific requests
and send them to the items variable, accessible from the console.

In a future blog post, I may dive into using some of the other features of
the framework. In the mean time, please feel free to fork and contribute to
the Jython Burp API!