Die wichtigsten Erkenntnisse
- Automatisierte Überprüfung der Benutzerkontensteuerung (UAC): Das Skript bietet eine automatisierte Lösung für die Überprüfung der Benutzerkontensteuerungs-Einstellungen auf Windows-Systemen.
- Verbesserte Sicherheit: Es stellt sicher, dass die UAC-Einstellungen mit den Sicherheitsstandards übereinstimmen und erhöht so die Systemsicherheit erheblich.
- Protokollierung in benutzerdefinierten Feldern: Das Skript integriert mit NinjaOne für die Protokollierung von UAC-Stufen in benutzerdefinierten Feldern und verbessert so die Aufrechterhaltung von Datensätzen und die Berichterstattung.
- Unterstützt Windows 7 und höher: Das Skript ist mit Windows 7, Windows Server 2012 und nachfolgenden Versionen kompatibel.
- Erfordert Administratorrechte: Für die Ausführung dieses Skripts sind Administratorrechte erforderlich, um auf die Registrierungseinstellungen zuzugreifen und sie zu ändern.
- Vielseitigkeit im Einsatz: Ideal für MSPs und IT-Expert:innen, die Sicherheit über mehrere Systeme hinweg gewährleisten müssen.
- Proaktive Risikominimierung: Die regelmäßige Anwendung hilft, unautorisierte Systemänderungen proaktiv zu verhindern.
- Integration mit Managed Services: Besonders vorteilhaft für diejenigen, die NinjaOne für ein zentrales IT-Management einsetzen.
- Führung von Protokollierung für Compliance-Zwecke: Das Skript protokolliert UAC-Einstellungen und hilft so bei der Einhaltung von IT-Sicherheitsrichtlinien und bei Audits.
Vorwort
Die Benutzerkontensteuerung (UAC) ist eine wichtige Komponente des Windows-Betriebssystems, die eine zusätzliche Sicherheitsebene bietet. Sie beschränkt die Anwendung der Software im Wesentlichen auf die Standardbenutzerrechte, bis ein Administrator eine Erhöhung der Berechtigungsstufe genehmigt. In der dynamischen Welt der IT-Sicherheit, in der Schwachstellen von nicht autorisierten Benutzer:innen ausgenutzt werden können, ist die Aufrechterhaltung optimaler UAC-Einstellungen essenziell. In diesem Blogbeitrag wird ein PowerShell-Skript vorgestellt, mit dem die UAC-Einstellungen auf einem Windows-Computer überprüft und konfiguriert werden können. Dieses Tool ist für IT-Expert:innen und Managed Service Provider (MSPs) von großer Bedeutung.
Kontext
Das betreffende Skript bietet einen umfassenden Ansatz zur Überprüfung der UAC-Stufe auf einem Windows-System. IT-Expert:innen und MSPs benötigen solche Tools häufig, um sicherzustellen, dass die von ihnen verwalteten Systeme bestimmte Sicherheitsstandards einhalten. Das Skript prüft nicht nur, sondern erleichtert auch die Aktualisierung der UAC-Einstellungen und kann diese in einem benutzerdefinierten Feld für Berichtszwecke protokollieren. Seine Fähigkeit, in der NinjaOne-Umgebung zu laufen, erhöht seinen Nutzen für Managed-IT-Services noch weiter.
Das Skript zur Überprüfung der Benutzerkontensteuerung
#Requires -Version 2 <# .SYNOPSIS Condition/Audit UAC Level. Can save the UAC Level to a custom field if specified. .DESCRIPTION Condition/Audit UAC Level. Can save the UAC Level to a custom field if specified. Exit Code of 0 is that the UAC Level is set to the defaults or higher Exit Code of 1 is that the UAC Level is to lower than defaults Exit Code of 2 is when this fails to update a custom field .EXAMPLE -CustomField "uac" Saves the UAC Level to a custom field. .OUTPUTS String[] .NOTES Minimum OS Architecture Supported: Windows 7, Windows Server 2012 Release Notes: Renamed script and added Script Variable support 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). #> [CmdletBinding()] param ( [Parameter()] [String]$CustomField ) begin { if ($env:customFieldName -and $env:customFieldName -notlike "null") { $CustomField = $env:customFieldName } # https://learn.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#registry-key-settings # Define the path in the registry $Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" # Define the values to check $Values = "FilterAdministratorToken", "EnableUIADesktopToggle", "ConsentPromptBehaviorAdmin", "ConsentPromptBehaviorUser", "EnableInstallerDetection", "ValidateAdminCodeSignatures", "EnableSecureUIAPaths", "EnableLUA", "PromptOnSecureDesktop", "EnableVirtualization" # This function is to make it easier to set Ninja Custom Fields. function Set-NinjaProperty { [CmdletBinding()] Param( [Parameter(Mandatory = $True)] [String]$Name, [Parameter()] [String]$Type, [Parameter(Mandatory = $True, ValueFromPipeline = $True)] $Value, [Parameter()] [String]$DocumentName ) # If we're requested to set the field value for a Ninja document we'll specify it here. $DocumentationParams = @{} if ($DocumentName) { $DocumentationParams["DocumentName"] = $DocumentName } # This is a list of valid fields we can set. If no type is given we'll assume the input doesn't have to be changed in any way. $ValidFields = "Attachment", "Checkbox", "Date", "Date or Date Time", "Decimal", "Dropdown", "Email", "Integer", "IP Address", "MultiLine", "MultiSelect", "Phone", "Secure", "Text", "Time", "URL" if ($Type -and $ValidFields -notcontains $Type) { Write-Warning "$Type is an invalid type! Please check here for valid types. https://ninjarmm.zendesk.com/hc/en-us/articles/16973443979789-Command-Line-Interface-CLI-Supported-Fields-and-Functionality" } # The below field requires additional information in order to set $NeedsOptions = "Dropdown" if ($DocumentName) { if ($NeedsOptions -contains $Type) { # We'll redirect the error output to the success stream to make it easier to error out if nothing was found or something else went wrong. $NinjaPropertyOptions = Ninja-Property-Docs-Options -AttributeName $Name @DocumentationParams 2>&1 } } else { if ($NeedsOptions -contains $Type) { $NinjaPropertyOptions = Ninja-Property-Options -Name $Name 2>&1 } } # If we received some sort of error it should have an exception property and we'll exit the function with that error information. if ($NinjaPropertyOptions.Exception) { throw $NinjaPropertyOptions } # The below type's require values not typically given in order to be set. The below code will convert whatever we're given into a format ninjarmm-cli supports. switch ($Type) { "Checkbox" { # While it's highly likely we were given a value like "True" or a boolean datatype it's better to be safe than sorry. $NinjaValue = [System.Convert]::ToBoolean($Value) } "Date or Date Time" { # Ninjarmm-cli is expecting the time to be representing as a Unix Epoch string. So we'll convert what we were given into that format. $Date = (Get-Date $Value).ToUniversalTime() $TimeSpan = New-TimeSpan (Get-Date "1970-01-01 00:00:00") $Date $NinjaValue = $TimeSpan.TotalSeconds } "Dropdown" { # Ninjarmm-cli is expecting the guid of the option we're trying to select. So we'll match up the value we were given with a guid. $Options = $NinjaPropertyOptions -replace '=', ',' | ConvertFrom-Csv -Header "GUID", "Name" $Selection = $Options | Where-Object { $_.Name -eq $Value } | Select-Object -ExpandProperty GUID if (-not $Selection) { throw "Value is not present in dropdown" } $NinjaValue = $Selection } default { # All the other types shouldn't require additional work on the input. $NinjaValue = $Value } } # We'll need to set the field differently depending on if its a field in a Ninja Document or not. if ($DocumentName) { $CustomField = Ninja-Property-Docs-Set -AttributeName $Name -AttributeValue $NinjaValue @DocumentationParams 2>&1 } else { $CustomField = Ninja-Property-Set -Name $Name -Value $NinjaValue 2>&1 } if ($CustomField.Exception) { throw $CustomField } } } process { $UacResults = [PSCustomObject]@{} # Loop through each value and get each value and add them to $UacResults as a property $Values | ForEach-Object { $Value = $_ $Result = $null $Result = Get-ItemProperty -Path $Path -Name $Value -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $Value if ($null -eq $Result) { switch ($Value) { 'FilterAdministratorToken' { $Result = 0; break } 'EnableUIADesktopToggle' { $Result = 0; break } 'ConsentPromptBehaviorAdmin' { $Result = 5; break } 'ConsentPromptBehaviorUser' { $Result = 3; break } 'EnableInstallerDetection' { $Result = 0; break } # Assumes enterprise and not Home 'ValidateAdminCodeSignatures' { $Result = 0; break } 'EnableSecureUIAPaths' { $Result = 1; break } 'EnableLUA' { $Result = 1; break } 'PromptOnSecureDesktop' { $Result = 1; break } 'EnableVirtualization' { $Result = 1; break } Default { $Result = 1 } } } $UacResults | Add-Member -MemberType NoteProperty -Name $Value -Value $Result } # Is UAC enabled or disabled if ( $UacResults.ConsentPromptBehaviorAdmin -eq 5 -and $UacResults.ConsentPromptBehaviorUser -eq 3 -and $UacResults.EnableLUA -eq 1 -and $UacResults.FilterAdministratorToken -eq 0 -and $UacResults.EnableUIADesktopToggle -eq 0 -and $UacResults.ConsentPromptBehaviorAdmin -eq 5 -and $UacResults.ConsentPromptBehaviorUser -eq 3 -and # Enterprise ( ( (Get-CimInstance -ClassName Win32_OperatingSystem).Caption -notlike "*Home*" -and $UacResults.EnableInstallerDetection -eq 1 ) -or ( (Get-CimInstance -ClassName Win32_OperatingSystem).Caption -like "*Home*" -and $UacResults.EnableInstallerDetection -eq 0 ) ) -and $UacResults.ValidateAdminCodeSignatures -eq 0 -and $UacResults.EnableSecureUIAPaths -eq 1 -and $UacResults.EnableLUA -eq 1 -and $UacResults.PromptOnSecureDesktop -eq 1 -and $UacResults.EnableVirtualization -eq 1 ) { "UAC Enabled with defaults." | Write-Host } elseif ( $UacResults.EnableLUA -eq 0 -or $UacResults.ConsentPromptBehaviorAdmin -eq 0 -or $UacResults.PromptOnSecureDesktop -eq 0 ) { "UAC Disabled." | Write-Host } # Get the UAC Level $UACLevel = if ( $UacResults.EnableLUA -eq 0 ) { 0 } elseif ( $UacResults.ConsentPromptBehaviorAdmin -eq 5 -and $UacResults.PromptOnSecureDesktop -eq 0 -and $UacResults.EnableLUA -eq 1 ) { 1 } elseif ( $UacResults.ConsentPromptBehaviorAdmin -eq 5 -and $UacResults.PromptOnSecureDesktop -eq 1 -and $UacResults.EnableLUA -eq 1 ) { 2 } elseif ( $UacResults.ConsentPromptBehaviorAdmin -eq 2 -and $UacResults.PromptOnSecureDesktop -eq 1 -and $UacResults.EnableLUA -eq 1 ) { 3 } # Get the Text version of the UAC Level $UACLevelText = switch ($UACLevel) { 0 { "Never notify"; break } 1 { "Notify me only (do not dim my desktop)"; break } 2 { "Notify me only (default)"; break } 3 { "Always notify"; break } Default { "Unknown"; break } } # Output the UAC Level "UAC Level: $UACLevel = $UACLevelText" | Write-Host # Output the UAC settings $UacResults | Out-String | Write-Host # When CustomField is used save the UAC Level to that custom field if ($CustomField) { try { Set-NinjaProperty -Name $CustomField -Value "$UACLevel = $UACLevelText" -ErrorAction Stop } catch { Write-Error "Failed to update Custom Field ($CustomField)" exit 2 } } # Return and exit code of 0 if UAC is set to the default or higher, or 1 when not set to the default if ($UACLevel -ge 2) { exit 0 } elseif ($UACLevel -lt 2) { exit 1 } else { exit 1 } } end { }
Greifen Sie auf über 300 Skripte im NinjaOne Dojo zu.
Detaillierte Aufschlüsselung
Das Skript arbeitet in mehreren Stufen:
- Initialisierung der Parameter: Es beginnt mit der Definition des Parameters CustomField, mit dem ein benutzerdefiniertes Feld zur Protokollierung angegeben werden kann.
- Einrichtung der Umgebung: Es prüft auf Umgebungsvariablen und richtet Registrierungspfade und Werte im Zusammenhang mit den UAC-Einstellungen ein.
- Definition der Parameter: Die Funktion Set-NinjaProperty ist definiert, um bei der Aktualisierung der benutzerdefinierten Felder in NinjaOne zu helfen. Dieser Parameter ist für MSPs, die NinjaOne für die Verwaltung von Kundensystemen verwenden, unerlässlich.
- Bestimmung der UAC-Stufe: Das Skript durchläuft dann verschiedene UAC-bezogene Registrierungseinstellungen und vergleicht sie mit Standard- oder sicheren Werten, um die UAC-Stufe des Systems zu ermitteln.
- Ausgabe und Protokollierung: Er gibt die UAC-Stufe und die Einstellungen auf der Konsole aus. Wenn der Parameter CustomField verwendet wird, protokolliert das Skript die UAC-Stufe in diesem benutzerdefinierten Feld.
- Beendigungs-Code: Zum Schluss gibt das Skript einen Beendigungs-Code zurück, der auf der ermittelten UAC-Stufe basiert.
Mögliche Anwendungsfälle
Stellen Sie sich vor, ein MSP verwaltet ein Computernetzwerk für einen Kunden. Er kann dieses Skript auf allen Rechnern einsetzen, um sicherzustellen, dass die UAC-Einstellungen auf der empfohlenen Stufe sind, und so unbefugte Änderungen verhindern, die die Sicherheit gefährden könnten.
Vergleiche
Traditionell kann die UAC-Überprüfung manuelle Kontrollen oder weniger ausgefeilte Skripte umfassen. Dieses Skript bietet einen automatisierten, detaillierten und integrierten Ansatz, insbesondere für Umgebungen, die über NinjaOne verwaltet werden.
FAQs
- Kann dieses Skript auf jeder Windows-Version ausgeführt werden?
- Es unterstützt Windows 7, Windows Server 2012 und neuere Versionen.
- Sind für die Ausführung dieses Skripts Administratorrechte erforderlich?
- Ja, es erfordert Administratorrechte, um auf die Registrierungseinstellungen zuzugreifen und sie zu ändern.
- Kann das Skript die UAC-Einstellungen ändern?
- Es ist zwar in erster Linie für Audits gedacht, kann aber erweitert werden, um Einstellungen auf der Grundlage von Audit-Ergebnissen zu ändern.
Folgen
Falsche UAC-Einstellungen können ein System anfällig für unbefugten Zugriff und die mögliche Installation von Malware machen. Dieses Skript hilft bei der Aufrechterhaltung optimaler Sicherheitskonfigurationen und minimiert so solche Risiken.
Empfehlungen
- Führen Sie das Skript regelmäßig aus, um die kontinuierliche Einhaltung der Sicherheitsstandards zu gewährleisten.
- Integrieren Sie das Skript in regelmäßige Wartungspläne für eine automatisierte Verwaltung.
- Verwenden Sie die Protokollierungsfunktion, um eine Aufzeichnung der UAC-Einstellungen für Prüfpfade zu erstellen.
Abschließende Überlegungen
Im Zusammenhang mit der Verwaltung der IT-Infrastruktur, insbesondere bei der Verwendung von NinjaOne, ist dieses PowerShell-Skript ein wertvolles Asset. Es automatisiert einen wichtigen Aspekt der Sicherheitsverwaltung und stellt sicher, dass die UAC-Einstellungen im gesamten Netzwerk eines Unternehmens auf einem optimalen Niveau für Sicherheit und Compliance bleiben. NinjaOne-Anwender:innen können besonders von den Integrationsmöglichkeiten des Skripts profitieren, was die Rolle der Plattform als umfassende Lösung für Managed-IT-Services unterstreicht.