0

I need to comunicate an old crm system with a new asset.
Crm system can only send fixed commans over telnet connection but this new asset can only receibe commands via api rest.
Im planning to intercept telnet connection , parse commands , modify them and send to the api and viceversa.
Is there any tool for that ?
If not .. I think faster way should by using some perl tcp library. It need to provide a "fake" login an then send received lines to a subroutine for processing.

Any though would be wellcome. Leandro.

  • If no such interface exists to buy, build one. Many programming languages will have telnet libraries. Other Stack Overflow sites can advise on development. Come back to Server Fault when you have something to deploy. – John Mahowald Apr 10 '20 at 02:18
  • Not sure if it would be enough, but I posit a combination of simple bash scripting relying on netcat, expect and curl might be enough? (netcat to talk with Telnet, expect to control its input and output and curl to make the API calls?) – davidgo Apr 10 '20 at 08:59
  • yes , I need basically to create a recibed line into a http post request. – user2977753 Apr 10 '20 at 19:50

1 Answers1

0

This is what I came up (it is not working)

#!/usr/bin/perl -w
 use IO::Socket;
 use Net::hostent;              # for OO version of gethostbyaddr

 $PORT = 9000;                  # pick something not in use
$prompt="MA5680T>";

 $server = IO::Socket::INET->new( Proto     => 'tcp',
                                  LocalPort => $PORT,
                                  Listen    => SOMAXCONN,
                                  Reuse     => 1);

 die "can't setup server" unless $server;
 print "[Server $0 accepting clients]\n";

 while ($client = $server->accept()) {
   $client->autoflush(1);
   #print $client "Welcome to $0; type help for command list.\n";
   #$hostinfo = gethostbyaddr($client->peeraddr);
   #printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost;
   print $client "\n";
   print $client "Warning: Telnet is not a secure protocol, and it is recommended to use Stelnet.";
   print $client "\n";
   print $client "\n";
   print $client ">>User name:";
   while ( <$client>) {
     next unless /\S/;       # blank line
    print "\nlinea :$_";

     if    (/quit|exit/i)    { last;                                     }
     elsif (/leo/i)    { printf $client "\n>>User password:";  }
     elsif (/password/i)    { printf $client "\n$prompt"; }
     else {
       print $client "\n$prompt";
     }
   } continue {
    #print $client $prompt;
   }
   close $client;
 }

Something is missing since I dont see any login attempt when forcing my client telneting to this "fake" server.
Im considering use telnetd server from some linux to manage login and session stablishment and then redirect recibed commands to my custom script ...
Dont know how but I will try , any idea would be welcome.