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/linux/libc/Libc.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/linux/libc/Libc.java')
-rw-r--r-- | src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java | 31 |
1 files changed, 31 insertions, 0 deletions
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); + } + } +} |