From 08ac486ac421f0481e93cc0e912355012e126d17 Mon Sep 17 00:00:00 2001 From: Eduardo Mosqueda Date: Mon, 3 Nov 2025 16:20:19 -0600 Subject: [PATCH] Add tests/privilegios.ps1 --- tests/privilegios.ps1 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/privilegios.ps1 diff --git a/tests/privilegios.ps1 b/tests/privilegios.ps1 new file mode 100644 index 0000000..20bf232 --- /dev/null +++ b/tests/privilegios.ps1 @@ -0,0 +1,30 @@ +# Script: test_privilegios.ps1 +# Objetivo: Prueba irrefutable de privilegios (SYSTEM vs. Usuario). + +$LogPath = "C:\TEMP\safecloud_privilege_test.log" +$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name + +# Definimos la clave de registro que SOLO SYSTEM puede tocar. +$ProtectedRegPath = "HKLM:\SECURITY\SafeCloudPrivilegeTest" + +try { + # --- LA PRUEBA --- + # Intentamos crear una clave en HKLM:\SECURITY + # Esto FALLARÁ para "RunAs User" (Acceso Denegado). + # Esto FUNCIONARÁ para "RunAs System". + New-Item -Path $ProtectedRegPath -Force -ErrorAction Stop + + # Si llegamos aquí, tuvimos éxito (somos SYSTEM) + $Content = "PRUEBA EXITOSA (Ejecutado como $CurrentUser) - $Timestamp`nSe creó la clave de registro en HKLM:\SECURITY." + + # Limpiamos nuestra prueba + Remove-Item -Path $ProtectedRegPath -Force +} +catch { + # Si llegamos aquí, fallamos (somos Usuario) + $Content = "PRUEBA FALLIDA (Ejecutado como $CurrentUser) - $Timestamp`nAcceso denegado a HKLM:\SECURITY, como se esperaba." +} + +# Escribimos el resultado en un archivo de registro para que podamos verlo. +Set-Content -Path $LogPath -Value $Content -Force \ No newline at end of file