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

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

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

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

工具目录

分类

查看所有分类
Loading categories
TS_LLMLib — Python库,用于本地LLM驱动的安全分析,集成Ghidra二进制分析、C/C++漏洞扫描和MCP工具集成,实现自动化逆向工程和报告生成。 | Kitploit
工具/GitHubGitHub/trustedsec/ts_llmlib
静态分析漏洞分析代码分析漏洞利用逆向工程脚本与自动化实用工具与框架二进制分析机器学习AI 安全
GitHubtrustedsec/ts_llmlib

TS_LLMLib

Python库,用于本地LLM驱动的安全分析,集成Ghidra二进制分析、C/C++漏洞扫描和MCP工具集成,实现自动化逆向工程和报告生成。

12个月前尚未审核

最受欢迎

查看全部 →

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

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
查看仓库

ts_llmlib - TrustedSec LLM 库

TrustedSec LLM 库 是一个用于与支持工具调用的本地大语言模型进行交互的 Python 库。通过利用本地 LLM 端点与 MCP(模型上下文协议)集成,它可以运行通常只有前沿模型才能实现的大规模工作流。

特性

  • 本地 LLM 支持:连接任何兼容 OpenAI 的 API 端点,或使用本地 LLM 服务器
  • MCP 集成:完整支持 RPC 和 SSE 协议的模型上下文协议
  • 工具注册表:内置文件操作工具,并支持扩展自定义工具
  • 对话历史:在多轮对话中保持聊天上下文
  • 时间限制:可配置的执行超时,防止操作失控
  • 纯 Python:除标准库外无外部依赖

安装

作为 Python 包安装

root@kitploit:~
# 克隆或复制仓库
git clone https://github.com/trustedsec/ts_llmlib.git
cd ts_llmlib

# 使用 pip 安装
pip install -e .

手动安装

将 ts_llmlib/ 目录复制到你的项目中:

root@kitploit:~
cp -rf ts_llmlib /path/to/your/project/

快速开始

基本用法

root@kitploit:~
from ts_llmlib import ChatSession

# 使用默认设置初始化(连接到 http://localhost:1234/v1/chat/completions)
chat = ChatSession()

# 运行提示词
response = chat.run_prompt("当前目录下有哪些文件?")
print(response['content'])

自定义配置

root@kitploit:~
from ts_llmlib import ChatSession

# 使用自定义设置配置
chat = ChatSession(
    system_prompt="你是一个乐于助人的助手,善于使用文件工具。",
    tool_list=[],  # 空列表 = 使用默认文件工具
    mcp_servers={
        "default": "http://localhost:3000/mcp"
    },
    llm_endpoint_url="http://localhost:1234/v1/chat/completions",
    model_name="qwen3-coder-next",
    timeout=60,
    max_runtime=300
)

response = chat.run_prompt("将 'hello' 写入 /tmp/greeting.txt")
print(response['content'])

使用对话历史

root@kitploit:~
from ts_llmlib import ChatSession

chat = ChatSession()

history = [
    {"role": "user", "content": "2+2 等于几?"},
    {"role": "assistant", "content": "答案是 4。"}
]

response = chat.run_prompt("你能把它写入文件吗?", history=history)

内置工具

工具

MCP 集成

MCP(模型上下文协议)支持与外部工具和服务集成。配置了 MCP 服务器后,ts_llmlib 将:

  1. 初始化与每个服务器的连接
  2. 从服务器获取可用工具
  3. 将其与内置工具合并(名称冲突时 MCP 工具优先)
  4. 使用相应服务器执行工具调用

以 Ghidra MCP 服务器为例

root@kitploit:~
from ts_llmlib import ChatSession

chat = ChatSession(
    mcp_servers={
        "ghidraSvr": "http://localhost:8081/sse"
    },
    llm_endpoint_url="http://localhost:1234/v1/chat/completions",
    model_name="qwen3-coder-next"
)

# 聊天会话将自动获取并集成 Ghidra 工具
# 例如 list_methods, decompile_function, get_xrefs_to 等

MCP 服务器端点

ts_llmlib 支持 RPC 风格和 SSE(服务器推送事件)端点:

  • RPC:http://localhost:3000/mcp
  • SSE:http://localhost:3000/sse(RPC 调用时自动转换为 /mcp)

API 参考

ChatSession 类

root@kitploit:~
ChatSession(
    system_prompt: str | None = None,
    tool_list: list | None = None,
    mcp_servers: dict[str, str] | None = None,
    llm_endpoint_url: str = "http://localhost:1234/v1/chat/completions",
    model_name: str = "default",
    timeout: int = 60,
    max_runtime: int = 300
)

参数说明:

  • system_prompt (str | None):自定义系统提示词。默认为一个最小化助手提示词。
  • tool_list (list | None):自定义工具定义列表。空列表使用内置工具。
  • mcp_servers (dict[str, str] | None):服务器名称到 URL 的字典。
  • llm_endpoint_url (str):LLM API 端点的 URL。
  • model_name (str):LLM 端点的模型标识符。
  • timeout (int):HTTP 请求超时时间(秒)。
  • max_runtime (int):单次提示词的最大执行时间(秒)。

run_prompt 方法

root@kitploit:~
response = chat.run_prompt(
    user_prompt: str,
    conversation_history: list[dict] | None = None,
    disable_tools: list[str] | None = None,
    max_runtime: int | None = None
) -> dict

参数说明:

  • user_prompt (str):用户的消息或问题。
  • conversation_history (list[dict] | None):可选的对话历史,格式为角色/内容对列表。
  • disable_tools (list[str] | None):本次调用中禁用的工具名称列表。
  • max_runtime (int | None):为本次调用覆盖默认的最大运行时间。

返回值:

root@kitploit:~
{
    "content": str,           # LLM 响应文本
    "tool_calls": list,       # 工具调用列表(如果有)
    "usage": dict | None,     # 令牌用量(如果 LLM 提供)
    "error": str | None       # 错误信息(如果失败)
}

工具注册表

ToolRegistry 管理聊天会话可用的所有工具:

  • 内置工具:文件操作(读/写/列出)
  • MCP 工具:从 MCP 服务器获取的工具
  • 自定义工具:通过 tool_list 参数定义的用户工具

示例

要覆盖默认路径,可以设置以下变量,这些变量会在 ChatSession 中被检查。

root@kitploit:~
TS_LLM_MODEL=qwen3-coder-next TS_LLM_ENDPOINT=http://HOSTNAME:1234/v1/chat/completions
# 使用示例
export TS_LLM_MODEL=qwen3-coder-next
export TS_LLM_ENDPOINT=http://HOSTNAME:1234/v1/chat/completions
ts_llmlib-redclippy
# 或者
TS_LLM_MODEL=qwen3-coder-next TS_LLM_ENDPOINT=http://HOSTNAME:1234/v1/chat/completions ts_llmlib-redclippy

C/C++ 源代码分析

分析 C/C++ 源文件中的安全漏洞:

root@kitploit:~
ts_llmlib-cpp-analyze <source_folder> <output_folder>

Ghidra 二进制分析

集成 Ghidra 的逆向工程二进制分析:

root@kitploit:~
# 基本分析
ts_llmlib-ghidra-analyze <output_folder>

# 仅重命名模式(第一遍)
ts_llmlib-ghidra-analyze --rename_only <output_folder>

# 仅处理先前未命名的函数
ts_llmlib-ghidra-analyze --process_unnamed_only <output_folder>

# 分组分析(用于调用关系分组)
ts_llmlib-ghidra-analyze --grouped <output_folder>

如果不使用 --rename_only 运行完毕后,可以通过以下命令清理结构:

root@kitploit:~
ts_llmlib-ghidra-cleanup <input_folder> <output_folder>

漏洞报告生成

从 JSON 审查文件生成格式化漏洞报告:

root@kitploit:~
ts_llmlib-ghidra-report <review_folder>

GUI 聊天应用

运行基于 Qt 的 RedClippy 聊天界面(注意此示例需要 pyside6):

root@kitploit:~
ts_llmlib-redclippy

配置选项

LLM 端点配置

ts_llmlib 连接到任何兼容 OpenAI 的 API 端点。常见的本地 LLM 服务器:

服务器默认 URL
Ollamahttp://localhost:11434/v1/chat/completions
LM Studiohttp://localhost:1234/v1/chat/completions
vLLMhttp://localhost:8000/v1/chat/completions

时间限制

两个超时设置控制执行:

  • HTTP 超时 (timeout):单次 API 请求的最大时间
  • 最大运行时间 (max_runtime):处理提示词(包括工具调用)允许的总墙钟时间

如果超过任一限制,响应中将包含错误信息。

错误处理

所有错误都在响应字典中返回:

root@kitploit:~
response = chat.run_prompt("某个提示词")

if response.get('error'):
    print(f"错误:{response['error']}")
else:
    print(response['content'])

常见错误

  • HTTP 错误:连接被拒绝、超时、API 密钥无效
  • JSON 解析错误:无效的工具参数或格式错误的响应
  • 工具执行错误:文件缺失、权限问题、无效参数
  • 超时错误:操作超过了 max_runtime 限制

项目结构

root@kitploit:~
ts_llmlib/
├── __init__.py          # 包初始化,导出 ChatSession
├── client.py            # 用于向 LLM 端点发起 HTTP 请求的 LLMClient
├── chat.py              # ChatSession 类(主要 API)
├── mcp.py               # 用于模型上下文协议集成的 MCPClient
├── tools.py             # 用于工具管理的 ToolRegistry
├── HOW_TO_TS_LLMLIB.md  # 原始文档
└── examples/            # 示例脚本
    ├── c_cpp_analyze.py     # C/C++ 漏洞分析脚本
    ├── redclippy.py         # 基于 Qt 的 GUI 聊天应用
    ├── ghidra_analyze.py    # 集成 MCP 的 Ghidra 二进制分析
    ├── ghidra_vuln_report.py  # 漏洞报告生成器
    ├── ghidra_cleanup.py    # 输出文件重组工具
    └── example_ts_llmlib.py # 演示库用法的示例脚本

pyproject.toml         # 现代 Python 包配置(脚本在此定义)
LICENSE.txt            # BSD-3-Clause 许可证
README.md              # 本文件

许可证

BSD-3-Clause 许可证 - 详情请见 LICENSE.txt 文件。

贡献

欢迎贡献!请随时提交拉取请求。

  1. Fork 本仓库
  2. 创建你的特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交你的更改 (git commit -m '添加一些 AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开一个拉取请求
下载工具
参数
描述
read_local_filepath: str读取本地文件内容
write_local_filepath: str, content: str将内容写入本地文件
list_directorypath: str列出路径下的文件和目录