How to hide telnet connection logs from getting printed in screen

Viewed 53

I have a script which telnet to remote system & user can interact with remote system. But i want to hide telnet connection logs from getting printed for security reasons. I tried all the redirection techniques like (> , 1>, 2>), but my purpose is not served. "1>" is not allowing to interact with remote system.

How to redirect/hide only telnet connection logs (or first 3 connection lines) below & make telnet session interactive ?


script :

#!/bin/bash  
telnet 1.2.3.4 7777

sample issue execution :

~/redirect.sh  
Trying 1.2.3.4...    //   redirect  
Connected to 1.2.3.4.      
Escape character is '^]'.  
login:

sample expected execution :

~/redirect.sh    
login:
1 Answers

There is no easy fix for this, as those three lines are simply printf() in the code. It would be a great deal of effort to remove those lines and allow interactive connections.

However, it is a simple client side change to modify the telnet client source and recompiling:

  • Download inetutils-2.3 from here.
  • Extract with tar -xJvf inetutils-2.3.tar.xz.
  • cd inetutils-2.3.
  • ./configure
  • Use the patch in this answer: patch telnet/commands.c < /path/to/telnet.patch
    patching file telnet/commands.c
  • make

Then test:

2>/dev/null ./telnet/telnet 192.168.100.1 22
SSH-2.0-OpenSSH_8.6

Copy this version of telnet into your PATH somewhere. Possibly rename it stelnet.

Related