id: mysql-user-enum

info:
  name: MySQL - User Enumeration
  author: pussycat0x
  severity: high
  description: |
    Attempts to list all users on a MySQL server.
  reference:
    - https://nmap.org/nsedoc/scripts/mysql-users.html
  metadata:
    verified: true
    max-request: 16
    shodan-query: "port:3306"
  tags: js,mysql,network,enum

javascript:
  - pre-condition: |
      isPortOpen(Host,Port);
    code: |
      let m = require('nuclei/mysql');
      let c = m.MySQLClient();
      let response = c.ExecuteQuery(Host,Port,User,Pass,Query);
      Export(response);

    args:
      Host: "{{Host}}"
      Port: "3306"
      Query: "SELECT DISTINCT user FROM mysql.user;"
      User: "{{usernames}}"
      Pass: "{{passwords}}"

    payloads:
      usernames:
        - root
        - admin
        - mysql
        - test
      passwords:
        - root
        - admin
        - mysql
        - test
    attack: clusterbomb

    stop-at-first-match: true
    matchers:
      - type: dsl
        dsl:
          - "success == true"

    extractors:
      - type: json
        part: response
        json:
          - '.Rows[].user'
# digest: 4b0a00483046022100d4e7677bf9c6094bc06b7145ad07b67859b34d03106faa76e99269a129b15290022100fb739127b1df6a6f9be1a6539253d83b72d9e15026335de6f77806ded8fcbaf7:922c64590222798bb761d5b6d8e72950