How to protect your process

How to protect your process...
Well, when you run it, I don't suggest terminating it, cos the effect will be the same as terminating winlogon.exe . RtlSetProcessIsCritical lets us do this.. I wonder what else ntdll.dll hidez .


#include <windows.h>
#include <stdio.h>

typedef VOID ( _stdcall *RtlSetProcessIsCritical ) (
      IN BOOLEAN     NewValue,
      OUT PBOOLEAN OldValue, // (optional)
      IN BOOLEAN   IsWinlogon );

BOOL EnablePriv(LPCSTR lpszPriv) // by Napalm
{
 HANDLE hToken;
 LUID luid;
 TOKEN_PRIVILEGES tkprivs;
 ZeroMemory(&tkprivs, sizeof(tkprivs));
 
 if(!OpenProcessToken(GetCurrentProcess(), (TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY), &hToken))
  return FALSE;
 
 if(!LookupPrivilegeValue(NULL, lpszPriv, &luid)){
  CloseHandle(hToken); return FALSE;
 }
 
 tkprivs.PrivilegeCount = 1;
 tkprivs.Privileges[0].Luid = luid;
 tkprivs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
 BOOL bRet = AdjustTokenPrivileges(hToken, FALSE, &tkprivs, sizeof(tkprivs), NULL, NULL);
 CloseHandle(hToken);
 return bRet;
}

BOOL ProtectProcess() // by _FIL73R_
{
   HANDLE hDLL;
   RtlSetProcessIsCritical fSetCritical;

   hDLL = LoadLibraryA("ntdll.dll");
   if ( hDLL != NULL )
   {
 EnablePriv(SE_DEBUG_NAME);
   (fSetCritical) = (RtlSetProcessIsCritical) GetProcAddress( (HINSTANCE)hDLL, "RtlSetProcessIsCritical" );
    if(!fSetCritical) return 0;
    fSetCritical(1,0,0);
 return 1;
   } else
    return 0;
}

int main (void)
{
ProtectProcess();
   while(1)
   {
 // do your virus thingy
   }
return 0;
}

posted on 2011-03-08 21:40 挑灯看剑 阅读(410) 评论(0)  编辑 收藏 引用 所属分类: C/C++

只有注册用户登录后才能发表评论。
<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

公告

【自我介绍】 08年南开大学硕士毕业 最近关注:算法、Linux、c++、高并发 爱好:滑旱冰、打乒乓球、台球、保龄球

常用链接

随笔分类(139)

文章分类

我常去的网站

技术博客(都是大牛)

技术站点

搜索

积分与排名