远程注入

 
  • 简介:注入代码到远程线程,在目标进程创建一个线程,执行期望的代码。
  • 项目需求:创建远程线程,并可以实现远程注入DLL.
  • 项目分析:使用CreateRemoteProcess在目标进程创建一个远程线程,执行自定义代码,自定义代码当然包括Load一个DLL,这样就可以现实远程注入DLL
  • 项目实现:先在远程线程分配部分空间,然后向里写入一些线程需要的参数,和线程体本身,然后调用CreateRemoteProcess执行那个远程线程体。

 

void __fastcall InjectToRemoteProcess(DWORD dwProcessId,PVOID funcStart,PVOID funcEnd,void * pParam,DWORD dwParamSize)
{
 HANDLE hRemoteProcess=NULL; //remote process will be injected
 HANDLE hRemoteThread=NULL; //injected thread!
 DWORD dwThreadSize=0;
 
 PVOID pRemoteThread=NULL;
 PVOID pRemoteParam=NULL;
 DWORD dwWriten=0;
 BOOL bRet=FALSE;
 
 EnablePrivilege(SE_DEBUG_NAME,true);//up Privilege
 
 hRemoteProcess = OpenProcess(PROCESS_ALL_ACCESS,false,dwProcessId);
 if(hRemoteProcess == NULL)
 {
  MessageBox(NULL,"Failed to Open Process","Open Process Error",MB_OK | MB_APPLMODAL|MB_ICONWARNING);
  return;
 }
 if (0 != dwParamSize)
 {
  pRemoteParam = VirtualAllocEx(hRemoteProcess,NULL,dwParamSize,MEM_COMMIT,PAGE_READWRITE); //alloc memory space for param!
  if(pRemoteParam == NULL)
  {
   MessageBox(NULL,"Failed to Allocate Memory at Remote Process for Param","Alloc Memory Error!",MB_OK | MB_APPLMODAL | MB_ICONWARNING);
   return;
  }
  bRet = WriteProcessMemory(hRemoteProcess,pRemoteParam,pParam,dwParamSize,&dwWriten); //write param to remote alloced space!
  if(!bRet)
  {
   MessageBox(NULL,"Failed to Write Param to Remote Process",NULL,MB_OK | MB_APPLMODAL | MB_ICONWARNING);
   return;          
  }
 }
 
 dwThreadSize = (int)funcEnd - (int)funcStart+2048; //cal remote function need size!
 
 pRemoteThread = VirtualAllocEx(hRemoteProcess,NULL,dwThreadSize,MEM_COMMIT,PAGE_READWRITE); //alloc memory for remote thread!
 if(pRemoteThread == NULL)
 {
  MessageBox(NULL,"Failed to Allocate Memory at Remote Process for Thread Code",NULL,MB_OK | MB_APPLMODAL | MB_ICONWARNING);
  return;
 }
 bRet = WriteProcessMemory(hRemoteProcess,pRemoteThread,(LPVOID)funcStart,dwThreadSize,&dwWriten); //write function to remote memory space!
 if(!bRet)
 {
  MessageBox(NULL,"Failed to Write Thread Code to Remote Process",NULL,MB_OK | MB_APPLMODAL | MB_ICONWARNING);
  return;
 }
 
 hRemoteThread = CreateRemoteThread(hRemoteProcess,0,0,(DWORD(__stdcall *)(VOID*))pRemoteThread,pRemoteParam,0,&dwWriten);
 
 EnablePrivilege(SE_DEBUG_NAME,false); //down Privilege
}

http://pgy12345.googlepages.com/inject

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值