Run UNIX command EXTERNALLY

Discussion in 'Spigot Plugin Development' started by NewEraStudios, Jul 5, 2018.

  1. Hello guys! I have a problem.

    When i make my plugin execute a LINUX command, the command is done in the SAME SERVER JAVA PROCESS.

    Code (Text):




    public class EffRunCmd
      extends Effect
    {
      static String o = "";
     
      public EffRunCmd() {}
     
      protected void execute(Event e) { String cmd = (String)cmdr.getSingle(e);
        try {
          Process localProcess = Runtime.getRuntime().exec(cmd);
        }
        catch (IOException x) {
          skUtilities.prSysE("Can't run Command: '" + cmd + "' - '" + x.getMessage(), String.valueOf(getClass().getSimpleName()) + "'", x);
        }
      }
     
      private Expression<String> cmdr;
      public boolean init(Expression<?>[] e, int i, Kleenean k, SkriptParser.ParseResult p) { cmdr = e[0];
        return true;
      }
     
      public String toString(@Nullable Event e, boolean b) {
        return getClass().getName();
      }
    }
     

    Is it posible to run a Linux command in the machine, but EXTERNAL to the server java process?

    Thank you!
     
  2. Pretty sure not, as that would be considered a major security flaw, I do however remember being send a plugin that would allow the users to assign more ram to their server process (problem some server hosting company encountered). Never verified it, and kinda lost the file :oops:
     
    #2 JustDJplease, Jul 5, 2018
    Last edited: Jul 5, 2018
  3. The only way I can imagine you could do something like this would to create some kind of cron job from your plugin, then have the external system execute it at a specific interval. Kind of like creating a task on windows which would be executed by the task manager. Removing the JVM from the picture entirely.

    If you run anything from your Java code the JVM will automatically sandbox it.

    Think about how a SMTP server reads and sends mail. It has a read folder and send folder, you could have another JAR running, listening for specific jobs to be executed.

    This is essentially how Java viruses escape the JVM sandbox, not that I'm condoning that type of activity, but that's how you do it.
     
    #3 DivineAnimation, Jul 5, 2018
    Last edited: Jul 6, 2018
    • Informative Informative x 1