@@ -690,10 +690,10 @@ def stdapi_sys_config_getenv(request, response):
690
690
def stdapi_sys_config_getsid (request , response ):
691
691
token = get_token_user (ctypes .windll .kernel32 .GetCurrentProcess ())
692
692
if not token :
693
- return ERROR_FAILURE , response
693
+ return error_result_windows () , response
694
694
sid_str = ctypes .c_char_p ()
695
695
if not ctypes .windll .advapi32 .ConvertSidToStringSidA (token .User .Sid , ctypes .byref (sid_str )):
696
- return ERROR_FAILURE , response
696
+ return error_result_windows () , response
697
697
sid_str = str (ctypes .string_at (sid_str ))
698
698
response += tlv_pack (TLV_TYPE_SID , sid_str )
699
699
return ERROR_SUCCESS , response
@@ -705,10 +705,10 @@ def stdapi_sys_config_getuid(request, response):
705
705
elif has_windll :
706
706
token = get_token_user (ctypes .windll .kernel32 .GetCurrentProcess ())
707
707
if not token :
708
- return ERROR_FAILURE , response
708
+ return error_result_windows () , response
709
709
username = get_username_from_token (token )
710
710
if not username :
711
- return ERROR_FAILURE , response
711
+ return error_result_windows () , response
712
712
else :
713
713
username = getpass .getuser ()
714
714
response += tlv_pack (TLV_TYPE_USER_NAME , username )
@@ -796,9 +796,9 @@ def stdapi_sys_process_kill(request, response):
796
796
k32 = ctypes .windll .kernel32
797
797
proc_h = k32 .OpenProcess (PROCESS_TERMINATE , False , pid )
798
798
if not proc_h :
799
- return ERROR_FAILURE , response
799
+ return error_result_windows () , response
800
800
if not k32 .TerminateProcess (proc_h , 0 ):
801
- return ERROR_FAILURE , response
801
+ return error_result_windows () , response
802
802
elif hasattr (os , 'kill' ):
803
803
os .kill (pid , 9 )
804
804
else :
@@ -865,7 +865,7 @@ def stdapi_sys_process_get_processes_via_windll(request, response):
865
865
proc_snap = k32 .CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS , 0 )
866
866
result = k32 .Process32First (proc_snap , ctypes .byref (pe32 ))
867
867
if not result :
868
- return ERROR_FAILURE , response
868
+ return error_result_windows () , response
869
869
while result :
870
870
proc_h = k32 .OpenProcess ((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ ), False , pe32 .th32ProcessID )
871
871
if not proc_h :
@@ -1348,10 +1348,10 @@ def stdapi_registry_create_key(request, response):
1348
1348
base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
1349
1349
permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
1350
1350
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
1355
1355
1356
1356
@meterpreter .register_function_windll
1357
1357
def stdapi_registry_delete_key (request , response ):
@@ -1442,33 +1442,31 @@ def stdapi_registry_open_key(request, response):
1442
1442
base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
1443
1443
permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
1444
1444
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
1449
1449
1450
1450
@meterpreter .register_function_windll
1451
1451
def stdapi_registry_open_remote_key (request , response ):
1452
1452
target_host = packet_get_tlv (request , TLV_TYPE_TARGET_HOST )['value' ]
1453
1453
root_key = packet_get_tlv (request , TLV_TYPE_ROOT_KEY )['value' ]
1454
1454
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
1460
1459
1461
1460
@meterpreter .register_function_windll
1462
1461
def stdapi_registry_query_class (request , response ):
1463
1462
hkey = packet_get_tlv (request , TLV_TYPE_HKEY )['value' ]
1464
1463
value_data = (ctypes .c_char * 4096 )()
1465
1464
value_data_sz = ctypes .c_uint32 ()
1466
1465
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
1472
1470
1473
1471
@meterpreter .register_function_windll
1474
1472
def stdapi_registry_query_value (request , response ):
@@ -1496,7 +1494,7 @@ def stdapi_registry_query_value(request, response):
1496
1494
else :
1497
1495
response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data , value_data_sz .value ))
1498
1496
return ERROR_SUCCESS , response
1499
- return ERROR_FAILURE , response
1497
+ return error_result_windows () , response
1500
1498
1501
1499
@meterpreter .register_function_windll
1502
1500
def stdapi_registry_set_value (request , response ):
0 commit comments