1
mirror of https://github.com/rapid7/metasploit-payloads synced 2024-11-20 14:39:22 +01:00
metasploit-payloads/java
2024-05-22 11:58:58 +01:00
..
androidpayload Add Java parent to AndroidPayload 2023-09-28 12:46:11 +01:00
javapayload Neater use of classloader, from review 2023-09-25 10:38:50 +10:00
meterpreter Remove early-access release suffix on version string 2024-05-14 19:05:32 +02:00
version-compatibility-check fix android ls, getenv and ifconfig 2020-12-21 13:45:20 +00:00
.gitignore remove duplication in gitignore 2021-02-11 23:17:52 +08:00
.travis.yml Update .gitignore and .travis.yml for new repo 2013-06-11 19:47:15 +02:00
Makefile remove (unused) references to the NDK from README and Makefile 2019-06-02 22:42:01 +08:00
pom.xml Bump junit from 3.8.2 to 4.13.1 in /java 2020-10-13 03:29:38 +00:00
README.md Update clean step to Java documentation 2024-05-22 11:54:53 +01:00

Building the Java and Android Meterpreter

  1. Install Maven and Java 1.8, this will depend on your OS
  2. Download the Android SDK
  3. Install Android SDK Platforms 3, 10 and 19, and update the "Android SDK Tools" and "Android SDK Platform-tools"
  4. Compile the Android and Java Meterpreter, which deploys to the ../metasploit-framework folder
mvn package -Dandroid.sdk.path=/path/to/android-sdk -Dandroid.release=true -P deploy

Next time you run msfconsole, you should see: WARNING: Local files may be incompatible with the Metasploit Framework. This means that msfconsole is now using your newly built version of the Java and Android Meterpreter :)

Building on Docker

Ensure that both the metasploit-payloads and metasploit-framework folders co-exist beside eachother:

$ ls working_directory
metasploit-framework
metasploit-payloads

Next you can download a pre-built Docker image from Rapid7's Docker Hub account:

docker pull rapid7/msf-ubuntu-x64-meterpreter:latest

Or this Docker image can be built manually:

cd working_directory/metasploit-payloads/docker
docker build -t rapid7/msf-ubuntu-x64-meterpreter:latest .

Next run the Docker image as a container and mount the working_directory. This interactive shell will allow you to compile the Android and Java Meterpreter, and deploy to the ../metasploit-framework folder as normal:

cd working_directory
docker run --rm  -it -w $(pwd) -v $(pwd):$(pwd) rapid7/msf-ubuntu-x64-meterpreter:latest /bin/bash

cd metasploit-payloads/java
# Optional: You may need to run a clean if you are having compilation issues
make clean
make android

Building on OSX

brew tap homebrew/cask-versions
brew install --cask temurin8
brew install --cask android-sdk
brew install maven
sdkmanager --licenses
sdkmanager "platforms;android-3"
sdkmanager "platforms;android-10"
sdkmanager "platforms;android-19"

#cd metasploit-payloads/java

# Important: Ensure Java 1.8 is used when compiling
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home

# Just Meterpreter
mvn package -P deploy

# With Android
mvn package -Dandroid.sdk.path=/usr/local/share/android-sdk -Dandroid.release=true -P deploy

Compiling JavaPayload and Java Meterpreter manually

To compile JavaPayload (a Java stager / code loader) and Java Meterpreter for Metasploit, you need Maven 3.1 or above (Maven 3.5 works at the time of this writing), and a copy of JDK 8.0 or later. Ensure that mvn and javac are in your path and work. Then run

mvn package

to package all the files needed for Java meterpreter. The two files that you will be generated are:

meterpreter/meterpreter/target/meterpreter.jar
meterpreter/stdapi/target/ext_server_stdapi.jar

To get Metasploit to use these files, you need to place them in a place where it can find them. To automatically build and install these files into Metasploit Framework for testing, run:

mvn -P deploy package

This will package all the files and copy them into the correct place for Metasploit, assuming that the metasploit-framework repository is checked out in an adjacent directory to this one. (../../metasploit-framework/data/java). If you get spurious compilation errors, make sure that there is an exclude rule in your antivirus for the Metasploit directory (or that your antivirus is disabled).

If the path to your metasploit framework repository is not ../../metasploit-framework, but for example (with Kali Linux)

/usr/share/metasploit-framework/, set the deploy.path directive like so:

mvn -D deploy.path=/usr/share/metasploit-framework -P deploy package

When you are editing this or any other Meterpreter, you will want to make sure that your copy of metasploit-framework is also up-to-date. We occasionally update the network protocol between Metasploit and its Payloads, and if the two do not match, things will probably not work. Metasploit will warn you the first time it stages a development payload that it is doing so, and that the payload and Metasploit framework may be incompatible.

Each time you make a change to your code, you must build and deploy the files into metasploit-framework for it to see the updates. It is not necessary to restart msfconsole when updating payloads however, as they are read from disk each time. So, a reasonable strategy when debugging is to leave msfconsole running with exploit/multi/handler, and just install and restage payloads as needed.

When you are done editing and want to revert Metasploit to use the builtin payloads, simply delete data/meterpreter/*.jar and data/meterpreter/java from your Metasploit framework directory. It will then fall back to the versions bundled with the metasploit-payloads Ruby gem.

IDE Support

Note: First ensure you have Java 1.8 installed, and your IDE is using Java 1.8

In case you want to edit/debug JavaPayload for Metasploit or Java Meterpreter with an IDE, Maven provides plugins to auto-generate project files for your favourite environment (at least for Eclipse, Netbeans or IntelliJ).

I use Eclipse, so to generate project files I use

mvn eclipse:eclipse

This will generate project files that can be imported via

File->Import->Existing Projects into Workspace

into your Eclipse workspace.

(Note that if this is your first Maven project you want to use in Eclipse, you also have to run

mvn -Declipse.workspace=/path/to/your/workspace eclipse:configure-workspace

to set up path variables like M2_REPO to point to the correct location.)

For NetBeans or IntelliJ IDEA, refer to the documentation at

http://maven.apache.org/netbeans-module.html http://maven.apache.org/plugins/maven-idea-plugin/