|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## Technical Specification Support\n", |
| 8 | + "\n", |
| 9 | + "### How imports will work\n", |
| 10 | + "\n", |
| 11 | + "Imports can be used in different ways depending on the use case and support levels.\n", |
| 12 | + "\n", |
| 13 | + "People who want to (in general) support the latest version of STIX 2.X without making changes, implicitly using the latest version" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": null, |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "import stix2\n", |
| 23 | + "\n", |
| 24 | + "stix2.Indicator()" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "metadata": {}, |
| 30 | + "source": [ |
| 31 | + "or," |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "from stix2 import Indicator\n", |
| 41 | + "\n", |
| 42 | + "Indicator()" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "markdown", |
| 47 | + "metadata": {}, |
| 48 | + "source": [ |
| 49 | + "People who want to use an explicit version" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "import stix2.v20\n", |
| 59 | + "\n", |
| 60 | + "stix2.v20.Indicator()" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "markdown", |
| 65 | + "metadata": {}, |
| 66 | + "source": [ |
| 67 | + "or," |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "execution_count": null, |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "from stix2.v20 import Indicator\n", |
| 77 | + "\n", |
| 78 | + "Indicator()" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "markdown", |
| 83 | + "metadata": {}, |
| 84 | + "source": [ |
| 85 | + "or even," |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "code", |
| 90 | + "execution_count": null, |
| 91 | + "metadata": {}, |
| 92 | + "outputs": [], |
| 93 | + "source": [ |
| 94 | + "import stix2.v20 as stix2\n", |
| 95 | + "\n", |
| 96 | + "stix2.Indicator()" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "markdown", |
| 101 | + "metadata": {}, |
| 102 | + "source": [ |
| 103 | + "The last option makes it easy to update to a new version in one place per file, once you've made the deliberate action to do this.\n", |
| 104 | + "\n", |
| 105 | + "People who want to use multiple versions in a single file:" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": null, |
| 111 | + "metadata": {}, |
| 112 | + "outputs": [], |
| 113 | + "source": [ |
| 114 | + "import stix2\n", |
| 115 | + "\n", |
| 116 | + "stix2.v20.Indicator()\n", |
| 117 | + "\n", |
| 118 | + "stix2.v21.Indicator()" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "markdown", |
| 123 | + "metadata": {}, |
| 124 | + "source": [ |
| 125 | + "or," |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "code", |
| 130 | + "execution_count": null, |
| 131 | + "metadata": {}, |
| 132 | + "outputs": [], |
| 133 | + "source": [ |
| 134 | + "from stix2 import v20, v21\n", |
| 135 | + "\n", |
| 136 | + "v20.Indicator()\n", |
| 137 | + "v21.Indicator()" |
| 138 | + ] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "markdown", |
| 142 | + "metadata": {}, |
| 143 | + "source": [ |
| 144 | + "or (less preferred):" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": null, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [], |
| 152 | + "source": [ |
| 153 | + "from stix2.v20 import Indicator as Indicator_v20\n", |
| 154 | + "from stix2.v21 import Indicator as Indicator_v21\n", |
| 155 | + "\n", |
| 156 | + "Indicator_v20()\n", |
| 157 | + "Indicator_v21()" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "cell_type": "markdown", |
| 162 | + "metadata": {}, |
| 163 | + "source": [ |
| 164 | + "### How parsing will work\n", |
| 165 | + "If the ``version`` positional argument is not provided. The data will be parsed using the latest version of STIX 2.X supported by the `stix2` library.\n", |
| 166 | + "\n", |
| 167 | + "You can lock your `parse()` method to a specific STIX version by" |
| 168 | + ] |
| 169 | + }, |
| 170 | + { |
| 171 | + "cell_type": "code", |
| 172 | + "execution_count": null, |
| 173 | + "metadata": {}, |
| 174 | + "outputs": [], |
| 175 | + "source": [ |
| 176 | + "from stix2 import parse\n", |
| 177 | + "\n", |
| 178 | + "indicator = parse(\"\"\"{\n", |
| 179 | + " \"type\": \"indicator\",\n", |
| 180 | + " \"id\": \"indicator--dbcbd659-c927-4f9a-994f-0a2632274394\",\n", |
| 181 | + " \"created\": \"2017-09-26T23:33:39.829Z\",\n", |
| 182 | + " \"modified\": \"2017-09-26T23:33:39.829Z\",\n", |
| 183 | + " \"labels\": [\n", |
| 184 | + " \"malicious-activity\"\n", |
| 185 | + " ],\n", |
| 186 | + " \"name\": \"File hash for malware variant\",\n", |
| 187 | + " \"pattern\": \"[file:hashes.md5 = 'd41d8cd98f00b204e9800998ecf8427e']\",\n", |
| 188 | + " \"valid_from\": \"2017-09-26T23:33:39.829952Z\"\n", |
| 189 | + "}\"\"\", version=\"2.0\")\n", |
| 190 | + "print(indicator)" |
| 191 | + ] |
| 192 | + }, |
| 193 | + { |
| 194 | + "cell_type": "markdown", |
| 195 | + "metadata": {}, |
| 196 | + "source": [ |
| 197 | + "Keep in mind that if a 2.1 or higher object is parsed, the operation will fail." |
| 198 | + ] |
| 199 | + }, |
| 200 | + { |
| 201 | + "cell_type": "markdown", |
| 202 | + "metadata": {}, |
| 203 | + "source": [ |
| 204 | + "### How will custom work\n", |
| 205 | + "\n", |
| 206 | + "CustomObject, CustomObservable, CustomMarking and CustomExtension must be registered explicitly by STIX version. This is a design decision since properties or requirements may change as the STIX Technical Specification advances.\n", |
| 207 | + "\n", |
| 208 | + "You can perform this by," |
| 209 | + ] |
| 210 | + }, |
| 211 | + { |
| 212 | + "cell_type": "code", |
| 213 | + "execution_count": null, |
| 214 | + "metadata": {}, |
| 215 | + "outputs": [], |
| 216 | + "source": [ |
| 217 | + "import stix2\n", |
| 218 | + "\n", |
| 219 | + "# Make my custom observable available in STIX 2.0\n", |
| 220 | + "@stix2.v20.CustomObservable('x-new-object-type',\n", |
| 221 | + " ((\"prop\", stix2.properties.BooleanProperty())))\n", |
| 222 | + "class NewObject2(object):\n", |
| 223 | + " pass\n", |
| 224 | + "\n", |
| 225 | + "\n", |
| 226 | + "# Make my custom observable available in STIX 2.1\n", |
| 227 | + "@stix2.v21.CustomObservable('x-new-object-type',\n", |
| 228 | + " ((\"prop\", stix2.properties.BooleanProperty())))\n", |
| 229 | + "class NewObject2(object):\n", |
| 230 | + " pass" |
| 231 | + ] |
| 232 | + } |
| 233 | + ], |
| 234 | + "metadata": {}, |
| 235 | + "nbformat": 4, |
| 236 | + "nbformat_minor": 0 |
| 237 | +} |
0 commit comments