A few days ago, I released the Bug Diaries Burp extension. It's a Burp extension that aims to mimic Burp issues for the community (free) version. For reasons, I decided to rewrite it in Java. This is the first part of my series on what I learned switching to Java.
This part discusses how my environment is set up for development with Visual Studio Code. Things like auto-completion, Gradle builds and most importantly debugging.
Clone the repository to skip some of the steps in the blog. I still recommend doing them yourself if you are not familiar with Gradle and Burp development, clone the following repository:
The original extension was in Python. To that day, all of my Burp extensions had been in Python. I documented what I learned:
I had a lot of problems enabling the right-click functionality on Burp's IMesageEditors.Long story short, I decided to rewrite the extension in Java instead.
This is how my development VM looks like.
There is also a VS Code installer for Java developers at https://aka.ms/vscode-java-installer-win. I did not use it.
You need to install a JDK version that is compatible with the version Burp was built with. To figure it out, you can check the bundled JRE that comes with the installer.
The rest of the instructions are for December 2019 and probably need to be changed for later use.
I use OpenJDK because of the shitty licensing requirements of Oracle.
JAVA_HOME
to C:\Program Files\path\to\jdk\
. (Do not include the
bin
directory).C:\Program Files\AdoptOpenJDK\jdk-11.0.5.10-hotspot
.bin
directory for the JDK installation to PATH
.Now java -version
should return something like (remember to open a new command
line after setting the PATH
):
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode
Note: If you install the JDK 13 or newer, you cannot use the Burp's exe file
to load your extension. As of December 2019, The Burp's exe
file, uses a
bundled JRE which is built with JDK 11 (version 55.0). If you try to load an
extension that is built with a later Java version, you will get this error:
java.lang.UnsupportedClassVersionError: burp/BurpExtender has been compiled by
a more recent version of the Java Runtime (class file version 57.0), this
version of the Java Runtime only recognizes class file versions up to 55.0
Solution:
Gradle does not have an installer either.
C:\Program Files
(the instructions say C:\
but I prefer
program files).C:\Program Files\gradle-6.0.1
.bin
directory to PATH
.C:\Program Files\gradle-6.0.1\bin
Now gradle -version
should return something like:
gradle -version
------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------
Build time: 2019-11-18 20:25:01 UTC
Revision: fad121066a68c4701acd362daf4287a7c309a0f5
Kotlin: 1.3.50
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.5 (AdoptOpenJDK 11.0.5+10)
OS: Windows 10 10.0 amd64
Create a directory for extension development. In the root of this directory run the following command:
gradle init --type basic
Enter
twice to select the default.settings.gradle
.This will create a bunch of directories and files.
Open build.gradle
and paste the following.
|
|
Read the comments inside the file to see what each section does. The most important section is adding the Burp Extender interface Maven repository. This gives us build support and the equally important code completion with IntelliCode (iT's Ai BaSeD!!1!).
Any extra dependencies are added similar to the Burp extender interface. For example, Google's Gson version 2.8.6 can be added like this:
dependencies {
// Add the Burp Extender interface
compile 'net.portswigger.burp.extender:burp-extender-api:2.1'
compile 'com.google.code.gson:gson:2.8.6'
}
The Gradle Wrapper is a way to get reliable builds regardless of the local Gradle version. Note you need Gradle to install the Wrapper.
If you just want to initiate the Wrapper, you need to have Gradle. Run
gradle wrapper
in the extension directory. To build the project with the
Wrapper, replace gradle
in your commands with gradlew
(*nix) or
gradlew.bat
(Windows). For example, gradlew.bat build
.
src\burp
directory. This directory will contain the burp
package.src
.src\burp
create a file named BurpExtender.java
.BurpExtender.java
and add this code.
|
|
Note: If your extension only has one package (or a few files), you can put all
your files inside src
directly.
To make our life easier, we are going to assign the bigJar
Gradle task to the
default build task in VS Code. This is important if your extension uses non-Burp
dependencies (like gson
above). In this case you need to publish this
jar file.
Ctrl+Shift+P
or F1
to open the VS Code command palette.task
and select Configure Default Build Task
.Create tasks.json file from template
.Others
..vscode\tasks.json
file..vscode\tasks.json
and paste the following in it:
|
|
Now we can build our project with:
Ctrl+Shift+B
. Recommended, it's faster and looks 1337.Terminal (menu) > Run Task (sub menu) > gradle
.tasks
then selecting Run Build Task
.Run it once to download the Burp Extender interface and build the library. The
output jar will be in build\libs\burp-sample-extension-java-all.jar
.
Our build works but you might have noticed that VS Code does not recognize
imported interfaces from the burp
package.
VS Code errors
Every time, a new dependency is added (or we get the same error again), we need to clean the Java language server.
Ctrl+Shift+P
or F1
.java clean
and select Java Clean the Java language server workspace
.IntelliCode support
Note: This is the solution to most vscode-java
extension problems.
Let's add some code to the extension to show how I test the extension after each build.
Modify BurpExtender.java
. See how IntelliCode is making our life easier.
IntelliCode in action, woot!
|
|
This code prints the extension file name to the console. Build the extension
with Ctrl+Shift+B
.
Extension built
The jar file will appear in build\libs
.
Built jar
Visual setup:
Extender
window via Window (menu) > Detach Extender
.Windows+Left Arrow
to send it to the corner of the screen.My extension development cycle is:
Ctrl+Shift+B
to build.Ctrl+Left-Click
on the checkbox in front of the extension in Extender to
reload it (this is in monitor 2).Extension loaded
This is the most important part of this post. I will discuss how I debug extensions in VS Code. Looking around, I could only find a few references:
burp.StartBurp
to the Run section of the project's properties does the trick.The VS Code Java extension pack comes with a Java debugger. To use it we need to run Burp with this command-line option:
-agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n
This will run the debug server at localhost:8000
. Note that most examples on
the internet run the server with just the port so the server will listen on
0.0.0.0
which is obviously not good (unless you want to debug from a remote
machine).
Next, we have to run Burp's jar file with the following parameter. Burp's jar file is at this path in a default installation:
C:\Program Files\BurpSuiteCommunity\burpsuite_community.jar
The complete command:
java -agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n
-jar "C:\Program Files\BurpSuiteCommunity\burpsuite_community.jar"
You might have seen the BurpSuiteCommunity.vmoptions
file inside the Burp's
directory. We can add run-time parameters to it. We can enable debugging by
adding the following line to the file:
-agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n
Now we can run the exe
and debug our extensions. I have included a sample
.vmoptions
file in the git repository.
Note: If you are using your main Burp instance, make sure to comment the
code in the .vmoptions
file after you are done. It might slow down your Burp
instance.
Next we have to launch the Java debugger in VS Code and connect to the debug
port. Put a breakpoint on the callbacks.printOutput(fileName);
line. Then
select Debug (menu) > Start Debugging
or press F5
.
This will create the .vscode\launch.json
file and open it. Paste this code
into it and save:
|
|
The file is very simple. The only important options are the hostName
and
port
which should point to the debug port specified above (localhost:8000
).
Start debugging again. Windows Firewall dialog might pop-up. If it does and you
are not debugging a remote machine, press cancel. If the debugger times out
while the firewall dialog is active, debug again (F5
).
After the debugger is attached, reload the extension with Ctrl+Right-Click
on the checkbox in the Extender tab and see the debugger break.
Achievement unlocked: Debugging in VS Code
Pretty nifty and super useful.
If you look inside the build
directory, you will see a lot of class files. We
do not want these in our source control. It's wise to add the build
directory
to the .gitignore
file. But this means our final jar file is also ignored and
we want our final jar file in the repository so people can just grab it and use
it.
We can change the location of the extension's jar file by modifying the
libsDirName
property in build.gradle
.
libsDirName = "../@jar"
This config copy the final jar file to
@jar\burp-sample-extension-java-all.jar
.