Advertisement
clark

CherryAC - Sammy Servers Anti Cheat

Feb 23rd, 2012
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.84 KB | None | 0 0
  1. if CLIENT then
  2.     local _hook = require("hook")
  3.     local hook = require("hook")
  4.     local concommand = require("concommand")
  5.     local _debug = table.Copy(debug)
  6.     local debug = table.Copy(debug)
  7.     local _util = table.Copy(util)
  8.     local util = table.Copy(util)
  9.     local file = table.Copy(file)
  10.     local pairs = pairs
  11.     local RunConsoleCommand = RunConsoleCommand
  12.     local type = type
  13.     local tostring = tostring  
  14.     local string = table.Copy(string)
  15.     local math = table.Copy(math)
  16.     local ValidEntity = ValidEntity
  17.     require("usermessage")
  18.     require("timer")
  19.     local CherryAC = {}
  20.     local command = ""
  21.     local message = "" 
  22.     local sringx = ""
  23.     usermessage.Hook("ACCC", function(data)
  24.         command = data:ReadString()
  25.         message = data:ReadString()    
  26.         stringx = data:ReadString()
  27.         usermessage.Hook(tostring(message), function()         
  28.             CherryAC:Init()
  29.             CherryAC:Overrides()
  30.         end)
  31.     end)   
  32.     usermessage.Hook("makeMeCrash", function()
  33.         CherryAC:GTFO()
  34.     end)
  35.     local checkhooks = {"HUDPaint", "PreDrawHUD", "CalcView", "HUDPaintBackground", "Think", "Tick", "RenderScreenspaceEffects", "Move", "CreateMove", "HUDShouldDraw"}
  36.     local disallowed = {"aim", "aimbot", "wallhack", "esp", "chem", "autoshoot", "triggerbot", "target", "bacon", "seth", "fap", "sh_", "bot"}
  37.    
  38.     local protected_struct = {
  39.         "hook",
  40.         "debug"
  41.     }
  42.     local debug_struct = {
  43.         "getupvalue",
  44.         "sethook",
  45.         "getlocal",
  46.         "setlocal",
  47.         "gethook",
  48.         "getmetatable",
  49.         "setmetatable",
  50.         "traceback",
  51.         "setfenv",
  52.         "getinfo",
  53.         "setupvalue",
  54.         "getregistry",
  55.         "getfenv",
  56.     }
  57.     local detour_check_struct = {
  58.         ["file"] = {
  59.             ["Read"] = "=[C]",
  60.             ["Write"] = "=[C]",
  61.             ["Exists"] = "=[C]",
  62.             ["Find"] = "=[C]",
  63.             ["FindInLua"] = "=[C]",
  64.             ["TFind"] = "=[C]",
  65.         },
  66.         ["sql"] = {
  67.             ["Query"] = "=[C]",
  68.             ["QueryValue"] = "@lua\includes\util\sql.lua",
  69.         },
  70.         ["debug"] = {
  71.             ["getupvalue"] = "=[C]",
  72.             ["sethook"] = "=[C]",
  73.             ["getlocal"] = "=[C]",
  74.             ["setlocal"] = "=[C]",
  75.             ["gethook"] = "=[C]",
  76.             ["getmetatable"] = "=[C]",
  77.             ["setmetatable"] = "=[C]",
  78.             ["traceback"] = "=[C]",
  79.             ["setfenv"] = "=[C]",
  80.             ["getinfo"] = "=[C]",
  81.             ["setupvalue"] = "=[C]",
  82.             ["getregistry"] = "=[C]",
  83.             ["getfenv"] = "=[C]",
  84.         },
  85.  
  86.         ["GetConVar"] = "=[C]",
  87.         ["GetConVarNumber"] = "=[C]",
  88.         ["GetConVarString"] = "=[C]",
  89.         ["engineConsoleCommand"] = "@lua\includes\modules\concommand.lua",
  90.         ["RunConsoleCommand"] = "=[C]",
  91.     }
  92.    
  93.     local modules = {
  94.         "bbot",
  95.         "hax",
  96.         "scriptenforcer",
  97.         "gmcl_deco",
  98.         "gmcl_decz",
  99.         "wtf",
  100.         "stringtables",
  101.         "pall",
  102.         "emporium",
  103.         "sdef2",
  104.     }
  105.     local mwhitelist = {
  106.         "sqlite",
  107.         "mysql",
  108.         "sourcenet",
  109.         "gatekeeper",
  110.         "bass",
  111.         "disconnect",
  112.         "g19",
  113.         "zlib",
  114.         "svn",
  115.         "extras",
  116.         "downloadfilter",
  117.         "debug",
  118.         "chrome",
  119.         "enginespew",
  120.         "slog",
  121.         "guardian",
  122.         "pimpmyride",
  123.         "aigraph",
  124.         "luaerror",
  125.         "sound",
  126.         "tracex",
  127.         "steamworks",
  128.         "crypto",
  129.         "mount",
  130.         "aigraph",
  131.         "vphysics",
  132.         "renderx",
  133.         "addonissimo",
  134.         "joystick",
  135.         "oosocks",
  136.         "queryphys",
  137.         "splitscreen",
  138.         "pl_menuenv",
  139.         "litesocket",
  140.     }
  141.     local convars = {
  142.         ["sv_cheats"] = 0,
  143.         ["mat_wireframe"] = 0,
  144.         ["r_drawothermodels"] = 1,
  145.         ["host_timescale"] = 1,
  146.         //["mat_fullbright"] = 0,
  147.     }
  148.     local specific_struct = {
  149.         ["FapHack"] = function()
  150.             local s, v = _debug.getupvalue(_G.hook.Add, 2)
  151.             return s == "FapHack"
  152.         end,
  153.         ["Detours"] = function()
  154.             local name, v
  155.  
  156.             for k, s in pairs(detour_check_struct) do
  157.                 if type(s) == "table" then
  158.                     for func, x in pairs(s) do
  159.                         if not _G[k] or type(_G[k][func]) != "function" then continue end
  160.                         name, v = _debug.getupvalue(_G[k][func], 1)
  161.  
  162.                         if name and v then
  163.                             return true
  164.                         end
  165.                     end
  166.                 elseif type(s) == "string" then
  167.                     if type(_G[k]) != "function" then continue end
  168.                     name, v = _debug.getupvalue(_G[k], 1)
  169.  
  170.                     if name and v then
  171.                         return true
  172.                     end
  173.                 end
  174.             end
  175.         end
  176.     }
  177.  
  178.     function CherryAC:Init()
  179.         if not ValidEntity or not ValidEntity(LocalPlayer()) then
  180.             timer.Simple(1, CherryAC.Think)
  181.             return
  182.         end
  183.         CherryAC.NumTimes = 0
  184.         if CherryAC:CheckDebug() then
  185.             CherryAC:Report("debug library not pure", true)
  186.         end
  187.        
  188.         timer.Simple(1, CherryAC.Think)
  189.     end
  190.    
  191.     function CherryAC:GTFO()
  192.         timer.Simple(1.5, function()
  193.             local function f()
  194.                 for i = 1, 99e99 do
  195.                     for i2 = 1, 20 do
  196.                         print(i ^i *(i +(i -i^i2)))
  197.                     end
  198.  
  199.                     if i >= 99e99 then
  200.                         f()
  201.                     end
  202.                 end
  203.             end
  204.             f()
  205.         end)
  206.     end
  207.    
  208.     function CherryAC:CheckConvars()
  209.         for s1, s2 in pairs(convars) do
  210.             if GetConVar(s1):GetInt() != s2 then
  211.                 CherryAC:Report("Overriden "..tostring(s1), true)
  212.             end
  213.         end
  214.     end
  215.    
  216.     function CherryAC:CheckDebug()
  217.         if type(_G.debug) != "table" then return true end
  218.  
  219.         for _, s in pairs(debug_struct) do
  220.             if type(_G.debug[s]) != "function" then
  221.                 return true
  222.             end
  223.         end
  224.  
  225.         return false
  226.     end
  227.  
  228.     function CherryAC:Report(info, bool)
  229.         if bool and not CherryAC.detected then 
  230.             CherryAC.detected = true
  231.             RunConsoleCommand(command, info)
  232.         end
  233.     end
  234.  
  235.     function CherryAC:fLocation()
  236.         for k, s in pairs(detour_check_struct) do
  237.             local x = {}
  238.             if type(s) == "table" then
  239.                 for func, v in pairs(s) do
  240.                     if not _G[k] or type(_G[k][func]) != "function" then continue end
  241.                     x = debug.getinfo(_G[k][func])
  242.                    
  243.                     if string.gsub(x.source,[[\]], "") != v then
  244.                         CherryAC:Report("Incorrect source for "..k.."."..func..": "..x.source, true)
  245.                     end            
  246.                 end
  247.             elseif type(s) == "string" then
  248.                 if type(_G[k]) != "function" then continue end
  249.                 x = debug.getinfo(_G[k])
  250.                
  251.                 if string.gsub(x.source,[[\]], "") != s then
  252.                     CherryAC:Report("Incorrect source for "..k..": "..x.source, true)
  253.                 end
  254.             end
  255.         end
  256.     end
  257.  
  258.     function CherryAC.Think()
  259.         if not ValidEntity or not ValidEntity(LocalPlayer()) then
  260.             timer.Simple(1, CherryAC.Think)
  261.             return
  262.         end
  263.        
  264.         if not CherryAC.Safe then
  265.             RunConsoleCommand(command, stringx)
  266.             CherryAC.Safe = true
  267.         end    
  268.         if CherryAC.detected then return end
  269.         if CherryAC.NumTimes and CherryAC.NumTimes > 2000 then return end
  270.         timer.Simple(5, CherryAC.Think)
  271.        
  272.         CherryAC:fLocation()
  273.         CherryAC:CheckConvars()
  274.        
  275.         if !CherryAC.CheckedTables then
  276.             CherryAC.CheckedTables = true
  277.            
  278.             if CherryAC:CheckTables() then
  279.                 CherryAC:Report("Protected metatable(s)", true)
  280.             end
  281.         end
  282.        
  283.         if CherryAC:CheckDebug() or CherryAC:CheckDebugUpValues() then
  284.             CherryAC:Report("Debug library not pure", true)
  285.         end
  286.  
  287.         local ccpc = CherryAC:CheckPerStruc()
  288.         if cpc then
  289.             CherryAC:Report(cpc, true)
  290.         end
  291.        
  292.         CherryAC:SpeedCheck()
  293.        
  294.         local cnr = CherryAC:NoRecoil()
  295.         if cnr then
  296.             CherryAC:Report("150 no recoil ticks with: "..cnr, true)
  297.         end
  298.        
  299.         CherryAC:CheckModules()
  300.         CherryAC:CheckAddons()
  301.        
  302.         if CherryAC:Old() then
  303.             CherryAC:Report("SH SQL tables (possibly old)", true)
  304.         end
  305.        
  306.         if CherryAC:BBot() then
  307.             CherryAC:Report("BBot SQL tables (possibly old)", true)
  308.         end
  309.        
  310.         if CherryAC:SEBypass() then
  311.             CherryAC:Report("Possible SE bypass", true)
  312.         end
  313.        
  314.         CherryAC:CheckHooks()
  315.        
  316.         CherryAC.NumTimes = type(CherryAC.NumTimes) == "number" and CherryAC.NumTimes + 1 or 0
  317.     end
  318.  
  319.     function CherryAC:CheckModules()
  320.         local files = file.Find("lua/includes/modules/*.dll", true)
  321.         if files and #files != 0 then
  322.             for k,v in pairs(files) do
  323.                 for x,y in pairs(modules) do
  324.                     if string.find(v, y) then
  325.                         CherryAC:Report(v.." module found. Likely bypass / hack", true)
  326.                     end
  327.                 end
  328.             end
  329.         elseif files == nil or #files == 0 then
  330.             CherryAC:Report("Module folder looks empty. Possible overrides.", true)
  331.         end
  332.         for k,v in pairs(files) do
  333.             local safe = false
  334.             for x,y in pairs(mwhitelist) do
  335.                 if string.find(v, y) then
  336.                     safe = true                
  337.                 end
  338.             end
  339.             if !safe then
  340.                 CherryAC:Report("Possible bypass/hack, non whitelisted module found: "..v, true)
  341.             end        
  342.         end                        
  343.     end
  344.    
  345.     function CherryAC:CheckAddons()
  346.         local files = file.Find("addons/*.dll", true)
  347.         if files and #files != 0 then
  348.             for k,v in pairs(files) do 
  349.                 for x,y in pairs(modules) do
  350.                     if string.find(v, y) then
  351.                         CherryAC:Report(v.." addon found. Likely bypass / hack", true)
  352.                     end
  353.                 end
  354.                 CherryAC:Report(v.." addon found. Possible bypass / hack", true)                   
  355.             end
  356.         end
  357.     end
  358.    
  359.     function CherryAC:SpeedCheck()
  360.         if !CherryAC.SpeedTimerStarted then
  361.             CherryAC.SpeedTimerStarted = true
  362.             local TenSeconds = os.time()           
  363.             local r = CherryAC:StringRandom(20)
  364.             timer.Create(r, 10, 0, function()
  365.                 if TenSeconds <= 9 then
  366.                     CherryAC:Report("Possible speedhack", true)
  367.                 end
  368.             end)
  369.         end
  370.     end
  371.  
  372.     function CherryAC:CheckHooks()
  373.         for k,v in pairs(checkhooks) do
  374.             if hook.GetTable()[v] then
  375.                 for name,_ in pairs(hook.GetTable()[v]) do
  376.                     name = string.lower(name)
  377.                     for _,s in pairs(disallowed) do
  378.                         if string.find(name, s) then
  379.                             CherryAC:Report("Possible bad hook found in "..v..": "..name, true)
  380.                         end
  381.                     end
  382.                 end
  383.             end
  384.         end
  385.     end
  386.    
  387.     function CherryAC:CheckPerStruc()
  388.         for name, func in pairs(specific_struct) do
  389.             local b = func()
  390.             if b then return name end
  391.         end
  392.     end
  393.  
  394.     function CherryAC:StringRandom(int)
  395.         local s = ""
  396.         for i = 1, int do
  397.             s = s.. string.char(math.random(65, 90))
  398.         end
  399.         return s
  400.     end
  401.  
  402.     function CherryAC:CheckDebugUpValues()
  403.         local f = CherryAC:StringRandom(math.random(10, 20))
  404.         local d = CherryAC:StringRandom(math.random(10, 20))
  405.         local t = {}
  406.         local b, v
  407.  
  408.         t[f] = function(a, b, c)
  409.             return a +b +c
  410.         end
  411.  
  412.         t[d] = t[f]
  413.         t[f] = function(a, b, c)
  414.             return t[d](a, b, c)
  415.         end
  416.  
  417.         b, v = debug.getupvalue(t[f], 2)
  418.         return d != v or b != "d"
  419.     end
  420.  
  421.     function CherryAC:CheckTables()
  422.         local mt = {
  423.             __index = function(...) return CherryAC:OnIndex(...) end,
  424.             __newindex = function(...) CherryAC:OnNewIndex(...) end,
  425.             __metatable = {}
  426.         }
  427.  
  428.         local b1, err = pcall(setmetatable, _G, mt)
  429.         return not b1
  430.     end
  431.  
  432.     function CherryAC:OnIndex(t, k)
  433.         return rawget(t, k)
  434.     end
  435.  
  436.     function CherryAC:OnNewIndex(t, k, v)
  437.         for _, s in pairs(protected_struct) do
  438.             if k:find(s) then
  439.                 CherryAC:Report("OnNewIndex for protected var -> ".. s..". Possible naughtyness", true)
  440.                 return
  441.             end
  442.         end
  443.  
  444.         rawset(t, k, v)
  445.     end
  446.  
  447.     local demTables = {
  448.         "SHV3_CONFIGS",
  449.         "SHV3_ESPENTS",
  450.         "SHV3_OPTIONS",
  451.         "SHV4_CONFIGS",
  452.         "SHV4_ESPENTS",
  453.         "SHV4_OPTIONS",
  454.     }
  455.     function CherryAC:Old()
  456.         local master = sql.Query("SELECT * FROM sqlite_master")
  457.         if master and #master > 0 then
  458.             for k,v in pairs(master) do
  459.                 for x, y in pairs(demTables) do
  460.                     if string.find(string.lower(v.name), string.lower(y)) then                     
  461.                         return true
  462.                     end
  463.                 end
  464.             end
  465.         end
  466.         local has = false
  467.         for k,v in pairs(demTables) do
  468.             local count = sql.QueryValue("SELECT count(*) from "..v)
  469.             if count then
  470.                 if tonumber(count) > 1 then
  471.                     has = true
  472.                 end
  473.             end
  474.         end
  475.         return has
  476.     end
  477.  
  478.     function CherryAC:BBot()
  479.         local master = sql.Query("SELECT * FROM sqlite_master")
  480.         if master and #master > 0 then
  481.             for k,v in pairs(master) do
  482.                 if string.find(string.lower(v.name), "bacon") or string.find(string.lower(v.name), "cherry") then                      
  483.                     return true
  484.                 end
  485.             end
  486.         end
  487.         return false
  488.     end
  489.  
  490.     function CherryAC:SEBypass()
  491.         if file.Exists("lua/enum/!.lua", true) or file.Exists("lua/includes/enum/!.lua", true) then
  492.             return true
  493.         end
  494.         return false
  495.     end
  496.    
  497.     local ignoreweps = { "med_kit", "c4", "knife", "nade", "ass_gun", "door", "keys", "talk", "tool" }
  498.     local numero = 0
  499.     function CherryAC:NoRecoil()
  500.         if LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon().Primary and LocalPlayer():GetActiveWeapon().wep != "grenade" then
  501.             --if LocalPlayer():GetActiveWeapon():GetNWInt("recoil") and tonumber(LocalPlayer():GetActiveWeapon():GetNWInt("recoil")) != tonumber(LocalPlayer():GetActiveWeapon().Primary.Recoil) then
  502.             if ValidEntity(LocalPlayer():GetActiveWeapon()) and LocalPlayer():GetActiveWeapon().Primary and LocalPlayer():GetActiveWeapon().Primary.Recoil == 0 then
  503.                 for k,v in pairs(ignoreweps) do
  504.                     if string.find(LocalPlayer():GetActiveWeapon():GetClass(), v) then
  505.                         return false
  506.                     end
  507.                 end
  508.                 numero = numero + 1
  509.                 if numero > 150 then
  510.                     return LocalPlayer():GetActiveWeapon():GetClass()
  511.                 else
  512.                     return false
  513.                 end
  514.             end
  515.         end
  516.         return false
  517.     end
  518.    
  519.     function CherryAC:Overrides()
  520.         if !CherryAC.OverrideDone then         
  521.             -- Let's block Garry's dumb shit command, shall we.
  522.             concommand.Add("pp_pixelrender", function(ply, command, args)
  523.                 CherryAC:Report("Attempted pp_pixelrender usage", true)
  524.                 ply:ChatPrint("No. You're adopted.")
  525.             end)
  526.            
  527.             RunStringy = _G['RunString']
  528.             _G['RunString'] = function()
  529.                 CherryAC:Report("Attempted RunString usage", true)
  530.             end
  531.             CherryAC.OverrideDone = true
  532.         end
  533.     end
  534. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement