@@ -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 :
@@ -945,8 +945,7 @@ def stdapi_fs_delete_dir(request, response):
945
945
@meterpreter .register_function
946
946
def stdapi_fs_delete_file (request , response ):
947
947
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 )
950
949
return ERROR_SUCCESS , response
951
950
952
951
@meterpreter .register_function
@@ -1348,10 +1347,10 @@ def stdapi_registry_create_key(request, response):
1348
1347
base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
1349
1348
permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
1350
1349
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
1355
1354
1356
1355
@meterpreter .register_function_windll
1357
1356
def stdapi_registry_delete_key (request , response ):
@@ -1442,33 +1441,31 @@ def stdapi_registry_open_key(request, response):
1442
1441
base_key = ctypes .create_string_buffer (bytes (base_key , 'UTF-8' ))
1443
1442
permission = packet_get_tlv (request , TLV_TYPE_PERMISSION ).get ('value' , winreg .KEY_ALL_ACCESS )
1444
1443
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
1449
1448
1450
1449
@meterpreter .register_function_windll
1451
1450
def stdapi_registry_open_remote_key (request , response ):
1452
1451
target_host = packet_get_tlv (request , TLV_TYPE_TARGET_HOST )['value' ]
1453
1452
root_key = packet_get_tlv (request , TLV_TYPE_ROOT_KEY )['value' ]
1454
1453
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
1460
1458
1461
1459
@meterpreter .register_function_windll
1462
1460
def stdapi_registry_query_class (request , response ):
1463
1461
hkey = packet_get_tlv (request , TLV_TYPE_HKEY )['value' ]
1464
1462
value_data = (ctypes .c_char * 4096 )()
1465
1463
value_data_sz = ctypes .c_uint32 ()
1466
1464
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
1472
1469
1473
1470
@meterpreter .register_function_windll
1474
1471
def stdapi_registry_query_value (request , response ):
@@ -1496,7 +1493,7 @@ def stdapi_registry_query_value(request, response):
1496
1493
else :
1497
1494
response += tlv_pack (TLV_TYPE_VALUE_DATA , ctypes .string_at (value_data , value_data_sz .value ))
1498
1495
return ERROR_SUCCESS , response
1499
- return ERROR_FAILURE , response
1496
+ return error_result_windows () , response
1500
1497
1501
1498
@meterpreter .register_function_windll
1502
1499
def stdapi_registry_set_value (request , response ):
0 commit comments