From c14e1e7bfe96b47d89e650ba7a28e21403524c85 Mon Sep 17 00:00:00 2001 From: Tim W <timrlw@gmail.com> Date: Mon, 17 Jan 2022 10:11:36 +0000 Subject: [PATCH 1/2] fix getenv for missing environment variables --- .../meterpreter/stdapi/stdapi_sys_config_getenv.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_sys_config_getenv.java b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_sys_config_getenv.java index 2fb064ef..450f5ee2 100644 --- a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_sys_config_getenv.java +++ b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_sys_config_getenv.java @@ -22,10 +22,12 @@ public class stdapi_sys_config_getenv implements Command { } String envVal = System.getenv(envVar); - TLVPacket grp = new TLVPacket(); - grp.add(TLVType.TLV_TYPE_ENV_VARIABLE, envVar); - grp.add(TLVType.TLV_TYPE_ENV_VALUE, envVal); - response.addOverflow(TLVType.TLV_TYPE_ENV_GROUP, grp); + if (envVal != null) { + TLVPacket grp = new TLVPacket(); + grp.add(TLVType.TLV_TYPE_ENV_VARIABLE, envVar); + grp.add(TLVType.TLV_TYPE_ENV_VALUE, envVal); + response.addOverflow(TLVType.TLV_TYPE_ENV_GROUP, grp); + } } } catch (IllegalArgumentException e) { Map<String,String> envVals = System.getenv(); From 56627ea5db3e0551d4a5eee4e1c95c3a6b852ae1 Mon Sep 17 00:00:00 2001 From: Tim W <timrlw@gmail.com> Date: Mon, 17 Jan 2022 10:13:55 +0000 Subject: [PATCH 2/2] add stdapi_sys_process_getpid on Android --- .../meterpreter/AndroidMeterpreter.java | 1 + .../stdapi_sys_process_getpid_android.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 java/androidpayload/library/src/com/metasploit/meterpreter/android/stdapi_sys_process_getpid_android.java diff --git a/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java b/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java index 0474becd..c82cbb23 100644 --- a/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java +++ b/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java @@ -134,6 +134,7 @@ public class AndroidMeterpreter extends Meterpreter { mgr.registerCommand(CommandId.STDAPI_SYS_PROCESS_EXECUTE, stdapi_sys_process_execute_V1_3.class); mgr.registerCommand(CommandId.STDAPI_SYS_PROCESS_CLOSE, stdapi_sys_process_close.class); mgr.registerCommand(CommandId.STDAPI_SYS_PROCESS_GET_PROCESSES, stdapi_sys_process_get_processes_android.class); + mgr.registerCommand(CommandId.STDAPI_SYS_PROCESS_GETPID, stdapi_sys_process_getpid_android.class); mgr.registerCommand(CommandId.STDAPI_UI_DESKTOP_SCREENSHOT, stdapi_ui_desktop_screenshot.class); if (context != null) { mgr.registerCommand(CommandId.APPAPI_APP_LIST, appapi_app_list.class); diff --git a/java/androidpayload/library/src/com/metasploit/meterpreter/android/stdapi_sys_process_getpid_android.java b/java/androidpayload/library/src/com/metasploit/meterpreter/android/stdapi_sys_process_getpid_android.java new file mode 100644 index 00000000..fde1cb20 --- /dev/null +++ b/java/androidpayload/library/src/com/metasploit/meterpreter/android/stdapi_sys_process_getpid_android.java @@ -0,0 +1,19 @@ +package com.metasploit.meterpreter.android; + +import android.os.Process; + +import com.metasploit.meterpreter.Meterpreter; +import com.metasploit.meterpreter.TLVPacket; +import com.metasploit.meterpreter.TLVType; +import com.metasploit.meterpreter.command.Command; +import com.metasploit.meterpreter.stdapi.stdapi_sys_process_getpid; + +public class stdapi_sys_process_getpid_android extends stdapi_sys_process_getpid implements Command { + + public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception { + int pid = Process.myPid(); + response.add(TLVType.TLV_TYPE_PID, pid); + return ERROR_SUCCESS; + + } +}