怎样让一个进程后台运行?

sharklu2000 2004-03-19 06:25:04
就是做成服务,在任务管理器里看不见的那种。
试过
typedef DWORD (FAR CALLBACK * myproc)( DWORD dwProcessId,
DWORD dwType);
myproc RegisterServiceProcess;

RegisterServiceProcess=(myproc)GetProcAddress(GetModuleHandle("KERNEL32.DLL") ,
"RegisterServiceProcess");
RegisterServiceProcess(GetCurrentProcessId(),1);

但这在Windows2000下不行。
...全文
287 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liutaoxwl 2004-03-22
  • 打赏
  • 举报
回复
做成服务程序
wyjtnt 2004-03-22
  • 打赏
  • 举报
回复
参考一下ATL服务吧,有现成的模板。
sevencat 2004-03-22
  • 打赏
  • 举报
回复
WIN2K下好像没办法隐藏进程吧。
Wolfe 2004-03-22
  • 打赏
  • 举报
回复
WIN2K下隐藏进程,可以采用远程线程潜入的方法,把一个dll潜入一个exe,这个exe可以是explorer、lsass之类的Windows必须运行的程序程序(隐藏了吧)。也可以用微软的detours库修改pe文件,使一个exe程序隐藏在另一个程序中运行
MuseIn 2004-03-21
  • 打赏
  • 举报
回复
嘿嘿。
mark了
Wolfe 2004-03-21
  • 打赏
  • 举报
回复
http://www.xinghecn.net/bbs/dispbbs.asp?boardid=9&rootid=212&id=212&skin=1
Wenxy1 2004-03-21
  • 打赏
  • 举报
回复
mark
vcforever 2004-03-21
  • 打赏
  • 举报
回复
在windows2000中隐藏进程?

参考一下:

在WinNT下"真正隐藏进程"这一说法,可以讲是根本不可能实现,只要我们的程序是以进程内核的形式运行,都是不可能逃离CTRL+ALT+DEL的法眼。那么奇怪了,这岂不是与我们的标题《WinNT & Win2K下实现进程的完全隐藏》相矛盾吗?是的,实际上应该是:以非进程方式执行目标代码,而逃避进程查看器的检查,从而达到"进程隐藏"的目的。
我们这里用的,是在宿主进程中,以线程的方式执行我们的代码。实现起来非常简单。首先,我们先建立一个不执行任何语句的线程
DWORD stdcall ThreadProc(LPVOID *lpVoid){
return 0;
}
然后,将线程代码拷备至宿主进程所能够执行的任何地方(即页面属性为PAGGE_EXECUTE_READWRITE),如:共享内存影射区、宿主进程内。这里我们选择宿主进程,拷备的时侯,我们需要先在宿主进程中使用VirtualAllocEx函数申请一段内存,然后再使用WriteProcessMemory将线程体写入宿主进程中。
以上工作完成后,我们便可CreateRemoteThread函数激活其执行。下面给出一个完整的例子
//远程线程执行体
DWORD __stdcall ThreadProc (void *lpPara){
return 0;
}
int main(int argc, char* argv[]){
const DWORD THREADSIZE=1024*4;//暂定线程体大小为4K,实际上没这么大,稍后我将会介绍
DWORD byte_write;
//获得指定进程ID句柄,并设其权限为PROCESS_ALL_ACCESS,992是宿进程的ID号,获取ID号的方法这里我就不多讲了
HANDLE hWnd = ::OpenProcess (PROCESS_ALL_ACCESS,FALSE,992);
if(!hWnd)return 0;
void *pRemoteThread =::VirtualAllocEx(hWnd,0,THREADSIZE,MEM_COMMIT| MEM_RESERVE,PAGE_EXECUTE_READWRITE);//申请
if(!pRemoteThread)return 0;
if(!::WriteProcessMemory(hWnd,pRemoteThread,&ThreadProc,THREADSIZE,0))//写入进程
return 0;
//启动线程
HANDLE hThread = ::CreateRemoteThread (hWnd ,0,0,(DWORD (__stdcall *)(void *))pRemoteThread ,NULL,0,&byte_write);
if(!hThread){ //还有内存分配未释放
return 0;
}
return 0;
}
到这里,对于隐藏的方法就算告一段落,相信看过的朋友对这个思路有个非常明确的概念了吧。

在理解隐藏的方法后,我们着重开始写线程的执行部分了。如下:
DWORD __stdcall ThreadProc(void *lpPara){
MessageBox(NULL,"hello","hello",0);
return 0;
}
编译执行后,你会发现出现一个非法操作错误,为什么呢?在我们以段页式内存管理的win2K操作系统中,编译时会把所有的常量编译在PE文件的.data节中,而代码段则在.text中,所以,我们拷备到宿主进程中的代码是在.text中的代码,MessageBox(NULL,(char *)指针,p,0);所指向的地址是本进程的内存虚拟地址。而在宿主进程中是无法访问的。解决的方法很简单,按旧照搬的将"hello"也拷备到目标进程中,然后再引用。同理,MessageBox函数地址编译时,也是保存在.Import中,写过Win2k病毒的朋友都知道,所有常量与函数入口地址都需在代码段定义与得出,我们这里也与他有点类似。言归正传,同样情况我们也把函数的入口地址一起写入目标进程中。

//先定义参数结构
typedef struct _RemotePara{//参数结构
char pMessageBox[12];
DWORD dwMessageBox;
}RemotePara;
//付值
RemotePara myRemotePara;
::ZeroMemory(&myRemotePara,sizeof(RemotePara));
HINSTANCE hUser32 = ::LoadLibrary ("user32.dll");
myRemotePara.dwMessageBox =(DWORD) ::GetProcAddress (hUser32 , "MessageBoxA");
strcat(myRemotePara.pMessageBox,"hello\0");
//写进目标进程
RemotePara *pRemotePara =(RemotePara *) ::VirtualAllocEx (hWnd ,0,sizeof(RemotePara),MEM_COMMIT,PAGE_READWRITE);//注意申请空间时的页面保护属性
if(!pRemotePara)return 0;
if(!::WriteProcessMemory (hWnd ,pRemotePara,&myRemotePara,sizeof myRemotePara,0))return 0;
//启动进将参数传递进入
HANDLE hThread = ::CreateRemoteThread (hWnd ,0,0,(DWORD (__stdcall *)(void *))pRemoteThread ,pRemotePara,0,&byte_write);
if(!hThread){
return 0;
}

好了,就这么简单,下在给出一个弹出一个MessageBox的实例:

// RemoteThread.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

typedef struct _RemotePara{//参数结构
char pMessageBox[12];
DWORD dwMessageBox;
}RemotePara;
//远程线程
DWORD __stdcall ThreadProc (RemotePara *lpPara){
typedef int (__stdcall *MMessageBoxA)(HWND,LPCTSTR,LPCTSTR,DWORD);//定义MessageBox函数
MMessageBoxA myMessageBoxA;
myMessageBoxA =(MMessageBoxA) lpPara->dwMessageBox ;//得到函数入口地址
myMessageBoxA(NULL,lpPara->pMessageBox ,lpPara->pMessageBox,0);//call
return 0;
}
void EnableDebugPriv();//提升应用级调试权限

int main(int argc, char* argv[]){
const DWORD THREADSIZE=1024*4;
DWORD byte_write;
EnableDebugPriv();//提升权限
HANDLE hWnd = ::OpenProcess (PROCESS_ALL_ACCESS,FALSE,992);
if(!hWnd)return 0;
void *pRemoteThread =::VirtualAllocEx(hWnd,0,THREADSIZE,MEM_COMMIT| MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(!pRemoteThread)return 0;
if(!::WriteProcessMemory(hWnd,pRemoteThread,&ThreadProc,THREADSIZE,0))
return 0;

//再付值
RemotePara myRemotePara;
::ZeroMemory(&myRemotePara,sizeof(RemotePara));
HINSTANCE hUser32 = ::LoadLibrary ("user32.dll");
myRemotePara.dwMessageBox =(DWORD) ::GetProcAddress (hUser32 , "MessageBoxA");
strcat(myRemotePara.pMessageBox,"hello\0");
//写进目标进程
RemotePara *pRemotePara =(RemotePara *) ::VirtualAllocEx (hWnd ,0,sizeof(RemotePara),MEM_COMMIT,PAGE_READWRITE);//注意申请空间时的页面属性
if(!pRemotePara)return 0;
if(!::WriteProcessMemory (hWnd ,pRemotePara,&myRemotePara,sizeof myRemotePara,0))return 0;

//启动线程
HANDLE hThread = ::CreateRemoteThread (hWnd ,0,0,(DWORD (__stdcall *)(void *))pRemoteThread ,pRemotePara,0,&byte_write);
if(!hThread){
return 0;
}
return 0;
}


//提升权限
void EnableDebugPriv( void )
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;

if ( ! OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
return;
if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){
CloseHandle( hToken );
return;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
CloseHandle( hToken );
}

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧