Keyboard Interactive Fails on Connect

Oct 15, 2012 at 10:50 PM
Edited Oct 15, 2012 at 10:52 PM

Hi I'm trying to implement the keyboard interactive in PowerShell

I have the following function I call to test the code and the results bellow

So I know the event is triggering and I'm passing the proper information to it because I see it shown back to me. Any ide why I'm getting the null exception?




function new-keyintauth
    $KeyboardInteractive = New-Object Renci.SshNet.KeyboardInteractiveAuthenticationMethod($user)
    $ConnectionInfo = New-Object Renci.SshNet.ConnectionInfo($target,22,$user,$KeyboardInteractive)
    Register-ObjectEvent -InputObject $KeyboardInteractive -MessageData $pass -EventName AuthenticationPrompt -Action {
        Write-Host "`nEvent Triggered!"
        Write-Host $Sender
        Write-Host $EventArgs.prompts
        foreach($prompt in  $EventArgs.prompts){
            if ($prompt.request -like '*ssword*')
                write-host "Prompt: $($prompt.request)"
                write-host "PrompID: $($"
                write-host "Is Echoed: $($prompt.IsEchoed)"
                $prompt.Response = 'password'
                Write-Host "Response is $($prompt.Response)"
    $SSH = New-Object Renci.SshNet.SshClient($ConnectionInfo)
    get-EventSubscriber | Unregister-Event

PS C:\Windows\System32\WindowsPowerShell\v1.0> C:\Users\Carlos\Desktop\Keyint.ps1

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
--     ----            -------------   -----         -----------     --------             -------                  
32     909b1bdf-8d3...                 NotStarted    False                                ...                      

Event Triggered!
Prompt: Password:
PrompID: 0
Is Echoed: False
Response is password
Exception calling "Connect" with "0" argument(s): "Value cannot be null.
Parameter name: data"
At C:\Users\Carlos\Desktop\Keyint.ps1:28 char:5
+     $SSH.Connect()
+     ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException
Oct 15, 2012 at 11:00 PM

Some additional info


PS C:\Windows\System32\WindowsPowerShell\v1.0> $Error[0].CategoryInfo

Category : NotSpecified

Activity :

Reason : MethodInvocationException

TargetName :

TargetType :


PS C:\Windows\System32\WindowsPowerShell\v1.0> $Error[0].FullyQualifiedErrorId


Oct 16, 2012 at 3:53 PM

figured out that is a race condition and do to the way PowerShell handles events it will not be possible to keyboard interactive, will have to lean C# and build what I want in a C# module.