Compare commits

...

20 Commits

Author SHA1 Message Date
5ed90e39f8 Merge pull request 'feature/package-development' (#22) from feature/package-development into main
Some checks failed
Python application test / build (push) Failing after 1m0s
Reviewed-on: #22
Reviewed-by: sangge <sangge@noreply.localhost>
Reviewed-by: ccyj <ccyj@noreply.localhost>
2024-05-30 16:26:58 +08:00
dqy
7cc81141c6 docs: 删除安装依赖 2024-05-30 15:59:26 +08:00
dqy
2a94f27edc docs: 修改README 2024-05-30 15:48:06 +08:00
dqy
0cd826c2fd docs: 修改README 2024-05-30 08:12:30 +08:00
dqy
d56d0173ad docs: 完善文档 2024-05-29 21:57:32 +08:00
dqy
0c4f560b7a Merge branch 'feature/package-development' of https://git.mamahaha.work/sangge/BackDoorBuster into feature/package-development 2024-05-29 21:29:12 +08:00
dqy
41b16c53bc fix: 修改检测模块引入 2024-05-29 21:24:08 +08:00
dqy
99b481059b style: 修改检测模块文件名 2024-05-29 21:23:26 +08:00
dqy
d2b0fb286c docs: 修改用法文档 2024-05-29 21:21:56 +08:00
5552a7e448 Merge branch 'feature/package-development' of https://git.mamahaha.work/sangge/BackDoorBuster into feature/package-development 2024-05-29 20:25:27 +08:00
99457f1ceb fix: fix setup require 2024-05-29 20:24:44 +08:00
dqy
2b90268628 Merge branch 'feature/package-development' of https://git.mamahaha.work/sangge/BackDoorBuster into feature/package-development 2024-05-29 20:24:35 +08:00
dqy
dd4ab45cbf fix: 修复依赖报错 2024-05-29 20:24:12 +08:00
dqy
3f8b2a7987 feat: 添加反汇编依赖 2024-05-29 20:23:48 +08:00
b73170cd2d Merge branch 'main' into feature/package-development 2024-05-29 20:05:05 +08:00
dqy
6967a154f7 perf: 修改安装包命名 2024-05-26 17:04:27 +08:00
dqy
569497f79e docs: 撰写deb文档
Some checks failed
Python application test / build (pull_request) Failing after 12m32s
2024-05-15 11:14:31 +08:00
dqy
958dee355e docs: 撰写pip文档 2024-05-15 10:45:34 +08:00
dqy
8d445b11a4 docs: 撰写pip文档 2024-05-15 10:40:36 +08:00
dqy
ed3b9e7e4c feat: 支持pip包 2024-05-15 10:32:53 +08:00
9 changed files with 231 additions and 33 deletions

2
MANIFEST.in Normal file
View File

@@ -0,0 +1,2 @@
include README.md
include LICENSE

View File

@@ -1,6 +1,7 @@
# BackDoorBuster
![BackDoorBuster Banner](./banner.webp)
## 项目背景
随着网络安全威胁的增加,恶意软件和后门的检测成为了保护个人和组织数据安全的重要任务。后门通常被隐藏在合法软件中,给黑客提供远程控制目标系统的能力。本项目旨在开发一个工具,能够有效识别和评估潜在的后门风险。
@@ -17,21 +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. 执行扫描:
1. 执行扫描:
```bash
python scan.py <project_directory>
python -m detection <project_directory> -o <path> -m <mode>
```
3. 查看报告:
2. 查看报告:
报告将以文本形式输出在控制台,并可选择输出到指定文件。

View File

@@ -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(

View File

@@ -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,7 +122,7 @@ python backdoor_detection.py ./src -o ./output/report.pdf
**使用示例**:
```bash
python requirements_detection.py ./requirements.txt -o ./output/report.md
python -m detection.requirements_detection ./requirements.txt -o ./output/report.md
```
---

View File

@@ -46,7 +46,18 @@
- **主要应用**:通过爬虫收集漏洞依赖信息并进行汇总,用于判断依赖是否存在漏洞版本。
## 8. 代码和风险分析
## 8. 打包
本项目支持打包作为`pip`包进行发布
- **主要应用**
- `pip`通过`wheel`并自行撰写`setup.py`以及`MANIFEST.in`,将项目打包发布
## 9. 反汇编
项目通过`uncompyle6`库提供的反汇编模块可以实现对python字节码进行反汇编之后扫描危险代码
## 10. 代码和风险分析
项目中实现了基本的静态代码分析功能,用于识别和报告潜在的安全风险函数调用,如 `system``exec` 等。

View File

@@ -2,31 +2,68 @@
本文档提供了后门检测系统的使用方法,包括依赖版本漏洞检测和静态代码后门检测两部分。这将帮助用户正确执行安全检测,并理解输出结果。
## 安装需求
在开始使用本系统之前,请确保您的环境中安装了以下依赖:
- Python 3.6 或更高版本
- `packaging` 库:用于版本控制和比较
- `reportlab` 库:用于生成 PDF 报告
您可以通过以下命令安装必要的 Python 库:
```bash
pip install packaging reportlab
```
## 下载和配置
- 克隆或下载后门检测系统到您的本地环境。
- 确保脚本文件 (`requirements_detection.py``backdoor_detection.py`) 在您的工作目录中。
## 打包
### 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
```
## 运行依赖版本漏洞检测脚本
**命令格式**
```bash
python requirements_detection.py <requirements_file> -o <output_file>
python -m detection.requirements_detection <requirements_file> -o <output_file>
```
**参数说明**
@@ -37,7 +74,7 @@ python requirements_detection.py <requirements_file> -o <output_file>
**示例**
```bash
python requirements_detection.py requirements.txt -o output/report.md
python -m detection.requirements_detection requirements.txt -o output/report.md
```
## 运行静态代码后门检测脚本
@@ -45,7 +82,7 @@ python requirements_detection.py requirements.txt -o output/report.md
**命令格式**
```bash
python backdoor_detection.py <code_path> -o <output_file> -m <mode>
python -m detection <code_path> -o <output_file> -m <mode>
```
**参数说明**
@@ -57,7 +94,7 @@ python backdoor_detection.py <code_path> -o <output_file> -m <mode>
**示例**
```bash
python backdoor_detection.py ./src -o output/report.pdf -m regex
python -m detection ./src -o output/report.pdf -m regex
```
## 结果解读

View File

@@ -3,3 +3,4 @@ requests
packaging
openai
bs4
uncompyle6

43
setup.py Normal file
View File

@@ -0,0 +1,43 @@
# 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",
"uncompyle6",
],
)

View File

@@ -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()