Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit aae81dd

Browse files
Matt GraeberMatt Graeber
Matt Graeber
authored and
Matt Graeber
committed
Adding -DoNotZeroMZ for testing
1 parent 992f980 commit aae81dd

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

CodeExecution/Invoke-ReflectivePEInjection.ps1

+14-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Optional, the process ID of the remote process to inject the DLL in to. If not i
6262
Optional, will force the use of ASLR on the PE being loaded even if the PE indicates it doesn't support ASLR. Some PE's will work with ASLR even
6363
if the compiler flags don't indicate they support it. Other PE's will simply crash. Make sure to test this prior to using. Has no effect when
6464
loading in to a remote process.
65+
66+
.PARAMETER DoNotZeroMZ
67+
68+
Optional, will not wipe the MZ from the first two bytes of the PE. This is to be used primarily for testing purposes and to enable loading the same PE with Invoke-ReflectivePEInjection more than once.
6569
6670
.EXAMPLE
6771
@@ -187,7 +191,10 @@ Param(
187191
$ProcName,
188192

189193
[Switch]
190-
$ForceASLR
194+
$ForceASLR,
195+
196+
[Switch]
197+
$DoNotZeroMZ
191198
)
192199

193200
Set-StrictMode -Version 2
@@ -2875,10 +2882,12 @@ Function Main
28752882
throw 'PE is not a valid PE file.'
28762883
}
28772884

2878-
# Remove 'MZ' from the PE file so that it cannot be detected by .imgscan in WinDbg
2879-
# TODO: Investigate how much of the header can be destroyed, I'd imagine most of it can be.
2880-
$PEBytes[0] = 0
2881-
$PEBytes[1] = 0
2885+
if (-not $DoNotZeroMZ) {
2886+
# Remove 'MZ' from the PE file so that it cannot be detected by .imgscan in WinDbg
2887+
# TODO: Investigate how much of the header can be destroyed, I'd imagine most of it can be.
2888+
$PEBytes[0] = 0
2889+
$PEBytes[1] = 0
2890+
}
28822891

28832892
#Add a "program name" to exeargs, just so the string looks as normal as possible (real args start indexing at 1)
28842893
if ($ExeArgs -ne $null -and $ExeArgs -ne '')

0 commit comments

Comments
 (0)