C and C++ Binaries


IO.INJ.LDAP : LDAPインジェクション

要旨

汚染された可能性のあるデータが LDAP 文の構成として使用されています。

プロパティ

クラス名 LDAP Injection
日本語クラス名 LDAPインジェクション
クラス分類 セキュリティ (security)
ニーモニック IO.INJ.LDAP
カテゴリー
MisraC2023 MisraC2023:D.4.14 The validity of values received from external sources shall be checked
Misra2012 Misra2012:D.4.14 The validity of values received from external sources shall be checked
AUTOSARC++14 AUTOSARC++14:A27-0-1 Inputs from independent components shall be validated.
CWE CWE:90 Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection')
CERT-C CERT-C:STR02-C Sanitize data passed to complex subsystems
DISA-6r1 DISA-6r1:V-222606 The application must validate all input.
  DISA-6r1:V-222609 The application must not be subject to input handling vulnerabilities.
DISA-5r3 DISA-5r3:V-70265 The application must validate all input.
  DISA-5r3:V-70271 The application must not be subject to input handling vulnerabilities.
DISA-4r3 DISA-4r3:V-70265 The application must validate all input.
  DISA-4r3:V-70271 The application must not be subject to input handling vulnerabilities.
DISA-3r10 DISA-3r10:V-6157 The designer will ensure the application does not contain invalid URL or path references.
  DISA-3r10:V-6164 The designer will ensure the application validates all input.
OWASP-2017 OWASP-2017:A1 Injection
OWASP-2021 OWASP-2021:A3 Injection
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="LDAP Injection"

以下の例は、ユーザー入力をベースにした LDAP クエリを構成するコードです。 通常ユーザーは ID 値を入力し、コードはその ID によって全ての LDAP レコードの DN フィールドを表示します。 しかし、攻撃者は悪意のある "*" の様な値を入力し、コードの作者の意図とかけ離れたディレクトリを使うことができます。

#include <stdlib.h>
#include <stdio.h>
#include "math.h"
#include "ldap.h"

void lookup_by_idnum(LDAP *ld ){
    char filter[256];
    char idnum[128];
    LDAPMessage *res_msg, *msg;
    BerElement *berel; 
    int retval, i;
    char *att, *dn;
    struct berval **attvals;

    printf("what is the ID number?\n");
    if (!fgets(idnum, 128, stdin)) return ;
    sprintf(filter, "(IDnum=%s)", idnum);

    retval=ldap_search_ext_s(ld, 
                             "dc=myserver,dc=example,dc=com",
                             LDAP_SCOPE_SUBTREE, 
                             filter,  NULL, 0, NULL, NULL, NULL, 
                             LDAP_NO_LIMIT, &res_msg );  // LDAP Injection Warning Here

    if (retval != LDAP_SUCCESS) { 
        for ( msg = ldap_first_message( ld, res_msg ); 
              msg != NULL; 
              msg = ldap_next_message( ld, msg ) ) {
            if (( dn = ldap_get_dn( ld, msg )) != NULL ) {
                printf( "dn: %s\n", dn );
                ldap_memfree( dn );
            }  
            for ( att = ldap_first_attribute( ld, msg, &berel );
                  att != NULL; 
                  att = ldap_next_attribute( ld, msg, berel ) ) {
                if ((attvals = ldap_get_values_len( ld, msg, att ))!= NULL ) {
                    for ( i = 0; attvals[ i ] != NULL; i++ ) {
                        printf( "%s: %s\n", att, attvals[ i ]->bv_val );

                    } 
                }
            }
        }
    }
    exit(0);
}

ワーニングを引き起こす関数

CodeSonar ships with library models that allow it to functions such as LDAP ldap_search_ext() that use one or more of their parameters to construct an LDAP statement. If one of these functions is called with a tainted value in one of those parameter positions, a warning will be issued.

If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering LDAP Injection warnings.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。