mirror of
https://github.com/naksyn/PythonMemoryModule
synced 2026-06-06 16:24:25 +00:00
db1893910c
This update include support to passing command line parameters to unmanaged exe via PEB stomping. This technique is not working with every executable since it depends on which functions are used to pass arguments. Generally, to get a universally working technique would be required to hook GetCommandlineA GetCommandlineW __getmainargs and __wgetmainargs since PEB stomping won't cover all cases, more details here: https://blog-30cm-tw.translate.goog/2020/08/windows-c-mainargc-argv.html?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=it&_x_tr_pto=wapp However, during my testing I found that mimikatz and several go binaries are working just by doing PEB stomping. On the other hand, cmdline passing via PEB stomping alone to mingw and VS compiled binaries won't likely work.
78 lines
3.1 KiB
Python
78 lines
3.1 KiB
Python
import ctypes
|
|
from ctypes import wintypes
|
|
import windows.generated_def as gdef
|
|
|
|
from ..apiproxy import ApiProxy, NeededParameter, is_implemented
|
|
from ..error import succeed_on_zero, fail_on_zero, result_is_handle, no_error_check
|
|
|
|
|
|
MAX_CLASS_NAME_LEN = 32
|
|
MAX_DEV_LEN = 1000
|
|
|
|
|
|
class SetupApiProxy(ApiProxy):
|
|
APIDLL = "SetupApi"
|
|
default_error_check = staticmethod(fail_on_zero)
|
|
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiClassNameFromGuidA(ClassGuid, ClassName, ClassNameSize=None, RequiredSize=None):
|
|
"""
|
|
Given a class Guid, return the name associated or raise an Exception
|
|
"""
|
|
if ClassNameSize is None:
|
|
ClassNameSize = ctypes.sizeof(ClassName)
|
|
return SetupDiClassNameFromGuidA.ctypes_function(ClassGuid, ClassName, ClassNameSize, RequiredSize)
|
|
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiClassNameFromGuidW(Guid):
|
|
|
|
"""
|
|
Given a class Guid, return the name associated or raise an Exception
|
|
"""
|
|
if ClassNameSize is None:
|
|
ClassNameSize = ctypes.sizeof(ClassName)
|
|
return SetupDiClassNameFromGuidW.ctypes_function(ClassGuid, ClassName, ClassNameSize, RequiredSize)
|
|
|
|
|
|
@SetupApiProxy(error_check=result_is_handle)
|
|
def SetupDiGetClassDevsA(Guid, Enumerator=None, hwndParent=None, Flags=0):
|
|
"""
|
|
Given a class GUID, return a HANDLE to the device's information set or raise an Exception
|
|
"""
|
|
return SetupDiGetClassDevsA.ctypes_function(Guid, Enumerator, hwndParent, Flags)
|
|
|
|
@SetupApiProxy(error_check=result_is_handle)
|
|
def SetupDiGetClassDevsW(Guid, Enumerator=None, hwndParent=None, Flags=0):
|
|
"""
|
|
Given a class GUID, return a HANDLE to the device's information set or raise an Exception
|
|
"""
|
|
return SetupDiGetClassDevsW.ctypes_function(Guid, Enumerator, hwndParent, Flags)
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData):
|
|
"""
|
|
Given a device information set, return the info associated with the index
|
|
or raise ERROR_NO_MORE_ITEMS if there is none anymore.
|
|
"""
|
|
return SetupDiEnumDeviceInfo.ctypes_function(DeviceInfoSet, MemberIndex, DeviceInfoData)
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiEnumDeviceInterfaces(DeviceInfoSet, DeviceInfoData, InterfaceClassGuid, MemberIndex, DeviceInterfaceData):
|
|
return SetupDiEnumDeviceInterfaces.ctypes_function(DeviceInfoSet, DeviceInfoData, InterfaceClassGuid, MemberIndex, DeviceInterfaceData)
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize):
|
|
return SetupDiGetDeviceRegistryPropertyA.ctypes_function(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize):
|
|
return SetupDiGetDeviceRegistryPropertyW.ctypes_function(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
|
|
|
|
|
|
|
|
|
|
@SetupApiProxy()
|
|
def SetupDiDestroyDeviceInfoList(hDevInfo):
|
|
return SetupDiDestroyDeviceInfoList.ctypes_function(hDevInfo) |