diff options
Diffstat (limited to 'nselib/data/jdwp-class')
-rw-r--r-- | nselib/data/jdwp-class/JDWPExecCmd.java | 31 | ||||
-rw-r--r-- | nselib/data/jdwp-class/JDWPSystemInfo.java | 41 | ||||
-rw-r--r-- | nselib/data/jdwp-class/README.txt | 26 |
3 files changed, 98 insertions, 0 deletions
diff --git a/nselib/data/jdwp-class/JDWPExecCmd.java b/nselib/data/jdwp-class/JDWPExecCmd.java new file mode 100644 index 0000000..0b9af5d --- /dev/null +++ b/nselib/data/jdwp-class/JDWPExecCmd.java @@ -0,0 +1,31 @@ +import java.io.*; + +/* This is the JDWPExecCmd source used for jdwp-exec script to execute + * a command on the remote system. + * + * It just executes the shell command passed as string argument to + * run() function and returns its output. + * + * Compile simply with: + * javac JDWPExecCmd.java (should be in the nselib/data/ directory). + * + * author = "Aleksandar Nikolic" + * license = "Same as Nmap--See https://nmap.org/book/man-legal.html" +*/ + +public class JDWPExecCmd { + public static String run(String cmd) { + String result = cmd + " output:\n"; + try{ + Process p = Runtime.getRuntime().exec(cmd); + BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = null; + while ((line = in.readLine()) != null) { + result += line.trim()+"\n"; + } + result += "\n"; + }catch(Exception ex){ + } + return result; + } +} diff --git a/nselib/data/jdwp-class/JDWPSystemInfo.java b/nselib/data/jdwp-class/JDWPSystemInfo.java new file mode 100644 index 0000000..1ad4951 --- /dev/null +++ b/nselib/data/jdwp-class/JDWPSystemInfo.java @@ -0,0 +1,41 @@ +import java.io.*; +import java.util.Date; +/* This is the JDWPSystemInfo source used for jdwp-info script to get remote + * system information. + * + * Compile simply with: + * javac JDWPSystemInfo.java (should be in the nselib/data/jdwp-class directory). + * + * author = "Aleksandar Nikolic" + * license = "Same as Nmap--See https://nmap.org/book/man-legal.html" +*/ + +public class JDWPSystemInfo { + public static String run() { + String result = ""; + result += "Available processors: " + Runtime.getRuntime().availableProcessors() + "\n"; + result += "Free memory: " + Runtime.getRuntime().freeMemory() + "\n"; + File[] roots = File.listRoots(); + for (File root : roots) { + result += "File system root: " + root.getAbsolutePath() + "\n"; + result += "Total space (bytes): " + root.getTotalSpace() + "\n"; + result += "Free space (bytes): " + root.getFreeSpace() + "\n"; + } + result += "Name of the OS: " + System.getProperty("os.name") + "\n"; + result += "OS Version : " + System.getProperty("os.version") + "\n"; + result += "OS patch level : " + System.getProperty("sun.os.patch.level") + "\n"; + result += "OS Architecture: " + System.getProperty("os.arch") + "\n"; + result += "Java version: " + System.getProperty("java.version") + "\n"; + result += "Username: " + System.getProperty("user.name") + "\n"; + result += "User home: " + System.getProperty("user.home") + "\n"; + Date dateNow = new Date(); + result += "System time: " + dateNow + "\n"; + + return result; + } + + public static void main(String[] args){ + System.out.println(run()); + } + +} diff --git a/nselib/data/jdwp-class/README.txt b/nselib/data/jdwp-class/README.txt new file mode 100644 index 0000000..aaac1f5 --- /dev/null +++ b/nselib/data/jdwp-class/README.txt @@ -0,0 +1,26 @@ +This directory contains sources and compiled classes +used by jdwp-* scripts. + +All classes must have run() method defined which is +expected to return a string. +Method run() can have arguments, but then the scripts +would need to be modified to add those arguments when +class is injected. As JDWPExecCmd has a run() method +which accepts a string as its argument, see +jdwp-exec script for details of passing the +arguments to a method via JDWP. +Arguments need to be tagged with their respective type. +For other tags see http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html#wp9502 . +Example from jdwp-exec: + + local cmdID + status,cmdID = jdwp.createString(socket,0,cmd) + local runArgs = string.pack(">B I8", 0x4c, cmdID) -- 0x4c is object type tag + -- invoke run method + local result + status, result = jdwp.invokeObjectMethod(socket,0,injectedClass.instance,injectedClass.thread,injectedClass.id,runMethodID,1,runArgs) + +To compile these sources: +# javac *.java + + |