Commit 6b30d4e2 authored by PidgeyL's avatar PidgeyL
Browse files

update

parents e97b4ba2 d9b82c44
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import re
import datetime
import configparser
import urllib.parse

import urllib.request as req

class Configuration():
    ConfigParser = configparser.ConfigParser()
@@ -50,7 +50,8 @@ class Configuration():
               'Indexdir': './indexdir',
               'includeCapec': True,      'includeD2Sec': True,
               'includeVFeed': True,      'includeVendor': True,
               'includeCWE': True
               'includeCWE': True,
               'http_proxy' : ''
               }

    @classmethod
@@ -282,3 +283,18 @@ class Configuration():
            return False
        else:
            return True

    # Http Proxy
    @classmethod
    def getProxy(cls):
        return cls.readSetting("Proxy", "http", cls.default['http_proxy'])

    @classmethod
    def getFile(cls, getfile):
        if cls.getProxy():
            proxy = req.ProxyHandler({'http': cls.getProxy(), 'https': cls.getProxy()})
            auth = req.HTTPBasicAuthHandler()
            opener = req.build_opener(proxy, auth, req.HTTPHandler)
            req.install_opener(opener)
        return req.urlopen(getfile)
+12 −10
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ sys.path.append(os.path.join(runPath, ".."))

import argparse
import datetime
from urllib.request import urlopen
from xml.sax import make_parser
from xml.sax.handler import ContentHandler

@@ -185,12 +184,6 @@ class CVEHandler(ContentHandler):
            self.inPUBElem = 0
            self.cves[-1]['Modified'] = self.PUB

def getFile(getfile):
    try:
        return urlopen(Configuration.getCVEDict() + getfile)
    except:
        sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getCVEDict() + getfile))

if __name__ == '__main__':
    # connect to the DB.
    db = Configuration.getMongoConnection()
@@ -203,7 +196,10 @@ if __name__ == '__main__':
    if args.u:
        # get the 'modified' file
        getfile = file_prefix + file_mod + file_suffix
        f = getFile(getfile)
        try:
            f = Configuration.getFile(Configuration.getCVEDict() + getfile)
        except:
            sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getCVEDict() + getfile))
        i = info.find_one({'db': 'cve'})
        if i is not None:
            if f.headers['last-modified'] == i['last-modified']:
@@ -232,7 +228,10 @@ if __name__ == '__main__':
                collection.insert(item)
        # get the 'recent' file
        getfile = file_prefix + file_rec + file_suffix
        f = getFile(getfile)
        try:
            f = Configuration.getFile(Configuration.getCVEDict() + getfile)
        except:
            sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getCVEDict() + getfile))
        parser = make_parser()
        ch = CVEHandler()
        parser.setContentHandler(ch)
@@ -271,7 +270,10 @@ if __name__ == '__main__':
                ch = CVEHandler()
                parser.setContentHandler(ch)
                getfile = file_prefix + str(x) + file_suffix
                f = getFile(getfile)
                try:
                    f = Configuration.getFile(Configuration.getCVEDict() + getfile)
                except:
                    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getCVEDict() + getfile))
                parser.parse(f)
                if args.v:
                    for item in ch.cves:
+2 −3
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ sys.path.append(os.path.join(runPath, ".."))

from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from urllib.request import urlopen

from lib.ProgressBar import progressbar
from lib.Config import Configuration
@@ -143,7 +142,7 @@ class CapecHandler(ContentHandler):
        if name == 'capec:CWE_ID':
            self.CWE_ID_tag = False
        if name == 'capec:Attack_Pattern':
            self.capec.append({'name': self.name, 'id': self.id, 'summary': self.Summary, 'prerequisites': self.Attack_Prerequisite, 'solutions': self.Solution_or_Mitigation, 'related_weakness': self.Related_Weakness})
            self.capec.append({'name': self.name, 'id': self.id, 'summary': '\n'.join(self.Summary), 'prerequisites': '\n'.join(self.Attack_Prerequisite), 'solutions': '\n'.join(self.Solution_or_Mitigation), 'related_weakness': self.Related_Weakness})
            self.Summary = []
            self.Attack_Prerequisite = []
            self.Solution_or_Mitigation = []
@@ -168,7 +167,7 @@ ch = CapecHandler()
parser.setContentHandler(ch)
# check modification date
try:
    f = urlopen(capecurl)
    f = Configuration.getFile(capecurl)
except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(capecurl))
i = info.find_one({'db': 'capec'})
+1 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ sys.path.append(os.path.join(runPath, ".."))

from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from urllib.request import urlopen

from lib.ProgressBar import progressbar
from lib.Toolkit import toStringFormattedCPE
@@ -82,7 +81,7 @@ ch = CPEHandler()
parser.setContentHandler(ch)
# check modification date
try:
    f = urlopen(cpedict)
    f = Configuration.getFile(cpedict)
except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(cpedict))
i = info.find_one({'db': 'cpe'})
+1 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ sys.path.append(os.path.join(runPath, ".."))

from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from urllib.request import urlopen
import argparse
import zipfile
import tempfile
@@ -84,7 +83,7 @@ ch = CWEHandler()
parser.setContentHandler(ch)
# check modification date
try:
    f = urlopen(cwedict)
    f = Configuration.getFile(cwedict)
except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(cwedict))
lastmodified = f.headers['last-modified']
Loading