PowerShell中實(shí)現(xiàn)混淆密碼示例
適用于PowerShell 3.0或者更高版本,
盡管我們并不推薦將密碼硬編碼在腳本文件中,但是仍舊有一些場景非如此不可。與將密碼以一種純文本的方式硬編碼相比,我們還可以稍微花點(diǎn)心思,把密碼混淆一下。雖然混淆密碼是一種非常低級的保護(hù)方式,但是對于不懂PowerShell的人來講,還是比較神秘的。
接下來的腳本會(huì)向用戶詢問用戶名和密碼,然后刪除通過混淆腳本進(jìn)行處理,產(chǎn)生用戶憑據(jù)對象。
當(dāng)你運(yùn)行了下面的腳本以后,用戶憑據(jù)已經(jīng)被保存在$cred。接下來你幾乎可以在任何帶有–Credential參數(shù)的命令中使用它了。
$cred = Get-Credential -Message 'Enter Domain\Username and Password'
$pwd = $cred.Password
$user = $cred.UserName
$key = 1..32 | ForEach-Object { Get-Random -Maximum 256 }
$pwdencrypted = $pwd | ConvertFrom-SecureString -Key $key
$private:ofs = ' '
$generatedScript = @()
$generatedScript += '$password = ''{0}''' -f $pwdencrypted
$generatedScript += '$key = ''{0}''' -f "$key "
$generatedScript += '$passwordSecure = ConvertTo-SecureString -String $password -Key ([Byte[]]$key.Split('' ''))'
$generatedScript += '$cred = New-Object system.Management.Automation.PSCredential(''{0}'', $passwordSecure)' -f $user
$generatedScript += '$cred'
$file = $psise.CurrentPowerShellTab.Files.Add()
$file.Editor.Text = $generatedScript | Out-String
$file.Editor.SetCaretPosition(1,1)
產(chǎn)生的密碼可能像這樣:
$password = '76492d1116743f0423413b16050a5345MgB8AHMAUQA3AFAAVwB0AGkAUQBUAC8AdwBqADYAUABVAFYAUwB4AEYAYgB4AFEAPQA9AHwAZgA0ADgAOQA4AGYANwA0AGEAMAA0ADUANwA5ADkAMwA5ADkAMwA1ADUANQA0AGYANwA5AGQANwBkAGYAOQBmAGEAYQA3ADMAYgBkADIAOQA3AGMAYQBmADUAMgA3ADEANwA3AGEAYgBmADAAYgA1AGYAYwAyADYAYgAzADkAOAA='
$key = '187 98 34 82 148 52 13 86 246 2 130 197 217 97 147 98 75 197 149 246 74 35 27 7 211 15 131 93 182 231 171 3'
$passwordSecure = ConvertTo-SecureString -String $password -Key ([Byte[]]$key.Split(' '))
$cred = New-Object system.Management.Automation.PSCredential('mickey\mouse', $passwordSecure)
$cred
相關(guān)文章
Windows Powershell 通過函數(shù)擴(kuò)展別名
這篇文章主要介紹了Windows Powershell 通過函數(shù)擴(kuò)展別名,需要的朋友可以參考下2014-09-09
PowerShell中實(shí)現(xiàn)混淆密碼示例
這篇文章主要介紹了PowerShell中實(shí)現(xiàn)混淆密碼示例,本文給出了混淆密碼的例子和使用混淆后的密碼例子,需要的朋友可以參考下2015-03-03
Powershell小技巧之使用Jint引擎在PowerShell中執(zhí)行Javascript函數(shù)
這里演示如何利用PowerShell將一段Javascript函數(shù)字符串交給Jint引擎去執(zhí)行。方法很簡單,希望對大家有所幫助2014-09-09
PowerShell中字符串使用單引號和雙引號的區(qū)別
這篇文章主要介紹了PowerShell中字符串使用單引號和雙引號的區(qū)別,大家可能會(huì)經(jīng)常遇到這個(gè)問題,需要的朋友可以參考下2014-08-08
Windows Powershell 復(fù)制數(shù)組
這篇文章主要介紹了Windows Powershell 復(fù)制數(shù)組 ,需要的朋友可以參考下2014-09-09
PowerShell腳本開發(fā)之對指定IP進(jìn)行端口掃描
在本文通過一段小腳本的方式引入了通過PowerShell實(shí)現(xiàn)簡單安全滲透功能的想法,首先介紹了該小腳本是如何實(shí)現(xiàn)功能的,接下來對創(chuàng)建腳本工具集并導(dǎo)入的方法,隨后又在該工具集中創(chuàng)建了Test-TCPPort函數(shù),并介紹了調(diào)用方法.2014-10-10
PowerShell 遠(yuǎn)程執(zhí)行任務(wù)的方法步驟
這篇文章主要介紹了PowerShell 遠(yuǎn)程執(zhí)行任務(wù)的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12

