diff options
author | PandaNinjas <admin@malwarefight.gq> | 2023-05-19 17:15:46 -0400 |
---|---|---|
committer | PandaNinjas <admin@malwarefight.gq> | 2023-05-19 17:15:46 -0400 |
commit | d30a5775fab3f4e8968e4066a5e59a4b953d8870 (patch) | |
tree | b530ea31755685193192230f5e570947caf2cba1 /src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java | |
parent | ca67ac4481ce308d42ab33defdee2e54e2ca82ab (diff) | |
download | NoSession-d30a5775fab3f4e8968e4066a5e59a4b953d8870.tar.gz NoSession-d30a5775fab3f4e8968e4066a5e59a4b953d8870.tar.bz2 NoSession-d30a5775fab3f4e8968e4066a5e59a4b953d8870.zip |
stuff
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java')
-rw-r--r-- | src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java | 111 |
1 files changed, 78 insertions, 33 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java b/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java index b61665f..9e0eb27 100644 --- a/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java +++ b/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java @@ -1,24 +1,28 @@ package gq.malwarefight.nosession; +import gq.malwarefight.nosession.linux.bwrap.BubblewrapBuilder; +import gq.malwarefight.nosession.linux.libc.Libc; import gq.malwarefight.nosession.relaunch.Relaunch; import gq.malwarefight.nosession.tweaks.initial.InitialTweaker; import gq.malwarefight.nosession.utils.Utils; +import net.minecraft.launchwrapper.Launch; +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; +import org.apache.commons.lang3.SystemUtils; +import org.apache.logging.log4j.LogManager; + +import java.io.File; import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.minecraft.launchwrapper.Launch; -import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; +@SuppressWarnings("unused") @IFMLLoadingPlugin.MCVersion("1.8.9") @IFMLLoadingPlugin.Name("NoSession trolling") @IFMLLoadingPlugin.SortingIndex(0) @@ -39,20 +43,14 @@ public class NoSessionLoadingPlugin implements IFMLLoadingPlugin { } @Override - public void injectData(Map<String, Object> map) {} + public void injectData(Map<String, Object> map) { + } @Override public String getAccessTransformerClass() { return null; } - public static void shutdown() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Class<?> shutdown = Class.forName("java.lang.Shutdown"); - Method m = shutdown.getDeclaredMethod("exit", int.class); - m.setAccessible(true); - m.invoke(null, 0); - } - @SuppressWarnings("unchecked") public static void injectTweaker() { ArrayList<String> tweakClassList = (ArrayList<String>) Launch.blackboard.get("TweakClasses"); @@ -65,7 +63,7 @@ public class NoSessionLoadingPlugin implements IFMLLoadingPlugin { public static ArrayList<String> constructLaunchArgs(HashMap<String, String> args) { ArrayList<String> constructedArgs = new ArrayList<>(); - for (Entry<String, String> entry: args.entrySet()) { + for (Entry<String, String> entry : args.entrySet()) { if (entry.getKey().equals("--accessToken")) { constructedArgs.add(entry.getKey()); constructedArgs.add("<noSessionAccessToken>"); @@ -77,31 +75,75 @@ public class NoSessionLoadingPlugin implements IFMLLoadingPlugin { return constructedArgs; } + public static void relaunchProcess(Matcher m) throws Exception { + RuntimeMXBean rmb = ManagementFactory.getRuntimeMXBean(); + if (!SystemUtils.IS_OS_LINUX) { + ArrayList<String> args = new ArrayList<>(); + args.add(Utils.getJavaExe()); + args.add("-cp"); + args.add(System.getProperty("java.class.path")); + args.addAll(rmb.getInputArguments()); + String newArgs = m.replaceAll("--accessToken <noSessionAccessToken>"); + args.addAll(Arrays.asList(newArgs.split(" "))); + ProcessBuilder processBuilder = new ProcessBuilder( + args.toArray(new String[0]) + ).inheritIO(); + try { + processBuilder.start(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + BubblewrapBuilder builder = new BubblewrapBuilder() + .setCommand(Utils.getJavaExe()) + .unshareAll() + .shareNet() + .setHostname("nosession-on-top") + .readOnlyBind("/usr", "/usr") + .mountTmpfs("/tmp") + .mountTmpfs("/var") + .mountProc("/proc") + .mountDev("/dev") + .readOnlyBind("/etc/resolv.conf", "/etc/resolv.conf") + .addSymlink("usr/lib", "/lib") + .addSymlink("usr/lib64", "/lib64") + .addSymlink("usr/bin", "/bin") + .addSymlink("usr/sbin", "/sbin") + .createDir("/run/user/" + Libc.geteuid()) + .setEnv("XDG_RUNTIME_DIR", "/run/user/" + Libc.geteuid()) + .readOnlyBind(System.getProperty("java.home"), System.getProperty("java.home")) + .bind(Launch.minecraftHome.getAbsolutePath(), Launch.minecraftHome.getAbsolutePath()) + .bind(Launch.assetsDir.getAbsolutePath(), Launch.assetsDir.getAbsolutePath()) + .readOnlyBind(Utils.getLibraryPathAsFile(NoSessionLoadingPlugin.class).getAbsolutePath(), Utils.getLibraryPathAsFile(NoSessionLoadingPlugin.class).getAbsolutePath()); + if (System.getenv("XDG_SESSION_TYPE").equals("x11")) { + LogManager.getLogger().warn("X11 detected, enabling X11 passthrough, which could allow keyloggers to work"); + } + builder.bind("/tmp/.X11-unix/X" + System.getenv("DISPLAY").substring(1), "/tmp/.X11-unix/X0") + .setEnv("DISPLAY", ":0"); + // add all the entries on the classpath read only + String classPath = rmb.getClassPath(); + for (String path : classPath.split(System.getProperty("path.separator"))) { + File lib = new File(path); + builder.readOnlyBind(lib.getAbsolutePath(), lib.getAbsolutePath()); + } + builder.addArgs("-cp", rmb.getClassPath(), "net.minecraft.launchwrapper.Launch"); + // blackboard erases the type, but we are sure that launchArgs will always be a HashMap<String, String> + //noinspection unchecked + builder.addArgs(constructLaunchArgs((HashMap<String, String>) Launch.blackboard.get("launchArgs"))); + builder.addArgs("--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker"); + builder.build().start(); + } + Utils.shutdown(); + } + static { addSelfToClassLoader(); try { - Properties p = Utils.getJavaProperties(); Pattern mcJWT = Pattern.compile("--accessToken +(?<token>eyJhbGciOiJIUzI1NiJ9\\.[A-Za-z0-9-_]*\\.[A-Za-z0-9-_]*)"); - Matcher m = mcJWT.matcher(p.getProperty("sun.java.command")); + Matcher m = mcJWT.matcher(System.getProperty("sun.java.command")); if (m.find()) { Utils.setToken(m.group("token")); - RuntimeMXBean rmb = ManagementFactory.getRuntimeMXBean(); - ArrayList<String> args = new ArrayList<>(); - args.add(Utils.getJavaExe(p)); - args.add("-cp"); - args.add(p.getProperty("java.class.path")); - args.addAll(rmb.getInputArguments()); - String newArgs = m.replaceAll("--accessToken <noSessionAccessToken>"); - args.addAll(Arrays.asList(newArgs.split(" "))); - ProcessBuilder processBuilder = new ProcessBuilder( - args.toArray(new String[0]) - ).inheritIO(); - try { - processBuilder.start(); - } catch (IOException e) { - throw new RuntimeException(e); - } - shutdown(); + relaunchProcess(m); } else { // test if we can find the token in Launch.blackboard.get("launchArgs") //noinspection unchecked @@ -114,6 +156,9 @@ public class NoSessionLoadingPlugin implements IFMLLoadingPlugin { System.out.println("======================="); System.out.println("NoSession: relaunching without the token"); System.out.println("======================="); + if (SystemUtils.IS_OS_LINUX) { + relaunchProcess(m); + } try { Relaunch.relaunch(constructLaunchArgs(launchArgs)); } catch (Exception e) { |