Exemple #1
0
def test_isVerified(monkeypatch):
    r = ReportWrapper()
    monkeypatch.setattr(r, '_ReportWrapper__getBody', lambda a: a)
    monkeypatch.setattr(r, '_getPublicCommentsByUsername', lambda u: ['Comment 1', 'Comment 2'])
    monkeypatch.setattr(r, 'getState', lambda: "new")
    assert r.isVerified() is False
    monkeypatch.setattr(r, 'getState', lambda: "triaged")
    assert r.isVerified() is True
    monkeypatch.setattr(r, 'getState', lambda: "new")
    monkeypatch.setattr(r, '_getPublicCommentsByUsername',
                        lambda u: ['Comment 1', 'Comment 2', "Message\nMetadata: {\"vulnDomain\": etc..."])
    assert r.isVerified() is True
Exemple #2
0
def process(report: ReportWrapper) -> Optional[VulnTestInfo]:
    """ Process the given report into a VulnTestInfo named tuple """
    # If the user has not yet been prompted for automatic triaging
    if not report.botHasCommented():
        token = AutoTriageUtils.generateToken()
        return VulnTestInfo(reproduced=False,
                            message=constants.initialMessage(token, 'redirect to a domain', 'Open Redirect'),
                            type='Open Redirect',
                            info={})
    elif report.shouldBackoff():
        if not report.hasPostedBackoffComment():
            addFailureToDB(report.getReporterUsername(), report.getReportID())
            return VulnTestInfo(reproduced=False,
                                message=('Automatic verification of vulnerability has failed, Backing off! Falling '
                                         'back to human verification. '),
                                type='Open Redirect',
                                info={})
        else:
            return None
    elif report.isVerified():
        return None
    try:
        if isStructured(report.getLatestActivity()):
            return processStructured(report, token=report.getToken())
        else:
            return processUnstructured(report, token=report.getToken())
    except Exception as e:
        print("Caught exception: %s" % str(e))
        traceback.print_exc()
        print("+" * 80)
        return VulnTestInfo(reproduced=False,
                            message=('Internal error detected! Backing off...'),
                            type='Open Redirect',
                            info={})
Exemple #3
0
def processReport(report: ReportWrapper) -> bool:
    """ Process a report via searching for duplicates and posting comments based off of the confidence levels
          Returns whether or not the report was classified as a duplicate with a high confidence """
    if report.getState() == "new" and not report.hasDuplicateComment(
    ) and not report.isVerified():
        earlierReports = getAllOpenReports(
            report.getReportedTime())  # type: List[ReportWrapper]
        idConfTuples = []  # type: List[Tuple[str, int]]
        matches = []  # type: List[str]
        for earlierReport in earlierReports:
            for module in modules:
                if (module.match(report.getReportBody(),
                                 report.getReportWeakness())
                        and  # type: ignore
                        module.match(earlierReport.getReportBody(),
                                     earlierReport.getReportWeakness())
                    ):  # type: ignore
                    matches.append(earlierReport.getReportID())
            try:
                confidence = int(isDuplicate(earlierReport, report)[0])
            except TypeError:
                confidence = 0
            if confidence == 99:
                AutoTriageUtils.postComment(
                    report.getReportID(),
                    VulnTestInfo(
                        message='Found a duplicate with 99%% confidence: #%s' %
                        earlierReport.getReportID(),
                        info={},
                        reproduced=False,
                        type=''),
                    internal=True)
                if config.DEBUG:
                    print("Detected that %s (%s) is a duplicate of %s (%s)!" %
                          (report.getReportID(), report.getReportTitle(),
                           earlierReport.getReportID(),
                           earlierReport.getReportTitle()))
                return False  # Change to return True to make the bot stop interacting after finding a duplicate
            elif confidence > 50:
                idConfTuples.append((earlierReport.getReportID(), confidence))
        # If you update the phrases here, you must also update them in AutoTriageUtils.ReportWrapper.hasDuplicateComment
        if len(idConfTuples) > 0:

            def idConfToStr(tuple: Tuple) -> str:
                return (
                    'Detected a possible duplicate report with confidence of %s: #%s'
                    % (tuple[1], tuple[0]))

            AutoTriageUtils.postComment(report.getReportID(),
                                        VulnTestInfo(message='\n'.join([
                                            idConfToStr(t)
                                            for t in idConfTuples
                                        ]),
                                                     info={},
                                                     reproduced=False,
                                                     type=''),
                                        internal=True)
            if config.DEBUG:
                print('Found partial matches: %s' % str(idConfTuples))
        if len(matches) > 0 and len(matches) <= 5:
            AutoTriageUtils.postComment(
                report.getReportID(),
                VulnTestInfo(message=(
                    'There are currently %s open reports about this type of '
                    'vulnerability: %s' %
                    (str(len(matches)), ', '.join(['#' + id
                                                   for id in matches]))),
                             info={},
                             reproduced=False,
                             type=''),
                internal=True)
            if config.DEBUG:
                print(
                    'Found %s reports on the same type of vulnerability as %s: %s'
                    % (str(len(matches)), str(report.getReportID()), ', '.join(
                        ['#' + id for id in matches])))
    return False