A autenticação moderna é um recurso de segurança do Office 365 que usa o Azure Active Directory (AAD) para autenticar usuários. Ele se destaca como um farol de segurança, ofuscando os métodos de autenticação tradicionais, como a autenticação básica. O motivo? A autenticação moderna emprega criptografia mais forte e a camada adicional de autenticação de dois fatores, o que a torna um mecanismo de defesa formidável no cenário cibernético atual.
Entendendo o roteiro
Basicamente, o script foi projetado para esclarecer o status da autenticação moderna nos perfis de usuário em um ambiente do Office 365. Como ele consegue isso? Percorrendo meticulosamente cada perfil de usuário na máquina e inspecionando os valores do registro vinculados à autenticação moderna. Se ele encontrar um valor definido como 0, é um indicador claro de que a autenticação moderna está desativada para esse perfil de usuário específico.
O roteiro
#Requires -Version 5.1
<#
.SYNOPSIS
Monitors if user profiles have modern auth for Office 365 enabled or disabled.
.DESCRIPTION
Monitors if user profiles have modern auth for Office 365 enabled or disabled.
Check if HKEY_CURRENT_USERSOFTWAREMicrosoftOffice15.0CommonIdentityEnableADAL is set to 1.
Check if HKEY_CURRENT_USERSOFTWAREMicrosoftOffice16.0CommonIdentityEnableADAL is set to 0.
Returns an exit code of 1 if one user has modern auth disabled.
Returns an exit code of 0 if all user have modern auth enabled.
.EXAMPLE
No parameter needed.
.OUTPUTS
None
.NOTES
Minimum OS Architecture Supported: Windows 10, Windows Server 2016
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).
#>
[CmdletBinding()]
param ()
begin {
function Test-IsElevated {
$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object System.Security.Principal.WindowsPrincipal($id)
$p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
}
}
process {
if (-not (Test-IsElevated)) {
Write-Error -Message "Access Denied. Please run with Administrator privileges."
exit 1
}
# Loop through each user's profile
# Check if HKEY_CURRENT_USERSOFTWAREMicrosoftOffice15.0CommonIdentityEnableADAL is set to 1
# Check if HKEY_CURRENT_USERSOFTWAREMicrosoftOffice16.0CommonIdentityEnableADAL is set to 1
$Path = @("SOFTWAREMicrosoftOffice15.0CommonIdentity", "SOFTWAREMicrosoftOffice16.0CommonIdentity")
$Name = "EnableADAL"
$Script:FoundModernAuthDisabled = $false
# Get each user profile SID and Path to the profile
$UserProfiles = Get-ItemProperty -Path "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionProfileList*" |
Where-Object { $_.PSChildName -match "S-1-5-21-(d+-?){4}$" } |
Select-Object @{Name = "SID"; Expression = { $_.PSChildName } }, @{Name = "UserHive"; Expression = { "$($_.ProfileImagePath)NTuser.dat" } }, @{Name = "UserName"; Expression = { "$($_.ProfileImagePath | Split-Path -Leaf)" } }
# Loop through each profile on the machine
Foreach ($UserProfile in $UserProfiles) {
# Load User ntuser.dat if it's not already loaded
If (($ProfileWasLoaded = Test-Path -Path "Registry::HKEY_USERS$($UserProfile.SID)") -eq $false) {
Start-Process -FilePath "cmd.exe" -ArgumentList "/C reg.exe LOAD HKU$($UserProfile.SID) $($UserProfile.UserHive)" -Wait -WindowStyle Hidden
}
# Read the user's registry
$Path | ForEach-Object {
$Key = Join-Path -Path "Registry::HKEY_USERS$($UserProfile.SID)" -ChildPath $($_)
$Value = Get-ItemProperty -Path $Key -ErrorAction SilentlyContinue | Select-Object $Name -ExpandProperty $Name -ErrorAction SilentlyContinue
if (
(
$_ -like "*15.0*" -and
$Value -ne 1 -and
$(Test-Path -Path $Key -ErrorAction SilentlyContinue)
) -or
(
$_ -like "*16.0*" -and
$Value -eq 0
)
) {
Write-Host "$($UserProfile.UserName) ModernAuth is not enabled."
$Script:FoundModernAuthDisabled = $true
}
}
# Unload NTuser.dat
If ($ProfileWasLoaded -eq $false) {
[gc]::Collect()
Start-Sleep 1
Start-Process -FilePath "cmd.exe" -ArgumentList "/C reg.exe UNLOAD HKU$($UserProfile.SID)" -Wait -WindowStyle Hidden | Out-Null
}
}
if ($FoundModernAuthDisabled) {
Write-Output $false
exit 1
}
else {
Write-Output $true
exit 0
}
}
end {}
Acesse mais de 300 scripts no NinjaOne Dojo
Como os profissionais de TI podem se beneficiar
O script não é apenas uma ferramenta; é uma solução personalizada para profissionais de TI. Veja como isso pode mudar o jogo:
- Monitoramento proativo: Antes que um possível lapso de segurança se torne um problema completo, o script permite que os profissionais de TI identifiquem e resolvam as instâncias em que a autenticação moderna está desativada.
- Eficiência em sua melhor forma: O tempo é essencial em TI. O script automatiza o processo tedioso de verificar individualmente cada perfil de usuário, liberando tempo valioso.
- Clareza e direção: Não há mais suposições. O script oferece feedback claro sobre quais perfis de usuário precisam de atenção, abrindo caminho para uma correção direcionada e eficaz.
NinjaOne: Seu parceiro no gerenciamento de TI
Embora o script ofereça uma solução focada, a integração com uma plataforma abrangente de gerenciamento de TI, como o NinjaOne, amplia seus recursos. O NinjaOne oferece uma plataforma unificada que simplifica as operações de TI. Quando se trata de autenticação moderna no Office 365, o NinjaOne pode executar o script sem problemas em intervalos programados. O resultado? Alertas em tempo real para as equipes de TI sobre quaisquer discrepâncias, garantindo que a segurança não seja comprometida.
Considerações finais
No mundo em constante evolução da TI, a autenticação moderna no Office 365 não é apenas um recurso; é uma necessidade. Ao aproveitar o script discutido e integrá-lo a soluções robustas como o NinjaOne, os profissionais de TI podem fortalecer suas defesas, garantindo que suas organizações estejam sempre um passo à frente no jogo da segurança cibernética.