Skip to content

Commit

Permalink
Directory restructure (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleemur committed Dec 11, 2018
1 parent 018f329 commit 8f6f5da
Show file tree
Hide file tree
Showing 194 changed files with 273 additions and 263 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ include *.md
include LICENSE.txt

# Include JSON files
include stix_shifter/src/modules/qradar/json/*.json
include stix_shifter/stix_translation/src/modules/qradar/json/*.json
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Stix-shifter handles two primary functions:

### Converting from STIX Patterns to data source queries (query) or from data source results to STIX cyber observables (results)

#### Call the stix_shifter in the format of
#### Call the stix_translation in the format of

```
usage: stix_shifter.py translate [-h]
{qradar, dummy, splunk}
usage: stix_translation.py translate [-h]
{'qradar', 'dummy', 'car', 'cim', 'splunk', 'elastic', 'bigfix', 'csa', 'csa:at', 'csa:nf'}
{results, query} data
positional arguments:
Expand Down Expand Up @@ -172,11 +172,11 @@ python main.py translate qradar results \

## Transmission

#### Call the stix_shifter in the format of
#### Call the stix_transmission in the format of

```
usage: stix_shifter.py transmit [-h]
{async_dummy, synchronous_dummy, qradar, splunk, bigfix}
usage: stix_transmission.py transmit [-h]
{'async_dummy', 'synchronous_dummy', 'qradar', 'splunk', 'bigfix', 'csa'}
positional arguments:
{<async_dummy, synchronous_dummy, qradar, splunk, bigfix>} Transmission module to use
Expand Down Expand Up @@ -248,11 +248,11 @@ python main.py transmit qradar '{"host":"<ip address>", "port":"<port>", "cert":

### Example of converting a STIX pattern to an IBM QRadar AQL query:

[See the QRadar module documentation](stix_shifter/src/modules/qradar/README.md)
[See the QRadar module documentation](stix_shifter/stix_translation/src/modules/qradar/README.md)

### Example of converting IBM QRadar events to STIX:

[See the QRadar module documentation](stix_shifter/src/modules/qradar/README.md)
[See the QRadar module documentation](stix_shifter/stix_translation/src/modules/qradar/README.md)

# Contributing

Expand Down
69 changes: 56 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import sys
from stix_shifter import stix_shifter
from stix_shifter.stix_translation import stix_translation
from stix_shifter.stix_transmission import stix_transmission
import json


Expand Down Expand Up @@ -45,9 +46,9 @@ def __main__():

# positional arguments
translate_parser.add_argument(
'module', choices=stix_shifter.TRANSLATION_MODULES, help='what translation module to use')
'module', choices=stix_translation.TRANSLATION_MODULES, help='what translation module to use')
translate_parser.add_argument('translate_type', choices=[
stix_shifter.RESULTS, stix_shifter.QUERY], help='what translation action to perform')
stix_translation.RESULTS, stix_translation.QUERY], help='what translation action to perform')
translate_parser.add_argument(
'data_source', help='STIX identity object representing a datasource')
translate_parser.add_argument(
Expand All @@ -66,7 +67,7 @@ def __main__():

# positional arguments
transmit_parser.add_argument(
'module', choices=stix_shifter.TRANSMISSION_MODULES,
'module', choices=stix_transmission.TRANSMISSION_MODULES,
help='choose which connection module to use'
)
transmit_parser.add_argument(
Expand All @@ -82,39 +83,81 @@ def __main__():

# operation subparser
operation_subparser = transmit_parser.add_subparsers(title="operation", dest="operation_command")
operation_subparser.add_parser(stix_shifter.PING, help="Pings the data source")
query_operation_parser = operation_subparser.add_parser(stix_shifter.QUERY, help="Executes a query on the data source")
operation_subparser.add_parser(stix_transmission.PING, help="Pings the data source")
query_operation_parser = operation_subparser.add_parser(stix_transmission.QUERY, help="Executes a query on the data source")
query_operation_parser.add_argument('query_string', help='native datasource query string')
results_operation_parser = operation_subparser.add_parser(stix_shifter.RESULTS, help="Fetches the results of the data source query")
results_operation_parser = operation_subparser.add_parser(stix_transmission.RESULTS, help="Fetches the results of the data source query")
results_operation_parser.add_argument('search_id', help='uuid of executed query')
results_operation_parser.add_argument('offset', help='offset of results')
results_operation_parser.add_argument('length', help='length of results')
status_operation_parser = operation_subparser.add_parser(stix_shifter.STATUS, help="Gets the current status of the query")
status_operation_parser = operation_subparser.add_parser(stix_transmission.STATUS, help="Gets the current status of the query")
status_operation_parser.add_argument('search_id', help='uuid of executed query')
operation_subparser.add_parser(stix_shifter.IS_ASYNC, help='Checks if the query operation is asynchronous')
operation_subparser.add_parser(stix_transmission.IS_ASYNC, help='Checks if the query operation is asynchronous')

args = parent_parser.parse_args()

if args.command is None:
parent_parser.print_help(sys.stderr)
sys.exit(1)

shifter = stix_shifter.StixShifter()

if args.command == TRANSLATE:
options = json.loads(args.options) if bool(args.options) else {}
if args.stix_validator:
options['stix_validator'] = args.stix_validator
if args.data_mapper:
options['data_mapper'] = args.data_mapper
result = shifter.translate(

translation = stix_translation.StixTranslation()
result = translation.translate(
args.module, args.translate_type, args.data_source, args.data, options=options)
elif args.command == TRANSMIT:
result = shifter.transmit(args)
result = transmit(args) # stix_transmission

print(result)
exit(0)


def transmit(args):
"""
Connects to datasource and executes a query, grabs status update or query results
:param args:
args: <module> '{"host": <host IP>, "port": <port>, "cert": <certificate>}', '{"auth": <authentication>}',
<
query <query string>,
status <search id>,
results <search id> <offset> <length>,
ping,
is_async
>
"""
connection_dict = json.loads(args.connection)
configuration_dict = json.loads(args.configuration)
transmission = stix_transmission.StixTransmission(args.module, connection_dict, configuration_dict)

operation_command = args.operation_command
if operation_command == stix_transmission.QUERY:
query = args.query_string
result = transmission.query(query)
elif operation_command == stix_transmission.STATUS:
search_id = args.search_id
result = transmission.status(search_id)
elif operation_command == stix_transmission.RESULTS:
search_id = args.search_id
offset = args.offset
length = args.length
result = transmission.results(search_id, offset, length)
elif operation_command == stix_transmission.DELETE:
search_id = args.search_id
result = transmission.delete(search_id)
elif operation_command == stix_transmission.PING:
result = transmission.ping()
elif operation_command == stix_transmission.IS_ASYNC:
result = transmission.is_async()
else:
raise NotImplementedError
return result


if __name__ == "__main__":
__main__()
__main__()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
# },
entry_points={
'console_scripts': [
'stix-transmission=stix_transmission.stix_transmission:main',
'stix-transmission=stix_shifter.stix_transmission.stix_transmission:main',
'stix-translation=stix_shifter.stix_translation.stix_translation:main',
],
},

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from . import json_to_stix_translator
from ..modules.base.base_result_translator import BaseResultTranslator
from stix_shifter.src import transformers
from stix_shifter.stix_translation.src import transformers

# Concrete BaseResultTranslator

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import path
import json
from stix_shifter.src.exceptions import DataMappingException
from stix_shifter.stix_translation.src.exceptions import DataMappingException


def _fetch_mapping():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from stix_shifter.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
from stix_shifter.stix_translation.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
ComparisonExpressionOperators, ComparisonComparators, Pattern, \
CombinedComparisonExpression, CombinedObservationExpression, ObservationOperators
from stix_shifter.src.patterns.errors import SearchFeatureNotSupportedError
from stix_shifter.stix_translation.src.patterns.errors import SearchFeatureNotSupportedError


class RelevanceQueryStringPatternTranslator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def transform_query(self, data, options, mapping=None):
Transforms STIX query into Relevance query format. Based on a mapping file
:param data: STIX query string to transform into aql query format
:type data: str
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into aql format. This defaults to the from_stix_map.json in the stix_shifter/src/modules/qradar/json/ directory
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into aql format. This defaults to the from_stix_map.json in the stix_shifter/stix_translation/src/modules/qradar/json/ directory
:type mapping: str (filepath)
:return: aql query string
:rtype: str
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from stix_shifter.src.exceptions import DataMappingException
from stix_shifter.stix_translation.src.exceptions import DataMappingException

# TODO: should this really be a class? Could be a module, made it a class
# in case we have configuration arguments at some point
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from stix_shifter.src.exceptions import DataMappingException
from stix_shifter.stix_translation.src.exceptions import DataMappingException

# TODO: should this really be a class? Could be a module, made it a class
# in case we have configuration arguments at some point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import re

from stix_shifter.src.exceptions import DataMappingException
from stix_shifter.stix_translation.src.exceptions import DataMappingException

def _fetch_mapping():
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

logger = logging.getLogger(__name__)

from stix_shifter.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
from stix_shifter.stix_translation.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
ComparisonExpressionOperators, ComparisonComparators, Pattern, \
CombinedComparisonExpression, CombinedObservationExpression, ObservationOperators
from stix_shifter.src.patterns.errors import SearchFeatureNotSupportedError
from stix_shifter.stix_translation.src.patterns.errors import SearchFeatureNotSupportedError

from stix_shifter.src.transformers import TimestampToMilliseconds, ValueTransformer
from stix_shifter.stix_translation.src.transformers import TimestampToMilliseconds, ValueTransformer


def _fetch_network_protocol_mapping():
try:
map_file = open(
'stix_shifter/src/modules/qradar/json/network_protocol_map.json').read()
'stix_shifter/stix_translation/src/modules/qradar/json/network_protocol_map.json').read()
map_data = json.loads(map_file)
return map_data
except Exception as ex:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def transform_query(self, data, options, mapping=None):
Transforms STIX query into sql query format. Based on a mapping file
:param data: STIX query string to transform into sql query format
:type data: str
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into sql format. This defaults to the from_stix_map.json in the stix_shifter/src/modules/qradar/json/ directory
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into sql format. This defaults to the from_stix_map.json in the stix_shifter/stix_translation/src/modules/qradar/json/ directory
:type mapping: str (filepath)
:return: sql query string
:rtype: str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import path
import json
from stix_shifter.src.exceptions import DataMappingException
from stix_shifter.stix_translation.src.exceptions import DataMappingException


def _fetch_mapping():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from stix_shifter.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
from stix_shifter.stix_translation.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
ComparisonExpressionOperators, ComparisonComparators, Pattern, \
CombinedComparisonExpression, CombinedObservationExpression, ObservationOperators
from stix_shifter.src.transformers import TimestampToMilliseconds
from stix_shifter.stix_translation.src.transformers import TimestampToMilliseconds
import logging
import re

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

logger = logging.getLogger(__name__)

from stix_shifter.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
from stix_shifter.stix_translation.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
ComparisonExpressionOperators, ComparisonComparators, Pattern, \
CombinedComparisonExpression, CombinedObservationExpression, ObservationOperators
from stix_shifter.src.patterns.errors import SearchFeatureNotSupportedError
from stix_shifter.stix_translation.src.patterns.errors import SearchFeatureNotSupportedError

class ElasticQueryStringPatternTranslator:
comparator_lookup = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def transform_query(self, data, options, mapping=None):
Transforms STIX query into elastic query format. Based on a mapping file
:param data: STIX query string to transform into elastic query format
:type data: str
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into elastic format. This defaults to the from_stix_map.json in the stix_shifter/src/modules/qradar/json/ directory
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into elastic format. This defaults to the from_stix_map.json in the stix_shifter/stix_translation/src/modules/qradar/json/ directory
:type mapping: str (filepath)
:return: elastic query string
:rtype: str
Expand All @@ -26,7 +26,7 @@ def transform_query(self, data, options, mapping=None):
if not data_mapper:
data_mapper = 'car'

data_mapper_module_name = ''.join(["stix_shifter.src.modules.", data_mapper, ".", data_mapper, "_data_mapping"])
data_mapper_module_name = ''.join(["stix_shifter.stix_translation.src.modules.", data_mapper, ".", data_mapper, "_data_mapping"])

try:
data_mapper_module = importlib.import_module(data_mapper_module_name)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from stix_shifter.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
from stix_shifter.stix_translation.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
ComparisonExpressionOperators, ComparisonComparators, Pattern, \
CombinedComparisonExpression, CombinedObservationExpression, ObservationOperators
from stix_shifter.src.transformers import TimestampToMilliseconds
from stix_shifter.stix_translation.src.transformers import TimestampToMilliseconds
import logging
import json
import re
Expand All @@ -15,7 +15,7 @@
def _fetch_network_protocol_mapping():
try:
map_file = open(
'stix_shifter/src/modules/qradar/json/network_protocol_map.json').read()
'stix_shifter/stix_translation/src/modules/qradar/json/network_protocol_map.json').read()
map_data = json.loads(map_file)
return map_data
except Exception as ex:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import path
import json
from stix_shifter.src.exceptions import DataMappingException
from stix_shifter.stix_translation.src.exceptions import DataMappingException


def _fetch_mapping():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def transform_query(self, data, options, mapping=None):
Transforms STIX query into aql query format. Based on a mapping file
:param data: STIX query string to transform into aql query format
:type data: str
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into aql format. This defaults to the from_stix_map.json in the stix_shifter/src/modules/qradar/json/ directory
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into aql format. This defaults to the from_stix_map.json in the stix_shifter/stix_translation/src/modules/qradar/json/ directory
:type mapping: str (filepath)
:return: aql query string
:rtype: str
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import uuid
from . import cim_to_stix_translator
from ...base.base_result_translator import BaseResultTranslator
from stix_shifter.src import transformers
from stix_shifter.stix_translation.src import transformers

class CIMToStix(BaseResultTranslator):

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

logger = logging.getLogger(__name__)

from stix_shifter.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
from stix_shifter.stix_translation.src.patterns.pattern_objects import ObservationExpression, ComparisonExpression, \
ComparisonExpressionOperators, ComparisonComparators, Pattern, \
CombinedComparisonExpression, CombinedObservationExpression, ObservationOperators
from stix_shifter.src.modules.car.car_data_mapping import CarDataMapper
from stix_shifter.stix_translation.src.modules.car.car_data_mapping import CarDataMapper

from . import encoders
from . import object_scopers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def transform_query(self, data, options, mapping=None):
Transforms STIX query into splunk query format. Based on a mapping file
:param data: STIX query string to transform into splunk query format
:type data: str
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into splunk format. This defaults to the from_stix_map.json in the stix_shifter/src/modules/qradar/json/ directory
:param mapping: The mapping file path to use as instructions on how to transform the given STIX query into splunk format. This defaults to the from_stix_map.json in the stix_shifter/stix_translation/src/modules/qradar/json/ directory
:type mapping: str (filepath)
:return: splunk query string
:rtype: str
Expand All @@ -33,7 +33,7 @@ def transform_query(self, data, options, mapping=None):
if not data_mapper:
data_mapper = 'cim'

data_mapper_module_name = ''.join(["stix_shifter.src.modules.", data_mapper, ".", data_mapper, "_data_mapping"])
data_mapper_module_name = ''.join(["stix_shifter.stix_translation.src.modules.", data_mapper, ".", data_mapper, "_data_mapping"])

try:
data_mapper_module = importlib.import_module(data_mapper_module_name)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8f6f5da

Please sign in to comment.