|
| 1 | +# Experimenting with the Neo4j graph database Python STIX DataStore |
| 2 | + |
| 3 | +The Neo4j graph database Python STIX DataStore is a proof-of-concept implementation to show how to store STIX content in a graph database. |
| 4 | + |
| 5 | +## Limitations: |
| 6 | + |
| 7 | +As a proof-of-concept it has minimal functionality. |
| 8 | + |
| 9 | +## Installing Neo4j |
| 10 | + |
| 11 | +See https://neo4j.com/docs/desktop-manual/current/installation |
| 12 | + |
| 13 | +This will install the neo4j desktop application, which contains the neo4j browser to view the database. |
| 14 | + |
| 15 | +## Installing Neo4j python library |
| 16 | + |
| 17 | +The python neo4j library used is py2neo, available in pypi at https://pypi.org/project/py2neo/. Note this library is no longer being supported and has reached the "end-of-life". A different implementation of the DataStore could be written using https://neo4j.com/docs/api/python-driver/current/. |
| 18 | + |
| 19 | +## Implementation Details |
| 20 | + |
| 21 | +We would like to that the folks at JHU/APL for their implementation of [STIX2NEO4J.py](https://github.com/opencybersecurityalliance/oca-iob/tree/main/STIX2NEO4J%20Converter), which this code is based on. |
| 22 | + |
| 23 | +Only the DataSink (for storing STIX data) part of the DataStore object has been implemented. The DataSource part is implemented as a stub. However, the graph database can be queried using the neo4j cypher langauge within |
| 24 | +the neo4j browser. |
| 25 | + |
| 26 | +The main concept behind any graphs is nodes and edges. STIX data is similar as it contains relationship objects (SROs) and node objects (SDOs, SCOs and SMOs). Additional edges are provided by STIX embedded relationships, which are expressed as properties in STIX node objects. This organization of data in STIX is a natural fit for graph models, such as neo4j. |
| 27 | + |
| 28 | +The order in which STIX objects are added to the graph database is arbitrary. Therefore, when an SRO or embedded relationship is added via the DataStore, the nodes that it connects may not be present in the database, so the relationship is not added to the database, but remembered by the DataStore code as an unconnected relationship. Whenever a new node is |
| 29 | +added to the database, the unconnected relationships must be reviewed to determine if both nodes of a relationship can now be represented using an edge in the graph database. |
| 30 | + |
| 31 | +Note that unless both the source and target nodes are eventually added, |
| 32 | +the relationship will not be added either. |
| 33 | +How to address this issue in the implementation has not been determined. |
| 34 | + |
| 35 | +## Demonstrating a neo4j database for STIX |
| 36 | + |
| 37 | +Open the neo4j desktop app and create a new project named STIX. |
| 38 | + |
| 39 | +Select local DBMS on your local machine. |
| 40 | + |
| 41 | +<img src="docs/diagrams/select-dbms.png" width="500" height="250"> |
| 42 | + |
| 43 | +Create the database. |
| 44 | + |
| 45 | +<img src="docs/diagrams/create-dbms.png" width="500" height="300"> |
| 46 | + |
| 47 | +Start the database. |
| 48 | + |
| 49 | +<img src="docs/diagrams/start-dbms.png" width="500" height="120"> |
| 50 | + |
| 51 | +python demo.py \<STIX bundle file\> is used populate a local neo4j database, which can be viewed using the neo4j browser. |
| 52 | +A sample bundle file bundle--21531315-283d-4604-8501-4b7166e58c84.json is provided in the docs directory. |
| 53 | + |
| 54 | +Open the neo4j browser to view the database. |
| 55 | + |
| 56 | +<img src="docs/diagrams/open-browser.png" width="500" height="250"> |
| 57 | + |
| 58 | +Query using the cypher language. |
| 59 | + |
| 60 | +<img src="docs/diagrams/query-for-incident.png" width="750" height="450"> |
| 61 | + |
| 62 | +Left-clicking on a node gives you a choice of adding all related nodes and edges, removing the node and its edges from the display, or locking the node position. |
| 63 | + |
| 64 | +<img src="docs/diagrams/node-actions.png" width="500" height="320"> |
| 65 | + |
| 66 | +Remove the report object node for a better view of the graph. |
| 67 | + |
| 68 | +<img src="docs/diagrams/dont-show-node-and-edges.png" width="750" height="450"> |
| 69 | + |
| 70 | +Explore the graph. |
| 71 | + |
| 72 | +<img src="docs/diagrams/exploring-the-graph.png" width="750" height="400"> |
| 73 | + |
| 74 | +View the node properties, by mousing-over any node. |
| 75 | + |
| 76 | +<img src="docs/diagrams/node-properties.png" width="750" height="400"> |
0 commit comments