-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_breach_attribution.js
More file actions
71 lines (60 loc) · 2.48 KB
/
update_breach_attribution.js
File metadata and controls
71 lines (60 loc) · 2.48 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
const fs = require('fs');
const path = require('path');
const dataFiles = [
path.join(__dirname, 'source', '_data', 'breaches.json'),
path.join(__dirname, 'source', 'data', 'breaches.json')
];
function cleanActorName(name) {
if (!name || name === 'null') return null;
// Nettoyage complet incluant le passage en minuscules pour éviter les doublons
return name.trim().replace(/["'`]/g, '').toLowerCase();
}
function updateAttributions(filePath) {
console.log(`Traitement de ${filePath}...`);
if (!fs.existsSync(filePath)) {
console.error(`Fichier ${filePath} introuvable.`);
return;
}
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
let updatedCount = 0;
data.breaches.forEach(breach => {
let changed = false;
// 1. Nettoyage et mise en minuscules de l'attribution existante
if (breach.Attribution && breach.Attribution !== 'null') {
const cleaned = cleanActorName(breach.Attribution);
if (cleaned !== breach.Attribution) {
breach.Attribution = cleaned;
changed = true;
}
}
// 2. Extraction si toujours vide ou null
if (!breach.Attribution || breach.Attribution === 'null') {
const description = breach.Description || breach.content || '';
const patterns = [
/par l'acteur de la menace\s+([^\s,.;!]+)/i,
/par l'acteur\s+([^\s,.;!]+)/i,
/L'acteur\s+([^\s,.;!]+)/i
];
for (const pattern of patterns) {
const match = description.match(pattern);
if (match && match[1]) {
const actorName = cleanActorName(match[1]);
const commonWords = ['de', 'la', 'un', 'une', 'le', 'les', 'des'];
if (actorName && !commonWords.includes(actorName.toLowerCase()) && actorName.length > 2) {
breach.Attribution = actorName;
changed = true;
break;
}
}
}
}
if (changed) updatedCount++;
});
if (updatedCount > 0) {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');
console.log(`Mis à jour de ${updatedCount} fuites (minuscules et nettoyage) dans ${filePath}.`);
} else {
console.log(`Aucune modification nécessaire pour ${filePath}.`);
}
}
dataFiles.forEach(updateAttributions);