Solved

Automated telnet -and yes!! I am crazy.

Posted on 2001-07-31
6
196 Views
Last Modified: 2010-03-18
I have several machines on an internal network that is DMZ and some level of promisquiety is allowed.

Is it possible to write a script that can automatically feed a Telnet prompt Username and Password ?
Username is easy but password is a bit troublesome.

Please present a script which will when executed log you in if you have password and username as variables in the script.
0
Comment
Question by:dryzone
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:superschlonz
ID: 6339061
Im using expect (http://expect.nist.gov/) for things like that.
It's a TCL/Tk interpreter with some added functionality for running an controlling processes.
0
 
LVL 40

Expert Comment

by:jlevie
ID: 6339255
Why bother with that. Given the description of what you have and want to do it would make just as much sense to configure the systems for rlogin or ssh access using rhosts. In that case no password would be required for those users/machines permitted access that way.

Personally I'd generate a keypair with ssh-keygen (with no passphrase) and place the public key in .ssh/authorized_keys2 on the remote system. That allows me to simply say "ssh remote-host" and be instantly logged in without having to supply a password. It's far more secure than using rhosts files or hosts.equiv and has the bonus of using an encrypted session.
0
 
LVL 1

Author Comment

by:dryzone
ID: 6340307
jleve.
Yes I am running SSH on my firewall for whenever I am outside.
However, the ssh behaviour as you describe could never be implimented. Passwords were always required. You are right about using ssh, but it is slow compared to telnet  and I am in a DMZ.
sure rlogin.......still needs a password.

Both superschlonz and jleve.
Give me a script which I enter username and password and when I run it I am logged in and you have the points.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Accepted Solution

by:
jlevie earned 100 total points
ID: 6342754
If you really want to do this with telnet the following will work. You'll need to edit the file and change "my-name" and "my-passwd" to the user name and password on the remote system. Also you'll want to make the file owned by yourself and set it to mode 700.

#!/usr/bin/expect --
# Simple script to open a telnet session on a remote host. The script will
# exit when you log out of the remote. It expects the host name on the
# command line, e.g., "this-script remote-server".
#
set host [lindex $argv 0]
set timeout 60
spawn telnet $host
expect "ogin:"
send "my-name\r"
expect "assword:"
send "my-passwd\r"
interact

If you were getting a password prompt using ssh then something didn't get set up properly. First of all you need to be using a recent copy of OpenSSH that supports SSH 2. Then on the local system execute:

illusion> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jlevie/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jlevie/.ssh/id_rsa.
Your public key has been saved in /home/jlevie/.ssh/id_rsa.pub.
The key fingerprint is:
9a:fa:78:ac:....
illusion>

At the passphrase prompts just hit return. Add the contents of .ssh/is_rsa.pub to ~/.ssh/authorized_keys2 on the remote system. That's easily done after copying the file to the remote with:

remote> cat ip_rsa.pub >>.ssh/authorized_keys2

Then from the local system just execute "ssh remote". You won't get a  passwd request and will be logged in. Another nice thing about this is that it also works for scp and when using ssh to execute commands on the remote... Much more powerful than using an expect script to establish a telnet session.
0
 
LVL 1

Author Comment

by:dryzone
ID: 6342844
Looked good but did not work.
Expect is in /usr/bin so that works.
HGowever the script failed.


[Lht@gateway Lht]$ ./loginhelper
spawn telnet
usage: telnet [-l user] [-a] host-name [port]
send: spawn id exp4 not open
    while executing
"send "Lht\r""
    (file "./loginhelper" line 10)
[Lht@gateway Lht]$
0
 
LVL 40

Expert Comment

by:jlevie
ID: 6343197
The script expects the host name of the remote system as an argument, so execute it as "loginhelper remote-name". My presumption was that you'd have the same name and password on each of the DMZ systems and you could then use one script and specify the system on the command line.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question