-
-
Notifications
You must be signed in to change notification settings - Fork 420
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
12 changed files
with
232 additions
and
33 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
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
57 changes: 57 additions & 0 deletions
57
src/main/java/net/wurstclient/mixin/ControlsListWidgetMixin.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,57 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Wurst-Imperium and contributors. | ||
* | ||
* This source code is subject to the terms of the GNU General Public | ||
* License, version 3. If a copy of the GPL was not distributed with this | ||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt | ||
*/ | ||
package net.wurstclient.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.option.ControlsListWidget; | ||
import net.minecraft.client.gui.widget.ElementListWidget; | ||
import net.minecraft.client.gui.widget.EntryListWidget; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.text.TranslatableTextContent; | ||
import net.wurstclient.WurstClient; | ||
|
||
@Mixin(ControlsListWidget.class) | ||
public abstract class ControlsListWidgetMixin | ||
extends ElementListWidget<ControlsListWidget.Entry> | ||
{ | ||
public ControlsListWidgetMixin(WurstClient wurst, MinecraftClient client, | ||
int width, int height, int y, int itemHeight) | ||
{ | ||
super(client, width, height, y, itemHeight); | ||
} | ||
|
||
/** | ||
* Prevents Wurst's zoom keybind from being added to the controls list. | ||
*/ | ||
@WrapOperation(at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/client/gui/screen/option/ControlsListWidget;addEntry(Lnet/minecraft/client/gui/widget/EntryListWidget$Entry;)I", | ||
ordinal = 1), | ||
method = "<init>(Lnet/minecraft/client/gui/screen/option/KeybindsScreen;Lnet/minecraft/client/MinecraftClient;)V") | ||
private int dontAddZoomEntry(ControlsListWidget instance, | ||
EntryListWidget.Entry<?> entry, Operation<Integer> original) | ||
{ | ||
if(!(entry instanceof ControlsListWidget.KeyBindingEntry kbEntry)) | ||
return original.call(instance, entry); | ||
|
||
Text name = kbEntry.bindingName; | ||
if(name == null || !(name | ||
.getContent() instanceof TranslatableTextContent trContent)) | ||
return original.call(instance, entry); | ||
|
||
if(!"key.wurst.zoom".equals(trContent.getKey())) | ||
return original.call(instance, entry); | ||
|
||
return 0; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/net/wurstclient/mixin/KeybindTextContentMixin.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,56 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Wurst-Imperium and contributors. | ||
* | ||
* This source code is subject to the terms of the GNU General Public | ||
* License, version 3. If a copy of the GPL was not distributed with this | ||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt | ||
*/ | ||
package net.wurstclient.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import net.minecraft.text.KeybindTextContent; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.text.TextContent; | ||
|
||
@Mixin(KeybindTextContent.class) | ||
public abstract class KeybindTextContentMixin implements TextContent | ||
{ | ||
@Shadow | ||
@Final | ||
private String key; | ||
|
||
/** | ||
* Ensures that any chat messages, written books, signs, etc. cannot resolve | ||
* Wurst-related keybinds. | ||
* | ||
* <p> | ||
* Fixes at least one security vulnerability affecting Minecraft 1.20 and | ||
* later versions, where the server can detect the presence of Wurst by | ||
* abusing Minecraft's sign editing feature. When a player edits a sign, any | ||
* translated text and keybind text components on that sign are resolved by | ||
* the client and sent back to the server as plain text. This allows the | ||
* server to detect the presence of non-vanilla keybinds, such as Wurst's | ||
* zoom keybind. | ||
* | ||
* <p> | ||
* It is likely that similar vulnerabilities exist or will exist in other | ||
* parts of the game, such as chat messages and written books. Mojang has a | ||
* long history of failing to properly secure their text component system | ||
* (see BookHack, OP-Sign, BookDupe). Therefore it's best to cut off this | ||
* entire attack vector at the source. | ||
*/ | ||
@Inject(at = @At("RETURN"), | ||
method = "getTranslated()Lnet/minecraft/text/Text;", | ||
cancellable = true) | ||
private void onGetTranslated(CallbackInfoReturnable<Text> cir) | ||
{ | ||
if(key != null && key.contains("wurst")) | ||
cir.setReturnValue(Text.literal(key)); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/net/wurstclient/mixin/TranslatableTextContentMixin.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,68 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Wurst-Imperium and contributors. | ||
* | ||
* This source code is subject to the terms of the GNU General Public | ||
* License, version 3. If a copy of the GPL was not distributed with this | ||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt | ||
*/ | ||
package net.wurstclient.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
|
||
import net.minecraft.text.TextContent; | ||
import net.minecraft.text.TranslatableTextContent; | ||
import net.minecraft.util.Language; | ||
|
||
@Mixin(TranslatableTextContent.class) | ||
public abstract class TranslatableTextContentMixin implements TextContent | ||
{ | ||
/** | ||
* Ensures that any chat messages, written books, signs, etc. cannot resolve | ||
* Wurst-related translation keys. | ||
* | ||
* <p> | ||
* Fixes at least one security vulnerability affecting Minecraft 1.20 and | ||
* later versions, where the server can detect the presence of Wurst by | ||
* abusing Minecraft's sign editing feature. When a player edits a sign, any | ||
* translated text and keybind text components on that sign are resolved by | ||
* the client and sent back to the server as plain text. This allows the | ||
* server to detect the presence of non-vanilla translation keys. | ||
* | ||
* <p> | ||
* It is likely that similar vulnerabilities exist or will exist in other | ||
* parts of the game, such as chat messages and written books. Mojang has a | ||
* long history of failing to properly secure their text component system | ||
* (see BookHack, OP-Sign, BookDupe). Therefore it's best to cut off this | ||
* entire attack vector at the source. | ||
*/ | ||
@WrapOperation(at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/util/Language;get(Ljava/lang/String;)Ljava/lang/String;", | ||
ordinal = 0), method = "updateTranslations()V") | ||
private String translate(Language instance, String key, | ||
Operation<String> original) | ||
{ | ||
if(key != null && key.contains("wurst")) | ||
return key; | ||
|
||
return original.call(instance, key); | ||
} | ||
|
||
/** | ||
* Same as above, but for translatable text components with a fallback. | ||
*/ | ||
@WrapOperation(at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/util/Language;get(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", | ||
ordinal = 0), method = "updateTranslations()V") | ||
private String translateWithFallback(Language instance, String key, | ||
String fallback, Operation<String> original) | ||
{ | ||
if(key != null && key.contains("wurst")) | ||
return fallback; | ||
|
||
return original.call(instance, key, fallback); | ||
} | ||
} |
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
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
Oops, something went wrong.