安全工具自动化脚本开发:用 Python 整合 Nmap+Burp在这里插入图片描述

做安全测试时,你是否常陷入 “重复操作循环”—— 用 Nmap 扫完资产,手动复制 IP 和端口到 Burp;扫完一个目标,又要回到 Nmap 切换下一个网段;最后还要手动整理两份工具的输出结果。这种 “工具割裂” 不仅浪费 1-2 小时 / 天,还容易因人工操作遗漏高危目标。

本文教你用 Python 开发自动化脚本,实现 “Nmap 扫描存活资产→提取 HTTP/HTTPS 目标→Burp 自动发起主动扫描→生成整合报告” 的全流程自动化,核心解决 “工具间数据流转” 和 “重复操作” 问题,附完整代码与避坑指南,新手 1 小时即可跑通。

一、自动化的核心价值与实现逻辑

1. 手动操作的 3 大痛点(为什么要自动化)

痛点场景 耗时占比 自动化解决方案
Nmap 扫完后手动筛选 HTTP 服务 30% Python 解析 Nmap 结果,自动提取 80/443 端口目标
复制目标到 Burp 并发起扫描 40% 调用 Burp REST API,批量创建扫描任务
整理 Nmap+Bupr 结果到报告 30% 脚本自动合并结果,生成 Markdown 报告

2. 技术实现逻辑(工具联动原理)

通过 Python 作为 “中间调度器”,打通 Nmap 与 Burp 的数据链路:

  1. Nmap 侧:用python-nmap库调用 Nmap 扫描,输出 XML 格式结果,Python 解析后提取 “IP: 端口” 形式的 HTTP/HTTPS 目标;

  2. Burp 侧:启用 Burp 的 REST API(需安装插件),Python 通过 API 将目标传入 Burp,触发主动扫描;

  3. 数据流转:Nmap 结果→Python 解析→Burp API 调用→Burp 扫描→Python 获取扫描结果→生成整合报告。

3. 前置依赖(10 分钟配齐环境)

工具 / 库 版本要求 作用 安装方式
Python ≥3.8 脚本开发运行 官网下载(https://www.python.org/
python-nmap ≥0.7.1 调用 Nmap 扫描 pip install python-nmap
requests ≥2.31.0 调用 Burp REST API pip install requests
Nmap ≥7.95 资产扫描 官网下载(Windows/macOS/Linux 均支持)
Burp Suite Professional ≥2025.3 漏洞检测 需激活专业版,安装 “Burp REST API” 插件(BApp Store 中搜索 “REST API”)

二、Step 1:配置 Burp REST API(关键前提)

Burp 默认不开启 API,需先配置插件,让 Python 能通过接口控制 Burp:

1. 安装 Burp REST API 插件

  1. 打开 Burp→Extender → BApp Store,搜索 “Burp REST API”,点击 “Install” 安装;

  2. 安装完成后,插件会自动生成 API 密钥(记下来,后续脚本要用),默认端口为8090。

2. 验证 API 可用性

  1. 保持 Burp 运行,打开浏览器访问http://localhost:8090/api/v0.1/scan,若提示 “Unauthorized”,说明 API 已启动(需带密钥访问);

  2. 用 Postman 发送 GET 请求验证(后续脚本会自动实现):

  • URL:http://localhost:8090/api/v0.1/scan

  • Headers:X-API-Key: 你的API密钥

  • 若返回空列表(无扫描任务),说明 API 配置正常。

三、Step 2:核心脚本开发(分模块实现)

脚本分 3 个核心模块:Nmap扫描与结果解析→Burp扫描任务创建→结果整合与报告生成,每个模块独立可调试,新手可分步实现。

1. 模块 1:Nmap 扫描与存活 HTTP 目标提取

功能:输入目标网段(如192.168.1.0/24),调用 Nmap 扫描存活主机的 80/443/8080 端口,提取 HTTP/HTTPS 服务的 “IP: 端口”。

import nmap
import re

def nmap_scan(target, ports="80,443,8080"):
    """
    Nmap扫描目标网段,提取HTTP/HTTPS服务
    :param target: 目标网段(如192.168.1.0/24)
    :param ports: 待扫描端口(默认80,443,8080)
    :return: http_targets(列表,格式["http://192.168.1.100:80", "https://192.168.1.101:443"])
    """
    print(f"[+] 开始Nmap扫描:目标{target},端口{ports}")
    # 初始化Nmap扫描器(Linux需sudo权限,Windows直接运行)
    nm = nmap.PortScanner()
    # 执行扫描:-sn ping扫描(存活检测),-p指定端口,-sV探测服务版本
    try:
        nm.scan(hosts=target, ports=ports, arguments="-sn -sV")
    except Exception as e:
        print(f"[-] Nmap扫描失败:{str(e)}")
        return []
    
    http_targets = []
    # 遍历扫描结果,提取存活主机的HTTP/HTTPS服务
    for host in nm.all_hosts():
        if nm[host].state() == "up":  # 只处理存活主机
            print(f"[+] 发现存活主机:{host}")
            for proto in nm[host].all_protocols():  # 遍历TCP/UDP协议
                if proto != "tcp":
                    continue
                ports = nm[host][proto].keys()  # 获取开放的TCP端口
                for port in ports:
                    service = nm[host][proto][port]["name"]  # 服务名称(http/https/http-proxy)
                    # 判断是否为HTTP/HTTPS服务
                    if service in ["http", "https", "http-proxy"]:
                        # 构建目标URL(http/https自动区分)
                        if service == "https" or port == 443:
                            url = f"https://{host}:{port}"
                        else:
                            url = f"http://{host}:{port}"
                        http_targets.append(url)
                        print(f"  - 发现HTTP服务:{url}")
    
    print(f"[+] Nmap扫描完成,共提取{len(http_targets)}个HTTP/HTTPS目标")
    return http_targets

# 测试模块1:扫描本地网段
if __name__ == "__main__":
    test_target = "192.168.1.0/24"  # 替换为你的目标网段
    targets = nmap_scan(test_target)
    print("提取的HTTP目标:", targets)
模块 1 关键说明:
  • Nmap 参数:-sn跳过端口扫描(先快速检测存活),-sV识别服务版本,避免误判非 HTTP 服务;

  • 权限问题:Linux/macOS 运行需在终端执行sudo python 脚本名.py(Nmap 扫描需要 root 权限),Windows 直接双击运行;

  • 结果过滤:通过服务名称(http/https/http-proxy)和端口(443 默认 HTTPS)双重判断,确保提取的是有效 HTTP 目标。

2. 模块 2:调用 Burp API 发起主动扫描

功能:接收模块 1 提取的 HTTP 目标,通过 Burp REST API 创建扫描任务,等待扫描完成后获取漏洞结果。

import requests
import time

def burp_scan(targets, burp_api_key, burp_url="http://localhost:8090/api/v0.1"):
    """
    调用Burp API发起主动扫描,获取漏洞结果
    :param targets: HTTP目标列表(模块1输出)
    :param burp_api_key: Burp API密钥(插件生成的密钥)
    :param burp_url: Burp API地址(默认localhost:8090)
    :return: scan_results(字典,key为目标URL,value为漏洞列表)
    """
    if not targets:
        print("[-] 无HTTP目标,跳过Burp扫描")
        return {}
    
    headers = {
        "X-API-Key": burp_api_key,
        "Content-Type": "application/json"
    }
    scan_results = {}
    
    # 1. 为每个目标创建Burp扫描任务
    task_ids = []
    for target in targets:
        print(f"[+] 为{target}创建Burp扫描任务")
        # 创建扫描任务的API请求体(主动扫描配置)
        scan_config = {
            "urls": [target],
            "scan_configurations": [
                {
                    "name": "Default Active Scan",  # 使用Burp默认主动扫描配置
                    "type": "NamedConfiguration"
                }
            ],
            "scope": {
                "include": [{"rule": "Domain", "target": target.split("//")[-1].split(":")[0]}],  # 扫描范围限制为目标域名
                "exclude": []
            }
        }
        # 发送创建扫描任务请求
        try:
            resp = requests.post(
                f"{burp_url}/scan",
                headers=headers,
                json=scan_config,
                timeout=30
            )
            resp.raise_for_status()  # 若HTTP状态码非200,抛出异常
            task_id = resp.json()["task_id"]
            task_ids.append({"target": target, "task_id": task_id})
            print(f"  - 任务创建成功,ID:{task_id}")
        except Exception as e:
            print(f"[-] 创建{target}扫描任务失败:{str(e)}")
            continue
    
    # 2. 等待所有扫描任务完成(每30秒检查一次)
    print(f"[+] 共{len(task_ids)}个扫描任务,等待完成...")
    while True:
        completed_tasks = 0
        for task in task_ids:
            if "completed" in task and task["completed"]:
                completed_tasks += 1
                continue
            # 检查任务状态
            try:
                resp = requests.get(
                    f"{burp_url}/scan/{task['task_id']}",
                    headers=headers,
                    timeout=10
                )
                status = resp.json()["status"]  # 状态:running/completed/failed
                if status == "completed":
                    task["completed"] = True
                    completed_tasks += 1
                    print(f"[+] {task['target']} 扫描完成")
                elif status == "failed":
                    task["completed"] = True
                    completed_tasks += 1
                    print(f"[-] {task['target']} 扫描失败")
            except Exception as e:
                print(f"[-] 检查{task['target']}任务状态失败:{str(e)}")
                continue
        # 所有任务完成,退出循环
        if completed_tasks == len(task_ids):
            break
        time.sleep(30)  # 每30秒检查一次
    
    # 3. 获取每个任务的漏洞结果
    for task in task_ids:
        target = task["target"]
        task_id = task["task_id"]
        try:
            resp = requests.get(
                f"{burp_url}/scan/{task_id}/issues",
                headers=headers,
                timeout=10
            )
            issues = resp.json()  # 漏洞列表(每个元素是一个漏洞详情)
            # 提取关键漏洞信息(简化输出)
            simplified_issues = []
            for issue in issues:
                simplified_issues.append({
                    "severity": issue["severity"],  # 风险等级(High/Medium/Low/Info)
                    "name": issue["name"],          # 漏洞名称(如SQL Injection)
                    "location": issue["location"],  # 漏洞位置(URL+参数)
                    "description": issue["description"][:100] + "..."  # 漏洞描述(截取前100字)
                })
            scan_results[target] = simplified_issues
            print(f"[+] {target} 共发现{len(simplified_issues)}个漏洞")
        except Exception as e:
            print(f"[-] 获取{target}漏洞结果失败:{str(e)}")
            scan_results[target] = []
    
    return scan_results

# 测试模块2:需先运行模块1获取targets,再执行
if __name__ == "__main__":
    # 替换为你的实际数据
    test_targets = ["http://192.168.1.100:80", "https://192.168.1.101:443"]
    test_api_key = "你的Burp API密钥"  # 替换为插件生成的密钥
    results = burp_scan(test_targets, test_api_key)
    print("Burp扫描结果:", results)
模块 2 关键说明:
  • 扫描配置:使用 Burp 默认主动扫描配置(Default Active Scan),包含 SQL 注入、XSS 等常见漏洞检测;若需自定义,可在 Burp 中创建配置并替换scan_configurations中的 “name”;

  • 状态检查:通过循环查询任务状态(running/completed),避免扫描未完成就获取结果;

  • 结果简化:从 Burp 返回的详细漏洞信息中提取 “风险等级、名称、位置、描述”,便于后续报告展示。

3. 模块 3:结果整合与 Markdown 报告生成

功能:合并 Nmap 扫描结果和 Burp 漏洞结果,生成结构化 Markdown 报告,方便后续分享或归档。

import datetime

def generate_report(nmap_targets, burp_results, report_path="security_scan_report.md"):
    """
    生成Nmap+Bupr整合报告(Markdown格式)
    :param nmap_targets: Nmap提取的HTTP目标列表
    :param burp_results: Burp扫描结果(模块2输出)
    :param report_path: 报告保存路径
    """
    print(f"[+] 生成扫描报告:{report_path}")
    # 报告内容模板
    report_content = f"""# 安全扫描报告
## 报告信息
- 扫描时间:{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
- 扫描范围:{', '.join(nmap_targets) if nmap_targets else '无'}
- 扫描工具:Nmap + Burp Suite
- 报告生成工具:Python自动化脚本

## 1. Nmap资产扫描结果
共发现{len(nmap_targets)}个HTTP/HTTPS服务,清单如下:
| 序号 | 目标URL | 服务类型 |
|------|---------|----------|
"""
    # 填充Nmap结果表格
    for i, target in enumerate(nmap_targets, 1):
        service_type = "HTTPS" if target.startswith("https") else "HTTP"
        report_content += f"| {i} | {target} | {service_type} |\n"
    
    # 填充Burp漏洞结果
    report_content += "\n## 2. Burp漏洞扫描结果\n"
    high_count = 0  # 统计高危漏洞数量
    for target, issues in burp_results.items():
        if not issues:
            report_content += f"### {target}\n- 未发现漏洞\n"
            continue
        # 按风险等级排序(High > Medium > Low > Info)
        issues_sorted = sorted(issues, key=lambda x: {"High": 4, "Medium": 3, "Low": 2, "Info": 1}[x["severity"]], reverse=True)
        report_content += f"### {target}\n共发现{len(issues_sorted)}个漏洞,清单如下:\n"
        report_content += "| 风险等级 | 漏洞名称 | 漏洞位置 | 描述 |\n"
        report_content += "|----------|----------|----------|------|\n"
        for issue in issues_sorted:
            report_content += f"| {issue['severity']} | {issue['name']} | {issue['location']} | {issue['description']} |\n"
            if issue["severity"] == "High":
                high_count += 1
    
    # 报告总结
    total_issues = sum(len(issues) for issues in burp_results.values())
    report_content += f"\n## 3. 扫描总结\n- 总HTTP/HTTPS目标数:{len(nmap_targets)}\n- 总漏洞数:{total_issues}\n- 高危漏洞数:{high_count}\n- 建议:优先修复高危漏洞,定期重新扫描"
    
    # 保存报告
    try:
        with open(report_path, "w", encoding="utf-8") as f:
            f.write(report_content)
        print(f"[+] 报告生成成功,路径:{report_path}")
    except Exception as e:
        print(f"[-] 报告生成失败:{str(e)}")

# 测试模块3:需先运行模块1和2获取数据,再执行
if __name__ == "__main__":
    test_nmap_targets = ["http://192.168.1.100:80", "https://192.168.1.101:443"]
    test_burp_results = {
        "http://192.168.1.100:80": [
            {"severity": "High", "name": "SQL Injection", "location": "http://192.168.1.100:80/login?id=1", "description": "存在SQL注入漏洞,可执行任意SQL语句..."}
        ],
        "https://192.168.1.101:443": []
    }
    generate_report(test_nmap_targets, test_burp_results)
模块 3 关键说明:
  • 报告结构:包含 “报告信息、Nmap 资产清单、Burp 漏洞清单、总结”,符合安全测试报告的通用规范;

  • 风险排序:漏洞按 “高危→中危→低危→信息” 排序,方便优先处理关键风险;

  • 编码处理:用utf-8编码保存,避免中文乱码(Windows 默认编码易导致乱码,需显式指定)。

四、Step 3:脚本整合与实战演示

将 3 个模块整合为完整脚本,实现 “一键扫描→自动生成报告”,以 “扫描内网 192.168.1.0/24 网段” 为例演示:

1. 完整脚本(可直接复制运行)

# 安全工具自动化脚本:Python整合Nmap+Burp
# 功能:Nmap扫描→Burp扫描→报告生成

import nmap
import re
import requests
import time
import datetime

# ---------------------- 模块1:Nmap扫描 ----------------------
def nmap_scan(target, ports="80,443,8080"):
    print(f"[+] 开始Nmap扫描:目标{target},端口{ports}")
    nm = nmap.PortScanner()
    try:
        nm.scan(hosts=target, ports=ports, arguments="-sn -sV")
    except Exception as e:
        print(f"[-] Nmap扫描失败:{str(e)}")
        return []
    
    http_targets = []
    for host in nm.all_hosts():
        if nm[host].state() == "up":
            print(f"[+] 发现存活主机:{host}")
            for proto in nm[host].all_protocols():
                if proto != "tcp":
                    continue
                ports = nm[host][proto].keys()
                for port in ports:
                    service = nm[host][proto][port]["name"]
                    if service in ["http", "https", "http-proxy"]:
                        if service == "https" or port == 443:
                            url = f"https://{host}:{port}"
                        else:
                            url = f"http://{host}:{port}"
                        http_targets.append(url)
                        print(f"  - 发现HTTP服务:{url}")
    
    print(f"[+] Nmap扫描完成,共提取{len(http_targets)}个HTTP/HTTPS目标")
    return http_targets

# ---------------------- 模块2:Burp扫描 ----------------------
def burp_scan(targets, burp_api_key, burp_url="http://localhost:8090/api/v0.1"):
    if not targets:
        print("[-] 无HTTP目标,跳过Burp扫描")
        return {}
    
    headers = {
        "X-API-Key": burp_api_key,
        "Content-Type": "application/json"
    }
    scan_results = {}
    task_ids = []
    
    # 创建扫描任务
    for target in targets:
        print(f"[+] 为{target}创建Burp扫描任务")
        scan_config = {
            "urls": [target],
            "scan_configurations": [{"name": "Default Active Scan", "type": "NamedConfiguration"}],
            "scope": {"include": [{"rule": "Domain", "target": target.split("//")[-1].split(":")[0]}], "exclude": []}
        }
        try:
            resp = requests.post(f"{burp_url}/scan", headers=headers, json=scan_config, timeout=30)
            resp.raise_for_status()
            task_id = resp.json()["task_id"]
            task_ids.append({"target": target, "task_id": task_id, "completed": False})
            print(f"  - 任务创建成功,ID:{task_id}")
        except Exception as e:
            print(f"[-] 创建{target}扫描任务失败:{str(e)}")
            continue
    
    # 等待任务完成
    print(f"[+] 共{len(task_ids)}个扫描任务,等待完成...")
    while True:
        completed_tasks = 0
        for task in task_ids:
            if task["completed"]:
                completed_tasks += 1
                continue
            try:
                resp = requests.get(f"{burp_url}/scan/{task['task_id']}", headers=headers, timeout=10)
                status = resp.json()["status"]
                if status == "completed":
                    task["completed"] = True
                    completed_tasks += 1
                    print(f"[+] {task['target']} 扫描完成")
                elif status == "failed":
                    task["completed"] = True
                    completed_tasks += 1
                    print(f"[-] {task['target']} 扫描失败")
            except Exception as e:
                print(f"[-] 检查{task['target']}任务状态失败:{str(e)}")
                continue
        if completed_tasks == len(task_ids):
            break
        time.sleep(30)
    
    # 获取漏洞结果
    for task in task_ids:
        target = task["target"]
        task_id = task["task_id"]
        try:
            resp = requests.get(f"{burp_url}/scan/{task_id}/issues", headers=headers, timeout=10)
            issues = resp.json()
            simplified_issues = []
            for issue in issues:
                simplified_issues.append({
                    "severity": issue["severity"],
                    "name": issue["name"],
                    "location": issue["location"],
                    "description": issue["description"][:100] + "..."
                })
            scan_results[target] = simplified_issues
            print(f"[+] {target} 共发现{len(simplified_issues)}个漏洞")
        except Exception as e:
            print(f"[-] 获取{target}漏洞结果失败:{str(e)}")
            scan_results[target] = []
    
    return scan_results

# ---------------------- 模块3:生成报告 ----------------------
def generate_report(nmap_targets, burp_results, report_path="security_scan_report.md"):
    print(f"[+] 生成扫描报告:{report_path}")
    report_content = f"""# 安全扫描报告
## 报告信息
- 扫描时间:{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
- 扫描范围:{', '.join(nmap_targets) if nmap_targets else '无'}
- 扫描工具:Nmap + Burp Suite
- 报告生成工具:Python自动化脚本

## 1. Nmap资产扫描结果
共发现{len(nmap_targets)}个HTTP/HTTPS服务,清单如下:
| 序号 | 目标URL | 服务类型 |
|------|---------|----------|
"""
    for i, target in enumerate(nmap_targets, 1):
        service_type = "HTTPS" if target.startswith("https") else "HTTP"
        report_content += f"| {i} | {target} | {service_type} |\n"
    
    report_content += "\n## 2. Burp漏洞扫描结果\n"
    high_count = 0
    for target, issues in burp_results.items():
        if not issues:
            report_content += f"### {target}\n- 未发现漏洞\n"
            continue
        issues_sorted = sorted(issues, key=lambda x: {"High": 4, "Medium": 3, "Low": 2, "Info": 1}[x["severity"]], reverse=True)
        report_content += f"### {target}\n共发现{len(issues_sorted)}个漏洞,清单如下:\n"
        report_content += "| 风险等级 | 漏洞名称 | 漏洞位置 | 描述 |\n"
        report_content += "|----------|----------|----------|------|\n"
        for issue in issues_sorted:
            report_content += f"| {issue['severity']} | {issue['name']} | {issue['location']} | {issue['description']} |\n"
            if issue["severity"] == "High":
                high_count += 1
    
    total_issues = sum(len(issues) for issues in burp_results.values())
    report_content += f"\n## 3. 扫描总结\n- 总HTTP/HTTPS目标数:{len(nmap_targets)}\n- 总漏洞数:{total_issues}\n- 高危漏洞数:{high_count}\n- 建议:优先修复高危漏洞,定期重新扫描"
    
    try:
        with open(report_path, "w", encoding="utf-8") as f:
            f.write(report_content)
        print(f"[+] 报告生成成功,路径:{report_path}")
    except Exception as e:
        print(f"[-] 报告生成失败:{str(e)}")

# ---------------------- 主函数:整合执行 ----------------------
def main():
    # 配置参数(需根据实际环境修改)
    TARGET_NETWORK = "192.168.1.0/24"  # 目标网段
    BURP_API_KEY = "your_burp_api_key"  # Burp API密钥
    REPORT_PATH = f"scan_report_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.md"  # 报告路径(带时间戳)
    
    print("="*50)
    print("          安全工具自动化脚本(Nmap+Burp)          ")
    print("="*50)
    
    # 1. Nmap扫描
    nmap_targets = nmap_scan(TARGET_NETWORK)
    # 2. Burp扫描
    burp_results = burp_scan(nmap_targets, BURP_API_KEY)
    # 3. 生成报告
    generate_report(nmap_targets, burp_results, REPORT_PATH)
    
    print("="*50)
    print("                      扫描完成                      ")
    print("="*50)

if __name__ == "__main__":
    main()

2. 实战演示步骤

步骤 1:配置参数

打开脚本,修改main函数中的 3 个核心参数:

  • TARGET_NETWORK:替换为你要扫描的网段(如192.168.1.0/24、10.0.0.0/8);

  • BURP_API_KEY:替换为 Burp REST API 插件生成的密钥;

  • REPORT_PATH:报告保存路径(默认带时间戳,避免覆盖)。

步骤 2:运行脚本
  • Windows:双击运行脚本(需确保 Python 和 Nmap 已添加到环境变量);

  • Linux/macOS:打开终端,执行sudo python3 脚本名.py(Nmap 需要 root 权限)。

步骤 3:查看结果
  1. 控制台输出:实时显示 Nmap 扫描进度、Burp 任务状态、漏洞数量;

  2. 报告文件:脚本运行完成后,在当前目录生成scan_report_20250925153000.md(时间戳不同),用 Markdown 阅读器打开,可看到结构化的资产清单和漏洞详情。

五、避坑指南:新手常踩的 5 个问题

1. 问题 1:Nmap 扫描报错 “Permission denied”(Linux/macOS)

  • 原因:Nmap 扫描需要 root 权限(尤其是-sn ping 扫描和端口扫描);

  • 解决:用sudo python3 脚本名.py运行,而非直接python3 脚本名.py。

2. 问题 2:Burp API 调用报错 “401 Unauthorized”

  • 原因:API 密钥错误或未带密钥访问;

  • 解决

  1. 确认 Burp REST API 插件生成的密钥正确(在 Burp 的Extender → Installed → Burp REST API → Configure中查看);

  2. 检查脚本中BURP_API_KEY参数是否与插件一致。

3. 问题 3:Burp 扫描任务一直 “running”,不完成

  • 原因:扫描目标不可达(如目标关闭、网络不通)或 Burp 配置错误;

  • 解决

  1. 手动访问目标 URL,确认能正常打开;

  2. 检查 Burp 的 “Proxy” 是否开启(API 扫描依赖 Proxy 的流量处理)。

4. 问题 4:报告生成后中文乱码

  • 原因:Windows 默认编码为 GBK,脚本用 UTF-8 保存,导致乱码;

  • 解决:用 Notepad++ 或 VS Code 打开报告,选择 “编码→UTF-8” 即可正常显示中文。

5. 问题 5:Python 报错 “ModuleNotFoundError: No module named ‘nmap’”

  • 原因:未安装python-nmap库;

  • 解决:打开终端,执行pip install python-nmap(若有多个 Python 版本,用pip3 install python-nmap)。

六、脚本扩展:按需添加更多功能

基础脚本可根据需求扩展,推荐 3 个实用方向:

  1. 多线程加速:在 Nmap 扫描和 Burp 任务创建环节添加多线程,减少扫描时间(用threading库实现);

  2. 漏洞告警:扫描到高危漏洞时,自动发送邮件或钉钉通知(调用smtplib邮件库或钉钉机器人 API);

  3. 整合更多工具:在 Burp 扫描后,对高危 SQL 注入目标自动调用 Sqlmap 深化检测(用subprocess库调用 Sqlmap 命令)。

七、总结:自动化的核心不是 “替代人”,而是 “解放人”

这个脚本的价值不是 “完全自动化安全测试”,而是帮你摆脱 “复制 IP、手动创建任务、整理报告” 等重复劳动,把时间用在 “漏洞分析、风险评估、修复验证” 等更有价值的工作上。

对新手来说,开发这个脚本的过程也是一次 “工具原理 + Python 编程” 的实战学习 —— 你不仅能得到一个可用的工具,还能理解 Nmap 的扫描逻辑、Burp 的 API 设计,为后续开发更多自动化脚本(如整合 Nessus、Sqlmap)打下基础。

试着用这个脚本扫描你的内网环境,看看能节省多少时间 —— 当你不用再手动切换工具时,会发现安全测试的效率能提升一倍以上。

网络安全学习资料分享

为了帮助大家更好的学习网络安全,我把我从一线互联网大厂薅来的网络安全教程及资料分享给大家,里面的内容都是适合零基础小白的笔记和资料,不懂编程也能听懂、看懂,朋友们如果有需要这套网络安全教程+进阶学习资源包,可以扫码下方二维码限时免费领取(如遇扫码问题,可以在评论区留言领取哦)~

在这里插入图片描述

在这里插入图片描述

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐