🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3312

Re: finding the current socket of your telnet session

#3312
From: Vic Abell
Date: Sun, 03 Nov 1996 00:00
57 lines
3190 bytes
dbin@sce.de (David Binette) writes:

>Fine, i picked up lsof, its a well produced package with a good eye to
>security.

>Butwhat i really want to do is to find the IP address or name for the
> originator of a process...
>say for example a user is running process 16502 and i want to know the IP
> address of the rlogin/telnet/ftp/rexec/whatever that it comes from.

>does anyboddy have a non-perl solution for this?

Read the 00QUICKSTART documentation that comes with lsof.  Section
9, "Deciphering the Remote Login Trail," gives examples for several
UNIX dialects on how to identify remotely originated connection
processes when you know the originating Internet address, then
using that information to identify other processes initiated by
the connection process.

Reversing that sequence will go from a known process to the Internet
address of the incoming connection process.

Here's an example from SCO Release 3.0, taking three lsof probes.
Of course, with a Perl script (or AWK, if you don't like Perl) this
could be done in one probe.

This probe locates the tty name for the process.

dipper: 4 = lsof -p 25947 -ad0
COMMAND     PID     USER   FD   TYPE     DEVICE   SIZE/OFF      INODE NAME
ksh       25947      abe    0u   CHR    58,   0      0t951        596 /dev/ttyp0

This probe locates the rlogind process that has the pseudo tty
analog of /dev/ttyp0 open.

dipper: 5 = lsof /dev/ptyp0
COMMAND     PID     USER   FD   TYPE     DEVICE   SIZE/OFF      INODE NAME
rlogind   25946     root    3u   CHR    59,   0     0t1329        564 /dev/ptyp0

This probe shows the standard input file (an Internet file) open
by the rlogind process, thus identifying the host name of origin.

dipper: 6 = lsof -p25946 -ai -ad0
COMMAND     PID     USER   FD   TYPE     DEVICE   SIZE/OFF      INODE NAME
rlogind   25946     root    0u  inet 0xf1394384          0        TCP dipper.cc.purdue.edu:login->vic.cc.purdue.edu:1023

A Perl or AWK script could be used to access all open files at once
with lsof, saving their relevant information, and then selecting
for display the same information given in the above three probes.

Other UNIX dialects may require slightly different strategies,
depending on how pseudo and real tty files are associated, but the
basic techniques as described in lsof's 00QUICKSTART and its reversal
as described here are essentially the same.

Vic Abell <abe@purdue.edu>
Technical Details
Message-ID: <55ja35$n6s@mozo.cc.purdue.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <846254378.24798.0@arete.demon.co.uk> <5558g8$rmu@mozo.cc.purdue.edu> <327dbb33.78367404@news.hamburg.pop.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc89c,5f5b38c13e89ce7a
X-Google-Attributes: gidfc89c,public
X-Google-Thread: fa664,5f5b38c13e89ce7a
X-Google-Attributes: gidfa664,public
X-Google-Thread: 108f6a,5f5b38c13e89ce7a
X-Google-Attributes: gid108f6a,public
From: abe@cc.purdue.edu (Vic Abell)
Subject: Re: finding the current socket of your telnet session
Date: 1996/11/03
Message-ID: <55ja35$n6s@mozo.cc.purdue.edu>
X-Deja-AN: 194172037
references: <846254378.24798.0@arete.demon.co.uk> <5558g8$rmu@mozo.cc.purdue.edu> <327dbb33.78367404@news.hamburg.pop.de>
to: dbin@sce.de (David Binette)
organization: Purdue University
newsgroups: comp.unix.programmer,comp.unix.sco.programmer,demon.ip.support.unix