<# .HARDENING M365 - CHECKLIST TÉCNICO Versión: 3.2 Requisitos: Módulos ExchangeOnline, AzureAD, Microsoft.Graph #> # 1. CONFIGURACIÓN BÁSICA DE SEGURIDAD function Enable-BasicSecurity { Write-Host "`n[1/10] Configurando seguridad básica..." -ForegroundColor Cyan # 1.1. Activar MFA para todos los usuarios (Azure AD) $mfaPolicy = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement $mfaPolicy.RelyingParty = "*" $mfaPolicy.State = "Enabled" Set-MsolUser -UserPrincipalName (Get-MsolUser -All).UserPrincipalName -StrongAuthenticationRequirements $mfaPolicy # 1.2. Deshabilitar protocolos legacy (Exchange Online) Set-CASMailbox -Identity "All" -PopEnabled $false -ImapEnabled $false -ActiveSyncEnabled $false -OWAEnabled $true # 1.3. Bloquear autenticación básica (Modern Auth only) Set-OrganizationConfig -OAuth2ClientProfileEnabled $true Write-Host "[✓] Autenticación básica deshabilitada" -ForegroundColor Green } # 2. HARDENING DE SHAREPOINT/ONEDRIVE function Hardening-SPO { Write-Host "`n[2/10] Aplicando hardening SharePoint/OneDrive..." -ForegroundColor Cyan # 2.1. Limitar sharing externo Set-SPOTenant -SharingCapability "ExistingExternalUserSharingOnly" # Solo usuarios externos ya invitados Set-SPOTenant -OneDriveStorageQuota 1024 # 1TB máximo por usuario # 2.2. Desactivar sincronización con clientes no gestionados Set-SPOTenant -BlockSyncOnNonDomainJoinedComputers $true Write-Host "[✓] Sharing externo restringido" -ForegroundColor Green } # 3. PROTECCIÓN CONTRA RANSOMWARE function AntiRansomware { Write-Host "`n[3/10] Configurando protección anti-ransomware..." -ForegroundColor Cyan # 3.1. Retención de versiones en SharePoint Set-SPOSite -Identity "https://[tenant].sharepoint.com" -DenyAddAndCustomizePages $true Set-SPOTenant -EnableAutoExpirationVersioning $true -ExpireVersionsAfterDays 365 # 3.2. Reglas de transporte contra extensiones peligrosas New-TransportRule -Name "Block Ransomware Extensions" -Enabled $true -AttachmentExtensionMatchesWords @("exe", "js", "vbs", "scr") -DeleteMessage $true Write-Host "[✓] Reglas anti-ransomware aplicadas" -ForegroundColor Green } # 4. HARDENING DE TEAMS function Hardening-Teams { Write-Host "`n[4/10] Aplicando hardening de Teams..." -ForegroundColor Cyan # 4.1. Desactivar guest access si no es necesario Set-CsTeamsGuestMessagingConfiguration -AllowUserToMessageGuests $false # 4.2. Restringir tipos de archivos en chats Set-CsTeamsClientConfiguration -AllowedFileExtensions @(".docx", ".xlsx", ".pptx", ".pdf") Write-Host "[✓] Configuración de Teams asegurada" -ForegroundColor Green } # 5. MONITORIZACIÓN CONTINUA function Enable-Monitoring { Write-Host "`n[5/10] Configurando monitorización..." -ForegroundColor Cyan # 5.1. Alertas de actividades sospechosas New-ProtectionAlert -Name "Multiple Failed Logins" -Description "Alerta para intentos de login fallidos" -Severity "High" -Threshold 5 -Operations "UserLoginFailed" -NotificationEmails "admin@tuempresa.com" # 5.2. Habilitar auditoría global Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true Write-Host "[✓] Auditoría y alertas activadas" -ForegroundColor Green } # 6. EJECUCIÓN COMPLETA Write-Host "`n=== INICIANDO HARDENING M365 ===" -ForegroundColor Yellow Enable-BasicSecurity Hardening-SPO AntiRansomware Hardening-Teams Enable-Monitoring Write-Host "`n[✔] Hardening completado. Verifica el registro completo en $PSScriptRoot\hardening_log.txt" -ForegroundColor Green