forked from GreyDGL/PentestGPT_website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_filesystem.py
More file actions
82 lines (66 loc) · 2.14 KB
/
generate_filesystem.py
File metadata and controls
82 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
"""
Generate filesystem.json manifest from pentest artifacts directory
"""
import json
import os
from pathlib import Path
def read_file_safe(filepath):
"""Safely read file contents, return None if binary or unreadable"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
return f.read()
except (UnicodeDecodeError, PermissionError):
return "[Binary file or unreadable]"
def build_tree(directory):
"""Recursively build directory tree with file contents"""
tree = {
"name": directory.name,
"type": "directory",
"children": []
}
try:
items = sorted(directory.iterdir(), key=lambda x: (not x.is_dir(), x.name))
for item in items:
if item.is_dir():
tree["children"].append(build_tree(item))
else:
# Get file size
size = item.stat().st_size
# Read content for text files
content = read_file_safe(item)
tree["children"].append({
"name": item.name,
"type": "file",
"size": size,
"content": content
})
except PermissionError:
pass
return tree
def main():
# Path to pentest artifacts
base_dir = Path("assets/demo/pentest_Expressway_20250927_030837")
if not base_dir.exists():
print(f"Error: Directory {base_dir} not found")
return
print(f"Scanning {base_dir}...")
# Build filesystem tree
filesystem = build_tree(base_dir)
# Add metadata
manifest = {
"root": filesystem,
"metadata": {
"generated": "2025-10-28",
"description": "PentestGPT artifacts from HTB Expressway machine",
"target": "10.129.179.253"
}
}
# Write to JSON
output_path = Path("assets/demo/filesystem.json")
with open(output_path, 'w', encoding='utf-8') as f:
json.dump(manifest, f, indent=2)
print(f"Generated {output_path}")
print(f"Total size: {output_path.stat().st_size} bytes")
if __name__ == "__main__":
main()