noPE

Prestige Gaming BHop Anticheat

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