Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit a919cc1

Browse files
committed
replace opensoc-steaming version 0.4BETA with 0.6BETA 8e7a6b4ad9febbc4ea47ba7810c42cc94d4dee37
1 parent 05e188b commit a919cc1

File tree

256 files changed

+43963
-5245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+43963
-5245
lines changed

opensoc-streaming/.gitignore

Lines changed: 0 additions & 15 deletions
This file was deleted.

opensoc-streaming/.travis.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

opensoc-streaming/OpenSOC-Alerts/pom.xml

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@
1515
<parent>
1616
<groupId>com.opensoc</groupId>
1717
<artifactId>OpenSOC-Streaming</artifactId>
18-
<version>0.3BETA-SNAPSHOT</version>
18+
<version>0.6BETA</version>
1919
</parent>
2020
<artifactId>OpenSOC-Alerts</artifactId>
2121
<name>OpenSOC-Alerts</name>
2222
<description>Taggers for alerts</description>
2323
<properties>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2426
<commons.validator.version>1.4.0</commons.validator.version>
2527
</properties>
2628
<dependencies>
2729
<dependency>
2830
<groupId>com.opensoc</groupId>
2931
<artifactId>OpenSOC-Common</artifactId>
30-
<version>${parent.version}</version>
32+
<version>${project.parent.version}</version>
3133
</dependency>
3234
<dependency>
3335
<groupId>com.googlecode.json-simple</groupId>
@@ -39,6 +41,12 @@
3941
<artifactId>storm-core</artifactId>
4042
<version>${global_storm_version}</version>
4143
<scope>provided</scope>
44+
<exclusions>
45+
<exclusion>
46+
<artifactId>servlet-api</artifactId>
47+
<groupId>javax.servlet</groupId>
48+
</exclusion>
49+
</exclusions>
4250
</dependency>
4351
<dependency>
4452
<groupId>org.apache.kafka</groupId>
@@ -69,13 +77,60 @@
6977
<groupId>commons-validator</groupId>
7078
<artifactId>commons-validator</artifactId>
7179
<version>${commons.validator.version}</version>
80+
<exclusions>
81+
<exclusion>
82+
83+
<groupId>commons-beanutils</groupId>
84+
85+
<artifactId>commons-beanutils</artifactId>
86+
87+
</exclusion>
88+
</exclusions>
7289
</dependency>
7390
</dependencies>
7491
<build>
92+
<plugins>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-surefire-plugin</artifactId>
96+
<version>2.18</version>
97+
<configuration>
98+
<systemProperties>
99+
<property>
100+
<name>mode</name>
101+
<value>local</value>
102+
</property>
103+
</systemProperties>
104+
</configuration>
105+
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-compiler-plugin</artifactId>
109+
<version>3.1</version>
110+
<configuration>
111+
<source>1.7</source>
112+
<target>1.7</target>
113+
</configuration>
114+
</plugin>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-pmd-plugin</artifactId>
118+
<version>3.3</version>
119+
<configuration>
120+
<targetJdk>1.7</targetJdk>
121+
</configuration>
122+
</plugin>
123+
<plugin>
124+
<groupId>org.codehaus.mojo</groupId>
125+
<artifactId>emma-maven-plugin</artifactId>
126+
<version>1.0-alpha-3</version>
127+
<inherited>true</inherited>
128+
</plugin>
129+
</plugins>
75130
<resources>
76131
<resource>
77132
<directory>src/main/resources</directory>
78133
</resource>
79134
</resources>
80135
</build>
81-
</project>
136+
</project>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#OpenSOC-Alerts
2+
3+
##Module Description
4+
5+
This module enables telemetry alerts. It splits the mssage stream into two streams. The original message is emitted on the "message" stream. The corresponding alert is emitted on the "alerts" stream. The two are tied together through the alerts UUID.
6+
7+
##Message Format
8+
9+
Assuming the original message (with enrichments enabled) has the following format:
10+
11+
```json
12+
{
13+
"message":
14+
{"ip_src_addr": xxxx,
15+
"ip_dst_addr": xxxx,
16+
"ip_src_port": xxxx,
17+
"ip_dst_port": xxxx,
18+
"protocol": xxxx,
19+
"timestamp": xxxx.
20+
"original_string": xxxx,
21+
"additional-field 1": xxxx,
22+
},
23+
"enrichment" : {"geo": xxxx, "whois": xxxx, "hosts": xxxxx, "CIF": "xxxxx"}
24+
25+
}
26+
```
27+
28+
The telemetry message will be tagged with a UUID alert tag like so:
29+
30+
```json
31+
{
32+
"message":
33+
{"ip_src_addr": xxxx,
34+
"ip_dst_addr": xxxx,
35+
"ip_src_port": xxxx,
36+
"ip_dst_port": xxxx,
37+
"protocol": xxxx,
38+
"timestamp": xxxx,
39+
"original_string": xxxx,
40+
"additional-field 1": xxxx,
41+
},
42+
"enrichment" : {"geo": xxxx, "whois": xxxx, "hosts": xxxxx, "CIF": "xxxxx"},
43+
"alerts": [UUID1, UUID2, UUID3, etc]
44+
45+
}
46+
```
47+
48+
The alert will be fired on the "alerts" stream and can be customized to have any format as long as it includes the required mandatory fields. The mandatory fields are:
49+
50+
* timestamp (epoch): The time from the message that triggered the alert
51+
* description: A human friendly string representation of the alert
52+
* alert_id: The UUID generated for the alert. This uniquely identifies an alert
53+
54+
There are other standard but not mandatory fields that can be leveraged by opensoc-ui and other alert consumers:
55+
56+
* designated_host: The IP address that corresponds to an asset. Ex. The IP address of the company device associated with the alert.
57+
* enrichment: A copy of the enrichment data from the message that triggered the alert
58+
* priority: The priority of the alert. Mustb e set to one of HIGH, MED or LOW
59+
60+
An example of an alert with all mandatory and standard fields would look like so:
61+
62+
```json
63+
{
64+
"timestamp": xxxx,
65+
"alert_id": UUID,
66+
"description": xxxx,
67+
"designated_host": xxxx,
68+
"enrichment": { "geo": xxxx, "whois": xxxx, "cif": xxxx },
69+
"priority": "MED"
70+
}
71+
```
72+
73+
##Alerts Bolt
74+
75+
The bolt can be extended with a variety of alerts adapters. The ability to stack alerts is currently in beta, but is not currently advisable. We advice to only have one alerts bolt per topology. The adapters are rules-based adapters which fire alerts when rules are a match. Currently only Java adapters are provided, but there are future plans to provide Grok-Based adapters as well.
76+
77+
The signature of the Alerts bolt is as follows:
78+
79+
```
80+
TelemetryAlertsBolt alerts_bolt = new TelemetryAlertsBolt()
81+
.withIdentifier(alerts_identifier).withMaxCacheSize(1000)
82+
.withMaxTimeRetain(3600).withAlertsAdapter(alerts_adapter)
83+
.withMetricConfiguration(config);
84+
```
85+
Identifier - JSON key where the alert is attached
86+
TimeRetain & MaxCacheSize - Caching parameters for the bolt
87+
MetricConfiguration - export custom bolt metrics to graphite (if not null)
88+
AlertsAdapter - pick the appropriate adapter for generating the alerts
89+
90+
### Java Adapters
91+
92+
Java adapters are designed for high volume topologies, but are not easily extensible. The adapters provided are:
93+
94+
* com.opensoc.alerts.adapters.AllAlertsAdapter - will tag every single message with the static alert (appropriate for topologies like Sourcefire, etc, where every single message is an alert)
95+
* com.opensoc.alerts.adapters.HbaseWhiteAndBlacklistAdapter - will read white and blacklists from HBase and fire alerts if source or dest IP are not on the whitelist or if any IP is on the blacklist
96+
* com.opensoc.alerts.adapters.CIFAlertsAdapter - will alert on messages that have results in enrichment.cif.
97+
* com.opensoc.alerts.adpaters.KeywordsAlertAdapter - will alert on messages that contain any of a list of keywords
98+
###Grok Adapters
99+
100+
Grok alerts adapters for OpenSOC are still under devleopment
101+
102+
###Stacking Alert Adapters
103+
104+
The functionality to stack alerts adapters is still under development

opensoc-streaming/OpenSOC-Alerts/src/main/java/com/opensoc/alerts/AbstractAlertBolt.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public abstract class AbstractAlertBolt extends BaseRichBolt {
5454
protected JSONObject _identifier;
5555
protected MetricReporter _reporter;
5656

57-
protected int _MAX_CACHE_SIZE = -1;
58-
protected int _MAX_TIME_RETAIN = -1;
57+
protected int _MAX_CACHE_SIZE_OBJECTS_NUM = -1;
58+
protected int _MAX_TIME_RETAIN_MINUTES = -1;
5959

6060
protected Counter ackCounter, emitCounter, failCounter;
6161

@@ -82,10 +82,10 @@ public final void prepare(Map conf, TopologyContext topologyContext,
8282
if (this._identifier == null)
8383
throw new IllegalStateException("Identifier must be specified");
8484

85-
if (this._MAX_CACHE_SIZE == -1)
86-
throw new IllegalStateException("MAX_CACHE_SIZE must be specified");
87-
if (this._MAX_TIME_RETAIN == -1)
88-
throw new IllegalStateException("MAX_TIME_RETAIN must be specified");
85+
if (this._MAX_CACHE_SIZE_OBJECTS_NUM == -1)
86+
throw new IllegalStateException("MAX_CACHE_SIZE_OBJECTS_NUM must be specified");
87+
if (this._MAX_TIME_RETAIN_MINUTES == -1)
88+
throw new IllegalStateException("MAX_TIME_RETAIN_MINUTES must be specified");
8989

9090
try {
9191
doPrepare(conf, topologyContext, collector);
@@ -95,6 +95,7 @@ public final void prepare(Map conf, TopologyContext topologyContext,
9595
}
9696

9797
boolean success = _adapter.initialize();
98+
9899
try {
99100
if (!success)
100101

opensoc-streaming/OpenSOC-Alerts/src/main/java/com/opensoc/alerts/TelemetryAlertsBolt.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import backtype.storm.tuple.Tuple;
3232
import backtype.storm.tuple.Values;
3333

34-
import com.esotericsoftware.minlog.Log;
3534
import com.google.common.cache.CacheBuilder;
3635
import com.opensoc.alerts.interfaces.AlertsAdapter;
36+
import com.opensoc.helpers.topology.ErrorGenerator;
3737
import com.opensoc.json.serialization.JSONEncoderHelper;
3838
import com.opensoc.metrics.MetricReporter;
39-
import com.opensoc.topologyhelpers.ErrorGenerator;
4039

4140
@SuppressWarnings("rawtypes")
4241
public class TelemetryAlertsBolt extends AbstractAlertBolt {
@@ -120,33 +119,33 @@ public TelemetryAlertsBolt withMetricConfiguration(Configuration config) {
120119
}
121120

122121
/**
123-
* @param MAX_CACHE_SIZE
122+
* @param MAX_CACHE_SIZE_OBJECTS_NUM
124123
* Maximum size of cache before flushing
125124
* @return Instance of this class
126125
*/
127126

128-
public TelemetryAlertsBolt withMaxCacheSize(int MAX_CACHE_SIZE) {
129-
_MAX_CACHE_SIZE = MAX_CACHE_SIZE;
127+
public TelemetryAlertsBolt withMaxCacheSize(int MAX_CACHE_SIZE_OBJECTS_NUM) {
128+
_MAX_CACHE_SIZE_OBJECTS_NUM = MAX_CACHE_SIZE_OBJECTS_NUM;
130129
return this;
131130
}
132131

133132
/**
134-
* @param MAX_TIME_RETAIN
133+
* @param MAX_TIME_RETAIN_MINUTES
135134
* Maximum time to retain cached entry before expiring
136135
* @return Instance of this class
137136
*/
138137

139-
public TelemetryAlertsBolt withMaxTimeRetain(int MAX_TIME_RETAIN) {
140-
_MAX_TIME_RETAIN = MAX_TIME_RETAIN;
138+
public TelemetryAlertsBolt withMaxTimeRetain(int MAX_TIME_RETAIN_MINUTES) {
139+
_MAX_TIME_RETAIN_MINUTES = MAX_TIME_RETAIN_MINUTES;
141140
return this;
142141
}
143142

144143
@Override
145144
void doPrepare(Map conf, TopologyContext topologyContext,
146145
OutputCollector collector) throws IOException {
147146

148-
cache = CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE)
149-
.expireAfterWrite(_MAX_TIME_RETAIN, TimeUnit.MINUTES).build();
147+
cache = CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE_OBJECTS_NUM)
148+
.expireAfterWrite(_MAX_TIME_RETAIN_MINUTES, TimeUnit.MINUTES).build();
150149

151150
LOG.info("[OpenSOC] Preparing TelemetryAlert Bolt...");
152151

@@ -185,22 +184,22 @@ public void execute(Tuple tuple) {
185184
JSONArray uuid_list = new JSONArray();
186185

187186
if (alerts_list == null || alerts_list.isEmpty()) {
188-
LOG.trace("[OpenSOC] No alerts detected in: "
187+
System.out.println("[OpenSOC] No alerts detected in: "
189188
+ original_message);
190189
_collector.ack(tuple);
191-
_collector.emit(new Values(original_message));
190+
_collector.emit("message", new Values(key, original_message));
192191
} else {
193192
for (String alert : alerts_list.keySet()) {
194193
uuid_list.add(alert);
195194

196195
LOG.trace("[OpenSOC] Checking alerts cache: " + alert);
197196

198197
if (cache.getIfPresent(alert) == null) {
199-
LOG.trace("[OpenSOC]: Alert not found in cache: " + alert);
198+
System.out.println("[OpenSOC]: Alert not found in cache: " + alert);
200199

201200
JSONObject global_alert = new JSONObject();
202201
global_alert.putAll(_identifier);
203-
global_alert.put("triggered", alerts_list.get(alert));
202+
global_alert.putAll(alerts_list.get(alert));
204203
global_alert.put("timestamp", System.currentTimeMillis());
205204
_collector.emit("alert", new Values(global_alert));
206205

@@ -244,11 +243,9 @@ public void execute(Tuple tuple) {
244243
* if (metricConfiguration != null) { failCounter.inc(); }
245244
*/
246245

247-
String error_as_string = org.apache.commons.lang.exception.ExceptionUtils
248-
.getStackTrace(e);
249246

250247
JSONObject error = ErrorGenerator.generateErrorMessage(
251-
"Alerts problem: " + original_message, error_as_string);
248+
"Alerts problem: " + original_message, e);
252249
_collector.emit("error", new Values(error));
253250
}
254251
}

opensoc-streaming/OpenSOC-Alerts/src/main/java/com/opensoc/alerts/adapters/AbstractAlertAdapter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
package com.opensoc.alerts.adapters;
2020

2121
import java.io.Serializable;
22-
import java.util.Set;
23-
import java.util.TreeSet;
2422
import java.util.UUID;
2523
import java.util.concurrent.TimeUnit;
2624

@@ -62,9 +60,9 @@ private String makeKey(String ip1, String ip2, int alert_type) {
6260
return (ip1 + "-" + ip2 + "-" + alert_type);
6361
}
6462

65-
private void generateCache(int _MAX_CACHE_SIZE, int _MAX_TIME_RETAIN)
63+
protected void generateCache(int _MAX_CACHE_SIZE_OBJECTS_NUM, int _MAX_TIME_RETAIN_MINUTES)
6664
{
67-
cache = CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE)
68-
.expireAfterWrite(_MAX_TIME_RETAIN, TimeUnit.MINUTES).build();
65+
cache = CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE_OBJECTS_NUM)
66+
.expireAfterWrite(_MAX_TIME_RETAIN_MINUTES, TimeUnit.MINUTES).build();
6967
}
7068
}

0 commit comments

Comments
 (0)