Remote shell with Java and netcat
Results 1 to 3 of 3

Thread: Remote shell with Java and netcat

  1. #1
    Senior Member
    Join Date
    Jun 2003
    Posts
    772

    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: http://www.atstake.com/research/tool...ork_utilities/
    Someone might possibly learn *cough* something from this...

    Code:
    import java.io.*;
    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 = System.in.read()) != '\n')
    			buffer.append((char)c);
    			
    			String string = buffer.toString().trim();
    			
    			if (string.equalsIgnoreCase("exit"))
    			System.exit(0);	
    			
    			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("\n---------------------");
    		    	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");
    		    	System.out.println("---------------------\n");
    		    	
    		    		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);
    		            System.out.println(questions[num]);
    		            	
    		             while ((d = System.in.read()) != '\n')
    		              input_buffer.append((char)d);
    		             
    		             String answer = input_buffer.toString().trim();
    		             if (answer.equalsIgnoreCase(answers[num]))
    		               System.out.println("Correct!\n");
    		             else if(answer.equalsIgnoreCase("quit"))
    		                return;
    		             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());
    	    	e.printStackTrace();
    	      }
    	} 
    }
    Shell.bat:
    Code:
    @echo off
    cd \dev\java
    java Shell
    RemoteShell.bat:
    Code:
    @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

    www.elhalf.com

  2. #2
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    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.

    edit
    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
    Posts
    772
    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

    www.elhalf.com

Posting Permissions

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

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides