Skip to content

Commit

Permalink
patch new exploit and update plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Dec 20, 2024
1 parent 092b455 commit 2c33bda
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 58 deletions.
1 change: 0 additions & 1 deletion AnarchyExploitFixesFolia/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ tasks.shadowJar {
archiveFileName = "${rootProject.name}-${project.name}-${project.version}.${archiveExtension.get()}"
exclude(
"com/cryptomorin/xseries/XBiome*",
"com/cryptomorin/xseries/XPotion*",
"com/cryptomorin/xseries/NMSExtras*",
"com/cryptomorin/xseries/NoteBlockMusic*",
"com/cryptomorin/xseries/SkullCacheListener*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.xginko.aef;

import com.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import de.tr7zw.changeme.nbtapi.NBT;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.config.Config;
import me.xginko.aef.config.LanguageCache;
Expand Down Expand Up @@ -49,13 +48,6 @@ public final class AnarchyExploitFixes extends JavaPlugin {
@Override
public void onLoad() {
PlatformUtil.load();
isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (isPacketEventsInstalled) {
// Configure and load packetevents
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().kickOnPacketException(true).reEncodeByDefault(false);
PacketEvents.getAPI().load();
}
}

@Override
Expand All @@ -76,6 +68,7 @@ public void onEnable() {
prefixedLogger = ComponentLogger.logger(getLogger().getName());
unPrefixedLogger = ComponentLogger.logger("");

isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (!isPacketEventsInstalled) {
Stream.of(" ",
" _ _ _ _ _ ",
Expand Down Expand Up @@ -128,8 +121,8 @@ public void onEnable() {
prefixedLogger.info("Registering Permissions");
AEFPermission.registerPermissions();

prefixedLogger.info("Initializing PacketEvents");
PacketEvents.getAPI().init();
prefixedLogger.info("Initializing NBT-API");
NBT.preloadApi();

prefixedLogger.info("Ready.");
}
Expand All @@ -138,7 +131,6 @@ public void onEnable() {
public void onDisable() {
if (isPacketEventsInstalled) {
AEFModule.disableAll();
PacketEvents.getAPI().terminate();
}
if (languageCacheMap != null) {
languageCacheMap.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.xginko.aef.modules.packets.PacketModule;
import me.xginko.aef.utils.models.ConditionalEnableable;
import me.xginko.aef.utils.models.Disableable;
import me.xginko.aef.utils.models.Enableable;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.reflections.Reflections;
Expand Down Expand Up @@ -75,6 +76,8 @@ public static void reloadModules() {
AnarchyExploitFixes.prefixedLogger().warn("Failed initialising module class '{}'.", moduleClass.getSimpleName(), t);
}
}

ENABLED_MODULES.forEach(Enableable::enable);
}

protected void error(String message, Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.xginko.aef.modules.packets;

import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

import java.nio.charset.StandardCharsets;

public class BigMessages extends PacketModule {

private final int charLimit;
private final boolean log, kick;

public BigMessages() {
super("patches.message-char-limit", PacketListenerPriority.HIGHEST);
config.addComment(configPath + ".enable", """
Sets a character limit for command and message packets to prevent a lag exploit.""");
this.charLimit = config.getInt(configPath + ".max-characters", 512);
this.log = config.getBoolean(configPath + ".log", false);
this.kick = config.getBoolean(configPath + ".kick-player", false);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", true);
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.isCancelled()) return;

if (
event.getPacketType() == PacketType.Play.Client.CHAT_MESSAGE
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND_UNSIGNED
) {
if (isStringTooBig(new PacketWrapper<>(event))) {
event.setCancelled(true);
onCancel(log, kick, event.getUser());
}
}
}

private boolean isStringTooBig(PacketWrapper<?> packetWrapper) {
int strBufLen = packetWrapper.readVarInt();

// Check if the received encoded string buffer length is zero or longer than maximum allowed
if (strBufLen < 0 || strBufLen > charLimit * 4) {
return true;
}

// The received string length is longer than maximum allowed
return ByteBufHelper.toString(packetWrapper.buffer, ByteBufHelper.readerIndex(packetWrapper.buffer), strBufLen, StandardCharsets.UTF_8)
.length() > charLimit;
}
}
1 change: 0 additions & 1 deletion AnarchyExploitFixesLegacy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ tasks {
archiveFileName = "${rootProject.name}-${project.name}-${project.version}.${archiveExtension.get()}"
exclude(
"com/cryptomorin/xseries/XBiome*",
"com/cryptomorin/xseries/XPotion*",
"com/cryptomorin/xseries/NMSExtras*",
"com/cryptomorin/xseries/NoteBlockMusic*",
"com/cryptomorin/xseries/SkullCacheListener*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.xginko.aef;

import com.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import de.tr7zw.changeme.nbtapi.NBT;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.config.Config;
import me.xginko.aef.config.Datastore;
Expand Down Expand Up @@ -50,13 +49,6 @@ public final class AnarchyExploitFixes extends JavaPlugin {
@Override
public void onLoad() {
PlatformUtil.load();
isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (isPacketEventsInstalled) {
// Configure and load packetevents
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().kickOnPacketException(true).reEncodeByDefault(false);
PacketEvents.getAPI().load();
}
}

@Override
Expand All @@ -70,6 +62,7 @@ public void onEnable() {
prefixedLogger = LoggerFactory.getLogger(getLogger().getName());
unPrefixedLogger = LoggerFactory.getLogger("");

isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (!isPacketEventsInstalled) {
Stream.of(" ",
" _ _ _ _ _ ",
Expand Down Expand Up @@ -128,8 +121,8 @@ public void onEnable() {
prefixedLogger.info("Registering Permissions");
AEFPermission.registerPermissions();

prefixedLogger.info("Initializing PacketEvents");
PacketEvents.getAPI().init();
prefixedLogger.info("Initializing NBT-API");
NBT.preloadApi();

prefixedLogger.info("Ready.");
}
Expand All @@ -138,7 +131,6 @@ public void onEnable() {
public void onDisable() {
if (isPacketEventsInstalled) {
AEFModule.disableAll();
PacketEvents.getAPI().terminate();
}
if (languageCacheMap != null) {
languageCacheMap.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,10 @@ public Config() throws Exception {
"Plays XP pickup sound to alert players when theyre going\n" +
"above the limit.");
String configuredSound = getString("elytra.elytra-speed.sound", XSound.ENTITY_EXPERIENCE_ORB_PICKUP.name());
Sound parsedSound;
try {
parsedSound = XSound.valueOf(configuredSound).parseSound();
} catch (IllegalArgumentException e) {
AnarchyExploitFixes.prefixedLogger().warn("<elytra-speed> Sound '"+configuredSound+"' does not exist in XSound. Using default.");
parsedSound = XSound.ENTITY_EXPERIENCE_ORB_PICKUP.parseSound();
}
this.elytra_too_fast_sound = parsedSound;
this.elytra_too_fast_sound = XSound.of(configuredSound).orElseGet(() -> {
AnarchyExploitFixes.prefixedLogger().warn("<elytra-speed> Sound '{}' does not exist in XSound. Using default.", configuredSound);
return XSound.ENTITY_EXPERIENCE_ORB_PICKUP;
}).get();
this.elytra_teleport_back = getBoolean("elytra.elytra-speed.teleport-instead-of-canceling-movement", false,
"Recommended to leave false if you dont experience any issues.");
this.elytra_enable_global = getBoolean("elytra.elytra-speed.Global-Settings.enable", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.xginko.aef.modules.packets.PacketModule;
import me.xginko.aef.utils.models.ConditionalEnableable;
import me.xginko.aef.utils.models.Disableable;
import me.xginko.aef.utils.models.Enableable;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.reflections.Reflections;
Expand Down Expand Up @@ -75,6 +76,8 @@ public static void reloadModules() {
AnarchyExploitFixes.prefixedLogger().warn("Failed initialising module class '{}'.", moduleClass.getSimpleName(), t);
}
}

ENABLED_MODULES.forEach(Enableable::enable);
}

protected void error(String message, Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.xginko.aef.modules.packets;

import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

import java.nio.charset.StandardCharsets;

public class BigMessages extends PacketModule {

private final int charLimit;
private final boolean log, kick;

public BigMessages() {
super("patches.message-char-limit", PacketListenerPriority.HIGHEST);
config.addComment(configPath + ".enable",
"Sets a character limit for command and message packets to prevent a lag exploit.");
this.charLimit = config.getInt(configPath + ".max-characters", 512);
this.log = config.getBoolean(configPath + ".log", false);
this.kick = config.getBoolean(configPath + ".kick-player", false);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", true);
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.isCancelled()) return;

if (
event.getPacketType() == PacketType.Play.Client.CHAT_MESSAGE
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND_UNSIGNED
) {
if (isStringTooBig(new PacketWrapper<>(event))) {
event.setCancelled(true);
onCancel(log, kick, event.getUser());
}
}
}

private boolean isStringTooBig(PacketWrapper<?> packetWrapper) {
int strBufLen = packetWrapper.readVarInt();

// Check if the received encoded string buffer length is zero or longer than maximum allowed
if (strBufLen < 0 || strBufLen > charLimit * 4) {
return true;
}

// The received string length is longer than maximum allowed
return ByteBufHelper.toString(packetWrapper.buffer, ByteBufHelper.readerIndex(packetWrapper.buffer), strBufLen, StandardCharsets.UTF_8)
.length() > charLimit;
}
}
6 changes: 3 additions & 3 deletions build-logic/src/main/kotlin/me.xginko.aef.wrapper.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ repositories {
}

dependencies {
compileOnly("com.github.retrooper:packetevents-spigot:2.6.0") // PacketEvents to patch packet based exploits
api("com.github.cryptomorin:XSeries:11.3.0") // Crossversion entitytype and material support
compileOnly("com.github.retrooper:packetevents-spigot:2.7.0") // PacketEvents to patch packet based exploits
api("com.github.cryptomorin:XSeries:12.1.0") // Crossversion entitytype and material support
api("com.github.thatsmusic99:ConfigurationMaster-API:v2.0.0-rc.1") // ConfigurationMaster for enhanced config management
api("de.tr7zw:item-nbt-api:2.14.0") // NBT API for cross version nbt tag handling
api("de.tr7zw:item-nbt-api:2.14.1") // NBT API for cross version nbt tag handling
api("org.bstats:bstats-bukkit:3.0.2") // Bukkit bStats
api("org.apache.commons:commons-math3:3.6.1") // FastMath
api("org.reflections:reflections:0.10.2") // Reflections
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ hikaricp = "com.zaxxer:HikariCP:5.1.0"

[plugins]
runpaper = { id = "xyz.jpenilla.run-paper", version = "2.3.1" }
shadow = { id = "io.github.goooler.shadow", version = "8.1.8" }
userdev = { id = "io.papermc.paperweight.userdev", version = "1.7.4" }
downgradeJava = { id = "xyz.wagyourtail.jvmdowngrader", version = "1.2.0" }
shadow = { id = "com.gradleup.shadow", version = "8.3.5" }
userdev = { id = "io.papermc.paperweight.userdev", version = "1.7.7" }
downgradeJava = { id = "xyz.wagyourtail.jvmdowngrader", version = "1.2.1" }

[bundles]
Loading

0 comments on commit 2c33bda

Please sign in to comment.