这是一个用用户模式的APC实现WriteProcessMemory功能的示例,也就是说:这仅仅只是一个概念模型,与实际应用还差几条街的距离。但它提供远程进程内存覆盖的一种新方法,完全可以取代API WriteProcessMemory应用程序界面。
WriteProcessMemoryAPC Proc USES RBX RSI RDI hProcess:HANDLE,pAddress:QWORD,pData:QWORD,dqLength:QWORD
Local hThread:HANDLE
;// create suspended thread (ExitThread)
invoke pNtCreateThreadEx, addr hThread,NT_CREATE_THREAD_EX_ALL_ACCESS,0,hProcess,pExitThread,0, NT_CREATE_THREAD_EX_SUSPENDED, NULL, 0, 0, NULL
;int 3
.if rax != 0
;invoke ErrorMessage,CStr("pNtCreateThreadEx")
mov rax,1
ret
.endif
;// write memory
xor rbx,rbx
;invoke MessageBox, 0, pAddress, 0, 0
;invoke MessageBox, 0, pData, 0, 0
.repeat
mov rsi,pAddress
mov rdi,pData
add rsi,rbx
mov al,byte ptr [rdi+rbx]
;// schedule a call to RtlFillMemory to update the current byte
invoke pNtQueueApcThread,hThread,pRtlFillMemory,rsi,1,al
.if rax != 0
;// error
invoke TerminateThread,hThread,NULL
invoke CloseHandle,hThread
mov rax,1
.break
.endif
inc rbx
.until rbx == dqLength
;// resume thread to execute queued APC calls
invoke ResumeThread,hThread
;// wait for thread to exit
invoke WaitForSingleObject,hThread, INFINITE
;// close thread handle
invoke CloseHandle,hThread
mov rax,0
ret
WriteProcessMemoryAPC EndP
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)