Advertisement
Derek1017

Anti-Virus

Apr 5th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.34 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3.  
  4. --[[
  5.  
  6. Give credit to Shinjiteru 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. resp = http.get(VirusDefinitionsURL)
  129. if resp then
  130.     defs = split(resp.readAll(),"\n")
  131. else
  132.     doError("Could not get Definitions!")
  133. end
  134.  
  135. nDefs = {}
  136.  
  137. for n,m in ipairs(defs) do
  138.     nDefs[n] = split(m,"|")
  139. end
  140.  
  141. function rVirus ( nID )
  142.     -- Name , Type , CatchString , Age , Common-ness , Danger , Estimated Total Infections , Curing Function , Sonar Pattern (NORTAN METHOD)
  143.     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] }
  144. end
  145.  
  146. curIt = ""
  147. curInf = 0
  148. curInfs = {}
  149. curInfsT = {}
  150.  
  151. function scanDisplay ()
  152.     while true do
  153.         if isColor() then
  154.             term.setBackgroundColor(colors.purple)
  155.             term.clear()
  156.             term.setCursorPos(1,1)
  157.             cPrint("MALSCAN")
  158.             cLine(colors.white,colors.purple)
  159.             term.setCursorPos(3,4)
  160.             write("Currently Scanning: "..curIt)
  161.             term.setCursorPos(3,5)
  162.             write("Infections: ")
  163.             if curInf > 0 then
  164.                 term.setTextColor(colors.red)
  165.                 write(curInf)
  166.                 term.setTextColor(colors.white)
  167.             else
  168.                 write(curInf)
  169.             end
  170.             term.setCursorPos(3,7)
  171.             write("Stay Calm! Scanning!")
  172.         else
  173.             term.clear()
  174.             term.setCursorPos(1,1)
  175.             cPrint("MALSCAN")
  176.             tLine("-")
  177.             term.setCursorPos(3,4)
  178.             write("Currently Scanning: "..curIt)
  179.             term.setCursorPos(3,5)
  180.             write("Infections: "..curInf)
  181.             term.setCursorPos(3,7)
  182.             write("Stay calm! Scanning!")
  183.         end
  184.         sleep(0.5)
  185.     end
  186. end
  187.  
  188. readStack = {
  189.  
  190. }
  191.  
  192. -- Prepare the readStack
  193.  
  194. -- >:( I know there is an easier way! But.... I can't think of that right now, too many ideas! XD
  195. function toStack6 (nS5)
  196.     for n5,m5 in ipairs(fs.list(nS5)) do
  197.         readStack[#readStack+1] = nS5..m5
  198.     end
  199. end
  200.  
  201. function toStack5 (nS4)
  202.     for n4,m4 in ipairs(fs.list(nS4)) do
  203.         readStack[#readStack+1] = nS4..m4
  204.         if fs.isDir(m4) then
  205.             nCarry5 = n4
  206.             toStack6(m4.."/")
  207.         end
  208.     end
  209. end
  210.  
  211. function toStack4 (nS3)
  212.     for n3,m3 in ipairs(fs.list(nS3)) do
  213.         readStack[#readStack+1] = nS3..m3
  214.         if fs.isDir(m3) then
  215.             nCarry4 = n3
  216.             toStack5(m3.."/")
  217.         end
  218.         nCarry4 = 0
  219.     end
  220. end
  221.  
  222. function toStack3 (nS2)
  223.     for n2,m2 in ipairs(fs.list(nS2)) do
  224.         readStack[#readStack+1] = nS2..m2
  225.         if fs.isDir(m2) then
  226.             nCarry3 = n2
  227.             toStack4(m2.."/")
  228.         end
  229.         nCarry3 = 0
  230.     end
  231. end
  232.  
  233. function toStack2 (nS1)
  234.     for n1,m1 in ipairs(fs.list(nS1)) do
  235.         readStack[#readStack+1] = nS1..m1
  236.         if fs.isDir(m1) then
  237.             nCarry2 = n1
  238.             toStack3(m1.."/")
  239.         end
  240.         nCarry2 = 0
  241.     end
  242. end
  243.  
  244. -- 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*
  245. nCarry1 = 0
  246. nCarry2 = 0
  247. nCarry3 = 0
  248. nCarry4 = 0
  249. nCarry5 = 0
  250. nCarry6 = 0
  251.  
  252. function toStack1 (nS)
  253.     for n,m in ipairs(fs.list(nS)) do
  254.         readStack[#readStack+1] = nS..m
  255.         if fs.isDir(m) then
  256.             nCarry1 = n
  257.             toStack2(m.."/")
  258.         end
  259.         nCarry1 = 0
  260.     end
  261. end
  262.  
  263. toStack1("/")
  264.  
  265. fileTable = {}
  266.  
  267. function detectFile_MALDEF ( nData )
  268.     if nData == nil then nData = "" ad=io.open(".errors.ffs","a") ad:write("Nil catchy! >:(\n") ad:close() end -- Error catch~ for debugging.
  269.     for i=1, #nDefs do
  270.         if string.find ( nData, rVirus(i).def ) ~= nil then
  271.             return i
  272.         end
  273.     end
  274.     return false
  275. end
  276.  
  277. function scanProc ()
  278.     -- WARNING: Caution of Remote Code Injection! INFECTED_FILE -> PASTEBIN -> INFECTED_CLIENT -> LOADSTRING(VIRUS)()
  279.     -- Note to self: Perform a google search on common CC viruses (exact code) and have google tell you where they are stored.
  280.     for n,m in ipairs(readStack) do
  281.         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
  282.             curIt = m
  283.             ell=fs.open(m,"r")
  284.             md=ell:readAll()
  285.             ell:close()
  286.             di = detectFile_MALDEF(md)
  287.             if di ~= false then
  288.                 curInfs[#curInfs+1]=n
  289.                 curInf = curInf + 1
  290.             end
  291.         end end end end
  292.     end
  293. end
  294.  
  295. function scan ()
  296.     parallel.waitForAny (
  297.         scanDisplay,
  298.         scanProc
  299.     )
  300.     if isColor() then
  301.         if curInf > 0 then
  302.             term.setBackgroundColor(colors.red)
  303.             term.clear()
  304.             term.setCursorPos(1,1)
  305.             cPrint("VirusScope has found threats.")
  306.             cLine(colors.white,colors.red)
  307.             term.setCursorPos(3,4)
  308.             write("Threats detected: "..curInf)
  309.             term.setCursorPos(3,6)
  310.             for n,m in ipairs(curInfs) do
  311.                 fs.delete(readStack[m])
  312.             end
  313.             write("All threats are deleted!")
  314.             -- Subject to change in the future, we might just store all deleted files in a . folder and have them restorable. Not right now though.
  315.             aFi = io.open(".avl","a")
  316.             for n,m in ipairs(curInfsT) do
  317.                 aFi:write(m.."\n")
  318.             end
  319.             aFi:close()
  320.             term.setCursorPos(3,7)
  321.             write("Press any key to reboot!")
  322.             os.pullEvent("key")
  323.             os.reboot()
  324.         else
  325.             term.setBackgroundColor(colors.white)
  326.             term.clear()
  327.             term.setCursorPos(1,1)
  328.             term.setTextColor(colors.black)
  329.             cPrint("ALL CLEAR")
  330.             cLine(colors.lime,colors.white)
  331.             term.setCursorPos(3,4)
  332.             write("Infections: 0")
  333.             term.setCursorPos(3,6)
  334.             sleep(2)
  335.             write("Press any key to reboot!")
  336.             os.pullEvent("key")
  337.             os.reboot()
  338.         end
  339.     else
  340.         if curInfs > 0 then
  341.             term.clear()
  342.             term.setCursorPos(1,1)
  343.             cPrint("THREATS FOUND")
  344.             tLine("-")
  345.             term.setCursorPos(3,4)
  346.             for n,m in ipairs(curInfs) do
  347.                 fs.delete(readStack[m])
  348.             end
  349.             fileHandle = io.open(".avl","a")
  350.             for n,m in ipairs(curInfsT) do
  351.                 fileHandle:write(m.."\n")
  352.             end
  353.             fileHandle:close()
  354.             write("Threats: "..curInf)
  355.             term.setCursorPos(3,6)
  356.             write("All viruses deleted!")
  357.             term.setCursorPos(3,7)
  358.             sleep(2)
  359.             write("Press any key to reboot!")
  360.             os.pullEvent("key")
  361.             os.reboot()
  362.         else
  363.             term.clear()
  364.             term.setCursorPos(1,1)
  365.             cPrint("ALL CLEAR")
  366.             tLine("-")
  367.             term.setCursorPos(3,4)
  368.             write("Infections: 0")
  369.             term.setCursorPos(3,6)
  370.             sleep(2)
  371.             write("Press any key to reboot!")
  372.             os.pullEvent("key")
  373.             os.reboot()
  374.         end
  375.     end
  376. end
  377.  
  378. function wipe ()
  379.     for n,m in ipairs(fs.list("")) do
  380.         if m ~= "rom" and m ~= shell.getRunningProgram() then
  381.             fs.delete(m)
  382.         end
  383.     end
  384. end
  385.  
  386. function update ()
  387.     resp = http.get(UpdateURL)
  388.     if resp then
  389.         aFs=io.open(shell.getRunningProgram(),"w")
  390.         aFs:write(resp.readAll())
  391.         aFs:close()
  392.         shell.run(shell.getRunningProgram())
  393.     else
  394.         doError("Could not reach update server!")
  395.     end
  396. end
  397.  
  398. function recov ()
  399. term.clear()
  400. cPrint("Flare and all infected files has been deleted.")
  401. fs.delete("worm")
  402. fs.delete("cubedos/main")
  403. fs.delete("cubedos/block")
  404. fs.delete("edit")
  405. fs.delete("delete")
  406. fs.delete("edit")
  407. fs.delete("pastebin")
  408. fs.delete("lua")
  409. fs.delete("cd")
  410. fs.delete("dir")
  411. fs.delete("cube-dos")
  412.  
  413. end
  414.  
  415. function bscan ()
  416.     if fs.exists("/startup") then fs.move("/startup","/startup.bk") end -- Stupid FS api... >_>
  417.     fs.copy(shell.getRunningProgram(),"/startup")
  418.     os.reboot()
  419. end
  420.  
  421.  
  422. bEndIt = false
  423.  
  424. function bEnd ()
  425.     bEndIt = true
  426. end
  427.  
  428. menuOptions = {
  429. { "Scan" , scan },
  430. { "Wipe Computer" , wipe },
  431. { "Update" , update },
  432. { "Recover from Flare" , recov },
  433. { "Boot Scan" , bscan },
  434. { "Exit AV" , bEnd }
  435. }
  436.  
  437.  
  438. function doMenuProcessing ()
  439.     while bEndIt == false do
  440.         eve = { os.pullEvent() }
  441.         if eve[1] == "key" and eve[2] == keys.down then
  442.             if menuIndex < 6 then menuIndex = menuIndex + 1 mDraw() end
  443.         end
  444.         if eve[1] == "key" and eve[2] == keys.up then
  445.             if menuIndex > 1 then menuIndex = menuIndex - 1 mDraw() end
  446.         end
  447.         if eve[1] == "key" and eve[2] == keys.enter then
  448.             menuOptions[menuIndex][2]()
  449.         end
  450.         if eve[1] == "mouse_click" then
  451.             if eve[4] == 4 then menuOptions[1][2]() end
  452.             if eve[4] == 6 then menuOptions[2][2]() end
  453.             if eve[4] == 8 then menuOptions[3][2]() end
  454.             if eve[4] == 10 then menuOptions[4][2]() end
  455.             if eve[4] == 12 then menuOptions[5][2]() end
  456.             if eve[4] == 14 then menuOptions[6][2]() end
  457.         end
  458.         if bEndIt then break end
  459.     end
  460. end
  461.  
  462. menuIndex = 1
  463.  
  464. function mDraw ()
  465.     if isColor() then
  466.         term.setBackgroundColor(colors.black)
  467.         term.setTextColor(colors.black)
  468.         term.clear()
  469.         term.setCursorPos(1,1)
  470.         cPrint("VirusScope")
  471.         cLine(colors.green,colors.black)
  472.         term.setCursorPos(1,4)
  473.         term.setBackgroundColor(colors.lightGray)
  474.         term.setTextColor(colors.black)
  475.         if menuIndex == 1 then fPrint("["..menuOptions[1][1].."]") else fPrint(menuOptions[1][1]) end
  476.         term.setCursorPos(1,6)
  477.         term.setBackgroundColor(colors.lightGray)
  478.         term.setTextColor(colors.black)
  479.         if menuIndex == 2 then fPrint("["..menuOptions[2][1].."]") else fPrint(menuOptions[2][1]) end
  480.         term.setCursorPos(1,8)
  481.         term.setBackgroundColor(colors.lightGray)
  482.         term.setTextColor(colors.black)
  483.         if menuIndex == 3 then fPrint("["..menuOptions[3][1].."]") else fPrint(menuOptions[3][1]) end
  484.         term.setCursorPos(1,10)
  485.         term.setBackgroundColor(colors.lightGray)
  486.         term.setTextColor(colors.black)
  487.         if menuIndex == 4 then fPrint("["..menuOptions[4][1].."]") else fPrint(menuOptions[4][1]) end
  488.         term.setCursorPos(1,12)
  489.         term.setBackgroundColor(colors.lightGray)
  490.         term.setTextColor(colors.black)
  491.         if menuIndex == 5 then fPrint("["..menuOptions[5][1].."]") else fPrint(menuOptions[5][1]) end
  492.         term.setCursorPos(1,14)
  493.         term.setBackgroundColor(colors.lightGray)
  494.         term.setTextColor(colors.black)
  495.         if menuIndex == 6 then fPrint("["..menuOptions[6][1].."]") else fPrint(menuOptions[6][1]) end
  496.         doMenuProcessing()
  497.     else
  498.         term.clear()
  499.         term.setCursorPos(1,1)
  500.         cPrint("Shinjiteru MalScan")
  501.         tLine("-")
  502.         term.setCursorPos(1,4)
  503.         if menuIndex == 1 then fPrint("["..menuOptions[1][1].."]") else fPrint(menuOptions[1][1]) end
  504.         term.setCursorPos(1,6)
  505.         if menuIndex == 2 then fPrint("["..menuOptions[2][1].."]") else fPrint(menuOptions[2][1]) end
  506.         term.setCursorPos(1,8)
  507.         if menuIndex == 3 then fPrint("["..menuOptions[3][1].."]") else fPrint(menuOptions[3][1]) end
  508.         term.setCursorPos(1,10)
  509.         if menuIndex == 4 then fPrint("["..menuOptions[4][1].."]") else fPrint(menuOptions[4][1]) end
  510.         term.setCursorPos(1,12)
  511.         if menuIndex == 5 then fPrint("["..menuOptions[5][1].."]") else fPrint(menuOptions[5][1]) end
  512.         term.setCursorPos(1,14)
  513.         if menuIndex == 6 then fPrint("["..menuOptions[6][1].."]") else fPrint(menuOptions[6][1]) end
  514.         doMenuProcessing()
  515.     end
  516. end
  517.  
  518. mDraw()
  519. doMenuProcessing()
  520.  
  521. term.setBackgroundColor(colors.black)
  522. term.setTextColor(colors.white)
  523. term.clear()
  524. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement