Skip to content

Commit 8da17ab

Browse files
authored
新增插件功能
1 parent f2e4ac5 commit 8da17ab

18 files changed

+255
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
691 Bytes
Binary file not shown.
Binary file not shown.
501 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

extensions/base64_decoder.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import base64
2+
import re
3+
4+
plugin_info = {
5+
"title": "Base64解码",
6+
"description": "尝试解码文件中的Base64编码内容",
7+
"usage": "选择一个文件,然后点击此插件",
8+
"category": "CTF工具"
9+
}
10+
11+
def run(file_path):
12+
with open(file_path, 'r') as f:
13+
content = f.read()
14+
15+
base64_pattern = re.compile(r'(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?')
16+
matches = base64_pattern.findall(content)
17+
18+
for match in matches:
19+
if len(match) > 20: # 忽略短字符串
20+
try:
21+
decoded = base64.b64decode(match).decode('utf-8')
22+
print(f"原始Base64: {match[:20]}...")
23+
print(f"解码结果: {decoded[:50]}...")
24+
print("---")
25+
except:
26+
pass

extensions/file_hash.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import hashlib
2+
3+
plugin_info = {
4+
"title": "文件哈希计算",
5+
"description": "计算文件的MD5, SHA1和SHA256哈希值",
6+
"usage": "选择一个文件,然后点击此插件",
7+
"category": "文件分析"
8+
}
9+
10+
def run(file_path):
11+
with open(file_path, 'rb') as f:
12+
data = f.read()
13+
print(f"MD5: {hashlib.md5(data).hexdigest()}")
14+
print(f"SHA1: {hashlib.sha1(data).hexdigest()}")
15+
print(f"SHA256: {hashlib.sha256(data).hexdigest()}")

extensions/file_header_analyzer.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import binascii
2+
3+
plugin_info = {
4+
"title": "文件头分析",
5+
"description": "分析文件头信息",
6+
"usage": "选择一个文件,然后点击此插件",
7+
"category": "文件分析"
8+
}
9+
10+
def run(file_path):
11+
with open(file_path, 'rb') as f:
12+
header = f.read(16)
13+
14+
print("文件头(十六进制):")
15+
print(binascii.hexlify(header).decode())
16+
17+
# 常见文件头签名
18+
signatures = {
19+
b'\x89PNG\r\n\x1a\n': 'PNG图像',
20+
b'GIF87a': 'GIF图像(87a)',
21+
b'GIF89a': 'GIF图像(89a)',
22+
b'\xff\xd8\xff': 'JPEG图像',
23+
b'PK\x03\x04': 'ZIP压缩文件',
24+
b'MZ': 'Windows可执行文件',
25+
b'%PDF': 'PDF文档'
26+
}
27+
28+
for sig, file_type in signatures.items():
29+
if header.startswith(sig):
30+
print(f"识别为: {file_type}")
31+
return
32+
33+
print("未识别的文件类型")
Binary file not shown.

extensions/front/openfile.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from plugin.NewtableWidget import NewtableWidget
2+
from plugin.QuicklyView import QuicklyView
3+
from PySide6.QtWidgets import QApplication
4+
import os
5+
import csv
6+
import chardet
7+
import traceback
8+
9+
class OpenFile:
10+
def __init__(self):
11+
self.table_widget = None
12+
13+
def run(self, file_path):
14+
print(f"文件分析器正在处理文件: {file_path}")
15+
16+
file_size = os.path.getsize(file_path)
17+
file_extension = os.path.splitext(file_path)[1]
18+
19+
try:
20+
with open(file_path, 'rb') as file:
21+
raw_content = file.read(1000)
22+
encoding = chardet.detect(raw_content)['encoding']
23+
content = raw_content.decode(encoding or 'utf-8', errors='replace')
24+
except Exception as e:
25+
content = f"无法读取文件内容: {str(e)}"
26+
27+
# 首先判断是否为CSV文件
28+
if file_extension.lower() == '.csv':
29+
try:
30+
self.table_widget = NewtableWidget(file_path, f"CSV内容 - {os.path.basename(file_path)}")
31+
self.table_widget.show()
32+
print("CSV文件内容已在表格中显示")
33+
except Exception as e:
34+
print(f"无法解析CSV文件: {str(e)}")
35+
traceback.print_exc()
36+
else:
37+
try:
38+
quick_view = QuicklyView(f"文件内容预览 - {os.path.basename(file_path)}")
39+
quick_view.load_file_content(file_path)
40+
QApplication.instance().processEvents()
41+
quick_view.show_and_exec()
42+
print("文件内容预览已在新窗口中打开")
43+
except Exception as e:
44+
print(f"显示 QuicklyView 时发生错误:{str(e)}")
45+
traceback.print_exc()
46+
47+
print(f"文件大小: {file_size} 字节")
48+
print(f"文件扩展名: {file_extension}")
49+
print("文件分析器执行完毕")

extensions/quick_open.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from extensions.front.openfile import OpenFile # 调用快速
2+
3+
4+
plugin_info = {
5+
"title": "快速打开文件",
6+
"description": "快速打开文件",
7+
"usage": "选择一个文件,然后点击此插件",
8+
"category": "文件操作"
9+
}
10+
11+
12+
file_analyzer = OpenFile()
13+
14+
def run(file_path):
15+
file_analyzer.run(file_path)
16+

extensions/steganography_detector.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from PIL import Image
2+
import binascii
3+
4+
plugin_info = {
5+
"title": "隐写术检测",
6+
"description": "检测图片中可能存在的隐写内容",
7+
"usage": "选择一个图片文件,然后点击此插件",
8+
"category": "CTF工具"
9+
}
10+
11+
def run(file_path):
12+
try:
13+
with Image.open(file_path) as img:
14+
# 检查LSB
15+
pixels = list(img.getdata())
16+
lsb = ''.join([bin(p)[-1] for p in pixels[:100]])
17+
print("前100像素的LSB:")
18+
print(lsb)
19+
20+
# 检查EXIF数据
21+
exif = img._getexif()
22+
if exif:
23+
print("EXIF数据:")
24+
for tag_id, value in exif.items():
25+
print(f"{tag_id}: {value}")
26+
else:
27+
print("没有EXIF数据")
28+
except Exception as e:
29+
print(f"分析图片时出错: {str(e)}")

extensions/string_extractor.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import re
2+
3+
plugin_info = {
4+
"title": "字符串提取",
5+
"description": "从文件中提取可打印字符串",
6+
"usage": "选择一个文件,然后点击此插件",
7+
"category": "文件分析"
8+
}
9+
10+
def run(file_path):
11+
with open(file_path, 'rb') as f:
12+
content = f.read()
13+
14+
strings = re.findall(b'[\x20-\x7E]{4,}', content)
15+
print("提取的字符串:")
16+
for s in strings[:20]: # 只打印前20个字符串
17+
print(s.decode())
18+
print(f"总共提取了 {len(strings)} 个字符串")

extensions/示例插件.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import zipfile
2+
import os
3+
4+
# 插件信息字典,包含插件的基本信息
5+
plugin_info = {
6+
"title": "解压文件", # 插件标题
7+
"description": "解压ZIP、RAR等压缩文件", # 插件描述
8+
"usage": "选择一个压缩文件,然后点击此插件", # 使用说明
9+
"category": "文件操作" # 插件类别
10+
}
11+
12+
def run(file_path):
13+
"""
14+
插件的主要执行函数
15+
16+
参数:
17+
file_path (str): 要处理的文件的路径
18+
19+
返回:
20+
None
21+
"""
22+
# 检查文件是否存在
23+
if not os.path.exists(file_path):
24+
print(f"错误: 文件 {file_path} 不存在")
25+
return
26+
27+
# 获取文件扩展名
28+
_, file_extension = os.path.splitext(file_path)
29+
30+
# 根据文件扩展名选择相应的解压方法
31+
if file_extension.lower() == '.zip':
32+
extract_zip(file_path)
33+
else:
34+
print(f"不支持的文件类型: {file_extension}")
35+
36+
def extract_zip(file_path):
37+
"""
38+
解压ZIP文件
39+
40+
参数:
41+
file_path (str): ZIP文件的路径,即文件槽内文件路径
42+
43+
返回:
44+
None
45+
"""
46+
try:
47+
# 创建输出目录
48+
output_dir = os.path.join('output', 'extracted_files')
49+
os.makedirs(output_dir, exist_ok=True)
50+
51+
# 解压文件
52+
with zipfile.ZipFile(file_path, 'r') as zip_ref:
53+
zip_ref.extractall(output_dir)
54+
55+
print(f"文件已成功解压到: {output_dir}")
56+
57+
# 列出解压后的文件
58+
print("解压的文件列表:")
59+
for root, dirs, files in os.walk(output_dir):
60+
for file in files:
61+
print(os.path.join(root, file))
62+
63+
except zipfile.BadZipFile:
64+
print("错误: 无效的ZIP文件")
65+
except Exception as e:
66+
print(f"解压过程中发生错误: {str(e)}")
67+
68+
# 注意: 如果需要支持其他类型的压缩文件(如RAR),
69+
# 可以添加相应的解压函数并在run()中调用

0 commit comments

Comments
 (0)