-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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/[email protected]/msg01194.html See koraktor/steam-condenser#331
- Loading branch information
Showing
5 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/github/koraktor/steamcondenser/steam/packets/QueryPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package com.github.koraktor.steamcondenser.steam.packets; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.apache.commons.lang3.ArrayUtils; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
class QueryPacket extends SteamPacket { | ||
|
||
// The minimum package size as defined by Valve | ||
private static final int STEAM_GAMESERVER_MIN_CONNECTIONLESS_PACKET_SIZE = 1200; | ||
|
||
static byte[] addPadding(byte[] data) { | ||
if (data.length < STEAM_GAMESERVER_MIN_CONNECTIONLESS_PACKET_SIZE - 5) { | ||
byte[] padding = new byte[STEAM_GAMESERVER_MIN_CONNECTIONLESS_PACKET_SIZE - 5 - data.length]; | ||
return ArrayUtils.addAll(data, padding); | ||
} else { | ||
return data; | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new query packet including data padding | ||
* | ||
* @param data The data of the original query | ||
*/ | ||
QueryPacket(byte header, byte[] data) { | ||
super(header, addPadding(data)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/com/github/koraktor/steamcondenser/steam/packets/QueryPacketTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package com.github.koraktor.steamcondenser.steam.packets; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.apache.commons.lang3.ArrayUtils; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.core.Is.*; | ||
import static org.hamcrest.core.IsEqual.*; | ||
|
||
public class QueryPacketTest { | ||
|
||
@Test | ||
public void testPadding() { | ||
QueryPacket packet = new QueryPacket((byte) 0x21, new byte[] { 0x22, 0x23, 0x24, 0x25 }); | ||
byte[] bytes = packet.getBytes(); | ||
|
||
assertThat(bytes.length, is(1200)); | ||
|
||
assertThat(bytes[0], is((byte) 0xFF)); | ||
assertThat(bytes[1], is((byte) 0xFF)); | ||
assertThat(bytes[2], is((byte) 0xFF)); | ||
assertThat(bytes[3], is((byte) 0xFF)); | ||
assertThat(bytes[4], is((byte) 0x21)); | ||
assertThat(bytes[5], is((byte) 0x22)); | ||
assertThat(bytes[6], is((byte) 0x23)); | ||
assertThat(bytes[7], is((byte) 0x24)); | ||
assertThat(bytes[8], is((byte) 0x25)); | ||
|
||
byte[] paddingBytes = ArrayUtils.subarray(bytes, 9, 1200); | ||
byte[] expectedPadding = new byte[1191]; | ||
Arrays.fill(expectedPadding, (byte) 0x0); | ||
assertThat(paddingBytes, is(equalTo(expectedPadding))); | ||
} | ||
} |