# 启动与登陆触发

我们还可以通过登陆操作来触发特定任务。与登陆相关的实现方式有数种，但实现效果是相似的。

#### **Startup 文件夹**

每个用户都拥有一个文件夹 **C:\\Users\\\[用户名\]\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup** 。如果我们在其中放置一个可执行文件，当前用户会在登陆的时候触发载荷。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/J7gTtFW2U2FpxjB0-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/J7gTtFW2U2FpxjB0-image.png)

如果我们是想让所有用户都执行该载荷，那么我们可以放在 **C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp** 文件夹下

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/rDwdRWVQ32BrMjUt-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/rDwdRWVQ32BrMjUt-image.png)

我们还可以通过SharPersist工具实现：**SharPersist.exe -t startupfolder -c "C:\\Windows\\System32\\calc.exe" -f "StartUp" -m add**

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/XYNmJsVgEdKIGwJB-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/XYNmJsVgEdKIGwJB-image.png)

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/BU5XPJE4q7ll3fIT-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/BU5XPJE4q7ll3fIT-image.png)

SharPersist 在该目录下生成了一个快捷方式，指定了要执行的程序以及参数。

#### **Run与RunOnce**

我们还可以通过修改注册表Run与RunOnce实现。

注册表位置：

```powershell
HKCU\Software\Microsoft\Windows\CurrentVersion\Run

HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

HKLM\Software\Microsoft\Windows\CurrentVersion\Run

HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
```

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/bMBhx5XoIeTVhXoI-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/bMBhx5XoIeTVhXoI-image.png)

我们也可以通过SharPersist工具来实现，命令为 **SharPersist.exe -t reg -c "C:\\Windows\\Tasks\\Beacon.exe" -a "/q /n" -k "hkcurun" -v "Microsoft Services" -m add**

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/CcHfHLr8CrOZ0iUI-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/CcHfHLr8CrOZ0iUI-image.png)

#### **Logon Helper**

之前的章节提到，我们可能在注册表的 **Winlogon** (**HKCU\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon**) 区域提取到明文帐号密码，但实际上我们也可以用来实现持久化。我们注意到，一些条目指向可执行文件，例如 **Userinit**。

```powershell
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\shell
```

我们直接替换的话，可能影响原本功能，因此我们**额外**添加要运行的程序及参数。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/OzhgBhvTfEyY32uR-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/OzhgBhvTfEyY32uR-image.png)