CVE-2016-5843 (published 2016-09-17T02:59Z)

Multiple SQL injection vulnerabilities in the FAQ package 2.x before 2.3.6, 4.x before 4.0.5, and 5.x before 5.0.5 in Open Ticket Request System (OTRS) allow remote attackers to execute arbitrary SQL commands via crafted search parameters.

Severity: HIGH
CVSS v2 base score: 9.0 (AV:N/AC:L/Au:N/C:C/I:P/A:P)
CVSS v3 base score: 9.4, CRITICAL (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:L)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/OTRS/FAQ
commit_details: repo_url: https://github.com/OTRS/FAQ
author: Carlos Rodriguez
author_date: 2016-06-27 16:28:09-05:00
msg: Fixed issue with not correctly quoted search parameters.
repository: repo_url: https://github.com/OTRS/FAQ
repo_name: OTRS/FAQ
description: An FAQ module to manage FAQs and also used as knowledge base.
repo_language: Perl
owner: OTRS
file_changes: filename: CHANGES-FAQ.md
change_type: ModificationType.MODIFY
diff: @@ -1,4 +1,5 @@
 #5.0.4 2016-??-??
+ - 2016-06-27 Fixed issue with not correctly quoted search parameters.
  - 2016-05-02 Added FileID attribute to the retrieved attachments using Generic Interface PublicFAQGet operation, thanks to Esteban Marin.
 
 #5.0.3 2016-05-17

programming_language: Markdown
filename: FAQ.sopm
change_type: ModificationType.MODIFY
diff: @@ -119,6 +119,7 @@
         <File Permission="644" Location="scripts/test/Console/Command/Admin/FAQ/Import.t"/>
         <File Permission="644" Location="scripts/webservices/GenericFAQConnectorSOAP.yml"/>
         <File Permission="644" Location="scripts/test/Console/Command/Maint/FAQ/ContentTypeSet.t"/>
+        <File Permission="644" Location="scripts/test/FAQSearch/InConditionGet.t"/>
         <File Permission="644" Location="scripts/test/FAQ.t"/>
         <File Permission="644" Location="scripts/test/FAQSearch.t"/>
         <File Permission="644" Location="scripts/test/GenericInterface/FAQConnector.t"/>

programming_language: TypeScript
filename: FAQSearch.pm
change_type: ModificationType.MODIFY
diff: @@ -217,6 +217,43 @@ sub FAQSearch {
         Result => 'vrate',
     );
 
+    # check types of given arguments
+    ARGUMENT:
+    for my $Key (qw(LanguageIDs CategoryIDs ValidIDs CreatedUserIDs LastChangedUserIDs)) {
+
+        next ARGUMENT if !$Param{$Key};
+        next ARGUMENT if ref $Param{$Key} eq 'ARRAY' && @{ $Param{$Key} };
+
+        # log error
+        $Kernel::OM->Get('Kernel::System::Log')->Log(
+            Priority => 'error',
+            Message  => "The given param '$Key' is invalid or an empty array reference!",
+        );
+        return;
+    }
+
+    # get database object
+    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
+
+    # quote id array elements
+    ARGUMENT:
+    for my $Key (qw(LanguageIDs CategoryIDs ValidIDs CreatedUserIDs LastChangedUserIDs)) {
+        next ARGUMENT if !$Param{$Key};
+
+        # quote elements
+        for my $Element ( @{ $Param{$Key} } ) {
+            if ( !defined $DBObject->Quote( $Element, 'Integer' ) ) {
+
+                # log error
+                $Kernel::OM->Get('Kernel::System::Log')->Log(
+                    Priority => 'error',
+                    Message  => "The given param '$Element' in '$Key' is invalid!",
+                );
+                return;
+            }
+        }
+    }
+
     my $FAQDynamicFields = [];
     my %ValidDynamicFieldParams;
     my %FAQDynamicFieldName2Config;
@@ -297,7 +334,6 @@ sub FAQSearch {
     my $Ext = '';
 
     # get needed objects
-    my $DBObject     = $Kernel::OM->Get('Kernel::System::DB');
     my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
 
     # full-text search
@@ -441,7 +477,9 @@ sub FAQSearch {
     # search for states
     if ( $Param{States} && ref $Param{States} eq 'HASH' && %{ $Param{States} } ) {
 
-        my @States = map {$_} keys %{ $Param{States} };
+        my @States = map { $DBObject->Quote( $_, 'Integer' ) } keys %{ $Param{States} };
+
+        return if scalar @States != keys $Param{States};
 
         my $InString = $Self->_InConditionGet(
             TableColumn => 's.type_id',
@@ -1018,16 +1056,20 @@ condition string from an array.
 sub _InConditionGet {
     my ( $Self, %Param ) = @_;
 
-    # check needed stuff
-    for my $Key (qw(TableColumn IDRef)) {
-        if ( !$Param{$Key} ) {
-            $Kernel::OM->Get('Kernel::System::Log')->Log(
-                Priority => 'error',
-                Message  => "Need $Key!",
-            );
+    if ( !$Param{TableColumn} ) {
+        $Kernel::OM->Get('Kernel::System::Log')->Log(
+            Priority => 'error',
+            Message  => "Need TableColumn!",
+        );
+        return;
+    }
 
-            return;
-        }
+    if ( !$Param{IDRef} || ref $Param{IDRef} ne 'ARRAY' || !@{ $Param{IDRef} } ) {
+        $Kernel::OM->Get('Kernel::System::Log')->Log(
+            Priority => 'error',
+            Message  => "Need IDRef!",
+        );
+        return;
     }
 
     # sort ids to cache the SQL query
@@ -1036,10 +1078,9 @@ sub _InConditionGet {
     # get database object
     my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
 
-    # quote values
-    for my $Value (@SortedIDs) {
-        $DBObject->Quote( $Value, 'Integer' );
-    }
+    # Error out if some values were not integers.
+    @SortedIDs = map { $Kernel::OM->Get('Kernel::System::DB')->Quote( $_, 'Integer' ) } @SortedIDs;
+    return if scalar @SortedIDs != scalar @{ $Param{IDRef} };
 
     # split IN statement with more than 900 elements in more statements combined with OR
     # because Oracle doesn't support more than 1000 elements in one IN statement.
@@ -1049,7 +1090,7 @@ sub _InConditionGet {
 
         my @SortedIDsPart = splice @SortedIDs, 0, 900;
 
-        my $IDString = join ',', @SortedIDsPart;
+        my $IDString = join ', ', @SortedIDsPart;
 
         push @SQLStrings, " $Param{TableColumn} IN ($IDString) ";
     }

programming_language: Perl
filename: FAQ.xml
change_type: ModificationType.MODIFY
diff: @@ -1561,7 +1561,9 @@ shell> bin/otrs.Console.pl Admin::Package::Install /path/to/$Name-$Version.opm
             command on the command line:
         </para>
         <screen>
-shell> perl bin/otrs.Console.pl Dev::UnitTest::Run --test FAQ:FAQSearch:GenericInterface/FAQConnector:Console/Command/Admin/FAQ/Import:Console/Command/Maint/FAQ/ContentTypeSet
+shell> perl bin/otrs.Console.pl Dev::UnitTest::Run --test FAQ:FAQSearch:FAQSearch/InConditionGet
+shell> perl bin/otrs.Console.pl Dev::UnitTest::Run --test GenericInterface/FAQConnector
+shell> perl bin/otrs.Console.pl Dev::UnitTest::Run --test Console/Command/Admin/FAQ/Import:Console/Command/Maint/FAQ/ContentTypeSet
         </screen>
         <para>Selenium unit tests</para>
         <para>

programming_language: HTML
filename: FAQSearch.t
change_type: ModificationType.MODIFY
diff: @@ -480,6 +480,58 @@ for my $Test (@Tests) {
     );
 }
 
+# other tests
+@Tests = (
+    {
+        Name   => 'States Hash Correct IDs',
+        Config => {
+            %SearchConfigTemplate,
+            States => {
+                1 => 'Internal',
+                2 => 'External',
+                3 => 'Public',
+            },
+        },
+        ExpectedResults => [ $AddedFAQs[0], $AddedFAQs[1] ],
+    },
+    {
+        Name   => 'States Hash Incorrect IDs (Float)',
+        Config => {
+            %SearchConfigTemplate,
+            States => {
+                1.1 => 'Internal',
+                2.2 => 'External',
+                3.3 => 'Public',
+            },
+        },
+        ExpectedResults => [],
+    },
+    {
+        Name   => 'States Hash Incorrect IDs (String)',
+        Config => {
+            %SearchConfigTemplate,
+            States => {
+                'Internal' => 'Internal',
+                'External' => 'External',
+                'Public'   => 'Public',
+            },
+        },
+        ExpectedResults => [],
+    },
+
+);
+
+# execute the tests
+for my $Test (@Tests) {
+    my @FAQIDs = $FAQObject->FAQSearch( %{ $Test->{Config} } );
+
+    $Self->IsDeeply(
+        \@FAQIDs,
+        $Test->{ExpectedResults},
+        "$Test->{Name} FAQSearch()",
+    );
+}
+
 # time based tests
 
 # update FAQs
@@ -751,12 +803,9 @@ for my $Test (@Tests) {
         Name   => 'Wrong LastChangedUserIDs Format',
         Config => {
             %SearchConfigTemplate,
-            CreatedUserIDs => $AddedUsers[2],
+            LastChangedUserIDs => $AddedUsers[2],
         },
-        ExpectedResults => [
-            $AddedFAQs[0],
-            $AddedFAQs[1],
-        ],
+        ExpectedResults => [],
     },
 );
 

programming_language: Perl
filename: InConditionGet.t
change_type: ModificationType.ADD
diff: @@ -0,0 +1,80 @@
+# --
+# Copyright (C) 2001-2016 OTRS AG, http://otrs.com/
+# --
+# This software comes with ABSOLUTELY NO WARRANTY. For details, see
+# the enclosed file COPYING for license information (AGPL). If you
+# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
+# --
+
+## no critic (Modules::RequireExplicitPackage)
+use strict;
+use warnings;
+use utf8;
+
+use vars (qw($Self));
+
+# get helper object
+$Kernel::OM->ObjectParamAdd(
+    'Kernel::System::UnitTest::Helper' => {
+        RestoreDatabase => 1,
+    },
+);
+my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
+
+my @Tests = (
+    {
+        Name   => 'No array',
+        Params => {
+            TableColumn => 'test.table',
+            IDRef       => 1,
+        },
+        Result => undef,
+    },
+    {
+        Name   => 'Single Integer',
+        Params => {
+            TableColumn => 'test.table',
+            IDRef       => [1],
+        },
+        Result => ' (  test.table IN (1)  ) ',
+    },
+    {
+        Name   => 'Sorted values',
+        Params => {
+            TableColumn => 'test.table',
+            IDRef       => [ 2, 1, -1, 0 ],
+        },
+        Result => ' (  test.table IN (-1, 0, 1, 2)  ) ',
+    },
+    {
+        Name   => 'Invalid value',
+        Params => {
+            TableColumn => 'test.table',
+            IDRef       => [1.1],
+        },
+        Result => undef,
+    },
+    {
+        Name   => 'Mix of valid and invalid values',
+        Params => {
+            TableColumn => 'test.table',
+            IDRef       => [ 1, 1.1 ],
+        },
+        Result => undef,
+    },
+);
+
+# get FAQ object
+my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
+
+for my $Test (@Tests) {
+    $Self->Is(
+        scalar $FAQObject->_InConditionGet( %{ $Test->{Params} } ),
+        $Test->{Result},
+        "$Test->{Name} _InConditionGet()"
+    );
+}
+
+# cleanup is done by RestoreDatabase.
+
+1;

programming_language: Perl