Skip to content

Commit

Permalink
Introduce server query padding
Browse files Browse the repository at this point in the history
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
  • Loading branch information
koraktor committed Nov 21, 2020
1 parent 2cb441f commit dacf220
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 35 deletions.
6 changes: 3 additions & 3 deletions lib/steam-condenser/servers/packets/a2s_info_packet.rb
@@ -1,9 +1,9 @@
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2008-2012, Sebastian Staudt
# Copyright (c) 2008-2020, Sebastian Staudt

require 'steam-condenser/servers/packets/base_packet'
require 'steam-condenser/servers/packets/query_packet'

module SteamCondenser::Servers::Packets

Expand All @@ -16,7 +16,7 @@ module SteamCondenser::Servers::Packets
# @see GameServer#update_server_info
class A2S_INFO_Packet

include BasePacket
include QueryPacket

# Creates a new A2S_INFO request object
def initialize
Expand Down
6 changes: 2 additions & 4 deletions lib/steam-condenser/servers/packets/a2s_player_packet.rb
@@ -1,10 +1,9 @@
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2008-2012, Sebastian Staudt
# Copyright (c) 2008-2020, Sebastian Staudt

require 'steam-condenser/servers/packets/base_packet'
require 'steam-condenser/servers/packets/request_with_challenge'

module SteamCondenser::Servers::Packets

Expand All @@ -20,14 +19,13 @@ module SteamCondenser::Servers::Packets
class A2S_PLAYER_Packet

include BasePacket
include RequestWithChallenge

# Creates a new A2S_PLAYER request object including the challenge number
#
# @param [Numeric] challenge_number The challenge number received from the
# server
def initialize(challenge_number = -1)
super A2S_PLAYER_HEADER, challenge_number
super A2S_PLAYER_HEADER, [challenge_number.to_i].pack('l')
end

end
Expand Down
10 changes: 4 additions & 6 deletions lib/steam-condenser/servers/packets/a2s_rules_packet.rb
@@ -1,10 +1,9 @@
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2008-2012, Sebastian Staudt
# Copyright (c) 2008-2020, Sebastian Staudt

require 'steam-condenser/servers/packets/base_packet'
require 'steam-condenser/servers/packets/request_with_challenge'
require 'steam-condenser/servers/packets/query_packet'

module SteamCondenser::Servers::Packets

Expand All @@ -20,15 +19,14 @@ module SteamCondenser::Servers::Packets
# @see GameServer#update_rules_info
class A2S_RULES_Packet

include BasePacket
include RequestWithChallenge
include QueryPacket

# Creates a new A2S_RULES request object including the challenge number
#
# @param [Numeric] challenge_number The challenge number received from the
# server
def initialize(challenge_number = -1)
super A2S_RULES_HEADER, challenge_number
super A2S_RULES_HEADER, [challenge_number.to_i].pack('l')
end

end
Expand Down
31 changes: 31 additions & 0 deletions lib/steam-condenser/servers/packets/query_packet.rb
@@ -0,0 +1,31 @@
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2020, Sebastian Staudt

require 'steam-condenser/servers/packets/base_packet'

module SteamCondenser::Servers::Packets

# This is used as a wrapper to create padding of request packets to a minimum
# size of 1200 bytes. This was introduced in November 2020 as a counter-measure
# to DoS attacks on game servers.
#
# @author Sebastian Staudt
module QueryPacket

include BasePacket

# The minimum package size as defined by Valve
STEAM_GAMESERVER_MIN_CONNECTIONLESS_PACKET_SIZE = 1200

# Creates a new query packet including data padding
#
# @param [Fixnum] header The packet header
# @param [String] content The raw data of the packet
def initialize(header, content)
super header, content.to_s.ljust(STEAM_GAMESERVER_MIN_CONNECTIONLESS_PACKET_SIZE - 5, "\0")
end

end
end
22 changes: 0 additions & 22 deletions lib/steam-condenser/servers/packets/request_with_challenge.rb

This file was deleted.

26 changes: 26 additions & 0 deletions test/steam-condenser/servers/packets/test_query_packet.rb
@@ -0,0 +1,26 @@
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2020, Sebastian Staudt

require 'helper'

class TestQueryPacket < Test::Unit::TestCase

class GenericQueryPacket
include Servers::Packets::QueryPacket
end

context 'A query packet' do

setup do
@packet = GenericQueryPacket.new 0x61, 'test'
end

should 'pad its content to at least 1200 bytes' do
assert_equal [255, 255, 255, 255, 'atest' + "\0" * 1191].pack('c4a*'), @packet.to_s
end

end

end

0 comments on commit dacf220

Please sign in to comment.