SQL インジェクション

From mediawiki.org
This page is a translated version of the page SQL injection and the translation is 37% complete.

概要

SQL injection is a type of attack that uses vulnerabilities in an application's input validation or data typing for SQL queries.

この攻撃に成功すると、攻撃者は既存の SQL クエリにデータを注入できます。 その結果、攻撃者は個人情報を取得したり、サービス拒否を引き起こしたり、その他の意図しない反応を引き起こしたりすることができます。 最悪の場合、注入されたコードにより、攻撃者はデータベース サーバー、システム ユーティリティ、オペレーティング システムに存在する複数の脆弱性を利用して、システムを完全に制御できます。

SQL インジェクション攻撃の概要については、ウィキペディアの SQL インジェクションのページを参照してください。

The following code snippet would allow an attacker to execute their own SQL commands (and is a syntax error in Oracle).

$limit = $wgRequest->getVal( 'limit' );
$res = $db->query( "SELECT * from kitties LIMIT $limit" );

The preferred way to run the above query would be:

$limit = $wgRequest->getVal( 'limit' );
$limit = intval( $limit ); // OPTIONAL validation
$res = $db->select( 'kitties',
                    '*',
                    false,
                    __METHOD__,
                    array( 'LIMIT' => $limit ) // REQUIRED automatic escaping
);

To exploit the vulnerability and fetch the email addresses of registered wiki users, the attacker would use a GET string of:

?limit=%201%20union%20select%20user_email%20from%20user;


SQL Injection and MediaWiki

MediaWiki has a custom SQL generation interface which has proven to be effective for eliminating SQL injection vulnerabilities. The SQL generation interface also provides DBMS abstraction and features such as table prefixes.

To keep MediaWiki safe from SQL injection: