Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 threat intel todos #7

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified security-analytics-commons-1.0.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
import org.opensearch.securityanalytics.threatIntel.resthandler.monitor.RestIndexThreatIntelMonitorAction;
import org.opensearch.securityanalytics.threatIntel.resthandler.monitor.RestSearchThreatIntelMonitorAction;
import org.opensearch.securityanalytics.threatIntel.resthandler.monitor.RestUpdateThreatIntelAlertsStatusAction;
import org.opensearch.securityanalytics.threatIntel.service.DefaultTifSourceConfigLoaderService;
import org.opensearch.securityanalytics.threatIntel.service.DetectorThreatIntelService;
import org.opensearch.securityanalytics.threatIntel.service.SATIFSourceConfigManagementService;
import org.opensearch.securityanalytics.threatIntel.service.SATIFSourceConfigService;
Expand Down Expand Up @@ -326,12 +327,13 @@ public Collection<Object> createComponents(Client client,
IocFindingService iocFindingService = new IocFindingService(client, clusterService, xContentRegistry);
ThreatIntelAlertService threatIntelAlertService = new ThreatIntelAlertService(client, clusterService, xContentRegistry);
SaIoCScanService ioCScanService = new SaIoCScanService(client, xContentRegistry, iocFindingService, threatIntelAlertService, notificationService);
DefaultTifSourceConfigLoaderService defaultTifSourceConfigLoaderService = new DefaultTifSourceConfigLoaderService(builtInTIFMetadataLoader, client, saTifSourceConfigManagementService);
return List.of(
detectorIndices, correlationIndices, correlationRuleIndices, ruleTopicIndices, customLogTypeIndices, ruleIndices, threatIntelAlertService,
mapperService, indexTemplateManager, builtinLogTypeLoader, builtInTIFMetadataLoader, threatIntelFeedDataService, detectorThreatIntelService,
correlationAlertService, notificationService,
tifJobUpdateService, tifJobParameterService, threatIntelLockService, saTifSourceConfigService, saTifSourceConfigManagementService, stix2IOCFetchService,
ioCScanService);
ioCScanService, defaultTifSourceConfigLoaderService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public static DetailedSTIX2IOCDto parse(XContentParser xcp, String id, Long vers
xcp.nextToken();

switch (fieldName) {
// synced up with @hurneyt, parsing the id and version but may need to change ioc id/version logic
case STIX2.ID_FIELD:
if (xcp.currentToken() != XContentParser.Token.VALUE_NULL) {
id = xcp.text();
Expand All @@ -90,7 +89,7 @@ public static DetailedSTIX2IOCDto parse(XContentParser xcp, String id, Long vers
name = xcp.text();
break;
case STIX2.TYPE_FIELD:
type = IOCType.valueOf(xcp.text().toLowerCase(Locale.ROOT));
type = new IOCType(xcp.text().toLowerCase(Locale.ROOT));
break;
case STIX2.VALUE_FIELD:
value = xcp.text();
Expand Down Expand Up @@ -177,7 +176,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.startObject()
.field(STIX2IOC.ID_FIELD, ioc.getId())
.field(STIX2IOC.NAME_FIELD, ioc.getName())
.field(STIX2IOC.TYPE_FIELD, ioc.getType())
.field(STIX2IOC.TYPE_FIELD, ioc.getType().getType())
.field(STIX2IOC.VALUE_FIELD, ioc.getValue())
.field(STIX2IOC.SEVERITY_FIELD, ioc.getSeverity())
.timeField(STIX2IOC.CREATED_FIELD, ioc.getCreated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public STIX2IOC(StreamInput sin) throws IOException {
this(
sin.readString(), // id
sin.readString(), // name
sin.readEnum(IOCType.class), // type
new IOCType(sin.readString()), // type
sin.readString(), // value
sin.readString(), // severity
sin.readInstant(), // created
Expand Down Expand Up @@ -142,7 +142,7 @@ public static STIX2IOC readFrom(StreamInput sin) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(super.getId());
out.writeString(super.getName());
out.writeEnum(super.getType());
out.writeString(super.getType().getType());
out.writeString(super.getValue());
out.writeString(super.getSeverity());
out.writeInstant(super.getCreated());
Expand All @@ -160,7 +160,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject()
.field(ID_FIELD, super.getId())
.field(NAME_FIELD, super.getName())
.field(TYPE_FIELD, super.getType())
.field(TYPE_FIELD, super.getType().getType())
.field(VALUE_FIELD, super.getValue())
.field(SEVERITY_FIELD, super.getSeverity());
XContentUtils.buildInstantAsField(builder, super.getCreated(), CREATED_FIELD);
Expand Down Expand Up @@ -205,7 +205,7 @@ public static STIX2IOC parse(XContentParser xcp, String id, Long version) throws
name = xcp.text();
break;
case TYPE_FIELD:
type = IOCType.valueOf(xcp.text().toLowerCase(Locale.ROOT));
type = new IOCType(xcp.text());
break;
case VALUE_FIELD:
value = xcp.text();
Expand Down Expand Up @@ -292,8 +292,8 @@ public static STIX2IOC parse(XContentParser xcp, String id, Long version) throws
public void validate() throws IllegalArgumentException {
if (super.getType() == null) {
throw new IllegalArgumentException(String.format("[%s] is required.", TYPE_FIELD));
} else if (!Arrays.asList(IOCType.values()).contains(super.getType())) {
logger.debug("Unsupported IOCType: {}", super.getType());
} else if (!IOCType.supportedType(super.getType().getType())) {
logger.debug("Unsupported IOCType: {}", super.getType().getType());
throw new IllegalArgumentException(String.format("[%s] is not supported.", TYPE_FIELD));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static STIX2IOCDto readFrom(StreamInput sin) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
out.writeString(name);
out.writeEnum(type);
out.writeString(type.getType());
out.writeString(value);
out.writeString(severity);
out.writeInstant(created);
Expand All @@ -120,7 +120,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.startObject()
.field(STIX2IOC.ID_FIELD, id)
.field(STIX2IOC.NAME_FIELD, name)
.field(STIX2IOC.TYPE_FIELD, type)
.field(STIX2IOC.TYPE_FIELD, type.getType())
.field(STIX2IOC.VALUE_FIELD, value)
.field(STIX2IOC.SEVERITY_FIELD, severity)
.timeField(STIX2IOC.CREATED_FIELD, created)
Expand Down Expand Up @@ -161,7 +161,6 @@ public static STIX2IOCDto parse(XContentParser xcp, String id, Long version) thr
xcp.nextToken();

switch (fieldName) {
// synced up with @hurneyt, parsing the id and version but may need to change ioc id/version logic
case STIX2.ID_FIELD:
if (xcp.currentToken() != XContentParser.Token.VALUE_NULL) {
id = xcp.text();
Expand All @@ -176,7 +175,7 @@ public static STIX2IOCDto parse(XContentParser xcp, String id, Long version) thr
name = xcp.text();
break;
case STIX2.TYPE_FIELD:
type = IOCType.valueOf(xcp.text().toLowerCase(Locale.ROOT));
type = new IOCType(xcp.text());
break;
case STIX2.VALUE_FIELD:
value = xcp.text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package org.opensearch.securityanalytics.services;

import com.amazonaws.services.s3.AmazonS3;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.securityanalytics.commons.connector.Connector;
import org.opensearch.securityanalytics.commons.connector.S3Connector;
import org.opensearch.securityanalytics.commons.connector.codec.InputCodec;
Expand All @@ -21,6 +23,7 @@
import java.util.List;

public class STIX2IOCConnectorFactory extends UnaryParameterCachingFactory<FeedConfiguration, Connector<STIX2>> {
private static final Logger logger = LogManager.getLogger(STIX2IOCConnectorFactory.class);
private final InputCodecFactory inputCodecFactory;
private final S3ClientFactory s3ClientFactory;

Expand All @@ -31,7 +34,7 @@ public STIX2IOCConnectorFactory(final InputCodecFactory inputCodecFactory, final

protected Connector<STIX2> doCreate(FeedConfiguration feedConfiguration) {
final FeedLocation feedLocation = FeedLocation.fromFeedConfiguration(feedConfiguration);
// TODO hurneyt add debug log for which location gets used
logger.debug("FeedLocation: {}", feedLocation);
switch(feedLocation) {
case S3: return createS3Connector(feedConfiguration);
default: throw new IllegalArgumentException("Unsupported feedLocation: " + feedLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ public void accept(final STIX2 ioc) {
feedStore.getSaTifSourceConfig().getName()
);

// TODO hurneyt refactor once the enum values are updated
// If the IOC received is not a type listed for the config, do not add it to the queue
if (!feedStore.getSaTifSourceConfig().getIocTypes().contains(stix2IOC.getType().name())) {
if (!feedStore.getSaTifSourceConfig().getIocTypes().contains(stix2IOC.getType().getType())) {
log.error("{} is not a supported Ioc type for tif source config {}. Skipping IOC {}: of type {} value {}",
stix2IOC.getType().name(), feedStore.getSaTifSourceConfig().getId(),
stix2IOC.getType().getType(), feedStore.getSaTifSourceConfig().getId(),
stix2IOC.getId(), stix2IOC.getType(), stix2IOC.getValue()
);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ public class STIX2IOCFeedStore implements FeedStore {
public static final String IOC_INDEX_PATTERN = IOC_INDEX_NAME_TEMPLATE + "-" + IOC_TIME_PLACEHOLDER;

private final Logger log = LogManager.getLogger(STIX2IOCFeedStore.class);

Instant startTime = Instant.now();

private Client client;
private ClusterService clusterService;
private SATIFSourceConfig saTifSourceConfig;

// TODO hurneyt FetchIocsActionResponse is just a placeholder response type for now
private ActionListener<STIX2IOCFetchService.STIX2IOCFetchResponse> baseListener;

// TODO hurneyt this is using TIF batch size setting. Consider adding IOC-specific setting
private Integer batchSize;

public STIX2IOCFeedStore(
Expand Down Expand Up @@ -97,7 +94,6 @@ public void storeIOCs(Map<IOC, UpdateAction> actionToIOCs) {
for (Map.Entry<UpdateAction, List<STIX2IOC>> entry : iocsSortedByAction.entrySet()) {
switch (entry.getKey()) {
case DELETE:
// TODO hurneyt consider whether DELETE actions should be handled elsewhere
break;
case UPSERT:
try {
Expand All @@ -119,7 +115,7 @@ public void indexIocs(List<STIX2IOC> iocs) throws IOException {
initFeedIndex(newActiveIndex, ActionListener.wrap(
r -> {
saTifSourceConfig.getIocTypes().forEach(type -> {
IOCType iocType = IOCType.fromString(type);
IOCType iocType = new IOCType(type);
if (saTifSourceConfig.getIocStoreConfig() instanceof DefaultIocStoreConfig) {
List<DefaultIocStoreConfig.IocToIndexDetails> listOfIocToIndexDetails =
((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocToIndexDetails();
Expand Down
Loading
Loading