Re: socket programming...lsof?



Derek Smith <derekbellnersmith@xxxxxxxxx> wrote:
env ruby -w
require 'socket'
host = 'localhost'
port = 22
#
s = TCPSocket.open(host, port)

while line = s.gets # Read lines from the socket
puts line.chop # And print with platform line terminator
end
s.close # Close the socket when done


derek@vaio-ubuntu:~$ sudo ruby port_tst.rb
SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1

What if I want to see any data passing over that port, 113 or any other
port? Any adjustments in this code?

You should actually use something like tcpdump or some other sniffer.
See http://en.wikipedia.org/wiki/Tcpdump for more info.

Since tcpdump uses libpcap, and there are libpcap bindings for Ruby, so
you could probably do this via the Ruby bindings without much
difficulty (I've never tried this).

SSH port 22 seems to work, well sort of. When connections come in,
shouldn't I see some type of encryption strings?

No, not at all.

Your current code is opening a new and private connection to a TCP
server (sshd). This is just as if you're normally opening a new ssh
client connection to your server (without actually going through the
handshake.

TCP connections are generally private (unicast). That is when a client
connects to a server, that connection is a bidirectional bytestream
only intended for the client and server to consume.

You need special OS-level tracing tools like libpcap (or knowledge
of obscure syscalls which libpcap uses) to listen into the private
server<->client channel as a 3rd party.

--
Eric Wong

.



Relevant Pages

  • Re: Still cant connect to RWW or OWA remotely
    ... it certainly appears to be something about the SBS configuration. ... Meridian.local Ethernet adapter Local Area Connection: ... Windows SMALL BUSINESS SERVER 2003 Windows IP Configuration ... 192.168.254.254) directly to a port on the router and then ...
    (microsoft.public.windows.server.sbs)
  • Re: Still cant connect to RWW or OWA remotely
    ... it certainly appears to be something about the SBS configuration. ... Meridian.local Ethernet adapter Local Area Connection: ... Windows SMALL BUSINESS SERVER 2003 Windows IP Configuration ... 192.168.254.254) directly to a port on the router and then ...
    (microsoft.public.windows.server.sbs)
  • RE: VBscript Error on SBS2k3
    ... DHCP Server turned of SonicWALL with VPN Pass through request for IP to ... the problem should be caused by the 4125 port. ... > | Accessories and Communications and Remote Desktop Connection? ... > | 2.In Internet Explorer on the workstation you are connecting from, ...
    (microsoft.public.windows.server.sbs)
  • Re: interfaces lo:1 lo:2 lo:3? (for remote ssh tunnels)
    ... That's the problem tunneling (port forwarding) solves. ... >>can't get past the client firewall. ... > I don't understand why the server would be making the ... server initiates another connection to the client -- in this ...
    (Debian-User)
  • Re: Can not access Web and FTP sites from Internet
    ... your IP Configuration on the Server is correctly. ... Connecting To 12.208.215.87...Could not open connection to the host, ... 1> From the result, we can see the telnet failed, which means the router ... does not forward Port 443 to SBS Server. ...
    (microsoft.public.windows.server.sbs)