Spaces:
Running

File size: 31,199 Bytes
cd932f8
 
 
 
 
47314b1
cd932f8
 
 
 
 
 
 
 
 
 
 
 
 
 
47314b1
cd932f8
47314b1
cd932f8
 
47314b1
cd932f8
 
47314b1
 
 
cd932f8
47314b1
cd932f8
 
47314b1
cd932f8
 
 
47314b1
 
 
cd932f8
 
 
47314b1
cd932f8
 
 
 
47314b1
cd932f8
 
 
47314b1
cd932f8
 
 
 
 
 
 
 
 
 
 
 
 
47314b1
 
 
 
 
cd932f8
 
 
 
47314b1
cd932f8
47314b1
cd932f8
 
 
 
 
 
47314b1
cd932f8
 
 
 
47314b1
 
 
 
 
 
 
 
 
 
cd932f8
 
 
47314b1
cd932f8
 
 
 
 
 
47314b1
 
 
 
 
cd932f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47314b1
cd932f8
66f14ef
 
47314b1
66f14ef
47314b1
66f14ef
 
 
 
 
47314b1
66f14ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47314b1
 
 
 
 
 
 
cd932f8
 
47314b1
 
 
 
 
 
 
 
cd932f8
 
47314b1
 
cd932f8
 
 
47314b1
cd932f8
 
 
 
47314b1
cd932f8
 
 
 
47314b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd932f8
47314b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd932f8
 
 
 
47314b1
cd932f8
 
47314b1
cd932f8
 
47314b1
cd932f8
 
 
 
47314b1
cd932f8
 
 
47314b1
 
 
 
 
cd932f8
 
 
47314b1
 
 
 
cd932f8
 
 
 
47314b1
cd932f8
 
47314b1
cd932f8
47314b1
 
 
cd932f8
 
 
 
47314b1
cd932f8
47314b1
 
cd932f8
 
 
 
 
 
47314b1
cd932f8
 
47314b1
cd932f8
47314b1
 
cd932f8
 
47314b1
 
 
cd932f8
 
 
 
 
 
 
 
 
47314b1
cd932f8
 
 
 
 
 
 
47314b1
cd932f8
47314b1
 
 
cd932f8
47314b1
cd932f8
 
 
 
 
 
 
 
 
47314b1
cd932f8
 
 
 
 
47314b1
 
 
 
 
 
cd932f8
47314b1
 
cd932f8
47314b1
cd932f8
47314b1
 
 
 
cd932f8
47314b1
cd932f8
47314b1
 
 
 
66f14ef
47314b1
cd932f8
47314b1
 
 
 
 
 
 
 
 
 
 
66f14ef
 
47314b1
 
66f14ef
 
 
 
47314b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd932f8
 
47314b1
 
cd932f8
47314b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd932f8
47314b1
cd932f8
 
 
 
47314b1
 
cd932f8
 
 
47314b1
 
 
 
 
 
cd932f8
47314b1
cd932f8
 
 
47314b1
 
 
 
 
cd932f8
47314b1
 
 
 
 
 
 
 
 
 
66f14ef
47314b1
 
 
 
 
cd932f8
 
 
 
 
 
 
 
47314b1
cd932f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47314b1
 
 
 
 
cd932f8
47314b1
 
 
 
cd932f8
47314b1
 
cd932f8
 
 
47314b1
cd932f8
 
 
47314b1
cd932f8
47314b1
 
 
 
 
 
 
 
 
cd932f8
 
47314b1
 
 
 
 
cd932f8
 
47314b1
 
 
cd932f8
 
 
47314b1
 
cd932f8
 
 
 
 
47314b1
 
 
cd932f8
 
 
47314b1
cd932f8
 
47314b1
cd932f8
 
 
 
 
 
 
 
47314b1
 
 
 
cd932f8
47314b1
 
cd932f8
 
 
47314b1
 
cd932f8
 
47314b1
 
cd932f8
 
 
 
 
 
47314b1
cd932f8
47314b1
 
 
 
 
 
cd932f8
 
47314b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd932f8
47314b1
 
 
 
 
 
 
 
cd932f8
 
 
 
 
e993677
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><rect width='16' height='16' fill='%230A0908'/><circle cx='8' cy='8' r='4' fill='%23D4A843'/></svg>">
<title>SENTRY INTEL β€” attacker telemetry</title>
<style>
  :root{
    --forge:#0A0908; --black2:#12100D; --gold:#D4A843; --gold-light:#E8C56D;
    --gold-muted:#8A7440; --stone:#6B6560; --bone:#F0EDE8; --hairline:#2A2418;
    --mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace;
  }
  *{box-sizing:border-box}
  html,body{margin:0;padding:0;background:var(--forge);color:var(--bone);
    font-family:var(--mono);font-size:13px;line-height:1.45;-webkit-font-smoothing:antialiased}
  a{color:var(--gold);text-decoration:none}
  a:hover{color:var(--gold-light)}
  .wrap{max-width:1560px;margin:0 auto;padding:18px 20px 60px}

  header.top{border-bottom:1px solid var(--hairline);padding-bottom:14px;margin-bottom:14px;
    display:flex;flex-wrap:wrap;align-items:flex-end;justify-content:space-between;gap:14px}
  .brand{display:flex;align-items:baseline;gap:12px;flex-wrap:wrap}
  .brand h1{margin:0;font-size:22px;letter-spacing:.24em;font-weight:600;color:var(--gold-light)}
  .brand .tag{color:var(--stone);letter-spacing:.14em;font-size:11px;text-transform:uppercase}
  .prov{font-size:11px;color:var(--stone);text-align:right;max-width:820px}
  .prov b{color:var(--gold-muted);font-weight:600}
  .prov .stale{color:var(--gold-light)}
  .frozen{display:inline-block;border:1px solid var(--gold-muted);color:var(--gold-light);
    font-size:10px;letter-spacing:.18em;text-transform:uppercase;padding:2px 7px;border-radius:2px;
    margin-bottom:6px}

  .kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(168px,1fr));gap:10px;margin-bottom:10px}
  .kpi{background:var(--black2);border:1px solid var(--hairline);border-left:2px solid var(--gold-muted);
    padding:10px 13px;border-radius:2px}
  .kpi.hot{border-left-color:var(--gold)}
  .kpi .lbl{font-size:10px;letter-spacing:.16em;color:var(--stone);text-transform:uppercase}
  .kpi .val{font-size:25px;color:var(--gold-light);font-weight:600;letter-spacing:.02em;margin-top:2px}
  .kpi .sub{font-size:10px;color:var(--stone);margin-top:2px}
  .strip{display:flex;flex-wrap:wrap;gap:6px 20px;font-size:11px;color:var(--stone);
    border:1px solid var(--hairline);background:var(--black2);padding:8px 13px;border-radius:2px;margin-bottom:16px}
  .strip b{color:var(--gold-light);font-weight:600}

  .grid{display:grid;gap:14px;margin-bottom:16px}
  .g2{grid-template-columns:1.35fr 1fr}
  .g2b{grid-template-columns:1fr 1.25fr}
  @media(max-width:1080px){.g2,.g2b{grid-template-columns:1fr}}

  .panel{background:var(--black2);border:1px solid var(--hairline);border-radius:2px;
    display:flex;flex-direction:column;min-width:0}
  .panel.pri{border-color:var(--gold-muted)}
  .panel > h2{margin:0;font-size:11px;letter-spacing:.18em;text-transform:uppercase;color:var(--stone);
    padding:9px 13px;border-bottom:1px solid var(--hairline);font-weight:600;
    display:flex;justify-content:space-between;align-items:center;gap:10px}
  .panel.pri > h2{color:var(--gold-light);border-bottom-color:var(--gold-muted)}
  .panel > h2 .hint{color:var(--gold-muted);letter-spacing:.06em;text-transform:none;font-size:10px}
  .panel .body{padding:12px 13px}
  .panel .body.tight{padding:0}

  canvas{display:block;width:100%}

  table{width:100%;border-collapse:collapse;font-size:11.5px}
  th{position:sticky;top:0;background:var(--black2);color:var(--stone);text-align:left;
    font-weight:600;letter-spacing:.1em;text-transform:uppercase;font-size:10px;
    padding:7px 9px;border-bottom:1px solid var(--hairline)}
  td{padding:5px 9px;border-bottom:1px solid rgba(42,36,24,.55);white-space:nowrap;color:var(--bone)}
  td.num{text-align:right;color:var(--gold-light)}
  td.dim{color:var(--stone)}
  td.url{white-space:normal;word-break:break-all;color:var(--gold)}
  tr.hitrow td{color:var(--gold-light)}
  .scroll{max-height:340px;overflow:auto}
  .scroll.tall{max-height:440px}
  .scroll.short{max-height:250px}
  .tagchip{display:inline-block;border:1px solid var(--hairline);border-radius:2px;color:var(--gold-muted);
    font-size:9.5px;letter-spacing:.08em;padding:1px 5px;text-transform:uppercase}

  .bars{display:flex;flex-direction:column;gap:6px}
  .bar{display:grid;grid-template-columns:96px 1fr 66px;align-items:center;gap:9px;font-size:11.5px}
  .bar .n{color:var(--gold-light);text-align:right}
  .bar .k{color:var(--stone);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .bar .track{background:rgba(42,36,24,.7);height:13px;border-radius:1px;overflow:hidden}
  .bar .fill{height:100%;background:var(--gold);opacity:.82}
  .bar .track.muted .fill{background:var(--stone)}

  .wraplegend{display:flex;flex-wrap:wrap;gap:14px;font-size:10.5px;color:var(--stone);margin-top:9px}
  .dot{display:inline-block;width:7px;height:7px;border-radius:50%;background:var(--gold);margin-right:5px}
  .dim{color:var(--stone)}

  select,input{background:var(--forge);color:var(--bone);border:1px solid var(--hairline);
    border-radius:2px;font-family:var(--mono);font-size:11.5px;padding:5px 7px;max-width:100%}
  select:focus,input:focus{outline:none;border-color:var(--gold-muted)}
  button{background:var(--forge);color:var(--stone);border:1px solid var(--hairline);border-radius:2px;
    font-family:var(--mono);font-size:10.5px;letter-spacing:.1em;text-transform:uppercase;
    padding:4px 10px;cursor:pointer}
  button:hover{color:var(--gold-light);border-color:var(--gold-muted)}
  button.on{color:var(--forge);background:var(--gold);border-color:var(--gold)}

  .inspect{display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px}
  @media(max-width:1180px){.inspect{grid-template-columns:1fr}}
  .codepane{background:var(--forge);border:1px solid var(--hairline);border-radius:2px;min-width:0;
    display:flex;flex-direction:column}
  .codepane h3{margin:0;font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:var(--stone);
    padding:6px 9px;border-bottom:1px solid var(--hairline);font-weight:600}
  .codepane pre{margin:0;padding:9px;font-size:11px;line-height:1.55;color:var(--gold-light);
    white-space:pre-wrap;word-break:break-all;max-height:260px;overflow:auto}
  .codepane pre.txt{color:var(--bone)}
  .meta{display:flex;flex-wrap:wrap;gap:8px 16px;font-size:11px;color:var(--stone);margin-bottom:10px}
  .meta b{color:var(--gold-light);font-weight:600}

  .note{font-size:10.5px;color:var(--stone);line-height:1.6;margin-top:10px;
    border-left:2px solid var(--hairline);padding-left:9px}
  .dk{display:flex;flex-wrap:wrap;gap:10px;margin-top:4px}
  .dkbox{border:1px solid var(--gold-muted);background:var(--forge);border-radius:2px;
    padding:9px 12px;min-width:180px}
  .dkbox .k{font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:var(--stone)}
  .dkbox .v{font-size:16px;color:var(--gold-light);margin-top:3px;letter-spacing:.08em}
  footer{margin-top:26px;border-top:1px solid var(--hairline);padding-top:12px;
    font-size:10.5px;color:var(--stone);display:flex;flex-wrap:wrap;gap:6px 22px;justify-content:space-between}
  .warn{color:var(--gold-muted)}
  ::-webkit-scrollbar{width:9px;height:9px}
  ::-webkit-scrollbar-track{background:var(--forge)}
  ::-webkit-scrollbar-thumb{background:var(--hairline);border-radius:0}
  ::-webkit-scrollbar-thumb:hover{background:var(--gold-muted)}
</style>
</head>
<body>
<div class="wrap">

  <header class="top">
    <div class="brand">
      <h1>SENTRY&nbsp;INTEL</h1>
      <span class="tag">tarpit telemetry Β· attacker-side</span>
    </div>
    <div class="prov" id="prov">loading dataset…</div>
  </header>

  <div class="kpis" id="kpis"></div>
  <div class="strip" id="kpis2"></div>

  <!-- PRIMARY INTEL PANEL β€” endpoints the intruders actually used -->
  <div class="grid g2">
    <div class="panel pri">
      <h2>Attacker endpoints <span class="hint" id="c2hint"></span></h2>
      <div class="body tight">
        <p style="color:#6B6560;font-size:11.5px;line-height:1.5;margin:0 0 10px">
          URLs found <b style="color:#D4A843">inside the bytes the attacker sent</b> β€” endpoints they
          actually tried to pull a payload or push data to. These are real callbacks.
        </p>
        <div class="scroll" style="max-height:360px">
          <table id="t_c2">
            <thead><tr><th class="num" style="width:64px">hits</th><th>endpoint</th></tr></thead>
            <tbody></tbody></table>
        </div>
      </div>
    </div>
    <div class="panel">
      <h2>Scanner self-identifiers <span class="hint" id="scihint"></span></h2>
      <div class="body tight">
        <p style="color:#6B6560;font-size:11.5px;line-height:1.5;margin:0 0 10px">
          URLs that appear <b style="color:#F0EDE8">only in a client's User-Agent</b>, never in payload
          bytes β€” crawlers and research scanners announcing themselves. <b style="color:#F0EDE8">Not callbacks.</b>
        </p>
        <div class="scroll" style="max-height:360px">
          <table id="t_sci">
            <thead><tr><th class="num" style="width:64px">hits</th><th>crawler identifier</th></tr></thead>
            <tbody></tbody></table>
        </div>
      </div>
    </div>
  </div>

  <!-- load over time (+ daily) & protocol mix -->
  <div class="grid g2">
    <div class="panel">
      <h2>Load over time
        <span>
          <button id="b_hour" class="on">hourly</button>
          <button id="b_day">daily</button>
          <span class="hint" id="tlhint"></span>
        </span>
      </h2>
      <div class="body"><canvas id="c_time" height="214"></canvas></div>
    </div>
    <div class="panel">
      <h2>Protocol mix <span class="hint">sensor wire protocol</span></h2>
      <div class="body" id="protocols"></div>
    </div>
  </div>

  <!-- geography & attack paths -->
  <div class="grid g2b">
    <div class="panel">
      <h2>Attacker geography <span class="hint">per-subnet /24 cluster β€” real coords, offline-resolved</span></h2>
      <div class="body">
        <canvas id="c_map" height="372"></canvas>
        <div class="wraplegend" id="mlegend"></div>
      </div>
    </div>
    <div class="panel">
      <h2>Top attack paths <span class="hint">nginx decoy hits β€” web attack surface</span></h2>
      <div class="body" id="attack_paths"></div>
    </div>
  </div>

  <!-- sensor event mix & honeypot client mix -->
  <div class="grid g2">
    <div class="panel">
      <h2>Sensor event mix <span class="hint" id="evhint"></span></h2>
      <div class="body" id="events"></div>
    </div>
    <div class="panel">
      <h2>Honeypot client type mix <span class="hint" id="hphint"></span></h2>
      <div class="body" id="honeypot"></div>
    </div>
  </div>

  <!-- tool fingerprints & credential capture / decoy keys -->
  <div class="grid g2">
    <div class="panel">
      <h2>Tool fingerprints <span class="hint">client library / user-agent</span></h2>
      <div class="body tight">
        <div class="scroll"><table id="t_tools">
          <thead><tr><th>fingerprint</th><th class="num" style="width:78px">events</th></tr></thead>
          <tbody></tbody></table></div>
      </div>
    </div>
    <div class="panel">
      <h2>Credential capture <span class="hint" id="credhint"></span></h2>
      <div class="body tight">
        <div class="scroll short"><table id="t_cred">
          <thead><tr><th>timestamp</th><th>source ip</th><th>proto</th><th>user</th><th>cc</th></tr></thead>
          <tbody></tbody></table></div>
      </div>
      <div class="panel" style="border:0;border-top:1px solid var(--hairline)">
        <h2>Decoy access keys captured <span class="hint">honeytoken value exfiltrated by attackers</span></h2>
        <div class="body" id="decoy"></div>
      </div>
    </div>
  </div>

  <!-- recent sessions -->
  <div class="grid">
    <div class="panel">
      <h2>Recent sessions <span class="hint" id="rechint"></span></h2>
      <div class="body tight">
        <div class="scroll tall"><table id="t_recent">
          <thead><tr><th>timestamp</th><th>source ip</th><th>cc</th><th class="num">port</th>
          <th>proto</th><th>event</th><th>tool</th><th>path</th></tr></thead>
          <tbody></tbody></table></div>
      </div>
    </div>
  </div>

  <!-- payload inspector -->
  <div class="grid">
    <div class="panel">
      <h2>Payload inspector <span class="hint">pick a captured session β€” raw bytes ↔ decoded text</span></h2>
      <div class="body">
        <div class="meta" style="margin-bottom:10px">
          <label>session <select id="sel"></select></label>
          <span id="imeta" style="align-self:center"></span>
        </div>
        <div class="inspect">
          <div class="codepane">
            <h3>raw hex β€” payload_hex field</h3>
            <pre id="hex"></pre>
          </div>
          <div class="codepane">
            <h3>byte hex β€” derived (utf-8)</h3>
            <pre id="dhex"></pre>
          </div>
          <div class="codepane">
            <h3>decoded text β€” payload_text field</h3>
            <pre id="txt" class="txt"></pre>
          </div>
        </div>
        <div class="note">Literal <span style="color:var(--gold-muted)">\n</span> sequences render as typed. The
          <span style="color:var(--gold-muted)">payload_hex</span> pane carries the captured payload string exactly as the
          extractor wrote it; the derived byte-hex pane is the same bytes encoded UTF-8, so a hash or grep against the
          source log verifies byte-for-byte. An empty pane means no payload bytes were captured for that connection.</div>
      </div>
    </div>
  </div>

  <!-- top subnets & top IPs -->
  <div class="grid g2">
    <div class="panel">
      <h2>Top source subnets /24 <span class="hint">cluster centroid</span></h2>
      <div class="body tight">
        <div class="scroll"><table id="t_sub">
          <thead><tr><th>subnet</th><th>cc</th><th class="num">events</th><th class="num">ips</th>
          <th class="num">lat</th><th class="num">lon</th></tr></thead>
          <tbody></tbody></table></div>
      </div>
    </div>
    <div class="panel">
      <h2>Top source IPs</h2>
      <div class="body tight">
        <div class="scroll"><table id="t_ips">
          <thead><tr><th>ip</th><th>country</th><th>city</th><th class="num">events</th>
          <th class="num">lat</th><th class="num">lon</th></tr></thead>
          <tbody></tbody></table></div>
      </div>
    </div>
  </div>

  <!-- provenance -->
  <div class="grid g2b">
    <div class="panel">
      <h2>Source files &amp; digests <span class="hint">sha256 per sensor log</span></h2>
      <div class="body tight">
        <div class="scroll"><table id="t_src">
          <thead><tr><th>file</th><th class="num">bytes</th><th>sha256</th></tr></thead>
          <tbody></tbody></table></div>
      </div>
      <div class="body" style="border-top:1px solid var(--hairline)">
        <div class="note" id="geonote"></div>
      </div>
    </div>
    <div class="panel">
      <h2>Provenance &amp; method</h2>
      <div class="body" id="method"></div>
    </div>
  </div>

  <footer>
    <span id="f_left"></span>
    <span class="warn">NOT A LIVE FEED β€” a frozen capture. Data reflects the sensor log window above, nothing since.</span>
  </footer>
</div>

<script>
const C = {forge:'#0A0908',black2:'#12100D',gold:'#D4A843',goldLight:'#E8C56D',
           goldMuted:'#8A7440',stone:'#6B6560',bone:'#F0EDE8',hair:'#2A2418'};
const $ = s => document.querySelector(s);
const fmt = n => (n==null?'β€”':Number(n).toLocaleString('en-US'));
const cc = s => (s||'--').toUpperCase();
const esc = s => (s==null?'':String(s)).replace(/[&<>"']/g, c =>
  ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const tsShort = t => (t||'').replace('T',' ').slice(0,19);

let DATA=null, LM=null, TSMODE='hour';

async function boot(){
  try{
    const [d,l] = await Promise.all([
      fetch('data/intel.json').then(r=>{ if(!r.ok) throw new Error('intel.json HTTP '+r.status); return r.json(); }),
      fetch('data/landmask.json').then(r=>{ if(!r.ok) throw new Error('landmask.json HTTP '+r.status); return r.json(); })
    ]);
    DATA=d; LM=l;
  }catch(e){
    document.getElementById('prov').innerHTML='DATASET LOAD FAILED: '+esc(e.message);
    return;
  }
  renderAll();
}

function shortTool(t){
  if(!t) return 'β€”';
  const s=String(t);
  return s.length>46 ? s.slice(0,45)+'…' : s;
}

function renderAll(){
  const T=DATA.totals, W=DATA.window;
  const winH = (new Date(W.last)-new Date(W.first))/3600000;

  // ---- provenance header ----
  $('#prov').innerHTML =
    `<span class="frozen">frozen capture Β· point-in-time snapshot</span><br>`+
    `dataset generated <b>${esc(DATA.generated_at)}</b> Β· feed <b>${esc(DATA.feed)}</b><br>`+
    `capture window <span class="stale">${tsShort(W.first)} β†’ ${tsShort(W.last)}</span> `+
    `<span style="color:var(--gold-muted)">(${winH.toFixed(0)} h Β· not re-polled)</span>`;

  // ---- KPIs ----
  const kpis=[
    ['total events', fmt(T.events), T.sessions.toLocaleString('en-US')+' sessions parsed', false],
    ['unique attacking IPs', fmt(T.unique_ips), T.alert_ips+' flagged in HIGH alerts', false],
    ['unique /24 subnets', fmt(T.unique_subnets), 'distinct source networks', false],
    ['HIGH C2 alerts', fmt(T.high_alerts), 'beacon alerts raised', true],
    ['attacker endpoints', fmt(T.c2_urls), 'URLs found in payload bytes', true],
    ['decoy keys captured', fmt(T.decoy_keys), 'honeytoken value exfiltrated', true]
  ];
  $('#kpis').innerHTML = kpis.map(([l,v,s,hot])=>
    `<div class="kpi${hot?' hot':''}"><div class="lbl">${l}</div><div class="val">${v}</div><div class="sub">${s}</div></div>`).join('');

  $('#kpis2').innerHTML =
    `<span>poison hits <b>${fmt(T.poison_hits)}</b></span>`+
    `<span>honeypot sessions <b>${fmt(T.honeypot_sessions)}</b></span>`+
    `<span>credential events <b>${fmt(T.credential_events)}</b></span>`+
    `<span>capture span <b>${winH.toFixed(0)} h</b></span>`+
    `<span>hourly bins <b>${fmt(DATA.timeline.length)}</b></span>`+
    `<span>days observed <b>${fmt(DATA.daily.length)}</b></span>`;

  // ---- attacker endpoints (payload-borne) + scanner self-IDs (primary) ----
  $('#c2hint').textContent = DATA.c2_urls.length+' endpoints Β· payload-borne';
  $('#t_c2 tbody').innerHTML = DATA.c2_urls.map((u,i)=>
    `<tr class="${i<3?'hitrow':''}"><td class="num">${fmt(u.count)}</td><td class="url">${esc(u.url)}</td></tr>`).join('');
  const SCI = DATA.scanner_ids || [];
  $('#scihint').textContent = SCI.length+' client UA identifiers';
  $('#t_sci tbody').innerHTML = SCI.map(u=>
    `<tr><td class="num">${fmt(u.count)}</td><td class="url">${esc(u.url)}</td></tr>`).join('');

  // ---- protocol mix ----
  bars('#protocols', DATA.protocols.map(p=>[p.name, p.count]));

  // ---- sensor event mix ----
  $('#evhint').textContent = fmt(T.events)+' parsed events';
  bars('#events', DATA.events.map(e=>[e.name, e.count]), true);

  // ---- honeypot client mix ----
  $('#hphint').textContent = fmt(DATA.honeypot.rows)+' honeypot rows';
  bars('#honeypot', DATA.honeypot.types.map(h=>[h.name, h.count]), true);

  // ---- attack paths ----
  bars('#attack_paths', DATA.attack_paths.map(p=>[p.name, p.count]));

  // ---- load over time ----
  $('#tlhint').textContent = TSMODE==='hour' ? DATA.timeline.length+' hourly bins' : DATA.daily.length+' daily bins';
  drawTime();

  // ---- geography ----
  drawMap();

  // ---- tool fingerprints ----
  $('#t_tools tbody').innerHTML = DATA.tools.map(t=>
    `<tr><td class="dim" style="white-space:normal;word-break:break-all">${esc(t.name||'β€”')}</td>`+
    `<td class="num">${fmt(t.count)}</td></tr>`).join('');

  // ---- credentials + decoy keys ----
  $('#credhint').textContent = DATA.credentials.length+' captured credential events';
  $('#t_cred tbody').innerHTML = DATA.credentials.map(c=>
    `<tr><td class="dim">${tsShort(c.ts)}</td><td>${esc(c.ip)}</td>`+
    `<td><span class="tagchip">${esc(c.protocol)}</span></td>`+
    `<td class="dim">${esc(c.user||'β€”')}</td><td class="dim">${cc(c.country)}</td></tr>`).join('');
  $('#decoy').innerHTML = DATA.decoy_keys.length
    ? '<div class="dk">'+DATA.decoy_keys.map(k=>
        `<div class="dkbox"><div class="k">decoy key</div><div class="v">${esc(k)}</div></div>`).join('')+'</div>'
      + `<div class="note">Reference value planted in the decoy surface. Any occurrence in a captured payload means the
         attacker read the honeytoken and sent it back β€” it is not a working credential.</div>`
    : '<div class="dim">no decoy keys observed in the window</div>';

  // ---- recent sessions ----
  $('#rechint').textContent = DATA.recent.length+' newest captured sessions';
  $('#t_recent tbody').innerHTML = DATA.recent.map(r=>
    `<tr><td class="dim">${tsShort(r.ts)}</td><td>${esc(r.ip)}</td><td class="dim">${cc(r.country)}</td>`+
    `<td class="num">${r.port==null?'β€”':r.port}</td>`+
    `<td><span class="tagchip">${esc(r.proto||'β€”')}</span></td><td class="dim">${esc(r.event||'β€”')}</td>`+
    `<td class="dim" style="white-space:normal;word-break:break-all;max-width:260px">${esc(shortTool(r.tool))}</td>`+
    `<td class="dim">${esc(r.path||'β€”')}</td></tr>`).join('');

  // ---- subnet / ip tables ----
  $('#t_sub tbody').innerHTML = DATA.subnets.slice(0,80).map(s=>
    `<tr><td>${esc(s.subnet)}</td><td class="dim">${cc(s.country)}</td><td class="num">${fmt(s.count)}</td>`+
    `<td class="num">${s.ips}</td>`+
    `<td class="num dim">${s.lat==null?'β€”':s.lat.toFixed(2)}</td>`+
    `<td class="num dim">${s.lon==null?'β€”':s.lon.toFixed(2)}</td></tr>`).join('');
  $('#t_ips tbody').innerHTML = DATA.top_ips.map(s=>
    `<tr><td>${esc(s.ip)}</td><td class="dim">${esc(s.country_name||cc(s.country))}</td>`+
    `<td class="dim">${esc(s.city||'β€”')}</td><td class="num">${fmt(s.count)}</td>`+
    `<td class="num dim">${s.lat==null?'β€”':s.lat.toFixed(2)}</td>`+
    `<td class="num dim">${s.lon==null?'β€”':s.lon.toFixed(2)}</td></tr>`).join('');

  // ---- sources / geo note ----
  $('#t_src tbody').innerHTML = DATA.sources.map(s=>
    `<tr><td>${esc(s.name)}</td><td class="num">${fmt(s.bytes)}</td>`+
    `<td class="dim" title="${esc(s.sha256)}">${esc(s.sha256.slice(0,24))}…</td></tr>`).join('');
  $('#geonote').innerHTML = `<span style="color:var(--gold-muted)">geo note</span> β€” ${esc(DATA.geo_note)}`;

  $('#mlegend').innerHTML =
    `<span><span class="dot"></span>subnet cluster β€” radius ∝ log(events)</span>`+
    `<span class="dim">${DATA.subnets.filter(s=>s.lat!=null).length} plotted of ${DATA.subnets.length} subnets</span>`+
    `<span class="dim">land mask: Natural Earth 110m (offline)</span>`;

  $('#method').innerHTML =
    DATA.sources.map(s=>
      `<div><b style="color:var(--gold-muted)">source</b> ${esc(s.name)}<br>`+
      `<span style="color:var(--stone)">&nbsp;&nbsp;${esc(s.remote_path)}<br>`+
      `&nbsp;&nbsp;${fmt(s.bytes)} B Β· sha256 ${esc(s.sha256.slice(0,16))}…</span></div>`
    ).join('<hr style="border:0;border-top:1px solid var(--hairline);margin:9px 0">')
    + `<div class="note"><b style="color:var(--gold-muted)">frozen capture.</b> These logs were read once at build time;
       this page is a point-in-time snapshot and never re-polls the sensors. Every coordinate was resolved offline
       against a local GeoLite2-City database β€” zero runtime geo API calls.<br><br>`+
      `Static Space: plain HTML/CSS/JS committed to the repo, no build step, no framework, no runtime network calls.
       Charts and the world view are hand-rolled canvas; the land mask and every coordinate are baked into
       <span style="color:var(--gold-muted)">data/</span> by <span style="color:var(--gold-muted)">scripts/parse_live.py</span>.<br><br>`+
      `Attacker-side telemetry only: source IPs that probed the tarpit, the ports they hit and the bytes they sent. No
       operator data, no working credentials, no interior network detail.</div>`;

  $('#f_left').innerHTML = `SENTRY INTEL Β· ${fmt(T.events)} events Β· ${fmt(T.unique_ips)} src IPs Β· `+
    `${DATA.c2_urls.length} attacker endpoints Β· ${fmt(T.high_alerts)} HIGH alerts Β· built ${esc(DATA.generated_at)}`;

  $('#b_hour').onclick = ()=>{ TSMODE='hour'; $('#b_hour').classList.add('on'); $('#b_day').classList.remove('on');
    $('#tlhint').textContent = DATA.timeline.length+' hourly bins'; drawTime(); };
  $('#b_day').onclick  = ()=>{ TSMODE='day';  $('#b_day').classList.add('on'); $('#b_hour').classList.remove('on');
    $('#tlhint').textContent = DATA.daily.length+' daily bins'; drawTime(); };

  buildInspector();
  window.addEventListener('resize', ()=>{ drawTime(); drawMap(); });
}

function bars(sel, rows, muted){
  const max = Math.max(...rows.map(r=>r[1]),1);
  $(sel).innerHTML = '<div class="bars">'+rows.map(([k,v])=>
    `<div class="bar"><span class="k" title="${esc(k)}">${esc(k)}</span>`+
    `<span class="track${muted?' muted':''}"><span class="fill" style="width:${(100*v/max).toFixed(2)}%"></span></span>`+
    `<span class="n">${fmt(v)}</span></div>`).join('')+'</div>';
}

function prep(cv,h){
  const dpr = window.devicePixelRatio||1;
  const w = cv.clientWidth||600;
  cv.width = Math.round(w*dpr); cv.height = Math.round(h*dpr);
  cv.style.height = h+'px';
  const x = cv.getContext('2d');
  x.setTransform(dpr,0,0,dpr,0,0);
  x.clearRect(0,0,w,h);
  return {x,w,h};
}

function series(){
  if(TSMODE==='hour') return DATA.timeline.map(p=>({l:p.t.slice(5,13).replace('T',' '),count:p.count}));
  return DATA.daily.map(p=>({l:p.d.slice(5),count:p.count}));
}

function drawTime(){
  const cv=$('#c_time'); if(!cv||!DATA) return;
  const {x,w,h}=prep(cv,214);
  const S=series(); if(!S.length) return;
  const pad={l:62,r:14,t:14,b:26};
  const iw=w-pad.l-pad.r, ih=h-pad.t-pad.b;
  const max=Math.max(...S.map(p=>p.count))||1;
  const sx=i=>pad.l+(S.length<2?iw/2:iw*i/(S.length-1));
  const sy=v=>pad.t+ih-(v/max)*ih;

  x.strokeStyle=C.hair; x.lineWidth=1;
  x.font='10px ui-monospace,monospace';
  for(let i=0;i<=4;i++){
    const v=max*i/4, y=sy(v);
    x.beginPath(); x.moveTo(pad.l,y); x.lineTo(pad.l+iw,y); x.stroke();
    x.fillStyle=C.stone; x.textAlign='right'; x.fillText(Math.round(v).toLocaleString('en-US'),pad.l-7,y+3.5);
  }

  // one bar per bin β€” hairline-scaled so dense hourly bins stay legible
  const bw=Math.max(iw/S.length-0.4, 0.9);
  x.fillStyle='rgba(212,168,67,.72)';
  S.forEach((p,i)=>{ const bh=(p.count/max)*ih; x.fillRect(sx(i)-bw/2, pad.t+ih-bh, bw, bh); });

  // line on top
  x.beginPath(); S.forEach((p,i)=>{ i?x.lineTo(sx(i),sy(p.count)):x.moveTo(sx(i),sy(p.count)); });
  x.strokeStyle=C.goldLight; x.lineWidth=1.3; x.stroke();

  // peak marker
  let pi=0; S.forEach((p,i)=>{ if(p.count>S[pi].count) pi=i; });
  x.beginPath(); x.arc(sx(pi),sy(S[pi].count),3.2,0,7); x.fillStyle=C.goldLight; x.fill();
  x.textAlign='left';
  x.fillText(S[pi].count.toLocaleString('en-US')+' peak @ '+S[pi].l,
             Math.min(sx(pi)+7,w-180), Math.max(sy(S[pi].count)-7,pad.t+10));

  x.fillStyle=C.stone; x.textAlign='center';
  const step=Math.max(Math.ceil(S.length/7),1);
  S.forEach((p,i)=>{ if(i%step===0) x.fillText(p.l, sx(i), h-9); });
  x.textAlign='left'; x.fillText(TSMODE==='hour'?'events / hour':'events / day', pad.l, pad.t+9);
}

function drawMap(){
  const cv=$('#c_map'); if(!cv||!DATA) return;
  const {x,w,h}=prep(cv,372);
  const pad={l:6,r:6,t:6,b:6};
  const iw=w-pad.l-pad.r, ih=h-pad.t-pad.b;
  const X=lon=>pad.l+(lon+180)/360*iw;
  const Y=lat=>pad.t+(90-lat)/180*ih;

  x.fillStyle=C.black2; x.fillRect(0,0,w,h);

  // land silhouette
  if(LM){
    const bytes=Uint8Array.from(atob(LM.b64),c=>c.charCodeAt(0));
    const cw=iw/LM.w, ch=ih/LM.h;
    x.fillStyle='rgba(107,101,96,.36)';
    for(let r=0;r<LM.h;r++)for(let c=0;c<LM.w;c++){
      const k=r*LM.w+c;
      if((bytes[k>>3]>>(7-(k&7)))&1) x.fillRect(pad.l+c*cw,pad.t+r*ch,cw+0.6,ch+0.6);
    }
  }
  // graticule
  x.strokeStyle='rgba(42,36,24,.9)'; x.lineWidth=1;
  for(let lon=-150;lon<=150;lon+=30){ x.beginPath(); x.moveTo(X(lon),pad.t); x.lineTo(X(lon),pad.t+ih); x.stroke(); }
  for(let lat=-60;lat<=60;lat+=30){ x.beginPath(); x.moveTo(pad.l,Y(lat)); x.lineTo(pad.l+iw,Y(lat)); x.stroke(); }
  x.strokeStyle=C.hair; x.strokeRect(pad.l,pad.t,iw,ih);

  // blips β€” radius ∝ log(count)
  const pts=DATA.subnets.filter(s=>s.lat!=null&&s.lon!=null).slice().sort((a,b)=>a.count-b.count);
  pts.forEach(s=>{
    const r=2.0+3.1*Math.log10(s.count+1);
    const cx=X(s.lon), cy=Y(s.lat);
    const a=0.30+0.55*Math.min(Math.log10(s.count+1)/4,1);
    x.beginPath(); x.arc(cx,cy,r*2.5,0,7); x.fillStyle='rgba(212,168,67,'+(a*0.16).toFixed(3)+')'; x.fill();
    x.beginPath(); x.arc(cx,cy,r,0,7); x.fillStyle='rgba(232,197,109,'+a.toFixed(3)+')'; x.fill();
    x.strokeStyle='rgba(212,168,67,.85)'; x.lineWidth=1; x.stroke();
  });
  // label top two clusters
  DATA.subnets.filter(s=>s.lat!=null).slice(0,2).forEach(s=>{
    const cx=X(s.lon), cy=Y(s.lat);
    x.font='10px ui-monospace,monospace'; x.fillStyle=C.goldLight; x.textAlign='left';
    const t=s.subnet+'  '+s.count.toLocaleString('en-US');
    const tx=Math.min(cx+13,w-142), ty=Math.max(cy-11,pad.t+11);
    x.fillText(t,tx,ty);
    x.strokeStyle='rgba(212,168,67,.55)'; x.beginPath(); x.moveTo(cx,cy); x.lineTo(tx-3,ty-3); x.stroke();
  });
}

function buildInspector(){
  const rows=DATA.recent;
  const sel=$('#sel');
  sel.innerHTML = rows.map((r,i)=>
    `<option value="${i}">${tsShort(r.ts)}  ${r.ip}:${r.port==null?'β€”':r.port}  [${r.proto}]${(r.payload_hex||r.payload_text)?'  payload':''}</option>`).join('');
  sel.onchange = ()=>show(rows[+sel.value]);
  const first = rows.findIndex(r=>r.payload_hex||r.payload_text);
  sel.value = first>=0?first:0;
  show(rows[+sel.value]);
}

function show(r){
  if(!r) return;
  const hex = r.payload_hex||'', txt = r.payload_text||'';
  $('#hex').textContent = hex || '(no payload bytes captured for this connection)';
  $('#txt').textContent = txt || '(no payload bytes captured for this connection)';
  let dhex='(no bytes)';
  const src = txt||hex;
  if(src){
    try{
      const bytes = new TextEncoder().encode(src);
      const parts=[];
      for(let i=0;i<bytes.length;i++) parts.push(bytes[i].toString(16).padStart(2,'0'));
      dhex = parts.join(' ');
    }catch(e){ dhex='(encode failed: '+e.message+')'; }
  }
  $('#dhex').textContent = dhex;
  $('#imeta').innerHTML =
    `<span>src <b>${esc(r.ip)}${r.port==null?'':':'+r.port}</b></span>`+
    `<span>${tsShort(r.ts)}</span>`+
    `<span>proto <b>${esc(r.proto||'β€”')}</b></span>`+
    `<span>event <b>${esc(r.event||'β€”')}</b></span>`+
    `<span>tool <b>${esc(shortTool(r.tool))}</b></span>`+
    `<span>cc <b>${cc(r.country)}</b></span>`+
    (r.path?`<span>path <b>${esc(r.path)}</b></span>`:'')+
    `<span>bytes <b>${txt?txt.length:0}</b></span>`;
}

boot();
</script>
</body>
</html>