Home > Enterprise >  iterate over large JSON file using python and create a reduced JSON output only with specific values
iterate over large JSON file using python and create a reduced JSON output only with specific values

Time:10-31

1: I have to iterate over this JSON using PYTHON.

2: loop to find java (only) vulnerabilities.

3: order (descending) the results by cvss3 severity score (base score), then by CVE_ID.

4: Save filtered results to new output file.

I am in over my head. Just started programming and dont even know where to start. Searched the internet for hours and tried different things, but couldnt figure it out. Please help!

I have so far:

import json

with open('nvdcve-1.1-2022.json', encoding='utf8') as cve_file: data = json.load(cve_file)

link to full JSON: https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2022.json.gz

Sample of full JSON:

{
  "CVE_data_type" : "CVE",
  "CVE_data_format" : "MITRE",
  "CVE_data_version" : "4.0",
  "CVE_data_numberOfCVEs" : "15872",
  "CVE_data_timestamp" : "2022-10-30T07:00Z",
  "CVE_Items" : [ {
    "cve" : {
      "data_type" : "CVE",
      "data_format" : "MITRE",
      "data_version" : "4.0",
      "CVE_data_meta" : {
        "ID" : "CVE-2022-0001",
        "ASSIGNER" : "[email protected]"
      },
      "problemtype" : {
        "problemtype_data" : [ {
          "description" : [ {
            "lang" : "en",
            "value" : "NVD-CWE-noinfo"
          } ]
        } ]
      },
      "references" : {
        "reference_data" : [ {
          "url" : "https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00598.html",
          "name" : "https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00598.html",
          "refsource" : "MISC",
          "tags" : [ "Vendor Advisory" ]
        }, {
          "url" : "http://www.openwall.com/lists/oss-security/2022/03/18/2",
          "name" : "[oss-security] 20220318 Xen Security Advisory 398 v2 - Multiple speculative security issues",
          "refsource" : "MLIST",
          "tags" : [ "Mailing List", "Third Party Advisory" ]
        }, {
          "url" : "https://www.oracle.com/security-alerts/cpujul2022.html",
          "name" : "N/A",
          "refsource" : "N/A",
          "tags" : [ "Patch", "Third Party Advisory" ]
        }, {
          "url" : "https://security.netapp.com/advisory/ntap-20220818-0004/",
          "name" : "https://security.netapp.com/advisory/ntap-20220818-0004/",
          "refsource" : "CONFIRM",
          "tags" : [ "Third Party Advisory" ]
        } ]
      },
      "description" : {
        "description_data" : [ {
          "lang" : "en",
          "value" : "Non-transparent sharing of branch predictor selectors between contexts in some Intel(R) Processors may allow an authorized user to potentially enable information disclosure via local access."
        } ]
      }
    },
    "configurations" : {
      "CVE_data_version" : "4.0",
      "nodes" : [ {
        "operator" : "OR",
        "children" : [ ],
        "cpe_match" : [ {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:celeron_j4005:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:celeron_n4100:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:celeron_n4000:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:celeron_j4105:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:pentium_silver_j5005:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:pentium_silver_n5000:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i3-10110u:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i3-1005g1:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-10210u:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-10310y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-10210y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-1035g4:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-1035g7:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-1035g1:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-9300h:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-9400h:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-9400:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-9600k:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-8265u:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i5-8200y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-10510u:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-10510y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-10710u:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-1065g7:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-9850h:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-9700k:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-8565u:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-8500y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_m3-8100y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i9-7960x:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i9-7940x:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i9-7920x:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i9-7900x:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-7820x:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:core_i7-7800x:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_9282:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_9242:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_9222:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_9221:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8280l:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8280:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8276l:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8276:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8270:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8268:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8260y:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8260l:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8260:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8256:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_platinum_8253:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6262v:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6254:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6252n:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6252:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6248:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6246:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6244:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6242:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6240:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6238t:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6238l:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6238:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:h:intel:xeon_gold_6234:-:*:*:*:*:*:*:*",
          "cpe_name" : [ ]

further down in the JSON file, there are base scores listed. I need to sort the results from the previous steps in descending order according to the base scores listed below:

},
"impact" : {
  "baseMetricV3" : {
    "cvssV3" : {
      "version" : "3.1",
      "vectorString" : "CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
      "attackVector" : "ADJACENT_NETWORK",
      "attackComplexity" : "LOW",
      "privilegesRequired" : "NONE",
      "userInteraction" : "NONE",
      "scope" : "UNCHANGED",
      "confidentialityImpact" : "NONE",
      "integrityImpact" : "NONE",
      "availabilityImpact" : "HIGH",
      "baseScore" : 6.5,
      "baseSeverity" : "MEDIUM"
    },
    "exploitabilityScore" : 2.8,
    "impactScore" : 3.6
  },
  "baseMetricV2" : {
    "cvssV2" : {
      "version" : "2.0",
      "vectorString" : "AV:A/AC:L/Au:N/C:N/I:N/A:P",
      "accessVector" : "ADJACENT_NETWORK",
      "accessComplexity" : "LOW",
      "authentication" : "NONE",
      "confidentialityImpact" : "NONE",
      "integrityImpact" : "NONE",
      "availabilityImpact" : "PARTIAL",
      "baseScore" : 3.3
    },
    "severity" : "LOW",
    "exploitabilityScore" : 6.5,
    "impactScore" : 2.9,
    "acInsufInfo" : false,
    "obtainAllPrivilege" : false,
    "obtainUserPrivilege" : false,
    "obtainOtherPrivilege" : false,
    "userInteractionRequired" : false
  }
},
"publishedDate" : "2022-06-20T06:15Z",
"lastModifiedDate" : "2022-07-05T20:40Z"

}, { "cve" : { "data_type" : "CVE", "data_format" : "MITRE", "data_version" : "4.0", "CVE_data_meta" : { "ID" : "CVE-2022-21743", "ASSIGNER" : "[email protected]" }, "problemtype" : { "problemtype_data" : [ { "description" : [ { "lang" : "en", "value" : "CWE-190" } ] } ] }, "references" : { "reference_data" : [ { "url" : "https://corp.mediatek.com/product-security-bulletin/May-2022", "name" : "https://corp.mediatek.com/product-security-bulletin/May-2022", "refsource" : "MISC", "tags" : [ "Vendor Advisory" ] } ] }, "description" : { "description_data" : [ { "lang" : "en", "value" : "In ion, there is a possible use after free due to an integer overflow. This could lead to local escalation of privilege with no additional execution privileges needed. User interaction is not needed for exploitation. Patch ID: ALPS06371108; Issue ID: ALPS06371108." } ] } }, "configurations" : { "CVE_data_version" : "4.0", "nodes" : [ { "operator" : "AND", "children" : [ { "operator" : "OR", "children" : [ ], "cpe_match" : [ { "vulnerable" : true, "cpe23Uri" : "cpe:2.3:o:google:android:9.0:::::::", "cpe_name" : [ ] }, { "vulnerable" : true, "cpe23Uri" : "cpe:2.3:o:google:android:10.0:::::::", "cpe_name" : [ ] }, { "vulnerable" : true, "cpe23Uri" : "cpe:2.3:o:google:android:11.0:::::::", "cpe_name" : [ ] }, { "vulnerable" : true, "cpe23Uri" : "cpe:2.3:o:google:android:12.0:::::::", "cpe_name" : [ ] } ] }, { "operator" : "OR", "children" : [ ], "cpe_match" : [ { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6757:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6785:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6779:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6768:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6769:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6761:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6765:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6762:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6771:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6580:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6735:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6737:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6739:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6750:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6750s:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6753:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6757c:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6757cd:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6757ch:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6763:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6797:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6833:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6853:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6853t:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6873:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6875:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6877:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6781:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6883:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6885:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6889:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt6893:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8167:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8168:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8173:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8185:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8321:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8362a:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8365:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8385:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8666:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8675:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8695:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8696:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8765:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8766:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8768:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8786:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8788:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8789:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8791:-:::::::", "cpe_name" : [ ] }, { "vulnerable" : false, "cpe23Uri" : "cpe:2.3:h:mediatek:mt8797:-:::::::", "cpe_name" : [ ] } ] } ], "cpe_match" : [ ] } ] }, "impact" : { "baseMetricV3" : { "cvssV3" : { "version" : "3.1", "vectorString" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H", "attackVector" : "LOCAL", "attackComplexity" : "LOW", "privilegesRequired" : "LOW", "userInteraction" : "NONE", "scope" : "UNCHANGED", "confidentialityImpact" : "HIGH", "integrityImpact" : "HIGH", "availabilityImpact" : "HIGH", "baseScore" : 7.8, "baseSeverity" : "HIGH" }, "exploitabilityScore" : 1.8, "impactScore" : 5.9 }, "baseMetricV2" : { "cvssV2" : { "version" : "2.0", "vectorString" : "AV:L/AC:L/Au:N/C:P/I:P/A:P", "accessVector" : "LOCAL", "accessComplexity" : "LOW", "authentication" : "NONE", "confidentialityImpact" : "PARTIAL", "integrityImpact" : "PARTIAL", "availabilityImpact" : "PARTIAL", "baseScore" : 4.6 }, "severity" : "MEDIUM", "exploitabilityScore" : 3.9, "impactScore" : 6.4, "acInsufInfo" : false, "obtainAllPrivilege" : false, "obtainUserPrivilege" : false, "obtainOtherPrivilege" : false, "userInteractionRequired" : false } }, "publishedDate" : "2022-05-03T21:15Z", "lastModifiedDate" : "2022-05-12T02:50Z" }, {

CodePudding user response:

This solution should solve your initial problem (remove configurations with 'vulnerable:false'). I used the sample json data you provided in the question.

import json

with open('data.json','r') as f:
    data = json.load(f)

nodes = data.get('CVE_Items')[0].get('configurations').get('nodes')[0].get('cpe_match')

for index,node in enumerate(nodes):
    if not node.get('vulnerable'):
        nodes.pop(index)

with open('new_data.json','w') as f:
    f.write(json.dumps(data))

CodePudding user response:

Here is a way that you could read in the data, clean it (remove the vulnerabilities with false), and then download it as a new file.

import json

with open('nvdcve-1.1-2022.json', 'r') as file: # read in the file and load it as a json format (similar to python dictionaries)
    dict_data = json.load(file)

for CVE_Item in dict_data['CVE_Items']:
    for node in CVE_Item['configurations']['nodes']:
        # https://stackoverflow.com/questions/1207406/how-to-remove-items-from-a-list-while-iterating
        node['cpe_match'][:] = [item for item in node['cpe_match'] if item['vulnerable']] # removing items while iterating through

with open('cleaned_nvdcve-1.1-2022.json','w') as f: # write the file to the current working directory.
    f.write(json.dumps(dict_data))

As for ordering it is unsure what you are ordering by, you could set up a sort() with a function that can order based on the criteria that you want, though unsure what those criteria are as your question is vague with that part.

  • Related