Skip to content

Commit 803cef9

Browse files
committed
Update vulnerability index mappings (#75)
* Remove 'events' ECS field * Add 'wazuh' custom field * Update event_generator.py for vulnerability detector
1 parent 80561b1 commit 803cef9

File tree

6 files changed

+49
-31
lines changed

6 files changed

+49
-31
lines changed

ecs/generate.sh

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
set -e
4+
set -u
5+
36
# Function to display usage information
47
show_usage() {
58
echo "Usage: $0 <ECS_VERSION> <INDEXER_SRC> <MODULE> [--upload <URL>]"
@@ -12,20 +15,15 @@ show_usage() {
1215

1316
# Function to generate mappings
1417
generate_mappings() {
15-
ECS_VERSION="$1"
16-
INDEXER_SRC="$2"
17-
MODULE="$3"
18-
UPLOAD="$4"
19-
URL="$5"
20-
21-
IN_FILES_DIR="$INDEXER_SRC/ecs/$MODULE/fields"
22-
OUT_DIR="$INDEXER_SRC/ecs/$MODULE/mappings/$ECS_VERSION"
18+
local IN_FILES_DIR="$INDEXER_SRC/ecs/$MODULE/fields"
19+
local OUT_DIR="$INDEXER_SRC/ecs/$MODULE/mappings/$ECS_VERSION"
2320

2421
# Ensure the output directory exists
2522
mkdir -p "$OUT_DIR" || exit 1
2623

2724
# Generate mappings
2825
python scripts/generator.py --strict --ref "$ECS_VERSION" \
26+
--include "$IN_FILES_DIR/custom/wazuh.yml" \
2927
--subset "$IN_FILES_DIR/subset.yml" \
3028
--template-settings "$IN_FILES_DIR/template-settings.json" \
3129
--template-settings-legacy "$IN_FILES_DIR/template-settings-legacy.json" \
@@ -55,8 +53,8 @@ generate_mappings() {
5553

5654
# Function to upload generated composable index template to the OpenSearch cluster
5755
upload_mappings() {
58-
OUT_DIR="$1"
59-
URL="$2"
56+
local OUT_DIR="$1"
57+
local URL="$2"
6058

6159
echo "Uploading index template to the OpenSearch cluster"
6260
for file in "$OUT_DIR/generated/elasticsearch/composable/component"/*.json; do

ecs/vulnerability-detector/event-generator/event_generator.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def generate_random_event():
6464
'created': generate_random_date(),
6565
'dataset': random.choice(['process', 'file', 'registry', 'socket', 'dns', 'http', 'tls', 'alert',
6666
'authentication', 'authorization', 'configuration', 'communication', 'file',
67-
'network', 'process', 'registry', 'storage', 'system', 'web']),
67+
'network', 'process', 'registry', 'storage', 'system', 'web']),
6868
'duration': random.randint(0, 99999),
6969
'end': generate_random_date(),
7070
'hash': str(hash(f'hash{random.randint(0, 99999)}')),
@@ -74,12 +74,12 @@ def generate_random_event():
7474
'state', 'pipeline_error', 'signal']),
7575
'module': random.choice(['process', 'file', 'registry', 'socket', 'dns', 'http', 'tls', 'alert',
7676
'authentication', 'authorization', 'configuration', 'communication', 'file',
77-
'network', 'process', 'registry', 'storage', 'system', 'web']),
77+
'network', 'process', 'registry', 'storage', 'system', 'web']),
7878
'original': f'original{random.randint(0, 99999)}',
7979
'outcome': random.choice(['success', 'failure', 'unknown']),
8080
'provider': random.choice(['process', 'file', 'registry', 'socket', 'dns', 'http', 'tls', 'alert',
8181
'authentication', 'authorization', 'configuration', 'communication', 'file',
82-
'network', 'process', 'registry', 'storage', 'system', 'web']),
82+
'network', 'process', 'registry', 'storage', 'system', 'web']),
8383
'reason': f'This event happened due to reason{random.randint(0, 99999)}',
8484
'reference': f'https://system.example.com/event/#{random.randint(0, 99999)}',
8585
'risk_score': round(random.uniform(0, 10), 1),
@@ -89,15 +89,16 @@ def generate_random_event():
8989
'start': generate_random_date(),
9090
'timezone': random.choice(['UTC', 'GMT', 'PST', 'EST', 'CST', 'MST', 'PDT', 'EDT', 'CDT', 'MDT']),
9191
'type': random.choice(['access', 'admin', 'allowed', 'change', 'connection', 'creation', 'deletion',
92-
'denied', 'end', 'error', 'group', 'indicator', 'info', 'installation', 'protocol',
93-
'start', 'user']),
92+
'denied', 'end', 'error', 'group', 'indicator', 'info', 'installation', 'protocol',
93+
'start', 'user']),
9494
'url': f'http://mysystem.example.com/alert/{random.randint(0, 99999)}'
9595
}
9696
return event
9797

9898

9999
def generate_random_host():
100-
family = random.choice(['debian', 'ubuntu', 'macos', 'ios', 'android', 'RHEL'])
100+
family = random.choice(
101+
['debian', 'ubuntu', 'macos', 'ios', 'android', 'RHEL'])
101102
version = f'{random.randint(0, 99)}.{random.randint(0, 99)}'
102103
host = {
103104
'os': {
@@ -114,7 +115,8 @@ def generate_random_host():
114115

115116

116117
def generate_random_labels():
117-
labels = {'label1': f'label{random.randint(0, 99)}', 'label2': f'label{random.randint(0, 99)}'}
118+
labels = {
119+
'label1': f'label{random.randint(0, 99)}', 'label2': f'label{random.randint(0, 99)}'}
118120
return labels
119121

120122

@@ -133,7 +135,7 @@ def generate_random_package():
133135
'size': random.randint(0, 99999),
134136
'type': random.choice(['deb', 'rpm', 'msi', 'pkg', 'app', 'apk', 'exe', 'zip', 'tar', 'gz', '7z',
135137
'rar', 'cab', 'iso', 'dmg', 'tar.gz', 'tar.bz2', 'tar.xz', 'tar.Z', 'tar.lz4',
136-
'tar.sz', 'tar.zst']),
138+
'tar.sz', 'tar.zst']),
137139
'version': f'v{random.randint(0, 9)}-stable'
138140
}
139141
return package
@@ -166,20 +168,30 @@ def generate_random_vulnerability():
166168
return vulnerability
167169

168170

171+
def generate_random_wazuh():
172+
wazuh = {
173+
'cluster': {
174+
'name': f'wazuh-cluster-{random.randint(0,10)}'
175+
}
176+
}
177+
return wazuh
178+
179+
169180
def generate_random_data(number):
170181
data = []
171182
for _ in range(number):
172183
event_data = {
173184
'@timestamp': generate_random_date(),
174185
'agent': generate_random_agent(),
175186
'ecs': {'version': '1.7.0'},
176-
'event': generate_random_event(),
187+
# 'event': generate_random_event(),
177188
'host': generate_random_host(),
178189
'labels': generate_random_labels(),
179190
'message': f'message{random.randint(0, 99999)}',
180191
'package': generate_random_package(),
181192
'tags': generate_random_tags(),
182-
'vulnerability': generate_random_vulnerability()
193+
'vulnerability': generate_random_vulnerability(),
194+
'wazuh': generate_random_wazuh()
183195
}
184196
data.append(event_data)
185197
return data
@@ -221,7 +233,8 @@ def main():
221233

222234
logging.info('Data generation completed.')
223235

224-
inject = input("Do you want to inject the generated data into your indexer? (y/n) ").strip().lower()
236+
inject = input(
237+
"Do you want to inject the generated data into your indexer? (y/n) ").strip().lower()
225238
if inject == 'y':
226239
ip = input("Enter the IP of your Indexer: ")
227240
port = input("Enter the port of your Indexer: ")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: wazuh
3+
title: Wazuh
4+
description: >
5+
Wazuh Inc. custom fields
6+
fields:
7+
- name: cluster.name
8+
type: keyword
9+
level: custom
10+
description: >
11+
Wazuh cluster name.

ecs/vulnerability-detector/fields/subset.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ fields:
77
fields: "*"
88
ecs:
99
fields: "*"
10-
event:
11-
fields: "*"
1210
package:
1311
fields: "*"
1412
host:
@@ -17,3 +15,5 @@ fields:
1715
fields: "*"
1816
vulnerability:
1917
fields: "*"
18+
wazuh:
19+
fields: "*"

ecs/vulnerability-detector/fields/template-settings-legacy.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
"base.tags",
1919
"agent.id",
2020
"ecs.version",
21-
"event.id",
22-
"event.module",
23-
"event.severity",
2421
"host.os.family",
2522
"host.os.full.text",
2623
"host.os.version",
2724
"package.name",
2825
"package.version",
2926
"vulnerability.id",
3027
"vulnerability.description.text",
31-
"vulnerability.severity"
28+
"vulnerability.severity",
29+
"wazuh.cluster.name"
3230
]
3331
}
3432
}

ecs/vulnerability-detector/fields/template-settings.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
"base.tags",
2020
"agent.id",
2121
"ecs.version",
22-
"event.id",
23-
"event.module",
24-
"event.severity",
2522
"host.os.family",
2623
"host.os.full.text",
2724
"host.os.version",
2825
"package.name",
2926
"package.version",
3027
"vulnerability.id",
3128
"vulnerability.description.text",
32-
"vulnerability.severity"
29+
"vulnerability.severity",
30+
"wazuh.cluster.name"
3331
]
3432
}
3533
}

0 commit comments

Comments
 (0)