From ed3b9e7e4c48b4f945e40d3fd0929a5de7311682 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 15 May 2024 10:32:53 +0800 Subject: [PATCH 01/15] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81pip=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MANIFEST.in | 2 ++ setup.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 MANIFEST.in create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..04f196a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.md +include LICENSE diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..acc425b --- /dev/null +++ b/setup.py @@ -0,0 +1,36 @@ +# pip install wheel +# python setup.py sdist bdist_wheel + +from setuptools import setup, find_packages + + +def read_file(filename: str) -> str: + """Read a file and return its content as a string. + + Args: + filename (str): The name of the file to read. + + Returns: + str: The content of the file. + """ + with open(filename, encoding="utf-8") as f: + return f.read() + + +setup( + name="backdoor_buster", + version="0.1.0", + author="ciscn", + description="A tool for integrated backdoor detection", + long_description=read_file("README.md"), + long_description_content_type="text/markdown", + url="https://git.mamahaha.work/sangge/BackDoorBuster", + packages=find_packages(), + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires=">=3.6", + install_requires=["reportlab" "requests" "packaging" "openai" "bs4"], +) From 8d445b11a4b1437d14556f877eafaff691cf926f Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 15 May 2024 10:40:36 +0800 Subject: [PATCH 02/15] =?UTF-8?q?docs:=20=E6=92=B0=E5=86=99pip=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/design.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/docs/design.md b/docs/design.md index 113bbc8..4af8edf 100644 --- a/docs/design.md +++ b/docs/design.md @@ -70,6 +70,59 @@ python backdoor_detection.py ./src -o ./output/report.pdf python requirements_detection.py ./requirements.txt -o ./output/report.md ``` +## 打包 + +### 简介 + +本项目需要将 Python 代码打包成 pip 包,以便于分发和安装。以下是如何实现和使用该打包功能的详细步骤。 + +### 打包命令 + +```bash +pip install wheel +python setup.py sdist bdist_wheel +``` + +执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 + +### 本地安装 + +- 安装 .whl 文件: + +``` bash +pip install dist/my_project-0.1.0-py3-none-any.whl +``` + +- 安装 .tar.gz 文件: + +``` bash +pip install dist/my_project-0.1.0.tar.gz +``` + +## 上传到 PyPI + +- 安装 twine: + +``` bash +pip install twine +``` + +- 使用 twine 上传包到 PyPI: + +``` bash +twine upload dist/* +``` + +需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 + +## 使用 PyPI 安装 + +包上传到 PyPI 后,可以通过以下命令安装: + +``` bash +pip install my_project +``` + --- ### 结论 From 958dee355e7b7b9583dc5f01a12dc69218f0a766 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 15 May 2024 10:45:34 +0800 Subject: [PATCH 03/15] =?UTF-8?q?docs:=20=E6=92=B0=E5=86=99pip=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tech_notes.md | 8 +++++++- docs/usage.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/tech_notes.md b/docs/tech_notes.md index 3e3f28c..e2abb8e 100644 --- a/docs/tech_notes.md +++ b/docs/tech_notes.md @@ -46,7 +46,13 @@ - **主要应用**:通过爬虫收集漏洞依赖信息并进行汇总,用于判断依赖是否存在漏洞版本。 -## 8. 代码和风险分析 +## 8. 打包 + +本项目支持打包作为pip包进行发布 + +- **主要应用**:通过`wheel`并自行撰写`setup.py`以及`MANIFEST.in`,将项目打包发布 + +## 9. 代码和风险分析 项目中实现了基本的静态代码分析功能,用于识别和报告潜在的安全风险函数调用,如 `system`、`exec` 等。 diff --git a/docs/usage.md b/docs/usage.md index a13bb77..b1f1d12 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -66,6 +66,55 @@ python backdoor_detection.py ./src -o output/report.pdf -m regex - 结果中会标注出每个文件中发现的高风险和中风险函数调用位置。 - 对于依赖检测,结果将标明每个依赖包的安全状态,包括存在安全风险的依赖及其版本。 +## 打包 + +### 打包命令 + +```bash +pip install wheel +python setup.py sdist bdist_wheel +``` + +执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 + +### 本地安装 + +- 安装 .whl 文件: + +``` bash +pip install dist/my_project-0.1.0-py3-none-any.whl +``` + +- 安装 .tar.gz 文件: + +``` bash +pip install dist/my_project-0.1.0.tar.gz +``` + +### 上传到 PyPI + +- 安装 twine: + +``` bash +pip install twine +``` + +- 使用 twine 上传包到 PyPI: + +``` bash +twine upload dist/* +``` + +需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 + +### 使用 PyPI 安装 + +包上传到 PyPI 后,可以通过以下命令安装: + +``` bash +pip install my_project +``` + ## 常见问题处理 - 确保所有路径都正确无误,避免因路径错误导致文件读取失败。 From 569497f79ec7216393563d8293bb476c64663421 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 15 May 2024 11:14:31 +0800 Subject: [PATCH 04/15] =?UTF-8?q?docs:=20=E6=92=B0=E5=86=99deb=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/design.md | 46 +++++++++++++++++++++++++++++++++++++++++----- docs/tech_notes.md | 6 ++++-- docs/usage.md | 44 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 85 insertions(+), 11 deletions(-) diff --git a/docs/design.md b/docs/design.md index 4af8edf..2a2c9a0 100644 --- a/docs/design.md +++ b/docs/design.md @@ -74,9 +74,11 @@ python requirements_detection.py ./requirements.txt -o ./output/report.md ### 简介 -本项目需要将 Python 代码打包成 pip 包,以便于分发和安装。以下是如何实现和使用该打包功能的详细步骤。 +本项目需要将 Python 代码打包成`pip`包和`deb`包,以便于分发和安装。以下是如何实现和使用该打包功能的详细步骤。 -### 打包命令 +### pip + +#### 打包命令 ```bash pip install wheel @@ -85,7 +87,7 @@ python setup.py sdist bdist_wheel 执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 -### 本地安装 +#### 本地安装 - 安装 .whl 文件: @@ -99,7 +101,7 @@ pip install dist/my_project-0.1.0-py3-none-any.whl pip install dist/my_project-0.1.0.tar.gz ``` -## 上传到 PyPI +#### 上传到 PyPI - 安装 twine: @@ -115,7 +117,7 @@ twine upload dist/* 需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 -## 使用 PyPI 安装 +#### 使用 PyPI 安装 包上传到 PyPI 后,可以通过以下命令安装: @@ -123,6 +125,40 @@ twine upload dist/* pip install my_project ``` +### deb + +#### 命令 + +- 安装`stdeb` + +```bash +sudo apt-get install python-stdeb +``` + +- 创建`debian`目录 + +- 编写 debian/rules 文件 + + ```makefile + #!/usr/bin/make -f + + %: + dh $@ + ``` + +- 打包 + +```bash +python setup.py --command-packages=stdeb.command bdist_deb +``` + +- 构建DEB包 + +```bash +cd deb_dist +sudo dpkg -i backdoor_buster.deb +``` + --- ### 结论 diff --git a/docs/tech_notes.md b/docs/tech_notes.md index e2abb8e..dd5c6c6 100644 --- a/docs/tech_notes.md +++ b/docs/tech_notes.md @@ -48,9 +48,11 @@ ## 8. 打包 -本项目支持打包作为pip包进行发布 +本项目支持打包作为`pip`包和`deb`包进行发布 -- **主要应用**:通过`wheel`并自行撰写`setup.py`以及`MANIFEST.in`,将项目打包发布 +- **主要应用**: + - `pip`通过`wheel`并自行撰写`setup.py`以及`MANIFEST.in`,将项目打包发布 + - `deb`通过`stdeb`打包 ## 9. 代码和风险分析 diff --git a/docs/usage.md b/docs/usage.md index b1f1d12..9fd2268 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -68,7 +68,9 @@ python backdoor_detection.py ./src -o output/report.pdf -m regex ## 打包 -### 打包命令 +### pip + +#### 打包命令 ```bash pip install wheel @@ -77,7 +79,7 @@ python setup.py sdist bdist_wheel 执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 -### 本地安装 +#### 本地安装 - 安装 .whl 文件: @@ -91,7 +93,7 @@ pip install dist/my_project-0.1.0-py3-none-any.whl pip install dist/my_project-0.1.0.tar.gz ``` -### 上传到 PyPI +#### 上传到 PyPI - 安装 twine: @@ -107,7 +109,7 @@ twine upload dist/* 需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 -### 使用 PyPI 安装 +#### 使用 PyPI 安装 包上传到 PyPI 后,可以通过以下命令安装: @@ -115,6 +117,40 @@ twine upload dist/* pip install my_project ``` +### deb + +#### 命令 + +- 安装`stdeb` + +```bash +sudo apt-get install python-stdeb +``` + +- 创建`debian`目录 + +- 编写 debian/rules 文件 + + ```makefile + #!/usr/bin/make -f + + %: + dh $@ + ``` + +- 打包 + +```bash +python setup.py --command-packages=stdeb.command bdist_deb +``` + +- 构建DEB包 + +```bash +cd deb_dist +sudo dpkg -i backdoor_buster.deb +``` + ## 常见问题处理 - 确保所有路径都正确无误,避免因路径错误导致文件读取失败。 From 6967a154f71f44c3111261f570368ebcd42a1fd5 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Sun, 26 May 2024 17:04:27 +0800 Subject: [PATCH 05/15] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=8C=85=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/design.md | 6 +++--- docs/usage.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/design.md b/docs/design.md index 2a2c9a0..3e5c530 100644 --- a/docs/design.md +++ b/docs/design.md @@ -92,13 +92,13 @@ python setup.py sdist bdist_wheel - 安装 .whl 文件: ``` bash -pip install dist/my_project-0.1.0-py3-none-any.whl +pip install dist/backdoor_buster-0.1.0-py3-none-any.whl ``` - 安装 .tar.gz 文件: ``` bash -pip install dist/my_project-0.1.0.tar.gz +pip install dist/backdoor_buster-0.1.0.tar.gz ``` #### 上传到 PyPI @@ -122,7 +122,7 @@ twine upload dist/* 包上传到 PyPI 后,可以通过以下命令安装: ``` bash -pip install my_project +pip install backdoor_buster ``` ### deb diff --git a/docs/usage.md b/docs/usage.md index 9fd2268..13e41c3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -84,13 +84,13 @@ python setup.py sdist bdist_wheel - 安装 .whl 文件: ``` bash -pip install dist/my_project-0.1.0-py3-none-any.whl +pip install dist/backdoor_buster-0.1.0-py3-none-any.whl ``` - 安装 .tar.gz 文件: ``` bash -pip install dist/my_project-0.1.0.tar.gz +pip install dist/backdoor_buster-0.1.0.tar.gz ``` #### 上传到 PyPI @@ -114,7 +114,7 @@ twine upload dist/* 包上传到 PyPI 后,可以通过以下命令安装: ``` bash -pip install my_project +pip install backdoor_buster ``` ### deb From 3f8b2a7987168c2e94f57d70c067f5fa6e635366 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 20:23:48 +0800 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8F=8D?= =?UTF-8?q?=E6=B1=87=E7=BC=96=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5842882..399f7e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ reportlab requests packaging openai -bs4 \ No newline at end of file +bs4 +uncompyle6 \ No newline at end of file From dd4ab45cbfe2052e811182f3909ec84be98f2bd0 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 20:24:12 +0800 Subject: [PATCH 07/15] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index acc425b..0c48b75 100644 --- a/setup.py +++ b/setup.py @@ -32,5 +32,12 @@ setup( "Operating System :: OS Independent", ], python_requires=">=3.6", - install_requires=["reportlab" "requests" "packaging" "openai" "bs4"], + install_requires=[ + "reportlab", + "requests", + "packaging", + "openai", + "bs4", + "uncompyle6", + ], ) From 99457f1ceb14064d234079b1f46d3f78de0408bb Mon Sep 17 00:00:00 2001 From: sangge-redmi <2251250136@qq.com> Date: Wed, 29 May 2024 20:24:44 +0800 Subject: [PATCH 08/15] fix: fix setup require --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index acc425b..9182cb6 100644 --- a/setup.py +++ b/setup.py @@ -32,5 +32,5 @@ setup( "Operating System :: OS Independent", ], python_requires=">=3.6", - install_requires=["reportlab" "requests" "packaging" "openai" "bs4"], + install_requires=["reportlab", "requests", "packaging", "openai", "bs4"], ) From d2b0fb286cc4d416637407d16c38cca074b76826 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 21:21:56 +0800 Subject: [PATCH 09/15] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=B3=95=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/usage.md | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 13e41c3..16935f6 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -6,14 +6,10 @@ 在开始使用本系统之前,请确保您的环境中安装了以下依赖: -- Python 3.6 或更高版本 -- `packaging` 库:用于版本控制和比较 -- `reportlab` 库:用于生成 PDF 报告 - 您可以通过以下命令安装必要的 Python 库: ```bash -pip install packaging reportlab +pip install -r requirements.txt ``` ## 下载和配置 @@ -117,40 +113,6 @@ twine upload dist/* pip install backdoor_buster ``` -### deb - -#### 命令 - -- 安装`stdeb` - -```bash -sudo apt-get install python-stdeb -``` - -- 创建`debian`目录 - -- 编写 debian/rules 文件 - - ```makefile - #!/usr/bin/make -f - - %: - dh $@ - ``` - -- 打包 - -```bash -python setup.py --command-packages=stdeb.command bdist_deb -``` - -- 构建DEB包 - -```bash -cd deb_dist -sudo dpkg -i backdoor_buster.deb -``` - ## 常见问题处理 - 确保所有路径都正确无误,避免因路径错误导致文件读取失败。 From 99b481059b65c3b76c185bc1062570f81905033d Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 21:23:26 +0800 Subject: [PATCH 10/15] =?UTF-8?q?style:=20=E4=BF=AE=E6=94=B9=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=A8=A1=E5=9D=97=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/{backdoor_detection.py => __main__.py} | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename detection/{backdoor_detection.py => __main__.py} (98%) diff --git a/detection/backdoor_detection.py b/detection/__main__.py similarity index 98% rename from detection/backdoor_detection.py rename to detection/__main__.py index ef3e32b..5f41266 100644 --- a/detection/backdoor_detection.py +++ b/detection/__main__.py @@ -170,7 +170,9 @@ def process_path(path: str, output_format: str, mode: str, output_file=None): def main(): import argparse - parser = argparse.ArgumentParser(description="Backdoor detection tool.") + parser = argparse.ArgumentParser( + description="Backdoor detection tool.", prog="detection" + ) parser.add_argument("path", help="Path to the code to analyze") parser.add_argument("-o", "--output", help="Output file path", default=None) parser.add_argument( From 41b16c53bce9bc2624414417498b5970e127fd6b Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 21:24:08 +0800 Subject: [PATCH 11/15] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=A8=A1=E5=9D=97=E5=BC=95=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_backdoor_detection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_backdoor_detection.py b/tests/test_backdoor_detection.py index c0d2a05..3d4fcf5 100644 --- a/tests/test_backdoor_detection.py +++ b/tests/test_backdoor_detection.py @@ -1,7 +1,7 @@ import unittest import warnings -from detection.backdoor_detection import find_dangerous_functions +from detection.__main__ import find_dangerous_functions from detection.GPTdetection import detectGPT import os @@ -83,5 +83,6 @@ class TestBackdoorDetection(unittest.TestCase): self.assertEqual(len(results["medium"]), 0) self.assertEqual(len(results["low"]), 0) + if __name__ == "__main__": unittest.main() From d56d0173ad495379708604a19cf4dddc6215cf70 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 21:57:32 +0800 Subject: [PATCH 12/15] =?UTF-8?q?docs:=20=E5=AE=8C=E5=96=84=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/design.md | 148 +++++++++++++++++---------------------------- docs/tech_notes.md | 9 ++- docs/usage.md | 90 +++++++++++++-------------- 3 files changed, 108 insertions(+), 139 deletions(-) diff --git a/docs/design.md b/docs/design.md index 3e5c530..403add4 100644 --- a/docs/design.md +++ b/docs/design.md @@ -1,9 +1,64 @@ # 项目设计文档 - 后门检测系统 +## 打包 + +### 简介 + +本项目需要将 Python 代码打包成`pip`包和`deb`包,以便于分发和安装。以下是如何实现和使用该打包功能的详细步骤。 + +### pip + +#### 打包命令 + +```bash +pip install wheel +python setup.py sdist bdist_wheel +``` + +执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 + +#### 本地安装 + +- 安装 .whl 文件: + +``` bash +pip install dist/backdoor_buster-0.1.0-py3-none-any.whl +``` + +- 安装 .tar.gz 文件: + +``` bash +pip install dist/backdoor_buster-0.1.0.tar.gz +``` + +#### 上传到 PyPI + +- 安装 twine: + +``` bash +pip install twine +``` + +- 使用 twine 上传包到 PyPI: + +``` bash +twine upload dist/* +``` + +需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 + +#### 使用 PyPI 安装 + +包上传到 PyPI 后,可以通过以下命令安装: + +``` bash +pip install backdoor_buster +``` + ## 静态代码后门检测 **功能描述**: -这个脚本用于扫描指定路径下的代码文件,检测潜在的危险函数调用,支持 `.py`, `.js`, `.cpp` 文件。 +这个脚本用于扫描指定路径下的代码文件,检测潜在的危险函数调用,支持 `.py`, `.js`, `.cpp`, `.pyc` 文件。 **主要组件**: @@ -67,96 +122,7 @@ python backdoor_detection.py ./src -o ./output/report.pdf **使用示例**: ```bash -python requirements_detection.py ./requirements.txt -o ./output/report.md -``` - -## 打包 - -### 简介 - -本项目需要将 Python 代码打包成`pip`包和`deb`包,以便于分发和安装。以下是如何实现和使用该打包功能的详细步骤。 - -### pip - -#### 打包命令 - -```bash -pip install wheel -python setup.py sdist bdist_wheel -``` - -执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 - -#### 本地安装 - -- 安装 .whl 文件: - -``` bash -pip install dist/backdoor_buster-0.1.0-py3-none-any.whl -``` - -- 安装 .tar.gz 文件: - -``` bash -pip install dist/backdoor_buster-0.1.0.tar.gz -``` - -#### 上传到 PyPI - -- 安装 twine: - -``` bash -pip install twine -``` - -- 使用 twine 上传包到 PyPI: - -``` bash -twine upload dist/* -``` - -需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 - -#### 使用 PyPI 安装 - -包上传到 PyPI 后,可以通过以下命令安装: - -``` bash -pip install backdoor_buster -``` - -### deb - -#### 命令 - -- 安装`stdeb` - -```bash -sudo apt-get install python-stdeb -``` - -- 创建`debian`目录 - -- 编写 debian/rules 文件 - - ```makefile - #!/usr/bin/make -f - - %: - dh $@ - ``` - -- 打包 - -```bash -python setup.py --command-packages=stdeb.command bdist_deb -``` - -- 构建DEB包 - -```bash -cd deb_dist -sudo dpkg -i backdoor_buster.deb +python -m detection.requirements_detection ./requirements.txt -o ./output/report.md ``` --- diff --git a/docs/tech_notes.md b/docs/tech_notes.md index dd5c6c6..e907d6c 100644 --- a/docs/tech_notes.md +++ b/docs/tech_notes.md @@ -48,13 +48,16 @@ ## 8. 打包 -本项目支持打包作为`pip`包和`deb`包进行发布 +本项目支持打包作为`pip`包进行发布 - **主要应用**: - `pip`通过`wheel`并自行撰写`setup.py`以及`MANIFEST.in`,将项目打包发布 - - `deb`通过`stdeb`打包 -## 9. 代码和风险分析 +## 9. 反汇编 + +项目通过`uncompyle6`库提供的反汇编模块可以实现对python字节码进行反汇编之后扫描危险代码 + +## 10. 代码和风险分析 项目中实现了基本的静态代码分析功能,用于识别和报告潜在的安全风险函数调用,如 `system`、`exec` 等。 diff --git a/docs/usage.md b/docs/usage.md index 16935f6..77210d1 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -17,51 +17,6 @@ pip install -r requirements.txt - 克隆或下载后门检测系统到您的本地环境。 - 确保脚本文件 (`requirements_detection.py` 和 `backdoor_detection.py`) 在您的工作目录中。 -## 运行依赖版本漏洞检测脚本 - -**命令格式**: - -```bash -python requirements_detection.py -o -``` - -**参数说明**: - -- ``: 项目的 `requirements.txt` 文件路径。 -- ``: 指定输出结果的文件路径和格式,支持的格式有 `.txt`, `.md`, `.html`, `.pdf`。 - -**示例**: - -```bash -python requirements_detection.py requirements.txt -o output/report.md -``` - -## 运行静态代码后门检测脚本 - -**命令格式**: - -```bash -python backdoor_detection.py -o -m -``` - -**参数说明**: - -- ``: 代码文件或目录的路径。 -- ``: 指定输出结果的文件路径和格式,支持的格式有 `.txt`, `.md`, `.html`, `.pdf`。 -- ``: 指定检测模式,目前支持的模式有 `regex` 和 `llm`。 - -**示例**: - -```bash -python backdoor_detection.py ./src -o output/report.pdf -m regex -``` - -## 结果解读 - -- 输出结果将根据指定的格式保存在您指定的文件中。 -- 结果中会标注出每个文件中发现的高风险和中风险函数调用位置。 -- 对于依赖检测,结果将标明每个依赖包的安全状态,包括存在安全风险的依赖及其版本。 - ## 打包 ### pip @@ -113,6 +68,51 @@ twine upload dist/* pip install backdoor_buster ``` +## 运行依赖版本漏洞检测脚本 + +**命令格式**: + +```bash +python -m detection.requirements_detection -o +``` + +**参数说明**: + +- ``: 项目的 `requirements.txt` 文件路径。 +- ``: 指定输出结果的文件路径和格式,支持的格式有 `.txt`, `.md`, `.html`, `.pdf`。 + +**示例**: + +```bash +python -m detection.requirements_detection requirements.txt -o output/report.md +``` + +## 运行静态代码后门检测脚本 + +**命令格式**: + +```bash +python -m detection -o -m +``` + +**参数说明**: + +- ``: 代码文件或目录的路径。 +- ``: 指定输出结果的文件路径和格式,支持的格式有 `.txt`, `.md`, `.html`, `.pdf`。 +- ``: 指定检测模式,目前支持的模式有 `regex` 和 `llm`。 + +**示例**: + +```bash +python -m detection ./src -o output/report.pdf -m regex +``` + +## 结果解读 + +- 输出结果将根据指定的格式保存在您指定的文件中。 +- 结果中会标注出每个文件中发现的高风险和中风险函数调用位置。 +- 对于依赖检测,结果将标明每个依赖包的安全状态,包括存在安全风险的依赖及其版本。 + ## 常见问题处理 - 确保所有路径都正确无误,避免因路径错误导致文件读取失败。 From 0cd826c2fde722a0be1173e0f0861e3d6688179d Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Thu, 30 May 2024 08:12:30 +0800 Subject: [PATCH 13/15] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bb337d..5f7e6cf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # BackDoorBuster ![BackDoorBuster Banner](./banner.webp) + ## 项目背景 随着网络安全威胁的增加,恶意软件和后门的检测成为了保护个人和组织数据安全的重要任务。后门通常被隐藏在合法软件中,给黑客提供远程控制目标系统的能力。本项目旨在开发一个工具,能够有效识别和评估潜在的后门风险。 @@ -27,8 +28,16 @@ 2. 执行扫描: + 未打包: + ```bash - python scan.py + python /detection/__main__.py -o -m + ``` + + 打包后: + + ```bash + python -m detection -o -m ``` 3. 查看报告: From 2a94f27edc5bea76140d0ac728c7d52325611af4 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Thu, 30 May 2024 15:48:06 +0800 Subject: [PATCH 14/15] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 69 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5f7e6cf..f460baf 100644 --- a/README.md +++ b/README.md @@ -18,29 +18,66 @@ - **报告生成**: 自动生成详细的检测报告,列出所有发现的敏感操作和对应的风险等级。 - **持续更新与维护**: 随着新的后门技术和检测方法的出现,持续更新正则表达式库和评级标准。 +## 打包 + +### pip + +#### 打包命令 + +```bash +pip install wheel +python setup.py sdist bdist_wheel +``` + +执行上述命令后,会在 dist 目录下生成 .tar.gz 和 .whl 文件。 + +#### 本地安装 + +- 安装 .whl 文件: + +``` bash +pip install dist/backdoor_buster-0.1.0-py3-none-any.whl +``` + +- 安装 .tar.gz 文件: + +``` bash +pip install dist/backdoor_buster-0.1.0.tar.gz +``` + +#### 上传到 PyPI + +- 安装 twine: + +``` bash +pip install twine +``` + +- 使用 twine 上传包到 PyPI: + +``` bash +twine upload dist/* +``` + +需要提供 PyPI 的用户名和密码。如果没有 PyPI 账号,可以在 PyPI 注册。 + +#### 使用 PyPI 安装 + +包上传到 PyPI 后,可以通过以下命令安装: + +``` bash +pip install backdoor_buster +``` + ## 使用说明 -1. 安装依赖: - - ```bash - pip install -r requirements.txt - ``` - -2. 执行扫描: - - 未打包: - - ```bash - python /detection/__main__.py -o -m - ``` - - 打包后: +1. 执行扫描: ```bash python -m detection -o -m ``` -3. 查看报告: +2. 查看报告: 报告将以文本形式输出在控制台,并可选择输出到指定文件。 From 7cc81141c646c8cb819f2a2a2459c548358c7c3a Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Thu, 30 May 2024 15:59:26 +0800 Subject: [PATCH 15/15] =?UTF-8?q?docs:=20=E5=88=A0=E9=99=A4=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/usage.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 77210d1..eab725a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -2,16 +2,6 @@ 本文档提供了后门检测系统的使用方法,包括依赖版本漏洞检测和静态代码后门检测两部分。这将帮助用户正确执行安全检测,并理解输出结果。 -## 安装需求 - -在开始使用本系统之前,请确保您的环境中安装了以下依赖: - -您可以通过以下命令安装必要的 Python 库: - -```bash -pip install -r requirements.txt -``` - ## 下载和配置 - 克隆或下载后门检测系统到您的本地环境。