├── CITATION.cff ├── LICENSE.txt ├── NVDDataFetch-V1.ipynb ├── NVDDataFetch-V2.ipynb ├── PAPERCITATION.bib ├── QuarterlyVuln4Cast-V1.ipynb ├── QuarterlyVuln4Cast-V2.ipynb ├── README.md ├── Vuln4CastPaper.pdf ├── YearlyVuln4Cast-V1.ipynb ├── YearlyVuln4Cast-V2Vectors.ipynb └── requirements.txt /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: "Éireann" 5 | given-names: "Leverett" 6 | orcid: "https://orcid.org/0000-0001-6586-7359" 7 | - family-names: "Matilda" 8 | given-names: "Rhode" 9 | - family-names: "Erin" 10 | given-names: "Burns" 11 | - family-names: "Art" 12 | given-names: "Manion" 13 | 14 | title: "Vuln4Cast" 15 | version: 1.0.0 16 | doi: 10.5281/zenodo.1234 17 | date-released: 2023-05-20 18 | url: "https://github.com/FIRSTdotorg/Vuln4Cast/releases" 19 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2023] [Éireann Leverett and Matilda Rhode] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NVDDataFetch-V1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "tSjJuvKTyjbo", 6 | "metadata": { 7 | "id": "tSjJuvKTyjbo" 8 | }, 9 | "source": [ 10 | "# Setup our vulnerability data science lab environment" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "QVjRIuM97Wv4", 16 | "metadata": { 17 | "id": "QVjRIuM97Wv4" 18 | }, 19 | "source": [ 20 | "First we'll import all the libraries we need. A couple of them need installed first. JQ is a pythonic implementation of jq; a tool for querying json really fast. When looking at 25 years of vulnerabilities it is enormously useful." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "id": "Ac3vLew6N8Ik", 27 | "metadata": { 28 | "colab": { 29 | "base_uri": "https://localhost:8080/" 30 | }, 31 | "id": "Ac3vLew6N8Ik", 32 | "outputId": "d82755ff-c8b6-42ce-cb0a-faa60dec1195" 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "#!pip install requests\n", 37 | "#!pip install hurst\n", 38 | "#!pip install jq" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 2, 44 | "id": "aPf4YVs47Hr3", 45 | "metadata": { 46 | "id": "aPf4YVs47Hr3" 47 | }, 48 | "outputs": [], 49 | "source": [ 50 | "import requests\n", 51 | "import gzip as gz\n", 52 | "import shutil\n", 53 | "import pandas as pd\n", 54 | "import json\n", 55 | "import datetime\n", 56 | "import tqdm\n", 57 | "import os\n", 58 | "import jq\n", 59 | "import json\n", 60 | "import itertools\n", 61 | "import numpy as np\n", 62 | "import datetime\n", 63 | "from sklearn.metrics import mean_absolute_error as mae\n", 64 | "from sklearn.metrics import mean_absolute_percentage_error as mape\n", 65 | "import re\n", 66 | "from pandas.plotting import autocorrelation_plot" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "id": "HaE6Q136LzU2", 72 | "metadata": { 73 | "id": "HaE6Q136LzU2" 74 | }, 75 | "source": [ 76 | "The folders where we will store the data as a gzip, and as a json need to be created." 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "id": "DMJg36yV7NU6", 83 | "metadata": { 84 | "id": "DMJg36yV7NU6" 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "file_exists = os.path.exists('CVE-NVD')\n", 89 | "if not file_exists:\n", 90 | " os.mkdir('CVE-NVD')\n", 91 | " os.mkdir('CVE-NVD/GZIP')\n", 92 | " os.mkdir('CVE-NVD/JSON')" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "id": "lqd6pK-_y3V2", 98 | "metadata": { 99 | "id": "lqd6pK-_y3V2" 100 | }, 101 | "source": [ 102 | "Let's also setup some other folders for MITRE's advance views of CVE data." 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 4, 108 | "id": "FgvWYE3HVV1J", 109 | "metadata": { 110 | "id": "FgvWYE3HVV1J" 111 | }, 112 | "outputs": [], 113 | "source": [ 114 | "file_exists = os.path.exists('CVE-MITRE')\n", 115 | "if not file_exists:\n", 116 | " os.mkdir('CVE-MITRE')\n", 117 | " os.mkdir('CVE-MITRE/CSV')" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "id": "Peg0lTsMy_g0", 123 | "metadata": { 124 | "id": "Peg0lTsMy_g0" 125 | }, 126 | "source": [ 127 | "# convert datetime obj to string\n", 128 | "str_current_datetime = str(current_datetime)\n", 129 | "  \n", 130 | "# create a file object along with extension\n", 131 | "file_name = str_current_datetime+\".txt\"# Download the CVE data from NVD and MITRE" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "id": "d_nZqbNCS4vE", 137 | "metadata": { 138 | "id": "d_nZqbNCS4vE" 139 | }, 140 | "source": [ 141 | "Now we'll download the NVD data for every year since 1999. Don't worry it's faster than you think. \n", 142 | "PROTIP: The progress bar comes for free from the tqdm package. Just wrap a for loop in tqdm.tqdm() it and you get a progress bar for free.\n", 143 | "Now after this tutorial if you keep this notebook, you'll always be able to fetch all this CVE data easily. Handy for many more things than just forecasting." 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 5, 149 | "id": "mhHNC2b87SNZ", 150 | "metadata": { 151 | "colab": { 152 | "base_uri": "https://localhost:8080/" 153 | }, 154 | "id": "mhHNC2b87SNZ", 155 | "outputId": "13c13822-b8ef-45a4-a463-8c0acd1e4837" 156 | }, 157 | "outputs": [ 158 | { 159 | "name": "stderr", 160 | "output_type": "stream", 161 | "text": [ 162 | "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [00:27<00:00, 1.08s/it]\n" 163 | ] 164 | } 165 | ], 166 | "source": [ 167 | "now = datetime.datetime.now()\n", 168 | "#PROTIP wrap an iterative loop in python with tqdm.tqdm() and you get a progress bar\n", 169 | "for i in tqdm.tqdm(range(1999,now.year+1)):\n", 170 | " url = 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-'+str(i)+'.json.gz'\n", 171 | " req = requests.get(url, stream=True)\n", 172 | " with open('CVE-NVD/GZIP/nvdcve-1.1-'+str(i)+'.json.gz', 'wb') as f:\n", 173 | " for chunk in req.iter_content(chunk_size=1024):\n", 174 | " if chunk:\n", 175 | " f.write(chunk)\n", 176 | " f.flush()" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "id": "btOEgkvVTGpV", 182 | "metadata": { 183 | "id": "btOEgkvVTGpV" 184 | }, 185 | "source": [ 186 | "Here we need to decompress all those gzip files so we can work with the data as json files." 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 6, 192 | "id": "CsOo8_Nv7VSF", 193 | "metadata": { 194 | "colab": { 195 | "base_uri": "https://localhost:8080/" 196 | }, 197 | "id": "CsOo8_Nv7VSF", 198 | "outputId": "11f45d40-41a0-47ce-852b-9cf79b0f2dd5" 199 | }, 200 | "outputs": [ 201 | { 202 | "name": "stderr", 203 | "output_type": "stream", 204 | "text": [ 205 | "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [00:04<00:00, 5.53it/s]\n" 206 | ] 207 | } 208 | ], 209 | "source": [ 210 | "for i in tqdm.tqdm(range(1999,now.year+1)):\n", 211 | " with gz.open('CVE-NVD/GZIP/nvdcve-1.1-'+str(i)+'.json.gz', 'rb') as f_in:\n", 212 | " with open('CVE-NVD/JSON/nvdcve-1.1-'+str(i)+'.json', 'wb') as f_out:\n", 213 | " shutil.copyfileobj(f_in, f_out)" 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "id": "1obZacReVYcn", 219 | "metadata": { 220 | "id": "1obZacReVYcn" 221 | }, 222 | "source": [ 223 | "Now we need to download the MITRE version of CVEs too, which gives us a different kind of information that is useful later. Specifically, it gives us a view of CVEs that didn't make the cut, and some other timestamps we can use to show when CVEs where submitted, as opposed to published. That can help us calculate the rate of publication." 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 7, 229 | "id": "8zEaEjpIWO5T", 230 | "metadata": { 231 | "id": "8zEaEjpIWO5T" 232 | }, 233 | "outputs": [], 234 | "source": [ 235 | "url = 'https://cve.mitre.org/data/downloads/allitems.csv'\n", 236 | "req = requests.get(url, stream=True)\n", 237 | "now = datetime.datetime.now()\n", 238 | "with open('CVE-MITRE/CSV/allitems_current.csv', 'wb') as f:\n", 239 | " for chunk in req.iter_content(chunk_size=1024):\n", 240 | " if chunk:\n", 241 | " f.write(chunk)\n", 242 | " f.flush()" 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "id": "MsUxquJB2Am4", 248 | "metadata": { 249 | "id": "MsUxquJB2Am4" 250 | }, 251 | "source": [ 252 | "# Convert the data to panda dataframes and csv files" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "id": "nHa3etpy2YJT", 258 | "metadata": { 259 | "id": "nHa3etpy2YJT" 260 | }, 261 | "source": [ 262 | "Here we start to use JQ to make queiries specific to CVE json structure. We pull out the CVE-ID, the published date, the assigner, and the CVSSv2 base score." 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 8, 268 | "id": "Bkc7OhffsWxZ", 269 | "metadata": { 270 | "colab": { 271 | "background_save": true, 272 | "base_uri": "https://localhost:8080/" 273 | }, 274 | "id": "Bkc7OhffsWxZ", 275 | "outputId": "9cb6697c-a620-4723-98f1-f35c079e93d1" 276 | }, 277 | "outputs": [ 278 | { 279 | "name": "stderr", 280 | "output_type": "stream", 281 | "text": [ 282 | "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [08:03<00:00, 21.98s/it]\n" 283 | ] 284 | } 285 | ], 286 | "source": [ 287 | "cve_id_query = jq.compile(\".CVE_Items[].cve.CVE_data_meta.ID\")\n", 288 | "cve_publication_query = jq.compile(\".CVE_Items[].publishedDate\")\n", 289 | "cve_assigner_query = jq.compile(\".CVE_Items[].cve.CVE_data_meta.ASSIGNER\")\n", 290 | "cve_description_query = jq.compile(\".CVE_Items[].cve.description.description_data[].value\")\n", 291 | "cvss_v2_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV2.cvssV2.baseScore\")\n", 292 | "cvss_v2_exploitability_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV2.cvssV2.exploitabilityScore\")\n", 293 | "cvss_v2_vector_query = jq.compile(\".CVE_Items[].impact.baseMetricV2.cvssV2.vectorString\")\n", 294 | "cvss_v3_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV3.cvssV3.baseScore\")\n", 295 | "cvss_v3_exploitability_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV3.cvssV3.exploitabilityScore\")\n", 296 | "cvss_v3_vector_query = jq.compile(\".CVE_Items[].impact.baseMetricV3.cvssV3.vectorString\")\n", 297 | "cwe_query = jq.compile(\".CVE_Items[].cve.problemtype.problemtype_data[].description[].value\")\n", 298 | "now = datetime.datetime.now()\n", 299 | "collector = []\n", 300 | "for i in tqdm.tqdm(range(2002, now.year+1)):\n", 301 | " with open('CVE-NVD/JSON/nvdcve-1.1-'+str(i)+'.json') as json_file:\n", 302 | " data = json.load(json_file)\n", 303 | " pubs = cve_publication_query.input(data).text()\n", 304 | " pubs = pubs.split('\\n')\n", 305 | " pubs = [pd.to_datetime(ts.strip('\"'), yearfirst=True, infer_datetime_format=True) for ts in pubs]\n", 306 | " index= pd.Series(pubs,name='Publication')\n", 307 | " cves = cve_id_query.input(data).text()\n", 308 | " cves = cves.split('\\n')\n", 309 | " cves = [cve.strip('\"') for cve in cves]\n", 310 | " assigners = cve_assigner_query.input(data).text()\n", 311 | " assigners = assigners.split('\\n')\n", 312 | " description = cve_description_query.input(data).text()\n", 313 | " description = description.split('\\n')\n", 314 | " cvss_v2 = cvss_v2_score_query.input(data).text()\n", 315 | " cvss_v2 = cvss_v2.split('\\n')\n", 316 | " cvss_v2_vector = cvss_v2_vector_query.input(data).text()\n", 317 | " cvss_v2_vector = cvss_v2_vector.split('\\n')\n", 318 | " cvss_v2_exploitability = cvss_v2_exploitability_score_query.input(data).text()\n", 319 | " cvss_v2_exploitability = cvss_v2_exploitability.split('\\n')\n", 320 | " cvss_v3 = cvss_v3_score_query.input(data).text()\n", 321 | " cvss_v3 = cvss_v3.split('\\n')\n", 322 | " cvss_v3_vector = cvss_v3_vector_query.input(data).text()\n", 323 | " cvss_v3_vector = cvss_v3_vector.split('\\n')\n", 324 | " cvss_v3_exploitability = cvss_v3_exploitability_score_query.input(data).text()\n", 325 | " cvss_v3_exploitability = cvss_v3_exploitability.split('\\n')\n", 326 | " cwe = cwe_query.input(data).text()\n", 327 | " cwe = cwe.split('\\n')\n", 328 | " s1 = pd.Series(cves,name='ID')\n", 329 | " s2 = pd.Series(assigners,name='ASSIGNER')\n", 330 | " s3 = pd.Series(description,name='DESCRIPTION')\n", 331 | " ones = [1]*len(cves)\n", 332 | " s4 = pd.Series(ones,name='Count')\n", 333 | " s5 = pd.Series(cvss_v2,name='v2 CVSS')\n", 334 | " s6 = pd.Series(cvss_v2_vector,name='v2 Vector')\n", 335 | " s7 = pd.Series(cvss_v2_exploitability,name='v2 Exploitability Score')\n", 336 | " s8 = pd.Series(cvss_v3,name='v3 CVSS')\n", 337 | " s9 = pd.Series(cvss_v3_vector,name='v3 Vector')\n", 338 | " s10 = pd.Series(cvss_v3_exploitability,name='v3 Expoitability Score')\n", 339 | " s11 = pd.Series(cwe,name='CWE')\n", 340 | " vulns = pd.concat([index,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11], axis=1)\n", 341 | " vulns = vulns.set_index('Publication')\n", 342 | " collector.append(vulns)\n", 343 | " json_file.close()\n", 344 | "all_items = pd.concat(collector)" 345 | ] 346 | }, 347 | { 348 | "cell_type": "markdown", 349 | "id": "sgzeBTCf2w1R", 350 | "metadata": { 351 | "id": "sgzeBTCf2w1R" 352 | }, 353 | "source": [ 354 | "Save all the data we just filtered to a CSV file, for future use." 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "execution_count": 9, 360 | "id": "d5a634b0", 361 | "metadata": { 362 | "colab": { 363 | "background_save": true 364 | }, 365 | "id": "d5a634b0" 366 | }, 367 | "outputs": [], 368 | "source": [ 369 | "all_items.sort_index()\n", 370 | "all_items.to_csv('NVD-Vulnerability-Volumes.csv')" 371 | ] 372 | }, 373 | { 374 | "cell_type": "markdown", 375 | "id": "fEoLX86f2727", 376 | "metadata": { 377 | "id": "fEoLX86f2727" 378 | }, 379 | "source": [ 380 | "If you want to read that file in the future, without fetching all the data again, just uncoment the cell below." 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": 10, 386 | "id": "2d2a5b2e", 387 | "metadata": { 388 | "colab": { 389 | "background_save": true 390 | }, 391 | "id": "2d2a5b2e", 392 | "outputId": "955e5b09-f4da-4c1c-cdca-92930b5fac07" 393 | }, 394 | "outputs": [], 395 | "source": [ 396 | "all_items = pd.read_csv('NVD-Vulnerability-Volumes.csv',index_col=['Publication'],parse_dates=['Publication'],infer_datetime_format=True)\n", 397 | "all_items = all_items.sort_index()" 398 | ] 399 | } 400 | ], 401 | "metadata": { 402 | "colab": { 403 | "collapsed_sections": [], 404 | "provenance": [] 405 | }, 406 | "kernelspec": { 407 | "display_name": "Python 3 (ipykernel)", 408 | "language": "python", 409 | "name": "python3" 410 | }, 411 | "language_info": { 412 | "codemirror_mode": { 413 | "name": "ipython", 414 | "version": 3 415 | }, 416 | "file_extension": ".py", 417 | "mimetype": "text/x-python", 418 | "name": "python", 419 | "nbconvert_exporter": "python", 420 | "pygments_lexer": "ipython3", 421 | "version": "3.10.6" 422 | } 423 | }, 424 | "nbformat": 4, 425 | "nbformat_minor": 5 426 | } 427 | -------------------------------------------------------------------------------- /NVDDataFetch-V2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "tSjJuvKTyjbo", 6 | "metadata": { 7 | "id": "tSjJuvKTyjbo" 8 | }, 9 | "source": [ 10 | "# Setup our vulnerability data science lab environment" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "QVjRIuM97Wv4", 16 | "metadata": { 17 | "id": "QVjRIuM97Wv4" 18 | }, 19 | "source": [ 20 | "First we'll import all the libraries we need. A couple of them need installed first. JQ is a pythonic implementation of jq; a tool for querying json really fast. When looking at 25 years of vulnerabilities it is enormously useful." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "id": "Ac3vLew6N8Ik", 27 | "metadata": { 28 | "colab": { 29 | "base_uri": "https://localhost:8080/" 30 | }, 31 | "id": "Ac3vLew6N8Ik", 32 | "outputId": "d82755ff-c8b6-42ce-cb0a-faa60dec1195" 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "#!pip install requests\n", 37 | "#!pip install hurst\n", 38 | "#!pip install jq" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 2, 44 | "id": "aPf4YVs47Hr3", 45 | "metadata": { 46 | "id": "aPf4YVs47Hr3" 47 | }, 48 | "outputs": [], 49 | "source": [ 50 | "import requests\n", 51 | "import gzip as gz\n", 52 | "import shutil\n", 53 | "import pandas as pd\n", 54 | "import json\n", 55 | "import datetime\n", 56 | "import tqdm\n", 57 | "import os\n", 58 | "import jq\n", 59 | "import json\n", 60 | "#import matplotlib.pyplot as plt\n", 61 | "#plt.rcParams['font.size'] = '22'\n", 62 | "#plt.rcParams['font.weight'] = 'bold'\n", 63 | "# Increase size of plot in jupyter\n", 64 | "#plt.rcParams[\"figure.figsize\"] = (20,12)\n", 65 | "import itertools\n", 66 | "#import seaborn as sns\n", 67 | "import numpy as np\n", 68 | "import datetime\n", 69 | "from sklearn.metrics import mean_absolute_error as mae\n", 70 | "from sklearn.metrics import mean_absolute_percentage_error as mape\n", 71 | "import re\n", 72 | "from pandas.plotting import autocorrelation_plot" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "id": "HaE6Q136LzU2", 78 | "metadata": { 79 | "id": "HaE6Q136LzU2" 80 | }, 81 | "source": [ 82 | "The folders where we will store the data as a gzip, and as a json need to be created." 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 3, 88 | "id": "DMJg36yV7NU6", 89 | "metadata": { 90 | "id": "DMJg36yV7NU6" 91 | }, 92 | "outputs": [], 93 | "source": [ 94 | "file_exists = os.path.exists('CVE-NVD')\n", 95 | "if not file_exists:\n", 96 | " os.mkdir('CVE-NVD')\n", 97 | " os.mkdir('CVE-NVD/GZIP')\n", 98 | " os.mkdir('CVE-NVD/JSON')" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "id": "lqd6pK-_y3V2", 104 | "metadata": { 105 | "id": "lqd6pK-_y3V2" 106 | }, 107 | "source": [ 108 | "Let's also setup some other folders for MITRE's advance views of CVE data." 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 4, 114 | "id": "FgvWYE3HVV1J", 115 | "metadata": { 116 | "id": "FgvWYE3HVV1J" 117 | }, 118 | "outputs": [], 119 | "source": [ 120 | "file_exists = os.path.exists('CVE-MITRE')\n", 121 | "if not file_exists:\n", 122 | " os.mkdir('CVE-MITRE')\n", 123 | " os.mkdir('CVE-MITRE/CSV')" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "id": "Peg0lTsMy_g0", 129 | "metadata": { 130 | "id": "Peg0lTsMy_g0" 131 | }, 132 | "source": [ 133 | "# convert datetime obj to string\n", 134 | "str_current_datetime = str(current_datetime)\n", 135 | "  \n", 136 | "# create a file object along with extension\n", 137 | "file_name = str_current_datetime+\".txt\"# Download the CVE data from NVD and MITRE" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "id": "d_nZqbNCS4vE", 143 | "metadata": { 144 | "id": "d_nZqbNCS4vE" 145 | }, 146 | "source": [ 147 | "Now we'll download the NVD data for every year since 1999. Don't worry it's faster than you think. \n", 148 | "PROTIP: The progress bar comes for free from the tqdm package. Just wrap a for loop in tqdm.tqdm() it and you get a progress bar for free.\n", 149 | "Now after this tutorial if you keep this notebook, you'll always be able to fetch all this CVE data easily. Handy for many more things than just forecasting." 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 5, 155 | "id": "mhHNC2b87SNZ", 156 | "metadata": { 157 | "colab": { 158 | "base_uri": "https://localhost:8080/" 159 | }, 160 | "id": "mhHNC2b87SNZ", 161 | "outputId": "13c13822-b8ef-45a4-a463-8c0acd1e4837" 162 | }, 163 | "outputs": [ 164 | { 165 | "name": "stderr", 166 | "output_type": "stream", 167 | "text": [ 168 | "100%|██████████| 27/27 [00:01<00:00, 16.24it/s]\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "now = datetime.datetime.now()\n", 174 | "#PROTIP wrap an iterative loop in python with tqdm.tqdm() and you get a progress bar\n", 175 | "for i in tqdm.tqdm(range(1999,now.year+1)):\n", 176 | " url = 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-'+str(i)+'.json.gz'\n", 177 | " req = requests.get(url, stream=True)\n", 178 | " with open('CVE-NVD/GZIP/nvdcve-1.1-'+str(i)+'.json.gz', 'wb') as f:\n", 179 | " for chunk in req.iter_content(chunk_size=1024):\n", 180 | " if chunk:\n", 181 | " f.write(chunk)\n", 182 | " f.flush()" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "id": "btOEgkvVTGpV", 188 | "metadata": { 189 | "id": "btOEgkvVTGpV" 190 | }, 191 | "source": [ 192 | "Here we need to decompress all those gzip files so we can work with the data as json files." 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 6, 198 | "id": "CsOo8_Nv7VSF", 199 | "metadata": { 200 | "colab": { 201 | "base_uri": "https://localhost:8080/" 202 | }, 203 | "id": "CsOo8_Nv7VSF", 204 | "outputId": "11f45d40-41a0-47ce-852b-9cf79b0f2dd5" 205 | }, 206 | "outputs": [ 207 | { 208 | "name": "stderr", 209 | "output_type": "stream", 210 | "text": [ 211 | "100%|██████████| 27/27 [00:10<00:00, 2.53it/s]\n" 212 | ] 213 | } 214 | ], 215 | "source": [ 216 | "for i in tqdm.tqdm(range(1999,now.year+1)):\n", 217 | " with gz.open('CVE-NVD/GZIP/nvdcve-1.1-'+str(i)+'.json.gz', 'rb') as f_in:\n", 218 | " with open('CVE-NVD/JSON/nvdcve-1.1-'+str(i)+'.json', 'wb') as f_out:\n", 219 | " shutil.copyfileobj(f_in, f_out)" 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "id": "1obZacReVYcn", 225 | "metadata": { 226 | "id": "1obZacReVYcn" 227 | }, 228 | "source": [ 229 | "Now we need to download the MITRE version of CVEs too, which gives us a different kind of information that is useful later. Specifically, it gives us a view of CVEs that didn't make the cut, and some other timestamps we can use to show when CVEs where submitted, as opposed to published. That can help us calculate the rate of publication." 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 7, 235 | "id": "8zEaEjpIWO5T", 236 | "metadata": { 237 | "id": "8zEaEjpIWO5T" 238 | }, 239 | "outputs": [], 240 | "source": [ 241 | "url = 'https://cve.mitre.org/data/downloads/allitems.csv'\n", 242 | "req = requests.get(url, stream=True)\n", 243 | "now = datetime.datetime.now()\n", 244 | "with open('CVE-MITRE/CSV/allitems_current.csv', 'wb') as f:\n", 245 | " for chunk in req.iter_content(chunk_size=1024):\n", 246 | " if chunk:\n", 247 | " f.write(chunk)\n", 248 | " f.flush()" 249 | ] 250 | }, 251 | { 252 | "cell_type": "markdown", 253 | "id": "MsUxquJB2Am4", 254 | "metadata": { 255 | "id": "MsUxquJB2Am4" 256 | }, 257 | "source": [ 258 | "# Convert the data to panda dataframes and csv files" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "id": "nHa3etpy2YJT", 264 | "metadata": { 265 | "id": "nHa3etpy2YJT" 266 | }, 267 | "source": [ 268 | "Here we start to use JQ to make queiries specific to CVE json structure. We pull out the CVE-ID, the published date, the assigner, and the CVSSv2 base score." 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 8, 274 | "id": "Bkc7OhffsWxZ", 275 | "metadata": { 276 | "colab": { 277 | "background_save": true, 278 | "base_uri": "https://localhost:8080/" 279 | }, 280 | "id": "Bkc7OhffsWxZ", 281 | "outputId": "9cb6697c-a620-4723-98f1-f35c079e93d1" 282 | }, 283 | "outputs": [ 284 | { 285 | "name": "stderr", 286 | "output_type": "stream", 287 | "text": [ 288 | "100%|██████████| 24/24 [11:49<00:00, 29.55s/it]\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "cve_id_query = jq.compile(\".CVE_Items[].cve.CVE_data_meta.ID\")\n", 294 | "cve_publication_query = jq.compile(\".CVE_Items[].publishedDate\")\n", 295 | "cve_assigner_query = jq.compile(\".CVE_Items[].cve.CVE_data_meta.ASSIGNER\")\n", 296 | "cve_description_query = jq.compile(\".CVE_Items[].cve.description.description_data[].value\")\n", 297 | "cvss_v2_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV2.cvssV2.baseScore\")\n", 298 | "cvss_v2_exploitability_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV2.cvssV2.exploitabilityScore\")\n", 299 | "cvss_v2_vector_query = jq.compile(\".CVE_Items[].impact.baseMetricV2.cvssV2.vectorString\")\n", 300 | "cvss_v3_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV3.cvssV3.baseScore\")\n", 301 | "cvss_v3_exploitability_score_query = jq.compile(\".CVE_Items[].impact.baseMetricV3.cvssV3.exploitabilityScore\")\n", 302 | "cvss_v3_vector_query = jq.compile(\".CVE_Items[].impact.baseMetricV3.cvssV3.vectorString\")\n", 303 | "cpe23_query = jq.compile('.CVE_Items[] | [.cve.CVE_data_meta.ID, .configurations.nodes[].cpe_match[].cpe23Uri]')\n", 304 | "#Product, cpe strings?, cwe\n", 305 | "cwe_query = jq.compile(\".CVE_Items[].cve.problemtype.problemtype_data[].description[].value\")\n", 306 | "#Add CVE state in v5, date-assigned, date_requested, date public, product,cpe_string\n", 307 | "now = datetime.datetime.now()\n", 308 | "collector = []\n", 309 | "for i in tqdm.tqdm(range(2002, now.year+1)):\n", 310 | " with open('CVE-NVD/JSON/nvdcve-1.1-'+str(i)+'.json') as json_file:\n", 311 | " try:\n", 312 | " data = json.load(json_file)\n", 313 | " except:\n", 314 | " continue\n", 315 | " pubs = cve_publication_query.input(data).text()\n", 316 | " pubs = pubs.split('\\n')\n", 317 | " pubs = [pd.to_datetime(ts.strip('\"'), yearfirst=True) for ts in pubs]\n", 318 | " index= pd.Series(pubs,name='Publication')\n", 319 | " cves = cve_id_query.input(data).text()\n", 320 | " cves = cves.split('\\n')\n", 321 | " cves = [cve.strip('\"') for cve in cves]\n", 322 | " assigners = cve_assigner_query.input(data).text()\n", 323 | " assigners = assigners.split('\\n')\n", 324 | " description = cve_description_query.input(data).text()\n", 325 | " description = description.split('\\n')\n", 326 | " cvss_v2 = cvss_v2_score_query.input(data).text()\n", 327 | " cvss_v2 = cvss_v2.split('\\n')\n", 328 | " cvss_v2_vector = cvss_v2_vector_query.input(data).text()\n", 329 | " cvss_v2_vector = cvss_v2_vector.split('\\n')\n", 330 | " cvss_v2_exploitability = cvss_v2_exploitability_score_query.input(data).text()\n", 331 | " cvss_v2_exploitability = cvss_v2_exploitability.split('\\n')\n", 332 | " cvss_v3 = cvss_v3_score_query.input(data).text()\n", 333 | " cvss_v3 = cvss_v3.split('\\n')\n", 334 | " cvss_v3_vector = cvss_v3_vector_query.input(data).text()\n", 335 | " cvss_v3_vector = cvss_v3_vector.split('\\n')\n", 336 | " cvss_v3_exploitability = cvss_v3_exploitability_score_query.input(data).text()\n", 337 | " cvss_v3_exploitability = cvss_v3_exploitability.split('\\n')\n", 338 | " cwe = cwe_query.input(data).text()\n", 339 | " cwe = cwe.split('\\n')\n", 340 | " cpe23 = cpe23_query.input(data).text()\n", 341 | " cpe23_list = cpe23.split(\"\\n\")\n", 342 | " cpe23_string_list = [s.split(\",\") for s in cpe23_list]\n", 343 | " s1 = pd.Series(cves,name='ID')\n", 344 | " s2 = pd.Series(assigners,name='ASSIGNER')\n", 345 | " s3 = pd.Series(description,name='DESCRIPTION')\n", 346 | " ones = [1]*len(cves)\n", 347 | " s4 = pd.Series(ones,name='Count')\n", 348 | " s5 = pd.Series(cvss_v2,name='v2 CVSS')\n", 349 | " s6 = pd.Series(cvss_v2_vector,name='v2 Vector')\n", 350 | " s7 = pd.Series(cvss_v2_exploitability,name='v2 Exploitability Score')\n", 351 | " s8 = pd.Series(cvss_v3,name='v3 CVSS')\n", 352 | " s9 = pd.Series(cvss_v3_vector,name='v3 Vector')\n", 353 | " s10 = pd.Series(cvss_v3_exploitability,name='v3 Expoitability Score')\n", 354 | " s11 = pd.Series(cwe,name='CWE')\n", 355 | " s12 = pd.Series(cpe23_string_list,name='v2.3 CPE')\n", 356 | " vulns = pd.concat([index,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12], axis=1)\n", 357 | " vulns = vulns.set_index('Publication')\n", 358 | " collector.append(vulns)\n", 359 | " json_file.close()\n", 360 | "all_items = pd.concat(collector)" 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "id": "sgzeBTCf2w1R", 366 | "metadata": { 367 | "id": "sgzeBTCf2w1R" 368 | }, 369 | "source": [ 370 | "Save all the data we just filtered to a CSV file, for future use." 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": 9, 376 | "id": "d5a634b0", 377 | "metadata": { 378 | "colab": { 379 | "background_save": true 380 | }, 381 | "id": "d5a634b0" 382 | }, 383 | "outputs": [], 384 | "source": [ 385 | "all_items.sort_index()\n", 386 | "all_items.to_csv('NVD-Vulnerability-Volumes.csv')" 387 | ] 388 | }, 389 | { 390 | "cell_type": "markdown", 391 | "id": "fEoLX86f2727", 392 | "metadata": { 393 | "id": "fEoLX86f2727" 394 | }, 395 | "source": [ 396 | "If you want to read that file in the future, without fetching all the data again, just uncoment the cell below." 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 10, 402 | "id": "2d2a5b2e", 403 | "metadata": { 404 | "colab": { 405 | "background_save": true 406 | }, 407 | "id": "2d2a5b2e", 408 | "outputId": "955e5b09-f4da-4c1c-cdca-92930b5fac07" 409 | }, 410 | "outputs": [], 411 | "source": [ 412 | "all_items = pd.read_csv('NVD-Vulnerability-Volumes.csv',index_col=['Publication'],parse_dates=['Publication'], low_memory=False)\n", 413 | "all_items = all_items.sort_index()" 414 | ] 415 | }, 416 | { 417 | "cell_type": "code", 418 | "execution_count": null, 419 | "id": "67c4d913-7321-435b-93a6-fddf6c1d1665", 420 | "metadata": {}, 421 | "outputs": [], 422 | "source": [] 423 | } 424 | ], 425 | "metadata": { 426 | "colab": { 427 | "collapsed_sections": [], 428 | "provenance": [] 429 | }, 430 | "kernelspec": { 431 | "display_name": "Python 3 (ipykernel)", 432 | "language": "python", 433 | "name": "python3" 434 | }, 435 | "language_info": { 436 | "codemirror_mode": { 437 | "name": "ipython", 438 | "version": 3 439 | }, 440 | "file_extension": ".py", 441 | "mimetype": "text/x-python", 442 | "name": "python", 443 | "nbconvert_exporter": "python", 444 | "pygments_lexer": "ipython3", 445 | "version": "3.11.9" 446 | } 447 | }, 448 | "nbformat": 4, 449 | "nbformat_minor": 5 450 | } 451 | -------------------------------------------------------------------------------- /PAPERCITATION.bib: -------------------------------------------------------------------------------- 1 | @article{10.1145/3492328, 2 | author = {Leverett, \'{E}ireann and Rhode, Matilda and Wedgbury, Adam}, 3 | title = {Vulnerability Forecasting: Theory and Practice}, 4 | year = {2022}, 5 | issue_date = {December 2022}, 6 | publisher = {Association for Computing Machinery}, 7 | address = {New York, NY, USA}, 8 | volume = {3}, 9 | number = {4}, 10 | issn = {2692-1626}, 11 | url = {https://doi.org/10.1145/3492328}, 12 | doi = {10.1145/3492328}, 13 | abstract = {It is possible to forecast the volume of CVEs released within a time frame with a given prediction interval. For example, the number of CVEs published between now and a year from now can be forecast within 8% of the actual value. Different predictive algorithms perform well at different lookahead values other than 365 days, such as monthly, quarterly, and half year. It is also possible to estimate the proportions of that total volume belonging to specific vendors, software, CVSS scores, or vulnerability types. Some vendors and products can be predicted with accuracy, others with too much uncertainty to be practically useful. This article documents which vendors are amenable to being forecasted. Strategic patch management should become much easier with these tools, and further uncertainty reductions can be built from the methodologies in this article.}, 14 | journal = {Digital Threats}, 15 | month = {mar}, 16 | articleno = {42}, 17 | numpages = {27}, 18 | keywords = {Cyberrisk, forecasting, prediction, CVE, vulnerabilities, vulnerability management} 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vuln4Cast 2 | 3 | ## What is this repository all about? 4 | This repository holds the code that uses NVD data to demonstrate that it is possible to forecast vulnerabilities with reasonable accuracy both quarterly and yearly. We believe this is foundational rather than an end result. In other words, this forecasting will enable other research to be performed that might not have existed before. We encourage you to make more accurate forecasts, or extend the lookahead window, or make sub-forecasts for specific vendors. 5 | 6 | ## Quickstart 7 | 8 | Clone this repository, configure a suitable Python 3 and Jupyter Notebook environment. 9 | 10 | ``` 11 | git clone https://github.com/FIRSTdotorg/Vuln4Cast.git 12 | cd Vuln4Cast 13 | pip install -r requirements.txt 14 | ``` 15 | 16 | Before running the analysis, you will need to run the code to fetch NVD data, see `NVDDataFetch-V1.ipynb`. This builds directory structures, fetches data from NVD (and CVE), and unpacks that data into formats that are easier to work with. This will take a few minutes depending on your network. 17 | 18 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/FIRSTdotorg/Vuln4Cast/HEAD) 19 | 20 | Open In Colab 21 | 22 | 23 | ## Analysis 24 | 25 | Once the data has been fetched, you can run either the quarterly or yearly forecasts, e.g. `YearlyVuln4Cast-V1.ipynb`. They each use a Sarimax model that gives good results, and we consider as a benchmark for your own research to beat. They also contain a hurst exponent analysis that should demonstrate that it is both possible to forecast, and there is long term trending in the data. Other graphs help demonstrate features useful to forecasters who will wish to extend or improve the work. 26 | 27 | If all of this interests you, we encourage you to get in touch, and help us build a community dedicated to prediction and forecasting of vulnerabilities. We believe we are part of a wider movement of cyber risk quantification that includes our allies like [EPSS](https://github.com/FIRSTdotorg/epss). They predict exploitation of CVEs rather than CVE volumes. We honestly foresee a world in which these techniques become combined and even perhaps the economic damage of explotation can be predicted as well. 28 | 29 | ## To cite the original paper 30 | 31 | See the PAPERCITATION.bib file or: 32 | 33 | Éireann Leverett, Matilda Rhode, and Adam Wedgbury. 2022. Vulnerability Forecasting: Theory and Practice. Digital Threats 3, 4, Article 42 (mar2022), 27 pages. https://doi.org/10.1145/3492328 34 | 35 | ## To cite this codebase if you use it for your own paper 36 | 37 | See the CITATION.cff file or: 38 | 39 | Leverett, É; Rhode, M; Burns, E; Manion, A (2023) Vuln4Cast source code (Version 1.0.0) [Source code]. https://github.com/FIRSTdotorg/Vuln4Cast/ 40 | -------------------------------------------------------------------------------- /Vuln4CastPaper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FIRSTdotorg/Vuln4Cast/3887b443bf12589b058c334052e53a5babc968e5/Vuln4CastPaper.pdf -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | hurst==0.0.5 2 | jq==1.4.1 3 | matplotlib==3.7.1 4 | numpy==1.24.1 5 | pandas==1.5.3 6 | python_dateutil==2.8.2 7 | Requests==2.30.0 8 | scikit_learn==1.2.2 9 | statsmodels==0.14.0 10 | tqdm==4.65.0 11 | --------------------------------------------------------------------------------