JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
汚染された可能性のあるデータが LDAP 文の構成として使用されています。
| クラス名 | LDAP Injection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | LDAPインジェクション | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| クラス分類 | セキュリティ (security) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ニーモニック | IO.INJ.LDAP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 対応言語 | 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" #ifdef HAVE_LDAP_H #include "ldap.h" #else /* Provide minimal declarations so this can compile even if openldap * headers are not available. */ typedef struct ldap LDAP; typedef struct ldapmsg LDAPMessage; typedef struct berelement BerElement; typedef struct ldapmsg LDAPMessage; #define LBER_INT_T int #define LBER_LEN_T long typedef unsigned LBER_LEN_T ber_len_t; typedef LBER_INT_T ber_int_t; #define LDAP_SCOPE_SUBTREE ((ber_int_t) 0x0002) #define LDAP_SUCCESS 0x00 #define LDAP_NO_LIMIT 0 typedef struct berval { ber_len_t bv_len; char *bv_val; } BerValue; typedef struct ldapcontrol { char * ldctl_oid; /* numericoid of control */ struct berval ldctl_value; /* encoded value of control */ char ldctl_iscritical; /* criticality */ } LDAPControl; #define LDAP_CONST const int ldap_search_ext_s( LDAP *ld, LDAP_CONST char *base, int scope, LDAP_CONST char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeout, int sizelimit, LDAPMessage **res ); LDAPMessage * ldap_first_message ( LDAP *ld, LDAPMessage *chain ); LDAPMessage * ldap_next_message ( LDAP *ld, LDAPMessage *msg ); char * ldap_get_dn ( LDAP *ld, LDAPMessage *entry ); void ldap_memfree ( void* p ); char * ldap_first_attribute ( LDAP *ld, LDAPMessage *entry, BerElement **ber ); char * ldap_next_attribute ( LDAP *ld, LDAPMessage *entry, BerElement *ber ); struct berval ** ldap_get_values_len ( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target ); #endif 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.
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.