Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

Mit dem Absenden dieses Formulars akzeptiere ich die Datenschutzerklärung von NinjaOne.

Festlegen der NTLM-Authentifizierung in Windows mit PowerShell

In einer sich ständig weiterentwickelnden Cybersecurity-Landschaft ist die Sicherung von Kommunikation und Datenaustausch von höchster Bedeutung. Ein Protokoll, das in diesem Zusammenhang besonders diskutiert wird, ist NTLM (NT LAN Manager), das zur Authentifizierung von Benutzer:innen in Microsoft-Umgebungen verwendet wird. Mit den jüngsten Fortschritten und Bedenken hinsichtlich Sicherheit hat es eine Umstellung von älteren NTLM-Versionen auf das sicherere NTLMv2 gegeben. Heute werden wir tief in ein PowerShell-Skript eintauchen, das dabei hilft, die NTLM-Authentifizierungs-Antworten zu verwalten, indem es den LmCompatibilityLevel in der Windows-Registrierung festlegt.

Hintergrund

Ursprünglich von Microsoft als Authentifizierungsprotokoll entwickelt, hat NTLM mehrere Aktualisierungen durchlaufen, um verschiedene Sicherheitslücken anzugehen. Allerdings wurde mit dem Aufkommen sicherer Authentifizierungsmechanismen, insbesondere NTLMv2, deutlich, dass es notwendig wurde, ältere Versionen einzuschränken oder zu deaktivieren. Dieses Skript unterstützt IT-Profis und Managed Service Providers (MSPs) dabei, diese Umstellung reibungslos zu vollziehen, ohne manuell durch komplexe Registrierungseinstellungen navigieren zu müssen.

Das Skript

#Requires -Version 5.1

<#
.SYNOPSIS
    Set the LM and NTLMv1 authentication responses via LmCompatibilityLevel in the registry
.DESCRIPTION
    Set the LM and NTLMv1 authentication responses via LmCompatibilityLevel in the registry
.EXAMPLE
    No parameters needed.
    Sets LAN Manager auth level to 5, "Send NTLMv2 response only. Refuse LM & NTLM."
.EXAMPLE
     -LmCompatibilityLevel 5
    Sets LAN Manager auth level to 5, "Send NTLMv2 response only. Refuse LM & NTLM."
.EXAMPLE
     -LmCompatibilityLevel 3
    Sets LAN Manager auth level to 3, "Send NTLMv2 response only."
    This is the default from Windows 7 and up.
.EXAMPLE
    PS C:> Disable-LmNtlmV1.ps1 -LmCompatibilityLevel 5
    Sets LAN Manager auth level to 5, "Send NTLMv2 response only. Refuse LM & NTLM."
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Reference chart: https://ss64.com/nt/syntax-ntlm.html
    Release Notes:
    Initial Release
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
.COMPONENT
    ProtocolSecurity
#>

[CmdletBinding()]
param (
    [Parameter()]
    [ValidateRange(0, 5)]
    [int]
    $LmCompatibilityLevel = 5
)

begin {
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))
        { Write-Output $true }
        else
        { Write-Output $false }
    }
    function Set-ItemProp {
        param (
            $Path,
            $Name,
            $Value,
            [ValidateSet("DWord", "QWord", "String", "ExpandedString", "Binary", "MultiString", "Unknown")]
            $PropertyType = "DWord"
        )
        New-Item -Path $Path -Force -ErrorAction SilentlyContinue | Out-Null
        if ((Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue)) {
            Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false | Out-Null
        }
        else {
            New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false | Out-Null
        }
    }
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }
    $Path = @(
        "HKLM:SYSTEMCurrentControlSetServicesLsa"
        "HKLM:SYSTEMCurrentControlSetControlLSA"
    )
    $Name = "LmCompatibilityLevel"
    # $Value = $LmCompatibilityLevel
    # Sets LmCompatibilityLevel to $LmCompatibilityLevel
    try {
        $Path | ForEach-Object {
            Set-ItemProp -Path $_ -Name $Name -Value $LmCompatibilityLevel
        }
        
    }
    catch {
        Write-Error $_
        exit 1
    }
    $Path | ForEach-Object {
        $Value = Get-ItemPropertyValue -Path $_ -Name $Name -ErrorAction SilentlyContinue
        if ($null -eq $Value) {
            Write-Host "$_$Name set to: OS's default value(3)."
        }
        else {
            Write-Host "$_$Name set to: $Value"
        }
    }
}
end {}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detailansicht

Das Skript ist im Wesentlichen in drei Phasen unterteilt: begin, process und end.

  • Beginn der Phase: Das Skript beginnt mit der Definition zweier Funktionen:
  • Test-IsElevated: Überprüft, ob das Skript mit Administratorrechten ausgeführt wird.
  • Set-ItemProp: Erstellt oder setzt eine Eigenschaft eines Registrierungsschlüssels.
  • Prozess-Phase: Es überprüft, ob der Benutzer erhöhte Rechte hat. Ist dies nicht der Fall, wird ein Fehler gemeldet. Andernfalls wird fortgefahren, den LmCompatibilityLevel in zwei potenziellen Registrierungspfaden zu ändern. Nach der Änderung bestätigt das Skript die vorgenommene Einstellung.
  • Endphase: Nicht explizit verwendet, aber es dient als Platzhalter für mögliche zukünftige Aktualisierungen oder Erweiterungen des Skripts.

Potenzielle Anwendungsfälle

Fallstudie: Stellen Sie sich Jenny vor, eine IT-Administratorin in einem mittelgroßen Unternehmen. Wenn aktiviert, werden alle Geräusche vom entfernten Gerät an die Lautsprecher des Technikers gesendet. (z.B. Wenn das entfernte Gerät ein YouTube-Video abspielt, kann der Techniker den Ton hören.) Bei Hunderten von Maschinen ist es nicht praktikabel, jede einzelne manuell zu aktualisieren. Wenn aktiviert, werden alle Geräusche vom entfernten Gerät an die Lautsprecher des Technikers gesendet. (z.B. wenn das entfernte Gerät ein YouTube-Video abspielt, kann der Techniker den Ton hören.)

Vergleiche

Obwohl Gruppenrichtlinien auch für die Verwaltung von NTLM-Einstellungen in einer Organisation verwendet werden können, bieten PowerShell-Skripte, wie das besprochene, eine genauere Steuerung und Automatisierung. Sie können in größere Automatisierungstools oder Arbeitsabläufe integriert werden, um den Prozess effizienter zu gestalten und weniger anfällig für manuelle Fehler zu sein.

FAQs

  • Wie prüft das Skript, ob es über Administratorrechte verfügt?
    Das Skript verwendet die Funktion Test-IsElevated, um festzustellen, ob es mit Administratorrechten ausgeführt wird.
  • Was ist, wenn ich einen anderen Wert für LmCompatibilityLevel festlegen möchte?
    Sie können dies tun, indem Sie den Parameter -LmCompatibilityLevel beim Ausführen des Skripts angeben, z.B. Disable-LmNtlmV1.ps1 -LmCompatibilityLevel 3.
  • Ist es rückwärtskompatibel mit älteren Windows-Versionen?
    Das Skript unterstützt Windows 10 und Windows Server 2016 und höher.

Auswirkungen

Durch Festlegen des LmCompatibilityLevel bestimmen IT-Profis, wie Systeme die NTLM-Authentifizierung behandeln. Die Beschränkung auf NTLMv2 verbessert die Sicherheit und reduziert Risiken im Zusammenhang mit älteren, weniger sicheren Versionen. Es ist jedoch entscheidend sicherzustellen, dass die Kompatibilität gewährleistet ist, da ältere Systeme oder Anwendungen nach den Änderungen möglicherweise Konnektivitätsprobleme haben könnten.

Empfehlungen

  • Sichern Sie immer den aktuellen Zustand der Registrierung, bevor Sie Änderungen vornehmen.
  • Testen Sie das Skript zuerst in einer kontrollierten Umgebung, um seine Auswirkungen zu verstehen.
  • Informieren Sie sich über die neuesten bewährten Sicherheitspraktiken und integrieren Sie diese in Ihre routinemäßigen Audits.

Abschließende Überlegungen

PowerShell-Skripte wie diese ermöglichen es IT-Profis, die Sicherheit zu stärken. Darüber hinaus erweitern Überwachungs- und Managementtools wie NinjaOne diese Fähigkeiten zusätzlich. Mit integrierten Plattformen für Überwachung, Automatisierung und Berichterstellung, wie NinjaOne stellen Sie sicher, dass Ihre IT-Infrastruktur robust, sicher und effizient bleibt. Diese ergänzen Skripte und manuelle Eingriffe.

Denken Sie daran, im Bereich der IT ebnet eine proaktive Vorgehensweise in Kombination mit den richtigen Tools den Weg für erhöhte Sicherheit und effizientes Systemmanagement.

 

Next Steps

Building an efficient and effective IT team requires a centralized solution that acts as your core service deliver tool. NinjaOne enables IT teams to monitor, manage, secure, and support all their devices, wherever they are, without the need for complex on-premises infrastructure.

Learn more about NinjaOne Remote Script Deployment, check out a live tour, or start your free trial of the NinjaOne platform.

Kategorien:

Das könnte Sie auch interessieren

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).