Trabajando con el Registro de Windows - PowerShell

En esta sección vamos a profundizar en uno de los componentes más complejos de Windows: el Registro. Aprenderemos qué es, cómo navegarlo, cómo leer claves/valores y cómo modificarlos cuando sea necesario.


📌 ¿Qué es el Registro de Windows?


🔑 Claves (Keys)

Visualmente, cada carpeta en el Editor del Registro representa una clave.


📝 Valores (Values)


🏠 Hives del Registro

Cada Windows tiene hives predefinidos con funciones específicas:

Nombre Abreviatura Descripción
HKEY_LOCAL_MACHINE HKLM Información sobre hardware, drivers, sistema operativo.
HKEY_CURRENT_CONFIG HKCC Perfil de hardware actual.
HKEY_CLASSES_ROOT HKCR Tipos de archivo y compatibilidad.
HKEY_CURRENT_USER HKCU Configuración específica del usuario.
HKEY_USERS HKU Configuración de todos los usuarios y perfil predeterminado.

💻 Accediendo al Registro desde CLI

Usando PowerShell

Ejemplo: Consultar aplicaciones que se ejecutan al iniciar sesión

Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Salida típica:

SecurityHealth : C:\Windows\system32\SecurityHealthSystray.exe
RtkAudUService : "C:\Windows\System32\DriverStore\FileRepository\...\RtkAudUService64.exe" -background
WavesSvc       : "C:\Windows\System32\DriverStore\FileRepository\...\WavesSvc64.exe" -Jack
...

Usando reg.exe

reg query HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip

Salida:

Path64 REG_SZ C:\Program Files\7-Zip\
Path   REG_SZ C:\Program Files\7-Zip\

🔍 Buscar información en el Registro

REG QUERY HKCU /F "Password" /t REG_SZ /S /K

Útil para pentesters al buscar credenciales, usuarios, claves, etc.


➕ Crear y modificar claves y valores

Crear nueva clave

New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\ -Name TestKey

Crear valor dentro de la clave

New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\TestKey `
-Name "access" -PropertyType String -Value "C:\Users\htb-student\Downloads\payload.exe"

Salida:

access : C:\Users\htb-student\Downloads\payload.exe
PSPath  : ...\RunOnce\TestKey

Esto permite ejecutar un payload la próxima vez que el usuario inicie sesión.

Crear el mismo valor con reg.exe

reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce\TestKey" /v access /t REG_SZ /d "C:\Users\htb-student\Downloads\payload.exe"

❌ Eliminar un valor

Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\TestKey -Name "access"

💡 Resumen: