Kali Linux & Gemini-Cli 详细实战教程从下载安装 到自动化安全测试

Kali Linux & Gemini-Cli 详细实战教程从下载安装 到自动化安全测试


一、前言:Kali Linux 2025.4 带来了什么?

Kali Linux 2025.4 的最大亮点之一,就是官方集成了 gemini-cli —— 一款可直接在终端中使用的 AI 安全助手。

它并不是“自动黑客工具”,而是:

  • 🧠 理解安全测试目标与上下文
  • 🛠️ 自动调用 nmap / nikto 等 Kali 工具
  • 📊 分析扫描结果并生成结构化报告
  • 🔐 内置沙箱、审批、检查点等安全机制

可以理解为:AI + Kali 工具链的统一指挥官


二、Kali Linux 2025.4 下载与安装

1️⃣ 官方下载地址

🔗 Kali Linux 2025.4 官方下载页
https://www.kali.org/get-kali/

支持:

  • Installer / Live ISO
  • VMware / VirtualBox 镜像
  • ARM(树莓派等)
  • NetInstaller

⚠️ 建议优先使用 官方预构建 VM 镜像,省时省力。


三、gemini-cli 简介

gemini-cli 是 Kali 官方维护的 AI 命令行工具,底层基于 Google Gemini 模型。

🔗 官方工具页:
https://www.kali.org/tools/gemini-cli/

它的能力包括:

  • 用自然语言描述安全测试任务
  • AI 自动拆解步骤
  • 选择合适的 Kali 工具执行
  • 解读输出并生成报告

四、安装 gemini-cli(一步到位)

1️⃣ 更新系统

1
sudo apt update

2️⃣ 安装 gemini-cli

1
sudo apt install gemini-cli

3️⃣ 验证是否安装成功

1
gemini-cli -h

若看到参数说明,说明安装完成。


五、基础使用教程

1️⃣ 查看帮助与参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
┌──(kali@kali)-[~]
└─$ gemini-cli -h
Usage: gemini [options] [command]

Gemini CLI - Launch an interactive CLI, use -p/--prompt for non-interactive mode

Commands:
gemini [query..] Launch Gemini CLI [default]
gemini mcp Manage MCP servers
gemini extensions <command> Manage Gemini CLI extensions.

Positionals:
query Positional prompt. Defaults to one-shot; use -i/--prompt-interactive for interactive.

Options:
-d, --debug Run in debug mode? [boolean] [default: false]
-m, --model Model [string]
-p, --prompt Prompt. Appended to input on stdin (if any).
[deprecated: Use the positional prompt instead. This flag will be removed in a future version.] [string]
-i, --prompt-interactive Execute the provided prompt and continue in interactive mode [string]
-s, --sandbox Run in sandbox? [boolean]
-y, --yolo Automatically accept all actions (aka YOLO mode, see https://www.youtube.com/watch?v=xvFZjo5PgG0 for more details)?
[boolean] [default: false]
--approval-mode Set the approval mode: default (prompt for approval), auto_edit (auto-approve edit tools), yolo (auto-approve all tools)
[string] [choices: "default", "auto_edit", "yolo"]
--experimental-acp Starts the agent in ACP mode [boolean]
--allowed-mcp-server-names Allowed MCP server names [array]
--allowed-tools Tools that are allowed to run without confirmation [array]
-e, --extensions A list of extensions to use. If not provided, all extensions are used. [array]
-l, --list-extensions List all available extensions and exit. [boolean]
--include-directories Additional directories to include in the workspace (comma-separated or multiple --include-directories) [array]
--screen-reader Enable screen reader mode for accessibility. [boolean]
-o, --output-format The format of the CLI output. [string] [choices: "text", "json", "stream-json"]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]

2️⃣ 指定模型

1
gemini --model gemini-pro

3️⃣ 单次提问(非交互模式)

1
gemini --prompt "Explain how SQL injection works"

适合:

  • 学习安全知识
  • 获取测试思路

4️⃣ 交互模式(强烈推荐)

1
gemini --prompt-interactive "You are a penetration testing assistant"

在该模式中,你可以连续对话,例如:

  • “我已经拿到 nmap 结果,帮我分析”
  • “下一步测试什么?”

六、安全防护机制(新手必须看)

1️⃣ 沙箱模式(sandbox)

用于高风险命令:

1
gemini --sandbox --prompt "Potentially dangerous command"

作用:

  • 限制系统访问
  • 防止误删关键文件

2️⃣ 审批模式(approval-mode)

涉及文件修改时:

1
gemini --approval-mode default --prompt "File modification task"

AI 每一步都会请求你确认。


3️⃣ 检查点(checkpointing)

1
gemini --checkpointing --prompt "Important file changes"

自动创建回滚点,适合配置与脚本操作。


七、高级功能详解

1️⃣ 分析整个项目(代码审计)

1
gemini --all-files --prompt "Analyze entire project for security issues"

适用于:

  • Web 源码审计
  • 配置安全检查

2️⃣ 扩展系统(调用 Kali 工具)

查看可用扩展

1
gemini --list-extensions

使用 nmap + 安全扫描扩展

1
gemini --extensions "security-scanner,nmap" --prompt "Security assessment"

八、完整实战:一条命令完成自动化安全测试

🎯 测试目标(示例)

  • 端口扫描
  • HTTP 服务指纹
  • Nikto 常见漏洞检测
  • SQL 注入 & XSS 初步检查
  • 生成 JSON 报告

⚠️ 以下命令仅限授权目标

🧠 AI 自动化扫描命令

1
gemini --extensions "nmap,nikto" --prompt "Scan http://xxxxx.com: find open ports, fingerprint HTTP server, run nikto for common vulns, check for SQL injection and XSS; generate a JSON report saved to /tmp/example_report.json"

📄 输出说明

AI 会自动:

  • 选择 nmap 扫描参数
  • 执行 nikto Web 扫描
  • 分析潜在 SQLi / XSS
  • 汇总结果
  • 输出 /tmp/example_report.json

该 JSON 可用于:

  • 报告系统
  • 自动化流程
  • 安全审计存档

九、最佳实践建议

✅ 始终开启 sandbox 进行未知操作
✅ 高风险任务配合 approval + checkpointing
✅ AI ≠ 自动黑客,而是智能助手
✅ 结合人工判断结果


十、总结

Kali Linux 2025.3 的 gemini-cli 标志着:

渗透测试正式进入 AI 协同时代。

它不会替你“违法攻击”,但会让你:

  • 更快完成信息收集
  • 更好理解漏洞风险
  • 更专业地输出报告

如果你熟悉 Kali,却还没用过 gemini-cli ——

🚀 现在就是最佳入门时机。