fix: stability and OPSEC correctness improvements#1
Open
mranv wants to merge 7 commits intoLongWayHomie:masterfrom
Open
fix: stability and OPSEC correctness improvements#1mranv wants to merge 7 commits intoLongWayHomie:masterfrom
mranv wants to merge 7 commits intoLongWayHomie:masterfrom
Conversation
…, unique RANDOM preset indices
…t PRNG Removes the stdlib.h dependency from MutationEngine.c and makes the PRNG consistent with the XORshift pattern used in Crypto.c and Common.c. Two independent PRNG states (stdlib rand + XORshift) in the same Builder process now unified under one approach.
fix: address all Son of Anubhav review findings
short notes on why each fix exists — overflow guard, xorshift swap, insertion sort rationale, trampoline RUNTIME_FUNCTION requirement, djb2 seed range, and random preset dedup. nothing structural changed.
Author
|
Hey @LongWayHomie — been going through this codebase pretty carefully over the last few days and wanted to flag this PR for your attention. The changes in here are things I noticed while trying to understand how the whole pipeline hangs together. Added inline comments to the modified files so the reasoning is easier to follow without having to cross-reference everything — should make the review less painful. Quick summary of what's in there if you don't want to read through all of it:
Nothing dramatic, just tightening things up. Would appreciate a look when you have a minute — happy to answer questions or adjust anything you're not happy with. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey, been playing with PolyEngine for a bit and found a handful of things worth fixing. Nothing earth-shattering but a couple of them could bite in production builds.
What's in here
MutationEngine.c
HeapAlloc— ifpayloadLengets large enough,maxStubSize + payloadLenwraps to a small value and the subsequentmemcpywalks off the end of the heap allocation. Not a real-world concern with normal payloads but the guard is two lines and costs nothing.HeapFree(GetProcessHeap(), 0, NULL)in the template validation error path. It's a no-op (docs say so) but it looked like cleanup that wasn't actually cleaning anything up.rand()/srand()for a local XORshift. Builder was running two independent PRNG states (stdlib + the XORshift in Crypto.c) seeded from the samerdtscwindow. Unified them.Syscalls.c
SortSyscalls()with insertion sort. ntdll's Zw* exports come out of the export table nearly sorted by RVA already, so insertion sort is basically O(n) here vs O(n²) for bubble.FindCleanTrampoline()now validates that a matched0F 05 C3site sits inside aRUNTIME_FUNCTIONentry before returning it.FindJmpRbxGadget()already enforced this — trampoline should too, otherwise an EDR stack walker starting from the syscall RIP could see a frame without unwind info.ApiHashing.cpp
DJB2_SEEDwasRandomCompileTimeSeed() % 0xFFwhich allows 0. Seed=0 gives a degenerate distribution for short strings. Changed to% 0xFE + 1(range [1,254]), matching whatXOR_SEEDin Evasion.cpp already does.OpsecFlags.h / Stub.cpp / Builder.cpp
EVASION_FLAG_UNHOOKrenamed toOPSEC_FLAG_UNHOOK. The unhooker is a loader technique, not an evasion check disable — theEVASION_FLAG_NO_*namespace is for per-check disables. Trivial rename, no behaviour change.--preset RANDOMcould pick the same DLL index for all three slots. Added a small dedup nudge so all three indices always resolve to different DLLs.Test plan
--preset RANDOMa few times — check log shows three distinct DLL indices--unhookflag still accepted and works