<commit_before>/*
 *  Copyright (C) 2017  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package net.vdbaan.issuefinder.parser

import groovy.util.logging.Log
import net.vdbaan.issuefinder.model.Finding

import java.util.logging.Level

@Log
class NetsparkerParser extends Parser {
    static String IDENTIFIER = "netsparker"
    static String scanner = "Netsparker"

    NetsparkerParser(content) {
        this.content = content
    }

    static boolean identify(contents) {
        return IDENTIFIER.equalsIgnoreCase(contents.name())
    }


    List<Finding> parse() {
        List<Finding> result = new ArrayList<>()
        content.target.each { scan ->
            String summary = "Target URL: " + scan.url + '\n' + 'Scan time : ' + scan.scantime + '\n'
            result << new Finding([scanner : scanner, ip: 'none', port: 'generic', service: 'none', plugin: 'scaninfo',
                                   severity: Finding.Severity.INFO, summary: summary])
        }

        content.vulnerability.each { vuln ->
            def url = new URL(vuln.url.toString())
            int port = url.port
            String service = url.protocol.toUpperCase()
            if (port == -1) {
                port = service == 'HTTPS' ? 443 : 80
            }
            String plugin = vuln.type
            Finding.Severity severity = calcSeverity('' + vuln.severity)
            String summary = 'URL: ' + vuln.url + '\n'
            summary += 'Severity:' + vuln.severity + ' (' + vuln.certainty + '%)'
            summary += 'Extra Information (' + vuln.extrainformation.info.@name + '):'
            summary += vuln.extrainformation.info + '\n'
            summary += 'Classification:\n' + classification(vuln.classification)
            result << new Finding([scanner : scanner, ip: url.host, port: '' + port, service: service, plugin: plugin,
                                   severity: severity, summary: summary])

        }
        return result
    }

    private Finding.Severity calcSeverity(String risk) {
        Finding.Severity result
        try {
            result = Finding.Severity.valueOf(Finding.Severity, risk.toUpperCase())
        } catch (IllegalArgumentException e) {
            log.log(Level.FINE,'Got an exception',e)
            result = Finding.Severity.INFO
        }
        return result
    }<commit_msg>Changed summary setup for clearer info<commit_after>/*
 *  Copyright (C) 2017  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package net.vdbaan.issuefinder.parser

import groovy.util.logging.Log
import net.vdbaan.issuefinder.model.Finding

import java.util.logging.Level

@Log
class NetsparkerParser extends Parser {
    static String IDENTIFIER = "netsparker"
    static String scanner = "Netsparker"

    NetsparkerParser(content) {
        this.content = content
    }

    static boolean identify(contents) {
        return IDENTIFIER.equalsIgnoreCase(contents.name())
    }


    List<Finding> parse() {
        List<Finding> result = new ArrayList<>()
        content.target.each { scan ->
            String summary = "Target URL: " + scan.url + '\n' + 'Scan time : ' + scan.scantime + '\n'
            result << new Finding([scanner : scanner, ip: 'none', port: 'generic', service: 'none', plugin: 'scaninfo',
                                   severity: Finding.Severity.INFO, summary: summary])
        }

        content.vulnerability.each { vuln ->
            def url = new URL(vuln.url.toString())
            int port = url.port
            String service = url.protocol.toUpperCase()
            if (port == -1) {
                port = service == 'HTTPS' ? 443 : 80
            }
            String plugin = vuln.type
            Finding.Severity severity = calcSeverity('' + vuln.severity)
            String summary = 'URL: ' + vuln.url + '\n'
            summary += 'Severity:' + vuln.severity + ' (' + vuln.certainty + '%)\n'
            summary += 'Classification:' + classification(vuln.classification) +'\n'
            summary += 'Extra Information (' + vuln.extrainformation.info.@name + '):\n'
            summary += vuln.extrainformation.info + '\n'

            result << new Finding([scanner : scanner, ip: url.host, port: '' + port, service: service, plugin: plugin,
                                   severity: severity, summary: summary])

        }
        return result
    }

    private Finding.Severity calcSeverity(String risk) {
        Finding.Severity result
        try {
            result = Finding.Severity.valueOf(Finding.Severity, risk.toUpperCase())
        } catch (IllegalArgumentException e) {
            log.log(Level.FINE,'Got an exception',e)
            result = Finding.Severity.INFO
        }
        return result
    }
{'fraction_non_alphanumeric': 0.1055351783927976, 'fraction_numerical': 0.003667889296432144, 'mean_word_length': 2.3402004454342986, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6001096', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1617, 'n_words': 516}