forked from FebbanHD123/FAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
182 additions
and
5 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
72 changes: 72 additions & 0 deletions
72
src/main/java/de/febanhd/anticrash/checks/impl/ChatMessageCheck.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,72 @@ | ||
package de.febanhd.anticrash.checks.impl; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
import de.febanhd.anticrash.checks.AbstractCheck; | ||
import de.febanhd.anticrash.plugin.AntiCrashPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import org.bukkit.event.player.PlayerCommandPreprocessEvent; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class ChatMessageCheck extends AbstractCheck implements Listener { | ||
|
||
private ConcurrentHashMap<Player, Long> lastMessage; | ||
|
||
public ChatMessageCheck() { | ||
super("Chat Message Check"); | ||
lastMessage = new ConcurrentHashMap<>(); | ||
Bukkit.getPluginManager().registerEvents(this, AntiCrashPlugin.getPlugin()); | ||
} | ||
|
||
@EventHandler | ||
public void handleChat(AsyncPlayerChatEvent event){ | ||
if(lastMessage.containsKey(event.getPlayer())){ | ||
if(System.currentTimeMillis() - lastMessage.get(event.getPlayer()) < 100){ | ||
this.sendInvalidPacketWarning(event.getPlayer(), "Sent messages too fast (<100ms)"); | ||
event.setCancelled(true); | ||
} | ||
lastMessage.replace(event.getPlayer(), System.currentTimeMillis()); | ||
}else lastMessage.put(event.getPlayer(), System.currentTimeMillis()); | ||
} | ||
|
||
@EventHandler | ||
public void handlePreCommand(PlayerCommandPreprocessEvent event){ | ||
if(event.getMessage().contains("/calc") || event.getMessage().contains("/solve") || event.getMessage().contains("/eval") || event.getMessage().contains("/desc")){ | ||
if(event.getMessage().contains("(") | ||
|| event.getMessage().contains(")") | ||
|| event.getMessage().contains("[") | ||
|| event.getMessage().contains("]") | ||
|| event.getMessage().contains("{") | ||
|| event.getMessage().contains("}") | ||
|| event.getMessage().contains("?") | ||
|| event.getMessage().contains(":") | ||
|| event.getMessage().contains(";")){ | ||
this.sendInvalidPacketWarning(event.getPlayer(), "The player executed a dangerous WorldEdit Crash Command. (Calculation)"); | ||
event.setCancelled(true); | ||
}else if(event.getMessage().length() > 20){ | ||
this.sendInvalidPacketWarning(event.getPlayer(), "The player executed a dangerous WorldEdit Crash Command. (Calculation)"); | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
if(event.getMessage().contains("mv") && (event.getMessage().contains("\n") || event.getMessage().contains(".*.*")) || event.getMessage().contains(String.valueOf((char) 775))){ | ||
this.sendInvalidPacketWarning(event.getPlayer(), "The player executed a Crash Command. (MV Crasher / Bad Char)"); | ||
event.setCancelled(true); | ||
} | ||
|
||
if(event.getMessage().contains("mv") && (event.getMessage().contains("/") || event.getMessage().contains("\\"))){ | ||
this.sendInvalidPacketWarning(event.getPlayer(), "The player executed a dangerous Multiverse Command. (Path Navigation)"); | ||
event.setCancelled(true); | ||
} | ||
|
||
if((event.getMessage().contains("pex promote a a") || event.getMessage().contains("pex demote a a")) && event.getMessage().startsWith("/")){ | ||
this.sendInvalidPacketWarning(event.getPlayer(), "The player executed a permission ex crash command. (Promote/Demote)"); | ||
event.setCancelled(true); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/de/febanhd/anticrash/checks/impl/Log4JExploitCheck.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,78 @@ | ||
package de.febanhd.anticrash.checks.impl; | ||
|
||
import de.febanhd.anticrash.checks.AbstractCheck; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.core.Appender; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.filter.AbstractFilter; | ||
import org.apache.logging.log4j.core.filter.AbstractFilterable; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import org.bukkit.event.player.PlayerCommandPreprocessEvent; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
public class Log4JExploitCheck extends AbstractCheck { | ||
|
||
private static final Pattern PATTERN = Pattern.compile(".*\\$\\{[^}]*\\}.*"); | ||
|
||
public Log4JExploitCheck() { | ||
super("Log4J Exploit Check"); | ||
Logger logger = plugin.getLogger(); | ||
|
||
plugin.getServer().getPluginManager().registerEvents(new Listener() { | ||
|
||
@EventHandler | ||
public void handleMessage(AsyncPlayerChatEvent chatEvent){ | ||
if(chatEvent.getMessage().toLowerCase().contains("${jndi:ldap") || chatEvent.getMessage().toLowerCase().contains("${jndi") | ||
|| chatEvent.getMessage().toLowerCase().contains("ldap")){ | ||
sendInvalidPacketWarning(chatEvent.getPlayer(), "Tryed to exploit Log4J via chat"); | ||
chatEvent.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void handleCommand(PlayerCommandPreprocessEvent event){ | ||
if(event.getMessage().toLowerCase().contains("${jndi:ldap") || event.getMessage().toLowerCase().contains("${jndi") | ||
|| event.getMessage().toLowerCase().contains("ldap")){ | ||
sendInvalidPacketWarning(event.getPlayer(), "Tryed to exploit Log4J via command"); | ||
event.setCancelled(true); | ||
} | ||
} | ||
}, plugin); | ||
|
||
try { | ||
this.applyAppenders(); | ||
logger.info("Successfully applied filters to all Appenders! (Log4J Fix)"); | ||
} catch (Exception exception) { | ||
logger.warning("Failed to add Log4J Appenders (LoggerFilter) to Logger. (Incompatible Logger version)!"); | ||
} | ||
} | ||
|
||
private void applyAppenders() { | ||
Map appenders = ((org.apache.logging.log4j.core.Logger)(LogManager.getRootLogger())).getAppenders(); | ||
LoggerFilter filter = new LoggerFilter(); | ||
List<Appender> filterable = (List<Appender>) appenders.values().stream().filter(appender -> appender instanceof AbstractFilterable).collect(Collectors.toList()); | ||
filterable.forEach(appender -> ((AbstractFilterable)(appender)).addFilter(filter)); | ||
} | ||
|
||
private static class LoggerFilter | ||
extends AbstractFilter { | ||
private LoggerFilter() { | ||
} | ||
|
||
public Result filter(LogEvent event) { | ||
String message = event.getMessage().getFormattedMessage(); | ||
if (message.indexOf(36) != -1 && PATTERN.matcher(message.toLowerCase()).find()) { | ||
Bukkit.getConsoleSender().sendMessage("Server blocked Log4J Exploit try succesfully via Log Filter."); | ||
return Result.DENY; | ||
} | ||
return super.filter(event); | ||
} | ||
} | ||
} |
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
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
target/classes/de/febanhd/anticrash/checks/AbstractCheck$Broadcast.class
Binary file not shown.
Binary file modified
BIN
+587 Bytes
(110%)
target/classes/de/febanhd/anticrash/checks/AbstractCheck.class
Binary file not shown.
Binary file modified
BIN
+24 Bytes
(100%)
target/classes/de/febanhd/anticrash/checks/impl/DosCheck.class
Binary file not shown.
Binary file modified
BIN
+311 Bytes
(110%)
target/classes/de/febanhd/anticrash/checks/impl/nbt/NBTTagCheck.class
Binary file not shown.
Binary file modified
BIN
+263 Bytes
(110%)
target/classes/de/febanhd/anticrash/commands/AntiCrashCommand.class
Binary file not shown.
Binary file modified
BIN
+6 Bytes
(100%)
target/classes/de/febanhd/anticrash/commands/UnblockIPsCommand.class
Binary file not shown.
Binary file modified
BIN
-259 Bytes
(96%)
target/classes/de/febanhd/anticrash/handler/ByteBufDecoderHandler.class
Binary file not shown.
Binary file modified
BIN
+18 Bytes
(100%)
target/classes/de/febanhd/anticrash/plugin/AntiCrashPlugin.class
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#Generated by Maven | ||
#Sun Jan 23 14:06:09 CET 2022 | ||
#Sun Jan 23 14:59:02 CET 2022 | ||
groupId=de.febanhd | ||
artifactId=FAC | ||
version=1.2.9 | ||
version=1.2.9-FIXED |