10 Commits
Author SHA1 Message Date
RyanDeLap d4e41d2c28 Revert tinyprotocol changes, generic extra hostname info 2020-05-11 21:11:14 -05:00
Ryan De Lap 751bcafcc6 Merge pull request #4 from TCPShield/timestamp-valdiation
Update to block legacy ping
2020-04-28 08:50:56 -05:00
RyanDeLap a641acdfb6 Small cleanup 2020-04-28 08:50:45 -05:00
RyanDeLap c89705c0c8 Update to block legacy ping 2020-04-28 08:48:37 -05:00
Ryan De Lap 4c8e446600 Merge pull request #3 from TCPShield/timestamp-valdiation
Add timestamp validation
2020-04-20 13:13:52 -05:00
RyanDeLap 961c6c0e20 Changes to output 2020-04-20 13:13:13 -05:00
RyanDeLap 30140afcf6 Add timestamp validation 2020-04-18 21:25:01 -05:00
Josiah White 65020bbcd3 Merge pull request #2 from TCPShield/hostname-fowarding
Forward hostname and port on serverlistping
2020-03-08 01:41:18 -05:00
RyanDeLap 7d746b25ff Update forge support 2020-03-07 18:12:50 -06:00
RyanDeLap 4bedf22b59 Forward hostname and port on serverlistping 2020-03-07 02:12:09 -06:00
8 changed files with 92 additions and 47 deletions

No files matched your search

+11
View File
@@ -1,2 +1,13 @@
# RealIP
Bungee/Spigot plugin which parses client IP addresses passed from the TCPShield network.
### Compiling
To compile this project, install maven and run the following command:
```
mvn clean install
```
### Support
Please contact [@RyanDeLap](https://t.me/RyanDeLap) on Telegram for all support related to this product.
Before contact, ensure you have tested with no Bungee Plugins installed. Plugins like BungeePluginManager will break this plugin!
+3 -3
View File
@@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tcpshield.realip</groupId>
<artifactId>RealIP</artifactId>
<version>1.4-SNAPSHOT</version>
<artifactId>TCPShield</artifactId>
<version>1.7-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
@@ -55,7 +55,7 @@
</dependencies>
<build>
<finalName>RealIP</finalName>
<finalName>TCPShield</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
@@ -1,18 +1,14 @@
package net.tcpshield.realip;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Handshake.Client;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.server.SocketInjector;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.reflect.StructureModifier;
import io.netty.channel.AbstractChannel;
import io.netty.channel.Channel;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@@ -24,16 +20,17 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class PacketHandler
extends PacketAdapter {
public class HandshakePacketHandler extends PacketAdapter {
private String properField = null;
private final Logger logger;
private final boolean onlyProxy;
private final boolean debugMode;
public PacketHandler(Logger logger, boolean onlyProxy) {
public HandshakePacketHandler(Logger logger, boolean onlyProxy, boolean debugMode) {
super(TCPShieldBukkit.getInstance(), new PacketType[]{PacketType.Handshake.Client.SET_PROTOCOL});
this.logger = logger;
this.onlyProxy = onlyProxy;
this.debugMode = debugMode;
}
public void onPacketReceiving(PacketEvent event) {
@@ -41,6 +38,12 @@ public class PacketHandler
String raw = null;
try {
raw = (String) event.getPacket().getStrings().read(0);
String extraData = "";
String[] hostnameSplits = raw.split("\0", 2);
if(hostnameSplits.length > 1) {
extraData = hostnameSplits[1];
}
raw = hostnameSplits[0];
String[] payload = raw.split("///", 3);
if (payload.length >= 3) {
@@ -56,6 +59,7 @@ public class PacketHandler
int port = Integer.parseInt(hostnameParts[1]);
String reconstructedPayload = hostname + "///" + host + ":" + port + "///" + timestamp;
if (!Signing.verify(reconstructedPayload.getBytes(StandardCharsets.UTF_8), signature)) {
throw new Exception("Couldn't verify signature.");
}
@@ -78,18 +82,22 @@ public class PacketHandler
} catch (Exception e) {
e.printStackTrace();
}
hostname = hostname + extraData;
event.getPacket().getStrings().write(0, hostname);
}
}
} catch (Exception ex) {
Player player;
ex.printStackTrace();
ex.printStackTrace();
} finally {
if ((this.onlyProxy) &&
(!proxyConnection)) {
if ((this.onlyProxy) && (!proxyConnection)) {
Player player = event.getPlayer();
this.logger.warning("Disconnecting " + player.getAddress() + " because no proxy info was received and only-allow-proxy-connections is enabled.");
if(raw != null) {
if (this.debugMode) {
this.logger.warning("Disconnecting " + player.getAddress() + " because no proxy info was received and only-allow-proxy-connections is enabled.");
}
if (raw != null) {
this.logger.warning(raw);
}
player.kickPlayer("");
@@ -97,20 +105,8 @@ public class PacketHandler
}
}
private Channel getChannel(Player player) {
try {
Class<? extends Player> playerClass = player.getClass();
Object playerHandle = playerClass.getMethod("getHandle", new Class[0]).invoke(player, new Object[0]);
Object playerConnection = getNmsClass("EntityPlayer").getField("playerConnection").get(playerHandle);
Object networkManager = getNmsClass("PlayerConnection").getField("networkManager").get(playerConnection);
return (Channel) getNmsClass("NetworkManager").getField("channel").get(networkManager);
} catch (Exception e) {
throw new RuntimeException("Couldn't get player channel", e);
}
}
private Class getNmsClass(String name)
throws ClassNotFoundException {
private Class getNmsClass(String name) throws ClassNotFoundException {
return Class.forName(getNmsPackage() + "." + name);
}
@@ -1,21 +1,18 @@
package net.tcpshield.realip;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.logging.Logger;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class TCPShieldBukkit
extends JavaPlugin {
public class TCPShieldBukkit extends JavaPlugin implements Listener {
private static TCPShieldBukkit INSTANCE;
private static Boolean stopping = Boolean.valueOf(false);
private boolean onlyProxy;
private boolean debugMode;
public void onEnable() {
INSTANCE = this;
@@ -25,13 +22,17 @@ public class TCPShieldBukkit
getLogger().severe("Couldn't initialize signing module.");
throw new RuntimeException(e);
}
saveDefaultConfig();
FileConfiguration config = getConfig();
this.onlyProxy = config.getBoolean("only-allow-proxy-connections");
this.debugMode = config.getBoolean("debug-mode");
ProtocolLibrary.getProtocolManager().addPacketListener(new HandshakePacketHandler(getLogger(), this.onlyProxy, this.debugMode));
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketHandler(getLogger(), this.onlyProxy));
}
public void onDisable() {
stopping = Boolean.valueOf(true);
INSTANCE = null;
@@ -7,6 +7,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.CopyOption;
@@ -20,6 +21,7 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
@@ -28,10 +30,9 @@ import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import net.md_5.bungee.event.EventHandler;
public class TCPShieldBungee
extends Plugin
implements Listener {
public class TCPShieldBungee extends Plugin implements Listener {
private boolean onlyProxy;
private boolean debugMode;
public void onEnable() {
saveDefaultConfig();
@@ -43,6 +44,7 @@ public class TCPShieldBungee
throw new RuntimeException(e);
}
this.onlyProxy = config.getBoolean("only-allow-proxy-connections");
this.debugMode = config.getBoolean("debug-mode");
ProxyServer proxy = getProxy();
PluginManager pluginManager = proxy.getPluginManager();
@@ -114,6 +116,23 @@ public class TCPShieldBungee
return new File(dataFolder, "config.yml");
}
@EventHandler(priority = -64)
public void onProxyPingEvent(ProxyPingEvent event) {
if(event.getConnection().isLegacy()) {
try {
Field wrapperField = event.getConnection().getClass().getDeclaredField("ch");
wrapperField.setAccessible(true);
Object wrapper = wrapperField.get(event.getConnection());
wrapperField.setAccessible(false);
Method m = wrapper.getClass().getMethod("close");
m.invoke(wrapper);
} catch(Exception e) {
event.getConnection().disconnect(new BaseComponent[0]);
}
}
}
@EventHandler(priority = -64)
public void onPlayerHandshake(PlayerHandshakeEvent e) {
boolean proxyConnection = false;
@@ -146,9 +165,24 @@ public class TCPShieldBungee
int port = Integer.parseInt(hostnameParts[1]);
String reconstructedPayload = hostname + "///" + host + ":" + port + "///" + timestamp;
if (signature.contains("%%%")) {
signature = signature.split("%%%", 2)[0];
}
if (!Signing.verify(reconstructedPayload.getBytes(StandardCharsets.UTF_8), signature)) {
throw new Exception("Couldn't verify signature.");
}
long currentTime = System.currentTimeMillis() / 1000;
if(!(timestamp >= (currentTime - 2) && timestamp <= (currentTime + 2))) {
if(this.debugMode) {
getLogger().warning("Current time: " + currentTime + ", Timestamp Time: " + timestamp);
}
throw new Exception("Invalid signature timestamp, please check system's local clock if error persists.");
}
PendingConnection connection = e.getConnection();
InetSocketAddress sockadd = new InetSocketAddress(host, port);
@@ -187,15 +221,14 @@ public class TCPShieldBungee
}
}
} catch (Exception localException) {
Logger logger;
PendingConnection connection;
localException.printStackTrace();
} finally {
if ((this.onlyProxy) &&
(!proxyConnection)) {
if (this.onlyProxy && !proxyConnection) {
Logger logger = getLogger();
PendingConnection connection = e.getConnection();
logger.warning("Disconnecting " + connection.getAddress() + " because no proxy info was received and only-allow-proxy-connections is enabled.");
if(this.debugMode) {
logger.warning("Disconnecting " + connection.getAddress() + " because no proxy info was received and only-allow-proxy-connections is enabled.");
}
if (channel != null) {
channel.flush().close();
} else {
+1 -1
View File
@@ -1,4 +1,4 @@
name: TCPShield
version: 1.3
version: 1.7
main: net.tcpshield.realip.TCPShieldBungee
author: 'https://tcpshield.com'
+5 -1
View File
@@ -1 +1,5 @@
only-allow-proxy-connections: true
# Please keep this as true in while using TCPShield!
only-allow-proxy-connections: true
# Turn on to diagnose connection issues
debug-mode: false
+1 -1
View File
@@ -1,5 +1,5 @@
name: TCPShield
version: 1.3
version: 1.7
main: net.tcpshield.realip.TCPShieldBukkit
depend: ['ProtocolLib']
author: 'https://tcpshield.com'