Files
naksyn-PythonMemoryModule/pythonmemorymodule/windows/winproxy/apis/iphlpapi.py
T
naksyn db1893910c command line support (partial) via PEB stomping
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.
2023-07-27 06:44:29 -07:00

47 lines
1.6 KiB
Python

import ctypes
import windows.generated_def as gdef
from ..apiproxy import ApiProxy, NeededParameter
from ..error import succeed_on_zero
class IphlpapiProxy(ApiProxy):
APIDLL = "iphlpapi"
default_error_check = staticmethod(succeed_on_zero)
@IphlpapiProxy()
def SetTcpEntry(pTcpRow):
return SetTcpEntry.ctypes_function(pTcpRow)
@IphlpapiProxy()
def GetExtendedTcpTable(pTcpTable, pdwSize=None, bOrder=True, ulAf=NeededParameter, TableClass=gdef.TCP_TABLE_OWNER_PID_ALL, Reserved=0):
if pdwSize is None:
pdwSize = gdef.ULONG(ctypes.sizeof(pTcpTable))
return GetExtendedTcpTable.ctypes_function(pTcpTable, pdwSize, bOrder, ulAf, TableClass, Reserved)
@IphlpapiProxy()
def GetInterfaceInfo(pIfTable, dwOutBufLen=None):
if dwOutBufLen is None:
dwOutBufLen = gdef.ULONG(ctypes.sizeof(pIfTable))
return GetInterfaceInfo.ctypes_function(pIfTable, dwOutBufLen)
@IphlpapiProxy()
def GetIfTable(pIfTable, pdwSize, bOrder=False):
return GetIfTable.ctypes_function(pIfTable, pdwSize, bOrder)
@IphlpapiProxy()
def GetIpAddrTable(pIpAddrTable, pdwSize, bOrder=False):
return GetIpAddrTable.ctypes_function(pIpAddrTable, pdwSize, bOrder)
@IphlpapiProxy()
def GetIpNetTable(IpNetTable, SizePointer, Order):
return GetIpNetTable.ctypes_function(IpNetTable, SizePointer, Order)
@IphlpapiProxy()
def GetAdaptersInfo(AdapterInfo, SizePointer):
return GetAdaptersInfo.ctypes_function(AdapterInfo, SizePointer)
@IphlpapiProxy()
def GetPerAdapterInfo(IfIndex, pPerAdapterInfo, pOutBufLen):
return GetPerAdapterInfo.ctypes_function(IfIndex, pPerAdapterInfo, pOutBufLen)