Skip to content

Commit cbaeba2

Browse files
committed
初始化项目
0 parents  commit cbaeba2

28 files changed

+1103
-0
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ------------ MySQL 配置 ------------
2+
MYSQL_HOST=142.123.123.25
3+
MYSQL_PORT=3306
4+
MYSQL_USER=root
5+
MYSQL_PASSWORD=8888888
6+
MYSQL_CHARSET=utf8mb4
118 KB
Loading
35.9 KB
Loading
70.7 KB
Loading

README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# 敏感数据探测工具
2+
3+
## 项目介绍
4+
5+
这是一个功能强大的敏感数据探测工具,能够连接到多种数据库系统,自动扫描和识别包含敏感信息的表和字段,并将结果导出为CSV或JSON格式。该工具适用于数据库安全审计、合规性检查和隐私保护评估等场景。
6+
7+
## 功能特点
8+
9+
- **多数据库支持**:兼容MySQL、Oracle、SQL Server等主流数据库系统
10+
- **敏感数据识别**:自动识别包含个人身份信息(PII)、信用卡信息、密码等敏感数据的字段
11+
- **可配置的关键词规则**:通过配置文件自定义敏感数据关键词和规则
12+
- **灵活的导出格式**:支持CSV和JSON两种导出格式
13+
- **详细的日志记录**:记录探测过程中的关键操作和错误信息
14+
- **代理支持**:可配置代理服务器进行数据库连接
15+
- **服务名自定义**:Oracle数据库支持自定义服务名
16+
17+
## 支持的数据库类型
18+
19+
- MySQL
20+
- Oracle
21+
- SQL Server
22+
23+
## 安装说明
24+
25+
### 环境要求
26+
27+
- Python 3.8+
28+
- 通过requirements.txt安装需要的库
29+
- 下载sqlserver连接需要的驱动
30+
31+
### 安装步骤
32+
33+
1. **克隆或下载项目**
34+
35+
```bash
36+
git clone [项目仓库地址] # 如果是通过git获取
37+
# 或直接下载项目压缩包并解压
38+
```
39+
40+
2. **安装依赖**
41+
42+
```bash
43+
cd sensitive_data
44+
pip install -r requirements.txt
45+
```
46+
47+
### 可执行文件版本
48+
49+
如果您不想安装Python环境,也可以使用预编译的可执行文件版本:
50+
51+
## 使用方法
52+
53+
### 命令行参数
54+
55+
```bash
56+
python main.py [参数]
57+
```
58+
59+
主要参数:
60+
61+
- `-h`, `--help`:显示帮助信息
62+
- `-t`, `--type`:数据库类型 (mysql/oracle/sqlserver)
63+
- `-H`, `--host`:数据库主机地址
64+
- `-P`, `--port`:数据库端口
65+
- `-u`, `--user`:数据库用户名
66+
- `-p`, `--password`:数据库密码
67+
- `-s`, `--service-name`:Oracle数据库服务名(默认:ORCL)
68+
- `-o`, `--output-format`:输出格式 (csv/json),默认csv
69+
- `-proxy`, `--use-proxy`:使用代理服务器
70+
71+
### 示例
72+
73+
1. **使用MySQL数据库**
74+
75+
```bash
76+
python main.py -t mysql -H localhost -P 3306 -u root -p password
77+
```
78+
79+
2. **使用Oracle数据库,指定服务名**
80+
81+
```bash
82+
python main.py -t oracle -H localhost -P 1521 -u system -p password -s ORCLPDB1
83+
```
84+
85+
3. **指定输出格式为JSON**
86+
87+
```bash
88+
python main.py -t sqlserver -H localhost -P 1433 -u sa -p password -o json
89+
```
90+
91+
4. **使用代理服务器**
92+
93+
```bash
94+
python main.py -t mysql -H localhost -P 3306 -u root -p password -px
95+
```
96+
97+
这里以mysql获取敏感数据为例:
98+
99+
![image-20251118173416682](README.assets/image-20251118173416682.png)
100+
101+
输出的文件:
102+
103+
![image-20251118173621165](README.assets/image-20251118173621165.png)
104+
105+
![image-20251118173707101](README.assets/image-20251118173707101.png)
106+
107+
## 输出说明
108+
109+
工具会在`output`目录下生成以下文件:
110+
111+
- `sensitive_data_YYYYMMDD_HHMMSS.csv``sensitive_data_YYYYMMDD_HHMMSS.json`:包含检测到的敏感数据表和字段信息
112+
113+
输出内容包括:
114+
- 数据库名称
115+
- 表名
116+
- 字段名
117+
- 字段类型
118+
- 发现的敏感关键词
119+
- 数据样本(如果有)
120+
121+
## 日志说明
122+
123+
工具会在`logs`目录下生成日志文件,记录运行过程中的关键信息和错误。
124+
125+
## 注意事项
126+
127+
1. 请确保数据库连接信息正确,并且具有足够的权限读取所有表结构
128+
2. 对于大型数据库,扫描可能需要较长时间
129+
3. 敏感数据识别基于关键词匹配,可能存在误报或漏报
130+
4. 建议在非生产环境中先进行测试
131+
5. 对于Oracle数据库,确保服务名配置正确
132+
133+
## 打包可执行文件
134+
135+
如果您需要将程序打包为可执行文件,可以使用PyInstaller:
136+
137+
```bash
138+
# 安装PyInstaller
139+
pip install pyinstaller
140+
141+
# 打包为单文件可执行程序
142+
pyinstaller --onefile main.py
143+
144+
# 打包时添加图标
145+
pyinstaller --onefile --icon=test.ico main.py
146+
```
147+
148+
打包后的可执行文件将位于`dist`目录中。
149+
150+
## 故障排除
151+
152+
1. **连接失败**:检查数据库地址、端口、用户名和密码是否正确
153+
2. **Oracle连接问题**:确保服务名配置正确,可使用`-s`参数指定
154+
3. **缺少依赖**:确保所有依赖已通过`requirements.txt`安装
155+
4. **权限不足**:确保数据库用户具有足够的权限查看所有表结构
3.01 KB
Binary file not shown.
5.01 KB
Binary file not shown.
1.73 KB
Binary file not shown.
1.67 KB
Binary file not shown.

common/exception_handler.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from common.logger import logger
2+
3+
class BaseExtractorError(Exception):
4+
"""基础异常类"""
5+
pass
6+
7+
class DBConnectionError(BaseExtractorError):
8+
"""数据库连接异常"""
9+
def __init__(self, db_type: str, msg: str):
10+
self.db_type = db_type
11+
self.msg = msg
12+
super().__init__(f"[{db_type}] 连接失败:{msg}")
13+
logger.error(self.__str__())
14+
15+
class DBQueryError(BaseExtractorError):
16+
"""数据库查询异常"""
17+
def __init__(self, db_name: str, table_name: str, msg: str):
18+
self.db_name = db_name
19+
self.table_name = table_name
20+
self.msg = msg
21+
super().__init__(f"[{db_name}.{table_name}] 查询失败:{msg}")
22+
logger.error(self.__str__())
23+
24+
class ProxyError(BaseExtractorError):
25+
"""代理配置异常"""
26+
def __init__(self, proxy: str, msg: str):
27+
self.proxy = proxy
28+
self.msg = msg
29+
super().__init__(f"代理配置失败({proxy}):{msg}")
30+
logger.error(self.__str__())
31+
32+
class ExportError(BaseExtractorError):
33+
"""导出异常"""
34+
def __init__(self, export_type: str, msg: str):
35+
self.export_type = export_type
36+
self.msg = msg
37+
super().__init__(f"[{export_type}] 导出失败:{msg}")
38+
logger.error(self.__str__())

0 commit comments

Comments
 (0)