src/detection/heuristics.ts (view raw)
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 |
import type { Detection, Observations } from '../core/types.js';
import { faixaDe } from './confidence.js';
export function heuristicas(obs: Observations, jaDetectadas: Detection[]): Detection[] {
const extra: Detection[] = [];
const nomes = new Set(jaDetectadas.map((d) => d.nome));
if (obs.cdnAparente && !nomes.has(obs.cdnAparente)) {
const evidencia = pistaCdn(obs);
if (evidencia) {
extra.push({
nome: obs.cdnAparente,
categorias: ['CDN'],
confianca: 80,
faixa: faixaDe(80),
evidencias: [evidencia],
});
}
}
return extra;
}
function pistaCdn(obs: Observations) {
const h = obs.headers;
const cabecalhos = ['cf-ray', 'x-vercel-id', 'x-amz-cf-id', 'x-fastly-request-id', 'x-nf-request-id'];
for (const c of cabecalhos) {
if (h[c] != null) {
return { fonte: 'header' as const, descricao: `cabeƧalho ${c}`, trecho: h[c] };
}
}
if (h['server']) {
return { fonte: 'header' as const, descricao: 'cabeƧalho Server', trecho: h['server'] };
}
return undefined;
}
|