Advertisement
Derek1017

Updated Anti-Virus

Apr 6th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.13 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3.  
  4. --[[
  5.  
  6. Give credit to derekseitz for the base-code!
  7.  
  8. Types of viruses:
  9.  
  10. R.A.K - Random access keys. These hook a math.random to startup and keep rebooting the computer until it gets a certain number.
  11. They will often display it's payload or allow the user to continue after it gets the number.
  12.  
  13. Virus - Just your average malware. Often infect other files and display it's payload later.
  14.  
  15. Attackware - These are usually made for revenge. They often flood rednet with long, spam messages or try to DDOS a certain url.
  16.  
  17. R.A.T - Remote admin tools. They allow for the attacker to remotely access the system that is infected.
  18.  
  19. Worm - ANY of the types of malware that spread. They often use an exploit, mass email, or infect floppy disks.
  20.  
  21. Keyloggers - These log the keys that you type into the computer, and often upload them to pastebin as items such as key.log, etc
  22.  
  23. Spyware - They can spy on ANYTHING you do. Keys, programs ran, programs edited, etc.
  24.  
  25. P.U.P - Not guaranteed to be a virus, but can sneak out malicious functions.
  26.  
  27. Trojan - Programs that download other malware or P.U.Ps.
  28.  
  29. Adware - None found yet. Advertise other malware to you, this will likely become a problem in Firewolf 3.0 with http support.
  30.  
  31. Crapware - Don't really damage your computer, but can be really annoying.
  32.  
  33. Scareware - Same as crapware, except they are made to scare you in some way, such as saying "Deleting ROM", Deleting "bios.lua", or displaying a scary image.
  34.  
  35. -- ]]
  36. UpdateURL = "https://snipt.net/raw/bf1103f7d45ff3f74a05a2075e5b5671/"
  37. VirusDefinitionsURL = "https://snipt.net/raw/59d2a60b6183005904b7192e1fc3914e/"
  38.  
  39. function split(pString, pPattern)
  40. local Table = {n = 0} -- NOTE: use {n = 0} in Lua-5.0
  41. local fpat = "(.-)" .. pPattern
  42. local last_end = 1
  43. local s, e, cap = pString:find(fpat, 1)
  44. while s do
  45. if s ~= 1 or cap ~= "" then
  46. table.insert(Table,cap)
  47. end
  48. last_end = e+1
  49. s, e, cap = pString:find(fpat, last_end)
  50. end
  51. if last_end <= #pString then
  52. cap = pString:sub(last_end)
  53. table.insert(Table, cap)
  54. end
  55. return Table
  56. end
  57.  
  58. function isColor ()
  59. if term.isColor then return term.isColor() else return false end
  60. end
  61.  
  62. function isEven ( nNum ) xn=0 while xn < nNum do xn = xn + 2 if xn == nNum then return true elseif xn > nNum then return false end end return false end
  63.  
  64.  
  65. function cPrint ( nString )
  66. if isEven(nString:len()) then nString = nString.." " end
  67. ox, oy = term.getCursorPos()
  68. scrWid, scrHei = term.getSize()
  69. term.setCursorPos(scrWid/2-nString:len()/2,oy)
  70. write(nString)
  71. term.setCursorPos(1,oy+1)
  72. end
  73.  
  74. function fPrint ( nString )
  75. if isEven(nString:len()) then nString = nString.." " end
  76. ox, oy = term.getCursorPos()
  77. scrWid, scrHei = term.getSize()
  78. write(string.rep(" ",scrWid/2-nString:len()/2)..nString..string.rep(" ",scrWid/2-nString:len()/2))
  79. term.setCursorPos(1,oy+1)
  80. end
  81.  
  82. function cLine ( nCol , rCol )
  83. ox, oy = term.getCursorPos()
  84. scrWid, scrHei = term.getSize()
  85. term.setBackgroundColor(nCol)
  86. write(string.rep(" ",scrWid))
  87. term.setBackgroundColor(rCol)
  88. term.setCursorPos(1,oy+1)
  89. end
  90.  
  91. function tLine ( nT )
  92. ox, oy = term.getCursorPos()
  93. scrWid, scrHei = term.getSize()
  94. write(string.rep(nT:sub(1,1),scrWid))
  95. term.setCursorPos(1,oy+1)
  96. end
  97.  
  98. function doError ( nErr )
  99. if isColor() then
  100. term.setBackgroundColor(colors.red)
  101. term.clear()
  102. term.setCursorPos(1,1)
  103. cPrint("ERROR")
  104. cLine(colors.white,colors.red)
  105. term.setCursorPos(3,4)
  106. write("Err: "..nErr)
  107. sleep(2)
  108. term.setBackgroundColor(colors.white)
  109. term.setCursorPos(3,6)
  110. write("Press any key to reboot.")
  111. os.pullEvent("key")
  112. os.reboot()
  113. else
  114. term.clear()
  115. term.setCursorPos(1,1)
  116. cPrint("ERROR")
  117. tLine("-")
  118. term.setCursorPos(3,4)
  119. write("Err: "..nErr)
  120. sleep(2)
  121. term.setCursorPos(3,6)
  122. write("Press any key to reboot.")
  123. os.pullEvent("key")
  124. os.reboot()
  125. end
  126. end
  127.  
  128.  
  129.  
  130.  
  131. function rVirus ( nID )
  132. -- Name , Type , CatchString , Age , Common-ness , Danger , Estimated Total Infections , Curing Function , Sonar Pattern (NORTAN METHOD)
  133. return { name = nDefs[nID][1] , nType = nDefs[nID][2] , def = nDefs[nID][3] , age = nDefs[nID][4] , recurrency = nDefs[nID][5] , threatLevel = nDefs[nID][6] , infectionsToDate = nDefs[nID][7] , cure = nDefs[nID][8] , sonarPattern = nDefs[nID][9] }
  134. end
  135.  
  136. curIt = ""
  137. curInf = 0
  138. curInfs = {}
  139. curInfsT = {}
  140.  
  141. function scanDisplay ()
  142. while true do
  143. if isColor() then
  144. term.setBackgroundColor(colors.purple)
  145. term.clear()
  146. term.setCursorPos(1,1)
  147. cPrint("MALSCAN")
  148. cLine(colors.white,colors.purple)
  149. term.setCursorPos(3,4)
  150. write("Currently Scanning: "..curIt)
  151. term.setCursorPos(3,5)
  152. write("Infections: ")
  153. if curInf > 0 then
  154. term.setTextColor(colors.red)
  155. write(curInf)
  156. term.setTextColor(colors.white)
  157. else
  158. write(curInf)
  159. end
  160. term.setCursorPos(3,7)
  161. write("Stay Calm! Scanning!")
  162. else
  163. term.clear()
  164. term.setCursorPos(1,1)
  165. cPrint("MALSCAN")
  166. tLine("-")
  167. term.setCursorPos(3,4)
  168. write("Currently Scanning: "..curIt)
  169. term.setCursorPos(3,5)
  170. write("Infections: "..curInf)
  171. term.setCursorPos(3,7)
  172. write("Stay calm! Scanning!")
  173. end
  174. sleep(0.5)
  175. end
  176. end
  177.  
  178. readStack = {
  179.  
  180. }
  181.  
  182. -- Prepare the readStack
  183.  
  184. -- >:( I know there is an easier way! But.... I can't think of that right now, too many ideas! XD
  185. function toStack6 (nS5)
  186. for n5,m5 in ipairs(fs.list(nS5)) do
  187. readStack[#readStack+1] = nS5..m5
  188. end
  189. end
  190.  
  191. function toStack5 (nS4)
  192. for n4,m4 in ipairs(fs.list(nS4)) do
  193. readStack[#readStack+1] = nS4..m4
  194. if fs.isDir(m4) then
  195. nCarry5 = n4
  196. toStack6(m4.."/")
  197. end
  198. end
  199. end
  200.  
  201. function toStack4 (nS3)
  202. for n3,m3 in ipairs(fs.list(nS3)) do
  203. readStack[#readStack+1] = nS3..m3
  204. if fs.isDir(m3) then
  205. nCarry4 = n3
  206. toStack5(m3.."/")
  207. end
  208. nCarry4 = 0
  209. end
  210. end
  211.  
  212. function toStack3 (nS2)
  213. for n2,m2 in ipairs(fs.list(nS2)) do
  214. readStack[#readStack+1] = nS2..m2
  215. if fs.isDir(m2) then
  216. nCarry3 = n2
  217. toStack4(m2.."/")
  218. end
  219. nCarry3 = 0
  220. end
  221. end
  222.  
  223. function toStack2 (nS1)
  224. for n1,m1 in ipairs(fs.list(nS1)) do
  225. readStack[#readStack+1] = nS1..m1
  226. if fs.isDir(m1) then
  227. nCarry2 = n1
  228. toStack3(m1.."/")
  229. end
  230. nCarry2 = 0
  231. end
  232. end
  233.  
  234. -- Teehee! ( >_> ) ffs world, I was thinking: "How can I prevent overlapping table variables??" So I came up with this BRILLIANT bugged out carry in / out system, BUT, I wasted 40 minutes on trying to solve this riddle when it was as simple as, table[#table+1]=var. >_< *facepalm*
  235. nCarry1 = 0
  236. nCarry2 = 0
  237. nCarry3 = 0
  238. nCarry4 = 0
  239. nCarry5 = 0
  240. nCarry6 = 0
  241.  
  242. function toStack1 (nS)
  243. for n,m in ipairs(fs.list(nS)) do
  244. readStack[#readStack+1] = nS..m
  245. if fs.isDir(m) then
  246. nCarry1 = n
  247. toStack2(m.."/")
  248. end
  249. nCarry1 = 0
  250. end
  251. end
  252.  
  253. toStack1("/")
  254.  
  255. fileTable = {}
  256.  
  257. function detectFile_MALDEF ( nData )
  258. if nData == nil then nData = "" ad=io.open(".errors.ffs","a") ad:write("Nil catchy! >:(\n") ad:close() end -- Error catch~ for debugging.
  259. for i=1, #nDefs do
  260. if string.find ( nData, rVirus(i).def ) ~= nil then
  261. return i
  262. end
  263. end
  264. return false
  265. end
  266.  
  267. function scanProc ()
  268. -- WARNING: Caution of Remote Code Injection! INFECTED_FILE -> PASTEBIN -> INFECTED_CLIENT -> LOADSTRING(VIRUS)()
  269. -- Note to self: Perform a google search on common CC viruses (exact code) and have google tell you where they are stored.
  270. for n,m in ipairs(readStack) do
  271. if fs.exists(m) then if fs.isDir(m) == false then if fs.getSize(m) > 0 then if fs.isReadOnly(m) == false and m ~= shell.getRunningProgram() and m ~= "/"..shell.getRunningProgram() then
  272. curIt = m
  273. ell=fs.open(m,"r")
  274. md=ell:readAll()
  275. ell:close()
  276. di = detectFile_MALDEF(md)
  277. if di ~= false then
  278. curInfs[#curInfs+1]=n
  279. curInf = curInf + 1
  280. end
  281. end end end end
  282. end
  283. end
  284.  
  285. function scan ()
  286. parallel.waitForAny (
  287. scanDisplay,
  288. scanProc
  289. )
  290. if isColor() then
  291. if curInf > 0 then
  292. term.setBackgroundColor(colors.red)
  293. term.clear()
  294. term.setCursorPos(1,1)
  295. cPrint("VirusScope has found threats.")
  296. cLine(colors.white,colors.red)
  297. term.setCursorPos(3,4)
  298. write("Threats detected: "..curInf)
  299. term.setCursorPos(3,6)
  300. for n,m in ipairs(curInfs) do
  301. fs.delete(readStack[m])
  302. end
  303. write("All threats are deleted!")
  304. -- Subject to change in the future, we might just store all deleted files in a . folder and have them restorable. Not right now though.
  305. aFi = io.open(".avl","a")
  306. for n,m in ipairs(curInfsT) do
  307. aFi:write(m.."\n")
  308. end
  309. aFi:close()
  310. term.setCursorPos(3,7)
  311. write("Press any key to reboot!")
  312. os.pullEvent("key")
  313. os.reboot()
  314. else
  315. term.setBackgroundColor(colors.white)
  316. term.clear()
  317. term.setCursorPos(1,1)
  318. term.setTextColor(colors.black)
  319. cPrint("ALL CLEAR")
  320. cLine(colors.lime,colors.white)
  321. term.setCursorPos(3,4)
  322. write("Infections: 0")
  323. term.setCursorPos(3,6)
  324. sleep(2)
  325. write("Press any key to reboot!")
  326. os.pullEvent("key")
  327. os.reboot()
  328. end
  329. else
  330. if curInfs > 0 then
  331. term.clear()
  332. term.setCursorPos(1,1)
  333. cPrint("THREATS FOUND")
  334. tLine("-")
  335. term.setCursorPos(3,4)
  336. for n,m in ipairs(curInfs) do
  337. fs.delete(readStack[m])
  338. end
  339. fileHandle = io.open(".avl","a")
  340. for n,m in ipairs(curInfsT) do
  341. fileHandle:write(m.."\n")
  342. end
  343. fileHandle:close()
  344. write("Threats: "..curInf)
  345. term.setCursorPos(3,6)
  346. write("All viruses deleted!")
  347. term.setCursorPos(3,7)
  348. sleep(2)
  349. write("Press any key to reboot!")
  350. os.pullEvent("key")
  351. os.reboot()
  352. else
  353. term.clear()
  354. term.setCursorPos(1,1)
  355. cPrint("ALL CLEAR")
  356. tLine("-")
  357. term.setCursorPos(3,4)
  358. write("Infections: 0")
  359. term.setCursorPos(3,6)
  360. sleep(2)
  361. write("Press any key to reboot!")
  362. os.pullEvent("key")
  363. os.reboot()
  364. end
  365. end
  366. end
  367.  
  368. function wipe ()
  369. for n,m in ipairs(fs.list("")) do
  370. if m ~= "rom" and m ~= shell.getRunningProgram() then
  371. fs.delete(m)
  372. end
  373. end
  374. end
  375.  
  376. function update ()
  377. resp = http.get(UpdateURL)
  378. if resp then
  379. aFs=io.open(shell.getRunningProgram(),"w")
  380. aFs:write(resp.readAll())
  381. aFs:close()
  382. shell.run(shell.getRunningProgram())
  383. else
  384. doError("Could not reach update server!")
  385. end
  386. end
  387.  
  388. function recov ()
  389. term.clear()
  390. cPrint("Flare and all infected files has been deleted.")
  391. fs.delete("worm")
  392. fs.delete("cubedos/main")
  393. fs.delete("cubedos/block")
  394. fs.delete("edit")
  395. fs.delete("delete")
  396. fs.delete("edit")
  397. fs.delete("pastebin")
  398. fs.delete("lua")
  399. fs.delete("cd")
  400. fs.delete("dir")
  401. fs.delete("cube-dos")
  402.  
  403. end
  404.  
  405. function bscan ()
  406. if fs.exists("/startup") then fs.move("/startup","/startup.bk") end -- Stupid FS api... >_>
  407. fs.copy(shell.getRunningProgram(),"/startup")
  408. os.reboot()
  409. end
  410.  
  411.  
  412. bEndIt = false
  413.  
  414. function bEnd ()
  415. bEndIt = true
  416. end
  417.  
  418. menuOptions = {
  419. { "Scan" , scan },
  420. { "Wipe Computer" , wipe },
  421. { "Update" , update },
  422. { "Recover from Flare" , recov },
  423. { "Boot Scan" , bscan },
  424. { "Exit AV" , bEnd }
  425. }
  426.  
  427.  
  428. function doMenuProcessing ()
  429. while bEndIt == false do
  430. eve = { os.pullEvent() }
  431. if eve[1] == "key" and eve[2] == keys.down then
  432. if menuIndex < 6 then menuIndex = menuIndex + 1 mDraw() end
  433. end
  434. if eve[1] == "key" and eve[2] == keys.up then
  435. if menuIndex > 1 then menuIndex = menuIndex - 1 mDraw() end
  436. end
  437. if eve[1] == "key" and eve[2] == keys.enter then
  438. menuOptions[menuIndex][2]()
  439. end
  440. if eve[1] == "mouse_click" then
  441. if eve[4] == 4 then menuOptions[1][2]() end
  442. if eve[4] == 6 then menuOptions[2][2]() end
  443. if eve[4] == 8 then menuOptions[3][2]() end
  444. if eve[4] == 10 then menuOptions[4][2]() end
  445. if eve[4] == 12 then menuOptions[5][2]() end
  446. if eve[4] == 14 then menuOptions[6][2]() end
  447. end
  448. if bEndIt then break end
  449. end
  450. end
  451.  
  452. menuIndex = 1
  453.  
  454. function mDraw ()
  455. if isColor() then
  456. term.setBackgroundColor(colors.black)
  457. term.setTextColor(colors.black)
  458. term.clear()
  459. term.setCursorPos(1,1)
  460. cPrint("VirusScope")
  461. cLine(colors.green,colors.black)
  462. term.setCursorPos(1,4)
  463. term.setBackgroundColor(colors.lightGray)
  464. term.setTextColor(colors.black)
  465. if menuIndex == 1 then fPrint("["..menuOptions[1][1].."]") else fPrint(menuOptions[1][1]) end
  466. term.setCursorPos(1,6)
  467. term.setBackgroundColor(colors.lightGray)
  468. term.setTextColor(colors.black)
  469. if menuIndex == 2 then fPrint("["..menuOptions[2][1].."]") else fPrint(menuOptions[2][1]) end
  470. term.setCursorPos(1,8)
  471. term.setBackgroundColor(colors.lightGray)
  472. term.setTextColor(colors.black)
  473. if menuIndex == 3 then fPrint("["..menuOptions[3][1].."]") else fPrint(menuOptions[3][1]) end
  474. term.setCursorPos(1,10)
  475. term.setBackgroundColor(colors.lightGray)
  476. term.setTextColor(colors.black)
  477. if menuIndex == 4 then fPrint("["..menuOptions[4][1].."]") else fPrint(menuOptions[4][1]) end
  478. term.setCursorPos(1,12)
  479. term.setBackgroundColor(colors.lightGray)
  480. term.setTextColor(colors.black)
  481. if menuIndex == 5 then fPrint("["..menuOptions[5][1].."]") else fPrint(menuOptions[5][1]) end
  482. term.setCursorPos(1,14)
  483. term.setBackgroundColor(colors.lightGray)
  484. term.setTextColor(colors.black)
  485. if menuIndex == 6 then fPrint("["..menuOptions[6][1].."]") else fPrint(menuOptions[6][1]) end
  486. doMenuProcessing()
  487. else
  488. term.clear()
  489. term.setCursorPos(1,1)
  490. cPrint("Shinjiteru MalScan")
  491. tLine("-")
  492. term.setCursorPos(1,4)
  493. if menuIndex == 1 then fPrint("["..menuOptions[1][1].."]") else fPrint(menuOptions[1][1]) end
  494. term.setCursorPos(1,6)
  495. if menuIndex == 2 then fPrint("["..menuOptions[2][1].."]") else fPrint(menuOptions[2][1]) end
  496. term.setCursorPos(1,8)
  497. if menuIndex == 3 then fPrint("["..menuOptions[3][1].."]") else fPrint(menuOptions[3][1]) end
  498. term.setCursorPos(1,10)
  499. if menuIndex == 4 then fPrint("["..menuOptions[4][1].."]") else fPrint(menuOptions[4][1]) end
  500. term.setCursorPos(1,12)
  501. if menuIndex == 5 then fPrint("["..menuOptions[5][1].."]") else fPrint(menuOptions[5][1]) end
  502. term.setCursorPos(1,14)
  503. if menuIndex == 6 then fPrint("["..menuOptions[6][1].."]") else fPrint(menuOptions[6][1]) end
  504. doMenuProcessing()
  505. end
  506. end
  507.  
  508. mDraw()
  509. doMenuProcessing()
  510.  
  511. term.setBackgroundColor(colors.black)
  512. term.setTextColor(colors.white)
  513. term.clear()
  514. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement