help with java.net
Results 1 to 7 of 7

Thread: help with java.net

  1. #1
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407

    help with java.net

    After reading Rioter's netbios hacking tutorial, and starting to work with the java.net package, and decided to make a fake "server" that listens on port 139. The only problem is that I wanted it to be where if you typed:
    nbtstat -A 24.243.64.239
    at the command prompt it would give you the same output as if it were real. But the nbtstat command doesn't recognize my "server" and I'm guessing it would be impossible, or at least nearly impossible to get it to work. The best I can do right now is get it to where if you type:
    telnet 24.243.64.239 139
    at the prompt it will take you to a telnet session, then from there if you type:
    nbtstat -A 24.243.64.239
    it will give you what you would see if you did it normally, only it is just text that i made up.
    next you would type:
    net view \\24.243.64.239
    and it will show you that I'm sharing my c drive.
    Then you type:
    net use z: \\24.243.64.239\c
    and it will say, your ip has been logged and your isp will be contacted, then it ends the session. Actually you could type anything and it will give you the same messages. But let that be our little secret.
    I recommend that you see this for yourself by doing the above steps. It is really neat I think.
    My question is, How can I get it to do the same except by using the nbtstat -A command instead of telnetting on port 139. Because telnetting wouldn't work anyway and if anyone were to try this trick on me they would use nbtstat or nmblookup. The only way I can think of would be to write the netbios protocol into the program. But I don't know it and I don't think I could even if I did. So my question is does anyone know how this can be done(getting it to respond to nbtstat)?
    please check out this program by telnetting to it with:
    telnet 24.243.64.239 139
    thanks for the help.

    here is some of the code if it helps

    Code:
    import java.net.*;
    import java.io.*;
    import java.util.*;
    
    public class netprotocol {
        private static final int WAITING = 0;
        private static final int SENTKNOCKKNOCK = 1;
        private static final int SENTCLUE = 2;
        private static final int ANOTHER = 3;
        private static final int END = 4;
    
        private int state = WAITING;    
    
        public String processInput(String theInput) {
            String theOutput = "";
            Date date = new Date();
    
            if (state == WAITING) {
    
                state = SENTKNOCKKNOCK;
            } else if (state == SENTKNOCKKNOCK) {
                if (theInput.equalsIgnoreCase("nbtstat -A 24.243.64.239") || theInput.equalsIgnoreCase("nmblookup -A 24.243.64.239")) {
                    theOutput = "      NetBIOS Remote Machine Name Table" +
                    "\n\n\r   Name               Type         Status"+
                    "\n\r---------------------------------------------"+
                    "\n\rFACES_COMP2    <00>  UNIQUE      Registered"+
                    "\n\rFACES_ETC      <00>  GROUP       Registered"+
                    "\n\rFACES_COMP2    <03>  UNIQUE      Registered"+
                    "\n\rFACES_COMP2    <20>  UNIQUE      Registered"+
                    "\n\rFACES_ETC      <1E>  GROUP       Registered"+
                    "\n\n\rMAC Address = 44-45-53-54-00-00";
                    state = SENTCLUE;
                } else {
                    theOutput = "      NetBIOS Remote Machine Name Table" +
                    "\n\n\r   Name               Type         Status"+
                    "\n\r---------------------------------------------"+
                    "\n\rFACES_COMP2    <00>  UNIQUE      Registered"+
                    "\n\rFACES_ETC      <00>  GROUP       Registered"+
                    "\n\rFACES_COMP2    <03>  UNIQUE      Registered"+
                    "\n\rFACES_COMP2    <20>  UNIQUE      Registered"+
                    "\n\rFACES_ETC      <1E>  GROUP       Registered"+
                    "\n\n\rMAC Address = 44-45-53-54-00-00";
                    state = SENTCLUE;
                }
            } else if (state == SENTCLUE) {
                if (theInput.equalsIgnoreCase("net view " )) {
                    theOutput = "Sharename    Type         Comment" +
                    "\n\r-------------------------------------------------------------------------------"+
                    "\n\rC            Disk "+
                    "\n\rThe command was completed successfully.";
                    state = ANOTHER;
                } else {
                    theOutput = "Sharename    Type         Comment" +
                    "\n\r-------------------------------------------------------------------------------"+
                    "\n\rC            Disk "+
                    "\n\rThe command was completed successfully.";
                    state = ANOTHER;
                }
                }
             else if (state == ANOTHER) {
                if (theInput.equalsIgnoreCase("net use ")) {
                    theOutput = "Your IP has been logged and your isp will be contacted";
                    state = WAITING;
                }
                else {
                        theOutput = "Your IP has been logged and your isp will be contacted";
                        state = WAITING;
                }}
                return theOutput;
            }
    
        }
    this is one of three programs. The other two set up the connection.

  2. #2
    Junior Member
    Join Date
    Dec 2002
    Posts
    3
    I don't think I could help you with your nbtstat problem but I was wondering if you could post some of the code from the other two programs that set up the connection. I just curious to see what you did and how you did it. Thanks

  3. #3
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    I basically used this stuff as a frame: http://java.sun.com/docs/books/tutor...entServer.html

    here are the other two programs:

    netmulti.java
    Code:
    package fakenetpkg;
    
    import java.net.*;
    import java.io.*;
    
    public class netmulti {
        public static void main(String[] args) throws IOException {
            ServerSocket serverSocket = null;
            boolean listening = true;
    
            try {
                serverSocket = new ServerSocket(139);
            } catch (IOException e) {
                System.err.println("Could not listen on port: 139.");
                System.exit(-1);
            }
    
            while (listening)
                new netmultithread(serverSocket.accept()).start();
    
            serverSocket.close();
        }
    }
    in the serverSocket = new ServerSocket(139); part, you can put any valid port number that is not already
    being used on your system. I used 139 because I was trying to fake the netbios thingy, but if you wanted
    a fake telnet for example, you would put 23 in there and change the error to say 23 also, although you
    don't have to change the error part.

    netmultithread.java
    Code:
    package fakenetpkg;
    
    import java.net.*;
    import java.io.*;
    
    public class netmultithread extends Thread {
        private Socket socket = null;
    
        public netmultithread(Socket socket) {
            super("netmultithread");
            this.socket = socket;
        }
    
        public void run() {
    
            try {
                PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
                BufferedReader in = new BufferedReader(
                                        new InputStreamReader(
                                        socket.getInputStream()));
    
                String inputLine, outputLine;
                netprotocol kkp = new netprotocol();
                outputLine = kkp.processInput(null);
                out.println(outputLine);
    
                while ((inputLine = in.readLine()) != null) {
                    outputLine = kkp.processInput(inputLine);
                    out.println(outputLine);
                    if (outputLine.equals("Your IP has been logged and your isp will be contacted"))
                        break;
                }
                out.close();
                in.close();
                socket.close();
    
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    I used that in jbuilder9 and that explains the package thing at the top. if you're not doing this as a project,
    and by that I mean the different file type in jbuilder9, then you would just remove the line that says
    "package fakenetpkg;". I originally did this in JCreator without using a project and that is the code I
    posted initially, if I was using jbuilder with a project I would have had to put the package name at the top
    of that file too. Well, there are the files, have fun developing.

  4. #4
    Member
    Join Date
    Aug 2003
    Posts
    42
    Hi,

    I would really like to devote more time to working on your problem, but I'm at work right now, I'll try to take a more in depth look at it later. I do, however, have a question and a suggestion. When you say that nbtstat doesn't "recognize" your server, what do you mean? Does your program hang? Does an error generate a stack trace(although I'm sure you would have posted that)?

    The program itself looks sound, however there is one thing that I noticed. Your problem may have less to do with java.net, and more to do with java.io. Assuming that your ServerSocket is actually creating a Socket object from its accept method, then the problem may lie with in the netmultithread's implementation of the run() method. You can see that the program is using a BufferedReader Object to handle the incoming I/O. In particular, the readLine() method is used to get the data from the inputStream. readLine() is a method used for receiving text data, which is why when you telnet into port 139 with your server running and begin typing ascii charcters, you get a response.

    I think there may be a good chance that the nbtstat program that you run at the command line does not try to send a text stream, but rather a byte array containing data that is better received on your end by using a DataInputStream. You can use a DataInputStream to read raw bytes from your Socket's inputStream using either the read(byte[] b) method or the readFully(byte[] b) method. The DataInputStream is a member of java.io.

    Basically, I am suggesting that you try and replace the BufferedReader with a DataInputStream and instead of readLine() use the read(byte[] b) method. You can still interpet ascii characters from the byte array, it will just take a little more work. I could be totally wrong, but I will look into this later. good luck.

  5. #5
    Member
    Join Date
    Aug 2003
    Posts
    42
    I've had a chance to look over the program and it seems that nbtstat is returning "Host not found" with the Server process running on port 139. The first order of business is to establish a connection using nbtstat. I will continue to look into the problem, unfortunately I'm at work again, so it may take a while. Please let me know if you make any progress.

  6. #6
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    What you said in the first post was beyond my knowledge of java. The actual netmultithread program was taken right from the java.sun site. I think the problem is that the nbtstat command sends something to a specific program on the host computer which responds, and We would have to make this program act like the real program for it to work. Perhaps a fake telnet is better since you just telnet to that and there is set program to respond. I think it would require a great deal of work to get this program to act like the true program set to respond to nbtstat queries. I have pretty much given up on this, it was just a little project for a few days I had. I have a new little project to work on every few days. Thanks for your input, I don't know if I would be much help to you if you were to continue trying to get this to work, but I could try. Good luck if you try to work on it.

  7. #7
    Member
    Join Date
    Aug 2003
    Posts
    42
    I've actually made some interesting progress, I'll wait until I either get it to work or give up to post my results.

Posting Permissions

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