@@ -690,10 +690,10 @@ def stdapi_sys_config_getenv(request, response):
690690def stdapi_sys_config_getsid (request , response ):
691691 token = get_token_user (ctypes .windll .kernel32 .GetCurrentProcess ())
692692 if not token :
693- return ERROR_FAILURE , response
693+ return error_result_windows () , response
694694 sid_str = ctypes .c_char_p ()
695695 if not ctypes .windll .advapi32 .ConvertSidToStringSidA (token .User .Sid , ctypes .byref (sid_str )):
696- return ERROR_FAILURE , response
696+ return error_result_windows () , response
697697 sid_str = str (ctypes .string_at (sid_str ))
698698 response += tlv_pack (TLV_TYPE_SID , sid_str )
699699 return ERROR_SUCCESS , response
@@ -705,10 +705,10 @@ def stdapi_sys_config_getuid(request, response):
705705 elif has_windll :
706706 token = get_token_user (ctypes .windll .kernel32 .GetCurrentProcess ())
707707 if not token :
708- return ERROR_FAILURE , response
708+ return error_result_windows () , response
709709 username = get_username_from_token (token )
710710 if not username :
711- return ERROR_FAILURE , response
711+ return error_result_windows () , response
712712 else :
713713 username = getpass .getuser ()
714714 response += tlv_pack (TLV_TYPE_USER_NAME , username )
@@ -796,9 +796,9 @@ def stdapi_sys_process_kill(request, response):
796796 k32 = ctypes .windll .kernel32
797797 proc_h = k32 .OpenProcess (PROCESS_TERMINATE , False , pid )
798798 if not proc_h :
799- return ERROR_FAILURE , response
799+ return error_result_windows () , response
800800 if not k32 .TerminateProcess (proc_h , 0 ):
801- return ERROR_FAILURE , response
801+ return error_result_windows () , response
802802 elif hasattr (os , 'kill' ):
803803 os .kill (pid , 9 )
804804 else :
@@ -865,7 +865,7 @@ def stdapi_sys_process_get_processes_via_windll(request, response):
865865 proc_snap = k32 .CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS , 0 )
866866 result = k32 .Process32First (proc_snap , ctypes .byref (pe32 ))
867867 if not result :
868- return ERROR_FAILURE , response
868+ return error_result_windows () , response
869869 while result :
870870 proc_h = k32 .OpenProcess ((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ ), False , pe32 .th32ProcessID )
871871 if not proc_h :
@@ -1348,10 +1348,10 @@ def stdapi_registry_create_key(request, response):
13481348 base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
13491349 permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
13501350 res_key = ctypes .c_void_p ()
1351- if ctypes .windll .advapi32 .RegCreateKeyExA (root_key , ctypes .byref (base_key ), 0 , None , 0 , permission , None , ctypes .byref (res_key ), None ) = = ERROR_SUCCESS :
1352- response += tlv_pack ( TLV_TYPE_HKEY , res_key . value )
1353- return ERROR_SUCCESS , response
1354- return ERROR_FAILURE , response
1351+ if ctypes .windll .advapi32 .RegCreateKeyExA (root_key , ctypes .byref (base_key ), 0 , None , 0 , permission , None , ctypes .byref (res_key ), None ) ! = ERROR_SUCCESS :
1352+ return error_result_windows (), response
1353+ response += tlv_pack ( TLV_TYPE_HKEY , res_key . value )
1354+ return ERROR_SUCCESS , response
13551355
13561356@meterpreter .register_function_windll
13571357def stdapi_registry_delete_key (request , response ):
@@ -1442,33 +1442,31 @@ def stdapi_registry_open_key(request, response):
14421442 base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
14431443 permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
14441444 handle_id = ctypes .c_void_p ()
1445- if ctypes .windll .advapi32 .RegOpenKeyExA (root_key , ctypes .byref (base_key ), 0 , permission , ctypes .byref (handle_id )) = = ERROR_SUCCESS :
1446- response += tlv_pack ( TLV_TYPE_HKEY , handle_id . value )
1447- return ERROR_SUCCESS , response
1448- return ERROR_FAILURE , response
1445+ if ctypes .windll .advapi32 .RegOpenKeyExA (root_key , ctypes .byref (base_key ), 0 , permission , ctypes .byref (handle_id )) ! = ERROR_SUCCESS :
1446+ return error_result_windows (), response
1447+ response += tlv_pack ( TLV_TYPE_HKEY , handle_id . value )
1448+ return ERROR_SUCCESS , response
14491449
14501450@meterpreter .register_function_windll
14511451def stdapi_registry_open_remote_key (request , response ):
14521452 target_host = packet_get_tlv (request , TLV_TYPE_TARGET_HOST )['value' ]
14531453 root_key = packet_get_tlv (request , TLV_TYPE_ROOT_KEY )['value' ]
14541454 result_key = ctypes .c_void_p ()
1455- result = ctypes .windll .advapi32 .RegConnectRegistry (target_host , root_key , ctypes .byref (result_key ))
1456- if (result == ERROR_SUCCESS ):
1457- response += tlv_pack (TLV_TYPE_HKEY , result_key .value )
1458- return ERROR_SUCCESS , response
1459- return ERROR_FAILURE , response
1455+ if ctypes .windll .advapi32 .RegConnectRegistry (target_host , root_key , ctypes .byref (result_key )) != ERROR_SUCCESS :
1456+ return error_result_windows (), response
1457+ response += tlv_pack (TLV_TYPE_HKEY , result_key .value )
1458+ return ERROR_SUCCESS , response
14601459
14611460@meterpreter .register_function_windll
14621461def stdapi_registry_query_class (request , response ):
14631462 hkey = packet_get_tlv (request , TLV_TYPE_HKEY )['value' ]
14641463 value_data = (ctypes .c_char * 4096 )()
14651464 value_data_sz = ctypes .c_uint32 ()
14661465 value_data_sz .value = ctypes .sizeof (value_data )
1467- result = ctypes .windll .advapi32 .RegQueryInfoKeyA (hkey , value_data , ctypes .byref (value_data_sz ), None , None , None , None , None , None , None , None , None )
1468- if result == ERROR_SUCCESS :
1469- response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data ))
1470- return ERROR_SUCCESS , response
1471- return ERROR_FAILURE , response
1466+ if ctypes .windll .advapi32 .RegQueryInfoKeyA (hkey , value_data , ctypes .byref (value_data_sz ), None , None , None , None , None , None , None , None , None ) != ERROR_SUCCESS :
1467+ return error_result_windows (), response
1468+ response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data ))
1469+ return ERROR_SUCCESS , response
14721470
14731471@meterpreter .register_function_windll
14741472def stdapi_registry_query_value (request , response ):
@@ -1496,7 +1494,7 @@ def stdapi_registry_query_value(request, response):
14961494 else :
14971495 response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data , value_data_sz .value ))
14981496 return ERROR_SUCCESS , response
1499- return ERROR_FAILURE , response
1497+ return error_result_windows () , response
15001498
15011499@meterpreter .register_function_windll
15021500def stdapi_registry_set_value (request , response ):
0 commit comments