哥写的线程注入程序 可以在线程中…

#include <stdio.h>
#include <windows.h>

int main(int argc, char** argv)
{
      if(argc<3)
      {
          fprintf(stdout,"\nUsage : %s <pid> <dll-path>\n\n",argv[0]);
          return 1;
      }

      DWORD Pid,DllPathLen;
      if(sscanf(argv[1],"%u",&Pid)<=0 ) // Get Process Id
      {
          fprintf(stderr,"\n[-] ERROR: Pid Value\n"),fflush(stderr);
          return 1;
      }
      if(   DllPathLen = strlen(argv[2]),DllPathLen == 0 ) // Get Dll Path
      {
          fprintf(stderr,"\n[-] ERROR: DllPath\n"),fflush(stderr);
          return 1;
      }

      // Get Process Handle
      HANDLE hDstProc = OpenProcess(PROCESS_CREATE_THREAD|PROCESS_VM_OPERATION|PROCESS_VM_WRITE,TRUE,Pid);
      if(hDstProc==NULL)
      {
          fprintf(stderr,"\n[-] ERROR: in OpenProcess(), Pid %u\n",Pid),fflush(stderr);
          return 1;
      }

      // Get LoadLibraryA Address
      fprintf(stdout,"\n[+] Pid: %u, Handle : 0Xx \n",Pid,hDstProc),fflush(stdout);
      LPTHREAD_START_ROUTINE LibFunc =
          (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32"),"LoadLibraryA");
      fprintf(stdout,"\n[+] LoadLibraryA Address : 0Xx\n",LibFunc),fflush(stdout);

      // Create Remote Heap, Set Dll Path
      DWORD Success = TRUE;
      char * DllPath = (char*) VirtualAllocEx(hDstProc,NULL,DllPathLen + 1,MEM_COMMIT,PAGE_READWRITE);
      if(DllPath)
      {
fprintf(stdout,"\n[+] Create Memory in %u, Address : 0Xx\n",Pid,DllPath);
          if(WriteProcessMemory(hDstProc,DllPath,argv[2],DllPathLen + 1,NULL))
          {
              fprintf(stdout,"\n[+] Set Dll Path : %s\n",argv[2]);
          }
          else
          {
              fprintf(stderr,"\n[-] ERROR: in WriteProcessMemory(), Set Dll Path Failed\n");
              Success = FALSE;
          }
      }
      else
      {
          fprintf(stderr,"\n[-] ERROR: in VirtualAllocEx(), Get Memory\n");
          Success = FALSE;
      }

      //Start Dll Inject
      if(Success)
      {
          HANDLE hThread = CreateRemoteThread(hDstProc,NULL,0,LibFunc,DllPath,0,NULL);
          if(hThread)
          {
              fprintf(stdout,"\n[+] Create Remote Thread, Handle : 0Xx, Dll Injection Success\n",hThread);
          }
          else
          {
              fprintf(stderr,"\n[-] in CreateRemoteThread(), Dll Injection Failed\n");
              Success = FALSE;
          }
          CloseHandle(hThread);
      }

      //Cleaning
      VirtualFreeEx(hDstProc,DllPath,0,MEM_RELEASE);
      CloseHandle(hDstProc);

      return !Success;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值