Skip to content

Commit 37fabe2

Browse files
Add code
0 parents  commit 37fabe2

File tree

7 files changed

+208
-0
lines changed

7 files changed

+208
-0
lines changed

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
replay_pid*
25+
26+
target/
27+
.DS_Store

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2022, Stephen Bradshaw
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# BurpPythonGateway
2+
Uses py4j to make Burp Extender internals available to Python code and interactive interpreters like iPython

pom.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.mycompany</groupId>
5+
<artifactId>Burp_Python_Gateway</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<build>
9+
<sourceDirectory>src</sourceDirectory>
10+
<plugins>
11+
<plugin>
12+
<artifactId>maven-compiler-plugin</artifactId>
13+
<version>3.8.1</version>
14+
<configuration>
15+
<source>1.8</source>
16+
<target>1.8</target>
17+
</configuration>
18+
</plugin>
19+
<plugin>
20+
<artifactId>maven-assembly-plugin</artifactId>
21+
<version>3.1.1</version>
22+
<configuration>
23+
<descriptorRefs>
24+
<descriptorRef>jar-with-dependencies</descriptorRef>
25+
</descriptorRefs>
26+
</configuration>
27+
<executions>
28+
<execution>
29+
<id>make-assembly</id>
30+
<phase>package</phase>
31+
<goals>
32+
<goal>single</goal>
33+
</goals>
34+
</execution>
35+
</executions>
36+
</plugin>
37+
</plugins>
38+
</build>
39+
<name>Burp_Python_Gateway</name>
40+
<dependencies>
41+
<dependency>
42+
<groupId>net.portswigger.burp.extender</groupId>
43+
<artifactId>burp-extender-api</artifactId>
44+
<version>1.7.22</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>net.sf.py4j</groupId>
48+
<artifactId>py4j</artifactId>
49+
<version>0.10.9</version>
50+
</dependency>
51+
</dependencies>
52+
</project>

python/examples.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
3+
from py4j.java_gateway import JavaGateway
4+
gateway = JavaGateway()
5+
6+
# callbacks
7+
callbacks = gateway.entry_point
8+
9+
# helpers
10+
helpers = callbacks.getHelpers()
11+
12+
# sitemap
13+
sm = callbacks.getSiteMap('h')
14+
15+
# out of scope host names
16+
set([a.getHost() for a in sm if not callbacks.isInScope(a.getUrl())])
17+
18+
# in scope items
19+
ssm = [a for a in sm if callbacks.isInScope(a.getUrl())]
20+
21+
# get headers
22+
def get_headers(request):
23+
head = request.split(b'\r\n\r\n')[0].decode('utf8')
24+
return [(a.split(':', 1)[0].rstrip(), a.split(':', 1)[1].rstrip().lstrip()) for a in head.split('\r\n') if ':' in a]
25+
26+
27+
# in scope site map items
28+
ssm = [a for a in sm if callbacks.isInScope(a.getUrl())]
29+
30+
# get user agents for in scope hosts
31+
set([b[1] for a in ssm for b in get_headers(a.getRequest()) if b[0].lower() == 'user-agent'])
32+
33+
34+
# get user agents used per host in scope
35+
host_user_agents = { a: [] for a in set([a.getHost() for a in ssm])}
36+
for entry in ssm:
37+
host = entry.getHost()
38+
headers = get_headers(entry.getRequest())
39+
host_user_agents[host] = host_user_agents[host] + list(set([a[1] for a in headers if a[0].lower() == 'user-agent' and a[1] not in host_user_agents[host]]))
40+
41+
42+
# request types of in scope items
43+
set([a.getRequest().split(b' ')[0].decode('utf8') for a in ssm])
44+
45+
# data
46+
47+
# URL parameters
48+
49+
# unusual request types (not GET, HEAD, POST)
50+
51+
# unusual headers
52+
53+
54+
55+
56+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package burp;
2+
3+
import java.io.PrintWriter;
4+
import py4j.GatewayServer;
5+
6+
public class BurpExtender implements IBurpExtender {
7+
8+
@Override
9+
public void registerExtenderCallbacks (IBurpExtenderCallbacks callbacks)
10+
{
11+
callbacks.setExtensionName("Burp Python Gateway");
12+
13+
PrintWriter stdout = new PrintWriter(callbacks.getStdout(), true);
14+
15+
GatewayServer gatewayServer = new GatewayServer(callbacks);
16+
gatewayServer.start();
17+
18+
callbacks.registerExtensionStateListener(new ExtensionStateListener(gatewayServer));
19+
20+
stdout.println("Burp Python Gateway Loaded!");
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package burp;
2+
3+
import py4j.GatewayServer;
4+
5+
6+
public class ExtensionStateListener implements IExtensionStateListener {
7+
private GatewayServer gatewayServer;
8+
9+
10+
public ExtensionStateListener(GatewayServer gatewayServer){
11+
this.gatewayServer = gatewayServer;
12+
13+
}
14+
15+
@Override
16+
public void extensionUnloaded(){
17+
this.gatewayServer.shutdown();
18+
}
19+
20+
}

0 commit comments

Comments
 (0)