コード例 #1
0
def addcve():
    errstatus = "Generic error"
    r = request.get_json()
    cve = r['cve_id']
    notes = r['cve_notes']
    # Match CVE-1990-0000 to CVE-2999-##### (> 4 digits), to ensure at least a little sanity
    pattern = re.compile("^(CVE|LVT)-(199\d|2\d{3})-(\d{4}|[1-9]\d{4,})$")

    if not cve:
        errstatus = "No CVE specified!"
    elif not pattern.match(cve):
        errstatus = "CVE '" + cve + "' is invalid!"
    elif CVE.objects(cve_name=cve):
        errstatus = cve + " already exists!"
    elif not notes or len(notes) < 10:
        errstatus = "Notes have to be at least 10 characters!"
    else:
        CVE(cve_name=cve, notes=notes).save()
        cve_id = CVE.objects.get(cve_name=cve)['id']
        for k in Kernel.objects():
            Patches(cve=cve_id,
                    kernel=k.id,
                    status=Status.objects.get(short_id=1)['id']).save()
            k.progress = utils.getProgress(k.id)
            k.save()
        # add a mitre link for non-internal CVEs
        if not cve.startswith("LVT"):
            mitrelink = 'https://cve.mitre.org/cgi-bin/cvename.cgi?name='
            Links(cve_id=cve_id, link=mitrelink + cve).save()
        errstatus = "success"

    return jsonify({'error': errstatus})
コード例 #2
0
def update():
    r = request.get_json()
    k = r['kernel_id']
    c = r['cve_id']
    s = r['status_id']

    Patches.objects(kernel=k,
                    cve=c).update(status=Status.objects.get(short_id=s).id)
    progress = utils.getProgress(k)
    Kernel.objects(id=k).update(progress=progress)
    return jsonify({'error': 'success', 'progress': progress})
コード例 #3
0
def resetcve(cvename=None):
    if cvename and CVE.objects(cve_name=cvename):
        cve_id = CVE.objects.get(cve_name=cvename).id
        status_id = Status.objects.get(short_id=6).id
        writeLog("cve_reset", cve_id, cvename)
        for k in Kernel.objects():
            Patches.objects(cve=cve_id, kernel=k.id).update(status=status_id)
            k.progress = utils.getProgress(k.id)
            k.save()
        return render_template('resetcve.html', cve_name=cvename)
    else:
        errmsg = "CVE '{}' is invalid or doesn't exist!"
        msg = errmsg.format(cvename)
        return error(msg=msg)
コード例 #4
0
def update():
    r = request.get_json()
    k = r['kernel_id']
    c = r['cve_id']
    s = r['status_id']

    old_status = Status.objects.get(
        id=Patches.objects.get(kernel=k, cve=c)['status'])
    status = Status.objects.get(short_id=s)
    Patches.objects(kernel=k, cve=c).update(status=status.id)
    progress = utils.getProgress(k)
    Kernel.objects(id=k).update(progress=progress)
    cveName = CVE.objects.get(id=c)['cve_name']
    msg = "{}, From: '{}', To: '{}'"
    logStr = msg.format(cveName, old_status.text, status.text)
    writeLog("patched", k, logStr)
    return jsonify({'error': 'success', 'progress': progress})
コード例 #5
0
def import_statuses():
    errstatus = "Generic error"
    errorLog = None
    r = request.get_json()
    from_kernel_repo = r['from_kernel']
    to_kernel_repo = r['to_kernel']
    override_all = r['override_all']

    try:
        from_kernel = Kernel.objects.get(repo_name=from_kernel_repo).id
        to_kernel = Kernel.objects.get(repo_name=to_kernel_repo).id
    except:
        errstatus = "Invalid kernels!"

    statuses = {s.id: s.short_id for s in Status.objects()}

    for patch in Patches.objects(kernel=from_kernel):
        patchMissing = False

        try:
            target_patch = Patches.objects.get(kernel=to_kernel, cve=patch.cve)
        except (MultipleObjectsReturned, DoesNotExist) as e:
            if type(e).__name__ == "MultipleObjectsReturned":
                # Somehow, more than 1 patch object exists. Remove all and recreate one
                Patches.objects(kernel=to_kernel, cve=patch.cve).delete()
                msg = "Too many patch objects for {} were found, fixed"
            else:
                msg = "Patch object for {} was missing, fixed"
            cve_name = CVE.objects.get(id=patch.cve)['cve_name']
            logStr = msg.format(cve_name)
            writeLog("fixed", to_kernel, logStr)
            patchMissing = True

        if patchMissing:
            Patches(cve=patch.cve, kernel=to_kernel,
                    status=patch.status).save()
        elif override_all or statuses[target_patch.status] == 1:
            target_patch.update(status=patch.status)

    progress = utils.getProgress(to_kernel)
    Kernel.objects(id=to_kernel).update(progress=progress)
    writeLog("imported", to_kernel, to_kernel_repo)
    errstatus = "success"

    return jsonify({'error': errstatus})
コード例 #6
0
def update_progress():
    for k in Kernel.objects():
        k.progress = utils.getProgress(k.id)
        k.save()