-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporting.py
More file actions
199 lines (169 loc) · 4.67 KB
/
reporting.py
File metadata and controls
199 lines (169 loc) · 4.67 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
from pathlib import Path
from datetime import datetime, timezone
import json
import html
def generate_reports(domain, results, output_dir, logger=None):
output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
txt_path = output_dir / f"{domain}_{timestamp}.txt"
json_path = output_dir / f"{domain}_{timestamp}.summary.json"
html_path = output_dir / f"{domain}_{timestamp}.html"
_generate_txt(domain, results, txt_path)
_generate_json(results, json_path)
_generate_html(domain, results, html_path, timestamp)
if logger:
logger.info(f"Reports generated at {output_dir}")
def _generate_txt(domain, results, path):
with open(path, "w", encoding="utf-8") as f:
f.write(f"Recon Report for {domain}\n")
f.write("=" * 40 + "\n\n")
# Passive Recon
f.write("[PASSIVE RECON]\n")
passive = results.get("passive", {})
for module, data in passive.items():
f.write(f"\n{module.upper()}:\n")
if not data:
f.write(" No data found\n")
else:
f.write(str(data) + "\n")
# Active Recon
f.write("\n[ACTIVE RECON]\n")
active = results.get("active", {})
# Port Scan
portscan = active.get("portscan")
if portscan:
f.write("\nOpen Ports:\n")
for port in portscan.get("open_ports", []):
f.write(f" - {port}\n")
# Banner Grabbing
banners = active.get("banners")
if banners:
f.write("\nService Banners:\n")
for port, banner in banners.items():
f.write(f" Port {port}: {banner}\n")
# Technology Detection
tech = active.get("technology")
if tech:
f.write("\nTechnology Detection:\n")
for proto, info in tech.items():
f.write(f" [{proto.upper()}]\n")
if info:
for line in str(info).splitlines():
f.write(f" {line}\n")
else:
f.write(" No data found\n")
def _generate_json(results, path):
import json
with open(path, "w", encoding="utf-8") as f:
json.dump(results, f, indent=2)
def _generate_html(domain, results, path, timestamp):
def esc(text):
return html.escape(str(text))
passive = results.get("passive", {})
active = results.get("active", {})
with open(path, "w", encoding="utf-8") as f:
f.write(f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Recon Report - {esc(domain)}</title>
<style>
body {{
font-family: Arial, sans-serif;
background-color: #0f172a;
color: #e5e7eb;
padding: 20px;
}}
h1, h2 {{
color: #38bdf8;
}}
.section {{
margin-bottom: 30px;
}}
.box {{
background: #020617;
padding: 15px;
border-radius: 8px;
}}
pre {{
white-space: pre-wrap;
word-wrap: break-word;
}}
ul {{
list-style: none;
padding-left: 0;
}}
li {{
padding: 4px 0;
}}
.footer {{
margin-top: 40px;
font-size: 0.9em;
color: #94a3b8;
}}
</style>
</head>
<body>
<h1>Recon Report</h1>
<p><strong>Target:</strong> {esc(domain)}</p>
<p><strong>Generated (UTC):</strong> {esc(timestamp)}</p>
<div class="section">
<h2>Passive Recon</h2>
""")
# Passive recon blocks
for module, data in passive.items():
f.write(f"""
<div class="box">
<h3>{esc(module.upper())}</h3>
<pre>{esc(json.dumps(data, default=str))}</pre>
</div>
""")
f.write("""
</div>
<div class="section">
<h2>Active Recon</h2>
""")
# Port scan
portscan = active.get("portscan")
if portscan:
f.write("""
<div class="box">
<h3>Open Ports</h3>
<ul>
""")
for port in portscan.get("open_ports", []):
f.write(f"<li>Port {esc(port)}</li>")
f.write("</ul></div>")
# Banners
banners = active.get("banners")
if banners:
f.write("""
<div class="box">
<h3>Service Banners</h3>
<pre>
""")
for port, banner in banners.items():
f.write(f"Port {esc(port)}: {esc(banner)}\n")
f.write("</pre></div>")
# Technology Detection
tech = active.get("technology")
if tech:
f.write("""
<div class="box">
<h3>Technology Detection</h3>
""")
for proto, info in tech.items():
f.write(f"""
<h4>{esc(proto.upper())}</h4>
<pre>{esc(info) if info else "No data found"}</pre>
""")
f.write("</div>")
f.write("""
</div>
<div class="footer">
Generated by Custom Recon Tool
</div>
</body>
</html>
""")