Anthr4x292

Lua File Security

Feb 16th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. /* It is actually illegal for the server to read your private files unless you agreed to it */
  2.  
  3. // Lua file security by Anthr4x292
  4. // Feel free to troll anti cheats with file stealers or enter any server safely.
  5.  
  6. local file = file
  7. local SLASH = "[\\/]+"
  8.  
  9. local _file = {}
  10.     _file.Read = file.Read
  11.     _file.Find = file.Find
  12.     _file.FindDir = file.FindDir
  13.     _file.FindInLua = file.FindInLua
  14.     _file.Exists = file.Exists
  15.     _file.Delete = file.Delete
  16.  
  17. local blacklist =
  18. {
  19.     "lua" .. SLASH,
  20.     "addons" .. SLASH,
  21.     "cfg" .. SLASH
  22. }
  23.  
  24. local whitelist =
  25. {
  26.     "gmod_tool" .. SLASH,
  27.     "wire" .. SLASH .. "gates",
  28.     "wire" .. SLASH .. "uwsvn_load",
  29.     "entities" .. SLASH .. "gmod_wire_egp",
  30.     "entities" .. SLASH .. "gmod_emitter",
  31.     "gamemode" .. SLASH .. "FAdmin",
  32.     "ulib" .. SLASH .. "modules",
  33.     "ulx" .. SLASH .. "modules",
  34. }
  35.  
  36. local function RandomNum(t)
  37.     if t then
  38.         local _T = {}
  39.  
  40.         for i = 0, math.Round(math.random(1, 15)) do
  41.             table.insert(_T, math.Round(math.random(10000000, 99999999)))
  42.         end
  43.  
  44.         return _T
  45.     else
  46.         return math.Round(math.random(10000000, 99999999))
  47.     end
  48. end
  49.  
  50. local function IsWhiteListed(f)
  51.     for k, v in pairs(whitelist) do
  52.         if string.match(f, v) then
  53.             return true
  54.         end
  55.     end
  56. end
  57.  
  58. // Start detouring the functions
  59. function file.Read(f, use_base_folder)
  60.     if use_base_folder then
  61.         for k, v in pairs(blacklist) do
  62.             if string.match(f, v) then
  63.                 if not IsWhiteListed(f) then
  64.                     MsgN("Lua File Security: Disallowed file read '" .. f .. "'!")
  65.                     return RandomNum(false)
  66.                 end
  67.             end
  68.         end
  69.     end
  70.  
  71.     return _file.Read(f, use_base_folder)
  72. end
  73.  
  74. function file.Find(f, use_base_folder)
  75.     if use_base_folder then
  76.         for k, v in pairs(blacklist) do
  77.             if string.match(f, v) then
  78.                 if not IsWhiteListed(f) then
  79.                     MsgN("Lua File Security: Illegal file scan on folder '" .. f .. "'!")
  80.                     return RandomNum(true)
  81.                 end
  82.             end
  83.         end
  84.     end
  85.  
  86.     return _file.Find(f, use_base_folder)
  87. end
  88.  
  89. function file.FindDir(f, use_base_folder)
  90.     if use_base_folder then
  91.         for k, v in pairs(blacklist) do
  92.             if string.match(f, v) then
  93.                 if not IsWhiteListed(f) then
  94.                     MsgN("Lua File Security: Illegal folder scan on folder '" .. f .. "'!")
  95.                     return RandomNum(true)
  96.                 end
  97.             end
  98.         end
  99.     end
  100.  
  101.     return _file.FindDir(f, use_base_folder)
  102. end
  103.  
  104. function file.FindInLua(f)
  105.     if not IsWhiteListed(f) then
  106.         MsgN("Lua File Security: Disallowed lua file scan on folder '" .. f .. "'!")
  107.         return RandomNum(true)
  108.     end
  109.  
  110.     return _file.FindInLua(f, use_base_folder)
  111. end
  112.  
  113. function file.Exists(f, use_base_folder)
  114.     if use_base_folder then
  115.         for k, v in pairs(blacklist) do
  116.             if string.match(f, v) then
  117.                 if not IsWhiteListed(f) then
  118.                     MsgN("Lua File Security: Disallowed file existance check '" .. f .. "'!")
  119.                     return false
  120.                 end
  121.             end
  122.         end
  123.     end
  124.  
  125.     return _file.Exists(f, use_base_folder)
  126. end
Advertisement
Add Comment
Please, Sign In to add comment