Anti Inject for games?

Hi, a few months ago i saw some games has an anti inject and this made me wondered how did they do that, but i haven’t to see any kind of that anti recently idk if it was patched by the developer of the executer, is there anyway to prevent anti exploit or anti inject ?

Some bad exploits modify client in a way the game can detect what’s been manipulated or done. For example: this is how you used to detect SirHurt:

game:GetService("LogService").MessageOut:Connect(function(msg)
    if string.find(msg, "INIT SCRIPT") then
       game.Players.LocalPlayer:Kick("SirHurt detected")
    end
end)

SirHurt for whatever stupid reason logged when exploit injected into the console, this is easily detectable, but of course the patch to this is just as simple as not logging.

You should less focus on detecting an exploit and focus on detecting client manipulations (walkspeed change, teleportation, etc)

I personally use a custom anti-inject script that I made for my game. I haven’t been able to test it out yet; however, I do have some knowledge (that I gained from “things” I cannot disclose) about executor injections, so I made this script based off of that knowledge. It’s quite simple, really. It just checks if any instances are added to the game that shouldn’t be there. If it detects any, it fires a remote event for the server to kick the player. Note that this script is a local script because all exploits (afaik) are client-sided.

Script
--    AntiCheatClient script
-- (located in ReplicatedFirst)

-- Not really any point other than to make this script harder to locate by exploiters
script.Name = math.random(100_000_000, 999_999_999)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local anticheatEvent = ReplicatedStorage:WaitForChild("AntiCheatEvent")

local player = game.Players.LocalPlayer

-- List of valid children of the game object (self explanatory) so it doesn't flag for services
local validChildren = {
	["Workspace"] = "Workspace",
	["Run Service"] = "RunService",
	["GuiService"] = "GuiService",
	["Stats"] = "Stats",
	["TimerService"] = "TimerService",
	["SoundService"] = "SoundService",
	["VideoCaptureService"] = "VideoCaptureService",
	["LogService"] = "LogService",
	["MicroProfilerService"] = "MicroProfilerService",
	["ContentProvider"] = "ContentProvider",
	["KeyframeSequenceProvider"] = "KeyframeSequenceProvider",
	["AnimationClipProvider"] = "AnimationClipProvider",
	["Chat"] = "Chat",
	["MarketplaceService"] = "MarketplaceService",
	["Players"] = "Players",
	["PointsService"] = "PointsService",
	["NotificationService"] = "NotificationService",
	["ReplicatedFirst"] = "ReplicatedFirst",
	["HttpRbxApiService"] = "HttpRbxApiService",
	["TweenService"] = "TweenService",
	["MaterialService"] = "MaterialService",
	["TextChatService"] = "TextChatService",
	["TextService"] = "TextService",
	["PermissionsService"] = "PermissionsService",
	["SharedTableRegistry"] = "SharedTableRegistry",
	["StarterPlayer"] = "StarterPlayer",
	["StarterPack"] = "StarterPack",
	["StarterGui"] = "StarterGui",
	["CoreGui"] = "CoreGui",
	["LocalizationService"] = "LocalizationService",
	["PolicyService"] = "PolicyService",
	["Teleport Service"] = "TeleportService",
	["JointsService"] = "JointsService",
	["CollectionService"] = "CollectionService",
	["PhysicsService"] = "PhysicsService",
	["BadgeService"] = "BadgeService",
	["FriendService"] = "FriendService",
	["InsertService"] = "InsertService",
	["GamePassService"] = "GamePassService",
	["Debris"] = "Debris",
	["CookiesService"] = "CookiesService",
	["Selection"] = "Selection",
	["UserInputService"] = "UserInputService",
	["KeyboardService"] = "KeyboardService",
	["MouseService"] = "MouseService",
	["VRService"] = "VRService",
	["ContextActionService"] = "ContextActionService",
	["ScriptService"] = "ScriptService",
	["AssetService"] = "AssetService",
	["TouchInputService"] = "TouchInputService",
	["BrowserService"] = "BrowserService",
	["CaptureService"] = "CaptureService",
	["AnalyticsService"] = "AnalyticsService",
	["PublishService"] = "PublishService",
	["ChangeHistoryService"] = "ChangeHistoryService",
	["LuaWebService"] = "LuaWebService",
	["ProcessInstancePhysicsService"] = "ProcessInstancePhysicsService",
	["ReplicatedStorage"] = "ReplicatedStorage",
	["ServerScriptService"] = "ServerScriptService",
	["ServerStorage"] = "ServerStorage",
	["NetworkClient"] = "NetworkClient",
	["StudioService"] = "StudioService",
	["Script Context"] = "ScriptContext",
	["ServiceVisibilityService"] = "ServiceVisibilityService",
	["PathfindingService"] = "PathfindingService",
	["PluginGuiService"] = "PluginGuiService",
	["StreamingService"] = "StreamingService",
	["SelectionHighlightManager"] = "SelectionHighlightManager",
	["RemoteDebuggerServer"] = "RemoteDebuggerServer",
	["DebuggerManager"] = "DebuggerManager",
	["ScriptEditorService"] = "ScriptEditorService",
	["HapticService"] = "HapticService",
	["HttpService"] = "HttpService",
	["VoiceChatService"] = "VoiceChatService",
	["Visit"] = "Visit",
	["GuidRegistryService"] = "GuidRegistryService",
	["Lighting"] = "Lighting",
	["Teams"] = "Teams",
	["FeatureRestrictionManager"] = "FeatureRestrictionManager",
	["CommerceService"] = "CommerceService",
	["TestService"] = "TestService",
	["AdService"] = "AdService",
	["SocialService"] = "SocialService",
	["ProximityPromptService"] = "ProximityPromptService",
	["AvatarCreationService"] = "AvatarCreationService",
	["GenerationService"] = "GenerationService",
	["ScriptProfilerService"] = "ScriptProfilerService",
	["HeapProfilerService"] = "HeapProfilerService",
	["FilteredSelection"] = "",
	["MeshContentProvider"] = "MeshContentProvider",
	["SolidModelContentProvider"] = "SolidModelContentProvider",
	["HSRDataContentProvider"] = "HSRDataContentProvider",
	["VideoService"] = "VideoService",
	["PackageService"] = "PackageService",
	["GamepadService"] = "GamepadService",
	["MemStorageService"] = "MemStorageService",
	["UserService"] = "UserService",
	["GenericChallengeService"] = "GenericChallengeService",
	["GroupService"] = "GroupService",
	["UGCValidationService"] = "UGCValidationService",
	["CreatorStoreService"] = "CreatorStoreService",
	["AvatarEditorService"] = "AvatarEditorService",
	["TextBoxService"] = "TextBoxService",
	["ControllerService"] = "ControllerService",
	["PluginDebugService"] = "PluginDebugService",
	["DraggerService"] = "DraggerService",
	["StylingService"] = "StylingService",
	["UniqueIdLookupService"] = "UniqueIdLookupService",
	["PluginManagementService"] = "PluginManagementService",
	["RemoteCommandService"] = "RemoteCommandService",
	["Geometry"] = "Geometry",
	["DataStoreService"] = "DataStoreService",
	["UIDragDetectorService"] = "UIDragDetectorService",
	["SpawnerService"] = "SpawnerService",
	["ExperienceNotificationService"] = "ExperienceNotificationService",
	["PlayerViewService"] = "PlayerViewService",
	["VoiceChatInternal"] = "VoiceChatInternal",
	
	-- Without this, if you use Rojo, it would detect you as an exploiter
	["Rojo"] = "ModuleScript"
}

local kicked = false

local function validateChild(child: Instance)
	if validChildren[child.Name] and validChildren[child.Name] == child.ClassName then return end

	local success, err = pcall(function()
		child.Parent = child.Parent
		local new = Instance.new(child.ClassName)
		if new then
			new:Destroy()
		end
	end)

	if not success then return end

	print(child.Name, child.ClassName)
	warn("Exploiter Detected: "..player.Name)
	
	repeat
		player:Kick()
		anticheatEvent:FireServer()
		-- Intentionally lags out the player while spamming the remote event
	until kicked or not player or not player.Parent
	
	child:Destroy()
end

for _, child in pairs(game:GetChildren()) do
	validateChild(child)
end

game.ChildAdded:Connect(function(child)
	validateChild(child)
end)

anticheatEvent.OnClientEvent:Once(function()
	kicked = true
	player:Kick()
end)

-- Tested this out in studio. Doesn't work, but I'll leave it here.
script:GetPropertyChangedSignal("Enabled"):Connect(function()
	script.Parent.Enabled = true
end)

Feel free to point out any issues or make any modifications. The goal is to defend our games against exploiters.

P.S. Now that I’ve shared this script publicly, someone might bypass my anti-cheat when my game releases :sob:

  1. this is obvious, but client-side scripts can always be disabled. and their executor’s vm runs before ReplicatedFirst
  2. exploits can create “fake” instances and inject them to memory. or just hook child.ClassName because its mutable
  3. iirc, this check fails for legit roblox classes (readonly services such as CoreGui)
  1. again, this can be obviously spoofed (either hook the event or spoof the LocalPlayer). also this may just lag the server
  1. same stuff, and this will not age well when roblox updates with a new service
  1. checking script.Enabled doesnt really do anything
  2. exploits doesnt use real luau vm/instances. they just simulate it
  3. have you heard of security through obscurity

*most of these may actually be prevented by byfron though, but your script has quite some false flags

Thanks for the criticism and harsh-and-rude-but-constructive feedback (remember, we are on the same side—I think). I made some changes to my script recently, and I just updated it, but that didn’t really cover much of what you said.

I know that. I mentioned that in a comment in my script.

Yeah, I should have provided my server code, which does have some “measures” against this, but still not the most efficient. The thing is, I’m fine with the server lagging every once in a while to potentially get rid of an exploiter.

That’s why I have the static table :slight_smile:

Right, right, and right. Thanks.

I’m guessing you mean obfuscation? Sorry, I’ve heard that “saying” before, but I’m not quite sure what your point is. I think it would be far more productive if you could elaborate on points like these—clarity is key.


Again, thanks a lot for these points. These kinds of analyses and questions are crucial to developing counters to exploiters. Working together as a community is key. That said, do you have any possible suggestions and proposals to help solve the problem?

basically obfuscation yeah, what i was trying to say is that obscuring the name doesnt really help (i know about the comment but this just doesnt do anything)

Yeah, I’m kind of doing whatever. I know it doesn’t help, but in my eyes, the more, the better.

Most of them attempt to detect the traces each exploit may leave behind. Things such as memory spikes, specific images being preloaded, console messages, automated chat messages, specific instances, etc.

Although I would advice against it. It’s better if you focus on fixing your game vulnerabilities instead. If anything, exploiters help by pointing out the holes in your game logic. For example by logging their actions or playing your game with an alt/hidden account you can somewhat figure out what the cheats they develop do, and thus get feedback from them to make your game more secure.

there is no “global” anti-inject for games.

As others have mentioned, mosf of these rely on detection methods, accidents left by the developers, to detect abnormal behaviour. These are executor-specific.

You will always be at a disadvantage to the exploiter, they have way more power than you. That being said, alongside strengthening your server protection, a client anticheat implementing a few of these methods and maybe some other bits still helps to catch a lot of script kiddies.