Skip to content

Commit

Permalink
Add support to config the Observed Data Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenOTT committed Apr 29, 2019
1 parent 616aaac commit 8779449
Show file tree
Hide file tree
Showing 26 changed files with 379 additions and 170 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,28 @@ Sample Response:

GET `/api/sdo/observed-data`

Observed-data supports a optional JSON body in the GET request.
With this body you can configure the data generator.

Sample Request Body:

```json
{
"propCreatedProbability": 100,
"propFirstObservedSubsecondPrecision": 9,
"propLastObservedSubsecondPrecision": 6,
"macAddressCoo": {
"occurrence_probability": 100,
"occurs_count_lower": 99,
"occurs_count_upper": 100
}
}
```

See the `ObservedDataGeneratorConfig.class` in io.digitalstate.stix.faker;
all of the properties can be used for modification.


Sample Response:

```json
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.digitalstate.stix.faker</groupId>
<artifactId>stix-faker</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
<packaging>jar</packaging>

<name>STIX 2 Faker</name>
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.github.StephenOTT</groupId>
<artifactId>STIX-Java</artifactId>
<version>0.7.2</version>
<version>0.8.0</version>
</dependency>

<dependency>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.digitalstate.stix.faker.configs

import io.digitalstate.stix.faker.configs.sdo.observeddata.*

import java.time.Instant
import java.time.LocalDate

class ObservedDataGeneratorConfig {

Instant DEFAULT_LOWER_DATE = Instant.ofEpochMilli(LocalDate.of(2000, 1, 1).toEpochDay())
Instant DEFAULT_UPPER_DATE = Instant.now()
int DEFAULT_DATE_SUBSECOND_PRECISION = 3

int propCreatedProbability = 50
Instant propCreatedLowerDate = DEFAULT_LOWER_DATE
Instant propCreatedUpperDate = DEFAULT_UPPER_DATE
int propCreatedDateSubsecondPrecision = DEFAULT_DATE_SUBSECOND_PRECISION

int propModifiedProbability = 50
Instant propModifiedLowerDate = propCreatedUpperDate
Instant propModifiedUpperDate = DEFAULT_UPPER_DATE
int propModifiedSubsecondPrecision = DEFAULT_DATE_SUBSECOND_PRECISION

int propRevokedProbability = 50

int propCreatedByRefProbability = 50

int propCustomPropsProbability = 50

Instant propFirstObservedLowerDate = DEFAULT_LOWER_DATE
Instant propFirstObservedUpperDate = DEFAULT_UPPER_DATE
int propFirstObservedSubsecondPrecision = DEFAULT_DATE_SUBSECOND_PRECISION

Instant propLastObservedUpperDate = DEFAULT_UPPER_DATE
int propLastObservedSubsecondPrecision = DEFAULT_DATE_SUBSECOND_PRECISION

int propNumberObservedUpperCount = 999999999
int propNumberObservedLowerCount = 1

ObservedData_ArtifactCooConfig artifactCoo = new ObservedData_ArtifactCooConfig()
ObservedData_AutonomousSystemCooConfig autonomousSystemCoo = new ObservedData_AutonomousSystemCooConfig()
ObservedData_DirectoryCooConfig directoryCoo = new ObservedData_DirectoryCooConfig()
ObservedData_DomainNameCooConfig domainNameCoo = new ObservedData_DomainNameCooConfig()
ObservedData_EmailAddressCooConfig emailAddressCoo = new ObservedData_EmailAddressCooConfig()
ObservedData_EmailMessageCooConfig emailMessageCoo = new ObservedData_EmailMessageCooConfig()
ObservedData_FileCooConfig fileCoo = new ObservedData_FileCooConfig()
ObservedData_Ipv4AddressCooConfig ipv4AddressCoo = new ObservedData_Ipv4AddressCooConfig()
ObservedData_Ipv6AddressCooConfig ipv6AddressCoo = new ObservedData_Ipv6AddressCooConfig()
ObservedData_MacAddressCooConfig macAddressCoo = new ObservedData_MacAddressCooConfig()
ObservedData_MutexCooConfig mutexCoo = new ObservedData_MutexCooConfig()
ObservedData_NetworkTrafficCooConfig networkTrafficCoo = new ObservedData_NetworkTrafficCooConfig()
ObservedData_ProcessCooConfig processCoo = new ObservedData_ProcessCooConfig()
ObservedData_SoftwareCooConfig softwareCoo = new ObservedData_SoftwareCooConfig()
ObservedData_UrlCooConfig urlCoo = new ObservedData_UrlCooConfig()
ObservedData_UserAccountCooConfig userAccountCoo = new ObservedData_UserAccountCooConfig()
ObservedData_WindowsRegistryKeyCooConfig windowsRegisteryKeyCoo = new ObservedData_WindowsRegistryKeyCooConfig()
ObservedData_X509CertificateCooConfig x509CertificateCoo = new ObservedData_X509CertificateCooConfig()


ObservedData_ExternalReferencesConfig externalReferences = new ObservedData_ExternalReferencesConfig()

ObservedData_GranularMarkingConfig granuarMarkings = new ObservedData_GranularMarkingConfig()

ObservedData_ObjectMarkingsConfig objectMarkings = new ObservedData_ObjectMarkingsConfig()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_ArtifactCooConfig{
int occurrence_probability = 100
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_AutonomousSystemCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_DirectoryCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_DomainNameCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_EmailAddressCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_EmailMessageCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_ExternalReferencesConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_FileCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_GranularMarkingConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_Ipv4AddressCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_Ipv6AddressCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_MacAddressCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_MutexCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_NetworkTrafficCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_ObjectMarkingsConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_ProcessCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_SoftwareCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_UrlCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_UserAccountCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_WindowsRegistryKeyCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.digitalstate.stix.faker.configs.sdo.observeddata

class ObservedData_X509CertificateCooConfig {
int occurrence_probability = 10
int occurs_count_lower = 1
int occurs_count_upper = 5
}
22 changes: 16 additions & 6 deletions src/main/java/io/digitalstate/stix/faker/GeneratorVerticle.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package io.digitalstate.stix.faker;

import io.digitalstate.stix.faker.configs.ObservedDataGeneratorConfig;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;

import java.util.Optional;

public class GeneratorVerticle extends AbstractVerticle {

private StixFakeDataGenerator generator = new StixFakeDataGenerator();
private StixMockDataGenerator generator = new StixMockDataGenerator();

@Override
public void start() throws Exception {

HttpServer server = vertx.createHttpServer(new HttpServerOptions());
Router router = Router.router(vertx);

router.route().handler(BodyHandler.create());

router.route(HttpMethod.GET, "/api/sdo/attack-pattern").handler(routingContext -> {

HttpServerResponse response = routingContext.response();
Expand Down Expand Up @@ -75,13 +79,19 @@ public void start() throws Exception {
response.end(generator.mockMalware().toJsonString());
});

router.route(HttpMethod.GET, "/api/sdo/observed-data").handler(routingContext -> {
router.route(HttpMethod.GET, "/api/sdo/observed-data")
.handler(routingContext -> {
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "application/json");

HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "application/json");
if (routingContext.getBody().length() > 0){
ObservedDataGeneratorConfig genConfig = routingContext.getBodyAsJson().mapTo(ObservedDataGeneratorConfig.class);
response.end(generator.mockObservedData(genConfig).toJsonString());

response.end(generator.mockObservedData().toJsonString());
});
} else {
response.end(generator.mockObservedData().toJsonString());
}
});

router.route(HttpMethod.GET, "/api/sdo/report").handler(routingContext -> {

Expand Down

0 comments on commit 8779449

Please sign in to comment.