简体   繁体   English

存储加密密码 Powershell

[英]Storing encrypted password Powershell

I am having challenge with one of my Powershell scripts.我的 Powershell 脚本之一遇到了挑战。 The idea is to run a tool from a client, which will kill some processes using the PID.这个想法是从客户端运行一个工具,它将使用 PID 杀死一些进程。 Proof of concept works - ps1 script is converted to exe (PS2GUI) and the tool is successfully killing the PID of the user on the server.概念证明有效 - ps1 脚本被转换为 exe (PS2GUI),并且该工具成功地杀死了服务器上用户的 PID。


$credentials = New-Object System.Management.Automation.PsCredential("domain\user",$password)

$scriptBlockSQL = {
sqlplus.exe command
}

Invoke-Command -ComputerName "server" -Credential $credentials -scriptBlock $scriptBlockSQL

However I have a bit of a problem, because I currently store the password in the script as clear text which is very unsafe - since the.exe can be decompiled in less than a few seconds.但是我有一点问题,因为我目前将密码作为明文存储在脚本中,这是非常不安全的——因为.exe 可以在不到几秒钟的时间内被反编译。

I have tried the ConvertTo-SecureString with the encrypted string, however this ties it with the user account & pc - which is not an option.我已经尝试过使用加密字符串的 ConvertTo-SecureString,但是这会将它与用户帐户和 pc 联系起来——这不是一个选项。 The usage of the Key file is also not an option.密钥文件的使用也不是一种选择。

Do you have any suggestion how to make the script safer & usable?您对如何使脚本更安全和可用有什么建议吗? Or any other solution which will work in the same way?或任何其他将以相同方式工作的解决方案?

Thanks!谢谢!

Well, when you are encrypting password with a SecureString then you have to define the password somewhere in the code or in another file.好吧,当您使用 SecureString 加密密码时,您必须在代码或另一个文件中的某处定义密码。 So this is not a good idea.所以这不是一个好主意。 Then you have to look for a way to protect script source code in an efficient way.然后您必须寻找一种有效保护脚本源代码的方法。

PS2GUI will encrypt your source code in a reversible encryption, that means when the script is ran by powershell, the engine will decrypt the code. PS2GUI 将以可逆加密方式加密您的源代码,这意味着当 powershell 运行脚本时,引擎将解密代码。 It is also weak because of using symmetric key algorithm.由于使用对称密钥算法,它也很弱。

Powershell scripts are also encrypted in Base64 format, and PS2GUI does the quite same like thing. Powershell 脚本也以 Base64 格式加密,而 PS2GUI 也做了同样的事情。

The best way I think now is to prompt the user for credentials.我认为现在最好的方法是提示用户输入凭据。 Like this:像这样:

$password = Read-Host "Enter password" -AsSecureString

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM