ガイドライン

注射の基礎知識

脆弱性の中でも特によく知られているのがインジェクション攻撃です。中でも、誰もが納得する代表格といえば「SQLインジェクション」でしょう。IT業界に身を置いていれば耳にしない日はないほど有名なこの脆弱性について、改めて解説します。

SQLインジェクションとは、SQLクエリの動作を操作し、攻撃者の意図した通りにデータベースを動かしてしまう攻撃手法です。

他にも多くのインジェクション攻撃が存在しますが、表面上の違いはあっても、その仕組みはすべて同じ原理に基づいています。

代表的なインジェクション攻撃の種類を振り返ってみましょう。

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

インジェクションの基礎知識

先ほど挙げたインジェクション攻撃には、共通点が一つあります。それは、いずれも「文字列」がインタープリタ(解釈実行系)に渡され、その文字列が示す命令が実行されるという点です。ここでは「ユーザー入力」を波括弧で囲んで示します。

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インジェクション‍

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

タグライン

実践的なセキュアコーディング

OWASP Top 10のようなソフトウェアの脆弱性を理解し軽減するためのセキュアコーディングガイドラインを確認しましょう。また、実践的なアプリシミュレーションを通じて学べるトレーニングミッションにもぜひ挑戦してください。

その他のガイドライン
デモを予約する