2013-08-07 19 views
19

Jestem nowy w powershell i mam problemy z delegowaniem uprawnień. Mam następujący skrypt:Powielanie mocy Powershell - zasady nie zezwalają na przekazywanie danych uwierzytelniających użytkownika

$session = New-PSSession myserver -Authentication CredSSP -Credential DOMAIN\Administrator 
Invoke-Command -Session $session -ScriptBlock { <Some PowerShell Command> } 

Przed uruchomieniem go, zrobiłem następujący:

  1. Uruchom Enable-PSRemoting na mójserwer.
  2. Uruchom Enable-WSManCredSSP Server na myserver.
  3. Uruchom Restart-Service WinRM na myserver.
  4. Uruchom klienta Enable-WSManCredSSP Client –DelegateComputer myserver na kliencie.
  5. Ponownie uruchomiono serwer i klienta.

Ale kiedy uruchomić skrypt, pojawia się następujący komunikat o błędzie:

[myserver] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. A computer policy does not allow the delegation of 
the user credentials to the target computer. Use gpedit.msc and look at the following policy: Computer Configuration -> Administrative Templates -> System -> Credentials Delega 
tion -> Allow Delegating Fresh Credentials. Verify that it is enabled and configured with an SPN appropriate for the target computer. For example, for a target computer name "m 
yserver.domain.com", the SPN can be one of the following: WSMAN/myserver.domain.com or WSMAN/*.domain.com. For more information, see the about_Remote_Troubleshooting Help topic. 
    + CategoryInfo   : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException 
    + FullyQualifiedErrorId : PSSessionOpenFailed 

Sprawdziłem zasady jak wspomniano w komunikacie o błędzie, ale wszystko wydaje się być w porządku. Co jeszcze może mnie blokować?

+0

Czy jesteś wymieniony jako administrator na swoim pilocie? – BlackHatSamurai

+0

@Blaine: Użytkownik DOMAIN \ Administrator, którego próbuję podszywać się, jest administratorem zdalnego serwera. Jestem też połączony z komputerem klienta przy użyciu konta administracyjnego. – ChrisB

+0

Czy włączyłeś zdalne wykonywanie skryptów w zdalnym polu: 'Enable-PSRemoting' – BlackHatSamurai

Odpowiedz

10

W końcu udało mi się to osiągnąć dzięki this page. Zapewnia skrypt, który ustawia wymagane zasady delegowania poświadczeń, bezpośrednio ustawiając odpowiednie klucze rejestru. Raz wpadłem ten skrypt z uprawnieniami administratora, udało mi się z powodzeniem nawiązać połączenie CredSSP do mójserwer:

Enable-WSManCredSSP -Role client -DelegateComputer *.mydomain.com 

$allowed = @('WSMAN/*.mydomain.com') 

$key = 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation' 
if (!(Test-Path $key)) { 
    md $key 
} 
New-ItemProperty -Path $key -Name AllowFreshCredentials -Value 1 -PropertyType Dword -Force    

$key = Join-Path $key 'AllowFreshCredentials' 
if (!(Test-Path $key)) { 
    md $key 
} 
$i = 1 
$allowed |% { 
    # Script does not take into account existing entries in this key 
    New-ItemProperty -Path $key -Name $i -Value $_ -PropertyType String -Force 
    $i++ 
} 
+3

Czy to jest uruchamiane z klienta lub z serwera? – ginalster

+0

Od klienta. –

18

musiałem wykonać następujące czynności na serwerze:

Enable-WSManCredSSP -Role Server 

musiałem zrobić po stronie klienta:

set-item wsman:localhost\client\trustedhosts -value * 

Enable-WSManCredSSP -Role Client –DelegateComputer * 

Korzystając gpedit.msc na kliencie, aby umożliwić delegowanie Fresh poświadczeń WSMAN/*:

  1. Rozwiń Local Computer Policy rozwiń Computer Configuration rozwiń Administrative Templates rozwiń System, a następnie kliknij Credential Delegation.
  2. W okienku Settings kliknij dwukrotnie Allow Delegating Fresh Credentials with NTLM-only Server Authentication.
  3. W oknie dialogowym wykonaj następujące czynności:
  4. Kliknij przycisk Enabled.
  5. W obszarze Options kliknij pozycję Show.
  6. W wartości wpisz WSMAN/*, a następnie kliknij OK. Upewnij się, że wybrano Concatenate OS defaults with input above, a następnie kliknij OK.

Poniższa komenda działa teraz (po wierszu hasła):

Invoke-Command { dir \\fileserver\devtools } -computer appserver01 -authentication credssp -credential domain\user 

Zobacz MSDN forums.

Zobacz TechNet

+0

Czy możesz wyjaśnić "Użyj gpedit.msc, aby włączyć przekazywanie świeżych poświadczeń do WSMAN/*"? – Peter

+1

Sure @Peter. Właśnie dodałem więcej instrukcji. Dodałem także odniesienie do TechNet. –

+2

Aby pomóc innym: uruchom kroki gpedit na komputerze klienta. –

3

Rozwijając na odpowiedź Akiry powyżej, w gpedit.msc musiałem ustawić „Zezwalaj Delegowanie Fresh poświadczeń NTLM-tylko uwierzytelnianie serwera” zamiast „Pozwól Delegowanie Fresh Poświadczenia”.

+0

Dzięki, właśnie poprawiłem swoją odpowiedź. –

1

Musiałem w pełni zautomatyzować moje rozwiązanie, w szczególności część dotyczącą rozwiązania, które zostało wprowadzone do edytora GPO.

1) Włącz zdalnego PS

Enable-PSRemoting -force 

2) Włącz CredSSP

Enable-WSManCredSSP -Role Server -Force 
Enable-WSManCredSSP -Role Client -DelegateComputer locahost -Force 
Enable-WSManCredSSP -Role Client -DelegateComputer $env:COMPUTERNAME -Force 
Enable-WSManCredSSP -Role Client -DelegateComputer $domain -Force 
Enable-WSManCredSSP -Role Client -DelegateComputer "*.$domain" -Force 
Set-Item -Path "wsman:\localhost\service\auth\credSSP" -Value $True -Force 

3) Włącz ntlm Świeże poświadczenia przez Registery:

New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation -Name AllowFreshCredentialsWhenNTLMOnly -Force 
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation\AllowFreshCredentialsWhenNTLMOnly -Name 1 -Value * -PropertyType String 

tylko po to, że w stanie uruchamiać skrypt powershell jako lokalny administrator, który był w stanie uruchomić w usłudze PSSession i przedprocesowych działaniach AD.

$secpasswd = ConvertTo-SecureString $adPassword -AsPlainText -Force 
$credential = New-Object System.Management.Automation.PSCredential ("$domain\Admin", $secpasswd) 
$adminSession = New-PSSession -Credential $credential -Authentication Credssp; 

$sb = { 
    param($p1, $p2) 

    whoami 

    New-ADUser .... 
} 

Invoke-Command -Session $adminSession -Script $sb -ArgumentList $domain,$userPassword