From ae638bb2bfee4bd20136ed85cc177d257939ecbc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Mar 2023 20:43:24 +0100 Subject: [PATCH 1/4] Fix REntity Metadata --- SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java | 1 + SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java index ce3ba90..951cdc8 100644 --- a/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -32,6 +32,7 @@ public class ChatWrapper8 implements ChatWrapper { return chatComponentConstructor.invoke(text); } + private static final Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); private static final Reflection.FieldAccessor metadataEntity = Reflection.getField(metadataPacket, int.class, 0); private static final Reflection.FieldAccessor metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); @Override diff --git a/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java b/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java index b28f6e9..8c7d186 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java @@ -19,12 +19,9 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; - public interface ChatWrapper { ChatWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); - Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); Object stringToChatComponent(String text); From f74253f4cb167cb85a3a844d945014861280e360 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Mar 2023 15:37:57 +0100 Subject: [PATCH 2/4] AntiNocom false flag reduction --- .../de/steamwar/core/events/AntiNocom.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 0799523..ea7759d 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -27,12 +27,20 @@ import de.steamwar.techhider.ProtocolUtils; import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -public class AntiNocom { +public class AntiNocom implements Listener { + + private final Map flags = new ConcurrentHashMap<>(); public AntiNocom() { + Bukkit.getServer().getPluginManager().registerEvents(this, Core.getInstance()); TinyProtocol.instance.addFilter(blockDig, this::onDig); if(Core.getVersion() > 8) { @@ -40,6 +48,11 @@ public class AntiNocom { } } + @EventHandler + public void onQuit(PlayerQuitEvent e) { + flags.remove(e.getPlayer()); + } + private void registerUseItem() { Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); @@ -56,16 +69,7 @@ public class AntiNocom { TinyProtocol.instance.addFilter(useItem, (player, packet) -> { Object pos = getPosition.apply(packet); - int x = TechHider.blockPositionX.get(pos); - int z = TechHider.blockPositionZ.get(pos); - - if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { - Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); - SWException.log(player.getName() + " kicked for using item on unloaded block (potential NoCom-DOS attack)", x + " " + z); - return null; - } - - return packet; + return isValid(player, "UseItem", TechHider.blockPositionX.get(pos), TechHider.blockPositionZ.get(pos)) ? packet : null; }); } @@ -73,13 +77,20 @@ public class AntiNocom { private static final Reflection.FieldAccessor digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); private Object onDig(Player player, Object packet) { Object pos = digPosition.get(packet); - int x = TechHider.blockPositionX.get(pos); - int z = TechHider.blockPositionZ.get(pos); - if((x != 0 || z != 0) && !player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { - Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); - SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", x + " " + z); - return null; + return isValid(player, "Dig", TechHider.blockPositionX.get(pos), TechHider.blockPositionZ.get(pos)) ? packet : null; + } + + private boolean isValid(Player player, String type, int x, int z) { + if((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) + return true; + + int amount = flags.compute(player, (p, a) -> a == null ? 1 : a+1); + if(amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam + if(amount == 8) // Schedule player kick only once + Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); + + SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount); } - return packet; + return false; } } From b3f80e2be621f55922a3a8bf85a52dae4884f120 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Mar 2023 15:47:58 +0100 Subject: [PATCH 3/4] Add ignores to ErrorHandler --- SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java b/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java index 9d55e90..6e7e00c 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java +++ b/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java @@ -73,6 +73,9 @@ public class ErrorHandler extends Handler { if(stacktrace.contains("POI data mismatch")) return; + if(message.isEmpty() && stacktrace.isEmpty()) + return; + try { SWException.log(message, stacktrace); } catch (SecurityException e) { @@ -140,6 +143,7 @@ public class ErrorHandler extends Handler { startsWith.add("Biome with id"); startsWith.add("1.16 and 1.16.1 clients are only partially supported"); startsWith.add("Unable to parse CustomName from "); + startsWith.add("java.util.ConcurrentModificationException"); ignoreStartsWith = Collections.unmodifiableList(startsWith); List contains = new ArrayList<>(); From db00eb46d6765a66b14838e7de957b388dc225a0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Mar 2023 16:48:15 +0100 Subject: [PATCH 4/4] Add ignores to ErrorHandler --- SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java b/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java index 6e7e00c..2a5ffa5 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java +++ b/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java @@ -70,7 +70,7 @@ public class ErrorHandler extends Handler { if(logRecord.getThrown() != null) logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput)); String stacktrace = stacktraceOutput.toString(); - if(stacktrace.contains("POI data mismatch")) + if(stacktrace.contains("POI data mismatch") || stacktrace.contains("Newer version! Server downgrades are not supported!")) return; if(message.isEmpty() && stacktrace.isEmpty()) @@ -144,6 +144,11 @@ public class ErrorHandler extends Handler { startsWith.add("1.16 and 1.16.1 clients are only partially supported"); startsWith.add("Unable to parse CustomName from "); startsWith.add("java.util.ConcurrentModificationException"); + startsWith.add("com.destroystokyo.paper.exception.ServerInternalException: Attempted to place a tile entity"); + startsWith.add("World: minecraft:overworld"); + startsWith.add("Chunk coordinates: "); + startsWith.add("Failed to save history"); + startsWith.add("\t... "); ignoreStartsWith = Collections.unmodifiableList(startsWith); List contains = new ArrayList<>();