Bilgisayarları Windows Active Directory Etki Alanına Katma
Kurumsal ağlarda, bilgisayarları bir Windows Active Directory etki alanına (d...
 
        # MSOnline modülünü yükleyin (eğer yüklü değilse) if (-not (Get-Module -ListAvailable -Name MSOnline)) { Install-Module -Name MSOnline -Force -AllowClobber } # Microsoft Entra ID'ye bağlanın Connect-MsolService # Tüm kullanıcıların MFA durumunu alın $users = Get-MsolUser -All | Select-Object DisplayName, UserPrincipalName, @{ Name = "MFA Durumu"; Expression = { if ($_.StrongAuthenticationRequirements.State -ne $null) { $_.StrongAuthenticationRequirements.State } else { "Devre Dışı" } } } # Sonuçları görüntüleyin $users | Format-Table -AutoSize # CSV olarak dışa aktarın $users | Export-Csv -Path "MFA_Durumu_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation -Encoding UTF8 # Microsoft.Graph.Identity.SignIns modülünü yükleyin if (-not (Get-Module -ListAvailable -Name Microsoft.Graph.Identity.SignIns)) { Install-Module Microsoft.Graph.Identity.SignIns -Force } # Microsoft Graph'e bağlanın Connect-MgGraph -Scopes "User.Read.All", "UserAuthenticationMethod.Read.All" # Tüm kullanıcıları alın $users = Get-MgUser -All -Property DisplayName, UserPrincipalName, Id $userAuthMethods = @() foreach ($user in $users) { # Kullanıcının kimlik doğrulama yöntemlerini al $authMethods = Get-MgUserAuthenticationMethod -UserId $user.Id # MFA yöntemlerini say $authenticatorApp = ($authMethods | Where-Object { $_.AdditionalProperties -eq "#microsoft.graph.microsoftAuthenticatorAuthenticationMethod" }).Count $phoneAuth = ($authMethods | Where-Object { $_.AdditionalProperties -eq "#microsoft.graph.phoneAuthenticationMethod" }).Count $fido2Key = ($authMethods | Where-Object { $_.AdditionalProperties -eq "#microsoft.graph.fido2AuthenticationMethod" }).Count $softwareTotp = ($authMethods | Where-Object { $_.AdditionalProperties -eq "#microsoft.graph.softwareOathAuthenticationMethod" }).Count # MFA durumunu belirle $mfaStatus = if (($authenticatorApp + $phoneAuth + $fido2Key + $softwareTotp) -gt 0) { "Etkin" } else { "Devre Dışı" } # Sonuç nesnesini oluştur $userAuthMethods += @{ DisplayName = $user.DisplayName UserPrincipalName = $user.UserPrincipalName MFADurumu = $mfaStatus MicrosoftAuthenticator = $authenticatorApp -gt 0 TelefonDoğrulama = $phoneAuth -gt 0 FIDO2GüvenlikAnahtarı = $fido2Key -gt 0 YazılımTOTP = $softwareTotp -gt 0 KayıtlıYöntemSayısı = ($authenticatorApp + $phoneAuth + $fido2Key + $softwareTotp) } } # Sonuçları görüntüle $userAuthMethods | Format-Table -AutoSize # CSV olarak dışa aktar $userAuthMethods | Export-Csv -Path "Detaylı_MFA_Raporu_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation -Encoding UTF8 GET https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,id GET https://graph.microsoft.com/v1.0/users/{userId}/authentication/methods # Gerekli modülleri içe aktar Import-Module MSOnline # Bağlan Connect-MsolService # MFA durumunu al $report = @() Get-MsolUser -All | ForEach-Object { $user = $_ $mfaMethods = $user.StrongAuthenticationMethods $mfaEnabled = $user.StrongAuthenticationRequirements.Count -gt 0 $defaultMethod = ($mfaMethods | Where-Object { $_.IsDefault -eq $true }).MethodType $report += @{ Kullanıcı = $user.DisplayName UPN = $user.UserPrincipalName MFADurumu = if ($mfaEnabled) { "Etkin" } else { "Devre Dışı" } VarsayılanYöntem = if ($defaultMethod) { $defaultMethod } else { "Yok" } KayıtlıYöntemSayısı = $mfaMethods.Count SonGirişTarihi = $user.LastPasswordChangeTimestamp } } # Sonuçları görüntüle ve dışa aktar $report | Format-Table -AutoSize $report | Export-Csv -Path "MFA_Durum_Raporu.csv" -NoTypeInformation -Encoding UTF8 # Microsoft Graph modüllerini içe aktar Import-Module Microsoft.Graph.Authentication Import-Module Microsoft.Graph.Identity.SignIns Import-Module Microsoft.Graph.Users # Microsoft Graph'e bağlan Connect-MgGraph -Scopes "User.Read.All", "UserAuthenticationMethod.Read.All", "Directory.Read.All" # Kullanıcıları al $users = Get-MgUser -All -Property DisplayName, UserPrincipalName, Id, AccountEnabled, AssignedLicenses $detailedReport = @() foreach ($user in $users) { # Yalnızca etkin hesaplar için if ($user.AccountEnabled) { # Kullanıcının kimlik doğrulama yöntemlerini al $authMethods = Get-MgUserAuthenticationMethod -UserId $user.Id # Kayıtlı yöntemleri belirle $methodTypes = @() $mfaCapable = $false foreach ($method in $authMethods) { $oDataType = $method.AdditionalProperties switch ($oDataType) { "#microsoft.graph.microsoftAuthenticatorAuthenticationMethod" { $methodTypes += "Microsoft Authenticator" $mfaCapable = $true } "#microsoft.graph.phoneAuthenticationMethod" { $methodTypes += "Telefon" $mfaCapable = $true } "#microsoft.graph.passwordAuthenticationMethod" { $methodTypes += "Parola" } "#microsoft.graph.fido2AuthenticationMethod" { $methodTypes += "FIDO2 Güvenlik Anahtarı" $mfaCapable = $true } "#microsoft.graph.softwareOathAuthenticationMethod" { $methodTypes += "Yazılım TOTP" $mfaCapable = $true } "#microsoft.graph.windowsHelloForBusinessAuthenticationMethod" { $methodTypes += "Windows Hello for Business" $mfaCapable = $true } "#microsoft.graph.emailAuthenticationMethod" { $methodTypes += "E-posta" $mfaCapable = $true } } } # Yöntemler için konsolide edilmiş bir dize oluştur $methodsString = if ($methodTypes.Count -gt 0) { $methodTypes -join ", " } else { "Yok" } # Kullanıcı türünü belirle $isMember = $null -ne ($user.AssignedLicenses) -and $user.AssignedLicenses.Count -gt 0 # Rapor nesnesini oluştur $detailedReport += @{ DisplayName = $user.DisplayName UserPrincipalName = $user.UserPrincipalName MFADurumu = if ($mfaCapable) { "Etkin" } else { "Devre Dışı" } KayıtlıYöntemler = $methodsString YöntemSayısı = $methodTypes.Count KullanıcıTürü = if ($isMember) { "Lisanslı Kullanıcı" } else { "Misafir/Lisanssız" } } } } # Sonuçları görüntüle $detailedReport | Format-Table -AutoSize # CSV olarak dışa aktar $detailedReport | Export-Csv -Path "Detaylı_MFA_Raporu_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation -Encoding UTF8 # Microsoft Graph modüllerini içe aktar Import-Module Microsoft.Graph.Authentication Import-Module Microsoft.Graph.Identity.SignIns # Microsoft Graph'e bağlan Connect-MgGraph -Scopes "Policy.Read.All", "Directory.Read.All" # Koşullu erişim politikalarını al $policies = Get-MgIdentityConditionalAccessPolicy # MFA gerektiren politikaları filtrele $mfaPolicies = $policies | Where-Object { $_.State -eq "enabled" -and ($_.GrantControls.BuiltInControls -contains "mfa" -or $_.GrantControls.TermsOfUse -ne $null -or $_.GrantControls.AuthenticationStrength.Id -ne $null) } $caReport = @() foreach ($policy in $mfaPolicies) { # Politika kapsamındaki kullanıcıları belirle $includeUsers = if ($policy.Conditions.Users.IncludeUsers -contains "All") { "Tüm kullanıcılar" } elseif ($policy.Conditions.Users.IncludeUsers.Count -gt 0) { "Seçili kullanıcılar: $($policy.Conditions.Users.IncludeUsers.Count)" } elseif ($policy.Conditions.Users.IncludeGroups.Count -gt 0) { "Seçili gruplar: $($policy.Conditions.Users.IncludeGroups.Count)" } elseif ($policy.Conditions.Users.IncludeRoles.Count -gt 0) { "Seçili roller: $($policy.Conditions.Users.IncludeRoles.Count)" } else { "Belirtilmemiş" } # Hariç tutulan kullanıcıları belirle $excludeUsers = if ($policy.Conditions.Users.ExcludeUsers.Count -gt 0 -or $policy.Conditions.Users.ExcludeGroups.Count -gt 0 -or $policy.Conditions.Users.ExcludeRoles.Count -gt 0) { "Evet" } else { "Hayır" } # Doğrulama türünü belirle $authType = if ($policy.GrantControls.BuiltInControls -contains "mfa") { "Standart MFA" } elseif ($policy.GrantControls.AuthenticationStrength.Id -ne $null) { "Kimlik Doğrulama Gücü" } else { "Diğer" } # Rapor nesnesini oluştur $caReport += @{ PolitikaAdı = $policy.DisplayName PolitikaDurumu = $policy.State DahilKullanıcılar = $includeUsers HariçTutulanKullanıcılar = $excludeUsers MFATürü = $authType UygulamalarKapsamı = if ($policy.Conditions.Applications.IncludeApplications -contains "All") { "Tüm uygulamalar" } else { "Seçili uygulamalar" } OluşturmaTarihi = $policy.CreatedDateTime SonGüncellemeTarihi = $policy.ModifiedDateTime } } # Sonuçları görüntüle $caReport | Format-Table -AutoSize # CSV olarak dışa aktar $caReport | Export-Csv -Path "Koşullu_Erişim_MFA_Raporu_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation -Encoding UTF8 $totalUsers = $detailedReport.Count $mfaEnabledUsers = ($detailedReport | Where-Object { $_.MFADurumu -eq "Etkin" }).Count $mfaAdoptionRate = ::Round(($mfaEnabledUsers / $totalUsers) * 100, 2) Write-Host "MFA Benimseme Oranı: $mfaAdoptionRate%" Write-Host "Toplam Kullanıcı: $totalUsers" Write-Host "MFA Etkinleştirilmiş Kullanıcı: $mfaEnabledUsers" Write-Host "MFA Etkinleştirilmemiş Kullanıcı: $($totalUsers - $mfaEnabledUsers)" $authenticatorUsers = ($detailedReport | Where-Object { $_.KayıtlıYöntemler -like "*Microsoft Authenticator*" }).Count $phoneUsers = ($detailedReport | Where-Object { $_.KayıtlıYöntemler -like "*Telefon*" }).Count $fido2Users = ($detailedReport | Where-Object { $_.KayıtlıYöntemler -like "*FIDO2*" }).Count $windowsHelloUsers = ($detailedReport | Where-Object { $_.KayıtlıYöntemler -like "*Windows Hello*" }).Count Write-Host "Microsoft Authenticator Kullanıcıları: $authenticatorUsers" Write-Host "Telefon Doğrulama Kullanıcıları: $phoneUsers" Write-Host "FIDO2 Güvenlik Anahtarı Kullanıcıları: $fido2Users" Write-Host "Windows Hello for Business Kullanıcıları: $windowsHelloUsers" # Departman bilgisini içeren kullanıcı listesi $departmentUsers = Get-MgUser -All -Property DisplayName, UserPrincipalName, Department, Id # Departman bazlı analiz $departmentReport = @() $departments = $departmentUsers | Select-Object -ExpandProperty Department -Unique | Where-Object { $_ -ne $null -and $_ -ne "" } foreach ($dept in $departments) { $deptUsers = $departmentUsers | Where-Object { $_.Department -eq $dept } $deptUserCount = $deptUsers.Count $deptMfaUsers = 0 foreach ($user in $deptUsers) { $mfaStatus = $detailedReport | Where-Object { $_.UserPrincipalName -eq $user.UserPrincipalName } | Select-Object -ExpandProperty MFADurumu if ($mfaStatus -eq "Etkin") { $deptMfaUsers++ } } $deptMfaRate = if ($deptUserCount -gt 0) { ::Round(($deptMfaUsers / $deptUserCount) * 100, 2) } else { 0 } $departmentReport += @{ Departman = $dept ToplamKullanıcı = $deptUserCount MFAEtkinKullanıcı = $deptMfaUsers MFAUyumOranı = "$deptMfaRate%" } } # Sonuçları görüntüle $departmentReport | Sort-Object -Property MFAUyumOranı -Descending | Format-Table -AutoSize # CSV olarak dışa aktar $departmentReport | Export-Csv -Path "Departman_MFA_Raporu_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation -Encoding UTF8 Connect-MgGraph -Scopes "User.Read.All", "UserAuthenticationMethod.Read.All", "Directory.Read.All", "Policy.Read.All" $adminRoles = @( "Global Administrator", "Privileged Role Administrator", "User Administrator", "SharePoint Administrator", "Exchange Administrator", "Conditional Access Administrator", "Security Administrator" ) # Rol üyelerini ve MFA durumlarını al $privilegedUsers = @() foreach ($role in $adminRoles) { $roleUsers = Get-MgDirectoryRole -Filter "DisplayName eq '$role'" | Get-MgDirectoryRoleMember | Where-Object { $_.AdditionalProperties -eq "#microsoft.graph.user" } foreach ($user in $roleUsers) { $userId = $user.Id $userObj = Get-MgUser -UserId $userId # MFA durumunu kontrol et $authMethods = Get-MgUserAuthenticationMethod -UserId $userId $mfaEnabled = ($authMethods | Where-Object { $_.AdditionalProperties -ne "#microsoft.graph.passwordAuthenticationMethod" }).Count -gt 0 $privilegedUsers += @{ KullanıcıAdı = $userObj.DisplayName KullanıcıPrincipalName = $userObj.UserPrincipalName Rol = $role MFADurumu = if ($mfaEnabled) { "Etkin" } else { "Devre Dışı" } RiskSeviyesi = if ($mfaEnabled) { "Düşük" } else { "Yüksek" } } } } # Sonuçları görüntüle $privilegedUsers | Format-Table -AutoSize # CSV olarak dışa aktar $privilegedUsers | Export-Csv -Path "Yetkili_Kullanıcılar_MFA_Raporu_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation -Encoding UTF8 # MFA güvenlik açıklarını değerlendir $vulnReport = @{ YüksekRiskliYöneticiler = ($privilegedUsers | Where-Object { $_.MFADurumu -eq "Devre Dışı" }).Count ToplamYöneticiSayısı = $privilegedUsers.Count DüşükGüvenlikliMFAYöntemleri = ($detailedReport | Where-Object { $_.KayıtlıYöntemler -like "*SMS*" -or $_.KayıtlıYöntemler -like "*Telefon*" }).Count KonsolideRiskPuanı = 0 # Hesaplanacak } # Risk puanı hesapla (0-100 arasında, 100 en riskli) $adminRiskWeight = 40 # Yönetici MFA eksikliği ağırlığı $userRiskWeight = 30 # Genel kullanıcı MFA eksikliği ağırlığı $methodRiskWeight = 30 # Düşük güvenlikli MFA yöntemi ağırlığı $adminRiskScore = if ($vulnReport.ToplamYöneticiSayısı -gt 0) { ($vulnReport.YüksekRiskliYöneticiler / $vulnReport.ToplamYöneticiSayısı) * $adminRiskWeight } else { 0 } $userRiskScore = if ($totalUsers -gt 0) { (($totalUsers - $mfaEnabledUsers) / $totalUsers) * $userRiskWeight } else { 0 } $methodRiskScore = if ($mfaEnabledUsers -gt 0) { ($vulnReport.DüşükGüvenlikliMFAYöntemleri / $mfaEnabledUsers) * $methodRiskWeight } else { 0 } $vulnReport.KonsolideRiskPuanı = ::Round($adminRiskScore + $userRiskScore + $methodRiskScore, 2) # Sonuçları görüntüle $vulnReport | Format-Table -AutoSize # Risk değerlendirmesi özeti $riskLevel = switch ($vulnReport.KonsolideRiskPuanı) { {$_ -lt 20} { "Çok Düşük Risk" } {$_ -lt 40} { "Düşük Risk" } {$_ -lt 60} { "Orta Risk" } {$_ -lt 80} { "Yüksek Risk" } default { "Çok Yüksek Risk" } } Write-Host "MFA Risk Değerlendirmesi: $riskLevel ($($vulnReport.KonsolideRiskPuanı)/100)" -ForegroundColor $( switch ($riskLevel) { "Çok Düşük Risk" { "Green" } "Düşük Risk" { "DarkGreen" } "Orta Risk" { "Yellow" } "Yüksek Risk" { "Red" } "Çok Yüksek Risk" { "DarkRed" } } ) # MFA eksik kullanıcılara bildirim gönder $mfaMissingUsers = $detailedReport | Where-Object { $_.MFADurumu -eq "Devre Dışı" } foreach ($user in $mfaMissingUsers) { $emailBody = @" Sayın $($user.DisplayName), Şirketimizin güvenlik politikası gereği, Microsoft 365 hesabınız için Çok Faktörlü Kimlik Doğrulama (MFA) etkinleştirmeniz gerekmektedir. MFA'yı etkinleştirmek için: 1. https://aka.ms/mfasetup adresine gidin 2. Kurumsal hesabınızla oturum açın 3. Ek güvenlik doğrulama yöntemlerinizi kurun Daha fazla bilgi için IT Yardım Masası ile iletişime geçebilirsiniz. Saygılarımızla, IT Güvenlik Ekibi "@ # E-posta gönderme kodunu burada uygulayın # Send-MailMessage vb. } # Yönetici hesapları için MFA'yı zorunlu kıl $adminUsers = $privilegedUsers | Where-Object { $_.MFADurumu -eq "Devre Dışı" } foreach ($admin in $adminUsers) { # Kullanıcı başına MFA'yı etkinleştir $st = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement $st.RelyingParty = "*" $st.State = "Enabled" $sta = @($st) Set-MsolUser -UserPrincipalName $admin.KullanıcıPrincipalName -StrongAuthenticationRequirements $sta Write-Host "$($admin.KullanıcıAdı) ($($admin.Rol)) için MFA zorunlu kılındı" -ForegroundColor Green }   Microsoft Entra ID MFA durumunu izlemek ve raporlamak, organizasyonunuzun güvenlik duruşunu iyileştirmek için kritik bir uygulamadır. Bu rehberde açıklanan yöntemler ve araçlarla:
MFA'yı tüm kullanıcılarınız için uyguladığınızda, hesap ele geçirme saldırılarına karşı önemli bir koruma katmanı eklemiş olursunuz. Düzenli denetimler ve raporlar, bu kritik güvenlik kontrolünün organizasyonunuzda etkili bir şekilde uygulandığından emin olmanıza yardımcı olacaktır.
Unutmayın ki, MFA tek başına yeterli değildir - kimlik güvenliğini kapsamlı bir şekilde ele alan bir yaklaşımın parçası olmalıdır. Koşullu erişim politikaları, risk tabanlı kimlik doğrulama ve en az ayrıcalık ilkesi ile birlikte kullanıldığında, MFA modern bir güvenlik stratejisinin güçlü bir bileşeni haline gelir.
Önemli Not: Bu rehberde sağlanan PowerShell betikleri, kendi ortamınıza uyarlanması gerekebilir. Üretim ortamında uygulamadan önce test ortamında denemeniz önerilir.