Propósito:
El objetivo es garantizar que no existan cuentas de administrador no autorizadas en Active Directory.
Se realiza una comprobación en las cuentas que no son de administrador para identificar si tienen el atributo `admincount` activado. Si lo tienen, significa que esta cuenta, que no debería ser de administrador, ha recibido derechos de administrador en el pasado. Esto suele ocurrir cuando un administrador otorga derechos temporales a una cuenta normal fuera de proceso.
Se deben revisar estas cuentas, especialmente en lo que respecta a su actividad anterior, y eliminar el atributo `admincount`. Para identificar las cuentas detectadas por esta regla, recomendamos ejecutar el siguiente comando de PowerShell: `get-adobject -ldapfilter "(admincount=1)"`.
Pasos
- Domain Admins
- Enterprise Admins
- Schema Admins
- Account Operators
- Backup Operators
- Administrators (builtin)
- Print Operators
- Server Operators
adminCount
|
<# Script:
Audit_Usuarios_Privilegiados_AdminCount_ProtectedUsers.ps1 Descripcion: Este script audita cuentas de Active Directory con
AdminCount=1, indicando usuarios que actualmente o en el pasado han
tenido privilegios elevados. Adicionalmente valida si dichas
cuentas pertenecen al grupo de seguridad "Protected
Users" y si tienen activada la opcion "La cuenta es importante y no se
puede delegar". Uso previsto:
Requisitos:
Impacto:
#> Import-Module ActiveDirectory ========================== VARIABLES DEL USUARIO ========================== $SMTPServer = "smtp01.midomino.com" $SMTPPort = 25 $From = "srvdc01@midomino.com" $To =
"miemail@midomino.com" $DateStamp
= Get-Date -Format "yyyy-MM-dd - HHmm" $ReportPath
= "C:\Temp\AdminCount_Users_ProtectedUsers_$DateStamp.csv" ========================== OBTENCION DE MIEMBROS DE PROTECTED USERS ========================== $ProtectedUsersGroup
= Get-ADGroup "Protected Users" $ProtectedUsers
= Get-ADGroupMember $ProtectedUsersGroup -Recursive | Where-Object
{ $_.objectClass -eq "user" } | Select-Object
-ExpandProperty SamAccountName ========================== OBTENCION
DE USUARIOS ADMINCOUNT ========================== $Users =
Get-ADUser -Filter { AdminCount -eq 1 } -Properties ` WhenCreated, Description, Enabled, AccountNotDelegated, SamAccountName
| Select-Object
` Name, SamAccountName, WhenCreated, Description, Enabled, @{Name="NoDelegable";Expression={ if
($_.AccountNotDelegated) { "SI" } else { "NO" } }}, @{Name="ProtectedUsers";Expression={ if
($ProtectedUsers -contains $_.SamAccountName) { "SI" } else { "NO" } }} $UserCount
= $Users.Count $ProtectedCount
= ($Users | Where-Object
{ $_.ProtectedUsers -eq "SI" }).Count $NoDelegableCount
= ($Users | Where-Object
{ $_.NoDelegable -eq "SI" }).Count ========================== EXPORT
CSV ========================== $Users |
Export-Csv -Path $ReportPath -NoTypeInformation -Encoding UTF8 ========================== CUERPO HTML ========================== $HtmlBody = @" <html> <head> <style> body { font-family:
Segoe UI, Arial; font-size:
12px; } table { border-collapse:
collapse; width:
100%; } th, td { border:
1px solid #999; padding:
6px; text-align:
left; } th { background-color:
#dedede; } </style> </head> <body> <h2>Auditoria de cuentas privilegiadas
(AdminCount=1)</h2> <p> Este informe identifica cuentas con AdminCount=1 y valida
si estan protegidas mediante el grupo "Protected Users" y
si tienen activada la opcion "La cuenta es importante y no se puede
delegar". </p> <ul> <li>Total
cuentas privilegiadas: <strong>$UserCount</strong></li> <li>Cuentas
en Protected Users: <strong>$ProtectedCount</strong></li> <li>Cuentas
NO protegidas: <strong>$($UserCount -
$ProtectedCount)</strong></li> <li>Cuentas
NO delegables: <strong>$NoDelegableCount</strong></li> </ul> <table> <tr> <th>Nombre</th> <th>SamAccountName</th> <th>Fecha
de creacion</th> <th>Descripcion</th> <th>Habilitado</th> <th>No
delegable</th> <th>Protected
Users</th> </tr> $( foreach
($User in $Users) { @" <tr> <td>$($User.Name)</td> <td>$($User.SamAccountName)</td> <td>$($User.WhenCreated)</td> <td>$($User.Description)</td> <td>$($User.Enabled)</td> <td>$($User.NoDelegable)</td> <td>$($User.ProtectedUsers)</td> </tr> "@ } ) </table> <p> Recomendaciones: </p> <ul> <li>Evaluar inclusion progresiva en Protected Users
para administradores humanos.</li> <li>Revisar las cuentas privilegiadas que no estan
protegidas.</li> <li>Revisar las cuentas privilegiadas susceptibles
de delegacion Kerberos.</li> <li>No incluir cuentas de servicio sin validacion
previa.</li> <li>Todas las cuentas privilegiadas deberian tener
el campo "No delegable" a SI.</li> </ul> </body> </html> "@ ========================== ASUNTO Y ENVIO ========================== $Subject
= "$DateStamp - Auditoria AdminCount y Protected Users - $UserCount
cuentas" Send-MailMessage
` -From
$From ` -To $To ` -Subject
$Subject ` -Body
$HtmlBody ` -BodyAsHtml
` -SmtpServer
$SMTPServer ` -Port
$SMTPPort ` -Attachments
$ReportPath |


_%20-%20gonstation@gm.jpg)













