示例#1
0
    def do_report(self, package):
        try:
            filename = os.path.basename(database[package]["location_href"])
        except:
            print ("package not found!")
            return

        destination = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data", ".cache", filename)
        url = BASE_URL + database[package]["location_href"]
        if not os.path.exists(destination):
            print (url, "=>", destination)
            fetch(url, destination)
        data = analyze(destination, show_errors=False, opformat="csv")
        lines = data.split("\n")
        build = lines[0].split(",")[1]

        if pkg and package.startswith(pkg):
            package = pkg
            print "\n!!!! Setting package to %s !!!!\n\n\n" % pkg
        elif pkg:
            print "%s is too different from %s" % (pkg, package)
            return

        bug_summary = "%s package should be built with PIE flags" % package
        bug_data = bug_template % (package, build, build, data)
        # cmd = "bugzilla --bugzilla=https://partner-bugzilla.redhat.com/xmlrpc.cgi new --product Fedora " \
        cmd = "bugzilla new --product Fedora " "--component '%s' --version '19' --summary '%s' --comment '%s'" % (
            package,
            bug_summary,
            bug_data,
        )
        print cmd
        p = subprocess.Popen(cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        o, e = p.communicate()
        print o, e
示例#2
0
def scan():
    site = request.form['address']
    site = re.sub(r'^https?://', '', site)
    rescan = request.form['rescan']
    if rescan == '1' or not collection.find_one({'site': site}):
        res = analyze(site)
        if isinstance(res, ErrorResult):
            return render_template('error.html', error=res.error_msg)
        results_id = save_results(res)
        return redirect(f'/results/{results_id}')
    else:
        return redirect(f'/formerScans?q={site}')
示例#3
0
def process(id):
    stuff = majdoor.fetch_koji_build(id)
    if stuff and len(stuff) == 3:
        package, nvr, urls = stuff
    else:
        print "??? majdoor skipped / failed", id
        return "OK"

    if not urls:
        return
    for arch, url in urls:
        basename = url.split('/')[-1]
        path = os.path.join("cache", nvr, basename)

        if path.endswith(".rpm") and not \
                path.endswith(".src.rpm") and \
                not "-debuginfo-" in path:
            output = scanner.analyze(path)
            print output

            connection = Connection()
            db = connection.test_database
            analysis = db.analysis
            analysis.insert(json.loads(output))
            connection.close()

    # do rpmgrill stuff, spawn as we don't know how rpmgrill affets our env.
    basepath = os.path.join(os.path.realpath("cache"), nvr)
    print "Running rpmgrill on", basepath
    p = subprocess.Popen("./invoke_rpmgrill.sh %s" % basepath,
                         stderr=subprocess.PIPE,
                         shell=True)
    _, err = p.communicate()

    output = os.path.join(os.path.realpath("cache"), nvr, "rpmgrill.json")
    if not os.path.exists(output):
        print "!!! rpmgrill failed for", basepath
        print err
    else:
        with open(output) as f:
            data = f.read()
        # we store rpmgrill.json in a database
        connection = Connection()
        db = connection.test_database
        rpmgrill = db.rpmgrill
        entry = {"nvr": nvr, "output": data, "package": package}
        rpmgrill.insert(entry)
        print "!!!", err

    return "OK"
示例#4
0
    def do_analyze(self, package):
        try:
            filename = os.path.basename(database[package]["location_href"])
        except:
            print ("package not found!")
            return

        destination = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data", ".cache", filename)
        url = BASE_URL + database[package]["location_href"]
        if not os.path.exists(destination):
            print (url, "=>", destination)
            fetch(url, destination)
        data = json.loads(analyze(destination, show_errors=False))
        print json.dumps(data, sort_keys=True, indent=4, separators=(",", ": "))
示例#5
0
文件: tasks.py 项目: 7h3rAm/checksec
def process(id):
    stuff = majdoor.fetch_koji_build(id)
    if stuff and len(stuff) == 3:
        package, nvr, urls = stuff
    else:
        print "??? majdoor skipped / failed", id
        return "OK"

    if not urls:
        return
    for arch, url in urls:
        basename = url.split('/')[-1]
        path = os.path.join("cache", nvr, basename)

        if path.endswith(".rpm") and not \
                path.endswith(".src.rpm") and \
                not "-debuginfo-" in path:
            output = scanner.analyze(path)
            print output

            connection = Connection()
            db = connection.test_database
            analysis = db.analysis
            analysis.insert(json.loads(output))
            connection.close()

    # do rpmgrill stuff, spawn as we don't know how rpmgrill affets our env.
    basepath = os.path.join(os.path.realpath("cache"), nvr)
    print "Running rpmgrill on", basepath
    p = subprocess.Popen("./invoke_rpmgrill.sh %s" % basepath,
            stderr=subprocess.PIPE, shell=True)
    _, err = p.communicate()

    output = os.path.join(os.path.realpath("cache"), nvr, "rpmgrill.json")
    if not os.path.exists(output):
        print "!!! rpmgrill failed for", basepath
        print err
    else:
        with open(output) as f:
            data = f.read()
        # we store rpmgrill.json in a database
        connection = Connection()
        db = connection.test_database
        rpmgrill = db.rpmgrill
        entry =  { "nvr" : nvr, "output" : data, "package" : package }
        rpmgrill.insert(entry)
        print "!!!", err

    return "OK"
示例#6
0
    def do_analyze(self, package):
        try:
            filename = os.path.basename(database[package]["location_href"])
        except:
            print("package not found!")
            return

        destination = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   "data", ".cache", filename)
        url = BASE_URL + database[package]["location_href"]
        if not os.path.exists(destination):
            print(url, "=>", destination)
            fetch(url, destination)
        data = json.loads(analyze(destination, show_errors=False))
        print json.dumps(data, sort_keys=True, indent=4,
                         separators=(',', ': '))
示例#7
0
    def do_report(self, package):
        try:
            filename = os.path.basename(database[package]["location_href"])
        except:
            print("package not found!")
            return

        destination = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   "data", ".cache", filename)
        url = BASE_URL + database[package]["location_href"]
        if not os.path.exists(destination):
            print(url, "=>", destination)
            fetch(url, destination)
        data = analyze(destination, show_errors=False, opformat="csv")
        lines = data.split('\n')
        build = lines[0].split(',')[1]

        if pkg and package.startswith(pkg):
            package = pkg
            print "\n!!!! Setting package to %s !!!!\n\n\n" % pkg
        elif pkg:
            print "%s is too different from %s" % (pkg, package)
            return

        bug_summary = "%s package should be built with PIE flags" % package
        bug_data = bug_template % (package, build, build, data)
        # cmd = "bugzilla --bugzilla=https://partner-bugzilla.redhat.com/xmlrpc.cgi new --product Fedora " \
        cmd = "bugzilla new --product Fedora " \
                "--component '%s' --version '19' --summary '%s' --comment '%s'" % \
                (package, bug_summary, bug_data)
        print cmd
        p = subprocess.Popen(cmd,
                             shell=True,
                             stdin=None,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        o, e = p.communicate()
        print o, e