id: aws-bucket-takeover
info:
  name: AWS Bucket Takeover Detection
  author: pdteam,pwnhxl,zy9ard3,venjaku
  severity: high
  description: AWS Bucket takeover was detected.
  reference:
    - https://github.com/EdOverflow/can-i-take-over-xyz/issues/36
  metadata:
    max-request: 1
  tags: takeover,aws,bucket,vuln

http:
  - method: GET
    path:
      - "{{BaseURL}}"

    matchers-condition: and
    matchers:
      - type: dsl
        dsl:
          - Host != ip

      - type: word
        words:
          - "The specified bucket does not exist"
          - "BucketName"
        condition: and

      - type: dsl
        dsl:
          - contains(tolower(header), 'x-guploader-uploadid')
          - contains(tolower(header), "aliyunoss")
        negative: true

      - type: regex
        part: host
        regex:
          - '^[a-z0-9][a-z0-9-]+-[0-9]{12}-[a-z0-9-]+-an\.s3\.[a-z0-9-]+\.amazonaws\.com'
        negative: true

      - type: word
        part: host
        words:
          - "amazonaws.com"
          - "ks3.ksyun.com"
          - "kss.ksyun.com"
          - "kss3.ksyun.com"
          - "ks3-cn-beijing.ksyun.com"
          - "ks3-cn-guangzhou.ksyun.com"
          - "ks3-cn-hk-1.ksyun.com"
          - "ks3-cn-shanghai.ksyun.com"
          - "ks3-jr-beijing.ksyun.com"
          - "ks3-jr-shanghai.ksyun.com"
          - "ks3-rus.ksyun.com"
          - "ks3-sgp.ksyun.com"
          - "obs.jrzq.huaweicloud.com"
          - "obs.petalpay.huaweicloud.com"
          - "oss-cn-hangzhou.aliyuncs.com"
          - "oss-cn-shanghai.aliyuncs.com"
          - "oss-cn-qingdao.aliyuncs.com"
          - "oss-cn-beijing.aliyuncs.com"
          - "oss-cn-zhangjiakou.aliyuncs.com"
          - "oss-cn-huhehaote.aliyuncs.com"
          - "oss-cn-shenzhen.aliyuncs.com"
          - "oss-cn-hongkong.aliyuncs.com"
          - "oss-us-west-1.aliyuncs.com"
          - "oss-us-east-1.aliyuncs.com"
          - "oss-ap-southeast-1.aliyuncs.com"
          - "oss-ap-southeast-2.aliyuncs.com"
          - "oss-ap-southeast-3.aliyuncs.com"
          - "oss-ap-southeast-5.aliyuncs.com"
          - "oss-ap-south-1.aliyuncs.com"
          - "oss-ap-northeast-1.aliyuncs.com"
          - "oss-eu-central-1.aliyuncs.com"
          - "oss-me-east-1.aliyuncs.com"
        negative: true

    extractors:
      - type: regex
        part: body
        group: 1
        regex:
          - '<li>BucketName: (.*?)</li>'
          - '<BucketName>(.*?)</BucketName>'
# digest: 490a0046304402206f58d83ee9ca9941f593a2b7e93aa070aba4c5f2cb7d255105232d87a14151a702205dcd2c434c9fbe27637ab313782a829423bb480a5ae111a83a7f7b50fda75c49:922c64590222798bb761d5b6d8e72950