-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimproveddummy.ts
97 lines (85 loc) · 2.88 KB
/
improveddummy.ts
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
import axios from 'axios';
import dns from 'dns';
import { promisify } from 'util';
const mispUrl = 'https://your-misp-instance-url';
const mispKey = 'YOUR_MISP_API_KEY';
const mispVerifyCert = false;
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const resolvePtr = promisify(dns.resolvePtr);
const randomIp = () => {
return `${Math.floor(Math.random() * 255) + 1}.${Math.floor(Math.random() * 255)}.${Math.floor(Math.random() * 255)}.${Math.floor(Math.random() * 255)}`;
};
const randomDate = (start, end) => {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime())).toISOString();
};
const malwareNames = ['MalwareA', 'MalwareB', 'MalwareC', 'MalwareD'];
const countryCodes = ['US', 'CA', 'DE', 'FR', 'JP'];
const createDummyEvent = async () => {
const originIpAddress = randomIp();
const countryCode = countryCodes[Math.floor(Math.random() * countryCodes.length)];
let hostname;
try {
const hostnames = await resolvePtr(originIpAddress);
hostname = hostnames[0];
} catch (error) {
hostname = 'Unknown';
}
const lastOnline = randomDate(new Date(2022, 0, 1), new Date());
const lastSeen = randomDate(new Date(2022, 0, 1), new Date());
const malwareName = malwareNames[Math.floor(Math.random() * malwareNames.length)];
const eventInfo = `Dummy Event - ${Math.floor(Math.random() * 90000) + 10000}`;
const eventData = {
info: eventInfo,
distribution: 0,
threat_level_id: 2,
analysis: 1,
Attribute: [
{
type: 'ip-dst',
value: originIpAddress
},
{
type: 'country',
value: countryCode
},
{
type: 'hostname',
value: hostname
},
{
type: 'datetime',
value: lastOnline,
comment: 'Last Online'
},
{
type: 'datetime',
value: lastSeen,
comment: 'Last Seen'
},
{
type: 'text',
value: malwareName,
comment: 'Malware Name'
}
]
};
try {
const response = await axios.post(`${mispUrl}/events/add`, eventData, {
headers: {
Authorization: mispKey,
Accept: 'application/json',
'Content-Type': 'application/json'
},
httpsAgent: mispVerifyCert ? undefined : new (require('https').Agent)({ rejectUnauthorized: false })
});
console.log(`Event ${eventInfo} has been created:`, response.data);
} catch (error) {
console.error('Error creating event:', error);
}
};
(async () => {
while (true) {
await createDummyEvent();
await sleep(5000);
}
})();