如何让我的程序在"任务管理器"的进程中看不到(有点难啊..........)(157分)

  • 主题发起人 主题发起人 dafu2
  • 开始时间 开始时间
D

dafu2

Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个程序,不希望别人&quot;停止&quot;或&quot;删除&quot;.<br>比如在&quot;任务管理器&quot;中看不到程序的进程,<br>即使用户找到该程序文件,也不让删除.
 
帮帮我啊,各位大哥........
 
考不考虑用ShellExecuteHook
 
to luzhouman:<br><br> &nbsp; ShellExecuteHook 是咋搞的啊?<br>发个DEMO,或则贴点代码让我学习学习吧!
 
baidu 上搜索一下ShellExecuteHook, 很多
 
有没有简单一点的,看得有点晕啊<br><br>Email:gxhuangna@126.com
 
在你的程序里调用下面单元文件的函数就可以隐藏你的进程。<br><br><br>unit HideProcess;<br><br>interface<br><br>function MyHideProcess: Boolean;<br><br>implementation<br><br>uses<br> &nbsp;Windows, SysUtils, Variants, Classes, AclAPI, accCtrl;<br><br>type<br> &nbsp;NTSTATUS = LongInt;<br><br>const<br> &nbsp;//NT_SUCCESS(Status) ((NTSTATUS)(Status) &gt;= 0)<br> &nbsp;STATUS_INFO_LENGTH_MISMATCH = NTSTATUS($C0000004);<br> &nbsp;STATUS_ACCESS_DENIED = NTSTATUS($C0000022);<br> &nbsp;OBJ_INHERIT = $00000002;<br> &nbsp;OBJ_PERMANENT = $00000010;<br> &nbsp;OBJ_EXCLUSIVE = $00000020;<br> &nbsp;OBJ_CASE_INSENSITIVE = $00000040;<br> &nbsp;OBJ_OPENIF = $00000080;<br> &nbsp;OBJ_OPENLINK = $00000100;<br> &nbsp;OBJ_KERNEL_HANDLE = $00000200;<br> &nbsp;OBJ_VALID_ATTRIBUTES = $000003F2;<br><br>type<br> &nbsp;PIO_STATUS_BLOCK = ^IO_STATUS_BLOCK;<br> &nbsp;IO_STATUS_BLOCK = record<br> &nbsp; &nbsp;Status: NTSTATUS;<br> &nbsp; &nbsp;FObject: DWORD;<br> &nbsp;end;<br><br> &nbsp;PUNICODE_STRING = ^UNICODE_STRING;<br> &nbsp;UNICODE_STRING = record<br> &nbsp; &nbsp;Length: Word;<br> &nbsp; &nbsp;MaximumLength: Word;<br> &nbsp; &nbsp;Buffer: PWideChar;<br> &nbsp;end;<br><br> &nbsp;POBJECT_ATTRIBUTES = ^OBJECT_ATTRIBUTES;<br> &nbsp;OBJECT_ATTRIBUTES = record<br> &nbsp; &nbsp;Length: DWORD;<br> &nbsp; &nbsp;RootDirectory: Pointer;<br> &nbsp; &nbsp;ObjectName: PUNICODE_STRING;<br> &nbsp; &nbsp;Attributes: DWORD;<br> &nbsp; &nbsp;SecurityDescriptor: Pointer;<br> &nbsp; &nbsp;SecurityQualityOfService: Pointer;<br> &nbsp;end;<br><br> &nbsp;TZwOpenSection = function(SectionHandle: PHandle;<br> &nbsp; &nbsp;DesiredAccess: ACCESS_MASK;<br> &nbsp; &nbsp;ObjectAttributes: POBJECT_ATTRIBUTES): NTSTATUS; stdcall;<br> &nbsp;TRTLINITUNICODESTRING = procedure(DestinationString: PUNICODE_STRING;<br> &nbsp; &nbsp;SourceString: PWideChar); stdcall;<br><br>var<br> &nbsp;RtlInitUnicodeString: TRTLINITUNICODESTRING = nil;<br> &nbsp;ZwOpenSection: TZwOpenSection = nil;<br> &nbsp;g_hNtDLL: THandle = 0;<br> &nbsp;g_pMapPhysicalMemory: Pointer = nil;<br> &nbsp;g_hMPM: THandle = 0;<br> &nbsp;g_hMPM2: THandle = 0;<br> &nbsp;g_osvi: OSVERSIONINFO;<br> &nbsp;b_hide: Boolean = false;<br>//---------------------------------------------------------------------------<br><br>function InitNTDLL: Boolean;<br>begin<br> &nbsp;g_hNtDLL := LoadLibrary('ntdll.dll');<br><br> &nbsp;if 0 = g_hNtDLL then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := false;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;RtlInitUnicodeString := GetProcAddress(g_hNtDLL, 'RtlInitUnicodeString');<br> &nbsp;ZwOpenSection := GetProcAddress(g_hNtDLL, 'ZwOpenSection');<br><br> &nbsp;Result := True;<br>end;<br>//---------------------------------------------------------------------------<br><br>procedure CloseNTDLL;<br>begin<br> &nbsp;if (0 &lt;&gt; g_hNtDLL) then<br> &nbsp; &nbsp;FreeLibrary(g_hNtDLL);<br> &nbsp;g_hNtDLL := 0;<br>end;<br>//---------------------------------------------------------------------------<br><br>procedure SetPhyscialMemorySectionCanBeWrited(hSection: THandle);<br>var<br> &nbsp;pDacl: PACL;<br> &nbsp;pSD: PPSECURITY_DESCRIPTOR;<br> &nbsp;pNewDacl: PACL;<br> &nbsp;dwRes: DWORD;<br> &nbsp;ea: EXPLICIT_ACCESS;<br>begin<br> &nbsp;pDacl := nil;<br> &nbsp;pSD := nil;<br> &nbsp;pNewDacl := nil;<br><br> &nbsp;dwRes := GetSecurityInfo(hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, pDacl, nil, pSD);<br><br> &nbsp;if ERROR_SUCCESS &lt;&gt; dwRes then<br> &nbsp;begin<br> &nbsp; &nbsp;if Assigned(pSD) then<br> &nbsp; &nbsp; &nbsp;LocalFree(Hlocal(pSD^));<br> &nbsp; &nbsp;if Assigned(pNewDacl) then<br> &nbsp; &nbsp; &nbsp;LocalFree(HLocal(pNewDacl));<br> &nbsp;end;<br><br> &nbsp;ZeroMemory(@ea, sizeof(EXPLICIT_ACCESS));<br> &nbsp;ea.grfAccessPermissions := SECTION_MAP_WRITE;<br> &nbsp;ea.grfAccessMode := GRANT_ACCESS;<br> &nbsp;ea.grfInheritance := NO_INHERITANCE;<br> &nbsp;ea.Trustee.TrusteeForm := TRUSTEE_IS_NAME;<br> &nbsp;ea.Trustee.TrusteeType := TRUSTEE_IS_USER;<br> &nbsp;ea.Trustee.ptstrName := 'CURRENT_USER';<br><br> &nbsp;dwRes := SetEntriesInAcl(1, @ea, pDacl, pNewDacl);<br><br> &nbsp;if ERROR_SUCCESS &lt;&gt; dwRes then<br> &nbsp;begin<br> &nbsp; &nbsp;if Assigned(pSD) then<br> &nbsp; &nbsp; &nbsp;LocalFree(Hlocal(pSD^));<br> &nbsp; &nbsp;if Assigned(pNewDacl) then<br> &nbsp; &nbsp; &nbsp;LocalFree(HLocal(pNewDacl));<br> &nbsp;end;<br><br> &nbsp;dwRes := SetSecurityInfo<br><br> &nbsp;(hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, pNewDacl, nil);<br><br> &nbsp;if ERROR_SUCCESS &lt;&gt; dwRes then<br> &nbsp;begin<br> &nbsp; &nbsp;if Assigned(pSD) then<br> &nbsp; &nbsp; &nbsp;LocalFree(Hlocal(pSD^));<br> &nbsp; &nbsp;if Assigned(pNewDacl) then<br> &nbsp; &nbsp; &nbsp;LocalFree(HLocal(pNewDacl));<br> &nbsp;end;<br><br>end;<br>//---------------------------------------------------------------------------<br><br>function OpenPhysicalMemory: THandle;<br>var<br> &nbsp;status: NTSTATUS;<br> &nbsp;physmemString: UNICODE_STRING;<br> &nbsp;attributes: OBJECT_ATTRIBUTES;<br> &nbsp;PhyDirectory: DWORD;<br>begin<br> &nbsp;g_osvi.dwOSVersionInfoSize := sizeof(OSVERSIONINFO);<br> &nbsp;GetVersionEx(g_osvi);<br><br> &nbsp;if (5 &lt;&gt; g_osvi.dwMajorVersion) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;case g_osvi.dwMinorVersion of<br> &nbsp; &nbsp;0: PhyDirectory := $30000;<br> &nbsp; &nbsp;1: PhyDirectory := $39000;<br> &nbsp;else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br><br> &nbsp;RtlInitUnicodeString(@physmemString, '/Device/PhysicalMemory');<br><br> &nbsp;attributes.Length := SizeOf(OBJECT_ATTRIBUTES);<br> &nbsp;attributes.RootDirectory := nil;<br> &nbsp;attributes.ObjectName := @physmemString;<br> &nbsp;attributes.Attributes := 0;<br> &nbsp;attributes.SecurityDescriptor := nil;<br> &nbsp;attributes.SecurityQualityOfService := nil;<br><br> &nbsp;status := ZwOpenSection(@g_hMPM, SECTION_MAP_READ or SECTION_MAP_WRITE, @attributes);<br><br> &nbsp;if (status = STATUS_ACCESS_DENIED) then<br> &nbsp;begin<br> &nbsp; &nbsp;ZwOpenSection(@g_hMPM, READ_CONTROL or WRITE_DAC, @attributes);<br> &nbsp; &nbsp;SetPhyscialMemorySectionCanBeWrited(g_hMPM);<br> &nbsp; &nbsp;CloseHandle(g_hMPM);<br><br> &nbsp; &nbsp;status := ZwOpenSection(@g_hMPM, SECTION_MAP_READ or SECTION_MAP_WRITE, @attributes);<br> &nbsp;end;<br><br> &nbsp;if not (LongInt(status) &gt;= 0) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;g_pMapPhysicalMemory := MapViewOfFile(g_hMPM,<br> &nbsp; &nbsp;FILE_MAP_READ or FILE_MAP_WRITE, 0, PhyDirectory, $1000);<br><br> &nbsp;if (g_pMapPhysicalMemory = nil) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;Result := g_hMPM;<br>end;<br>//---------------------------------------------------------------------------<br><br>function LinearToPhys(BaseAddress: PULONG; addr: Pointer): Pointer;<br>var<br> &nbsp;VAddr, PGDE, PTE, PAddr, tmp: DWORD;<br>begin<br> &nbsp;VAddr := DWORD(addr);<br>// &nbsp;PGDE := BaseAddress[VAddr shr 22];<br> &nbsp;PGDE := PULONG(DWORD(BaseAddress) + (VAddr shr 22) * SizeOf(ULONG))^; // Modify by dot.<br><br> &nbsp;if 0 = (PGDE and 1) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := nil;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;tmp := PGDE and $00000080;<br><br> &nbsp;if (0 &lt;&gt; tmp) then<br> &nbsp;begin<br> &nbsp; &nbsp;PAddr := (PGDE and $FFC00000) + (VAddr and $003FFFFF);<br> &nbsp;end<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;PGDE := DWORD(MapViewOfFile(g_hMPM, 4, 0, PGDE and $FFFFF000, $1000));<br>// &nbsp; &nbsp;PTE := (PDWORD(PGDE))[(VAddr and $003FF000) shr 12];<br> &nbsp; &nbsp;PTE := PDWORD(PGDE + ((VAddr and $003FF000) shr 12) * SizeOf(DWord))^; // Modify by dot.<br><br> &nbsp; &nbsp;if (0 = (PTE and 1)) then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Result := nil;<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;PAddr := (PTE and $FFFFF000) + (VAddr and $00000FFF);<br> &nbsp; &nbsp;UnmapViewOfFile(Pointer(PGDE));<br> &nbsp;end;<br><br> &nbsp;Result := Pointer(PAddr);<br>end;<br>//---------------------------------------------------------------------------<br><br>function GetData(addr: Pointer): DWORD;<br>var<br> &nbsp;phys, ret: DWORD;<br> &nbsp;tmp: PDWORD;<br>begin<br> &nbsp;phys := ULONG(LinearToPhys(g_pMapPhysicalMemory, Pointer(addr)));<br> &nbsp;tmp := PDWORD(MapViewOfFile(g_hMPM, FILE_MAP_READ or FILE_MAP_WRITE, 0,<br> &nbsp; &nbsp;phys and $FFFFF000, $1000));<br><br> &nbsp;if (nil = tmp) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br>// &nbsp;ret := tmp[(phys and $FFF) shr 2];<br> &nbsp;ret := PDWORD(DWORD(tmp) + ((phys and $FFF) shr 2) * SizeOf(DWord))^; // Modify by dot.<br> &nbsp;UnmapViewOfFile(tmp);<br><br> &nbsp;Result := ret;<br>end;<br>//---------------------------------------------------------------------------<br><br>function SetData(addr: Pointer; data: DWORD): Boolean;<br>var<br> &nbsp;phys: DWORD;<br> &nbsp;tmp: PDWORD;<br>begin<br> &nbsp;phys := ULONG(LinearToPhys(g_pMapPhysicalMemory, Pointer(addr)));<br> &nbsp;tmp := PDWORD(MapViewOfFile(g_hMPM, FILE_MAP_WRITE, 0, phys and $FFFFF000, $1000));<br><br> &nbsp;if (nil = tmp) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := false;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br>// &nbsp;tmp[(phys and $FFF) shr 2] := data;<br> &nbsp;PDWORD(DWORD(tmp) + ((phys and $FFF) shr 2) * SizeOf(DWord))^ := data; // Modify by dot.<br> &nbsp;UnmapViewOfFile(tmp);<br><br> &nbsp;Result := TRUE;<br>end;<br>//---------------------------------------------------------------------------<br>{long __stdcall exeception(struct _EXCEPTION_POINTERS *tmp)<br>begin<br> ExitProcess(0);<br> return 1 ;<br>end }<br>//---------------------------------------------------------------------------<br><br>function YHideProcess: Boolean;<br>var<br> &nbsp;thread, process: DWORD;<br> &nbsp;fw, bw: DWORD;<br>begin<br>// &nbsp;SetUnhandledExceptionFilter(exeception);<br> &nbsp;if (FALSE = InitNTDLL) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := FALSE;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;if (0 = OpenPhysicalMemory) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := FALSE;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br> &nbsp;thread := GetData(Pointer($FFDFF124)); //kteb<br> &nbsp;process := GetData(Pointer(thread + $44)); //kpeb<br><br> &nbsp;if (0 = g_osvi.dwMinorVersion) then<br> &nbsp;begin<br> &nbsp; &nbsp;fw := GetData(Pointer(process + $A0));<br> &nbsp; &nbsp;bw := GetData(Pointer(process + $A4));<br><br> &nbsp; &nbsp;SetData(Pointer(fw + 4), bw);<br> &nbsp; &nbsp;SetData(Pointer(bw), fw);<br><br> &nbsp; &nbsp;Result := TRUE;<br> &nbsp;end<br> &nbsp;else if (1 = g_osvi.dwMinorVersion) then<br> &nbsp;begin<br> &nbsp; &nbsp;fw := GetData(Pointer(process + $88));<br> &nbsp; &nbsp;bw := GetData(Pointer(process + $8C));<br><br> &nbsp; &nbsp;SetData(Pointer(fw + 4), bw);<br> &nbsp; &nbsp;SetData(Pointer(bw), fw);<br><br> &nbsp; &nbsp;Result := TRUE;<br> &nbsp;end<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;Result := False;<br> &nbsp;end;<br><br> &nbsp;CloseHandle(g_hMPM);<br> &nbsp;CloseNTDLL;<br>end;<br><br>function MyHideProcess: Boolean;<br>begin<br> &nbsp;if not b_hide then<br> &nbsp;begin<br> &nbsp; &nbsp;b_hide := YHideProcess;<br> &nbsp;end;<br><br> &nbsp;Result := b_hide;<br>end;<br><br>end.
 
标记一下!<br>呵呵!<br>我只知道用DDK来做呵呵!
 
大唐电信 你的做法在64位的机器上还是可以看的到进程的
 
大唐电信:<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;MyHideProcess;<br>end;<br><br>还是隐藏不了啊!(TForm1.show一样不行啊)
 
to 精灵猪<br>你说的是64位的操作系统吧,这个我没试过。但64位的CPU是可以的,我用就是64位的AMD。<br>to dafu2<br>楼主你在试试,应该是可以的,我用的没问题,在任务管理器的进程里找不到的。
 
上面的方法行不行呀
 
怎么不行啊?我的系统是2000,调用了MyHideProcess还是没有隐藏。
 
我正和你的要求正相反,我的程序有时就自动在任务管理器里消失了(程序还在正常运行),真是莫名其妙,我还在为这个发愁呢!
 
我也试了一下,调用了MyHideProcess没有隐藏。winxp+sp2, delphi2006<br><br>这里出了问题:<br>status := ZwOpenSection(@g_hMPM, SECTION_MAP_READ or SECTION_MAP_WRITE, @attributes);<br><br> &nbsp;if (status = STATUS_ACCESS_DENIED) then<br> &nbsp;begin<br> &nbsp; &nbsp;ZwOpenSection(@g_hMPM, READ_CONTROL or WRITE_DAC, @attributes);<br> &nbsp; &nbsp;SetPhyscialMemorySectionCanBeWrited(g_hMPM);<br> &nbsp; &nbsp;CloseHandle(g_hMPM);<br><br> &nbsp; &nbsp;status := ZwOpenSection(@g_hMPM, SECTION_MAP_READ or SECTION_MAP_WRITE, @attributes);<br> &nbsp;end;<br><br> &nbsp;if not (LongInt(status) &gt;= 0) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br><br>status是个负数,就退出了
 
看来这个问题还是有价值,等问题解决的再揭贴!
 
引用以前的贴:<br>使用<br>RegisterServiceProcess(ProcessID:Long,Type:Long)函数<br><br>该函数存在于Kernel32.dll中.<br><br>function RegisterServiceProcess(a:longint;const b:longint):dword;stdcall;far;external 'Kernel32.dll' name 'RegisterServiceProcess';<br><br>ddd:=GetCurrentProcessId;<br>if (RegisterServiceProcess(ddd,1)=0) then <br> showmessage('error!');<br><br>用未公开函数RegisterServiceProcess<br>#define RSP_SIMPLE_SERVICE 1<br>#define RSP_UNREGISTER_SERVICE 0<br><br>//下面代码为隐藏<br>DWORD dwID,redserv;<br>dwID = GetCurrentProcessId();<br>regserv = RegisterServiceProcess(pid,RSP_SIMPLE_SERVICE);<br>//恢复隐藏<br>dwID= GetCurrentProcessId()<br>regserv = RegisterServiceProcess(pid,RSP_UNREGISTER_SERVICE);
 
哈哈,楼上大唐电信的兄弟那段代码好熟啊,应该标明一下出处比较好,毕竟dot兄辛苦的从VC里改过来嘛<br><br>上面那段代码是可行的,支持win2k、xp,但听说2003不支持,我没环境测,全部源码可以到这下载<br><br>http://3500.tomore.com
 
影藏进程方式很多,可以参考插件技术.<br>通过系统服务启动比如(rundll32.exe,svchost.exe)等等.<br>我有现成的DEMO,发给你.请查收!
 
多人接受答案了。
 
后退
顶部