From 104841babf051cc9678dc66e824ab379bebd5343 Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Sat, 8 Nov 2014 20:57:24 -0500 Subject: [PATCH 1/2] Add getsid to the python meterpreter --- data/meterpreter/ext_server_stdapi.py | 91 +++++++++++++++++++-------- 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/data/meterpreter/ext_server_stdapi.py b/data/meterpreter/ext_server_stdapi.py index 9285ad3f3a..526e61c480 100644 --- a/data/meterpreter/ext_server_stdapi.py +++ b/data/meterpreter/ext_server_stdapi.py @@ -215,6 +215,9 @@ if has_ctypes: ("wProcessorLevel", ctypes.c_uint16), ("wProcessorRevision", ctypes.c_uint16)] + class TOKEN_USER(ctypes.Structure): + _fields_ = [("User", SID_AND_ATTRIBUTES)] + # # Linux Structures # @@ -364,6 +367,7 @@ TLV_TYPE_COMPUTER_NAME = TLV_META_TYPE_STRING | 1040 TLV_TYPE_OS_NAME = TLV_META_TYPE_STRING | 1041 TLV_TYPE_USER_NAME = TLV_META_TYPE_STRING | 1042 TLV_TYPE_ARCHITECTURE = TLV_META_TYPE_STRING | 1043 +TLV_TYPE_SID = TLV_META_TYPE_STRING | 1045 ## # Environment @@ -525,6 +529,36 @@ def get_stat_buffer(path): st_buf += struct.pack(' Date: Mon, 10 Nov 2014 09:15:16 -0500 Subject: [PATCH 2/2] Don't fail if username_from_token returns None --- data/meterpreter/ext_server_stdapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/meterpreter/ext_server_stdapi.py b/data/meterpreter/ext_server_stdapi.py index 526e61c480..aa1ca27df5 100644 --- a/data/meterpreter/ext_server_stdapi.py +++ b/data/meterpreter/ext_server_stdapi.py @@ -879,7 +879,7 @@ def stdapi_sys_process_get_processes_via_windll(request, response): process_username = '' process_token_user = get_token_user(proc_h) if process_token_user: - process_username = get_username_from_token(process_token_user) + process_username = get_username_from_token(process_token_user) or '' parch = windll_GetNativeSystemInfo() is_wow64 = ctypes.c_ubyte() is_wow64.value = 0