【发布时间】:2014-11-07 19:00:49
【问题描述】:
因此,在我的脚本中,我不仅希望用户输入凭据并将其存储在变量中,而且能够验证密码是否与目标系统上的管理员密码匹配。到目前为止,我发现这样做的唯一方法是将未加密的实际密码放入脚本中,并将其与用户输入的密码进行比较。这是一个巨大的安全漏洞,为了解决这个问题,我想知道是否可以使用 gwmi 查询(SID?)作为对象获取管理员密码,并将其与用户输入的安全字符串进行比较。
这是我现在使用的有缺陷的代码。
Do
{
$password = $null
$password = read-host "Enter the Administrator Password" -assecurestring
$AdminPass = ConvertTo-SecureString "adminpassword" -AsPlainText -Force
$pwd1_text = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
$pwd2_text = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($AdminPass))
if ($pwd1_text -cne $pwd2_text) {Write-Host -ForegroundColor Red "Incorrect Password"; $password = $null}
$count ++
$tries = 3 - $count
if ($password -eq $null) {Write-Host -ForegroundColor Yellow "$tries Attempts Remaining"}
if ($count -eq 3) {Write-Host -ForegroundColor Red "$count Unsuccessful Password Attempts. Exiting..."; exit}
}While ($password -eq $null)
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "$ComputerName\Administrator",$password
【问题讨论】:
-
您可以尝试使用用户名管理员和用户提供的密码访问目标服务器上的资源吗?但是,这可能会导致本地管理员帐户无法锁定。
-
这就是我之前所做的,但是脚本会拉取凭据来进行一些远程安装并在另一台电脑上设置 reg 值。我想让使用这个脚本的技术人员知道他们输入了错误的密码,而不是来找我说它坏了。
标签: powershell passwords wmi remote-access password-encryption