Files
urutau/internal/server/web/sessions.js
T
Lucas RayanandClaude Opus 5.5 432f521ed1
Release / Publish tags (push) Successful in 18s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 28s
CI / Format and vet (push) Successful in 23s
CI / Tests (Linux, race detector) (push) Successful in 1m24s
CI / Dependency audit (push) Successful in 24s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
feat: 1.4.1 pagination, network probes, survival by blocker, report polish
Backend pagination with one pager for sessions, IPs, campaigns and events;
network probe source (port-scan, T1046, second firewall reason port-scan);
host kit logs inbound probes; urutau call on the report cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 00:21:43 -03:00

215 lines
11 KiB
JavaScript

/* Urutau - SESSIONS page: funnel by escalation stage and the sessions that escalated.
Data: /api/v1/sessions/funnel. Log data is hostile: textContent only, classes from whitelists. */
(function () {
'use strict';
var STAGES = ['recon', 'probe', 'exploit', 'access', 'banned'];
var ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 5h18l-7 8v6l-4 2v-8z"/></svg>';
var SHOW = 25;
function boot() {
var U = window.Urutau;
if (!U || !U.registerPage) return false;
var t = U.t, nf = U.fmt.num;
function h(tag, a) { if (typeof a === 'string') a = { class: a }; return U.el.apply(null, [tag, a].concat([].slice.call(arguments, 2))); }
U.registerI18n({
en: {
'ss.title': 'Sessions',
'ss.lead.one': '{n} session; {k} reached exploitation',
'ss.lead.other': '{n} sessions; {k} reached exploitation',
'ss.lead.body': 'Sessions {range}, grouped by the furthest stage each one reached.',
'ss.lead.empty': 'No sessions in this slice',
'ss.lead.emptyBody': 'Nothing was recorded {range}, or the event registry is off.',
'ss.sampled': 'Showing the {n} most severe of {m} sessions.',
'ss.funnel': 'Escalation funnel',
'ss.funnel.hint': 'Sessions that reached each stage or went beyond it. Click a stage to filter the list.',
'ss.stage.recon': 'Recon',
'ss.stage.probe': 'Probe',
'ss.stage.exploit': 'Exploit',
'ss.stage.access': 'Access',
'ss.stage.banned': 'Banned',
'ss.f.stage': 'Stage',
'ss.f.host': 'Host',
'ss.f.fam': 'Family',
'ss.f.all': 'All',
'ss.list': 'Sessions',
'ss.c.ip': 'Address',
'ss.c.stage': 'Stage',
'ss.c.start': 'Start',
'ss.c.dur': 'Duration',
'ss.c.events': 'Events',
'ss.c.hosts': 'Hosts',
'ss.c.fam': 'Family',
'ss.c.replay': 'Replay',
'ss.replay': 'Replay',
'ss.n.one': '{n} session',
'ss.n.other': '{n} sessions',
'ss.none': 'No session matches these filters',
'ss.esc': 'Escalation chains',
'ss.esc.hint': 'The steps of the most serious sessions.',
'ss.err': 'Could not load the sessions.',
'ss.retry': 'Try again',
'ss.dur.s': '{n} s',
'ss.dur.m': '{n} min',
'ss.dur.h': '{n} h'
},
'pt-BR': {
'ss.title': 'Sessões',
'ss.lead.one': '{n} sessão; {k} chegaram a exploração',
'ss.lead.other': '{n} sessões; {k} chegaram a exploração',
'ss.lead.body': 'Sessões {range}, agrupadas pelo estágio mais avançado de cada uma.',
'ss.lead.empty': 'Nenhuma sessão neste recorte',
'ss.lead.emptyBody': 'Nada foi registrado {range}, ou o registro de eventos está desligado.',
'ss.sampled': 'Mostrando as {n} mais graves de {m} sessões.',
'ss.funnel': 'Funil de escalada',
'ss.funnel.hint': 'Sessões que chegaram a cada estágio ou foram além. Clique num estágio para filtrar a lista.',
'ss.stage.recon': 'Reconhecimento',
'ss.stage.probe': 'Sondagem',
'ss.stage.exploit': 'Exploração',
'ss.stage.access': 'Acesso',
'ss.stage.banned': 'Banido',
'ss.f.stage': 'Estágio',
'ss.f.host': 'Servidor',
'ss.f.fam': 'Família',
'ss.f.all': 'Todos',
'ss.list': 'Sessões',
'ss.c.ip': 'Endereço',
'ss.c.stage': 'Estágio',
'ss.c.start': 'Início',
'ss.c.dur': 'Duração',
'ss.c.events': 'Eventos',
'ss.c.hosts': 'Servidores',
'ss.c.fam': 'Família',
'ss.c.replay': 'Reprodução',
'ss.replay': 'Reproduzir',
'ss.n.one': '{n} sessão',
'ss.n.other': '{n} sessões',
'ss.none': 'Nenhuma sessão combina com estes filtros',
'ss.esc': 'Cadeias de escalada',
'ss.esc.hint': 'Os passos das sessões mais graves.',
'ss.err': 'Não foi possível carregar as sessões.',
'ss.retry': 'Tentar de novo',
'ss.dur.s': '{n} s',
'ss.dur.m': '{n} min',
'ss.dur.h': '{n} h'
}
});
function stg(s) { return STAGES.indexOf(s) >= 0 ? s : 'recon'; }
function dur(s) { return s < 90 ? t('ss.dur.s', s) : s < 5400 ? t('ss.dur.m', Math.round(s / 60)) : t('ss.dur.h', Math.round(s / 360) / 10); }
function iso(sec) { return new Date(sec * 1000).toISOString(); }
function topFam(s) { var b = '', n = 0; Object.keys(s.fams || {}).forEach(function (k) { if (s.fams[k] > n) { n = s.fams[k]; b = k; } }); return b; }
function link(ip) { return h('a', { class: 'mono ss-ip', href: '#/ip/' + encodeURIComponent(ip), text: ip }); }
function opt(sel, v, label) { sel.appendChild(h('option', { value: v, text: label })); }
var inst = null;
function Page(root, ctx) {
var self = this, data = null, seq = 0, alive = true, st = { stage: '', host: '', fam: '' };
this.ctx = ctx;
var wrap = h('div', 'ss');
root.appendChild(wrap);
function load() {
var my = ++seq;
U.api('/api/v1/sessions/funnel', Object.assign({ host: self.ctx.host, page: U.pageParam(), per_page: SHOW, stage: st.stage, host_f: st.host, fam: st.fam }, U.rangeParams())).then(function (d) {
if (!alive || my !== seq) return;
if (d.page > 1 && !(d.sessions || []).length && d.total) { U.setParam('p', d.pages); load(); return; } // stale link past the last page
data = d; paint();
}).catch(function () {
if (!alive || my !== seq || data) return;
var b = h('button', { type: 'button', class: 'btn', text: t('ss.retry') });
b.addEventListener('click', load);
wrap.textContent = '';
wrap.appendChild(h('div', 'state-error', h('strong', { text: t('ss.err') }), b));
});
}
function refilter() { U.setParam('p', 1); load(); }
function paint() {
wrap.textContent = '';
var d = data, n = d.sessions_n || 0, k = d.exploited || 0, range = U.rangeLabel({ inline: true });
wrap.appendChild(n ? U.ui.lead(U.pl('ss.lead', n, { n: nf(n), k: nf(k) }), t('ss.lead.body', { range: range }), k > 0 ? 'danger' : 'ok')
: U.ui.lead(t('ss.lead.empty'), t('ss.lead.emptyBody', { range: range }), 'neutral'));
if (!n) return;
// funnel
var max = Math.max(1, d.reached.recon || 1), fb = h('div', 'ss-funnel');
STAGES.forEach(function (g) {
var v = d.reached[g] || 0, b = h('button', { type: 'button', class: 'ss-fr' + (st.stage === g ? ' on' : '') });
b.appendChild(h('span', { class: 'ss-fl', text: t('ss.stage.' + g) }));
var bar = h('span', 'ss-fbar'), i = h('i', 'ss-s-' + g);
i.style.width = Math.max(v ? 2 : 0, v / max * 100) + '%';
bar.appendChild(i);
b.appendChild(bar);
b.appendChild(h('span', { class: 'ss-fn num', text: nf(v) }));
b.addEventListener('click', function () { st.stage = st.stage === g ? '' : g; refilter(); });
fb.appendChild(b);
});
wrap.appendChild(U.ui.panel({ title: t('ss.funnel'), help: 'term.session', hint: t('ss.funnel.hint') }, fb));
// filters
var f = h('div', 'ss-filters');
function sel(label, key, values, labeler) {
var s = h('select', { 'aria-label': label });
opt(s, '', label + ': ' + t('ss.f.all'));
values.forEach(function (v) { opt(s, v, labeler ? labeler(v) : v); });
s.value = values.indexOf(st[key]) >= 0 ? st[key] : '';
s.addEventListener('change', function () { st[key] = s.value; refilter(); });
f.appendChild(s);
}
sel(t('ss.f.stage'), 'stage', STAGES, function (g) { return t('ss.stage.' + g); });
sel(t('ss.f.host'), 'host', d.hosts || []);
sel(t('ss.f.fam'), 'fam', d.fams || []);
// list
var rows = d.sessions || [];
var body = h('div');
if (d.sampled && !st.stage && !st.host && !st.fam) body.appendChild(h('p', { class: 'note', text: t('ss.sampled', { n: nf(d.total), m: nf(n) }) }));
body.appendChild(f);
if (!rows.length) body.appendChild(U.ui.empty(t('ss.none')));
else {
var tb = h('tbody');
rows.forEach(function (s) {
var a = Math.floor(Date.parse(s.start) / 1000), b = Math.floor(Date.parse(s.end) / 1000);
var rp = h('a', { class: 'btn ss-rp', href: '#/replay?ip=' + encodeURIComponent(s.ip) + '&from=' + encodeURIComponent(iso(a - 60)) + '&to=' + encodeURIComponent(iso(b + 60)), text: t('ss.replay') });
function td(label, kid, cls) { return h('td', { 'data-label': label, class: cls || null }, kid); }
tb.appendChild(h('tr', 'row',
td(t('ss.c.ip'), link(s.ip)),
td(t('ss.c.stage'), h('span', { class: 'ss-badge ss-s-' + stg(s.stage), text: t('ss.stage.' + stg(s.stage)) })),
td(t('ss.c.start'), h('span', { text: U.fmt.date(a) }), 'nw'),
td(t('ss.c.dur'), h('span', { text: dur(s.dur_s || 0) })),
td(t('ss.c.events'), h('span', { class: 'num', text: nf(s.n || 0) })),
td(t('ss.c.hosts'), h('span', { text: (s.hosts || []).slice(0, 3).join(', ') })),
td(t('ss.c.fam'), h('span', { text: topFam(s) })),
td(t('ss.c.replay'), rp)));
});
var th = h('tr');
['ip', 'stage', 'start', 'dur', 'events', 'hosts', 'fam', 'replay'].forEach(function (c) { th.appendChild(h('th', { text: t('ss.c.' + c) })); });
body.appendChild(h('table', 'stack ss-table', h('thead', null, th), tb));
var pg = U.ui.pager({ page: d.page, pages: d.pages, total: d.total, totalText: U.pl('ss.n', d.total, { n: nf(d.total) }), onPage: function (n) { U.setParam('p', n); load(); } });
if (pg) body.appendChild(pg);
}
wrap.appendChild(U.ui.panel({ title: t('ss.list') }, body));
// escalation chains
if (d.escalations && d.escalations.length) {
var ul = h('div', 'ss-chains');
d.escalations.slice(0, 20).forEach(function (e) {
var steps = h('div', 'ss-steps');
(e.steps || []).slice(0, 12).forEach(function (p) {
steps.appendChild(h('span', { class: 'ss-step ss-s-' + stg(p.stage), title: String(p.evidence || ''), text: t('ss.stage.' + stg(p.stage)) }));
});
ul.appendChild(h('div', 'ss-chain', link(e.ip), steps));
});
wrap.appendChild(U.ui.panel({ title: t('ss.esc'), help: 'term.stage.exploit', hint: t('ss.esc.hint') }, ul));
}
}
this.update = function (c) { var lang = self.ctx.lang; self.ctx = c; if (lang !== c.lang && data) paint(); data = null; load(); };
this.refresh = function () { load(); };
this.destroy = function () { alive = false; seq++; root.textContent = ''; };
load();
}
U.registerPage({
id: 'sessions', group: 'investigate', icon: ICON, titleKey: 'ss.title',
mount: function (el, ctx) { if (inst) inst.destroy(); inst = new Page(el, ctx); },
update: function (ctx) { if (inst) inst.update(ctx); },
refresh: function () { if (inst) inst.refresh(); },
unmount: function () { if (inst) { inst.destroy(); inst = null; } }
});
return true;
}
if (!boot()) document.addEventListener('DOMContentLoaded', boot);
})();