Solved

Network Sniffer prog needed

Posted on 1998-05-27
8
263 Views
Last Modified: 2010-08-05
Hi C gurus,

This Q is sort of a cross post as I asked it in the CGI area but didn't have much luck. (only unix heads about and while I am a fan of unix I need something that will compile under Micro$oft NT for my laptop).

Does anybody have a utility sitting in their toolbox which listens to a specified port (80 for my web work) and sends everything to the standard out?

Something nice and simple that I can have running in a DOS session would be perfect. No rocket science required. I need to debug some progs (CGI etc...) and do not have anything on hand that will give me this level of access to the network.

Source would be nice so I can fiddle with it (and maybe learn a thing or two about network programming..)


Cheers
Marty
0
Comment
Question by:mravell
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:tflai
ID: 1251011
0
 

Author Comment

by:mravell
ID: 1251012
Hi tflai,

I checked this stuff out but was really after something that isn't a commercial / pay through the nose type application.

My needs are very modest.

Monitor Port x (80) and dump everything to standard out.

I don't need a high-end monitoring package, just a scrap of C code that somebody may have lyig around.


Cheers
Marty
0
 
LVL 4

Expert Comment

by:tflai
ID: 1251013
Socket Spy is a shareware.  And as far as I know, there are no full-fledge network snooper source code free anywhere.
It is not too difficult conceptually to implement a network snooper.  What you need is a promiscous protoocol driver and a application-layer shell that interact it through device I/O control and decode the packet headers for different protocols:  802.3, IP, TCP, ...  But to actually develop it is another thing...
But if you want a Winsock API snooper, I know where you can get a skeletal code for Winsock DLL replacement.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1251014
I'll second tflai's comments here but add a couple of points.  The only free network sniffers that I've seen are for MSDOS and unix/Linux systems.  In fact, there are several really good ones under Linux.  Under Windows, however, there is nothing in the low-price or free range.  
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:mravell
ID: 1251015
What I am after is more of a code snippet than a full package. I don't need any whistles or bells. Just something that listens to port 80 and dumps what it hears to the standard out.

No analysis, fancy graphics or logging features just a few lines of code that can eavesdrop on my own webserver.

Cheers
Marty
0
 
LVL 6

Accepted Solution

by:
gadio earned 250 total points
ID: 1251016
 mravell, I think I have an answer for you. I had a problem like that and I solved it in the folowing manner. I set up a small program that does routing to and from the port that you want to snoop and another port (say 1234), and while routing the stream of data, prints them out. When you make your connection make it to the same host but indicate port 1234 (insted of www.xxx.yyy/zzz write www.xxx.yyy:1234/zzz), the routing is tranparent to the client and you get your info. I have such a program written in java. You can actually run it on any machine. If this solution is good for you I'll comment in the source.

G.

0
 

Author Comment

by:mravell
ID: 1251017
Hi Gadio,

An interesteing idea. Not exactly what I had in mindbut it sounds as if it could do what I am after.

Please comment the code.


Marty
0
 
LVL 6

Expert Comment

by:gadio
ID: 1251018
Here it is. For each connection that takes place you get a window opened and shows you the in and out going data. Note that when you monitor http protocol, the client will probably open connection for each image that is on the page. Pages with many images on them will couse a lot of windows to be opend.
Enjoy, G.

------------- snooper.java --------------

/*******************************************************************
 *
 * Program: snooper.java Written by gadio.
 *
 * This program opens a window for each connection to a the port
 * that it bridges. The window have one area for the input and one
 * for the output. Once the communication in finished a close button
 * is enabled.
 *
 *******************************************************************/

import java.awt.*;
import java.net.*;
import java.io.*;

public class snooper {

    public snooper (int origport, int newport ) {
        try {
            ServerSocket srvs = new ServerSocket( newport );
            while(1) {
                Socket inconnect = srvs.accept();
                Socket bridge = new Socket("127.0.0.1",origport);
                snooperObj so = new snooperObj( inconnect, bridge );
            }
        } catch( IOException e ) {
            System.out.println(e);
        }
    }

    public static void main(String args[]) {
        snooper snoopy = new snooper(80, 1234);
    }
}


class snooperObj extends Frame {
    private Thread inMonitor, outMonitor;
    Socket inconnect;
    Socket bridge;
    TextArea in_txt, out_txt;
    connector con1, con2;
    Button close, clearin, clearout;

    public snooperObj( Socket incon, Socket brdg ) {
        inconnect = incon;
        bridge = brdg;
        setLayout( new BorderLayout());
        in_txt = new TextArea( 20, 20 );
        out_txt = new TextArea( 20, 20 );
        in_txt.setEditable(false);
        out_txt.setEditable(false);
        Panel north = new Panel();
        Panel center = new Panel();
        north.setLayout( new GridLayout(2,2));
        center.setLayout( new GridLayout(1,2));
        String time = (new java.util.Date(System.currentTimeMillis())).toString();
        north.add( new Label("into server ("+time+"):"));
        north.add( new Label("out from the server:"));
        north.add( clearin = new Button("Clear input"));
        north.add( clearout = new Button("Clear output"));
        center.add(in_txt);
        center.add(out_txt);
        add("North", north);
        add("Center", center);
        add("South", (close = new Button("Close window")));
        close.disable();
        pack();
        show();
        con1 = new connector( incon, bridge, in_txt, close );
        con2 = new connector( bridge, incon, out_txt, close );
    }

    public boolean handleEvent( Event e ) {
        if( e.target == close ) {
            con1.stop();
            con2.stop();
            con1 = null;
            con2 = null;
            hide();
            dispose();
            return true;
        }
        if( e.target == clearin ) {
            in_txt.setText("");
            return true;
        }
        if( e.target == clearout ) {
            out_txt.setText("");
            return true;
        }
        return false;
    }
}

class connector extends Thread {
    Socket from, to;
    TextArea txtout;
    Button end_button;

    public connector( Socket from_s, Socket to_s, TextArea txta, Button closeb ) {
        from = from_s;
        to = to_s;
        txtout = txta;
        end_button = closeb;
        start();
    }

    public void run() {
        try {
            InputStream is = from.getInputStream();
            OutputStream os = to.getOutputStream();
            while(1) {
                int b = is.read();
                os.write(b);
                txtout.append( ""+(char)b );
            }
        } catch(IOException e) {
            end_button.enable();
        }
    }
}

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now