Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell Core: Unable to Prompt For SecureString Over PSSession #7239

Closed
pldmgg opened this issue Jul 6, 2018 · 7 comments
Closed

PowerShell Core: Unable to Prompt For SecureString Over PSSession #7239

pldmgg opened this issue Jul 6, 2018 · 7 comments
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-Duplicate The issue is a duplicate. WG-Remoting PSRP issues with any transport layer

Comments

@pldmgg
Copy link

pldmgg commented Jul 6, 2018

Steps to reproduce

On a Windows Client running PowerShell Core v6.1.0-preview.3, create a PSSession (via SSH) to a CentOS7 host running v6.1.0-preview.2 and do the following

PS C:\Users\zeroadmin> $CentOS7PSSession = New-PSSession -HostName 192.168.2.49 -KeyFilePath "$HOME\.ssh\vagrant_unsecure_key" -UserName vagrant
PS C:\Users\zeroadmin> Enter-PSSession -Session $CentOS7PSSession
[192.168.2.49]: PS /home/vagrant> $test = Read-Host "Pwd"
Pwd: PlainTextPwd
[192.168.2.49]: PS /home/vagrant> $test2 = Read-Host "Pwd" -AsSecureString
WARNING: A script or application on the remote computer 192.168.2.49 is sending a prompt request. When you are prompted, enter sensitive information, such as credentials or passwords, only if you trust the remote computer and the application or script that is requesting the data.
Pwd: ***********

# Hangs indefinitely here until ctrl+c

There is an error processing data from the background process. Error reported: Object reference not set to an instance of an object..
PS C:\Users\zeroadmin> Enter-PSSession -Session $CentOS7PSSession
Enter-PSSession : Cannot enter session Runspace5 because it is not in the disconnected state or is not available for connection. Retrieve the remote session using Get-PSSession -ComputerName 192.168.2.49 -InstanceId d8e069fb-f075-432c-a394-51e50a9f86b9.
At line:1 char:1
+ Enter-PSSession -Session $CentOS7PSSession
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Enter-PSSession], ArgumentException
+ FullyQualifiedErrorId : PushedRunspaceMustBeOpen,Microsoft.PowerShell.Commands.EnterPSSessionCommand

PS C:\Users\zeroadmin>

Expected behavior

Successfully create the securestring in a remote session

Actual behavior

Hangs indefinitely and breaks the PSSession.

Environment data

Windows Client Info:

PS C:\Users\zeroadmin> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.3
PSEdition                      Core
GitCommitId                    v6.1.0-preview.3
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\Users\zeroadmin> Get-Command ssh

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     ssh.exe                                            7.7.1.0    C:\Program Files\OpenSSH-Win64\ssh.exe

CentOS7 Remote Host Info:

[192.168.2.49]: PS /home/vagrant> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Linux 3.10.0-862.6.3.el7.x86_64 #1 SMP Tue Jun 26 16:32:21 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

[192.168.2.49]: PS /home/vagrant> sudo pwsh -Command 'Get-Content /etc/ssh/sshd_config'
#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile      .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication no

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server
Subsystem powershell /bin/pwsh -sshs -NoLogo -NoProfile

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
[192.168.2.49]: PS /home/vagrant>
@MaximoTrinidad
Copy link

Hi @pldmgg,

I notice your sshd_config has the Port 22 line still disable. You need to make sure both Windows and Linux has that port available for openssh to work.

Also, make sure you don't include the path in CentOS as it will find it automatically:

Subsystem	powershell pwsh -sshs -NoLogo -NoProfile

:)

@MaximoTrinidad
Copy link

@pldmgg, Apologies!! I see now.

So you're getting connected but creating the secure string hung the session. I'm trying it now with Preview.3.

@MaximoTrinidad
Copy link

MaximoTrinidad commented Jul 6, 2018

Yeap! I can reproduce the issue by simply doing:

Enter-PSSession -HostName mercury -UserName maxt
maxt@mercury's password:
[mercury]: PS /home/maxt>
[mercury]: PS /home/maxt> $test2 = Read-Host "Pwd" -AsSecureString
WARNING: A script or application on the remote computer MERCURY is sending a prompt request. When you are prompted, enter sensitive information, such as credentials or passwords, only if you trust the remote computer and the application or script that is requesting the data.
Pwd: *****

Hung Here

pscore_securestringhung_2018-07-06_17-42-31

There's the possibility that's happening in all distro of Linux (not only CentOS).

@MaximoTrinidad
Copy link

Yeap! Linux CentOS to Ubuntu the same thing.

centos2ubuntu_2018-07-06_18-09-44

@pldmgg
Copy link
Author

pldmgg commented Jul 7, 2018

@MaximoTrinidad Thanks for taking the time to reproduce. I have a feeling there might be something about this somewhere in https://github.com/PowerShell/Win32-OpenSSH/issues ... I'll try and take a look tomorrow

EDIT:
Didn't find anything related in https://github.com/PowerShell/Win32-OpenSSH/issues not sure what could be causing this...

@MaximoTrinidad
Copy link

On the contrary! Thanks @pldmgg for catching it now. For sure, someone will take a look at this next week.
:)

@iSazonov iSazonov added Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif WG-Remoting PSRP issues with any transport layer labels Jul 12, 2018
@pldmgg
Copy link
Author

pldmgg commented Sep 27, 2018

Dup of #1654. Closing...

@pldmgg pldmgg closed this as completed Sep 27, 2018
@iSazonov iSazonov added the Resolution-Duplicate The issue is a duplicate. label Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-Duplicate The issue is a duplicate. WG-Remoting PSRP issues with any transport layer
Projects
None yet
Development

No branches or pull requests

3 participants