Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telnet to login with username and password to mail Server

I am having some issues trying to connect through telnet to a mail server.The main problem that I am having is that I need to create a script that logs me to the destination and I can't find a way to echo the password.

What I tried:

telnet host -l username ; echo 'password'

And still it asks for my password.Is there any way to fix this or I am doing something wrong?

like image 667
tudoricc Avatar asked Jan 14 '15 10:01

tudoricc


1 Answers

First of all, you can use eval:

eval "{ echo user_name; sleep 1; echo pass; sleep 1; echo '?'; sleep 5; }" | telnet host_address

Make sure to replace user_name, pass, ? which is the command you want to run and host_address where your telnet host is listening; for me it is a local IP.

It’s surprisingly easy to script a set of command and pipe them into the telnet application. All you need to do is something like this:

(echo commandname;echo anothercommand) | telnet host_address

The only problem is the nagging login that you have to get through… it doesn’t show up right away. So if you pipe in an “echo admin” and then “echo password,” it will happen too quickly and won’t be sent to the server. The solution? Use the sleep command!

Adding in a couple of sleep 3 commands, to wait three seconds, solves the problem. First we’ll echo the username and password, and then we’ll echo the reboot command, and each time we’ll wait three seconds between. The final command will reboot the server immediately:

(sleep 3;echo admin;sleep 3;echo mypassword;sleep 3;echo system reboot;sleep 3;) | telnet host_address

You can put this into a shell script and run it whenever you want. Or you can add it to your cron like this (on OS X or Linux):

crontab -e

Add this line somewhere:

1 7 * * * (sleep 3;echo admin;sleep 3;echo mypassword;sleep 3;echo system reboot;sleep 3;) | telnet host_address

This will reboot your router at 7:01 AM each morning.

like image 82
Ahmad Awais Avatar answered Oct 23 '22 10:10

Ahmad Awais