Skip to main content
Glama

pentest-kb MCP Server

侵入テストの経験ナレッジベースを扱う MCP サーバーです。MCP (Model Context Protocol) に基づき、検索・追加・一覧表示などのツールを提供し、侵入テストの実戦経験を蓄積・再利用するためのものです。

このプロジェクトが解決する問題

背景となる課題:

  • 侵入テストの経験がノート、チャット履歴、個人の記憶に散在しており、検索や再利用が難しい。同種の問題(WAF バイパス、403 バイパスなど)に直面するたびに、再度検索しなければならないことが多い

  • Agent はデフォルトでは個人のナレッジベースにアクセスできないため、侵入テストの質問に対して汎用的な知識に頼るしかなく、実戦経験による裏付けがないまま、具体性に欠けたアドバイスになりがち

  • 経験を蓄積できず、シーンをまたいで再利用できないため、個人やチームが積み上げた知識を体系化することが難しい

このプロジェクトの解決策:

  • 侵入テストの経験を PostgreSQL(Supabase)データベースに一元蓄積し、構造化して保存する

  • MCP プロトコルを通じてナレッジベースを Agent に接続し、Agent が経験を直接検索(search_experience)、追加(add_experience)、一覧表示(list_all_experiences)できるようにする

  • 検索は BM25 関連性ランキング(jieba による中国語分かち書き)に基づいており、単純な曖昧一致よりも正確

  • 実戦シーンでは、Agent が汎用知識だけに頼るのではなく、個人のナレッジベースに基づいて回答できるようにする

Related MCP server: mcp-rag-bridge

機能

  • search_experience(keyword, tags_filter):BM25 関連性ランキングに基づきナレッジベースを検索します(承認済みレコードのみ)。中国語の分かち書きに対応し、Top 10 を返します。tags_filter でシナリオタグによる精密フィルタリングが可能です(例:["WAF绕过"])

  • add_experience(title, detail, scenario_tags, tool_code, tool_type, status):経験を追加します。status='draft' の場合は承認待ちの下書きとして保存し(デフォルト)、status='approved' の場合は直接本登録します。書き込み前に自動でマスキング検証を実行します(実在 IP、ドメイン、認証情報、クラウドベンダーの AccessKey、JWT、秘密鍵、電話番号を検出し、該当する場合は拒否)

  • list_all_experiences(limit, offset):ナレッジベース内の承認済み全レコードのタイトルをページングで一覧表示します(デフォルト 1 ページ 50 件、最大 200 件)

  • find_similar(title, detail):重複チェックを行い、指定された内容に類似する登録済みレコードを検索します

  • get_experience(experience_id):id で経験 1 件の完全な内容(タイトル、詳細、タグ、ツールコード、ステータスなど)を取得します

  • update_experience(experience_id, title, detail, scenario_tags, tool_code, tool_type, status):経験のフィールドを更新します(渡されたフィールドのみ更新し、渡されていないフィールドは変更しません。変更前には自動でマスキング検証を実行します)

  • list_pending_experiences():承認待ちの下書きを一覧表示し、各下書きについて重複する可能性のある登録済みレコードを提示します

  • approve_experience(experience_id, merge_with_id):下書きを承認します。merge_with_id を指定すると、指定レコードにマージしてから(詳細を追記、タグを統合、ツール情報を補完)下書きを削除します

  • reject_experience(experience_id):下書きを拒否します(ソフト削除。レコードは rejected として保持され、復元可能)

  • delete_experience(experience_id):承認済みの経験をソフト削除します(ステータスを deleted に設定。検索対象には含まれず、復元可能)

  • restore_experience(experience_id):ソフト削除されたレコードを復元します(拒否された下書き→draft、削除された経験→approved)

  • list_deleted_experiences():ソフト削除された全レコード(ゴミ箱)を一覧表示します。復元や完全削除に利用できます

  • purge_experiences(days):ソフト削除されてから指定日数を超えたレコードを物理削除します(デフォルト 30 日、復元不可。注意して実行してください)

経験の蓄積と承認

自動蓄積による冗長な内容の生成や機密情報の漏えいを防ぐため、「半自動蓄積 + 強制マスキング + 人による承認」のフローを採用しています:

实战结束 → Agent 生成经验草稿(status='draft',结构化 + 限长 + 脱敏)
        → 草稿进入待审批状态(不直接入库,不参与检索)
        → 用户审批(list_pending 查看 → approve / reject / merge)
        → 通过后才正式入库(status='approved')

マスキング対策:add_experience は書き込み前に、実在 IP アドレス、ドメイン、メールアドレス、認証情報(中国語の「密码/口令/密钥/账号」など)、クラウドベンダーの AccessKey(AWS/Aliyun/Tencent)、JWT、秘密鍵ブロック、電話番号を自動検出し、該当する場合は書き込みを拒否して、プレースホルダー(例:<目标URL>、<目标域名>)への置換を要求します。プライベート/ループバック/リンクローカルなどの特殊な IP と、ホワイトリスト登録されたドメイン(example.com など)は本登録可能です。

重複チェック対策:承認時に list_pending_experiences が、各下書きについて重複する可能性のある登録済みレコードを自動的に提示します。ユーザーはスキップ、マージ、またはそのまま新規登録を選択できます。

直接本登録 vs 下書き承認:add_experience は status='approved' で直接本登録できますが、これはユーザーが手動で確認した入力シーンにのみ使用します。AI ワークフロー(SKILL.md を参照)では、必ず draft 下書きを生成して承認を受ける必要があり、直接本登録してはいけません。

依存関係

  • Python 3.10+

  • mcp(MCP Python SDK)

  • psycopg2(PostgreSQL ドライバ)

  • jieba(中国語分かち書き。起動時にルートディレクトリの pentest_dict.txt 分野辞書を自動ロード)

  • rank_bm25(BM25 検索アルゴリズム)

  • PostgreSQL データベース(Supabase など)

依存関係のインストール:

pip install -r requirements.txt

依存リストは requirements.txt を参照してください(バージョン範囲を固定済み。mcp は 2.x である必要があります)。

データベース初期化

PostgreSQL(Supabase など)で、リポジトリルートの schema.sql を実行します(冪等で、繰り返し実行可能):

# 方式一:Supabase 控制台 → SQL Editor → 粘贴 schema.sql 内容执行
# 方式二:命令行(需已配置 psql)
psql "$PENTEST_KB_DB_CONNECTION_STRING" -f schema.sql

テーブル構造は以下のとおりです(schema.sql が唯一の保守元であり、README では SQL を重複掲載しません):

フィールド

型

説明

id

uuid PK

主キー、デフォルトは gen_random_uuid()

created_at

timestamptz

作成日時

title

text

経験タイトル

scenario_tags

jsonb

シナリオタグ配列(例:["WAF绕过","SQL注入"])

experience_detail

text

経験の詳細

tool_code

text

悪用/ツールコード

tool_type

text

ツールタイプ(例:sqlmap、burp)

status

text

approved(承認済み)/ draft(承認待ち下書き)/ rejected(拒否、ソフト削除)/ deleted(ソフト削除)

deleted_at

timestamptz

ソフト削除日時(rejected/deleted のときに記録され、保持期間のクリーンアップに使用)

オプション:セマンティック検索列(現在のコードでは未使用。将来用に予約) ベクトルセマンティック検索を導入する場合は、schema.sql 末尾のコメントを解除して実行してください(事前に pgvector 拡張を有効にする必要があります)。

設定

データベース接続情報は環境変数で注入します。コード内に認証情報をハードコードしないでください:

環境変数

説明

PENTEST_KB_DB_HOST

データベースホストアドレス

PENTEST_KB_DB_PORT

ポート(デフォルト 5432)

PENTEST_KB_DB_NAME

データベース名(デフォルト postgres)

PENTEST_KB_DB_USER

データベースユーザー名

PENTEST_KB_DB_PASSWORD

データベースパスワード

PENTEST_KB_DB_MAXCONN

コネクションプールの最大接続数(オプション、デフォルト 10)

MCP クライアント設定

MCP クライアントでサーバーを登録します。mcp.example.json を参照してください:

{
  "mcpServers": {
    "pentest-kb": {
      "command": "python",
      "args": ["/absolute/path/to/pentest_kb_mcp.py"],
      "env": {
        "PENTEST_KB_DB_HOST": "your-supabase-host.pooler.supabase.com",
        "PENTEST_KB_DB_PORT": "5432",
        "PENTEST_KB_DB_NAME": "postgres",
        "PENTEST_KB_DB_USER": "postgres.your-project-ref",
        "PENTEST_KB_DB_PASSWORD": "your-database-password"
      }
    }
  }
}

使用方法

MCP クライアントでツールを呼び出すだけです。例:

搜索:search_experience(keyword="WAF绕过")   # BM25 相关性排序
搜索+标签过滤:search_experience(keyword="绕过", tags_filter=["WAF绕过"])   # 只看 WAF 相关
新增(直接入库,仅手动操作):add_experience(title="Nginx 403 绕过", detail="...", scenario_tags=["WAF绕过"], tool_type="burp", status="approved")
新增草稿:add_experience(title="...", detail="...")   # 默认 status='draft',待审批
查重:find_similar(title="...", detail="...")
查看单条:get_experience(experience_id="...")
修改:update_experience(experience_id="...", detail="...")   # 只更新传入字段
查看草稿:list_pending_experiences()
审批:approve_experience(experience_id="...")   # 或 merge_with_id 合并
拒绝:reject_experience(experience_id="...")   # 软删除,可恢复
删除:delete_experience(experience_id="...")   # 软删除已审批经验
恢复:restore_experience(experience_id="...")
回收站:list_deleted_experiences()
清理:purge_experiences(days=30)   # 物理删除超期软删记录
列出:list_all_experiences(limit=50, offset=0)   # 分页

Skill のカプセル化

カスタム Skill としてカプセル化済みです。ファイルはプロジェクトルートの SKILL.md にあり、実行フローに沿って 6 つのフェーズに整理されています:

  • フェーズ 1:意図の判断

  • フェーズ 2:情報収集の優先

  • フェーズ 3:ナレッジベース検索のトリガー

  • フェーズ 4:結果の引用と回答

  • フェーズ 5:実行と適用除外の規定

  • フェーズ 6:経験の蓄積

SKILL.md をカスタム Skill ディレクトリに配置すれば読み込まれます。

セキュリティについて

  • データベース認証情報は環境変数を通じてのみ注入され、リポジトリには実際の接続情報は一切含まれません

  • データベースのパスワードは定期的にローテーションし、弱いパスワードを避けてください

Available Tools

13 tools
add_experienceB

往经验库中新增一条渗透测试经验。 参数: title: 经验标题,如 'Nginx 403 绕过' detail: 详细描述,包括漏洞类型、利用过程、关键payload等 scenario_tags: 场景标签列表(可选),如 ['WAF绕过', 'SQL注入'] tool_code: 利用/工具代码(可选) tool_type: 工具类型(可选),如 'sqlmap'、'burp' status: 'draft'(存为待审批草稿,默认)或 'approved'(直接入库)

Inputs: title (required), detail (required), status, tool_code, +2 more. Returns: result

approve_experienceB

审批通过一条待审批草稿。 参数: experience_id: 草稿的 id merge_with_id: 可选。提供时,将草稿内容合并进指定记录(详情追加、标签合并、工具信息补全),然后删除草稿

Inputs: experience_id (required), merge_with_id. Returns: result

delete_experienceA

软删除一条已审批经验(状态置为 deleted,不参与检索,可恢复)。 参数: experience_id: 经验的 id

Inputs: experience_id (required). Returns: result

find_similarA

查重:查找与给定标题/详情相似的已入库经验,用于避免重复录入。 参数: title: 待查重的标题 detail: 待查重的详情(可选)

Inputs: title (required), detail. Returns: result

get_experienceC

按 id 获取一条经验的完整内容(标题、详情、标签、工具代码、状态等)。 参数: experience_id: 经验的 id

Inputs: experience_id (required). Returns: result

list_all_experiencesA

分页列出经验库中所有已审批记录的标题。 参数: limit: 每页条数(默认 50,最大 200) offset: 偏移量(默认 0)

Inputs: limit, offset. Returns: result

list_deleted_experiencesA

列出所有软删除的记录(被拒绝的草稿 + 被删除的经验),便于恢复或彻底清理。

Inputs: no named parameters. Returns: result

list_pending_experiencesA

列出待审批的经验草稿,并提示每条草稿可能重复的已入库记录。

Inputs: no named parameters. Returns: result

purge_experiencesA

彻底删除软删除超过指定天数的记录(物理删除,不可恢复,请谨慎)。 参数: days: 保留天数,软删除超过该天数的记录将被物理删除(默认 30)

Inputs: days. Returns: result

reject_experienceA

拒绝一条待审批草稿(软删除:记录保留,状态置为 rejected,可恢复)。 参数: experience_id: 草稿的 id

Inputs: experience_id (required). Returns: result

restore_experienceB

恢复一条软删除的记录:被拒绝的草稿恢复为 draft,被删除的经验恢复为 approved。 参数: experience_id: 记录的 id

Inputs: experience_id (required). Returns: result

search_experienceA

搜索渗透测试经验库(仅已审批记录)。基于 BM25 相关性排序,支持中文分词。 参数: keyword: 搜索关键词,如 'WAF绕过'、'SQL注入'、'403' tags_filter: 场景标签过滤(可选),如 ['WAF绕过'],仅返回包含全部指定标签的记录

Inputs: keyword (required), tags_filter. Returns: result

update_experienceB

更新一条经验的字段(只更新传入的字段,未传字段保持不变)。修改前自动做脱敏校验。 参数: experience_id: 经验的 id title: 新标题(可选) detail: 新详情(可选) scenario_tags: 新标签列表(可选) tool_code: 新工具代码(可选) tool_type: 新工具类型(可选) status: 新状态(可选,approved/draft/rejected/deleted)

Inputs: experience_id (required), title, detail, status, +3 more. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 13 tools

    Disambiguation4/5

    Most tools have clearly distinct purposes: the three list_* tools are scoped by status (all/pending/deleted), and search vs. list vs. find_similar are distinguishable. However, update_experience can also set status to approved/rejected, overlapping with the dedicated approve_experience and reject_experience tools, and the delete/reject/purge triad requires careful reading to tell apart.

    Naming Consistency5/5

    All 13 tools follow a consistent snake_case verb_noun pattern (list_*, get_*, add_*, update_*, delete_*, restore_*, approve_*, reject_*, search_experience, find_similar, purge_experiences). No convention mixing.

    Tool Count5/5

    13 tools is well-scoped for a knowledge base with CRUD, search, moderation workflow, dedup, and soft-delete lifecycle. Each tool earns its place with a distinct role.

    Completeness5/5

    Full lifecycle is covered: create/add, get, update, search, paginated listing, approval/rejection moderation, dedup checking, soft-delete, restore, and physical purge. No obvious dead ends for the stated domain.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI agents with persistent knowledge storage, enabling them to store, search, and retrieve text, documents, and files using semantic and keyword search via MCP tools.
      35
      Apache 2.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to query and manage a document knowledge base via MCP, with RAG-powered search and grounded answers with citations.
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A knowledge base MCP server that aggregates team knowledge from multiple sources into Postgres. It provides hybrid search (full-text + vector + RRF) via MCP tools, and enables direct recording of decisions, learnings, and pitfalls.
      15
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents and MCP clients to search, retrieve, and read documents across unified knowledge sources including ShowDoc, GitHub, Gitee, ZenTao, Evernote, and Tencent Docs. It also supports connecting external MCP servers as additional knowledge sources.
      MIT