From d30a5775fab3f4e8968e4066a5e59a4b953d8870 Mon Sep 17 00:00:00 2001 From: PandaNinjas Date: Fri, 19 May 2023 17:15:46 -0400 Subject: stuff --- .../gq/malwarefight/nosession/linux/libc/Libc.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java (limited to 'src/main/java/gq/malwarefight/nosession/linux/libc') diff --git a/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java b/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java new file mode 100644 index 0000000..670f83d --- /dev/null +++ b/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java @@ -0,0 +1,31 @@ +package gq.malwarefight.nosession.linux.libc; + +import gq.malwarefight.nosession.utils.Utils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.InputStream; +import java.nio.file.Files; + +public class Libc { + private static final Logger log = LogManager.getLogger(); + public static native int geteuid(); + public static native void unlink(String pathname); + + static { + try { + File tempFile = Files.createTempFile("nosession_libc", ".so").toFile(); + try (InputStream is = Libc.class.getResourceAsStream("/native/" + System.getProperty("os.arch") + "/" + System.getProperty("os.name") + "/" + System.mapLibraryName("linux"))) { + assert is != null: "Native library not compiled"; + Utils.copy(is, Files.newOutputStream(tempFile.toPath())); + } + System.load(tempFile.getAbsolutePath()); + Runtime.getRuntime().addShutdownHook( + new Thread(() -> Libc.unlink(tempFile.getAbsolutePath())) + ); + } catch (Exception e) { + log.error("Failed to load the native Linux modules, native libraries may fail", e); + } + } +} -- cgit