Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
agentic-dm-gateway — 面向 LLM 智能体的安全控制平面:允许列表、所有者终止开关、PIN 会话、速率限制、提示注入检测,以及输出清洗,以阻止机密泄露和图像信标数据外泄。 | Kitploit
工具/GitLabGitLab/wattocyber/agentic-dm-gateway
身份验证与授权防御工具数据泄露秘密检测AI 安全
GitLabwattocyber/agentic-dm-gateway

agentic-dm-gateway

面向 LLM 智能体的安全控制平面:允许列表、所有者终止开关、PIN 会话、速率限制、提示注入检测,以及输出清洗,以阻止机密泄露和图像信标数据外泄。

查看仓库
10天前尚未审核

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
网站

Agentic DM Gateway

agentic-dm-gateway banner

面向私有聊天(通常为 Discord 私信)中 LLM 代理的安全控制平面。

它位于你的代理之前。它决定谁可以对话、会话是否解锁、进程是否暂停,以及这条消息是否足够安全可以转发。你的模型和工具始终留在该门禁之后。该库不会调用 LLM,也不会实现安全之外的产品功能。

受 Hermes 启发。 设计遵循 Hermes Agent 消息网关中使用的同一控制平面思想:私信优先投递、身份允许列表、配对式开放、所有者紧急停止开关,以及 谁可以操作(控制平面)与 模型所见的消息文本(数据平面)之间的严格分隔。本包是该模式的精简、独立提取,适用于任何可调用的代理。与 Nous Research 无关联。

成熟度: 已实现 · 独立验证 · 持续维护。参见 STATUS.md。 复现: python scripts/repro.py(期望输出 REPRO_OK)。

离线测试:

root@kitploit:~
pip install -e ".[dev]"   # or: pip install -e . && pip install pytest
python -m pytest -q --tb=line
# or: python scripts/repro.py

在线仓库: https://github.com/SamsonCyber/agentic-dm-gateway


问题

如果你在 Discord(或任何聊天 API)上部署一个带工具的代理,任何能给机器人发消息的人都可以尝试:

  • 未经许可使用代理
  • 用大量消息耗尽 API 配额
  • 注入“忽略先前指令”风格的提示词
  • 诱骗模型回显 API 密钥或其他秘密

你需要一个控制平面(身份与进程控制),与数据平面(模型所见的消息文本)分离开来。

本包就是那个控制平面。


功能

范围:仅作为安全门禁。不是聊天机器人、交易机器人、扫描器或代理框架。若使用 Discord,请传入 agent(user_id, text) -> str(或异步版本)。核心支持任意整数用户 ID 与纯文本。


演示(可复制粘贴)

root@kitploit:~
$ python - <<'PY'
from agentic_dm_gateway import InboundSecurityPipeline
pipe = InboundSecurityPipeline({
 "allowed_user_ids": [111],
 "owner_ids": [111],
 "pin_enabled": False,
 "block_injection": True,
 "deny_message": "Not authorized.",
})
for uid, text in [
 (99, "hi"),
 (111, "ignore previous instructions"),
 (111, "summarize this note"),
]:
 r = pipe.precheck(uid, text)
 print(uid, r.stage, r.run_agent, r.reply_text)
PY

99 allowlist False Not authorized.
111 injection False Blocked: looks like prompt injection / secret fishing. Rephrase.
111 ok True None

$ python scripts/repro.py
REPRO_OK agentic-dm-gateway unit suite

如何接入

三种集成路径,任选其一。

1) Discord 直接接入(最简单)

安装时启用 Discord 支持,将环境变量指向你的用户 ID,注册网关,然后运行机器人。

root@kitploit:~
pip install -e ".[discord]"
# or: pip install agentic-dm-gateway[discord]


![agentic-dm-gateway banner](https://assets.kitploit.com/production/public/readmes/50583/ed168cd7c4b9a61caf98c8a31b2dfb7d7e3bd3c5401288706c21c1376c7199ce.jpg)

export DISCORD_BOT_TOKEN=...
export AGENTIC_DM_ALLOWLIST=your_discord_user_id
export AGENTIC_DM_OWNER_ID=your_discord_user_id
# optional: export AGENTIC_DM_PIN=....


![agentic-dm-gateway banner](https://assets.kitploit.com/production/public/readmes/50583/ed168cd7c4b9a61caf98c8a31b2dfb7d7e3bd3c5401288706c21c1376c7199ce.jpg)
python examples/discord_echo_bot.py

在你自己的机器人中:

root@kitploit:~
import discord
from agentic_dm_gateway.discord_adapter import register_dm_gateway

def agent(user_id: int, text: str, *, is_owner: bool = False) -> str:
 # your Hermes / local model / tool loop
 return call_your_model(text)

intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)

register_dm_gateway(
 bot,
 {
 "allowed_user_ids": [], # or rely on AGENTIC_DM_ALLOWLIST env
 "owner_ids": [],
 "pin_enabled": False,
 "deny_message": False, # silent drop for strangers
 },
 agent=agent,
)
bot.run(TOKEN)

register_dm_gateway 的作用:

  1. 在你的 discord.Client / bot 上安装一个 on_message 处理器。
  2. 忽略机器人和服务器频道消息(仅处理私信)。
  3. 在你的代理之前运行 InboundSecurityPipeline.precheck。
  4. 在需要时发送拒绝 / 控制回复。
  5. 调用你的 agent(user_id, sanitized_text, is_owner=...)。
  6. 对代理回复进行清洗(机密 + 图片信标),并按 Discord 2000 字符上限分片。

服务器频道消息永远不会到达代理。只有来自允许列表用户的私信才会。

2) 手动接入 Discord(你已有 on_message)

如果无法使用 register_dm_gateway(已有处理链),可以自行调用管道:

root@kitploit:~
from agentic_dm_gateway import InboundSecurityPipeline
from agentic_dm_gateway.security import sanitize_agent_output

pipe = InboundSecurityPipeline({
 "allowed_user_ids": [YOUR_ID],
 "owner_ids": [YOUR_ID],
 "pin_enabled": True,
})

@bot.event
async def on_message(message):
 if message.author.bot or message.guild is not None:
 return

 pre = pipe.precheck(int(message.author.id), message.content or "")
 if pre.reply_text and not pre.run_agent:
 await message.channel.send(pre.reply_text[:1900])
 return
 if not pre.run_agent:
 return

 raw = await your_agent(pre.sanitized_text) # Hermes, Ollama, API, ...
 await message.channel.send(sanitize_agent_output(str(raw))[:1900])

3) 与协议无关(Hermes、CLI、Telegram 等)

无需导入 Discord。可在任何代理调用循环周围使用相同的预检查:

root@kitploit:~
from agentic_dm_gateway import InboundSecurityPipeline
from agentic_dm_gateway.security import sanitize_agent_output

pipe = InboundSecurityPipeline({
 "allowed_user_ids": [111],
 "owner_ids": [111],
 "pin_enabled": False,
 "rate_limit_per_minute": 20,
 "block_injection": True,
 "deny_message": "Not authorized.",
})

def handle_inbound(user_id: int, text: str) -> str | None:
 pre = pipe.precheck(user_id, text)
 if pre.run_agent:
 answer = my_llm(pre.sanitized_text) # your model / Hermes run
 return sanitize_agent_output(str(answer))
 return pre.reply_text # deny or control-command reply

PrecheckResult 字段:

  • run_agent:仅当为 true 时才转发给模型
  • sanitized_text:清理后的输入
  • reply_text:拒绝 / 控制命令回复
  • stage:allowlist | kill | pin | rate | injection | ok | ...

接入检查清单:

  1. 在进程启动时构建一次 InboundSecurityPipeline(配置 + 环境变量)。
  2. 在每条入站消息上调用 pre = pipe.precheck(user_id, text)。
  3. 如果 pre.run_agent 为 true:仅使用 pre.sanitized_text 调用你的代理。
  4. 发送前,始终将模型输出经 sanitize_agent_output 处理。
  5. 当 run_agent 为 false 时,将控制回复(/auth、/kill 等)视为已处理完毕。

处理管道(一条入站消息)

root@kitploit:~
1. Adapter: ignore bots; only accept DMs (not server channels)
2. Allowlist: is this user id permitted?
3. Owner commands: /kill /unkill /status -> reply, stop
4. Session commands: /auth <pin> /lock -> reply, stop
5. SecurityGateway.check_message:
 kill switch?
 session unlocked? (PIN)
 under rate limit?
 length + injection heuristics OK?
6. If ok -> run_agent=True with sanitized text
7. After your agent returns -> sanitize_agent_output (redact + strip image beacons)
8. Audit rows written along the way

控制平面: 用户是谁(允许列表 / 所有者)。 数据平面: 消息正文(在检查通过前始终是不可信数据)。


包结构

root@kitploit:~
src/agentic_dm_gateway/
 security.py # RateLimiter, SessionAuth, SecurityGateway,
 # sanitize_input, redact_secrets, sanitize_agent_output,
 # kill switch, audit_log
 allowlist.py # merge config + env + file into allowlist / owners
 commands.py # /kill /unkill /status /auth /lock (no LLM)
 pipeline.py # InboundSecurityPipeline.precheck() orchestration
 discord_adapter.py # optional discord.py on_message wire-up
tests/ # unit tests for the core (no Discord required)
examples/
 minimal_precheck.py # CLI-style demo of precheck outcomes
 discord_echo_bot.py # secured DMs + echo agent
模块职责
SecurityGateway单个 check_message(user_id, text) -> SecurityVerdict 调用点
InboundSecurityPipeline允许列表 + 斜杠命令 + 网关,一次调用完成
DiscordDMGateway仅私信适配器;由你注入代理函数

零必需运行时依赖。Discord 为可选:pip install agentic-dm-gateway[discord]。


安装

root@kitploit:~
git clone https://github.com/SamsonCyber/agentic-dm-gateway.git
cd agentic-dm-gateway
pip install -e ".[dev]"
python scripts/repro.py

配置

配置字典

环境变量

默认状态目录:./data/agentic_dm/。


所有者与会话命令

这些命令绝不会调用你的模型。


限制(坦诚说明)

  • 注入检测是一个正则启发式规则列表,不是完整的 LLM 判断器或分类器。
  • 脱敏是尽力而为的模式匹配;它可能漏掉新型的机密格式。
  • Hermes 的启发是架构层面的(私信控制平面)。这不是完整的 Hermes 网关或配对栈。
  • 在此库之外,你仍需安全的令牌存储、最小权限工具和主机加固。

许可证

MIT。参见 LICENSE。

下载工具
控制项行为
允许列表仅配置的用户 ID 可继续。其他所有人均被丢弃(静默或返回一条简短的拒绝字符串)。
所有者与好友所有者跳过 PIN,并可以暂停整个代理。好友可能需要共享 PIN 才能获得限时开放(Hermes 式配对思路的简化版)。
紧急停止开关全局暂停文件或环境变量标志。开启期间不执行任何代理轮次。
速率限制按用户的滑动窗口(每分钟和每小时)。
输入检查最大长度、剥离异常控制字符、针对常见注入 / 窃密短语的正则启发式规则。
输出清洗对形似机密的令牌(API 密钥、JWT、Bearer 头)进行脱敏,并剥离可通过自动获取机制外传的 Markdown/HTML 图片信标。
审计日志追加式 JSONL,记录 allow/deny/auth/kill 事件,供后续审查。
本地命令/auth、/lock、/kill、/unkill、/status 无需调用模型即可处理。
键默认值含义
allowed_user_ids[]允许聊天的用户 ID
owner_ids[]跳过 PIN;可执行 /kill
pin_enabledTrue非所有者的 PIN 门禁
pin_ttl_hours72开放时长
rate_limit_per_minute8滑动窗口
rate_limit_per_hour60滑动窗口
max_input_chars2000最大输入长度
block_injectionTrue启发式阻止列表
deny_messageFalse静默、True 或自定义字符串
audit_logTrue写入审计 JSONL
enabledTrue总开关
变量用途
AGENTIC_DM_ALLOWLIST逗号分隔的用户 ID
AGENTIC_DM_OWNER_ID所有者 ID
AGENTIC_DM_PINPIN 明文
AGENTIC_DM_PIN_REQUIRED1 = 即使未设置也要求 PIN
AGENTIC_DM_KILLED1 = 启用紧急停止开关
AGENTIC_DM_DATA_DIRkill 文件、open 状态、审计日志的目录
AGENTIC_DM_SECRETS_DIR存放 dm_pin.txt / dm_allowlist.txt 的目录
命令适用对象效果
/kill /pause所有者为所有人暂停代理
/unkill /resume所有者清除暂停
/status所有者Kill / PIN / 允许列表快照
/auth <pin>允许列表用户打开 TTL 会话
/lock允许列表用户清除开放会话