PowerShell / Win32-OpenSSH

Win32 port of OpenSSH
7.2k stars 739 forks source link

Paramiko ssh connection giving lots of residue output #2242

Open basu45 opened 1 week ago

basu45 commented 1 week ago

Prerequisites

Steps to reproduce

import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host=host, username=username, password=password)

channel = client.invoke_shell()
While channel.send_ready():
    channel.send('who am i\n')
While channel.rec_ready():
    Output=channel.recv(1024).decode()
Print(Output)

The issue is when we are using paramiko to connect to windows 2019 vm with invoke_shell() we are getting a lot of residue/garbage output. The output is similar to (https://stackoverflow.com/questions/61381631/read-buffer-data-continuously-running-on-remote-windows-command-prompt?noredirect=1&IQ=1)

And also the output is repeated multiple times.

Checked with bitvise ssh server it works fine with bitvise server

Tried with different version of openssh but same issue.

Any suggestions to get the clean output and non repeated/duplicate output

Expected behavior

Clean output

Actual behavior

"b'\x1b[2J\x1b[2J\x1b[1;1H\x1b[0;39;24;27;37;40mMicrosoft Windows [Version 10.0.1482] \n\x1b[2;1H(c) 2016 Microsoft Corporation. All rights reserved. \n\n\x1b[4;1Hadministrator@win C:\Users\Administrator>whoami \x1b[2J\x1b[4;54Hwhoami \x1b[4;55Hhoami \x1b[4;56Hoami \x1b[4;57Hami \x1b[4;58Hmi \x1b[4;59Hi \x1b[4;60H \x1b[5;1H' "

Error details

No response

Environment data

PSversion.                                     5.1.17763.5933
PsEdition.                                       Desktop
PSCompatibleVersions.                {1.0,2.0,30.,4.0.....}
BuildVersion.                                  10.0.17763.5993
CLRVersion.                                     4.0.30319.42000
WSManStackVersion.                      3.0
PSRemotingProtocolVersion.          2.3
Serialisation version.                          1.1.0.1

Version

OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2

Visuals

No response

basu45 commented 1 week ago

Can anyone please help here

basu45 commented 1 week ago

Hi @tgauth can you please look at this And help me?

maertendMSFT commented 1 week ago

Have you tried what is suggested on this StackOverflow: https://stackoverflow.com/questions/58063024/can-i-call-channel-invoke-shell-without-calling-channel-get-pty-beforehand

Can you try adding a -T parameter?

basu45 commented 1 week ago

Hi @maertendMSFT , 1.We are using the paramiko libraries invoke_shell() function which internally calls the get_pty() function however if we comment that in library itself on client.py of paramiko then it does not give any output

  1. Any way we need the interactive shell as most of our framework is built on it
basu45 commented 1 week ago

By any chance does the. https://github.com/PowerShell/Win32-OpenSSH/issues/1057 causing issues