-
Notifications
You must be signed in to change notification settings - Fork 3
/
map2.html
408 lines (381 loc) · 9.22 KB
/
map2.html
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!DOCTYPE html>
<meta charset="utf-8">
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<pre id="csvdata">
source,target
bro_http,timestamp
bro_http,bro_id
bro_http,ip
bro_http,port
bro_http,http_method
bro_http,domain
bro_http,user_agent
bro_http,uri
bro_http,bytes
bro_http,http_status
bro_http,filename
bro_http,x_originating_ip
bro_http,mime_type
bro_files,timestamp
bro_files,bro_id
bro_files,ip
bro_files,port
bro_files,mime_type
bro_files,duration
bro_files,bytes
bro_files,hash
bro_intel,timestamp
bro_intel,bro_id
bro_intel,ip
bro_intel,post
bro_intel,mime_type
bro_intel,indicator_type
bro_intel,intel_source
bro_dns,timestamp
bro_dns,bro_id
bro_dns,protocol
bro_dns,dns_trans_id
bro_dns,domain
bro_dns,dns_query_type
bro_dns,dns_response_code
bro_conn,timestamp
bro_conn,bro_id
bro_conn,ip
bro_conn,port
bro_conn,protocol
bro_conn,service
bro_conn,duration
bro_conn,bytes
bro_conn,pkt_count
bro_conn,countrycode
bro_notice,timestamp
bro_notice,bro_id
bro_notice,mime_type
bro_notice,protocol
bro_notice,ip
bro_notice,port
bro_smtp,timestamp
bro_smtp,bro_id
bro_smtp,mail_user_agent
bro_smtp,mail_subject
bro_smtp,mail_from
bro_smtp,mail_to
bro_smtp,mail_helo
bro_smtp,x_originating_ip
bro_software,timestamp
bro_software,bro_id
bro_software,ip
bro_software,port
bro_software,program_name
bro_software,program_version
bro_ssl,timestamp
bro_ssl,bro_id
bro_ssl,ip
bro_ssl,port
bro_ssl,ssl_version
bro_ssl,domain
bro_ssl,cert_subject
bro_ssl,cert_expiration
bro_ssl,cert_hash
bro_ssl,cert_validation_status
bro_ssh,timestamp
bro_ssh,bro_id
bro_ssh,ip
bro_ssh,port
bro_ssh,ssh_auth_status
bro_ssh,ssh_client_string
bro_ssh,ssh_server_string
bro_ssh,bytes
bro_tunnel,timestamp
bro_tunnel,bro_id
bro_tunnel,ip
bro_tunnel,port
bro_tunnel,tunnel_type
bro_tunnel,tunnel_action
bro_weird,timestamp
bro_weird,bro_id
bro_weird,ip
bro_weird,port
</pre>
<style>
body {
overflow: hidden;
margin: 0;
font-size: 14px;
font-family: "Helvetica Neue", Helvetica;
}
#header {
height: 0;
right: 0px;
width: 100%;
text-align: right;
direction: rtl;
padding-right: 20px;
text-indent: 20px;
background: #999;
z-index: 1;
display: block;
font-size: 36px;
font-weight: 300;
text-shadow: 0 1px 0 #fff;
}
.hinth {
position: absolute;
right: 0;
width: 100%;
font-size: 12px;
color: #999;
text-align: right;
direction: rtl;
}
#footer {
height: 1;
left: 0px;
width: 100%;
text-align: left;
padding-left: 20px;
background: #999;
z-index: 1;
display: block;
font-size: 36px;
font-weight: 300;
text-shadow: 0 1px 0 #fff;
}
.hintf {
position: absolute;
left: 0;
width: 100%;
font-size: 12px;
color: #999;
padding-left: 20px;
text-align: left;
}
#csvdata {
display: none;
}
#parsed {
display: none;
}
path.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
path.link.twofive {
opacity: 0.25;
}
path.link.fivezero {
opacity: 0.50;
}
path.link.sevenfive {
opacity: 0.75;
}
path.link.onezerozero {
opacity: 1.0;
}
circle {
fill: #ccc;
stroke: #fff;
stroke-width: 1.5px;
cursor: crosshair;
}
text {
fill: #000;
font: 10px sans-serif;
pointer-events: none;
}
</style>
<body>
<div id="body">
<div id="header">
Pivot Map
<div class="hinth">Generated by pivotmap.sh</div>
</div>
<div id="footer">
Instructions
<div class="hintf">Click to turn swelled blue
<br />ALTClick to turn green
<br />SHIFTClick to turn red
<br />Click+drag nodes to make sticky
<br />MouseScroll to zoom
<br />Click+drag empty space to pan </div>
</div>
</div>
<div id="parsed"></div>
<script>
//convert CSV to JSON
var raw = d3.select("#csvdata").text();
var parsed = d3.csv.parse(raw);
d3.select("#parsed").text(JSON.stringify(parsed));
var links = JSON.parse(document.getElementById('parsed').innerHTML);
// get the data
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] ||
(nodes[link.source] = {
name: link.source
});
link.target = nodes[link.target] ||
(nodes[link.target] = {
name: link.target
});
link.value = +link.value;
});
var width = 1960,
height = 1500;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(60)
.charge(-700)
.gravity(.15)
.on("tick", tick)
.start();
// Set the range
var v = d3.scale.linear().range([0, 100]);
// Scale the range of the data
v.domain([0, d3.max(links, function(d) {
return d.value;
})]);
// assign a type per value to encode opacity
links.forEach(function(link) {
if (v(link.value) <= 25) {
link.type = "twofive";
} else if (v(link.value) <= 50 && v(link.value) > 25) {
link.type = "fivezero";
} else if (v(link.value) <= 75 && v(link.value) > 50) {
link.type = "sevenfive";
} else if (v(link.value) <= 100 && v(link.value) > 75) {
link.type = "onezerozero";
}
});
var vis = d3.select("#body")
.append("svg:svg")
.attr("width", width)
.attr("height", height)
.attr("pointer-events", "all")
.append('svg:g')
.call(d3.behavior.zoom().on("zoom", redraw)).on("dblclick.zoom", null)
.append('svg:g');
var svg = vis
vis.append('svg:rect')
.attr('width', width)
.attr('height', height)
.attr('fill', 'white');
function redraw() {
console.log("here", d3.event.translate, d3.event.scale);
vis.attr("transform",
"translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")");
}
// build the arrow.
svg.append("svg:defs").selectAll("marker")
.data(["end"]) // Different link/path types can be defined here
.enter().append("svg:marker") // This section adds in the arrows
.attr("id", String)
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -.15)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("svg:path")
.attr("d", "M0,-5L10,0L0,5");
// add the links and the arrows
var path = svg.append("svg:g").selectAll("path")
.data(force.links())
.enter().append("svg:path")
.attr("class", function(d) {
return "link " + d.type;
})
.attr("marker-end", "url(#end)");
// define the nodes
var node = svg.selectAll(".node")
.data(force.nodes())
.enter().append("g")
.attr("class", "node")
.on("mousedown", function() { d3.event.stopPropagation(); })
.on("click", click)
.on("dblclick", dblclick)
.call(force.drag);
// add the nodes
node.append("circle")
.attr("r", 5);
// add the text
node.append("text")
.attr("x", 12)
.attr("dy", ".35em")
.text(function(d) {
return d.name;
});
// add the curvy lines
function tick() {
path.attr("d", function(d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" +
d.source.x + "," +
d.source.y + "A" +
dr + "," + dr + " 0 0,1 " +
d.target.x + "," +
d.target.y;
});
node
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
}
// action to take on mouse click
function click(d) {
d3.select(this).select("text").transition()
.duration(750)
.attr("x", 22)
.style("fill", "steelblue")
.style("stroke", "lightsteelblue")
.style("stroke-width", ".5px")
.style("font", "20px sans-serif");
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 16)
.style("fill", "lightsteelblue");
if (d3.event.shiftKey) {
d3.select(this).select("circle").transition()
.style("fill", "red");
d3.select(this).classed("fixed", d.fixed = true);
d3.select(this).select("text").transition()
.style("fill", "red");
//.remove();
return;
}
if (d3.event.altKey) {
d3.select(this).select("circle").transition()
.style("fill", "green");
d3.select(this).classed("fixed", d.fixed = true);
d3.select(this).select("text").transition()
.style("fill", "green");
//.remove();
return;
}
d3.select(this).classed("fixed", d.fixed = true);
}
// action to take on mouse double click
function dblclick(d) {
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 6)
.style("fill", "#ccc");
d3.select(this).select("text").transition()
.duration(750)
.attr("x", 12)
.style("stroke", "none")
.style("fill", "black")
.style("stroke", "none")
.style("font", "10px sans-serif");
d3.select(this).classed("fixed", d.fixed = false);
}
// });
</script>
</body>
</html>