2014-03-05 66 views
0

我的應用程序需要用戶通過Active Directory進行驗證。我們正在考慮使用System.DirectoryServices.DirectoryEntry來執行一個PowerShell腳本,我們會傳遞一個用戶名和密碼。如何在Powershell中安全驗證AD用戶(加密憑證)

我看到它在不同的答案中提到了System.DirectoryServices.DirectoryEntry使用LDAP來讀取AD信息的事實。 LDAP協議本身不加密。您可以使用LDAPS,但需要設置CA.我想知道這個命令生成的網絡流量是否默認安全 - 即是否有可能通過網絡嗅探密碼?

編輯 我發現您可以將其他選項傳遞給DirectoryEntry實例。這是示例代碼:

$username = $args[0] 
$password = $args[1] 

Function Test-ADAuthentication { 
    param($username,$password) 
    (new-object directoryservices.directoryentry "",$username,$password,Secure -bor Sealing).psbase.name -ne $null 
} 

Test-ADAuthentication $username $password 

第四個參數是一個枚舉AuthenticationTypes http://msdn.microsoft.com/en-us/library/system.directoryservices.authenticationtypes(v=vs.90).aspx

,似乎令人感興趣的是值:安全&密封它們組合起來將加密憑據

許多感謝讀。

回答

1

這是我發現的PowerShell腳本用戶AD認證的最佳解決方案。根據MS文檔,協商和密封標誌一起將加密數據:http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.contextoptions(v=vs.110).aspx

$username = $args[0] 
$password = $args[1] 

$pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Domain', $system.Domain 

return $pc.ValidateCredentials($username, $password, [DirectoryServices.AccountManagement.ContextOptions]::Negotiate -bor [DirectoryServices.AccountManagement.ContextOptions]::Sealing) 
0

如果我沒有記錯,則無法以未加密的方式向Active Directory進行身份驗證。每個域控制器在接受憑證之前都會與客戶端建立某種加密連接。

Powershell使用其他客戶端使用的相同方法向DC進行身份驗證。也就是說,無論您是在Windows 8登錄屏幕,Sharepoint頁面,自定義程序還是Powershell提示符下輸入憑據,DC都將以相同方式進行身份驗證。您可以通過組策略修改AD的身份驗證機制,但每種機制都會加密數據。

我在幾分鐘內沒有在Google上找到很多文檔,但華盛頓大學的這篇文章總的來說很好地概述了LDAP以及與AD有關的LDAP。跳轉到「活動目錄支持四種SASL認證機制」行讀取

http://www.netid.washington.edu/documentation/ldapAuth.aspx

而且,GPO的有關兩個鏈接登錄的安全性。 Tangientially關係到你的問題,但他們可能會派上用場: http://technet.microsoft.com/en-us/library/dn169021%28v=ws.10%29.aspx http://technet.microsoft.com/en-us/library/jj852258%28v=ws.10%29.aspx

+0

嗨邁克爾。感謝您的時間。就LDAP而言 - 除非你使用LDAPS協議,否則它不會被默認加密,我已經知道了。我不相信你的第二段 - Powershell只是使用.NET庫,如上面的代碼示例 - 除非所有的PowerShell流量都是加密的?不過,我現在已經發現如何啓用安全+密封認證,根據文檔將提供使用Kerberos的安全認證... –