Advertisement
McMrARM

CC antivirus

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