0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【19個目】【SQLインジェクション】SQL injection UNION attack, retrieving data from other tables

Posted at

SQL injection UNION attack, retrieving data from other tables

概要

UNION攻撃を用いて、userstableテーブルからクレデンシャル情報を取得する

攻撃手順

  • クエリパラメタで商品をフィルタしている機能を探す
  • 末尾にシングルクォーテーションを付与してエラーが発生するか確認。エラーが発生すれば、入力された文字列がエスケープされていない。つまり、SQLインジェクション攻撃が可能であると推測できる
  • UNION攻撃を試みるため、正常のSQLで取得されるカラム数を調査する。order by nをSQLクエリの末尾に追加して確認する。nの値を1から順に増やしていき、エラーが発生する直前のn-1がカラム数となる
  • UNIONを用い、'a', 'aa'のように、取り出したいカラムがテキスト型か確認
  • usersテーブルからusername及びpasswordを取得するためのSQLをクエリパラメタに付与する

対策

  • プレースホルダー(プリペアドステートメント)を利用する
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?