2018-07-03 13:00:18 +02:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import stix2
|
|
|
|
|
2018-07-13 17:10:05 +02:00
|
|
|
from .constants import (
|
2019-07-02 19:17:43 +02:00
|
|
|
FAKE_TIME, GROUPING_KWARGS, INDICATOR_KWARGS, INFRASTRUCTURE_KWARGS,
|
|
|
|
MALWARE_KWARGS, RELATIONSHIP_KWARGS,
|
2018-07-13 17:10:05 +02:00
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Inspired by: http://stackoverflow.com/a/24006251
|
|
|
|
@pytest.fixture
|
|
|
|
def clock(monkeypatch):
|
|
|
|
|
|
|
|
class mydatetime(stix2.utils.STIXdatetime):
|
|
|
|
@classmethod
|
|
|
|
def now(cls, tz=None):
|
|
|
|
return FAKE_TIME
|
|
|
|
|
|
|
|
monkeypatch.setattr(stix2.utils, 'STIXdatetime', mydatetime)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def uuid4(monkeypatch):
|
|
|
|
def wrapper():
|
|
|
|
data = [0]
|
|
|
|
|
|
|
|
def wrapped():
|
|
|
|
data[0] += 1
|
2018-07-11 15:43:37 +02:00
|
|
|
return "00000000-0000-4000-8000-00000000%04x" % data[0]
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
return wrapped
|
|
|
|
monkeypatch.setattr(uuid, "uuid4", wrapper())
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def indicator(uuid4, clock):
|
2018-07-03 15:40:51 +02:00
|
|
|
return stix2.v21.Indicator(**INDICATOR_KWARGS)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
|
2019-07-02 19:17:43 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def infrastructure(uuid4, clock):
|
|
|
|
return stix2.v21.Infrastructure(**INFRASTRUCTURE_KWARGS)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def grouping(uuid4, clock):
|
|
|
|
return stix2.v21.Grouping(**GROUPING_KWARGS)
|
|
|
|
|
|
|
|
|
2018-07-03 13:00:18 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def malware(uuid4, clock):
|
2018-07-03 15:40:51 +02:00
|
|
|
return stix2.v21.Malware(**MALWARE_KWARGS)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def relationship(uuid4, clock):
|
2018-07-03 15:40:51 +02:00
|
|
|
return stix2.v21.Relationship(**RELATIONSHIP_KWARGS)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def stix_objs1():
|
|
|
|
ind1 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
ind2 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
ind3 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.936Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
ind4 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
ind5 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
return [ind1, ind2, ind3, ind4, ind5]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def stix_objs2():
|
|
|
|
ind6 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-31T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 13:00:18 +02:00
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
ind7 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 13:00:18 +02:00
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
ind8 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-07-11 15:43:37 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-07-12 20:33:00 +02:00
|
|
|
"indicator_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"url-watchlist",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
2019-07-16 22:10:25 +02:00
|
|
|
"pattern_type": "stix",
|
2018-07-03 13:00:18 +02:00
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"type": "indicator",
|
2018-07-13 17:10:05 +02:00
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z",
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
return [ind6, ind7, ind8]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def real_stix_objs2(stix_objs2):
|
2018-07-03 15:40:51 +02:00
|
|
|
return [stix2.parse(x, version="2.1") for x in stix_objs2]
|