mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-02-16 00:24:29 +01:00
Add getpid to Java Meterpreter
This commit is contained in:
parent
c3b9bbc188
commit
9c937e5684
@ -106,7 +106,6 @@ public class NotYetImplementedCommand implements Command {
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_MEMORY_STATE), "TLV_TYPE_MEMORY_STATE");
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_MEMORY_TYPE), "TLV_TYPE_MEMORY_TYPE");
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_ALLOC_PROTECTION), "TLV_TYPE_ALLOC_PROTECTION");
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_PID), "TLV_TYPE_PID");
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_PROCESS_NAME), "TLV_TYPE_PROCESS_NAME");
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_PROCESS_PATH), "TLV_TYPE_PROCESS_PATH");
|
||||
typeNames.put(new Integer(TLVType.TLV_TYPE_PROCESS_GROUP), "TLV_TYPE_PROCESS_GROUP");
|
||||
|
@ -71,5 +71,6 @@ public class Loader implements ExtensionLoader {
|
||||
mgr.registerCommand(CommandId.STDAPI_UI_SEND_MOUSE, stdapi_ui_send_mouse.class, V1_4);
|
||||
mgr.registerCommand(CommandId.STDAPI_UI_SEND_KEYEVENT, stdapi_ui_send_keyevent.class, V1_4);
|
||||
mgr.registerCommand(CommandId.STDAPI_WEBCAM_AUDIO_RECORD, stdapi_webcam_audio_record.class, V1_4);
|
||||
mgr.registerCommand(CommandId.STDAPI_SYS_PROCESS_GETPID, stdapi_sys_process_getpid.class, V1_5);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.metasploit.meterpreter.stdapi;
|
||||
|
||||
//Dummy class
|
||||
public class stdapi_sys_process_getpid {
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.metasploit.meterpreter.stdapi;
|
||||
|
||||
import com.metasploit.meterpreter.Meterpreter;
|
||||
import com.metasploit.meterpreter.TLVPacket;
|
||||
import com.metasploit.meterpreter.TLVType;
|
||||
import com.metasploit.meterpreter.command.Command;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class stdapi_sys_process_getpid_V1_5 implements Command {
|
||||
private static boolean classExists(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||
if (classExists("java.lang.ProcessHandle"))
|
||||
{
|
||||
Class<?> processHandleClass = Class.forName("java.lang.ProcessHandle");
|
||||
Method getCurrentProcessHandleMethod = processHandleClass.getMethod("current");
|
||||
Object currentProcessHandle = getCurrentProcessHandleMethod.invoke(null);
|
||||
Object pidObject = processHandleClass.getMethod("pid").invoke(currentProcessHandle);
|
||||
Long pid = (Long) pidObject;
|
||||
response.add(TLVType.TLV_TYPE_PID, pid.intValue());
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
else if (classExists("java.lang.management.ManagementFactory") && classExists("java.lang.management.RuntimeMXBean"))
|
||||
{
|
||||
Class<?> managementFactory = Class.forName("java.lang.management.ManagementFactory");
|
||||
Method runtimeBeanMethod = managementFactory.getMethod("getRuntimeMXBean");
|
||||
Object runtimeBean = runtimeBeanMethod.invoke(null);
|
||||
Class<?> runtimeBeanClass = Class.forName("java.lang.management.RuntimeMXBean");
|
||||
Method nameMethod = runtimeBeanClass.getMethod("getName");
|
||||
Object nameObj = nameMethod.invoke(runtimeBean);
|
||||
String name = (String) nameObj;
|
||||
Integer pid = Integer.parseInt(name.substring(0, name.indexOf("@")));
|
||||
response.add(TLVType.TLV_TYPE_PID, pid);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user