Skip to content

Commit 134f80f

Browse files
authored
Merge commit from fork
Missing ban validation in Connect Request allows TShock ban bypassing
2 parents 80c29ee + ed39843 commit 134f80f

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

TShockAPI/Commands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5363,7 +5363,7 @@ private static void ListConnectedPlayers(CommandArgs args)
53635363

53645364
foreach (TSPlayer ply in TShock.Players)
53655365
{
5366-
if (ply != null && ply.Active)
5366+
if (ply != null && ply.Active && ply.FinishedHandshake)
53675367
{
53685368
if (displayIdsRequested)
53695369
if (ply.Account != null)

TShockAPI/GetDataHandlers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,8 @@ private static bool HandleSpawn(GetDataHandlerArgs args)
27262726
short numberOfDeathsPVP = args.Data.ReadInt16();
27272727
PlayerSpawnContext context = (PlayerSpawnContext)args.Data.ReadByte();
27282728

2729+
args.Player.FinishedHandshake = true;
2730+
27292731
if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context))
27302732
return true;
27312733

@@ -2762,6 +2764,7 @@ private static bool HandleSpawn(GetDataHandlerArgs args)
27622764
args.Player.Dead = true;
27632765
else
27642766
args.Player.Dead = false;
2767+
27652768
return false;
27662769
}
27672770

TShockAPI/TSPlayer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ public int RespawnTimer
351351
/// <summary>Determines if the player is disabled for not clearing their trash. A re-login is the only way to reset this.</summary>
352352
public bool IsDisabledPendingTrashRemoval;
353353

354+
/// <summary>Determines if the player has finished the handshake (Sent all necessary packets for connection, such as Request World Data, Spawn Player, etc). A normal client would do all of this no problem.</summary>
355+
public bool FinishedHandshake = false;
356+
354357
/// <summary>Checks to see if active throttling is happening on events by Bouncer. Rejects repeated events by malicious clients in a short window.</summary>
355358
/// <returns>If the player is currently being throttled by Bouncer, or not.</returns>
356359
public bool IsBouncerThrottled()

TShockAPI/TShock.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,8 @@ private void OnConnect(ConnectEventArgs args)
13761376
}
13771377
}
13781378
}
1379+
1380+
Bans.CheckBan(player);
13791381
Players[args.Who] = player;
13801382
}
13811383

@@ -1397,7 +1399,8 @@ private void OnJoin(JoinEventArgs args)
13971399
return;
13981400
}
13991401

1400-
Bans.CheckBan(player);
1402+
if (Bans.CheckBan(player))
1403+
return;
14011404
}
14021405

14031406
/// <summary>OnLeave - Called when a player leaves the server.</summary>
@@ -1437,7 +1440,7 @@ private void OnLeave(LeaveEventArgs args)
14371440

14381441
if (tsplr.ReceivedInfo)
14391442
{
1440-
if (!tsplr.SilentKickInProgress && tsplr.State >= 3)
1443+
if (!tsplr.SilentKickInProgress && tsplr.State >= 3 && tsplr.FinishedHandshake) //The player has left, do not broadcast any clients exploiting the behaviour of not spawning their player.
14411444
Utils.Broadcast(GetString("{0} has left.", tsplr.Name), Color.Yellow);
14421445
Log.Info(GetString("{0} disconnected.", tsplr.Name));
14431446

@@ -1458,6 +1461,9 @@ private void OnLeave(LeaveEventArgs args)
14581461
}
14591462
}
14601463

1464+
1465+
tsplr.FinishedHandshake = false;
1466+
14611467
// Fire the OnPlayerLogout hook too, if the player was logged in and they have a TSPlayer object.
14621468
if (tsplr.IsLoggedIn)
14631469
{
@@ -1487,6 +1493,12 @@ private void OnChat(ServerChatEventArgs args)
14871493
return;
14881494
}
14891495

1496+
if (!tsplr.FinishedHandshake)
1497+
{
1498+
args.Handled = true;
1499+
return;
1500+
}
1501+
14901502
if (args.Text.Length > 500)
14911503
{
14921504
tsplr.Kick(GetString("Crash attempt via long chat packet."), true);
@@ -1703,14 +1715,14 @@ private void OnGreetPlayer(GreetPlayerEventArgs args)
17031715
Log.Info(GetString("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP,
17041716
player.Group.Name, player.Country, TShock.Utils.GetActivePlayerCount(),
17051717
TShock.Config.Settings.MaxSlots));
1706-
if (!player.SilentJoinInProgress)
1718+
if (!player.SilentJoinInProgress && player.FinishedHandshake)
17071719
Utils.Broadcast(GetString("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow);
17081720
}
17091721
else
17101722
{
17111723
Log.Info(GetString("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP,
17121724
player.Group.Name, TShock.Utils.GetActivePlayerCount(), TShock.Config.Settings.MaxSlots));
1713-
if (!player.SilentJoinInProgress)
1725+
if (!player.SilentJoinInProgress && player.FinishedHandshake)
17141726
Utils.Broadcast(GetString("{0} has joined.", player.Name), Color.Yellow);
17151727
}
17161728

TShockAPI/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null)
183183
/// <returns>The number of active players on the server.</returns>
184184
public int GetActivePlayerCount()
185185
{
186-
return TShock.Players.Count(p => null != p && p.Active);
186+
return TShock.Players.Count(p => null != p && p.Active && p.FinishedHandshake);
187187
}
188188

189189
//Random should not be generated in a method

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Use past tense when adding new entries; sign your name off when you add or chang
7878
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. -->
7979

8080
## Upcoming changes
81+
* Added a variable for handshake (True upon spawn player), clients no longer notify others of their presence and cant chat if this is never set to true. (@ohayo)
82+
* Fixed a security issue with how bans are handled on join. (@ohayo)
8183
* Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi)
8284
* Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) for player, updated `CursedInferno` buff for NPC (@sgkoishi, #3005)
8385
* Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939)

0 commit comments

Comments
 (0)