Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
Posted: Sat Feb 06, 2010 9:44 am Post subject: VirtualProtect
I'm working on some code to help secure released .NET applications against disassembly. I'm already using smartassembly for obfuscation and modification protection. I've also implemented tests to make sure the binary is signed, as well as checks using RSA to make sure that the binary remains unmodified.
What I want to do is implement some (albeit primitive) protection routines to make it a little harder for casual debuggers to crack. I've read good things about VirtualProtect, but can't find any samples that would protect the code region of the process in-memory. For a start, I don't know how to find the pointer to the start of the code section, let alone how to identify a code section at runtime.
Another question: would calling IsDebuggerPresent work at all with a .NET process? I know it can be patched simply using something like OllyDbg, but it's another thing for the person to think about. _________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
Posted: Sat Feb 06, 2010 4:04 pm Post subject:
I know how to call the API, just not how to determine the address I want to protect. I want to run VirtualProtect all the way over my code section in-memory so that modifications are made more difficult. _________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
use virtualquery() to find your regions, if your looking for MEM_PRIVATE pages, you can specify that and protect those addies.
example
Code:
MEMORY_BASIC_INFORMATION mbi;
DWORD min = 0x00400000;
DWORD max = 0x7FFFFFFF;
SIZE_T s;
DWORD old;
for (DWORD i = min; i <= max; i++)
{
s = VirtualQuery((LPCVOID) i, &mbi, sizeof(mbi));
if (mbi.Type == MEM_PRIVATE)
{
VirtualProtect(i, 4, PAGE_EXECUTE_READWRITE, &old);
}
else
{
i = (DWORD) (mbi.BaseAddress + mbi.RegionSize) // get out of the region if its not a private one
}
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum