Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-12-2012, 07:37 AM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
Example Python Script Not Working

Hi All,

I wanted to try to script some logins to remote hosts. I took the example script below and updated it with my information. When I run it I always get "Password Authentication Failed" but I can copy/paste the same password and login to the device. I created a messagebox to see what was being sent and it looks ok. I have also tried removing the SSH options as well.

I am currently running Mac version 7.0.0 (build 307) so not sure if this is a bug in the Beta or not.


# $language = "python"
# $interface = "1.0"

# Connect to an SSH server using the SSH2 protocol. Specify the
# username and password and hostname on the command line as well as
# some SSH2 protocol specific options.

host = "firedrill"
user = "davinman"

def main():
# Prompt for a password instead of embedding it in a script...
#
passwd = crt.Dialog.Prompt("Enter password for " + host, "Login", "", True)

# Build a command-line string to pass to the Connect method.
cmd = "/SSH2 /L %s /PASSWORD %s /C 3DES /M MD5 %s" % (user, passwd, host)
crt.Dialog.MessageBox(cmd)

crt.Session.Connect(cmd)


main()
Reply With Quote
  #2  
Old 06-12-2012, 08:03 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi davinman,

Thanks for the question. I have successfully used your script in a couple of different test environments using SecureCRT 7.0b3 (build 307).

What version of Mac OS X are you using?

Are you copying and pasting the password into the prompt dialog when the script is running?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 06-12-2012, 08:12 AM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
I am using MacOS X 10.7.4. I have tried typing the password directly and copy/pasting in the dialog box.


Thanks,
David Inman
Reply With Quote
  #4  
Old 06-12-2012, 11:56 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

Thanks for the information. Are you able to use this script to connect to any device successfully or does it fail with any device?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 06-12-2012, 01:04 PM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
I am not able to get it to work no matter what I use. I have tried connecting to Cisco devices, Redhat servers, etc to no avail. I thought that it might even be my password since it has special characters in it as require by our security policy but I changed one of the development servers to a simple password with just letters and numbers and it still does not work.
Reply With Quote
  #6  
Old 06-12-2012, 01:38 PM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
To make sure that it was not an issue with the beta version I reinstalled 6.7.5 (build 411). I then took the exact script from the webpage and only updated the host and user variables. Still fails with "Password Authentication Failure"
Reply With Quote
  #7  
Old 06-12-2012, 02:42 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

Thanks for the information. What version of Python are you running on your system (python --version)?

If you hardcode the password in the script, does it fail in the same way?

Additionally, what happens if you modify your script in the following way?
PHP Code:
# $language = "python"
# $interface = "1.0"

# Connect to an SSH server using the SSH2 protocol. Specify the
# username and password and hostname on the command line as well as
# some SSH2 protocol specific options.
msgbox crt.Dialog.MessageBox
host 
"host"
user "user"

def main():
    
# Prompt for a password instead of embedding it in a script...
    #
    
passwd crt.Dialog.Prompt("Enter password for " host"Login"""True)

    
# Build a command-line string to pass to the Connect method.
    
cmd "/SSH2 /L %s %s" % (userhost)
    
crt.Session.Connect(cmdFalse)
    
crt.Screen.Synchronous True
    
# This line will need to be modified to wait for what the remote will send.
    
crt.Screen.WaitForString("Password:")
    
crt.Screen.Send(passwd "\r")


main() 
To use this modified script, you will need to enable Display logon prompts in terminal window for the Default Session. This option is located in the Connection / Logon Actions category. You can edit the Default Session in the General / Default Session category of the Global Options dialog.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 06-12-2012 at 03:08 PM.
Reply With Quote
  #8  
Old 06-12-2012, 05:45 PM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
I currently have Python 2.7.1 on my Mac.

I have tried to hardcode all the variables in the script and that does not work either.

When I look at the default session I do not see the option for "Display logon prompts in terminal window"
Reply With Quote
  #9  
Old 06-13-2012, 07:58 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

Thanks for the update. I should have noted that the Display logon prompts in terminal window option is not available until the beta. Would you run the test in SecureCRT 7.0b3?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #10  
Old 06-13-2012, 09:19 AM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
That test script works with the terminal prompts in the the window. What does that prove?
Reply With Quote
  #11  
Old 06-13-2012, 11:25 AM
davinman davinman is offline
Registered User
 
Join Date: May 2007
Posts: 9
Appears that it does not work if you switch to crt.Session.ConnectInTab or maybe I am missing something as it just sits there at the password prompt
Reply With Quote
  #12  
Old 06-13-2012, 11:35 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

The new data tells us that we need to dig a little deeper into the case where you are connecting with the username, password and hostname rather than sending the password when the Password: prompt is found.

I would like you to enable a very verbose version of trace options so you can see what packets SecureCRT is sending to the remote system with regards to the password. You will need to edit the Default Session .ini file. Here are the steps:
  1. Close all instances of SecureCRT. If changes are made to the Default.ini file while SecureCRT is running, the changes made will be undone when SecureCRT is restarted.
  2. Edit the Default.ini file (located in the Sessions subfolder of SecureCRT's configuration folder location indicated by the Configuration folder field in the General category of the Global Options dialog.
  3. Save the changes made to the Default.ini file and start SecureCRT.
The line to change is below:
From:
D:"Trace Level"=00000000
To:
D:"Trace Level"=0000000b
Once you have made this change, when you run the script, you should see lots of debugging data in the terminal window. You will need to make sure that the scrollback buffer has more than 500 lines. You may want to use 5000. In the data in the scrollback buffer, you should see where SecureCRT sends a password. Is SecureCRT sending what you are typing into the prompt?

Here is an example of what you should see in the terminal window output:
Code:
[LOCAL] : [SEND] : 
00000000 | b2 01 00 00 00 32 00 00 00 03 00 00 00 00 00 00  .....2..........
00000016 | 0e 73 73 68 2d 63 6f 6e 6e 65 63 74 69 6f 6e 00  .ssh-connection.
00000032 | 00 00 08 70 61 73 73 77 6f 72 64 00 00 00 00 0c  ...password.....
00000048 | 54 23 73 74 50 34 24 24 77 30 72 64              T#stP4$$w0rd
I have redacted the username. You should see the username in the first and possibly second lines. Notice that SecureCRT is sending T#stP4$$w0rd. This is what I typed into the prompt when I ran the script.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #13  
Old 06-13-2012, 03:00 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
To anyone reading this thread,

We are investigating this issue outside of the forums. I will post to this thread when we have a resolution or an explanation for this behavior.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #14  
Old 06-19-2012, 01:39 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi all,

After investigating this issue, we found that it is a result of Use KeyChain being enabled. This option is located in the Terminal / Advanced category of the Global Options dialog and is enabled by default.

Disabling Use KeyChain should resolve the issue.

We will post to this thread if a future release of SecureCRT has the ability to successfully run scripts that use the Connect method with Use KeyChain enabled.

If anyone would like to be notified directly if this capability is added, please complete and submit the form at the following location:
Submit Feature Request
Additionally, even though Mac OS X Lion has Python 2.7.1 installed, SecureCRT is linking against a 2.5.6 Python installation when running Python scripts.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:40 AM.