您的位置 : 资讯 > 软件教程 > DeepseekScanner deepseek+python实现代码审计实战

DeepseekScanner deepseek+python实现代码审计实战

来源:菜鸟下载 | 更新时间:2025-07-02

一、功能概述DeepseekScanner实现了扫描源代码项目中的所有代码文件发送给deepseek进行安全审计

一、功能概述

DeepseekScanner实现了扫描源代码项目中的所有代码文件发送给deepseek进行安全审计的功能。具体细节包括扫描所有子目录中的代码文件,然后依次将代码文件切片发送到deepseek api进行智能代码审计。审计结果包含存在安全问题的代码文件、代码位置行数、安全漏洞问题名称、存在安全漏洞的代码块。最后将审计结果保存到文件中方便查阅。

二、具体功能介绍

扫描指定的代码项目目录代码语言:javascript代码运行次数:0运行复制
//支持只扫描指定的文件后缀比如.php 只扫描.php文件 也可以扫描全部的文件类型def scan_directory(directory, file_types=None, scan_all=False):    try:        if scan_all:            files_to_scan = [os.path.join(root, file) for root, _, files in os.walk(directory) for file in files]        else:            files_to_scan = [os.path.join(root, file) for root, _, files in os.walk(directory) for file in files if                             any(file.endswith(ft) for ft in file_types)]        # Saving results to file        scan_results = []        filename = f"scan_results.txt"        directory = "./"        filepath = os.path.join(directory, filename)        for file_path in tqdm(files_to_scan, desc="Scanning files"):            file_scan_results = scan_file(file_path, scan_results, directory)            if file_scan_results is not None and len(file_scan_results) > 0:                save_results_to_file(filepath, file_scan_results)    except Exception as e:        print(e)
登录后复制

2.代码文件切片发送给deepseek做安全审计

立即学习“Python免费学习笔记(深入)”;

代码语言:javascript代码运行次数:0运行复制
//从项目中的各个目录提取代码文件后,开始对代码进行切片发送给deepseek做安全审计def scan_file(file_path, scan_results, directory):    try:        with open(file_path, 'r') as file:            content = file.readlines()        total_chunks = (len(content) - 1) // 100 + 100        file_scan_results = []        for chunk_start in range(0, len(content), 100):            chunk_end = min(chunk_start + 100, len(content))            code_chunk = ''.join(content[chunk_start:chunk_end])            response = analyze_security(code_chunk)            if hasattr(response, 'content'):                results = response.content            elif isinstance(response, dict) and 'content' in response:                results = response['content']            else:                results = response            if results:                # Split the result into individual issues using "@@@@", it can be unreliable depending on the output of the model                individual_results = results.split('@@@@')                for result in individual_results:                    if "存在风险" in result:                        try:                            _, line_numbers, issue_description, code_snippet = result.split(' | ', 3)                            adjusted_line_numbers = line_numbers.strip()                            issue_description = issue_description.strip()                            code_snippet = code_snippet.strip()                            file_scan_results.append(                                (file_path, adjusted_line_numbers, issue_description, code_snippet))                        except ValueError:                            continue        # Append this file's results to the main scan_results        # scan_results.extend(file_scan_results)        return file_scan_results    except Exception as e:        print(e)    return None
登录后复制

3.deepseek代码审计功能

代码语言:javascript代码运行次数:0运行复制
//严格定义prompt为资深安全专家实现代码安全审计def analyze_security(content):    try:        completion = client.chat.completions.create(            model="deepseek-chat",  # field is not currently used in LM studio            messages=[                {"role": "system", "content": '''你是一个安全专家严格分析以下代码片段,检查其中是否存在安全漏洞,请详细分析'''},                {"role": "user", "content": content}            ],            temperature=0.7,        )        return completion.choices[0].message    except Exception as e:        print(e)    return None
登录后复制

三、测试结果

1.命令执行

代码语言:javascript代码运行次数:0运行复制
//对项目中的所有代码进行安全审计python scanner.py E:\work\sqli-secound-order --all
登录后复制

2.结果展示

DeepseekScanner deepseek+python实现代码审计实战

四、总结

DeepseekScanner通过python+deepseek实现了python、php、java等语言项目代码审计,测试效果对于常见的安全问题甄别效果还是可以的,但可能也存在误报、错报等问题,需要再逐一帧对,不断完善。感兴趣的朋友可以在公众号回复"deepseekscanner"下载完整项目进行测试,包含代码项目和提供测试的漏洞代码项目。

菜鸟下载发布此文仅为传递信息,不代表菜鸟下载认同其观点或证实其描述。

展开
Python 3d
Python 3d
类型:体育竞技 运营状态:公测 语言:简体中文
闯关 方块 趣味
前往下载

相关文章

更多>>

热门游戏

更多>>

手机扫描此二维码,

在手机上查看此页面

关于本站 下载帮助 版权声明 网站地图

版权投诉请发邮件到 cn486com#outlook.com (把#改成@),我们会尽快处理

Copyright © 2019-2020 菜鸟下载(www.cn486.com).All Reserved | 备案号:湘ICP备2023003002号-8

本站资源均收集整理于互联网,其著作权归原作者所有,如有侵犯你的版权,请来信告知,我们将及时下架删除相应资源