📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Target Specific - General  >>  Windows Memory Protection

Topic created on: February 16, 2010 08:22 CST by tshadowh .

Hello,

I'm trying to protect my process against ReadProcessMemory(),OpenProcess() for the last 5 days I'm still working on it but no success 'til now..

Have any of you guyz experienced with this kind of protection?

  GynvaelColdwind     February 16, 2010 09:14.42 CST
I don't know of any 100% reliable method.

Anyway, you can for example change the access rights to you process to Deny for Everyone access to it. OpenProcess in this case will fail, but heh, the access can be regained easily in the same way it was denied.

As for other methods... try using segments for address obfuscation (http://vxheavens.com/lib/vzo13.html).
You can also setup an exception-driven encrypted-memory accessing layer for sensitive data.

You can also globally try to hook OpenProcess() to deny access for your process on API level.

However, as stated above, any method can be successfully defeated...

  tshadowh   February 16, 2010 16:16.03 CST
Hello GynvaelColdwind,

Thanks for the answer, i'm currently trying to change process permissions but it doesn't seems to work including AdjustTokenPrivileges(), SetKernelObjectSecurity() etc..

I do not want to protect it against crackers, then not high level protection needed, could you send me some good reading about hooking and any other kind of known protecion? Perhaps i'm checking out the addrs obfuscation thanks again.

> GynvaelColdwind: I don\'t know of any 100% reliable method.
>
> Anyway, you can for example change the access rights to you process to Deny for Everyone access to it. OpenProcess in this case will fail, but heh, the access can be regained easily in the same way it was denied.
>
> As for other methods... try using segments for address obfuscation (http://vxheavens.com/lib/vzo13.html).
> You can also setup an exception-driven encrypted-memory accessing layer for sensitive data.
>
> You can also globally try to hook OpenProcess() to deny access for your process on API level.
>
> However, as stated above, any method can be successfully defeated...

  GynvaelColdwind     February 17, 2010 02:27.40 CST
As for the 'Deny for Everyone' I was referring to earlier, I have the following code in my repository (I'm not sure who is the author of the code... I found it on the net or it was sent to me or something...):

#define _WIN32_WINNT 0x600
#include <tchar.h>
#include <windows.h>
#include <sddl.h>
#include <stdio.h>
static bool AdjustSingleTokenPrivilege(HANDLE TokenHandle, LPCTSTR lpName, DWORD dwAttributes)
{
   TOKEN_PRIVILEGES tp;
   tp.PrivilegeCount = 1;
   tp.Privileges[0].Attributes = dwAttributes;
   if (!LookupPrivilegeValue(NULL, lpName, &(tp.Privileges[0].Luid)))
      return false;
   if (!AdjustTokenPrivileges(TokenHandle, FALSE, &tp, 0, NULL, NULL))
      return false;
   return true;
}
bool EnableDebugPrivileges(DWORD dwPID)
{
   if (!dwPID)
      dwPID = GetCurrentProcessId();
   HANDLE hProcess = NULL;
   if ((hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwPID)) == INVALID_HANDLE_VALUE)
      return false;
   HANDLE hToken = NULL;
   if (!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
      return false;
   if (!AdjustSingleTokenPrivilege(hToken, SE_SECURITY_NAME, SE_PRIVILEGE_ENABLED) ||
      !AdjustSingleTokenPrivilege(hToken, SE_DEBUG_NAME, SE_PRIVILEGE_ENABLED))
      return false;
   CloseHandle(hToken);
   CloseHandle(hProcess);
   return true;
}
bool DisableDebugPrivileges(DWORD dwPID)
{
   if (!dwPID)
      dwPID = GetCurrentProcessId();
   HANDLE hProcess = NULL;
   if ((hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwPID)) == INVALID_HANDLE_VALUE)
      return false;
   HANDLE hToken = NULL;
   if (!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
      return false;
   if (!AdjustSingleTokenPrivilege(hToken, SE_SECURITY_NAME, SE_PRIVILEGE_REMOVED) ||
      !AdjustSingleTokenPrivilege(hToken, SE_DEBUG_NAME, SE_PRIVILEGE_REMOVED))
      return false;
   CloseHandle(hToken);
   CloseHandle(hProcess);
   return true;
}
BOOL ProtectProcess(HANDLE hProcess)
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;
     // DACL for your application.
     TCHAR * szSD = TEXT("D:")       // Discretionary ACL
        TEXT("(OD;;GAGWGRGX;;;S-1-1-0)")  ;   // Deny access to
if (!ConvertStringSecurityDescriptorToSecurityDescriptor(szSD, SDDL_REVISION_1, &(sa.lpSecurityDescriptor), NULL))
return FALSE;
if (!SetKernelObjectSecurity(GetCurrentProcess(), DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor))
return FALSE;
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
EnableDebugPrivileges(GetCurrentProcessId());
ProtectProcess(GetCurrentProcess());
while(1)
{
  Sleep(1000);
}
return 0;
}


As for the papers about the other things I referred to, I'm afraid I don't have any :( These were just a couple of ideas I recall / thought of. Not sure if there are any publications about them (anyone ?)

  tshadowh   February 17, 2010 09:27.54 CST
Hey GynvaelColdwind thank you again, i've been trying something simmilar and i made some changes at the code adding more seprivileges denied and even putting
DisableDebugPrivileges(GetCurrentProcessId());
ProtectProcess(GetCurrentProcess());
into loop and it's still not working, maybe CE(Cheat Engine) is changing privileges, feel free to send me any other reference, any kind of help is welcome..

edited:

the funny and strange thing is processexplorer shows all denied acces for everyone and privilege constants are ALL DISABLED by my code, take a look at the screenshot:

http://img31.imageshack.us/img31/3092/protectu.jpg

There's kinda interesting protection I found a couple of days ago , it's a new vista security feature that allows to protect an app and was bypassed by a sec researcher, it's described here:

http://www.alex-ionescu.com/?p=35

http://www.alex-ionescu.com/?p=34

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit