mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-01-14 17:37:27 +01:00
Land #5, @schierlm's meterpreter plugin maven archetype
This commit is contained in:
commit
379b455a10
36
java/meterpreter/CREATING_METERPRETER_EXTENSIONS.txt
Normal file
36
java/meterpreter/CREATING_METERPRETER_EXTENSIONS.txt
Normal file
@ -0,0 +1,36 @@
|
||||
To create a new Java Meterpreter extension, you can use a templating system
|
||||
called Maven Archetypes.
|
||||
|
||||
In this directory, type
|
||||
|
||||
cd extension-archetype
|
||||
mvn install
|
||||
cd ..
|
||||
mvn -DarchetypeGroupId=com.metasploit -DarchetypeArtifactId=extension-archetype -Dversion=1-SNAPSHOT archetype:generate
|
||||
|
||||
and follow the instructions.
|
||||
|
||||
You can choose arbitrary groupId, artifactId and package names; the
|
||||
default extensions use
|
||||
groupId: com.metasploit
|
||||
artifactId: Metasploit-Java-Meterpreter-${pluginName}
|
||||
package: com.metasploit.meterpreter.${pluginName}
|
||||
|
||||
The pluginName must satisfy the constraints for a Meterpreter plugin name:
|
||||
only lowercase letters and digits are allowed, and the first character may
|
||||
not be a digit.
|
||||
|
||||
|
||||
The newly created project will include a <NAME>.rb file in its root directory
|
||||
that needs to be moved to
|
||||
|
||||
msf3/lib/rex/post/meterpreter/extensions/<NAME>/<NAME>.rb
|
||||
|
||||
so that the extension can be loaded from a post module (or interactively
|
||||
from irb) like this:
|
||||
|
||||
client = session
|
||||
if client.<NAME> == nil
|
||||
client.core.use('<NAME>')
|
||||
end
|
||||
print_status client.<NAME>.<NAME>_greet_world()
|
29
java/meterpreter/extension-archetype/pom.xml
Normal file
29
java/meterpreter/extension-archetype/pom.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.metasploit</groupId>
|
||||
<artifactId>extension-archetype</artifactId>
|
||||
<version>1-SNAPSHOT</version>
|
||||
<packaging>maven-archetype</packaging>
|
||||
<name>Java Meterpreter extension archetype</name>
|
||||
<url>http://www.metasploit.com/</url>
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.archetype</groupId>
|
||||
<artifactId>archetype-packaging</artifactId>
|
||||
<version>2.2</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-archetype-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archetype-descriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
|
||||
name="Java Meterpreter extension archetype">
|
||||
<requiredProperties>
|
||||
<requiredProperty key="pluginName" />
|
||||
<requiredProperty key="groupId">
|
||||
<defaultValue>com.metasploit</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="artifactId">
|
||||
<defaultValue>Metasploit-Java-Meterpreter-${pluginName}</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="package">
|
||||
<defaultValue>com.metasploit.meterpreter.${pluginName}</defaultValue>
|
||||
</requiredProperty>
|
||||
</requiredProperties>
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory></directory>
|
||||
<includes>
|
||||
<include>*.rb</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</archetype-descriptor>
|
@ -0,0 +1,48 @@
|
||||
# -*- coding: binary -*-
|
||||
|
||||
module Rex
|
||||
module Post
|
||||
module Meterpreter
|
||||
module Extensions
|
||||
# This module contains a 'Hello World' meterpreter extension
|
||||
module ${pluginName.substring(0,1).toUpperCase()}${pluginName.substring(1)}
|
||||
TLV_TYPE_GREETEE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 1)
|
||||
|
||||
# This class implements a 'Hello World' meterpreter extension
|
||||
class ${pluginName.substring(0,1).toUpperCase()}${pluginName.substring(1)} < Extension
|
||||
def initialize(client)
|
||||
super(client, '${pluginName}')
|
||||
|
||||
client.register_extension_aliases(
|
||||
[
|
||||
{
|
||||
'name' => '${pluginName}',
|
||||
'ext' => self
|
||||
}
|
||||
])
|
||||
end
|
||||
|
||||
# Sends a greet_world request and gets a reply
|
||||
#
|
||||
# @return [String]
|
||||
def ${pluginName}_greet_world
|
||||
request = Packet.create_request('${pluginName}_greet_world')
|
||||
response = client.send_request(request)
|
||||
response.get_tlv_value(TLV_TYPE_STRING)
|
||||
end
|
||||
|
||||
# Sends a greet_someone request and gets a reply
|
||||
#
|
||||
# @return [String]
|
||||
def ${pluginName}_greet_someone(greetee)
|
||||
request = Packet.create_request('${pluginName}_greet_someone')
|
||||
request.add_tlv(TLV_TYPE_GREETEE, greetee)
|
||||
response = client.send_request(request)
|
||||
response.get_tlv_value(TLV_TYPE_STRING)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${artifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Java Meterpreter ${pluginName} Plugin</name>
|
||||
<url>http://www.metasploit.com/</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.metasploit</groupId>
|
||||
<artifactId>Metasploit-JavaPayload</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.metasploit</groupId>
|
||||
<artifactId>Metasploit-Java-Meterpreter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>ext_server_${pluginName}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<mkdir dir="${project.basedir}/../meterpreter/target/extension-src" />
|
||||
<copy todir="${project.basedir}/../meterpreter/target/extension-src">
|
||||
<fileset dir="${project.basedir}/src/main/java" includes="**/*.java" />
|
||||
</copy>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Extension-Loader>${package}.Loader</Extension-Loader>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<!-- deploy built files to Metasploit data directory -->
|
||||
<id>deploy</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<mkdir dir="${project.basedir}/target/tmp" />
|
||||
<unzip src="${project.basedir}/target/${project.build.finalName}.jar" dest="${project.basedir}/target/tmp" />
|
||||
<touch datetime="01/01/2000 00:00 AM">
|
||||
<fileset dir="${project.basedir}/target/tmp" includes="**/*" />
|
||||
</touch>
|
||||
<delete file="${project.basedir}/../../${deploy.path}/data/meterpreter/${project.build.finalName}.jar" />
|
||||
<zip destfile="${project.basedir}/../../${deploy.path}/data/meterpreter/${project.build.finalName}.jar">
|
||||
<fileset dir="${project.basedir}/target/tmp" includes="META-INF/**" />
|
||||
<fileset dir="${project.basedir}/target/tmp" excludes="META-INF/**" />
|
||||
</zip>
|
||||
<delete dir="${project.basedir}/target/tmp" />
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
@ -0,0 +1,18 @@
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
package ${package};
|
||||
|
||||
import com.metasploit.meterpreter.CommandManager;
|
||||
import com.metasploit.meterpreter.ExtensionLoader;
|
||||
|
||||
/**
|
||||
* Loader class to register all the commands of this extension.
|
||||
*/
|
||||
public class Loader implements ExtensionLoader {
|
||||
|
||||
public void load(CommandManager mgr) throws Exception {
|
||||
mgr.registerCommand("${pluginName}_greet_world", ${pluginName}_greet_world.class);
|
||||
mgr.registerCommand("${pluginName}_greet_someone", ${pluginName}_greet_someone.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
package ${package};
|
||||
|
||||
import com.metasploit.meterpreter.TLVPacket;
|
||||
|
||||
/**
|
||||
* TLV types for this extension. Add new types you need here.
|
||||
*/
|
||||
public interface TLVType extends com.metasploit.meterpreter.TLVType {
|
||||
|
||||
public static final int TLV_EXTENSIONS = 20000;
|
||||
|
||||
public static final int TLV_TYPE_GREETEE = TLVPacket.TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 1);
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
package ${package};
|
||||
|
||||
import com.metasploit.meterpreter.Meterpreter;
|
||||
import com.metasploit.meterpreter.TLVPacket;
|
||||
import com.metasploit.meterpreter.command.Command;
|
||||
|
||||
/**
|
||||
* Example how to implement a command differently for different target Java
|
||||
* versions. This command will build a dynamic greeting, print it to the
|
||||
* victim's console and return it.
|
||||
*
|
||||
* There are two implementations of this class. This base class uses
|
||||
* {@link StringBuffer} for building the greeting. The version for Java 1.5 and
|
||||
* above, {@link ${pluginName}_greet_someone_V1_5}, uses
|
||||
* {@link String${symbol_pound}format(String, Object[])} API which was added in Java 1.5. This
|
||||
* example is constructed since the new formatting API does not really justify a
|
||||
* separate version of the command.
|
||||
*/
|
||||
public class ${pluginName}_greet_someone implements Command {
|
||||
|
||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||
String greetee = request.getStringValue(TLVType.TLV_TYPE_GREETEE);
|
||||
String greeting = buildGreeting(greetee);
|
||||
System.out.println(greeting);
|
||||
response.add(TLVType.TLV_TYPE_STRING, greeting);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
protected String buildGreeting(String greetee) {
|
||||
StringBuffer sb = new StringBuffer(greetee.length() + 8);
|
||||
sb.append("Hello, ");
|
||||
sb.append(greetee);
|
||||
sb.append('!');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
package ${package};
|
||||
|
||||
/**
|
||||
* Implementation of {@link ${pluginName}_greet_someone} for Java 1.5 and above, using
|
||||
* {@link String${symbol_pound}format(String, Object[])} API.
|
||||
*/
|
||||
public class ${pluginName}_greet_someone_V1_5 extends ${pluginName}_greet_someone {
|
||||
|
||||
protected String buildGreeting(String greetee) {
|
||||
return String.format("Hello, %s!", new Object[] { greetee });
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
package ${package};
|
||||
|
||||
import com.metasploit.meterpreter.Meterpreter;
|
||||
import com.metasploit.meterpreter.TLVPacket;
|
||||
import com.metasploit.meterpreter.command.Command;
|
||||
|
||||
/**
|
||||
* Example of a very simple command. This command will print a greeting to the
|
||||
* victim's console and return it.
|
||||
*/
|
||||
public class ${pluginName}_greet_world implements Command {
|
||||
|
||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||
String greeting = "Hello, world!";
|
||||
System.out.println(greeting);
|
||||
response.add(TLVType.TLV_TYPE_STRING, greeting);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
}
|
@ -33,5 +33,6 @@
|
||||
<module>meterpreter</module>
|
||||
<module>stdapi</module>
|
||||
<module>debugloader</module>
|
||||
<module>extension-archetype</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
@ -26,6 +26,27 @@
|
||||
<build>
|
||||
<finalName>ext_server_stdapi</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<mkdir dir="${project.basedir}/../meterpreter/target/extension-src" />
|
||||
<copy todir="${project.basedir}/../meterpreter/target/extension-src">
|
||||
<fileset dir="${project.basedir}/src/main/java" includes="**/*.java" />
|
||||
</copy>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
|
@ -30,7 +30,7 @@
|
||||
<fileset dir="${project.basedir}/../../javapayload/src/main/java" includes="**/*.java" excludes="rmi/**" />
|
||||
<fileset dir="${project.basedir}/../../meterpreter/meterpreter/src/main/java" includes="**/*.java"/>
|
||||
<!-- Webcam_audio_record_V1_4 depends on Sun proprietary API -->
|
||||
<fileset dir="${project.basedir}/../../meterpreter/stdapi/src/main/java" includes="**/*.java" excludes="**/webcam_audio_record_V1_4.java" />
|
||||
<fileset dir="${project.basedir}/../../meterpreter/meterpreter/target/extension-src" includes="**/*.java" excludes="**/webcam_audio_record_V1_4.java" />
|
||||
</copy>
|
||||
</target>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user