当前位置: 首页 > news >正文

【转】MFC隐藏进程自身(任务管理器不可见,wSysCheck等工具可见)

只要把cpp和h加入工程,include就可以了。

代码地址:

//------------------HideProcess.h--------------------

//加入MFC工程调用即可
BOOL HideProcess();

 

//------------------HideProcess.cpp------------------

#include "stdafx.h"
#include<windows.h>
#include<Accctrl.h>
#include<Aclapi.h>
#include"HideProcess.h"

#define NT_SUCCESS(Status)((NTSTATUS)(Status) >= 0)
#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L)

typedef LONG NTSTATUS;

typedef struct _IO_STATUS_BLOCK 
{
    NTSTATUS Status;
    ULONG Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;

typedef struct _UNICODE_STRING 
{
    USHORT Length;
    USHORT MaximumLength;
    PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;

#define OBJ_INHERIT				0x00000002L
#define OBJ_PERMANENT			0x00000010L
#define OBJ_EXCLUSIVE			0x00000020L
#define OBJ_CASE_INSENSITIVE	0x00000040L
#define OBJ_OPENIF				0x00000080L
#define OBJ_OPENLINK			0x00000100L
#define OBJ_KERNEL_HANDLE		0x00000200L
#define OBJ_VALID_ATTRIBUTES	0x000003F2L

typedef struct _OBJECT_ATTRIBUTES 
{
    ULONG Length;
    HANDLE RootDirectory;
    PUNICODE_STRING ObjectName;
    ULONG Attributes;
    PVOID SecurityDescriptor;
    PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;

typedef NTSTATUS (CALLBACK* ZWOPENSECTION)(
    OUT PHANDLE SectionHandle,
    IN ACCESS_MASK DesiredAccess,
    IN POBJECT_ATTRIBUTES ObjectAttributes
    );

typedef VOID (CALLBACK* RTLINITUNICODESTRING)(
    IN OUT PUNICODE_STRING DestinationString,
    IN PCWSTR SourceString
    );

RTLINITUNICODESTRING RtlInitUnicodeString;
ZWOPENSECTION ZwOpenSection;
HMODULE g_hNtDLL = NULL;
PVOID g_pMapPhysicalMemory = NULL;
HANDLE g_hMPM = NULL;
OSVERSIONINFO g_osvi;

//---------------------------------------------------------------------------
BOOL InitNTDLL()
{
    g_hNtDLL = LoadLibrary("ntdll.dll");

    if (NULL == g_hNtDLL)
        return FALSE;

    RtlInitUnicodeString = (RTLINITUNICODESTRING)GetProcAddress(g_hNtDLL, "RtlInitUnicodeString");
    ZwOpenSection = (ZWOPENSECTION)GetProcAddress(g_hNtDLL, "ZwOpenSection");

    return TRUE;
}

//---------------------------------------------------------------------------
VOID CloseNTDLL()
{
    if(NULL != g_hNtDLL)
	{
        FreeLibrary(g_hNtDLL);
	}

    g_hNtDLL = NULL;
}
//---------------------------------------------------------------------------
VOID SetPhyscialMemorySectionCanBeWrited(HANDLE hSection) 
{ 
    PACL pDacl = NULL; 
    PSECURITY_DESCRIPTOR pSD = NULL; 
    PACL pNewDacl = NULL; 
    
    DWORD dwRes = GetSecurityInfo(hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION,
								NULL, NULL, &pDacl, NULL, &pSD);
    if(ERROR_SUCCESS != dwRes)
    {
		if(pSD) 
		{
			LocalFree(pSD); 
		}
		
		if(pNewDacl)
		{
			LocalFree(pNewDacl); 
		}
    }

    EXPLICIT_ACCESS ea; 
    RtlZeroMemory(&ea, sizeof(EXPLICIT_ACCESS)); 
    ea.grfAccessPermissions = SECTION_MAP_WRITE; 
    ea.grfAccessMode = GRANT_ACCESS; 
    ea.grfInheritance = NO_INHERITANCE; 
    ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME; 
    ea.Trustee.TrusteeType = TRUSTEE_IS_USER; 
    ea.Trustee.ptstrName = "CURRENT_USER";

    dwRes = SetEntriesInAcl(1, &ea, pDacl, &pNewDacl);
    
    if(ERROR_SUCCESS != dwRes)
    {
		if(pSD)
		{
			LocalFree(pSD); 
		}
		if(pNewDacl) 
		{
			LocalFree(pNewDacl); 
		}
    }
    dwRes = SetSecurityInfo(hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, pNewDacl, NULL);
    
    if(ERROR_SUCCESS != dwRes)
    {
		if(pSD) 
		{
			LocalFree(pSD); 
		}
		if(pNewDacl) 
		{
			LocalFree(pNewDacl); 
		}
    }
} 

//---------------------------------------------------------------------------
HANDLE OpenPhysicalMemory()
{
    NTSTATUS status;
    UNICODE_STRING physmemString;
    OBJECT_ATTRIBUTES attributes;
    ULONG PhyDirectory;

    g_osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx (&g_osvi);

    if (5 != g_osvi.dwMajorVersion)
	{
        return NULL;
	}

    switch(g_osvi.dwMinorVersion)
    {
        case 0:
            PhyDirectory = 0x30000;
            break; //2k
        case 1:
            PhyDirectory = 0x39000;
            break; //xp
        default:
            return NULL;
    }

    RtlInitUnicodeString(&physmemString, L"\\Device\\PhysicalMemory");

    attributes.Length = sizeof(OBJECT_ATTRIBUTES);
    attributes.RootDirectory = NULL;
    attributes.ObjectName = &physmemString;
    attributes.Attributes = 0;
    attributes.SecurityDescriptor = NULL;
    attributes.SecurityQualityOfService = NULL;

    status = ZwOpenSection(&g_hMPM, SECTION_MAP_READ|SECTION_MAP_WRITE, &attributes);

    if(status == STATUS_ACCESS_DENIED)
    { 
        status = ZwOpenSection(&g_hMPM, READ_CONTROL|WRITE_DAC, &attributes); 
        SetPhyscialMemorySectionCanBeWrited(g_hMPM); 
        CloseHandle(g_hMPM);
        status = ZwOpenSection(&g_hMPM, SECTION_MAP_READ|SECTION_MAP_WRITE, &attributes); 
    }

    if(!NT_SUCCESS(status)) 
	{
        return NULL;
	}

    g_pMapPhysicalMemory = MapViewOfFile(g_hMPM, FILE_MAP_READ|FILE_MAP_WRITE, 0, PhyDirectory, 0x1000);

    if( g_pMapPhysicalMemory == NULL )
	{
        return NULL;
	}

    return g_hMPM;
}

//---------------------------------------------------------------------------
PVOID LinearToPhys(PULONG BaseAddress, PVOID addr)
{
    ULONG VAddr = (ULONG)addr, PGDE, PTE, PAddr;
    PGDE = BaseAddress[VAddr>>22];

    if (0 == (PGDE&1))
	{
        return 0;
	}

    ULONG tmp = PGDE & 0x00000080;

    if (0 != tmp)
    {
        PAddr = (PGDE & 0xFFC00000) + (VAddr & 0x003FFFFF);
    }
    else
    {
        PGDE = (ULONG)MapViewOfFile(g_hMPM, 4, 0, PGDE & 0xfffff000, 0x1000);
        PTE = ((PULONG)PGDE)[(VAddr&0x003FF000)>>12];
        
        if (0 == (PTE&1))
		{
            return 0;
		}

        PAddr = (PTE&0xFFFFF000)+(VAddr&0x00000FFF);
        UnmapViewOfFile((PVOID)PGDE);
    }

    return (PVOID)PAddr;
}

//---------------------------------------------------------------------------
ULONG GetData(PVOID addr)
{
    ULONG phys = (ULONG)LinearToPhys((PULONG)g_pMapPhysicalMemory, (PVOID)addr);
    PULONG tmp = (PULONG)MapViewOfFile(g_hMPM, FILE_MAP_READ|FILE_MAP_WRITE, 0, phys&0xfffff000, 0x1000);
    
    if (0 == tmp)
	{
        return 0;
	}

    ULONG ret = tmp[(phys & 0xFFF)>>2];
    UnmapViewOfFile(tmp);

    return ret;
}
//---------------------------------------------------------------------------
BOOL SetData(PVOID addr,ULONG data)
{
    ULONG phys = (ULONG)LinearToPhys((PULONG)g_pMapPhysicalMemory, (PVOID)addr);
    PULONG tmp = (PULONG)MapViewOfFile(g_hMPM, FILE_MAP_WRITE, 0, phys & 0xfffff000, 0x1000);

    if (0 == tmp)
	{
        return FALSE;
	}

    tmp[(phys & 0xFFF)>>2] = data;
    UnmapViewOfFile(tmp);

    return TRUE;
}

//---------------------------------------------------------------------------
long __stdcall exeception(struct _EXCEPTION_POINTERS *tmp)
{
   ExitProcess(0);
   return 1;
}
//---------------------------------------------------------------------------
BOOL YHideProcess()
{
//    SetUnhandledExceptionFilter(exeception);

    if (FALSE == InitNTDLL())
	{
        return FALSE;
	}

    if (0 == OpenPhysicalMemory())
	{
        return FALSE;
	}

    ULONG thread = GetData((PVOID)0xFFDFF124); //kteb
    ULONG process = GetData(PVOID(thread + 0x44)); //kpeb

    ULONG fw, bw;
    if (0 == g_osvi.dwMinorVersion)
    {
        fw = GetData(PVOID(process + 0xa0));
        bw = GetData(PVOID(process + 0xa4));        
    }

    if (1 == g_osvi.dwMinorVersion)
    {
        fw = GetData(PVOID(process + 0x88));
        bw = GetData(PVOID(process + 0x8c));
    }
        
    SetData(PVOID(fw + 4), bw);
    SetData(PVOID(bw), fw);

    CloseHandle(g_hMPM);
    CloseNTDLL();

    return TRUE;
}

BOOL HideProcess()
{
	static BOOL b_hide = false;
	if (!b_hide)
	{
		b_hide = true;
		YHideProcess();
		return TRUE;
	}
	return TRUE;
}

 

这样在Example的Example.h中加入

#include <HideProcess.h>

在xample的Example.cpp中

BOOL CExampleApp::InitInstance()

加入

HideProcess();

即可。

---------------------------------------------------------------------

这个网上找了半天,结果一开始找到的代码要么不完整,要么有错误。然后自己就改啊改,总算改好了,呵呵。

转载于:https://www.cnblogs.com/ZzzZzz/archive/2012/01/02/2310080.html

相关文章:

  • rcna
  • 如何想要在开机启动登陆时,用户名也不输入
  • 【分析总结】ASP.NET中的状态管理原理
  • 巧用单臂
  • cocos2d-x学习笔记番外篇01:地图滚动代码
  • 【hibernate系列】hibernate的n+1问题
  • 易宝php支付
  • 看不到的“因”
  • 使用WITH提高查询效率
  • css 视图结构
  • UltraEdit批量删除空行
  • border padding margin , the difference among them
  • MATLAB概率统计函数(1)
  • hoj1058 Number Triangles
  • 五、oracle 表的管理
  • 《微软的软件测试之道》成书始末、出版宣告、补充致谢名单及相关信息
  • 【划重点】MySQL技术内幕:InnoDB存储引擎
  • 【面试系列】之二:关于js原型
  • Consul Config 使用Git做版本控制的实现
  • Java IO学习笔记一
  • JavaScript设计模式之工厂模式
  • MD5加密原理解析及OC版原理实现
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • React-Native - 收藏集 - 掘金
  • SpiderData 2019年2月23日 DApp数据排行榜
  • 基于OpenResty的Lua Web框架lor0.0.2预览版发布
  • 简单数学运算程序(不定期更新)
  • 使用Envoy 作Sidecar Proxy的微服务模式-4.Prometheus的指标收集
  • 新书推荐|Windows黑客编程技术详解
  • 一份游戏开发学习路线
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 源码之下无秘密 ── 做最好的 Netty 源码分析教程
  • 06-01 点餐小程序前台界面搭建
  • 你对linux中grep命令知道多少?
  • 带你开发类似Pokemon Go的AR游戏
  • ​queue --- 一个同步的队列类​
  • $(document).ready(function(){}), $().ready(function(){})和$(function(){})三者区别
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (8)Linux使用C语言读取proc/stat等cpu使用数据
  • (C++)八皇后问题
  • (cos^2 X)的定积分,求积分 ∫sin^2(x) dx
  • (ibm)Java 语言的 XPath API
  • (MIT博士)林达华老师-概率模型与计算机视觉”
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (ZT)薛涌:谈贫说富
  • (附源码)ssm码农论坛 毕业设计 231126
  • (六)软件测试分工
  • (每日持续更新)jdk api之FileFilter基础、应用、实战
  • (每日持续更新)jdk api之FileReader基础、应用、实战
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (使用vite搭建vue3项目(vite + vue3 + vue router + pinia + element plus))
  • (算法设计与分析)第一章算法概述-习题
  • (学习日记)2024.04.10:UCOSIII第三十八节:事件实验
  • (一)ClickHouse 中的 `MaterializedMySQL` 数据库引擎的使用方法、设置、特性和限制。
  • (最完美)小米手机6X的Usb调试模式在哪里打开的流程