Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

creating a fake telnet middleware

by leostereo (Beadle)
on Apr 10, 2020 at 00:43 UTC ( #11115301=perlquestion: print w/replies, xml ) Need Help??

leostereo has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys , im not trying to hack anything.
Just need to intercept a telnet session, modify client commands, send to api rest and return result back.
Everything is hardcoded so I need to simulate a telnet session with a login request and returning a prompt and so on.
Client should "believe" it is connected to original server.(luckily it uses telnet).
What do you think about it ?
Im thinking on building a simple tcp daemon with socket library and send proper responses to client "simulating a terminal"
Do you think it is possible ?should I consider any thing extra ?
Any idea would be welcome.

Replies are listed 'Best First'.
Re: creating a fake telnet middleware
by stevieb (Canon) on Apr 10, 2020 at 01:26 UTC
    "Do you think it is possible ?"

    Yes, it's definitely possible. I, and many others have done it.

    "should I consider any thing extra?"

    Yes, the ethical and moral obligations you have to yourself and others.

    ...ain't nobody around here going to help you script-kiddy around anything, so once you show the code you've got, feel free to ask questions related to the specific issues you're having. That way, if anyone here provides code, we'll be confident that you have a legitimate reason for snooping on traffic that isn't yours.

      As said before. It is not a ilegitimate action. I will explain it better for those who think I want to damage something. Billing system from my isp company can not implement api integration with an new service router we recently bought. Billing system vendor is out of business, I can not request to deploy api integration and can not modified it. Both assests belongs to my , are inside my company , installed next each other on same datacenter. Intercepting its commands is just a workaround I came up to solve my integration problem. Regards. Leandro
Re: creating a fake telnet middleware
by jo37 (Monk) on Apr 10, 2020 at 08:50 UTC

    Telnet isn't just a terminal. It is a protocol spoken between client and server. Intercepting such a session requires to implement the server side. See RFC 854


      Dear jo , this is my first attempt.
      From the client side it seems to work, I can telnet , insert my user , then it request my password and it seems similar to original shell. But when trying from legitimate telnet client it does not.
      Im also thinking the idea of creating a real linux server with telnet login and then redirect telnet daemon to a custom script (like a pseudo shell). I need to find out all pieces and make them work togheter.
      This is my perl telnet server:
      #!/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; }
      Regards, Leandro

        Though this is a rudimentary server, it is not a telnet server. It depends on the client if it is willing to communicate with such a non-telnet endpoint.

        I think it would be easier to replace the login shell of the user with some interceptor. That way the application would talk to a real telnetd, which - after authenticating the client - will connect it to your login shell replacement, where you may perform anything you like.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11115301]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-06-01 16:44 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (5 votes). Check out past polls.