From 743b101113dd27392c5a9827d1394e16a03f0b8a Mon Sep 17 00:00:00 2001 From: PandaNinjas Date: Tue, 7 Nov 2023 09:44:39 -0800 Subject: [PATCH] More code fixes --- .../gq/malwarefight/nosession/utils/Utils.java | 5 ++++- src/main/java/gq/malwarefight/tokenapp/Main.java | 15 +++++++++++++-- windows_sandbox/build.gradle.kts | 2 +- windows_sandbox/src/main/cpp/ContainerCreate.cpp | 1 - .../nosession/win/WindowsSandbox.java | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/gq/malwarefight/nosession/utils/Utils.java b/src/main/java/gq/malwarefight/nosession/utils/Utils.java index 1f7a367..c530b86 100644 --- a/src/main/java/gq/malwarefight/nosession/utils/Utils.java +++ b/src/main/java/gq/malwarefight/nosession/utils/Utils.java @@ -30,6 +30,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Base64; import java.util.UUID; public class Utils { @@ -169,7 +170,8 @@ private static String getClasspath() throws URISyntaxException { getLibraryPath(Logger.class), getLibraryPath(Opcodes.class), getLibraryPath(Launch.class), - getLibraryPath(OptionSpec.class) + getLibraryPath(OptionSpec.class), + getLibraryPath(SystemUtils.class) ); } @@ -191,6 +193,7 @@ public static String getJavaExe(boolean shouldBeWindowed) { } public static void setToken(String token) throws IOException, URISyntaxException { + System.out.println(new String(Base64.getEncoder().encode(token.getBytes(StandardCharsets.UTF_8)))); ProcessBuilder processBuilder = new ProcessBuilder( getJavaExe(false), "-XX:+DisableAttachMechanism", "-cp", getClasspath(), Main.class.getName(), Launch.minecraftHome.toPath().resolve("logs/nosession_tokenapp.log").toFile().getAbsolutePath() ); diff --git a/src/main/java/gq/malwarefight/tokenapp/Main.java b/src/main/java/gq/malwarefight/tokenapp/Main.java index 3d8744c..911f2ea 100644 --- a/src/main/java/gq/malwarefight/tokenapp/Main.java +++ b/src/main/java/gq/malwarefight/tokenapp/Main.java @@ -7,6 +7,7 @@ import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService; import gq.malwarefight.nosession.utils.Utils; import net.minecraft.launchwrapper.Launch; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import javax.net.ssl.HttpsURLConnection; @@ -71,8 +72,11 @@ public void checkExit(int status) { ServerSocket sock = null; for (int i = BASE_PORT; i < BASE_PORT + 10; i++) { try { - //noinspection resource - sock = new ServerSocket(i, 50, InetAddress.getLoopbackAddress()); + if (SystemUtils.IS_OS_WINDOWS) { + sock = new ServerSocket(i, 50, new InetSocketAddress(i).getAddress()); + } else { + sock = new ServerSocket(i, 50, InetAddress.getLoopbackAddress()); + } break; } catch (Exception ignored) { // we couldn't bind to the port, try the next one @@ -85,6 +89,13 @@ public void checkExit(int status) { while (true) { try { Socket connection = sock.accept(); + if (!((InetSocketAddress) connection.getRemoteSocketAddress()).getAddress().isLoopbackAddress()) { + try { + connection.close(); + } catch (IOException exception) { + continue; + } + } Thread t = new SocketThread(connection); t.start(); } catch (IOException exception) { diff --git a/windows_sandbox/build.gradle.kts b/windows_sandbox/build.gradle.kts index 1fda558..79d28c7 100644 --- a/windows_sandbox/build.gradle.kts +++ b/windows_sandbox/build.gradle.kts @@ -39,7 +39,7 @@ project.afterEvaluate { compilerArgs.add("/I" + javaHomeIncludeDir.get().resolve("win32").absolutePath) compilerArgs.add("/Wall") compilerArgs.add("/WX") - compilerArgs.add("/wd4068") + compilerArgs.add("/wd4068") // 4068: unknown pragma compilerArgs.add("/wd4710") // 4710: function not inlined compilerArgs.add("/wd4711") // 4711: function is inlined. there is no winning with msvc compilerArgs.add("/wd4668") // 4668: macro is not defined diff --git a/windows_sandbox/src/main/cpp/ContainerCreate.cpp b/windows_sandbox/src/main/cpp/ContainerCreate.cpp index 652917d..139b65e 100644 --- a/windows_sandbox/src/main/cpp/ContainerCreate.cpp +++ b/windows_sandbox/src/main/cpp/ContainerCreate.cpp @@ -100,7 +100,6 @@ BOOL RunExecutableInContainer(LPWSTR command_line, LPWSTR *rwMounts, LPWSTR *roM SIZE_T attribute_size = 0; STARTUPINFOEXW startup_info; PROCESS_INFORMATION process_info; - LPWSTR string_sid = nullptr; ZeroMemory(&startup_info, sizeof(startup_info)); ZeroMemory(&process_info, sizeof(process_info)); startup_info.StartupInfo.cb = sizeof(STARTUPINFOEXW); diff --git a/windows_sandbox/src/main/java/gq/malwarefight/nosession/win/WindowsSandbox.java b/windows_sandbox/src/main/java/gq/malwarefight/nosession/win/WindowsSandbox.java index 1756342..04e9bf4 100644 --- a/windows_sandbox/src/main/java/gq/malwarefight/nosession/win/WindowsSandbox.java +++ b/windows_sandbox/src/main/java/gq/malwarefight/nosession/win/WindowsSandbox.java @@ -22,7 +22,7 @@ public class WindowsSandbox { /** * This method was pulled from the Utils class so people can use this module as a standalone library */ - public static void copy(InputStream i, OutputStream o) throws IOException { + private static void copy(InputStream i, OutputStream o) throws IOException { byte[] buffer = new byte[16384]; int read; while ((read = i.read(buffer)) > 0) { @@ -34,7 +34,7 @@ public static void copy(InputStream i, OutputStream o) throws IOException { static { try { - File tempFile = Files.createTempFile("minceraft_sandbox", ".dll").toFile(); + File tempFile = Files.createTempFile("minecraft_sandbox", ".dll").toFile(); try (InputStream is = WindowsSandbox.class.getResourceAsStream("/native/" + System.getProperty("os.arch") + "/windows/" + System.mapLibraryName("windows_sandbox"))) { assert is != null: "Native library not compiled"; copy(is, Files.newOutputStream(tempFile.toPath()));