Monday, 27 May 2013

PowerShell, SSH, Keyboard Interactive and Frustration

PowerShell, SSH, Keyboard Interactive and Frustration

Hello Stack Overflowers!
My goal is to utilize Powershell and SSH to connect to a Unix system (specifically an Avaya PBX switch). Once logged in, to change the terminal type to ossi (avaya specific) and issue a series of commands back and forth to collect data into a PowerShell object that I can work with. I currently have working profiles in Putty and Plink to do this at the command line with human interaction.
I have been beating my head against a wall for over a week trying to implement this script.
I have found (and tried) tons of different code pieces from around the web and some almost get it but none truly function right for my situation. I have been able to pin down that one of my problems is that to connect to the specific Unix system I am trying to get to, I have to use an authentication method known as "keyboard interactive". And while many open source ssh libraries/code snippets seem to support other forms of authentication, they skip this one.
Many folks recommend NetCmdlets (Link1), which I tried but this seems to not be set up to allow for back and forth conversations in SSH, nor does it appear to support Keyboard Interactive authentication.
The closest I have gotten things to working was utilizing a set of powershell SSH functions created by Joel Bennett and TaoK against a "custom" SharpSSH dll. PS for those reading this and trying to do something similiar, all Tamir.SharpSsh.dll / Sharpssh.dll's are NOT created equal. The majority of them gave me the message
Add-Type : Could not load file or assembly 'file:///C:\Users\User\Documents \WindowsPowerShell\Modules\SharpSSH\Tamir.SharpSSH.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
I put this need for a specific version of the DLL down to being on a newer version of Windows with a newer version of .Net installed. Also remember you need to "unblock" the file by utilizing File Explorer, Right click to properties and choose unblock.
The working functions I found were here (Link2) utilizing a SharpSSH dll from here (Link3)
These allow me to connect to the Unix system with the Keyboard Interactive authentication, however I have been unable to successfully capture the output as it seems I am stuck in some kind of unix banner to the user.
For those working with "normal" SSH systems, the code at those two links will work great. I have used it against a standard RedHat installation and been happy with the results.
So now I have set aside the SharpSSH functions and am trying to get the newer SSH.NET dll component ( aka Renci.SshNet.dll ) working with Powershell.
The SSH.Net dll can be found here (Link4) and a good set of PowerShell functions built around it can be found here http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library
When trying to work with it and the Keyboard Interactive authentication, it continually returns the message:
Value cannot be null.\r\nParameter name: data
In this discussion (http://sshnet.codeplex.com/discussions/348102), swinster and Joel Bennett work on solving the problem, but eventually become stumped by the recurring error "Value cannot be null.\r\nParameter name: data".
This same error has previously hit StackOverflow utilizing the solu

No comments:

Post a Comment