From e65e1e798d77d9634c1631d66d62206818ca8c57 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Thu, 28 Sep 2023 01:21:23 +0200 Subject: [PATCH] security++, no more mixin leaking, also it launches now lol --- .../java/com/baseband/client/BaseBand.java | 6 +-- .../client/mixins/MixinEntityPlayerSP.java | 5 +-- .../client/mixins/MixinMinecraft.java | 4 +- .../client/mixins/MixinNetworkManager.java | 14 +------ .../baseband/client/mixins/MixinProxy.java | 38 +++++++++++++++++++ .../classloader/CustomClassloader.java | 21 +++------- .../org/baseband/launcher/launch/Loader.java | 4 +- .../launcher/util/MixinRestriction.java | 2 +- 8 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 Client/src/main/java/com/baseband/client/mixins/MixinProxy.java diff --git a/Client/src/main/java/com/baseband/client/BaseBand.java b/Client/src/main/java/com/baseband/client/BaseBand.java index 9b41520..64fdd49 100644 --- a/Client/src/main/java/com/baseband/client/BaseBand.java +++ b/Client/src/main/java/com/baseband/client/BaseBand.java @@ -29,11 +29,11 @@ import java.util.ArrayList; @Mod(modid = "baseband") public class BaseBand { public static int majorVersion = 1; - public static int buildNumber = 230; - public static String hash = "ec94c2de63a0191e"; + public static int buildNumber = 244; + public static String hash = "7e7800a2711492fc"; public static String name = "BaseBand"; - public long timeOfCompile = 1695853741523L; + public long timeOfCompile = 1695856587011L; public CommandManager commandRegistry; public EventBus eventBus; public ArrayList modules = new ArrayList<>(); diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinEntityPlayerSP.java b/Client/src/main/java/com/baseband/client/mixins/MixinEntityPlayerSP.java index 3060b60..15511b7 100644 --- a/Client/src/main/java/com/baseband/client/mixins/MixinEntityPlayerSP.java +++ b/Client/src/main/java/com/baseband/client/mixins/MixinEntityPlayerSP.java @@ -1,6 +1,5 @@ package com.baseband.client.mixins; -import com.baseband.client.BaseBand; import com.baseband.client.event.events.MoveEvent; import com.mojang.authlib.GameProfile; import net.minecraft.client.entity.AbstractClientPlayer; @@ -21,9 +20,7 @@ public class MixinEntityPlayerSP extends AbstractClientPlayer { @Redirect(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/AbstractClientPlayer;move(Lnet/minecraft/entity/MoverType;DDD)V")) public void move(AbstractClientPlayer abstractClientPlayer, MoverType type, double x, double y, double z) { - MoveEvent event = new MoveEvent(type, x, y, z); - BaseBand.INSTANCE.eventBus.publish(event); - + MoveEvent event = MixinProxy.playerMove(type, x, y, z); if(!event.isCancelled()) { super.move(event.type, event.x, event.y, event.z); } diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinMinecraft.java b/Client/src/main/java/com/baseband/client/mixins/MixinMinecraft.java index f6dcc89..cc7f4c5 100644 --- a/Client/src/main/java/com/baseband/client/mixins/MixinMinecraft.java +++ b/Client/src/main/java/com/baseband/client/mixins/MixinMinecraft.java @@ -1,6 +1,5 @@ package com.baseband.client.mixins; -import com.baseband.client.BaseBand; import net.minecraft.client.Minecraft; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,7 +13,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinMinecraft { @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;checkGLError(Ljava/lang/String;)V", ordinal = 1, shift = At.Shift.AFTER)) private void onInit(CallbackInfo ci) { - new BaseBand(); - BaseBand.INSTANCE.onInit(); + MixinProxy.minecraftOnInit(); } } diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinNetworkManager.java b/Client/src/main/java/com/baseband/client/mixins/MixinNetworkManager.java index c5e563b..2cc4e3a 100644 --- a/Client/src/main/java/com/baseband/client/mixins/MixinNetworkManager.java +++ b/Client/src/main/java/com/baseband/client/mixins/MixinNetworkManager.java @@ -1,7 +1,5 @@ package com.baseband.client.mixins; -import com.baseband.client.BaseBand; -import com.baseband.client.event.events.PacketEvent; import io.netty.channel.ChannelHandlerContext; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; @@ -15,20 +13,12 @@ public class MixinNetworkManager { @Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true) public void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_, CallbackInfo ci) { - PacketEvent.Read event = new PacketEvent.Read(p_channelRead0_2_); - BaseBand.INSTANCE.eventBus.publish(event); - - if (event.isCancelled()) - ci.cancel(); + MixinProxy.networkChannelRead0(p_channelRead0_2_, ci); } @Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) public void channelRead0(Packet packetIn, CallbackInfo ci) { - PacketEvent.Write event = new PacketEvent.Write(packetIn); - BaseBand.INSTANCE.eventBus.publish(event); - - if (event.isCancelled()) - ci.cancel(); + MixinProxy.networkSendPacket(packetIn, ci); } } diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinProxy.java b/Client/src/main/java/com/baseband/client/mixins/MixinProxy.java new file mode 100644 index 0000000..9b7f76e --- /dev/null +++ b/Client/src/main/java/com/baseband/client/mixins/MixinProxy.java @@ -0,0 +1,38 @@ +package com.baseband.client.mixins; + +import com.baseband.client.BaseBand; +import com.baseband.client.event.events.MoveEvent; +import com.baseband.client.event.events.PacketEvent; +import net.minecraft.entity.MoverType; +import net.minecraft.network.Packet; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +public class MixinProxy { + public static void minecraftOnInit() { + new BaseBand(); + BaseBand.INSTANCE.onInit(); + } + + public static void networkChannelRead0(Packet p_channelRead0_2_, CallbackInfo ci) { + PacketEvent.Read event = new PacketEvent.Read(p_channelRead0_2_); + BaseBand.INSTANCE.eventBus.publish(event); + + if (event.isCancelled()) + ci.cancel(); + } + + public static void networkSendPacket(Packet packetIn, CallbackInfo ci) { + PacketEvent.Write event = new PacketEvent.Write(packetIn); + BaseBand.INSTANCE.eventBus.publish(event); + + if (event.isCancelled()) + ci.cancel(); + } + + public static MoveEvent playerMove(MoverType type, double x, double y, double z) { + MoveEvent event = new MoveEvent(type, x, y, z); + BaseBand.INSTANCE.eventBus.publish(event); + + return event; + } +} diff --git a/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java b/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java index 8181588..ddf6d41 100644 --- a/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java +++ b/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java @@ -91,19 +91,10 @@ public class CustomClassloader extends ClassLoader { encryptedClasses.access(accessor -> Loader.classKey.access(classKey -> data[0] = classKey.getValue().decryptByte(accessor.getValue().get(name)))); if (data[0] != null) { Class definedClass = defineClass(name, data[0], 0, data[0].length); - //// TudbuT // using unsafe is a bad idea as it breaks DataKeeper - // try { - // Field b = Unsafe.class.getDeclaredField("theUnsafe"); - // Unsafe unsafe = (Unsafe)b.get(null); - // Class definedClass = unsafe.defineClass(name, data[0], 0, data[0].length, this, null); - - if (definedClass == null) { - throw new ClassNotFoundException(name); - } - return definedClass; - // }catch (Exception e){ - // return null; - // } + if (definedClass == null) { + throw new ClassNotFoundException(name); + } + return definedClass; } else { try { return Launch.classLoader.findClass(name); @@ -127,7 +118,7 @@ public class CustomClassloader extends ClassLoader { if(!accessControl.checkCaller(strictness)) { accessControl.crash(strictness); } - if (name.startsWith("com.baseband.client.mixin")) { + if (name.startsWith("com.baseband.client.mixin") || name.startsWith("com.baseband.client.event.events")) { final byte[][] bytes = {null}; encryptedClasses.access(accessor -> Loader.classKey.access(classKey -> bytes[0] = classKey.getValue().decryptByte(accessor.getValue().get(name)))); if (bytes[0] != null) { @@ -142,7 +133,7 @@ public class CustomClassloader extends ClassLoader { if(!accessControl.checkCaller(strictness)) { accessControl.crash(strictness); } - if (name.startsWith("com.baseband.client.mixin")) { + if (name.startsWith("com.baseband.client.mixin") || name.startsWith("com.baseband.client.event.events")) { final byte[][] bytes = {null}; encryptedClasses.access(accessor -> Loader.classKey.access(classKey -> bytes[0] = classKey.getValue().decryptByte(accessor.getValue().get(name)))); if (bytes[0] != null) { diff --git a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java index 335aad4..245e33b 100644 --- a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java +++ b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java @@ -68,8 +68,8 @@ public class Loader { objectKey = new DataKeeper<>(mainPermissionManager, defaultStrictness, new Key()); try { - //Socket socket = new Socket("127.0.0.1", 31212); - Socket socket = new Socket("88.208.243.108", 31212); + Socket socket = new Socket("127.0.0.1", 31212); + //Socket socket = new Socket("88.208.243.108", 31212); DataInputStream inputF = new DataInputStream(socket.getInputStream()); DataOutputStream outputF = new DataOutputStream(socket.getOutputStream()); diff --git a/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java b/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java index 2acf3df..0a8933a 100644 --- a/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java +++ b/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java @@ -5,7 +5,7 @@ import de.tudbut.security.Strictness; import de.tudbut.security.permissionmanager.Restriction; public class MixinRestriction extends Restriction { - private static final String pkg = "org.spongepowered.mixin"; + private static final String pkg = "org.spongepowered.asm.mixin.transformer"; public MixinRestriction(PermissionManager parent) { super(parent);