
LLMを使用したゼロショット脆弱性発見
LLMと静的コード解析を使用して、リモートで悪用可能な脆弱性を特定するツールです。
世界初の自律型AIが発見した0day脆弱性
Vulnhuntrは、LLMの力を活用して、リモートのユーザー入力から始まりサーバー出力に至るコード呼び出しチェーン全体を自動的に作成・分析し、従来の静的コード解析ツールの能力をはるかに超える、複雑で多段階のセキュリティ回避型脆弱性を検出します。すべての0dayに対するVulnhuntrの出力を含む詳細はこちら: Protect AI Vulnhuntr Blog
[!TIP] Vulnhuntrを使用して脆弱性を発見しましたか? huntr.com にレポートを提出して$$を獲得し、以下のリストに追加するPRを送信してください!
[!NOTE] この表はこれまでに発見された脆弱性の一部です。責任ある開示期間が終了し次第、伏せ字を解除します。
| リポジトリ | スター数 | 脆弱性 |
|---|---|---|
| gpt_academic | 67k | LFI, XSS |
| ComfyUI | 66k | XSS |
| Langflow | 46k | RCE, IDOR |
| FastChat | 37k | SSRF |
| Ragflow | 31k | RCE |
| LLaVA | 21k | SSRF |
| gpt-researcher | 17k | AFO |
| Letta | 14k | AFO |
[!IMPORTANT] Vulnhuntrは、Pythonコードの解析に使用するJediに多数のバグがあるため、Python 3.10を厳密に必要とします。他のバージョンのPythonでインストールした場合、確実には動作しません。
Vulnhuntrの簡単なインストールと実行には、pipxまたはDockerの使用をお勧めします。
Dockerを使用する場合:
docker build -t vulnhuntr https://github.com/protectai/vulnhuntr.git#main
pipxを使用する場合:
pipx install git+https://github.com/protectai/vulnhuntr.git --python python3.10
または、poetryを使用してソースから直接インストールすることもできます:
git clone https://github.com/protectai/vulnhuntr
cd vulnhuntr && poetry install
このツールは、GitHubリポジトリを分析してリモートで悪用可能な潜在的な脆弱性を検出するために設計されています。このツールにはAPIキーとGitHubリポジトリのローカルパスが必要です。オプションでLLMサービスのカスタムエンドポイントを指定することもできます。
[!CAUTION] 使用するLLMプロバイダーで常に支出制限を設定するか、コストを注意深く監視してください。このツールは、LLMのコンテキストウィンドウに可能な限り多くのコードを収めようとするため、高額な請求が発生する可能性があります。
[!TIP] LLMにはClaudeの使用をお勧めします。テストを通じて、GPTよりもClaudeの方が良い結果が得られています。
usage: vulnhuntr [-h] -r ROOT [-a ANALYZE] [-l {claude,gpt,ollama}] [-v]
Analyze a GitHub project for vulnerabilities. Export your ANTHROPIC_API_KEY/OPENAI_API_KEY before running.
options:
-h, --help show this help message and exit
-r ROOT, --root ROOT Path to the root directory of the project
-a ANALYZE, --analyze ANALYZE
Specific path or file within the project to analyze
-l {claude,gpt,ollama}, --llm {claude,gpt,ollama}
LLM client to use (default: claude)
-v, --verbosity Increase output verbosity (-v for INFO, -vv for DEBUG)
pipxインストールから、Claudeを使用してリポジトリ全体を分析する:
export ANTHROPIC_API_KEY="sk-1234"
vulnhuntr -r /path/to/target/repo/
[!TIP] リモートのユーザー入力を受け取る特定のファイルをVulnhuntrに指定し、個別にスキャンすることをお勧めします。
pipxインストールから、GPT-4oを使用して/path/to/target/repo/server.pyファイルを分析する。ファイルの代わりにサブディレクトリを指定することもできます:
export OPENAI_API_KEY="sk-1234"
vulnhuntr -r /path/to/target/repo/ -a server.py -l gpt
Dockerインストールから、Claudeとカスタムエンドポイントを使用して/local/path/to/target/repo/repo-subfolder/target-file.pyを分析する:
docker run --rm -e ANTHROPIC_API_KEY=sk-1234 -e ANTHROPIC_BASE_URL=https://localhost:1234/api -v /local/path/to/target/repo:/repo vulnhuntr:latest -r /repo -a repo-subfolder/target-file.py
実験的
Ollamaはオプションとして含まれていますが、オープンソースモデルが出力を正しく構造化する点では成功していません。
export OLLAMA_BASE_URL=http://localhost:11434/api/generate
export OLLAMA_MODEL=llama3.2
vulnhuntr -r /path/to/target/repo/ -a server.py -l ollama

[!TIP] 一般的に、信頼度スコアが7未満の場合は脆弱性が存在する可能性は低いことを意味します。スコア7は調査が必要であることを意味し、スコア8以上は有効な脆弱性である可能性が非常に高いことを意味します。
このツールは、分析されたファイルで見つかった脆弱性の詳細なレポートを生成します。レポートには以下が含まれます:
以下は、Ragflow(現在は修正済み)における0dayリモートコード実行脆弱性を説明するVulnhuntrレポートの例です:
scratchpad:
1. Analyzing the add_llm function in llm_app.py. 2. Identified user input used as keys to access dictionaries: EmbeddingModel, ChatModel, RerankModel,
CvModel, and TTSModel. 3. These dictionaries contain class references, which are instantiated with user-supplied parameters. 4. The factory variable is
directly used from user input (req['llm_factory']) without proper validation. 5. The llm_name is also derived from user input in most cases. 6. The
instantiation of these classes occurs in try-except blocks, but exceptions are only used for error messages, not preventing execution. 7. The api_key
and other sensitive information are passed directly to these instantiated classes. 8. There's no comprehensive input validation or sanitization for the
factory or llm_name variables. 9. The vulnerability is in a route decorated with @login_required, indicating it's accessible to authenticated users. 10.
Reviewing the EmbeddingModel, ChatModel, RerankModel, CvModel, and TTSModel dictionaries to understand their contents and potential for exploitation.
----------------------------------------
analysis:
The add_llm function in llm_app.py contains a critical Remote Code Execution (RCE) vulnerability. The function uses user-supplied input
(req['llm_factory'] and req['llm_name']) to dynamically instantiate classes from the EmbeddingModel, ChatModel, RerankModel, CvModel, and TTSModel
dictionaries. This pattern of using user input as a key to access and instantiate classes is inherently dangerous, as it allows an attacker to
potentially execute arbitrary code. The vulnerability is exacerbated by the lack of comprehensive input validation or sanitization on these
user-supplied values. While there are some checks for specific factory types, they are not exhaustive and can be bypassed. An attacker could potentially
provide a malicious value for 'llm_factory' that, when used as an index to these model dictionaries, results in the execution of arbitrary code. The
vulnerability is particularly severe because it occurs in a route decorated with @login_required, suggesting it's accessible to authenticated users,
which might give a false sense of security.
----------------------------------------
poc:
POST /add_llm HTTP/1.1
Host: target.com
Content-Type: application/json
Authorization: Bearer <valid_token>
{
"llm_factory": "__import__('os').system",
"llm_name": "id",
"model_type": "EMBEDDING",
"api_key": "dummy_key"
}
This payload attempts to exploit the vulnerability by setting 'llm_factory' to a string that, when evaluated, imports the os module and calls system.
The 'llm_name' is set to 'id', which would be executed as a system command if the exploit is successful.
----------------------------------------
confidence_score:
8
----------------------------------------
vulnerability_types:
- RCE
----------------------------------------
このツールは、分析プロセスと結果をvulnhuntr.logという名前のファイルに記録します。このファイルには、初期評価と二次評価を含む分析の各ステップに関する詳細情報が含まれています。