Skip to content

MongoDB Reporting - #5688

Merged
ehsandeep merged 8 commits into
projectdiscovery:devfrom
kchason:mongo-db-reporting
Oct 13, 2024
Merged

ehsandeep merged 8 commits into
projectdiscovery:devfrom
kchason:mongo-db-reporting

Conversation

@kchason

@kchason kchason commented Oct 4, 2024 •

Copy link
Copy Markdown
Contributor

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)

@ghost
ghost requested a review from dogancanbakir October 4, 2024 14:50
@dwisiswant0

Copy link
Copy Markdown
Member

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

@kchason

kchason commented Oct 7, 2024

Copy link
Copy Markdown
Contributor Author

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

Comment thread pkg/reporting/exporters/mongo/mongo.go Resolved
Comment thread pkg/reporting/exporters/mongo/mongo.go Resolved
Comment thread pkg/reporting/exporters/mongo/mongo.go Resolved
Comment thread pkg/reporting/exporters/mongo/mongo.go Resolved
@kchason kchason mentioned this pull request Oct 8, 2024
1 of 4 tasks
@ehsandeep
ehsandeep merged commit 3f0de96 into projectdiscovery:dev Oct 13, 2024
@kchason
kchason deleted the mongo-db-reporting branch October 16, 2024 16:10
@ehsandeep

Copy link
Copy Markdown
Member

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

@kchason

kchason commented Oct 20, 2024

Copy link
Copy Markdown
Contributor Author

@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