{"id":215495,"date":"2024-03-15T13:51:31","date_gmt":"2024-03-15T13:51:31","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=215495"},"modified":"2024-03-18T07:52:32","modified_gmt":"2024-03-18T07:52:32","slug":"fehlgeschlagene-anmeldungen-finden-windows-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/de\/script-hub\/fehlgeschlagene-anmeldungen-finden-windows-powershell\/","title":{"rendered":"So finden Sie fehlgeschlagene Anmeldeversuche in Windows mit PowerShell"},"content":{"rendered":"<p>Die Gew\u00e4hrleistung der Sicherheit von IT-Systemen ist eine wichtige Aufgabe. Die Erkennung verd\u00e4chtiger Aktivit\u00e4ten, wie z. B. mehrfache fehlgeschlagene Anmeldeversuche, ist eine wichtige Ma\u00dfnahme zur Eind\u00e4mmung potenzieller Bedrohungen. Das vorgestellte PowerShell-Skript dient als vielseitiges Tool, das IT-Experten und MSPs dabei unterst\u00fctzt, <strong>Einblicke in fehlgeschlagene Anmeldevorg\u00e4nge zu erhalten<\/strong>.<\/p>\n<h2>Hintergrund<\/h2>\n<p>Die Analyse der fehlgeschlagenen Anmeldeversuche auf einem System kann IT-Administratoren wichtige Erkenntnisse liefern. Sie k\u00f6nnen m\u00f6gliche Sicherheitsverletzungen aufdecken, das Benutzerverhalten \u00fcberwachen und die Integrit\u00e4t des Systems aufrechterhalten. Das vorgestellte PowerShell-Skript holt diese Daten effizient ab und bietet eine robuste L\u00f6sung f\u00fcr Profis. Die Bedeutung dieses Tools kann nicht \u00fcberbewertet werden. Angesichts der zunehmenden Bedrohungen f\u00fcr die Cyber-Sicherheit ist eine effiziente Methode zur Erkennung von Anomalien bei Benutzeranmeldungen f\u00fcr MSPs und IT-Experten unerl\u00e4sslich.<\/p>\n<h2>Das Skript<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 3.0 -RunAsAdministrator\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Returns the number of recent failed login attempts.\r\n.DESCRIPTION\r\n    Returns the number of recent failed login attempts of all users or of a specific user. If a user is specified then just a number is returned.\r\n.EXAMPLE\r\n    No parameters needed.\r\n    Returns all users, of the local machine, with a could of failed login attempts.\r\nOutput Example:\r\nUserName  FailedLoginAttempts\r\n--------  -------------------\r\nFred                        4\r\nBob                         0\r\n.EXAMPLE\r\n     -UserName \"Fred\"\r\n    Returns the number of failed login attempts of the user Fred on the local machine.\r\nOutput Example:\r\n4\r\n.EXAMPLE\r\n     -ComputerName \"FredPC\" -UserName \"Fred\"\r\n    Returns the number of failed login attempts of the user Fred on the computer named FredPC.\r\nOutput Example:\r\n4\r\n.EXAMPLE\r\n     -ComputerName \"FredPC\" -UserName \"Fred\" -Detailed\r\n    Returns the number of failed login attempts of the user Fred on the computer named FredPC, but will more details of each failed and successful logins.\r\nOutput Example:\r\n\r\nTimeGenerated   : 10\/18\/2019 7:52:43 AM\r\nEventID         : 4624\r\nCategory        : 12544\r\nADUsername      : Fred\r\nDomain          : FredPC\r\nUserSID         : S-1-0-0\r\nWorkstation     : -\r\nSourceIP        : -\r\nPort            : -\r\nFailureReason   : Interactive\r\nFailureStatus   : Incorrect password\r\nFailureSubStatus: Other\r\n.EXAMPLE\r\n    PS C:&gt; Monitor-Failed-Password-Attempts.ps1 -ComputerName \"FredPC\" -UserName \"Fred\"\r\n    Returns the number of failed login attempts of the user Fred on the computer named FredPC.\r\nOutput Example:\r\n4\r\n.OUTPUTS\r\n    System.Int32 Number of failed login attempts.\r\n.OUTPUTS\r\n    PSCustomObject List of user names and a count of failed login attempts.\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 7, Windows Server 2012\r\n    If ComputerName is specified, then be sure that the computer that this script is running on has network and permissions to access the Event Log on the remote computer.\r\n    Release Notes:\r\n    Initial Release\r\nBy 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.\r\n    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. \r\n    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. \r\n    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. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, 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. \r\n    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. \r\n    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. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n.COMPONENT\r\n    ManageUsers\r\n#&gt;\r\n\r\nparam (\r\n    # The name of a remote computer to get event logs for failed logins\r\n    [Parameter(Mandatory = $false)]\r\n    [String]\r\n    $ComputerName = [System.Net.Dns]::GetHostName(),\r\n    # A username\r\n    [Parameter(Mandatory = $false)]\r\n    [String]\r\n    $UserName,\r\n    # Returns all relevant events, sorted by TimeGenerated\r\n    [Switch]\r\n    $Detailed\r\n)\r\n\r\n# Support functions\r\n# Returns the matching FailureReason like Incorrect password\r\nfunction Get-FailureReason {\r\n    Param($FailureReason)\r\n    switch ($FailureReason) {\r\n        '0xC0000064' { \"Account does not exist\"; break; }\r\n        '0xC000006A' { \"Incorrect password\"; break; }\r\n        '0xC000006D' { \"Incorrect username or password\"; break; }\r\n        '0xC000006E' { \"Account restriction\"; break; }\r\n        '0xC000006F' { \"Invalid logon hours\"; break; }\r\n        '0xC000015B' { \"Logon type not granted\"; break; }\r\n        '0xc0000070' { \"Invalid Workstation\"; break; }\r\n        '0xC0000071' { \"Password expired\"; break; }\r\n        '0xC0000072' { \"Account disabled\"; break; }\r\n        '0xC0000133' { \"Time difference at DC\"; break; }\r\n        '0xC0000193' { \"Account expired\"; break; }\r\n        '0xC0000224' { \"Password must change\"; break; }\r\n        '0xC0000234' { \"Account locked out\"; break; }\r\n        '0x0' { \"0x0\"; break; }\r\n        default { \"Other\"; break; }\r\n    }\r\n}\r\nfunction Get-LogonType {\r\n    Param($LogonType)\r\n    switch ($LogonType) {\r\n        '0' { 'Interactive'; break; }\r\n        '2' { 'Interactive'; break; }\r\n        '3' { 'Network'; break; }\r\n        '4' { 'Batch'; break; }\r\n        '5' { 'Service'; break; }\r\n        '6' { 'Proxy'; break; }\r\n        '7' { 'Unlock'; break; }\r\n        '8' { 'Networkcleartext'; break; }\r\n        '9' { 'NewCredentials'; break; }\r\n        '10' { 'RemoteInteractive'; break; }\r\n        '11' { 'CachedInteractive'; break; }\r\n        '12' { 'CachedRemoteInteractive'; break; }\r\n        '13' { 'CachedUnlock'; break; }\r\n        Default {}\r\n    }\r\n}\r\n#-Newest $Records\r\n$Events = Get-EventLog -ComputerName $ComputerName -LogName 'security' -InstanceId 4625, 4624 | Sort-Object -Property TimeGenerated | ForEach-Object {\r\n    if ($_.InstanceId -eq 4625) {\r\n        $_ | Select-Object -Property @(\r\n            @{Label = 'TimeGenerated'; Expression = { $_.TimeGenerated } },\r\n            @{Label = 'EventID'; Expression = { $_.InstanceId } },\r\n            @{Label = 'Category'; Expression = { $_.CategoryNumber } },\r\n            @{Label = 'Username'; Expression = { $_.ReplacementStrings[5] } },\r\n            @{Label = 'Domain'; Expression = { $_.ReplacementStrings[6] } },\r\n            @{Label = 'UserSID'; Expression = { (($_.Message -Split 'rn' | Select-String 'Security ID')[1] -Split 's+')[3] } },\r\n            # @{Label = 'UserSID'; Expression = { $_.ReplacementStrings[0] } },\r\n            @{Label = 'Workstation'; Expression = { $_.ReplacementStrings[13] } },\r\n            @{Label = 'SourceIP'; Expression = { $_.ReplacementStrings[19] } },\r\n            @{Label = 'Port'; Expression = { $_.ReplacementStrings[20] } },\r\n            @{Label = 'LogonType'; Expression = { $_.ReplacementStrings[8] } },\r\n            @{Label = 'FailureStatus'; Expression = { Get-FailureReason($_.ReplacementStrings[7]) } },\r\n            @{Label = 'FailureSubStatus'; Expression = { Get-FailureReason($_.ReplacementStrings[9]) } }\r\n        )\r\n    }\r\n    elseif ($_.InstanceId -eq 4624 -and (Get-LogonType($_.ReplacementStrings[8])) -notlike 'Service') {\r\n        $_ | Select-Object -Property @(\r\n            @{Label = 'TimeGenerated'; Expression = { $_.TimeGenerated } },\r\n            @{Label = 'EventID'; Expression = { $_.InstanceId } },\r\n            @{Label = 'Category'; Expression = { $_.CategoryNumber } },\r\n            @{Label = 'Username'; Expression = { $_.ReplacementStrings[5] } },\r\n            @{Label = 'Domain'; Expression = { $_.ReplacementStrings[6] } },\r\n            @{Label = 'UserSID'; Expression = { $_.ReplacementStrings[0] } },\r\n            @{Label = 'Workstation'; Expression = { $_.ReplacementStrings[11] } },\r\n            @{Label = 'SourceIP'; Expression = { $_.ReplacementStrings[18] } },\r\n            @{Label = 'Port'; Expression = { $_.ReplacementStrings[19] } },\r\n            @{Label = 'LogonType'; Expression = { Get-LogonType($_.ReplacementStrings[8]) } },\r\n            @{Label = 'LogonID'; Expression = { Get-FailureReason($_.ReplacementStrings[7]) } },\r\n            @{Label = 'LogonProcess'; Expression = { Get-FailureReason($_.ReplacementStrings[9]) } }\r\n        )\r\n    }\r\n}\r\n\r\nif ($Detailed) {\r\n    if ($UserName) {\r\n        $Events | Where-Object {\r\n            $_.Username -like $UserName\r\n        }\r\n    }\r\n    else {\r\n        $Events | Where-Object {\r\n            $_.Username -notlike \"DWM*\" -and\r\n            $_.Username -notlike \"UMFD*\" -and\r\n            $_.Username -notlike \"SYSTEM\"\r\n        }\r\n    }\r\n}\r\nelse {\r\n    $UserNames = if ($UserName) {\r\n        ($Events | Select-Object -Property Username -Unique).Username | Where-Object {\r\n            $_ -like \"$UserName\"\r\n        }\r\n    }\r\n    else {\r\n        ($Events | Select-Object -Property Username -Unique).Username | Where-Object {\r\n            $_ -notlike \"DWM*\" -and\r\n            $_ -notlike \"UMFD*\" -and\r\n            $_ -notlike \"SYSTEM\"\r\n        }\r\n    }\r\n    \r\n    $UserNames | ForEach-Object {\r\n        $CurrentUserName = $_\r\n        $FailedLoginCount = 0\r\n        for ($i = 0; $i -lt $Events.Count; $i++) {\r\n            if ($Events[$i].EventID -eq 4625 -and $Events[$i].Username -like $CurrentUserName) {\r\n                # User failed to login X times\r\n                # Count the number of failed logins\r\n                $FailedLoginCount++\r\n            }\r\n            elseif ($Events[$i].EventID -eq 4624 -and $Events[$i].Username -like $CurrentUserName) {\r\n                # User logged in successfully\r\n                # Reset the number of failed logins to 0\r\n                $FailedLoginCount = 0\r\n            }\r\n        }\r\n        if ($UserName) {\r\n            # If a UserName was specified, then return only the failed login count\r\n            $FailedLoginCount\r\n        }\r\n        else {\r\n            # If no UserName was specified, then return the user name and failed login count\r\n            [PSCustomObject]@{\r\n                UserName            = $CurrentUserName\r\n                FailedLoginAttempts = $FailedLoginCount\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Zugriff auf \u00fcber 300 Skripte im NinjaOne Dojo<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/de\/kostenlosetestversionformular\/\">Zugang erhalten<\/a><\/p>\n<\/div>\n<h2>Detaillierte Aufschl\u00fcsselung des Skripts<\/h2>\n<p>Grundlegend holt das Skript Daten aus den Ereignisprotokollen eines bestimmten Computers, wobei es auf bestimmte Ereignis-IDs abzielt, die fehlgeschlagene und erfolgreiche Anmeldeversuche darstellen.<\/p>\n<ul>\n<li><strong>Parameter<\/strong>: Das Skript beginnt mit der Definition von Parametern wie <strong>ComputerName<\/strong>, <strong>UserName<\/strong> und <strong>Detailed<\/strong>. Damit kann der Benutzer den Rechner, den Benutzer und die Detailstufe f\u00fcr die Anmeldeversuche angeben.<\/li>\n<li><strong>Funktionen<\/strong>: Zwei Funktionen, <strong>Get-FailureReason<\/strong> und <strong>Get-LogonType<\/strong>, \u00fcbersetzen kodierte Informationen aus den Ereignisprotokollen in menschenlesbare Daten \u00fcber die Art der Anmeldung und den Grund f\u00fcr eine fehlgeschlagene Anmeldung.<\/li>\n<li><strong>Ereignisse abrufen<\/strong>: Das Skript holt dann die Ereignisprotokolle ab und filtert sie, so dass nur die notwendigen Informationen erhalten bleiben. Dazu m\u00fcssen die Instanzen mit den entsprechenden Ereignis-IDs ausgew\u00e4hlt werden.<\/li>\n<li><strong>Verarbeitung<\/strong>: Je nachdem, ob detaillierte Daten angefordert werden, liefert das Skript entweder eine umfassende Aufschl\u00fcsselung der einzelnen Anmeldeversuche oder eine Zusammenfassung der fehlgeschlagenen Versuche f\u00fcr jeden Benutzer.<\/li>\n<\/ul>\n<h2>Potenzielle Anwendungsf\u00e4lle<\/h2>\n<p>Stellen Sie sich einen IT-Administrator in einem mittelst\u00e4ndischen Unternehmen vor. In letzter Zeit hat die IT-Abteilung einen sprunghaften Anstieg in der Zahl der fehlgeschlagenen Anmeldeversuche festgestellt, insbesondere w\u00e4hrend der arbeitsfreien Zeit. Mit Hilfe des Skripts kann der Administrator schnell \u00fcberpr\u00fcfen, welche Benutzer wie oft fehlgeschlagene Anmeldeversuche hatten. Die Feststellung, dass ein einzelnes Benutzerkonto innerhalb kurzer Zeit mehrere Fehlversuche aufwies, lie\u00df den Schluss zu, dass dieses Konto m\u00f6glicherweise kompromittiert worden war. Auf diese Weise hilft das Skript bei der fr\u00fchzeitigen Erkennung und sofortigen Behebung.<\/p>\n<h2>Alternative Herangehensweise<\/h2>\n<p>Es gibt mehrere Methoden, um fehlgeschlagene Anmeldeversuche zu verfolgen. Mit der in Windows integrierten Sicherheits\u00fcberpr\u00fcfung k\u00f6nnen Sie beispielsweise die Sicherheitsprotokolle \u00fcber die Ereignisanzeige einsehen. Dieser Ansatz ist zwar einfach, kann aber zeitaufw\u00e4ndig sein. Unser PowerShell-Skript optimiert den Prozess und bietet eine effizientere und anpassbare L\u00f6sung.<\/p>\n<h2>FAQs<\/h2>\n<ul>\n<li>Wie erkennt das Skript ein fehlgeschlagenes Anmeldeereignis?<br \/>\nDas Skript sucht nach bestimmten Ereignis-IDs im Ereignisprotokoll, z. B. 4625 f\u00fcr fehlgeschlagene Anmeldungen.<\/li>\n<li>Kann ich Daten von einem entfernten Rechner abrufen?<br \/>\nJa, durch Angabe des Parameters <strong>ComputerName<\/strong> k\u00f6nnen Sie Daten von einem entfernten Computer abrufen.<\/li>\n<\/ul>\n<h2>Auswirkungen<\/h2>\n<p>Wenn IT-Administratoren die Anzahl der fehlgeschlagenen Anmeldeversuche kennen, k\u00f6nnen sie potenziellen Sicherheitsverletzungen zuvorkommen. Anomalien in den Anmeldemustern sind oft ein fr\u00fches Anzeichen f\u00fcr b\u00f6sartige Aktivit\u00e4ten. Indem sie auf diese Daten reagieren, k\u00f6nnen Fachleute ihre Systeme gegen potenzielle Bedrohungen verst\u00e4rken.<\/p>\n<h2>Empfehlungen<\/h2>\n<ul>\n<li>Vergewissern Sie sich, dass Sie \u00fcber die erforderlichen Berechtigungen zum Abrufen von Ereignisprotokollen verf\u00fcgen.<\/li>\n<li>F\u00fchren Sie das Skript regelm\u00e4\u00dfig aus, insbesondere bei Systemen mit sensiblen Daten.<\/li>\n<li>Untersuchen Sie alle Muster von fehlgeschlagenen Anmeldungen und benachrichtigen Sie die betroffenen Benutzer.<\/li>\n<\/ul>\n<h2>Abschlie\u00dfende \u00dcberlegungen<\/h2>\n<p>In Zeiten zunehmender Cyber-Bedrohungen sind Tools wie unser PowerShell-Skript unverzichtbar. F\u00fcr eine umfassende Sicherheitsl\u00f6sung k\u00f6nnen Plattformen wie NinjaOne integriert werden, die eine <a href=\"https:\/\/www.ninjaone.com\/de\/endpunkt-verwaltung\/fernsteuerung-und-alarmierung\/\">\u00dcberwachung und Verwaltung in Echtzeit<\/a> gew\u00e4hrleisten. NinjaOne bietet in Verbindung mit proaktiven Skripten wie dem hier beschriebenen zus\u00e4tzlichen Schutz vor Cyber-Bedrohungen.<\/p>\n","protected":false},"author":35,"featured_media":142609,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4309],"class_list":["post-215495","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub\/215495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/comments?post=215495"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/media?parent=215495"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/operating_system?post=215495"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/use_cases?post=215495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}