ciw_blue吧 关注:22贴子:259
  • 1回复贴,共1

【源代码】进程守护

只看楼主收藏回复


My_Code_Start equ this byte

dwProtectID dd ? ;要保护进程的ID

szJmp1 db 0e9h
dwNewText dd ? ;修改API后的内容

szOldText1 db 5 dup(0) ;修改API前的内容

dwMsgBoxAddr dd 77D5058Ah ;MessageBox 地址
dwTerminateProcessAddr dd 7C801E16h ;TerminateProcess 地址
dwWriteProcMemory dd 7C80220Fh ;WriteProcessMemory 地址
dwOpenProcess dd 7C8309E1h ;OpenProcess 地址
dwGetForegroundWndAddr  dd 77D1BE4Bh  ;GetForegroundWindow 地址
dwCloseHandle dd 7C809B47h         ;CloseHandle 地址

dwMyID dd ? ;要远程进程的ID
hMyProcess dd ? ;要远程进程的句柄
dwTerminateID dd ? ;要关闭程序的ID
hTerminateProcess dd ? ;要关闭程序的句柄

szMsgText db 'CIW_BLUE创建的进程,请不要关闭!',0
szMsgCaption db '错误提示',0

_MyEntry:

_MyFun proc

call @F
@@:
pop ebx
sub ebx, offset @B
;************************************************************
mov eax, dword ptr [esp - 010h]
mov [ebx + dwTerminateID], eax ;即将被关闭的程序的ID

.if eax == [ebx + dwProtectID] ;是不是要保护的进程
push MB_ICONERROR
lea eax, [ebx + szMsgCaption]
push eax
lea eax, [ebx + szMsgText]
push eax
call [ebx + dwGetForegroundWndAddr]
push eax
call [ebx + dwMsgBoxAddr] ;弹出对话框
ret
.endif

assume  fs:nothing
mov  eax,  fs:[24]
mov eax, ds:[eax + 32]
mov [ebx + dwMyID], eax ;获取远程进程的ID

push [ebx + dwMyID ]
push TRUE
push PROCESS_ALL_ACCESS
call [ebx + dwOpenProcess]
mov [ebx + hMyProcess], eax ;打开进程

push NULL
push 5
lea eax, [ebx + szOldText1]
push eax
push [ebx + dwTerminateProcessAddr]
push [ebx + hMyProcess]
call [ebx + dwWriteProcMemory] ;写入 TerminateProcess 原来的内容

push [ebx + dwTerminateID]
push TRUE
push PROCESS_ALL_ACCESS
call [ebx + dwOpenProcess] ;打开要关闭的进程
mov [ebx + hTerminateProcess], eax

push 0
push [ebx + hTerminateProcess]
call [ebx + dwTerminateProcessAddr] ;关闭进程

push [ebx + hTerminateProcess]
call [ebx + dwCloseHandle] ;关闭进程句柄
ret
_MyFun endp

My_Code_End  equ this byte


1楼2008-04-06 18:28回复
    .386
    .model stdcall, flat
    option  casemap:none

    include kernel32.inc
    include user32.inc
    include windows.inc
    includelib kernel32.lib
    includelib user32.lib

    .data
    szError db '找不到任务管理器',0
    szFormat db '%d',0
    szBuf db 100 dup (?)

    szWndName db 'Windows 任务管理器',0
    dwID dd ? ;要 HOOK 的进程ID
    lpMemory dd ? ;远程进程代码申请的空间
    hProcess dd ? ;远程进程句柄

    dwTerminateProcessFunAddr dd 7C801E16h ;TerminateProcess函数的地址

    szJmp db 0e9h
    dwMyOpenProcessFunAddr dd ? ;Hook OpenProcess 地址

    szOldText db 5 dup(0)

    dwMyProcessID dd ?

    szManagerPath db 'C:\WINDOWS\system32\taskmgr.exe',0

    szMyText db 'CIW_BLUE 进程守护',0
    szMyCaption db '进程保护',0
    .code
    include MyCode.asm
    start:
    invoke WinExec, offset szManagerPath , SW_SHOW
    invoke Sleep, 1000

    invoke FindWindow, NULL, offset szWndName
    invoke GetWindowThreadProcessId, eax, offset dwID

    invoke OpenProcess, PROCESS_ALL_ACCESS, FALSE, dwID ;打开进程
    mov hProcess, eax ;进程句柄
    .if !eax
    invoke MessageBox, NULL, offset szError, NULL, MB_OK
    invoke ExitProcess, 0
    .endif

    invoke VirtualAllocEx, hProcess, NULL, offset My_Code_End - offset My_Code_Start, MEM_COMMIT, PAGE_EXECUTE_READWRITE
    mov lpMemory, eax ;远程代码的地址

    invoke WriteProcessMemory, hProcess, lpMemory, offset My_Code_Start, offset My_Code_End - offset My_Code_Start, NULL

    mov eax, lpMemory
    mov ecx, offset _MyEntry
    sub ecx, offset My_Code_Start
    add eax, ecx
    sub eax, dwTerminateProcessFunAddr
    sub eax, 5
    mov dwMyOpenProcessFunAddr, eax ;远程代码的执行地址

    ;获取当前进程的ID
    invoke GetCurrentProcessId
    mov dwMyProcessID, eax

    ;把当前进程的ID写入到远进程中
    invoke WriteProcessMemory, hProcess, lpMemory, offset dwMyProcessID, 4, NULL

    ;修改API后的内容
    mov eax, lpMemory 
    add eax, 4
    invoke WriteProcessMemory, hProcess, eax, offset szJmp, 5, NULL

    ;修改API前的内容
    invoke ReadProcessMemory, hProcess, dwTerminateProcessFunAddr, offset szOldText, 5, 0
    mov eax, lpMemory 
    add eax, 9
    invoke WriteProcessMemory, hProcess, eax, offset szOldText, 5, 0

    ;修改API的内容
    invoke WriteProcessMemory, hProcess, dwTerminateProcessFunAddr, offset szJmp, 5, NULL

    invoke MessageBox, NULL, offset szMyText, offset szMyCaption, MB_OK

    invoke ExitProcess, 0

    end start


    2楼2008-04-06 18:28
    回复