Files
naksyn-PythonMemoryModule/pythonmemorymodule/windows/crypto/dpapi.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

34 lines
1.6 KiB
Python

from windows import winproxy
import windows.generated_def as gdef
__all__ = ["protect", "unprotect"]
def protect(data, entropy=None, flags=gdef.CRYPTPROTECT_UI_FORBIDDEN):
in_blob = gdef.DATA_BLOB.from_string(data)
out_blob = gdef.DATA_BLOB()
if entropy is not None:
entropy = gdef.DATA_BLOB.from_string(entropy)
winproxy.CryptProtectData(in_blob, pOptionalEntropy=entropy, dwFlags=flags, pDataOut=out_blob)
encrypted_data = bytes(out_blob.data)
# https://docs.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata
# pDataOut: A pointer to a DATA_BLOB structure that receives the encrypted data.
# When you have finished using the DATA_BLOB structure, free its pbData member by calling the LocalFree function.
winproxy.LocalFree(out_blob.pbData)
del out_blob
return encrypted_data
def unprotect(data, entropy=None, flags=gdef.CRYPTPROTECT_UI_FORBIDDEN):
in_blob = gdef.DATA_BLOB.from_string(data)
out_blob = gdef.DATA_BLOB()
if entropy is not None:
entropy = gdef.DATA_BLOB.from_string(entropy)
winproxy.CryptUnprotectData(in_blob, pOptionalEntropy=entropy, dwFlags=flags, pDataOut=out_blob)
decrypted_data = bytes(out_blob.data)
# https://docs.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata
# pDataOut: A pointer to a DATA_BLOB structure that receives the encrypted data.
# When you have finished using the DATA_BLOB structure, free its pbData member by calling the LocalFree function.
winproxy.LocalFree(out_blob.pbData)
del out_blob
return decrypted_data