From 06f4f8bf00cab403d9570aff582fbf01ca4dd8cc Mon Sep 17 00:00:00 2001 From: miniduikboot Date: Sat, 23 May 2026 12:52:26 +0200 Subject: [PATCH] Gate PackedGameDataTo behind AC check --- docs/Server-configuration.md | 29 ++++----- src/Impostor.Api/CheatCategory.cs | 3 + src/Impostor.Api/Config/AntiCheatConfig.cs | 2 + src/Impostor.Api/Net/Messages/MessageFlags.cs | 7 ++- src/Impostor.Server/Net/Client.cs | 61 +++++++++---------- 5 files changed, 55 insertions(+), 47 deletions(-) diff --git a/docs/Server-configuration.md b/docs/Server-configuration.md index a39b3c5..6189129 100644 --- a/docs/Server-configuration.md +++ b/docs/Server-configuration.md @@ -25,20 +25,21 @@ Impostor has an Http Server that is used by recent versions of Among Us to conne Impostor has an Anticheat that makes it possible to kick cheaters from games automatically. Note that the anticheat is tuned on the vanilla version of the game, so client-side modifications could trigger the Anticheat if you're playing with them. -| Key | Default | Value | -|-------------------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **Enabled** | `true` | Whether the anticheat should be enabled. | -| **BanIpFromGame** | `true` | When anticheat is enabled and a player is caught hacking, they will be kicked from the server. If this value is set to `true`, the player will be banned instead and will not be able to rejoin that specific game. | -| **AllowCheatingHosts** | `"Never"` | Configure whether hosts are allowed to cheat. "Never" forbids it, "Always" allows it. "IfRequested" allows hosts to cheat if they connect with the DisableServerAuthorityFlag set. | -| **EnableGameFlowChecks** | `true` | Enable checks that check if certain actions are done in the appropriate order or at the appropriate moment in the game. This includes changing cosmetics while in game or murdering too fast. | -| **EnableInvalidObjectChecks** | `true` | Enables checks that check if network objects are spawned properly. Disabling this option also implies disabling EnableRoleChecks. | -| **EnableMustBeHostChecks** | `true` | Enables checks that check if players are the host before they can do actions that require them to be host of the game. This includes starting the game and spawning objects. | -| **EnableColorLimitChecks** | `true` | Enables checks that checks if players request colors that are already in use. | -| **EnableNameLimitChecks** | `true` | Enables checks that checks if player names have a length that is possible to set using the user interface. | -| **EnableOwnershipChecks** | `true` | Enables checks that check if players are allowed to perform a certain action on themself or another player. | -| **EnableRoleChecks** | `true` | Enables checks that check if players have the correct role when performing certain role abilities like venting or murdering. | -| **EnableTargetChecks** | `true` | Enables checks that check if certain packets to everyone that should only have been sent to certain players or vice versa. This includes sending votes or network objects. | -| **ForbidProtocolExtensions** | `true` | If disabled allows players to send network packets that go beyond the network packets sent by the vanilla game. This is necessary for most mods that need all players to install it. | +| Key | Default | Value | +|-------------------------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **Enabled** | `true` | Whether the anticheat should be enabled. | +| **BanIpFromGame** | `true` | When anticheat is enabled and a player is caught hacking, they will be kicked from the server. If this value is set to `true`, the player will be banned instead and will not be able to rejoin that specific game. | +| **AllowCheatingHosts** | `"Never"` | Configure whether hosts are allowed to cheat. "Never" forbids it, "Always" allows it. "IfRequested" allows hosts to cheat if they connect with the DisableServerAuthorityFlag set. | +| **AllowHostOnlyExtensions** | "IfRequested" | Configure whether [Host-Only extensions](https://github.com/Innersloth-LLC/AmongUsModdingInformation#host-only-mods) are allowed in all games ("Always"), +25 games only ("IfRequested") or by nobody ("Never") | +| **EnableGameFlowChecks** | `true` | Enable checks that check if certain actions are done in the appropriate order or at the appropriate moment in the game. This includes changing cosmetics while in game or murdering too fast. | +| **EnableInvalidObjectChecks** | `true` | Enables checks that check if network objects are spawned properly. Disabling this option also implies disabling EnableRoleChecks. | +| **EnableMustBeHostChecks** | `true` | Enables checks that check if players are the host before they can do actions that require them to be host of the game. This includes starting the game and spawning objects. | +| **EnableColorLimitChecks** | `true` | Enables checks that checks if players request colors that are already in use. | +| **EnableNameLimitChecks** | `true` | Enables checks that checks if player names have a length that is possible to set using the user interface. | +| **EnableOwnershipChecks** | `true` | Enables checks that check if players are allowed to perform a certain action on themself or another player. | +| **EnableRoleChecks** | `true` | Enables checks that check if players have the correct role when performing certain role abilities like venting or murdering. | +| **EnableTargetChecks** | `true` | Enables checks that check if certain packets to everyone that should only have been sent to certain players or vice versa. This includes sending votes or network objects. | +| **ForbidProtocolExtensions** | `true` | If disabled allows players to send network packets that go beyond the network packets sent by the vanilla game. This is necessary for most mods that need all players to install it. | ### Compatibility diff --git a/src/Impostor.Api/CheatCategory.cs b/src/Impostor.Api/CheatCategory.cs index 9972268..26f6c5a 100644 --- a/src/Impostor.Api/CheatCategory.cs +++ b/src/Impostor.Api/CheatCategory.cs @@ -5,6 +5,9 @@ public enum CheatCategory /// A packet used a part of the network protocol that is unknown to Impostor, like a custom RPC. ProtocolExtension, + /// A host-only mod extension is used outside of host-authoritive mode. + HostOnlyExtension, + /// A packet was sent at an inappropriate moment. GameFlow, diff --git a/src/Impostor.Api/Config/AntiCheatConfig.cs b/src/Impostor.Api/Config/AntiCheatConfig.cs index f888fd7..a649904 100644 --- a/src/Impostor.Api/Config/AntiCheatConfig.cs +++ b/src/Impostor.Api/Config/AntiCheatConfig.cs @@ -10,6 +10,8 @@ namespace Impostor.Api.Config public CheatingHostMode AllowCheatingHosts { get; set; } = CheatingHostMode.Never; + public CheatingHostMode AllowHostOnlyExtensions { get; set; } = CheatingHostMode.IfRequested; + public bool EnableGameFlowChecks { get; set; } = true; public bool EnableMustBeHostChecks { get; set; } = true; diff --git a/src/Impostor.Api/Net/Messages/MessageFlags.cs b/src/Impostor.Api/Net/Messages/MessageFlags.cs index a902e77..4faba36 100644 --- a/src/Impostor.Api/Net/Messages/MessageFlags.cs +++ b/src/Impostor.Api/Net/Messages/MessageFlags.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -41,6 +41,11 @@ namespace Impostor.Api.Net.Messages .ToDictionary(x => (byte)x.GetValue(null)!, y => y.Name); } + /// + /// Convert a MessageFlag to the corresponding string. + /// + /// The MessageFlag to convert. + /// A string corresponding with the value of flag. public static string FlagToString(byte flag) { return FlagCache.TryGetValue(flag, out var res) ? res : $"Unknown Flag {flag}"; diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index 5f4572f..08597c2 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -74,6 +74,12 @@ namespace Impostor.Server.Net CheatCategory.Ownership => _antiCheatConfig.EnableOwnershipChecks, CheatCategory.Role => _antiCheatConfig.EnableRoleChecks, CheatCategory.Target => _antiCheatConfig.EnableTargetChecks, + CheatCategory.HostOnlyExtension => _antiCheatConfig.AllowHostOnlyExtensions switch { + CheatingHostMode.Always => false, + CheatingHostMode.IfRequested => !GameVersion.HasDisableServerAuthorityFlag, + CheatingHostMode.Never => true, + _ => true, + }, CheatCategory.Other => true, _ => LogUnknownCategory(category), }; @@ -194,7 +200,7 @@ namespace Impostor.Server.Net case MessageFlags.StartGame: { - if (!IsPacketAllowed(reader, true)) + if (!IsPacketAllowed(reader, true, flag)) { return; } @@ -209,7 +215,7 @@ namespace Impostor.Server.Net case MessageFlags.RemovePlayer: { - if (!IsPacketAllowed(reader, true)) + if (!IsPacketAllowed(reader, true, flag)) { return; } @@ -226,7 +232,7 @@ namespace Impostor.Server.Net case MessageFlags.GameData: case MessageFlags.GameDataTo: { - if (!IsPacketAllowed(reader, false)) + if (!IsPacketAllowed(reader, false, flag)) { return; } @@ -261,7 +267,17 @@ namespace Impostor.Server.Net case MessageFlags.PackedGameDataTo: { - if (!IsPackedGameDataToAllowed(reader)) + // We're limiting this to hosts right now. If you have a use case for this for + // players to use this feature, we're open to changing this. + if (!IsPacketAllowed(reader, true, flag)) + { + return; + } + + if (await ReportCheatAsync( + new CheatContext(MessageFlags.FlagToString(flag)), + CheatCategory.HostOnlyExtension, + "Client sent a PackedGameDataTo message")) { return; } @@ -302,7 +318,7 @@ namespace Impostor.Server.Net case MessageFlags.EndGame: { - if (!IsPacketAllowed(reader, true)) + if (!IsPacketAllowed(reader, true, flag)) { return; } @@ -317,7 +333,7 @@ namespace Impostor.Server.Net case MessageFlags.AlterGame: { - if (!IsPacketAllowed(reader, true)) + if (!IsPacketAllowed(reader, true, flag)) { return; } @@ -338,7 +354,7 @@ namespace Impostor.Server.Net case MessageFlags.KickPlayer: { - if (!IsPacketAllowed(reader, true)) + if (!IsPacketAllowed(reader, true, flag)) { return; } @@ -419,7 +435,7 @@ namespace Impostor.Server.Net await _gameManager.OnClientDisconnectAsync(this); } - private bool IsPacketAllowed(IMessageReader message, bool hostOnly) + private bool IsPacketAllowed(IMessageReader message, bool hostOnly, byte flag) { if (Player == null) { @@ -442,36 +458,17 @@ namespace Impostor.Server.Net return true; } - _logger.LogWarning("[{0}] Client sent packet only allowed by the host ({1}).", Id, game.HostId); + _logger.LogWarning( + "[{0}] Client sent packet {1} only allowed by the host ({2}).", + Id, + MessageFlags.FlagToString(flag), + game.HostId); return false; } return true; } - private bool IsPackedGameDataToAllowed(IMessageReader message) - { - if (Player == null) - { - return false; - } - - var game = Player.Game; - - if (message.ReadPackedInt32() != game.Code) - { - return false; - } - - if (game.HostId == Id) - { - return true; - } - - _logger.LogWarning("[{0}] Client sent PackedGameDataTo only allowed by the host ({1}).", Id, game.HostId); - return false; - } - /// /// Triggered when the connected client requests the PlatformSpecificData. /// -- 2.39.5