{ "cells": [ { "cell_type": "markdown", "id": "b3e3ebf1-3bba-41b2-9b9f-70bb80a9ad50", "metadata": { "tags": [] }, "source": [ "# CPE Data" ] }, { "cell_type": "code", "execution_count": 1, "id": "stuffed-appearance", "metadata": { "execution": { "iopub.execute_input": "2024-06-16T12:28:38.807863Z", "iopub.status.busy": "2024-06-16T12:28:38.807702Z", "iopub.status.idle": "2024-06-16T12:28:39.340467Z", "shell.execute_reply": "2024-06-16T12:28:39.339858Z" }, "tags": [ "remove-cell" ] }, "outputs": [ { "data": { "text/html": [ "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import glob\n", "import logging\n", "import json\n", "import os\n", "import pandas as pd\n", "import warnings\n", "from itables import init_notebook_mode, show\n", "import itables.options as opt\n", "\n", "opt.dom = \"tpir\"\n", "opt.style = \"table-layout:auto;width:auto\"\n", "init_notebook_mode(all_interactive=True, connected=True)\n", "\n", "logging.getLogger('matplotlib.font_manager').disabled = True\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "inner-count", "metadata": { "execution": { "iopub.execute_input": "2024-06-16T12:28:39.342773Z", "iopub.status.busy": "2024-06-16T12:28:39.342453Z", "iopub.status.idle": "2024-06-16T12:29:14.436181Z", "shell.execute_reply": "2024-06-16T12:29:14.435531Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "row_accumulator = []\n", "\n", "for filename in glob.glob('nvdcve-1.1-*.json'):\n", " with open(filename, 'r', encoding='utf-8') as f:\n", " nvd_data = json.load(f)\n", " for cves in nvd_data['CVE_Items']:\n", " if cves['configurations']['nodes'] != []:\n", " if \"children\" in cves['configurations']['nodes'][0]:\n", " for j in range(len(cves['configurations']['nodes'][0]['children'])):\n", " for cpe in cves['configurations']['nodes'][0]['children'][j]['cpe_match']:\n", " if cpe['vulnerable'] == True:\n", " cve = cves['cve']['CVE_data_meta']['ID']\n", " cpe_string = cpe['cpe23Uri']\n", " try:\n", " end = cpe['versionEndExcluding']\n", " except: \n", " end = 'None'\n", " try:\n", " end2 = cpe['versionEndIncluding']\n", " except: \n", " end2 = 'None' \n", " try:\n", " start = cpe['versionStartExcluding']\n", " except: \n", " start = 'None'\n", " try:\n", " start2 = cpe['versionStartIncluding']\n", " except: \n", " start2 = 'None' \n", " new_row = { \n", " 'CVE': cve,\n", " 'CPE' : cpe_string,\n", " 'StartI' : start,\n", " 'StartE' : start2,\n", " 'EndI' : end,\n", " 'EndE' : end2 \n", " }\n", " row_accumulator.append(new_row)\n", " \n", "\n", "\n", "nvd = pd.DataFrame(row_accumulator) " ] }, { "cell_type": "markdown", "id": "833383cc-8ef0-4490-acdc-98671760b1a3", "metadata": {}, "source": [ "## CVEs With Most CPE" ] }, { "cell_type": "code", "execution_count": 3, "id": "temporal-disposal", "metadata": { "execution": { "iopub.execute_input": "2024-06-16T12:29:14.438935Z", "iopub.status.busy": "2024-06-16T12:29:14.438749Z", "iopub.status.idle": "2024-06-16T12:29:14.464419Z", "shell.execute_reply": "2024-06-16T12:29:14.463953Z" }, "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "
count
CVE
\n", "\n", "
\n", "Loading ITables v2.1.1 from the internet...\n", "(need help?)
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "nvd_cve = nvd['CVE'].value_counts().head(50)\n", "show(nvd_cve, scrollY=\"400px\", scrollCollapse=True, paging=False)" ] }, { "cell_type": "markdown", "id": "69850125-3841-48cd-a36d-1cf998c68272", "metadata": {}, "source": [ "## Most Common CPEs" ] }, { "cell_type": "code", "execution_count": 4, "id": "celtic-employer", "metadata": { "execution": { "iopub.execute_input": "2024-06-16T12:29:14.466632Z", "iopub.status.busy": "2024-06-16T12:29:14.466305Z", "iopub.status.idle": "2024-06-16T12:29:14.498131Z", "shell.execute_reply": "2024-06-16T12:29:14.497691Z" }, "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "
count
CPE
\n", "\n", "
\n", "Loading ITables v2.1.1 from the internet...\n", "(need help?)
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "nvd_cpe = nvd['CPE'].value_counts().head(50)\n", "show(nvd_cpe, scrollY=\"400px\", scrollCollapse=True, paging=False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.6 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" }, "vscode": { "interpreter": { "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" } } }, "nbformat": 4, "nbformat_minor": 5 }