Blogs & Stories

SpiderLabs Blog

Attracting more than a half-million annual readers, this is the security community's go-to destination for technical breakdowns of the latest threats, critical vulnerability disclosures and cutting-edge research.

JSON Crypto Helper a Ruby-based Burp Extension for JSON Encryption/Decryption - Part II

This is the second post in a three-part series about how to write a simple Ruby extension that helps deal with encrypted JSON messages (read part one here). The complete extension code is available here.

In the last post we saw how to automatically decrypt JSON messages and display the well-formatted plaintext in a custom tab. This enabled you to easily read encrypted JSON requests captured by the Proxy tool.

In this post I will explain how to automatically encrypt JSON request values before sending it to the remote server. You will be able to write or modify any plaintext JSON and send it encrypted to the remote server using the Repeater tool.

Encrypting JSON

Let's say now the server accepts an encrypted JSON, processes it and returns the result. To keep it simple here, the fake server will simply return the decrypted value:

05 - decrypt request repeater

As can be seen, sending the original encrypted JSON in a POST request will result in the same decrypted values you had before. Now you want to be able to modify the plaintext JSON and send it encrypted to the server. To do so, you will need to process the message in the #getMessage method:

def getMessage
  is_request = @txt_input.text[0..3].to_s == "HTTP"
  if is_request
    info = @helper.analyze_request(@txt_input.text)
    info = @helper.analyze_response(@txt_input.text)
  headers = @txt_input.text[ 0..(info.get_body_offset - 1) ].to_s
  body = @txt_input.text[ info.get_body_offset..-1 ].to_s
  body = process_json(body, :encrypt) if json?(info, is_request)
  return (headers + body).to_java_bytes

As you can see, the logic is quite similar to #setMessage. It encrypts instead of decrypting and it returns the encrypted message instead of filling the text editor. Note that it is mandatory to use #to_java_bytes to be accepted by Burp.

You can now modify the JSON in the "JSON Crypto Helper" tab, check the encrypted version in the Raw tab and send the request. The server successfully decrypts the JSON and returns the plain text:

06 - modified JSON

07 - encryption of modified JSON

Parting Thoughts

With these first two posts we covered the basics of Burp Extender tool and learned how to write a simple ruby-based extension to decrypt a JSON, displaying it in the Burp interface and automatically encrypt plaintext values using the Repeater tool. This should be a good start for you to explore the Burp API and create your own extensions.

In the next post I will explain how to go further and do more awesome things with Burp Extender and the Intruder tools.

Stay tuned!

Recent SpiderLabs Blog Posts