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

MongoDB Reporting #5688

Merged
merged 8 commits into from
Oct 13, 2024
Merged

Conversation

kchason
Copy link
Contributor

@kchason kchason commented Oct 4, 2024

Proposed changes

Allows exporting of scan results to a MongoDB database for storage and reporting. As there are several options for JSON formatting and other datastore exports exist (e.g., Elasticsearch, Splunk), this seemed like a natural capability to support.

Closes #5700

It utilizes the same issue-tracker-config.yml format with the following options:

mongodb:
  # the connection string to the MongoDB database
  # (e.g., mongodb://root:example@localhost:27017/nuclei?ssl=false&authSource=admin)
  connection-string: ""
  # the name of the collection to store the issues
  collection-name: ""
  # excludes the Request and Response from the results (helps with filesize)
  omit-raw: false
  # determines the number of results to be kept in memory before writing it to the database or 0 to
  # persist all in memory and write all results at the end (default)
  batch-size: 0

It also optionally allows the use of the environment variable MONGO_CONNECTION_STRING as the connection string may contain passwords or other sensitive information that users may not want to store in a config file.

To run this locally:

Run a Docker Compose stack for MongoDB (source):

docker-compose.yml

services:
  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
      ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
      ME_CONFIG_BASICAUTH: false

Run the stack with:

docker compose up -d

Navigate to http://localhost:8081 and create a nuclei database.

Create the config file reporters.yml (or update one in place) with the contents:

mongodb:
  connection-string: "mongodb://root:example@localhost:27017/nuclei?ssl=false&authSource=admin"
  collection-name: "results"
  omit-raw: false
  batch-size: 0

Run Nuclei with the config, adding any additional parameters to tune the scan as desired.

nuclei -report-config reporters.yml -template-id ssl-issuer,http-missing-security-headers -target hackthissite.org

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@auto-assign auto-assign bot requested a review from dogancanbakir October 4, 2024 14:50
@dwisiswant0
Copy link
Member

Why do we need "database-name" field when we can just fill it in with a DSN/conn string?

@kchason
Copy link
Contributor Author

kchason commented Oct 7, 2024

Why do we need "database-name" field when we can just fill it in with a DSN/conn string?

Good call, it now parses it from the connection string as of 5d934aa

pkg/reporting/exporters/mongo/mongo.go Outdated Show resolved Hide resolved
pkg/reporting/exporters/mongo/mongo.go Show resolved Hide resolved
pkg/reporting/exporters/mongo/mongo.go Show resolved Hide resolved
@kchason kchason mentioned this pull request Oct 8, 2024
4 tasks
@ehsandeep ehsandeep merged commit 3f0de96 into projectdiscovery:dev Oct 13, 2024
11 of 12 checks passed
@kchason kchason deleted the mongo-db-reporting branch October 16, 2024 16:10
@ehsandeep
Copy link
Member

@kchason thank you for this addition, whenever you get a chance, please update the docs for the same.

@kchason
Copy link
Contributor Author

kchason commented Oct 20, 2024

@kchason thank you for this addition, whenever you get a chance, please update the docs for the same.

projectdiscovery/docs#93

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.

Add MongoDB Reporting
4 participants