[CODE] Linux Shell Command Line (through Java)

+4 jan burg · November 8, 2014
This code can easily be changed to execute code in the windows command shell too. I made this a few days ago, thought I'd share for anyone who's interested. This could be useful if you know shell code or want to do some file system operations through java.

What would be interesting is to have another method to detect what operating system your on... then maybe add some socket connection... and bam, you got a multi-platform hacking app.. with the best intentions of course.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class apples {
   public static void main(String[] args) throws IOException, InterruptedException {
    System.out.println("--------Command Line-------------");
    Scanner input = new Scanner(System.in);
        String command = "";
        while (!command.equals("exit")){
            System.out.print("Enter a command or \"exit\" to exit: ");
            command = input.nextLine();
            String[] cmd = {"/bin/sh","-c",command};

//execute shells commands and shows output
   static int shellExec(String[] args) throws IOException, InterruptedException{
        Runtime r = Runtime.getRuntime();
        Process p = r.exec(args);
        BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = "";

        while ((line = b.readLine()) != null) {

        return p.waitFor();


Post a Reply


Oldest  Newest  Rating
0 Alex Sweps · November 8, 2014
You just gave me an idea. You could use this as a backdoor by having it connect back to your listening server :P Would save using netcat or a php shell. Only thing is they would have to have java installed. Im sure there would be a method that checks some os related stuff to determine what distroe you are running on.
0 jan burg · November 8, 2014
Yeah, my java isn't quite good enough yet to code it, but I'd like to try and make something like that. It would definitely be nice to try between linux and windows.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator