<# : Co-CISO Windows security check __CC_VERSION__ - READ-ONLY. Double-click to run. @echo off title Co-CISO security check net session >nul 2>&1 if %errorlevel% neq 0 ( echo. echo Co-CISO needs administrator rights to READ your security settings. echo Click "Yes" in the next window. Nothing will be changed. echo. powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -WorkingDirectory '%~dp0' -Verb RunAs" exit /b ) set "CCDIR=%~dp0" set "CCSELF=%~f0" powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ([IO.File]::ReadAllText($env:CCSELF))" echo. pause exit /b #> # ------------------------------------------------------------------------------------------------ # Co-CISO Windows security check. READ-ONLY: it reads settings and writes ONE report file (HTML) # next to itself. It installs nothing, changes nothing, sends nothing and stores no passwords. # Published by Co-CISO ยท Template source: https://co-ciso.online/collectors/templates/ # ------------------------------------------------------------------------------------------------ $ErrorActionPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue' Write-Host '' Write-Host ' Co-CISO - __CC_MSG_RUNNING__' -ForegroundColor Cyan function Hide([string]$s) { if (-not $s) { return $s } $sha = [System.Security.Cryptography.SHA256]::Create() return 'user-' + ([BitConverter]::ToString($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes($s.ToLower()))) -replace '-', '').Substring(0, 8).ToLower() } function Try-Get($block) { try { & $block } catch { $null } } $os = Get-CimInstance Win32_OperatingSystem $cs = Get-CimInstance Win32_ComputerSystem $out = [ordered]@{ co_ciso_collector = 'windows'; version = '__CC_VERSION__'; collected_at = (Get-Date).ToUniversalTime().ToString('o') host = [ordered]@{ name = Hide $env:COMPUTERNAME; os = $os.Caption; os_version = $os.Version; build = $os.BuildNumber display_version = (Try-Get { (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').DisplayVersion }) model = "$($cs.Manufacturer) $($cs.Model)".Trim() domain_joined = [bool]$cs.PartOfDomain; is_server = ($os.ProductType -ne 1) last_boot = $os.LastBootUpTime.ToUniversalTime().ToString('o') } } $hf = Get-HotFix | Where-Object { $_.InstalledOn } | Sort-Object InstalledOn -Descending | Select-Object -First 1 $out.patching = [ordered]@{ last_update = if ($hf) { $hf.InstalledOn.ToString('yyyy-MM-dd') } else { $null }; last_kb = $hf.HotFixID } $mp = Get-MpComputerStatus $av = Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntiVirusProduct $out.antivirus = [ordered]@{ products = @($av | ForEach-Object { $_.displayName }) defender_enabled = $mp.AntivirusEnabled; realtime = if ($mp -and $null -ne $mp.RealTimeProtectionEnabled) { [bool]$mp.RealTimeProtectionEnabled } else { $null }; tamper_protection = $mp.IsTamperProtected signature_age_days = $mp.AntivirusSignatureAge } $out.bitlocker = @(Get-BitLockerVolume | ForEach-Object { [ordered]@{ volume = $_.MountPoint; protection = "$($_.ProtectionStatus)"; method = "$($_.EncryptionMethod)" } }) $out.firewall = @(Get-NetFirewallProfile | ForEach-Object { [ordered]@{ profile = $_.Name; enabled = [bool]$_.Enabled; inbound_default = "$($_.DefaultInboundAction)" } }) $out.local_admins = @(Get-LocalGroupMember -SID 'S-1-5-32-544' | ForEach-Object { [ordered]@{ name = Hide $_.Name; type = "$($_.ObjectClass)"; source = "$($_.PrincipalSource)" } }) $smb1 = Try-Get { (Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol).State } $rdp = Try-Get { (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server').fDenyTSConnections } $nla = Try-Get { (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp').UserAuthentication } $uac = Try-Get { (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').EnableLUA } $llmnr = Try-Get { (Get-ItemProperty 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient').EnableMulticast } $ps2 = Try-Get { (Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root).State } $laps = (Test-Path 'HKLM:\SOFTWARE\Microsoft\Policies\LAPS') -or (Test-Path 'HKLM:\SOFTWARE\Policies\Microsoft Services\AdmPwd') $lock = Try-Get { (Get-ItemProperty 'HKCU:\Control Panel\Desktop').ScreenSaveTimeOut } $out.settings = [ordered]@{ smb1 = "$smb1"; rdp_enabled = if ($null -ne $rdp) { $rdp -eq 0 } else { $null }; rdp_nla = if ($null -ne $nla) { $nla -eq 1 } else { $null }; uac = if ($null -ne $uac) { $uac -ne 0 } else { $null } llmnr_disabled = ($llmnr -eq 0); powershell_v2 = "$ps2"; laps = $laps autorun_disabled = ((Try-Get { (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer').NoDriveTypeAutoRun }) -eq 255) screen_lock_seconds = $lock } # Password policy is read from the exported local security policy: numeric keys are the same on every Windows language. $secpol = Join-Path $env:TEMP ("cc-secpol-{0}.inf" -f $PID) $pwPolicy = [ordered]@{ min_length = $null; lockout_threshold = $null; max_age_days = $null } try { & secedit /export /cfg $secpol /areas SECURITYPOLICY | Out-Null if (Test-Path $secpol) { $ini = Get-Content $secpol -Raw foreach ($k in @(@('MinimumPasswordLength', 'min_length'), @('LockoutBadCount', 'lockout_threshold'), @('MaximumPasswordAge', 'max_age_days'))) { if ($ini -match ('(?m)^\s*' + $k[0] + '\s*=\s*(-?\d+)')) { $pwPolicy[$k[1]] = [int]$Matches[1] } } } } catch { } Remove-Item $secpol -Force -ErrorAction SilentlyContinue $out.password_policy = $pwPolicy $out.listening = @(Get-NetTCPConnection -State Listen | Where-Object { $_.LocalAddress -notin @('127.0.0.1', '::1') } | Sort-Object LocalPort -Unique | Select-Object -First 80 | ForEach-Object { [ordered]@{ port = $_.LocalPort; address = $_.LocalAddress; process = (Get-Process -Id $_.OwningProcess).ProcessName } }) # Passive local inventory only: no ping sweep, port scan, packet capture or process command lines. # Network map: default gateways, DNS servers, shared folders, Wi-Fi name and the directory server this PC uses. $gw = @(Try-Get { Get-NetRoute -DestinationPrefix '0.0.0.0/0' -ErrorAction SilentlyContinue | Select-Object -First 8 | ForEach-Object { [ordered]@{ gateway = $_.NextHop; interface = $_.InterfaceAlias } } }) $dns = @(Try-Get { Get-DnsClientServerAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.ServerAddresses } | Select-Object -First 16 | ForEach-Object { [ordered]@{ interface = $_.InterfaceAlias; servers = @($_.ServerAddresses) } } }) $shares = @(Try-Get { Get-SmbShare -ErrorAction SilentlyContinue | Where-Object { -not $_.Special } | Select-Object -First 50 | ForEach-Object { [ordered]@{ name = $_.Name; path = "$($_.Path)" } } }) $ssid = Try-Get { $w = netsh wlan show interfaces; $m = $w | Select-String -Pattern '^\s*SSID\s*:\s*(.+)$' | Select-Object -First 1; if ($m) { $m.Matches[0].Groups[1].Value.Trim() } } $out.network = [ordered]@{ interfaces = @(Try-Get { Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' } | Select-Object -First 32 | ForEach-Object { [ordered]@{ interface = $_.InterfaceAlias; address = $_.IPAddress; prefix = $_.PrefixLength } } }) gateways = $gw dns = $dns shares = $shares wifi_ssid = "$ssid" logon_server = ("$($env:LOGONSERVER)" -replace '^\\+', '') dns_domain = "$($env:USERDNSDOMAIN)" neighbors = @(Try-Get { Get-NetNeighbor -AddressFamily IPv4 | Where-Object { $_.State -notin @('Unreachable','Incomplete') -and $_.IPAddress -notmatch '^(224\.|239\.|255\.)' } | Select-Object -First 256 | ForEach-Object { [ordered]@{ address = $_.IPAddress; state = "$($_.State)" } } }) } $out.services = @(Try-Get { Get-CimInstance Win32_Service | Where-Object { $_.State -eq 'Running' } | Select-Object -First 250 | ForEach-Object { [ordered]@{ name = $_.Name; state = $_.State; start_mode = $_.StartMode } } }) $out.collection_scope = 'This device, its backup and update settings, permitted directory records, shared folders, saved Wi-Fi name and cached neighbors only; not a complete network scan.' $keys = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' $out.software = @(Get-ItemProperty $keys | Where-Object { $_.DisplayName -and -not $_.SystemComponent } | Sort-Object DisplayName -Unique | Select-Object -First 400 | ForEach-Object { [ordered]@{ name = $_.DisplayName; version = $_.DisplayVersion; publisher = $_.Publisher } }) # Backups: Windows Server Backup summary, Volume Shadow Copies, File History and the newest restore point. $wb = Try-Get { Get-WBSummary } $shadows = @(Try-Get { Get-CimInstance Win32_ShadowCopy | Where-Object { $_ } }) $shadowLatest = ($shadows | Sort-Object InstallDate -Descending | Select-Object -First 1).InstallDate $shadowIso = $null if ($shadowLatest) { try { $shadowIso = ([System.Management.ManagementDateTimeConverter]::ToDateTime("$shadowLatest")).ToUniversalTime().ToString('o') } catch { $shadowIso = $null } } $fhTask = "$(Try-Get { (Get-ScheduledTask -TaskPath '\Microsoft\Windows\FileHistory\*' -ErrorAction SilentlyContinue).State })" $restore = Try-Get { (Get-ComputerRestorePoint | Sort-Object CreationTime -Descending | Select-Object -First 1).CreationTime } $out.backup = [ordered]@{ shadow_copies = $shadows.Count latest_shadow = $shadowIso file_history = $fhTask last_restore_point = if ($restore) { $restore.ToUniversalTime().ToString('o') } else { $null } last_backup = if ($wb -and $wb.LastSuccessfulBackupTime) { $wb.LastSuccessfulBackupTime.ToUniversalTime().ToString('o') } else { $null } last_result = if ($wb) { "$($wb.LastBackupResultHR)" } else { $null } next_backup = if ($wb -and $wb.NextBackupTime) { $wb.NextBackupTime.ToUniversalTime().ToString('o') } else { $null } } # Update policy: how updates are delivered (Windows Update, WSUS, Intune / MDM) and any deferrals set by policy. $au = Try-Get { Get-ItemProperty 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' } $wu = Try-Get { Get-ItemProperty 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' } $mdm = @(Try-Get { Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Enrollments' -ErrorAction SilentlyContinue | Where-Object { $_ -and (Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue).ProviderID } }) $out.update_policy = [ordered]@{ auto_update_disabled = if ($null -ne $au -and $null -ne $au.NoAutoUpdate) { [bool]$au.NoAutoUpdate } else { $null } au_options = if ($null -ne $au -and $null -ne $au.AUOptions) { [int]$au.AUOptions } else { $null } wsus_server = "$($wu.WUServer)" target_group = "$($wu.TargetGroup)" defer_quality_days = if ($null -ne $wu -and $null -ne $wu.DeferQualityUpdatesPeriodInDays) { [int]$wu.DeferQualityUpdatesPeriodInDays } else { $null } defer_feature_days = if ($null -ne $wu -and $null -ne $wu.DeferFeatureUpdatesPeriodInDays) { [int]$wu.DeferFeatureUpdatesPeriodInDays } else { $null } managed = [bool]($mdm.Count -gt 0 -or $wu.WUServer) service_start_mode = "$(Try-Get { (Get-Service wuauserv).StartType })" } if (Get-Module -ListAvailable ActiveDirectory) { Import-Module ActiveDirectory $cut = (Get-Date).AddDays(-90) $users = Get-ADUser -Filter 'Enabled -eq $true' -Properties LastLogonDate, PasswordNeverExpires if ($users) { $krb = Get-ADUser krbtgt -Properties PasswordLastSet $out.active_directory = [ordered]@{ domain_admins = (Get-ADGroupMember 'Domain Admins' -Recursive | Measure-Object).Count enterprise_admins = (Get-ADGroupMember 'Enterprise Admins' -Recursive | Measure-Object).Count enabled_users = ($users | Measure-Object).Count stale_90d = ($users | Where-Object { $_.LastLogonDate -and $_.LastLogonDate -lt $cut } | Measure-Object).Count password_never_expires = ($users | Where-Object PasswordNeverExpires | Measure-Object).Count krbtgt_password_age_days = if ($krb.PasswordLastSet) { [int]((Get-Date) - $krb.PasswordLastSet).TotalDays } else { $null } functional_level = "$((Get-ADDomain).DomainMode)" domain_controllers = @(Try-Get { Get-ADDomainController -Filter * | Measure-Object }).Count computers = @(Try-Get { Get-ADComputer -Filter * -ResultSetSize 1000 -Properties OperatingSystem,OperatingSystemVersion,Enabled | ForEach-Object { [ordered]@{ name = Hide $_.Name; os = $_.OperatingSystem; version = $_.OperatingSystemVersion; enabled = $_.Enabled } } }) } } } $json = $out | ConvertTo-Json -Depth 6 -Compress $b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($json)) $head = @' __CC_HEAD__ '@ $tail = @' __CC_TAIL__ '@ $dir = if ($env:CCDIR) { $env:CCDIR } else { [Environment]::GetFolderPath('Desktop') } $file = Join-Path $dir ("Co-CISO-Report-Windows-{0}.html" -f (Get-Date -Format 'yyyyMMdd-HHmm')) [IO.File]::WriteAllText($file, $head + $b64 + $tail, (New-Object Text.UTF8Encoding $false)) Write-Host '' Write-Host ' __CC_MSG_DONE__' -ForegroundColor Green Write-Host " $file" Write-Host '' Write-Host ' __CC_MSG_UPLOAD__' -ForegroundColor Yellow Start-Process $file Start-Process explorer.exe "/select,`"$file`""