hero bg no divider
ガイドライン

インジェクション 101

最もよく知られている脆弱性のクラスの 1 つは、インジェクションの脆弱性です。特に、誰もが疑う余地のない存在である SQL インジェクションは、誰も驚かないでしょう。テクノロジーの世界で SQL インジェクションについて耳にするのは避けられないので、ここではそのことについて話すことにします。

SQL インジェクションを使用すると、SQL クエリの動作を操作して攻撃者の命令を実行することができます。

表面的には異なりますが、すべて同じ原理に基づいて機能する注入タイプは他にもたくさんあります。

要約すると、最も一般的な注入タイプのいくつかは次のとおりです。

  • SQL インジェクション
  • クロスサイトスクリプティング (HTML/JavaScript インジェクション)
  • パストラバーサル (パス/URL インジェクション)
  • コマンド・インジェクション
  • コード・インジェクション

ア・リトル・インジェクション 101

前述のインジェクションタイプのリストを見ると、すべて共通点が1つあります。それらはすべて文字列に関係し、それがインタープリターを介して実行され、インタープリターが文字列が表すすべての処理を行います。「ユーザー入力」は中括弧で囲んでいます。

Type Example input How it’s interpreted
SQL SELECT name FROM users WHERE username = '{admin}' Selects the "Name" column from all rows from the users table where the username is 'admin'
HTML {John Smith} Shows the name "John Smith" in bold letters
Path /var/www/app/documents/{privacy-policy.pdf} Points at the file `privacy-policy.pdf` in the `/var/www/app/documents/` folder
Command ping {8.8.8.8} Sends a series of ICMP pings to the IP `8.8.8.8`
Code const name = '{John Smith}'; Sets the constant variable `name` to the value `John Smith

では、ユーザー入力の挿入が安全でない場合はどうなるでしょうか。攻撃者には何ができるでしょうか?繰り返しになりますが、このシナリオでは、中括弧内のものはすべて「ユーザー入力」と見なされます。

Type Example input How it’s interpreted
SQL - Injected SELECT name FROM users WHERE username = '{1' UNION SELECT passwordhash from users WHERE username = 'admin}' Selects the "Name" from all rows from the users table where the username is 'admin', and the password hash for the users where the username is 'admin'
HTML - Injected {} Show the name "John Smith" in bold letters
Path - Injected /var/www/app/documents/{../../../../../etc/shadow} Points at the file `shadow` in the `/etc/` folder
Command - Injected ping {8.8.8.8 && ls . } Sends a series of ICMP pings to the IP `8.8.8.8`, and prints the contents of the current directory with `ls`
Code - Injected const name = '{John Smith'; exec('ls .'); # }'; Sets the constant variable `name` to the value `John Smith`, and then executes the system command `ls .

これらの例では、入力がどのようにユーザー入力の結果に影響を与えることができるかに注意してください。

これが注射の本質です。元のプログラマーが意図していたこととは違うことを実行させるために、インタープリターに渡される内容に影響を及ぼしているのです。

これらは考慮すべき基本事項にすぎません。もう少し注意が必要なため、いくつかの異なるインジェクションタイプを個別のページに分けました。

ここで見つけることができます:

コマンド・インジェクション

パストラバーサル

SQL インジェクション

クロスサイトスクリプティング