pwndoc / pwndoc

Pentest Report Generator
https://pwndoc.github.io/pwndoc
MIT License
2.24k stars 420 forks source link

Is there a way to filter repeated data (Ex: Remediation) #413

Open m4konnen opened 1 year ago

m4konnen commented 1 year ago

I was wondering if there is a way to filter repeated content on the generated report.

EX:

Let's assume I registered 2 findings (Same vulnerability, like SQLI ) so the remediation is gonna be the same for both findings. In my report I don't want it to show the same remediation twice. Is there a way I can filter it using a "condition"?

I know this is not programming, but a way to create an array variable would be useful, so I can store on it all the things that is already on the document and make a condition to check if the field is already on the array...

I'm sorry for the bad english, I did my best ;)

Zeecka commented 1 year ago

Multiple findings from a same vulnerability may have different remediation depending of their context. But if we assume that you want to keep the first finding for each vulnerability, the answer is in your title: you need to make a "filter". Since Pwndoc support angular parser, you can create a custom filter.

Here is a filter that keep only 1 finding with the same name:

// Keep only first finding with a given title
expressions.filters.uniqFindings = function (findings) {
    if (!findings) return findings;
    titles = [];
    filtered_findings = [];
    findings.forEach(function (f) {
        if (!(titles.includes(f.title))){
            titles.push(f.title);
            filtered_findings.push(f);
        }
    });
    return filtered_findings;
};

You can put it in report-generator.js under // *** Angular parser filters ***.

You can then use your filter like this:

{#findings | uniqFindings }
    {#remediation}
        {@text | convertHTML}
        {#images}
        {%image}
        Image – {caption}
        {/images}
    {/remediation}
{/}

I integrated this filter on pwndoc-ng, see related PR.