Wednesday, March 18, 2009

bat file

This is a memory resident parasitic BAT-file infector. It's easier to show the text of the virus than to say something about its algorithm. The virus text is very simple:

@ECHO OFF
REM <<< code: jmp installation, int_21 handler part 1 >>>
copy %0 b.com>nul
b.com
del b.com
rem <<< code: TSR installation, int_21 handler part 2 >>>

Note: the brackets <<< >>> mean that here is the non-text bytes of the virus.

The main feature of this virus consist in its double-facing. The virus body is executed in two formats: it's executed as batch file if the infected file has BAT extension, or as COM file it the file has COM extension.

On running this virus from BAT file it copies itself (i.e. host file) into the new temporary file B.COM by using the DOS command

copy %0 b.com

The %0 parameter substitutes by the name of the batch file as it typed at the command prompt. This way the virus creates the copy of infected BAT-file with COM extension. Then this virus executes that file by next line of BAT file and then deletes it from disk. The binary code and data of the virus are remarked my REM command and do not influence on BAT virus flow.

The B.COM file is executed as a standard COM file. By this the text strings of the file beginning

@ECHO OFF
REM

are interpreted as 'dummy' i8086 instruction like these:

INC register
DEC register
OR register, immediate
AND register, register

These instructions do not influence on COM program execution (as the remarked binary code do not used by BAT variant of this virus). After execution of the last text bytes (REM instruction of the second line of BAT virus) the virus activation code starts to work.

The algorithm of virus installation is very primitive, it's occupies ten assembler instruction only. The virus hooks INT 21h by using standard DOS functions GETVECT and SETVECT (AX=3521h, 2521h) and then stays memory resident by using INT 27h. The virus do not checks the memory for the presence of the TSR part of previous execution. So the virus will present in memory so many times as the infected BAT-files are executed.

The virus intercepts one DOS function only, it's WRITE HANDLE function (INT 21h, AH=40H). The virus checks the beginning of write buffer for the '@echo' string and if that string is present the virus write itself body before saving that buffer. A lot of BAT-file contains that string at their beginnings so they will be infected upon creating, copying or modifying.

So the virus write itself into the BAT-file beginning. The infected files at first create the B.COM file, run and delete it and then they are continued as they are not infected.

February 28, 2009 3:05 AM

No comments:

Post a Comment