From 9e2656015f5ba1fbf2306f3a09a9fe079747b57c Mon Sep 17 00:00:00 2001 From: Sebastian Staudt Date: Sun, 22 Nov 2020 12:17:25 +0100 Subject: [PATCH] Introduce server query padding For compatibility with security patches to future game servers versions this adds a 1200 byte padding to all requests packets as defined in the following HLDS mailing list post: https://www.mail-archive.com/hlds_announce@list.valvesoftware.com/msg01194.html See koraktor/steam-condenser#331 --- .../Servers/Packets/A2SINFOPacket.php | 4 +-- .../Servers/Packets/A2SPLAYERPacket.php | 6 ++-- .../Servers/Packets/A2SRULESPacket.php | 6 ++-- .../Servers/Packets/QueryPacket.php | 35 +++++++++++++++++++ .../Packets/RequestPacketWithChallenge.php | 29 --------------- .../servers/packets/QueryPacketTest.php | 21 +++++++++++ 6 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 lib/SteamCondenser/Servers/Packets/QueryPacket.php delete mode 100644 lib/SteamCondenser/Servers/Packets/RequestPacketWithChallenge.php create mode 100644 tests/SteamCondenser/servers/packets/QueryPacketTest.php diff --git a/lib/SteamCondenser/Servers/Packets/A2SINFOPacket.php b/lib/SteamCondenser/Servers/Packets/A2SINFOPacket.php index f6315c9..6568abb 100644 --- a/lib/SteamCondenser/Servers/Packets/A2SINFOPacket.php +++ b/lib/SteamCondenser/Servers/Packets/A2SINFOPacket.php @@ -3,7 +3,7 @@ * This code is free software; you can redistribute it and/or modify it under * the terms of the new BSD License. * - * Copyright (c) 2008-2014, Sebastian Staudt + * Copyright (c) 2008-2020, Sebastian Staudt * * @license http://www.opensource.org/licenses/bsd-license.php New BSD License */ @@ -21,7 +21,7 @@ * @subpackage packets * @see GameServer::updateServerInfo() */ -class A2SINFOPacket extends SteamPacket { +class A2SINFOPacket extends QueryPacket { /** * Creates a new A2S_INFO request object diff --git a/lib/SteamCondenser/Servers/Packets/A2SPLAYERPacket.php b/lib/SteamCondenser/Servers/Packets/A2SPLAYERPacket.php index 1be71b2..0a59b5e 100644 --- a/lib/SteamCondenser/Servers/Packets/A2SPLAYERPacket.php +++ b/lib/SteamCondenser/Servers/Packets/A2SPLAYERPacket.php @@ -3,7 +3,7 @@ * This code is free software; you can redistribute it and/or modify it under * the terms of the new BSD License. * - * Copyright (c) 2008-2014, Sebastian Staudt + * Copyright (c) 2008-2020, Sebastian Staudt * * @license http://www.opensource.org/licenses/bsd-license.php New BSD License */ @@ -23,7 +23,7 @@ * @subpackage packets * @see GameServer::updatePlayerInfo() */ -class A2SPLAYERPacket extends RequestPacketWithChallenge { +class A2SPLAYERPacket extends QueryPacket { /** * Creates a new A2S_PLAYER request object including the challenge number @@ -32,6 +32,6 @@ class A2SPLAYERPacket extends RequestPacketWithChallenge { * server */ public function __construct($challengeNumber = 0xFFFFFFFF) { - parent::__construct(SteamPacket::A2S_PLAYER_HEADER, $challengeNumber); + parent::__construct(SteamPacket::A2S_PLAYER_HEADER, pack('V', $challengeNumber)); } } diff --git a/lib/SteamCondenser/Servers/Packets/A2SRULESPacket.php b/lib/SteamCondenser/Servers/Packets/A2SRULESPacket.php index f99b5f4..64eeaa7 100644 --- a/lib/SteamCondenser/Servers/Packets/A2SRULESPacket.php +++ b/lib/SteamCondenser/Servers/Packets/A2SRULESPacket.php @@ -3,7 +3,7 @@ * This code is free software; you can redistribute it and/or modify it under * the terms of the new BSD License. * - * Copyright (c) 2008-2014, Sebastian Staudt + * Copyright (c) 2008-2020, Sebastian Staudt * * @license http://www.opensource.org/licenses/bsd-license.php New BSD License */ @@ -24,7 +24,7 @@ * @subpackage packets * @see GameServer::updateRulesInfo() */ -class A2SRULESPacket extends RequestPacketWithChallenge { +class A2SRULESPacket extends QueryPacket { /** * Creates a new A2S_RULES request object including the challenge number * @@ -33,6 +33,6 @@ class A2SRULESPacket extends RequestPacketWithChallenge { */ public function __construct($challengeNumber = 0xFFFFFFFF) { - parent::__construct(SteamPacket::A2S_RULES_HEADER, $challengeNumber); + parent::__construct(SteamPacket::A2S_RULES_HEADER, pack('V', $challengeNumber)); } } diff --git a/lib/SteamCondenser/Servers/Packets/QueryPacket.php b/lib/SteamCondenser/Servers/Packets/QueryPacket.php new file mode 100644 index 0000000..f421dbc --- /dev/null +++ b/lib/SteamCondenser/Servers/Packets/QueryPacket.php @@ -0,0 +1,35 @@ +headerData, $this->contentData->_array()); - } -} diff --git a/tests/SteamCondenser/servers/packets/QueryPacketTest.php b/tests/SteamCondenser/servers/packets/QueryPacketTest.php new file mode 100644 index 0000000..fa294ce --- /dev/null +++ b/tests/SteamCondenser/servers/packets/QueryPacketTest.php @@ -0,0 +1,21 @@ +packet = $this->getMockForAbstractClass('\SteamCondenser\Servers\Packets\QueryPacket', array(0x61, 'test')); + } + + public function testPadding() { + $this->assertEquals(str_pad("\xFF\xFF\xFF\xFFatest", 1200, "\0"), $this->packet->__toString()); + } + +}