| **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. |
+| **EnablePacketSizeChecks** | `true` | Enables checks that verify if network messages exceed the maximum allowed size. |
+| **PacketSizeLimit** | `1203` | The maximum allowed size (in bytes) for a network message. The official servers of Among Us requires that a Hazel packet is < 1204 bytes, excluding headers. |
### Compatibility
/// <summary>A packet was sent on an invalid network object, like a PlayerControl without PlayerInfo.</summary>
InvalidObject,
+ /// <summary>A packet was sent that exceeded the maximum allowed RPC size.</summary>
+ PacketSize,
+
/// <summary>Legacy category for unsorted anticheat checks.</summary>
Other,
}
public bool EnableTargetChecks { get; set; } = true;
public bool ForbidProtocolExtensions { get; set; } = true;
+
+ public bool EnablePacketSizeChecks { get; set; } = true;
+
+ public int PacketSizeLimit { get; set; } = 1203;
}
}
CheatingHostMode.Never => true,
_ => true,
},
+ CheatCategory.PacketSize => _antiCheatConfig.EnablePacketSizeChecks,
CheatCategory.Other => true,
_ => LogUnknownCategory(category),
};
using System.Net;
using System.Threading.Tasks;
+using Impostor.Api;
+using Impostor.Api.Config;
using Impostor.Api.Net;
using Impostor.Hazel;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
namespace Impostor.Server.Net.Hazel
{
internal class HazelConnection : IHazelConnection
{
private readonly ILogger<HazelConnection> _logger;
+ private readonly AntiCheatConfig _antiCheatConfig;
- public HazelConnection(Connection innerConnection, ILogger<HazelConnection> logger)
+ public HazelConnection(Connection innerConnection, ILogger<HazelConnection> logger, IOptions<AntiCheatConfig> antiCheatOptions)
{
_logger = logger;
+ _antiCheatConfig = antiCheatOptions.Value;
InnerConnection = innerConnection;
innerConnection.DataReceived = ConnectionOnDataReceived;
innerConnection.Disconnected = ConnectionOnDisconnected;
return;
}
+ // Check raw message size against the configured limit.
+ // Innersloth requires full packet ≤ 1200 bytes (1168 bytes payload after 32 bytes IP+UDP headers).
+ if (e.Message.Length > _antiCheatConfig.PacketSizeLimit)
+ {
+ if (await Client.ReportCheatAsync(
+ new CheatContext("RootMessage"),
+ CheatCategory.PacketSize,
+ $"Received a message that is too large, length: {e.Message.Length}"))
+ {
+ return;
+ }
+ }
+
while (true)
{
if (e.Message.Position >= e.Message.Length)
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
+using Impostor.Api.Config;
using Impostor.Api.Events.Managers;
using Impostor.Api.Net.Messages.C2S;
using Impostor.Hazel;
using Impostor.Server.Net.Manager;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
+using Microsoft.Extensions.Options;
namespace Impostor.Server.Net
{
private readonly ClientManager _clientManager;
private readonly ObjectPool<MessageReader> _readerPool;
private readonly ILogger<HazelConnection> _connectionLogger;
+ private readonly IOptions<AntiCheatConfig> _antiCheatOptions;
private UdpConnectionListener? _connection;
public Matchmaker(
IEventManager eventManager,
ClientManager clientManager,
ObjectPool<MessageReader> readerPool,
- ILogger<HazelConnection> connectionLogger)
+ ILogger<HazelConnection> connectionLogger,
+ IOptions<AntiCheatConfig> antiCheatOptions)
{
_eventManager = eventManager;
_clientManager = clientManager;
_readerPool = readerPool;
_connectionLogger = connectionLogger;
+ _antiCheatOptions = antiCheatOptions;
}
public async ValueTask StartAsync(IPEndPoint ipEndPoint)
// Handshake.
HandshakeC2S.Deserialize(e.HandshakeData, out var clientVersion, out var name, out var language, out var chatMode, out var platformSpecificData);
- var connection = new HazelConnection(e.Connection, _connectionLogger);
+ var connection = new HazelConnection(e.Connection, _connectionLogger, _antiCheatOptions);
await _eventManager.CallAsync(new ClientConnectionEvent(connection, e.HandshakeData));
"EnableOwnershipChecks": true,
"EnableRoleChecks": true,
"EnableTargetChecks": true,
- "ForbidProtocolExtensions": true
+ "ForbidProtocolExtensions": true,
+ "EnablePacketSizeChecks": true,
+ "PacketSizeLimit": 1203
},
"Timeout": {
"SpawnTimeout": 2500,