Skip to content

Commit 6eb54d9

Browse files
authored
Merge pull request #54 from softwaresecured/feature-51
#51 - Added shared memory feature
2 parents 1fb8621 + 2301a5d commit 6eb54d9

7 files changed

Lines changed: 82 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Burp Hotpatch ️provides pentesters with a quick way to hook into key BurpSuite
99
- Add custom actions to the context menu for quick execution of other tools.
1010
- Easily work with the Montoya API within Burp.
1111
- Task manager to control execution of utility and context menu actions
12+
- Shared variables between scripts
1213

1314
# Use cases
1415
- Session handling actions that require further processing after the session macro has run.

resources/templates/javascript/stub/utility.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
- You can import Java libraries using the following syntax:
99
var Matcher = Packages.java.util.regex.Matcher;
1010
11+
Memory:
12+
- Variables can be shared across scripts using the memory feature
13+
- The setString(name,value), setInt(name,value) and setObject(name,value) functions can be used to set values
14+
- The getString(name), getInt(name) and getObject(name) functions can be used to retrieve values
15+
- The above functions throw the burp_hotpatch.script.ScriptSharedMemoryException exception
16+
1117
Example:
1218
- This script prints the current BurpSuite version
1319

resources/templates/python/stub/utility.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
- You can import Java libraries using the following syntax:
99
from java.util.regex import Matcher
1010
11+
Memory:
12+
- Variables can be shared across scripts using the memory feature
13+
- The setString(name,value), setInt(name,value) and setObject(name,value) functions can be used to set values
14+
- The getString(name), getInt(name) and getObject(name) functions can be used to retrieve values
15+
- The above functions raise the burp_hotpatch.script.ScriptSharedMemoryException exception
16+
1117
Example:
1218
- This script prints the current BurpSuite version
1319

src/burp/VERSION.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public final class VERSION {
44
public static final int VERSION_MAJOR = 1;
55
public static final int VERSION_MINOR = 0;
6-
public static final int VERSION_PATCH = 12;
6+
public static final int VERSION_PATCH = 13;
77
public static final String RELEASE_TYPE = "beta";
88
public static final String RELEASE_TAGS_URL = "https://github.com/softwaresecured/burp-hotpatch/tags";
99

src/burp_hotpatch/scripts/ScriptExecutionContainer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public Object execute() throws ScriptExecutionException {
7272
.allowHostClassLookup(className -> true)
7373
.build();
7474

75+
cx.getBindings(languageId).putMember("memory",ScriptSharedMemory.getInstance());
7576
cx.getBindings(languageId).putMember("montoyaApi", MontoyaUtil.getInstance().getApi());
7677
if ( argumentName != null ) {
7778
cx.getBindings(languageId).putMember(argumentName, argument);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package burp_hotpatch.scripts;
2+
import java.util.HashMap;
3+
4+
public class ScriptSharedMemory {
5+
6+
private HashMap<String,String> strings;
7+
private HashMap<String,Integer> integers;
8+
private HashMap<String,Object> objects;
9+
10+
private static ScriptSharedMemory INSTANCE;
11+
public ScriptSharedMemory() {
12+
}
13+
14+
public static ScriptSharedMemory getInstance() {
15+
if(INSTANCE == null) {
16+
INSTANCE = new ScriptSharedMemory();
17+
INSTANCE.reset();
18+
}
19+
return INSTANCE;
20+
}
21+
22+
public void reset() {
23+
strings = new HashMap<>();
24+
integers = new HashMap<>();
25+
objects = new HashMap<>();
26+
}
27+
28+
public synchronized void setInt( String name, int num ) {
29+
integers.put(name,num);
30+
}
31+
32+
public int getInt( String name ) throws ScriptSharedMemoryException {
33+
if ( integers.get(name) == null ) {
34+
throw new ScriptSharedMemoryException(String.format("Key %s does not exist", name));
35+
}
36+
return integers.get(name);
37+
}
38+
39+
public synchronized void setString( String name, String str ) {
40+
strings.put(name,str);
41+
}
42+
43+
public String getString( String name ) throws ScriptSharedMemoryException {
44+
if ( objects.get(name) == null ) {
45+
throw new ScriptSharedMemoryException(String.format("Key %s does not exist", name));
46+
}
47+
return strings.get(name);
48+
}
49+
50+
public synchronized void setObject( String name, Object obj ) {
51+
objects.put(name,obj);
52+
}
53+
54+
public Object getObject( String name ) throws ScriptSharedMemoryException {
55+
if ( objects.get(name) == null ) {
56+
throw new ScriptSharedMemoryException(String.format("Key %s does not exist", name));
57+
}
58+
return objects.get(name);
59+
}
60+
61+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package burp_hotpatch.scripts;
2+
public class ScriptSharedMemoryException extends Exception {
3+
public ScriptSharedMemoryException(String errorMessage) {
4+
super(errorMessage);
5+
}
6+
}

0 commit comments

Comments
 (0)