Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Feature: New-SSHSession - Allow to use -keyfile from string/stream, not just filesystem object

Open MVKozlov opened this issue 10 years ago • 8 comments

Subj. It is needed alternative to -keyfile

Now -keyFile can be used only as path to filename with secret key. Highly need support for selecting string/securestring/stream as key source. we can store secret key highly encrypted, but for use now we need to save it to disk unencrypted. it is security risk. I see that SSH.Net have support for PrivateKeyFile(Stream). I find it more secure....

MVKozlov avatar Jun 06 '16 12:06 MVKozlov

well a key is encrypted and protected with a passphrase, it has worked that way in many platforms so I do not agree on the argument of "More Secure" ;) but it is a feature I have planned for users that use CyberArk and Thycotic that get the key as a string from their password vaults.

darkoperator avatar Jul 09 '16 15:07 darkoperator

I'm using as workaround to this a simple tmp file where to store the key, using it and than remove the file. They key may be retrieved easily from virtually anywhere, in my case I store the key in a DB table. This way you may take care of the string/stream object and use it whenver you need to issue commands.

something similar to this:

#Create a temporary file to use $filetmp=[System.IO.Path]::GetTempFileName()

#Get content of key from DB

in this line we use a proper file to emulate the behavior

$key = Get-Content C:\PAG\Key\id_dsa | Out-File $filetmp

#Open a session to TPAM New-SSHSession -ComputerName $tpamurl -KeyFile $filetmp -Credential $username

#remove the file remove-item $filetmp -force

Eventually you may exclusively lock the file to be sure nobody can use it example: http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell

alefesta-zz avatar Sep 20 '16 12:09 alefesta-zz

I plan on adding the feature but it will take me a while since I’m traveling and teaching several offensive and defensive powershell and IR classes until decemeber and the mod is not a simple one.

On Sep 20, 2016, at 8:17 AM, alefesta [email protected] wrote:

I'm using as workaround to this a simple tmp file where to store the key, using it and than remove the file. They key may be retrieved easily from virtually anywhere, in my case I store the key in a DB table. This way you may take care of the string/stream object and use it whenver you need to issue commands.

something similar to this:

#Create a temporary file to use $filetmp=[System.IO.Path]::GetTempFileName()

#Get content of key from DB

in this line we use a proper file to emulate the behavior

$key = Get-Content C:\PAG\Key\id_dsa | Out-File $filetmp

#Open a session to TPAM New-SSHSession -ComputerName $tpamurl -KeyFile $filetmp -Credential $username

#remove the file remove-item $filetmp -force

Eventually you may exclusively lock the file to be sure nobody can use it example: http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/99#issuecomment-248284399, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HqJKo53UOKif49WqNdCqjUwrojI8ks5qr87rgaJpZM4Iu1n2.

darkoperator avatar Sep 20 '16 12:09 darkoperator

I may help if you like.. working right now on some scripting that uses your work.

Il Martedì 20 Settembre 2016 14:36, Carlos Perez <[email protected]> ha scritto:

I plan on adding the feature but it will take me a while since I’m traveling and teaching several offensive and defensive powershell and IR classes until decemeber and the mod is not a simple one.

On Sep 20, 2016, at 8:17 AM, alefesta [email protected] wrote:

I'm using as workaround to this a simple tmp file where to store the key, using it and than remove the file. They key may be retrieved easily from virtually anywhere, in my case I store the key in a DB table. This way you may take care of the string/stream object and use it whenver you need to issue commands.

something similar to this:

#Create a temporary file to use $filetmp=[System.IO.Path]::GetTempFileName()

#Get content of key from DB

in this line we use a proper file to emulate the behavior

$key = Get-Content C:\PAG\Key\id_dsa | Out-File $filetmp

#Open a session to TPAM New-SSHSession -ComputerName $tpamurl -KeyFile $filetmp -Credential $username

#remove the file remove-item $filetmp -force

Eventually you may exclusively lock the file to be sure nobody can use it example: http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/99#issuecomment-248284399, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HqJKo53UOKif49WqNdCqjUwrojI8ks5qr87rgaJpZM4Iu1n2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

alefesta-zz avatar Sep 20 '16 12:09 alefesta-zz

The changes are in C# in one of the classes and several cmdlets, how is your C#?

On Sep 20, 2016, at 8:40 AM, alefesta [email protected] wrote:

I may help if you like.. working right now on some scripting that uses your work.

Il Martedì 20 Settembre 2016 14:36, Carlos Perez [email protected] ha scritto:

I plan on adding the feature but it will take me a while since I’m traveling and teaching several offensive and defensive powershell and IR classes until decemeber and the mod is not a simple one.

On Sep 20, 2016, at 8:17 AM, alefesta [email protected] wrote:

I'm using as workaround to this a simple tmp file where to store the key, using it and than remove the file. They key may be retrieved easily from virtually anywhere, in my case I store the key in a DB table. This way you may take care of the string/stream object and use it whenver you need to issue commands.

something similar to this:

#Create a temporary file to use $filetmp=[System.IO.Path]::GetTempFileName()

#Get content of key from DB

in this line we use a proper file to emulate the behavior

$key = Get-Content C:\PAG\Key\id_dsa | Out-File $filetmp

#Open a session to TPAM New-SSHSession -ComputerName $tpamurl -KeyFile $filetmp -Credential $username

#remove the file remove-item $filetmp -force

Eventually you may exclusively lock the file to be sure nobody can use it example: http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/99#issuecomment-248284399, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HqJKo53UOKif49WqNdCqjUwrojI8ks5qr87rgaJpZM4Iu1n2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/99#issuecomment-248289332, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0Htu-Do34ENzKd9dOt-m4WDwJ00LBks5qr9Q9gaJpZM4Iu1n2.

darkoperator avatar Sep 20 '16 12:09 darkoperator

 A little bit rusty but I may at least work on a local copy and once is done show you so you may evaluate it..

Il Martedì 20 Settembre 2016 14:42, Carlos Perez <[email protected]> ha scritto:

The changes are in C# in one of the classes and several cmdlets, how is your C#?

On Sep 20, 2016, at 8:40 AM, alefesta [email protected] wrote:

I may help if you like.. working right now on some scripting that uses your work.

Il Martedì 20 Settembre 2016 14:36, Carlos Perez [email protected] ha scritto:

I plan on adding the feature but it will take me a while since I’m traveling and teaching several offensive and defensive powershell and IR classes until decemeber and the mod is not a simple one.

On Sep 20, 2016, at 8:17 AM, alefesta [email protected] wrote:

I'm using as workaround to this a simple tmp file where to store the key, using it and than remove the file. They key may be retrieved easily from virtually anywhere, in my case I store the key in a DB table. This way you may take care of the string/stream object and use it whenver you need to issue commands.

something similar to this:

#Create a temporary file to use $filetmp=[System.IO.Path]::GetTempFileName()

#Get content of key from DB

in this line we use a proper file to emulate the behavior

$key = Get-Content C:\PAG\Key\id_dsa | Out-File $filetmp

#Open a session to TPAM New-SSHSession -ComputerName $tpamurl -KeyFile $filetmp -Credential $username

#remove the file remove-item $filetmp -force

Eventually you may exclusively lock the file to be sure nobody can use it example: http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell http://stackoverflow.com/questions/21086051/locking-the-file-while-writing-in-powershell — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/99#issuecomment-248284399, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HqJKo53UOKif49WqNdCqjUwrojI8ks5qr87rgaJpZM4Iu1n2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/99#issuecomment-248289332, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0Htu-Do34ENzKd9dOt-m4WDwJ00LBks5qr9Q9gaJpZM4Iu1n2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

alefesta-zz avatar Sep 20 '16 12:09 alefesta-zz

this will be in the compiled version of 2.0, you can test the branch for the version

darkoperator avatar Nov 22 '16 19:11 darkoperator

thanks that's a great news!

Il Martedì 22 Novembre 2016 20:30, Carlos Perez <[email protected]> ha scritto:

this will be in the compiled version of 2.0, you can test the branch for the version— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

alefesta-zz avatar Nov 22 '16 19:11 alefesta-zz