From db97281dcaca40d7bfc02e2f769eed5e2c2b4ca4 Mon Sep 17 00:00:00 2001 From: AnatoliiER <70503278+AnatoliiER@users.noreply.github.com> Date: Sun, 20 Sep 2020 16:07:54 +0300 Subject: Update checker.py Added free updates db --- checker.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/checker.py b/checker.py index d4d5222..c1b285e 100644 --- a/checker.py +++ b/checker.py @@ -22,6 +22,7 @@ class VyosDf: self.db = self.client.dfbase self.vulndb = self.db.vulndb self.packages = self.db.packages + self.debtr = self.db.debtr self.debtrack_link = self.config.get('CVEDB', 'debtrack_link') self.MITRE_LOG = self.config.get('LOGS', 'MITRE_LOG') self.CVE_PATTERN = "CVE" @@ -29,6 +30,8 @@ class VyosDf: self.mitre_link = self.config.get('CVEDB', 'mitre_link') self.DEBTRACK_LOG = self.config.get('LOGS', 'DEBTRACK_LOG') self.CVE_for_update = set() + self.debtrack_cve = set() + def logger(self, logname, logrec, type): file = open(logname, type, encoding='utf-8') @@ -48,6 +51,7 @@ class Vuln(VyosDf): self.vulndb.create_index("id", unique=True) self.vulndb.create_index([('_source.affectedSoftware.name', "text"), ('_source.affectedSoftware.version', "text")]) + self.debtr.create_index("id", unique=True) except Exception as e: print("Error! " + str(e)) @@ -75,6 +79,40 @@ class Vuln(VyosDf): self.CVE_for_update = mitrecve - vulncve print(f"The database is missing - {len(self.CVE_for_update)} CVE") + def vuln_update_v2(self): + _cve = list(self.CVE_for_update) + self.CVE_DATA = self.vulners_api.documentList(_cve[:1000], fields=['index', + 'id', + 'score', + 'sort', + 'doc_type', + 'lastseen', + 'references', + 'description', + 'edition', + 'reporter', + 'published', + 'published', + 'title', + 'type', + 'enchantments', + 'score', + 'dependencies', + 'cwe', + 'bulletinFamily', + 'affectedSoftware', + 'cvss2', + 'modified', + 'href', + 'cvss', + 'cpe23'], references=True) + + for key, value in self.CVE_DATA.items(): + try: + self.vulndb.insert_one({"id":key, "_source":value}) + except errors.DuplicateKeyError: + pass + def save_cve_f(self): handle = open(self.FILECVE, "w") handle.write(json.dumps(self.all_cve)) @@ -139,16 +177,15 @@ def help(): You could use commands: 1.) --help 2.) --init-db - This operation is required when you first run the utility. - 3.) --update-db [date1, date2] - get updates of vulnerabilities database from date1 to date2 - for example: - 4.) --update-info - get information about the number of new CBEs, missing in the database. + 3.) --update-vulners-db - get updates of vulnerabilities database (only for trial, professional, etc. Vulners.com accounts) + 4.) --update-db - get updates of vulnerabilities database (Upgrade based on free databases) + 5.) --update-info - get information about the number of new CVEs, missing in the database. Checking is carried out on the basis of MitreCVE db. - 5.) --start [name of file with packages information] - it is something like this: - - accel-ppp/now 1.12.0-71-g4b5561e amd64 [installed,local] - acl/now 2.2.52-2 amd64 [installed,local] - acpi-support-base/now 0.142-6 all [installed,local] + 6.) --start [name of file with packages information] - This is the output of the command: + apt list --installed + it is something like this: + acl/stable,stable,now 2.2.53-4 amd64 [installed,automatic] + acpid/stable,stable,now 1:2.0.31-1 amd64 [installed] """) def init_db(config): @@ -167,6 +204,17 @@ def updatedb(start_dt, end_dt, config): #debupd.pull_debupdates() print("Vulnerabilities database updated successfully") +def updatedb_v2(config): + v = Vuln(config) + print("Starting analyze...") + v.pull_mitre_cve() + print("Сhecking the CVE...") + v.handler_mitre_cve() + print("Start updating databases") + v.vuln_update_v2() + v.handler_mitre_cve() + print("Vulnerabilities database updated successfully") + def update_info(config): v = Vuln(config) print("Starting analyze...") @@ -189,8 +237,10 @@ if __name__ == "__main__": help() elif sys.argv[1] == "--init-db": init_db(cnf) - elif sys.argv[1] == "--update-db": + elif sys.argv[1] == "--update-vulners-db": updatedb(sys.argv[2], sys.argv[3], cnf) + elif sys.argv[1] == "--update-db": + updatedb_v2(cnf) elif sys.argv[1] == "--update-info": update_info(cnf) elif sys.argv[1] == "--start": -- cgit v1.2.3