@@ -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 :
@@ -945,8 +945,7 @@ def stdapi_fs_delete_dir(request, response):
945945@meterpreter .register_function
946946def stdapi_fs_delete_file (request , response ):
947947 file_path = packet_get_tlv (request , TLV_TYPE_FILE_PATH )['value' ]
948- if os .path .exists (file_path ):
949- os .unlink (file_path )
948+ os .unlink (file_path )
950949 return ERROR_SUCCESS , response
951950
952951@meterpreter .register_function
@@ -1348,10 +1347,10 @@ def stdapi_registry_create_key(request, response):
13481347 base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
13491348 permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
13501349 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
1350+ if ctypes .windll .advapi32 .RegCreateKeyExA (root_key , ctypes .byref (base_key ), 0 , None , 0 , permission , None , ctypes .byref (res_key ), None ) ! = ERROR_SUCCESS :
1351+ return error_result_windows (), response
1352+ response += tlv_pack ( TLV_TYPE_HKEY , res_key . value )
1353+ return ERROR_SUCCESS , response
13551354
13561355@meterpreter .register_function_windll
13571356def stdapi_registry_delete_key (request , response ):
@@ -1442,33 +1441,31 @@ def stdapi_registry_open_key(request, response):
14421441 base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
14431442 permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
14441443 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
1444+ if ctypes .windll .advapi32 .RegOpenKeyExA (root_key , ctypes .byref (base_key ), 0 , permission , ctypes .byref (handle_id )) ! = ERROR_SUCCESS :
1445+ return error_result_windows (), response
1446+ response += tlv_pack ( TLV_TYPE_HKEY , handle_id . value )
1447+ return ERROR_SUCCESS , response
14491448
14501449@meterpreter .register_function_windll
14511450def stdapi_registry_open_remote_key (request , response ):
14521451 target_host = packet_get_tlv (request , TLV_TYPE_TARGET_HOST )['value' ]
14531452 root_key = packet_get_tlv (request , TLV_TYPE_ROOT_KEY )['value' ]
14541453 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
1454+ if ctypes .windll .advapi32 .RegConnectRegistry (target_host , root_key , ctypes .byref (result_key )) != ERROR_SUCCESS :
1455+ return error_result_windows (), response
1456+ response += tlv_pack (TLV_TYPE_HKEY , result_key .value )
1457+ return ERROR_SUCCESS , response
14601458
14611459@meterpreter .register_function_windll
14621460def stdapi_registry_query_class (request , response ):
14631461 hkey = packet_get_tlv (request , TLV_TYPE_HKEY )['value' ]
14641462 value_data = (ctypes .c_char * 4096 )()
14651463 value_data_sz = ctypes .c_uint32 ()
14661464 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
1465+ if ctypes .windll .advapi32 .RegQueryInfoKeyA (hkey , value_data , ctypes .byref (value_data_sz ), None , None , None , None , None , None , None , None , None ) != ERROR_SUCCESS :
1466+ return error_result_windows (), response
1467+ response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data ))
1468+ return ERROR_SUCCESS , response
14721469
14731470@meterpreter .register_function_windll
14741471def stdapi_registry_query_value (request , response ):
@@ -1496,7 +1493,7 @@ def stdapi_registry_query_value(request, response):
14961493 else :
14971494 response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data , value_data_sz .value ))
14981495 return ERROR_SUCCESS , response
1499- return ERROR_FAILURE , response
1496+ return error_result_windows () , response
15001497
15011498@meterpreter .register_function_windll
15021499def stdapi_registry_set_value (request , response ):
0 commit comments