[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalid/inaccurate json report #808

Merged
merged 7 commits into from
Dec 29, 2023
Merged

Conversation

HuntClauss
Copy link
Contributor
@HuntClauss HuntClauss commented Dec 16, 2023

Base

Problems

  • encode function from JSON:PP adds own quotes to encoded text. Because of that "msg" field was encoded incorrectly ("msg": ""[some info]"")
  • $uri was never set which resulted in empty value in the report
  • in json_item commas was blindly added after every item and then removed in json_host_end using seek(...). If there were no vulnerabilities found, instead of comma, '[' would be removed.
  • if the specified target does not exist, json_host_start is not executed, despite that json_host_end is. Because of that report ends up with invalid json ]}
  • for some reason report_host_end was called before report_host_start, thus resulting in weird behavior of json report plugin
  • json report was not usable with multiple hosts specified

@sullo
Copy link
Owner
sullo commented Dec 28, 2023

When control-c cancels a scan, it should terminate reports and call report_end. When testing on the main branch a terminated scan writes the json file as it should. However, when terminating with this branch it does not. I'm not immediately spotting why.

@HuntClauss
Copy link
Contributor Author

I assume that you mean report_close, not report_end?

If so, this is strange because I am not experiencing anything like this on any branch. When I press Control + C, the json is saved normally, as usual.

@HuntClauss
Copy link
Contributor Author

If I am not mistaken safe_quit is responsible for graceful shutdown and it invokes report_host_end, report_summary and report_close in this order. I did not change logic within json_close (equivalent to report_close) - only string content (maybe lack of newline is a problem, but I don't see why?).

If you can pinpoint a commit that breaks graceful shutdown I could look into it

@sullo
Copy link
Owner
sullo commented Dec 29, 2023

The mistake was on my end and an error I didn't notice.

@sullo sullo merged commit 8647ed6 into sullo:master Dec 29, 2023
@moxli
Copy link
Contributor
moxli commented Jan 3, 2024

@sullo @HuntClauss is this another breaking change to the JSON report format?
If yes, is there another release planned for this?
I would like to get the Nikto parser in DefectDojo updated for the JSON format from 2.5.0 and wonder if this will break it again.

@sullo
Copy link
Owner
sullo commented Jan 4, 2024

@sullo @HuntClauss is this another breaking change to the JSON report format?

I don't believe so. This was fixing some bugs that made it invalid JSON and cleaning up how it operates to ensure the JSON is closed correctly. For example, the message may have had stray unquoted characters.

@moxli
Copy link
Contributor
moxli commented Jan 4, 2024

@sullo Earlier I run two scans, one using the master branch and one using the 2.5.0 release tag.

The report from 2.5.0 turned out to be invalid as expected (thats what this fix is for?):

{"host":"REDACTED","ip":"REDACTED","port":"443","banner":"Apache","vulnerabilities":[{"id": "999103","references": "https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/","method":"GET","url":"","msg":""/: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type.""},{"id": "999992","references": "https://en.wikipedia.org/wiki/Wildcard_certificate","method":"GET","url":"","msg":""Server is using a wildcard certificate: REDACTED.""}]}

The report form the master branch was valid:

[
  {
    "host": "REDACTED",
    "ip": "REDACTED",
    "port": "443",
    "banner": "",
    "vulnerabilities": [
      {
        "id": "999992",
        "references": "https://en.wikipedia.org/wiki/Wildcard_certificate",
        "method": "GET",
        "url": "/",
        "msg": "Server is using a wildcard certificate: REDACTED."
      }
    ]
  }
]

However, notice how the master branch one is an array at the top level, where the other one is a single object?

@sullo
Copy link
Owner
sullo commented Jan 9, 2024

@HuntClauss I think that was to fix the multiple host issue--can you confirm?

I'm thinking more the report should just be done using a perl json library to ensure consistency and accuracy... but that will be a release if done.

@HuntClauss
Copy link
Contributor Author

@sullo Well, primarily my goal was to fix json report for one host only, because I didn't even know that nikto can scan more than one. But during implementation of this and couple other fixes I found out that it support multiple hosts so I changed json format accordingly.

@moxli
Copy link
Contributor
moxli commented Jan 10, 2024

@HuntClauss Thank you for your reply and the fixes :)
@sullo Currently this leaves me in an unclear state:

  • 2.5.0 branch: doesn't work because it misses this fix Fix nikto json plugin #807
  • 2.5.0 tag: doesn't work because it misses the fixes from this PR
  • master works great but is not supported in my dependencies (DefectDojo and SecureCodebox) and I would like to get them to update their parsers

Could we do a new release 2.5.1 which replaces 2.5.0 completely?
Otherwise people who want to change their parser, might just look at the 2.5.0 release and implement changes for a broken format.
They then will be hit with another necessary(!) but breaking change in the next release due to the encoding changes and the multi-host support.

@sullo
Copy link
Owner
sullo commented Jan 11, 2024

@moxli thanks for the suggestions and I understand your pain. Give me a day to evaluate replacing it all with proper usage of a JSON module--to your point I'd rather do this one time and do a dot release than do it more than once.

@sullo
Copy link
Owner
sullo commented Jan 11, 2024

@moxli one thing to clarify is that master, in my world, is always the working most current code and the 2.5.0 tag/branch are basically snapshots. I should probably archive the 2.5.0 branch as it's now obsolete.

I'm sure this is the non-recommended approach by most people 🤣

@moxli
Copy link
Contributor
moxli commented Jan 12, 2024

@sullo thank you very much for your reply :)

@moxli
Copy link
Contributor
moxli commented Jan 23, 2024

@sullo Did you come to a conclusion about a possible rewrite of the json reporting yet?:)

@Weltraumschaf
Copy link

I'm sure this is the non-recommended approach by most people 🤣

Yep, that's absolutely correct 😩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants