Results 1 to 3 of 3

Thread: Remote shell with Java and netcat

  1. #1
    Senior Member
    Join Date
    Jun 2003

    Remote shell with Java and netcat

    Coded this thing cause my dad asked, did it quick so there are probably better ways to do certain things...
    This thing was already on my computer, that's why it's with 2 batch files as I first didn't have the intention to make it remotely accessible. You'll need to modify the batch files to make it working properly on your box.
    You also need netcat which can be obtained here:
    Someone might possibly learn *cough* something from this...

    import java.util.Random;
    public class Shell {
    	public static void main(String[] args) {
    		int c;
    		StringBuffer buffer = new StringBuffer(128);
    		System.out.println("\nRemoteShell 1.1b\n");
    		System.out.println("Type help to view available commands\n");
    		try {
    		while (true) {
    		   while ((c = != '\n')
    			String string = buffer.toString().trim();
    			if (string.equalsIgnoreCase("exit"))
    			else if(string.equalsIgnoreCase("user"))
    			System.out.println("a person (probably)");
    			else if(string.equalsIgnoreCase("about")) {
    			System.out.println("\nRemoteShell 1.1b\n");
    			System.out.println("Running on some OS");
    		    else if (string.equalsIgnoreCase("help")) {
    		    System.out.println("\nquiz - start quiz");
    		    System.out.println("about - show shell/system information");
    		    System.out.println("user - displays current user");
    		    System.out.println("exit - exits RemoteShell\n");
    /*quiz*/    else if (string.equalsIgnoreCase("quiz")) {  
    		    	System.out.println("RemoteShell Quiz 1.0a\n");
    		    	System.out.println("Problem when you use telnet");
    		    	System.out.println("Better use netcat");
    		    	System.out.println("Type quit to exit");
    		    		String[] questions = new String[4];
    		            questions[0] = "What is the first name of Bart Simpson's father?";
    		            questions[1] = "What is the answer to this question?";
    		            questions[2] = "What does TCP mean?";
    		            questions[3] = "What caused the craters on the moon?";
    		            String[] answers = new String[4];
    		            answers[0] = "Homer";
    		            answers[1] = "How should I know";
    		            answers[2] = "Transmission Control Protocol";
    		            answers[3] = "meteorites";
    		            StringBuffer input_buffer = new StringBuffer(128);
    		            Random random = new Random();
    		            int d;
    		            int num;
    		            while (true) {		            
    	                num = (int) (random.nextDouble()*4);
    		             while ((d = != '\n')
    		             String answer = input_buffer.toString().trim();
    		             if (answer.equalsIgnoreCase(answers[num]))
    		             else if(answer.equalsIgnoreCase("quit"))
    		             else System.out.println("Wrong, the correct answer is " + answers[num] + "\n");
    		             input_buffer.delete(0, 128);
    /*end quiz*/}     
    		    buffer.delete(0, 128);
    	    } catch (IOException e) {
    	    	System.err.println("Exception: " + e.toString());
    @echo off
    cd \dev\java
    java Shell
    @echo off
    echo Remote Shell 1.1b Server
    echo ------------------------
    cd \dev\java
    nc -L -p 23 -e Shell.bat -t -vv
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

  2. #2
    Elite Hacker
    Join Date
    Mar 2003
    I had only a few problems.

    1. If i mistyped something and used backspace it wouldn't recognize it even if it was correct.

    2. When doing the quiz, for each question before you even answer it gives you the response
    Wrong, the correct answer is meteorites

    then outputs the question again which you now know the answer to. Other than that, it's ok. A good base for someone to build on. Thanks for sharing.

    I also just got this error after letting it sit for a long time:

    Exception in thread "main" java.lang.OutOfMemoryError
    Invalid function

    but when I tried to connect to it after that it still worked so I don't know what happened.

  3. #3
    Senior Member
    Join Date
    Jun 2003
    I know, but if you connect to it with netcat there are no problems anymore, the problem is, I can't get it to work decent with both telnet/putty and netcat. If I make it so that it works with telnet and putty it looks messed up when you use netcat.
    When you use netcat it doesn't answer by itself(I think when you use telnet or something there is something different when you enter a carriage return then with netcat).

    So people: this doesn't work like it's supposed to work when you connect to it with telnet or putty. Use netcat!
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts