id: matrix-detect

info:
  name: Matrix Server Detect
  author: erethon
  severity: info
  description: Detects Matrix servers based on .well-known entries. See https://en.wikipedia.org/wiki/Matrix_(protocol)
  reference:
    - https://spec.matrix.org/v1.3/server-server-api/#getwell-knownmatrixserver, https://spec.matrix.org/v1.3/client-server-api/#getwell-knownmatrixclient
  metadata:
    max-request: 2
  tags: tech,matrix,discovery

http:
  - method: GET
    redirects: true
    max-redirects: 2
    path:
      - "{{BaseURL}}/.well-known/matrix/server"
      - "{{BaseURL}}/.well-known/matrix/client"

    matchers-condition: and
    matchers:
      - type: regex
        regex:
          - '"m\.([a-z]+)":'

      - type: word
        part: header
        words:
          - text/html
        negative: true

      - type: status
        status:
          - 200

    extractors:
      - type: json
        part: body
        json:
          - '."m.server" | select( . != null )'
          - '."m.homeserver" | .base_url | select( . != null )'
          - '."m.identity_server" | .base_url | select( . != null )'
# digest: 4a0a00473045022072b4ebbe443552d75459ce433fd4c06d021c9e592ba5a7abb24fc0e0f6243866022100dd5237b0789347bd910c8b671d437b527fc28a608c8a5f30a18368f31c476f75:922c64590222798bb761d5b6d8e72950