网上有很多讨论进程注入编程的帖子,用汇编写的比较少点。最近工作中刚好用到了进程注入技术,下面是原代码。希望大家多提宝贵意见,共同学习、共同进步!
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc
include advapi32.inc
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
includelib advapi32.lib
include E:\MASMPlus\Exlib\macro.asm
.data
szKernel db "Kernel32.dll",0
szLoad db "LoadLibraryA",0
szCat db "\\dllinject.dll",0
szPrivilegeName db "SeDebugPrivilege",0 ;SE_DEBUG_NAME=SeDebugPrivilege
.data?
myFile db MAX_PATH dup (?)
szBuffer db 128 dup (?)
.code
;修改进程的一些访问权限
EnableDebugPriv proc
local @stTp:TOKEN_PRIVILEGES,@stLuid:LUID
local @hToken:DWORD
;获取进程句柄
invoke GetCurrentProcess
mov ebx,eax
;打开与进程相关联的访问令版,如果要修改访问令版的特权,需要指定参数TOKEN_ADJUST_PRIVILEGES
invoke OpenProcessToken,ebx,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,addr @hToken
;#define SE_DEBUG_NAME TEXT("SeDebugPrivilege")
invoke LookupPrivilegeValue,NULL,addr szPrivilegeName,addr @stLuid
mov @stTp.PrivilegeCount,1
push @stLuid.LowPart
push @stLuid.HighPart
pop @stTp.Privileges[0].Luid.HighPart
pop @stTp.Privileges[0].Luid.LowPart
invoke CloseHandle,@hToken
xor eax,eax
ret
EnableDebugPriv endp
;查找指定进程,这里找的是cmd。也可以换成其它程序
GetProcessId proc lpName:DWORD
local hProcessSnap:DWORD
local ProcessID:DWORD
local stPe:PROCESSENTRY32
local bRet:BYTE
invoke CloseHandle,hProcessSnap
mov eax,ProcessID
ret
GetProcessId endp
InjectDll proc lpName:DWORD ,dwRemoteProcessId:DWORD
local hRemoteProcess:DWORD
local pszLibFileRemote:DWORD
local len:DWORD
local pfnStartAddr:DWORD
local hRemoteThread:DWORD