miércoles, 25 de junio de 2025

WINDOWS. PS. SECURITY. Users do not require pre-authentication

Purpose

Here's a PowerShell script that will allow you to get the list of users who do not require pre-authentication in your environment.

Steps

# Importar el módulo de Active Directory

Import-Module ActiveDirectory

# Obtener todos los usuarios que no requieren autenticación previa

$usuariosSinAutenticacionPrevia = Get-ADUser -Filter {UserAccountControl -band 0x20000} -Properties DisplayName, UserPrincipalName

# Mostrar la lista de usuarios

$usuariosSinAutenticacionPrevia | Select-Object DisplayName, UserPrincipalName | Format-Table -AutoSize

by GoN | Published: Jun 2025 | Last Updated:

WINDOWS. PS. SECURITY. SPN. Service Principal Name

Purpose

PowerShell script that will allow you to verify if a SPN (Service Principal Name) exists in the domain that allows you to generate a TGS (Ticket Granting Service) ticket. This script searches Active Directory for registered SPNs and displays those that meet the criteria.

Steps

# Importar el módulo de Active Directory

Import-Module ActiveDirectory

# Definir el SPN que deseas buscar

$spn = "HTTP/*"

# Buscar cuentas de servicio con el SPN especificado

$cuentasConSPN = Get-ADObject -Filter {ServicePrincipalName -like $spn} -Properties ServicePrincipalName, Name

# Verificar si se encontraron cuentas con el SPN

if ($cuentasConSPN) {

    Write-Output "Se encontraron las siguientes cuentas con el SPN '$spn':"

    $cuentasConSPN | Select-Object Name, ServicePrincipalName | Format-Table -AutoSize

} else {

    Write-Output "No se encontraron cuentas con el SPN '$spn'."

}



By GoN | Published: Jun 2025 | Last Updated:

lunes, 23 de junio de 2025

 Purpose

Search my shared resources for the words "contraseña|password|contrasenya" and report it to me in a file.

I'm looking for words to ask the user to save their passwords in a secure place like Keepass.

Steps

# Función para obtener el propietario de un archivo o carpeta
function Get-Owner {
    param (
        [string]$Path
    )
    $acl = Get-Acl -Path $Path
    $owner = $acl.Owner
    return $owner
}
# Función para obtener los permisos de escritura de un archivo o carpeta
function Get-WritePermissions {
    param (
        [string]$Path
    )
    $acl = Get-Acl -Path $Path
    $permissions = @()
    foreach ($access in $acl.Access) {
        if ($access.FileSystemRights -match "Write") {
            $permissions += $access.IdentityReference
        }
    }
    return $permissions -join ", "
}
# Crear el archivo CSV y añadir encabezados
$csvPath = "resultado.csv"
"Nombre,RutaCompleta,RutaRelativa,Propietario,PermisosDeEscritura" | Out-File -FilePath $csvPath -Encoding UTF8
# Función para recorrer la estructura de directorios de una ruta de red
function Search-Path {
    param (
        [string]$NetworkPath
    )
    Get-ChildItem -Path $NetworkPath -Recurse | ForEach-Object {
        if ($_ -match "contraseña|password|contrasenya") {
            $owner = Get-Owner -Path $_.FullName
            $writePermissions = Get-WritePermissions -Path $_.FullName
            $relativePath = $_.FullName.Substring($NetworkPath.Length)  # Obtener la ruta relativa
            $result = "$($_.Name),$($_.FullName),$relativePath,$owner,$writePermissions"
            $result | Out-File -FilePath $csvPath -Append -Encoding UTF8
        }
    }
}
# Recorrer las rutas de red
Search-Path -NetworkPath "\\server1\d$"
Search-Path -NetworkPath "\\server2\r$"
Search-Path -NetworkPath "\\server4\r$"
Write-Host "El archivo resultado.csv ha sido creado con éxito."

 By GoN | Published: Jun 2025 | Last Updated: