-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnmap-xml-parser.html
More file actions
333 lines (299 loc) · 17.7 KB
/
nmap-xml-parser.html
File metadata and controls
333 lines (299 loc) · 17.7 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nmap XML Parser</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- React and ReactDOM -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<!-- Babel Standalone for JSX -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Lucide Icons -->
<script src="https://unpkg.com/lucide@latest"></script>
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState } = React;
// Lucide Icon Components
const Upload = () => (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
);
const Server = () => (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<rect x="2" y="2" width="20" height="8" rx="2" ry="2"/>
<rect x="2" y="14" width="20" height="8" rx="2" ry="2"/>
<line x1="6" y1="6" x2="6.01" y2="6"/>
<line x1="6" y1="18" x2="6.01" y2="18"/>
</svg>
);
const Shield = () => (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
</svg>
);
const Clock = () => (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<circle cx="12" cy="12" r="10"/>
<polyline points="12 6 12 12 16 14"/>
</svg>
);
const AlertCircle = () => (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="8" x2="12" y2="12"/>
<line x1="12" y1="16" x2="12.01" y2="16"/>
</svg>
);
function NmapParser() {
const [parsedData, setParsedData] = useState(null);
const [error, setError] = useState(null);
const parseNmapXML = (xmlContent) => {
try {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlContent, 'text/xml');
// Check for parsing errors
const parserError = xmlDoc.querySelector('parsererror');
if (parserError) {
throw new Error('Invalid XML file');
}
// Extract scan information
const nmaprun = xmlDoc.querySelector('nmaprun');
const scanInfo = {
scanner: nmaprun?.getAttribute('scanner') || 'Unknown',
version: nmaprun?.getAttribute('version') || 'Unknown',
args: nmaprun?.getAttribute('args') || 'Unknown',
startTime: new Date(parseInt(nmaprun?.getAttribute('start') || 0) * 1000).toLocaleString(),
};
// Extract hosts
const hosts = [];
const hostElements = xmlDoc.querySelectorAll('host');
hostElements.forEach(hostElement => {
const status = hostElement.querySelector('status');
const address = hostElement.querySelector('address');
const hostnames = hostElement.querySelectorAll('hostname');
const host = {
status: status?.getAttribute('state') || 'unknown',
ip: address?.getAttribute('addr') || 'Unknown',
hostnames: Array.from(hostnames).map(h => h.getAttribute('name')).filter(Boolean),
ports: [],
os: null,
};
// Extract ports
const ports = hostElement.querySelectorAll('port');
ports.forEach(port => {
const state = port.querySelector('state');
const service = port.querySelector('service');
host.ports.push({
portId: port.getAttribute('portid'),
protocol: port.getAttribute('protocol'),
state: state?.getAttribute('state') || 'unknown',
service: service?.getAttribute('name') || 'unknown',
product: service?.getAttribute('product') || '',
version: service?.getAttribute('version') || '',
extraInfo: service?.getAttribute('extrainfo') || '',
});
});
// Extract OS information
const osMatch = hostElement.querySelector('osmatch');
if (osMatch) {
host.os = {
name: osMatch.getAttribute('name'),
accuracy: osMatch.getAttribute('accuracy'),
};
}
hosts.push(host);
});
return { scanInfo, hosts };
} catch (err) {
throw new Error(`Failed to parse XML: ${err.message}`);
}
};
const handleFileUpload = (event) => {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
try {
const result = parseNmapXML(e.target.result);
setParsedData(result);
setError(null);
} catch (err) {
setError(err.message);
setParsedData(null);
}
};
reader.readAsText(file);
};
const getStateColor = (state) => {
switch (state.toLowerCase()) {
case 'open':
return 'text-green-600 bg-green-50';
case 'closed':
return 'text-red-600 bg-red-50';
case 'filtered':
return 'text-yellow-600 bg-yellow-50';
default:
return 'text-gray-600 bg-gray-50';
}
};
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 p-8">
<div className="max-w-7xl mx-auto">
{/* Header */}
<div className="text-center mb-8">
<h1 className="text-4xl font-bold text-white mb-2 flex items-center justify-center gap-3">
<Shield />
Nmap XML Parser
</h1>
<p className="text-slate-400">Upload and analyze your Nmap scan results</p>
</div>
{/* File Upload */}
<div className="bg-slate-800 rounded-lg shadow-xl p-6 mb-6 border border-slate-700">
<label className="flex flex-col items-center justify-center w-full h-32 border-2 border-dashed border-slate-600 rounded-lg cursor-pointer hover:border-blue-500 transition-colors">
<div className="flex flex-col items-center justify-center pt-5 pb-6">
<Upload />
<p className="text-sm text-slate-400 mt-2">
<span className="font-semibold">Click to upload</span> or drag and drop
</p>
<p className="text-xs text-slate-500 mt-1">Nmap XML file</p>
</div>
<input
type="file"
className="hidden"
accept=".xml"
onChange={handleFileUpload}
/>
</label>
</div>
{/* Error Display */}
{error && (
<div className="bg-red-900/30 border border-red-600 rounded-lg p-4 mb-6 flex items-start gap-3">
<AlertCircle />
<div>
<h3 className="text-red-400 font-semibold">Error</h3>
<p className="text-red-300 text-sm">{error}</p>
</div>
</div>
)}
{/* Parsed Data Display */}
{parsedData && (
<div className="space-y-6">
{/* Scan Info */}
<div className="bg-slate-800 rounded-lg shadow-xl p-6 border border-slate-700">
<h2 className="text-xl font-bold text-white mb-4 flex items-center gap-2">
<Clock />
Scan Information
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
<div>
<span className="text-slate-400">Scanner:</span>
<span className="text-white ml-2">{parsedData.scanInfo.scanner} {parsedData.scanInfo.version}</span>
</div>
<div>
<span className="text-slate-400">Start Time:</span>
<span className="text-white ml-2">{parsedData.scanInfo.startTime}</span>
</div>
<div className="md:col-span-2">
<span className="text-slate-400">Arguments:</span>
<span className="text-white ml-2 font-mono text-xs">{parsedData.scanInfo.args}</span>
</div>
</div>
</div>
{/* Hosts */}
{parsedData.hosts.map((host, index) => (
<div key={index} className="bg-slate-800 rounded-lg shadow-xl p-6 border border-slate-700">
<div className="mb-4">
<h2 className="text-xl font-bold text-white mb-2 flex items-center gap-2">
<Server />
Host: {host.ip}
</h2>
{host.hostnames.length > 0 && (
<p className="text-slate-400 text-sm">
Hostname(s): {host.hostnames.join(', ')}
</p>
)}
<div className="flex items-center gap-4 mt-2">
<span className={`px-3 py-1 rounded-full text-xs font-semibold ${
host.status === 'up' ? 'bg-green-900/50 text-green-300' : 'bg-red-900/50 text-red-300'
}`}>
{host.status.toUpperCase()}
</span>
{host.os && (
<span className="text-slate-400 text-sm">
OS: {host.os.name} ({host.os.accuracy}% accuracy)
</span>
)}
</div>
</div>
{/* Ports Table */}
{host.ports.length > 0 ? (
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b border-slate-700">
<th className="text-left text-slate-400 font-semibold py-2 px-2">Port</th>
<th className="text-left text-slate-400 font-semibold py-2 px-2">State</th>
<th className="text-left text-slate-400 font-semibold py-2 px-2">Service</th>
<th className="text-left text-slate-400 font-semibold py-2 px-2">Version</th>
</tr>
</thead>
<tbody>
{host.ports.map((port, portIndex) => (
<tr key={portIndex} className="border-b border-slate-700/50 hover:bg-slate-700/30">
<td className="py-2 px-2 text-white font-mono">
{port.portId}/{port.protocol}
</td>
<td className="py-2 px-2">
<span className={`px-2 py-1 rounded text-xs font-semibold ${getStateColor(port.state)}`}>
{port.state}
</span>
</td>
<td className="py-2 px-2 text-slate-300">{port.service}</td>
<td className="py-2 px-2 text-slate-400 text-xs">
{port.product && `${port.product} `}
{port.version && `${port.version} `}
{port.extraInfo && `(${port.extraInfo})`}
</td>
</tr>
))}
</tbody>
</table>
</div>
) : (
<p className="text-slate-500 text-sm">No open ports found</p>
)}
</div>
))}
</div>
)}
{/* Empty State */}
{!parsedData && !error && (
<div className="text-center py-12">
<Shield />
<p className="text-slate-400 mt-4">Upload an Nmap XML file to get started</p>
</div>
)}
</div>
</div>
);
}
// Render the app
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<NmapParser />);
</script>
</body>
</html>