作者:caozhengweile_854 | 来源:互联网 | 2023-09-24 14:47
第一部分:inetd.conf文件中telnet条目加一个-D选项telnetstreamtcpnowaitrootusrsbintcpdusrsbintelnetd
第一部分:inetd.conf文件中telnet条目加一个-D选项
telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/telnetd -D
-Dptydata 也是可以的,并且只显示ptydata相关的调试结果!
第二部分:telnetd.h中有DEBUG的定义
telnetd/telnetd.h:84:#define DEBUG(mode,level,c) if (debug_level[mode]>=level) c
第三部分:telnetd.c中debug_mode[]结构数组,第一个成员是名字,第二个选项是是否调试,有可能是0,有可能是1,-Dptydata,有可能是100,-D。
static struct
{
char *name;
int modnum;
} debug_mode[debug_max_mode] =
{
{"options", debug_options},
{"report", debug_report},
{"netdata", debug_net_data},
{"ptydata", debug_pty_data},
{"auth", debug_auth},
{"encr", debug_encr},
};
void
parse_debug_level (char *str)
{
int i;
char *tok;
if (!str)
{
for (i = 0; i debug_level[debug_mode[i].modnum] = MAX_DEBUG_LEVEL;
return;
}
syslog (LOG_NOTICE, "telnetd.c parse_debug_level str= %s", str);
for (tok = strtok (str, ","); tok; tok = strtok (NULL, ","))
{
int length, level;
char *p;
if (strcmp (tok, "tcp") == 0)
{
debug_tcp = 1;
continue;
}
p = strchr (tok, '=');
if (p)
{
length = p - tok;
level = strtoul (p + 1, NULL, 0);
}
else
{
length = strlen (tok);
level = MAX_DEBUG_LEVEL;
}
for (i = 0; i if (strncmp (debug_mode[i].name, tok, length) == 0)
{
debug_level[debug_mode[i].modnum] = level;
break;
}
syslog (LOG_NOTICE, "telnetd.c parse_debug_level i = %d", i );
if (i == debug_max_mode)
syslog (LOG_NOTICE, "unknown debug mode: %s", tok);
}
}
第四部分内容:调试的结果在哪里看?/tmp/telnet.debug文件里面就是调试结果。
utility.c
/* ************************************************************************* */
/* Debugging support */
static FILE *debug_fp = NULL;
static int
debug_open (void)
{
int um = umask (077);
if (!debug_fp)
debug_fp = fopen ("/tmp/telnet.debug", "a");
umask (um);
return debug_fp == NULL;
}
第五部分内容:一个典型的telent登录过程:root登录,密码ch123456,然后是pwd命令,然后是exit离开。
root@ch-Founder-PC:~# telnet 172.22.24.150
Trying 172.22.24.150...
Connected to 172.22.24.150.
Escape character is '^]'.
Linux 4.10.0-42-generic (ch-Founder-PC) (pts/20)
密码:
root@ch-Founder-PC:~# pwd
/root
root@ch-Founder-PC:~# exit
注销
Connection closed by foreign host.
root@ch-Founder-PC:~#
第六部分内容:调试的结果,可以看出交互的过程,还有调用/bin/login的过程,然后是输入命令,返回结果。
下一篇文章详解。
td: send do TERMINAL TYPE
td: send do TSPEED
td: send do XDISPLOC
td: send do NEW-ENVIRON
td: send do OLD-ENVIRON
td: ttloop
td: netflush 15 chars
td: ttloop read 27 chars
td: recv do SUPPRESS GO AHEAD
td: send will SUPPRESS GO AHEAD
td: recv will TERMINAL TYPE
td: recv will NAWS
td: send do NAWS
td: recv will TSPEED
td: recv will LFLOW
td: send do LFLOW
td: recv will LINEMODE
td: send do LINEMODE
td: netflush 19 chars
td: recv will NEW-ENVIRON
td: recv do STATUS
td: send will STATUS
td: recv will XDISPLOC
td: ttloop
td: netflush 3 chars
td: ttloop read 3 chars
td: recv wont OLD-ENVIRON
td: ttloop
td: netflush 24 chars
td: ttloop read 73 chars
td: recv suboption NAWS 0 80 (80) 0 24 (24)
td: recv suboption LINEMODE SLC SYNCH NOSUPPORT 0; IP VARIABLE|FLUSHIN|FLUSHOUT 3; AO VARIABLE 15; AYT NOSUPPORT 0; ABORT VARIABLE|FLUSHIN|FLUSHOUT 28; EOF VARIABLE 4; SUSP VARIABLE|FLUSHIN 26; EC VARIABLE 127; EL VARIABLE 21; EW VARIABLE 23; RP VARIABLE 18; LNEXT VARIABLE 22; XON VARIABLE 17; XOFF VARIABLE 19; FORW1 NOSUPPORT 0; FORW2 NOSUPPORT 0;
td: recv do SUPPRESS GO AHEAD
td: recv suboption LINEMODE MODE LIT_ECHO|ACK (0x14)
td: netflush 0 chars
td: ttloop
td: ttloop read 88 chars
td: recv suboption TERMINAL-SPEED IS 38400,38400
td: recv suboption X-DISPLAY-LOCATION IS "ch-Founder-PC:0"
td: recv suboption NEW-ENVIRON IS VAR "DISPLAY" VALUE "ch-Founder-PC:0"
td: recv suboption TERMINAL-TYPE IS "XTERM-256COLOR"
td: send do ECHO
td: ttloop
td: netflush 3 chars
td: ttloop read 3 chars
td: recv wont ECHO
td: send will ECHO
sending
Linux 4.10.0-42-generic (ch-Founder-PC) (pts/20)
td: send do BINARY
td: send dont LINEMODE
td: netflush 15 chars
td: netflush 42 chars
td: send suboption LINEMODE SLC IP VARIABLE|ACK|FLUSHIN|FLUSHOUT 3; AO VARIABLE|ACK 15; ABORT VARIABLE|ACK|FLUSHIN|FLUSHOUT 28; EOF VARIABLE|ACK 4; SUSP VARIABLE|ACK|FLUSHIN 26; EC VARIABLE|ACK 127; EL VARIABLE|ACK 21; EW VARIABLE|ACK 23; RP VARIABLE|ACK 18; LNEXT VARIABLE|ACK 22; XON VARIABLE|ACK 17; XOFF VARIABLE|ACK 19;
td: netflush 0 chars
td: Entering processing loop 这里开始接受输入,开始输出。
td: netread 9 chars
nd: fffd 01ff fb00 fffc 22 ........"
td: netflush 54 chars
td: recv do ECHO
td: recv will BINARY
td: recv wont LINEMODE
td: ptyread 1 chars
pd: 01 .
td: ptyread 11 chars
pd: 00e5 af86 e7a0 81ef bc9a 20 ..........
td: netflush 10 chars
td: netread 1 chars
nd: 63 c
td: ptyflush 1 chars
pd: 63 c
td: netread 1 chars
nd: 68 h
td: ptyflush 1 chars
pd: 68 h
td: netread 1 chars
nd: 31 1
td: ptyflush 1 chars
pd: 31 1
td: netread 1 chars
nd: 32 2
td: ptyflush 1 chars
pd: 32 2
td: netread 1 chars
nd: 33 3
td: ptyflush 1 chars
pd: 33 3
td: netread 1 chars
nd: 34 4
td: ptyflush 1 chars
pd: 34 4
td: netread 1 chars
nd: 35 5
td: ptyflush 1 chars
pd: 35 5
td: netread 1 chars
nd: 36 6
td: ptyflush 1 chars
pd: 36 6
td: netread 1 chars
nd: 0d .
td: ptyflush 1 chars
pd: 0d .
td: ptyread 1 chars
pd: 01 .
td: ptyread 3 chars
pd: 000d 0a ...
td: netflush 2 chars
td: ptyread 104 chars
pd: 001b 5d30 3b72 6f6f 7440 6368 2d46 6f75 6e64 6572 ..]0;root@ch-Founder
pd: 2d50 433a 7e07 1b5d 373b 6669 6c65 3a2f 2f63 682d -PC:~..]7;file://ch-
pd: 466f 756e 6465 722d 5043 2f72 6f6f 7407 1b5d 303b Founder-PC/root..]0;
pd: 726f 6f74 4063 682d 466f 756e 6465 722d 5043 3a20 root@ch-Founder-PC:
pd: 7e07 726f 6f74 4063 682d 466f 756e 6465 722d 5043 ~.root@ch-Founder-PC
pd: 3a7e 2320 :~#
td: netflush 103 chars
td: netread 1 chars
nd: 70 p
td: ptyflush 1 chars
pd: 70 p
td: ptyread 2 chars
pd: 0070 .p
td: netflush 1 chars
td: netread 1 chars
nd: 77 w
td: ptyflush 1 chars
pd: 77 w
td: ptyread 2 chars
pd: 0077 .w
td: netflush 1 chars
td: netread 1 chars
nd: 64 d
td: ptyflush 1 chars
pd: 64 d
td: ptyread 2 chars
pd: 0064 .d
td: netflush 1 chars
td: netread 1 chars
nd: 0d .
td: ptyflush 1 chars
pd: 0d .
td: ptyread 10 chars
pd: 000d 0a2f 726f 6f74 0d0a .../root..
td: netflush 9 chars
td: ptyread 56 chars
pd: 001b 5d30 3b72 6f6f 7440 6368 2d46 6f75 6e64 6572 ..]0;root@ch-Founder
pd: 2d50 433a 7e07 1b5d 373b 6669 6c65 3a2f 2f63 682d -PC:~..]7;file://ch-
pd: 466f 756e 6465 722d 5043 2f72 6f6f 7407 Founder-PC/root.
td: netflush 55 chars
td: ptyread 49 chars
pd: 001b 5d30 3b72 6f6f 7440 6368 2d46 6f75 6e64 6572 ..]0;root@ch-Founder
pd: 2d50 433a 207e 0772 6f6f 7440 6368 2d46 6f75 6e64 -PC: ~.root@ch-Found
pd: 6572 2d50 433a 7e23 20 er-PC:~#
td: netflush 48 chars
td: netread 1 chars
nd: 65 e
td: ptyflush 1 chars
pd: 65 e
td: ptyread 2 chars
pd: 0065 .e
td: netflush 1 chars
td: netread 1 chars
nd: 78 x
td: ptyflush 1 chars
pd: 78 x
td: ptyread 2 chars
pd: 0078 .x
td: netflush 1 chars
td: netread 1 chars
nd: 69 i
td: ptyflush 1 chars
pd: 69 i
td: ptyread 2 chars
pd: 0069 .i
td: netflush 1 chars
td: netread 1 chars
nd: 74 t
td: ptyflush 1 chars
pd: 74 t
td: ptyread 2 chars
pd: 0074 .t
td: netflush 1 chars
td: netread 1 chars
nd: 0d .
td: ptyflush 1 chars
pd: 0d .
td: ptyread 3 chars
pd: 000d 0a ...
td: netflush 2 chars
td: ptyread 9 chars
pd: 00e6 b3a8 e994 800d 0a .........
td: netflush 8 chars
td: ptyread 0 chars