# Rails Database Config Exposure Detection Module

id: rails-database-yml-exposure
info:
  name: Rails Database Config Exposure
  author: sif
  severity: high
  description: Detects an exposed Rails config/database.yml that leaks database credentials
  tags: [rails, ruby, database, credentials, exposure, recon]

type: http

http:
  method: GET
  paths:
    - "{{BaseURL}}/config/database.yml"

  matchers:
    - type: status
      status:
        - 200

    - type: word
      part: body
      words:
        - "adapter:"

    - type: word
      part: body
      condition: or
      words:
        - "password:"
        - "username:"

    - type: word
      part: body
      negative: true
      condition: or
      words:
        - "<!DOCTYPE"
        - "<!doctype"
        - "<html"
        - "<HTML"
        - "<head>"
        - "<title>"

  extractors:
    - type: regex
      name: database
      part: body
      regex:
        - 'database:\s*["'']?([A-Za-z0-9_./\-]+)'
      group: 1
