Skip to content

Commit

Permalink
patch tagparser crash exploit
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Feb 16, 2024
1 parent 4be719e commit 84c7e68
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import me.moomoo.anarchyexploitfixes.modules.preventions.portals.*;
import me.moomoo.anarchyexploitfixes.modules.preventions.withers.*;
import me.moomoo.anarchyexploitfixes.modules.protocollib.boatfly.AntiBoatFlyModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.tagparser.AntiTagParserCrash;
import me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick.AntiWindowClickCrash;

import java.util.HashSet;
Expand Down Expand Up @@ -213,6 +214,7 @@ static void reloadModules() {

modules.add(new AntiBoatFlyModule());
modules.add(new AntiWindowClickCrash());
modules.add(new AntiTagParserCrash());

if (!AnarchyExploitFixes.getConfiguration().protocolLib_IsDisabled && !protocolLibIsInstalled) {
AnarchyExploitFixes.getLog().severe("Could not find ProtocolLib. Packet exploits cannot be patched without it.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.tagparser;

import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;

import java.util.logging.Level;

public class AntiTagParserCrash implements AnarchyExploitFixesModule {

public AntiTagParserCrash() {
AnarchyExploitFixes.getConfiguration().addComment("patches.tag-parser-crash-patch.enable", "Patches TagParser crash exploit.");
}

@Override
public String name() {
return "tag-parser-crash-patch";
}

@Override
public String category() {
return "patches";
}

@Override
public void enable() {
new TabCompleteListener().register();
}

@Override
public boolean shouldEnable() {
Config config = AnarchyExploitFixes.getConfiguration();
if (config.getBoolean("patches.tag-parser-crash-patch.enable", true)) {
if (config.protocolLib_IsDisabled) {
LogUtil.moduleLog(Level.WARNING, name(), "Not patching exploit because you disabled ProtocolLib in config!");
return false;
}
if (!AnarchyExploitFixes.isProtocolLibInstalled()) {
LogUtil.moduleLog(Level.SEVERE, name(), "Unable to patch exploit because ProtocolLib is not installed!");
return false;
}
return true;
}
return false;
}

@Override
public void disable() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.tagparser;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;

import java.util.logging.Level;

public class TabCompleteListener extends PacketAdapter {

public TabCompleteListener() {
super(AnarchyExploitFixes.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE);
}

protected void register() {
ProtocolLibrary.getProtocolManager().addPacketListener(this);
}

@Override
public void onPacketReceiving(PacketEvent event) {
if (event.isPlayerTemporary()) return;

final PacketContainer packet = event.getPacket();

try {
final String command = packet.getStrings().read(0);

if (command.contains("@") || command.contains("nbt")) {
if (!event.getPlayer().isOp()) {
event.setCancelled(true);
return;
}
}

if (command.length() > 64) {
final int index = command.indexOf(' ');
if (index == -1 || index >= 64) {
event.setCancelled(true);
}
}
} catch (Exception e) {
LogUtil.moduleLog(Level.WARNING, "tag-parser-crash",
"Error reading TabComplete Request Packet - " + e.getLocalizedMessage() + "\n" +
"This might be due to version incompatibilities.\n" +
"Packet in question: " + packet.toString());
}
}
}
2 changes: 1 addition & 1 deletion AnarchyExploitFixesLegacy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

dependencies {
compileOnly("com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT")
api("com.github.cryptomorin:XSeries:9.8.0") // XSeries for cross-version support
api("com.github.cryptomorin:XSeries:9.9.0") // XSeries for cross-version support
api("com.github.ben-manes.caffeine:caffeine:2.9.3") // Fast caching // Use 2.x for Java8 compatibility
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import me.moomoo.anarchyexploitfixes.modules.protocollib.craftrecipe.CraftRecipeCooldownModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.lecterncrash.AntiLecternCrash;
import me.moomoo.anarchyexploitfixes.modules.protocollib.nocom.NoComModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.tagparser.AntiTagParserCrash;
import me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick.AntiWindowClickCrash;
import org.bukkit.event.HandlerList;

Expand Down Expand Up @@ -228,6 +229,7 @@ static void reloadModules() {
modules.add(new CraftRecipeCooldownModule());
modules.add(new AntiWindowClickCrash());
modules.add(new AntiLecternCrash());
modules.add(new AntiTagParserCrash());

if (!AnarchyExploitFixes.getConfiguration().protocolLib_IsDisabled && !protocolLibIsInstalled) {
AnarchyExploitFixes.getLog().severe("Could not find ProtocolLib. Many gamebreaking exploits cannot be patched without it.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.tagparser;

import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;

import java.util.logging.Level;

public class AntiTagParserCrash implements AnarchyExploitFixesModule {

public AntiTagParserCrash() {
AnarchyExploitFixes.getConfiguration().addComment("patches.tag-parser-crash-patch.enable", "Patches TagParser crash exploit.");
}

@Override
public String name() {
return "tag-parser-crash-patch";
}

@Override
public String category() {
return "patches";
}

@Override
public void enable() {
new TabCompleteListener().register();
}

@Override
public boolean shouldEnable() {
Config config = AnarchyExploitFixes.getConfiguration();
if (config.getBoolean("patches.tag-parser-crash-patch.enable", true)) {
if (config.protocolLib_IsDisabled) {
LogUtil.moduleLog(Level.WARNING, name(), "Not patching exploit because you disabled ProtocolLib in config!");
return false;
}
if (!AnarchyExploitFixes.isProtocolLibInstalled()) {
LogUtil.moduleLog(Level.SEVERE, name(), "Unable to patch exploit because ProtocolLib is not installed!");
return false;
}
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.tagparser;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;

import java.util.logging.Level;

public class TabCompleteListener extends PacketAdapter {

public TabCompleteListener() {
super(AnarchyExploitFixes.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE);
}

protected void register() {
ProtocolLibrary.getProtocolManager().addPacketListener(this);
}

@Override
public void onPacketReceiving(PacketEvent event) {
if (event.isPlayerTemporary()) return;

final PacketContainer packet = event.getPacket();

try {
final String command = packet.getStrings().read(0);

if (command.contains("@") || command.contains("nbt")) {
if (!event.getPlayer().isOp()) {
event.setCancelled(true);
return;
}
}

if (command.length() > 64) {
final int index = command.indexOf(' ');
if (index == -1 || index >= 64) {
event.setCancelled(true);
}
}
} catch (Exception e) {
LogUtil.moduleLog(Level.WARNING, "tag-parser-crash",
"Error reading TabComplete Request Packet - " + e.getLocalizedMessage() + "\n" +
"This might be due to version incompatibilities.\n" +
"Packet in question: " + packet.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "me.moomoo.anarchyexploitfixes"
version = "2.6.5"
version = "2.6.6"
description = "Prevent many exploits that affect anarchy servers."
var url: String? = "github.com/moom0o/AnarchyExploitFixes"

Expand Down

0 comments on commit 84c7e68

Please sign in to comment.