こんとろーるしーこんとろーるぶい

週末にカチャカチャッターン!したことを貼り付けていくブログ

UTCTF 2019 CTF Writeup - DragonScim Workshops

Question

DragonScim is holding it's PKing workshop again! 
Word on the street is the admins get into the console via the Contact. 
They thought it might be clever and crafty if they also just created 
their name with inspiration from fish that collide with themselves. 
Oh, and lastly, they've left a joke for us. 
Here it is:

How do you kill a circus?
You go for the juggler.

Also, the admins love Maryland a lot... They've been there 5 times.

NOTE: THIS IS NOT AN XSS CHALLENGE
http://dragonscim.xyz/

f:id:graneed:20190311015753p:plain

Solution

Contact Usのリンクを押下すると、Nameを入力する画面が表示される。
他の入力項目は見当たらない。

name項目を配列(/contact.php?name[]=aaa)にしてアクセスしてみると以下の表示。

Warning: md5() expects parameter 1 to be string, 
array given in /var/www/site/contact.php on line 76
Thanks for your message Array, it has been received.

入力文字列を使用してmd5を計算しているようだ。

問題文を再度読み直す。
They thought it might be clever and crafty if they also just created their name with inspiration from fish that collide with themselves

入力した文字列と、その文字列自身から計算したMD5ハッシュ値とが一致するものを探す問題と解釈。
ただ、流石に完全一致(===)ではなく、phpの==で比較されているものと想定。

こういう問題は0e + 数字の指数表記を使うと相場が決まっている。(CTF脳)

0e + 数字MD5ハッシュの計算結果が、1文字以上の0 + e + 数字の形式になれば、どちらも0になり、
==で比較するとTrueとなるため条件を充たす。

以下のスクリプトを作って、該当する文字列を探す。

# -*- coding: utf-8 -*-
import hashlib
import string
import re

def generateMD5():
    pattern = "^0+e[0-9]+$"
    i = 0

    while True:
        if i % 1000000 == 0:
            print("i:" + str(i))
        s = '0e' + str(i)
        md5 = hashlib.md5(s.encode("utf-8")).hexdigest()
        m = re.search(pattern, md5)
        if m:
            print("source:", s)
            print("md5   :", md5)
            return s
        i = i + 1

if __name__ == "__main__":
    generateMD5()

実行してしばらく待つ。

i:0
i:1000000
(snip)
i:214000000
i:215000000
source: 0e215962017
md5   : 0e291242476940776845150308577824

見つかった!

0e215962017を入力する。

f:id:graneed:20190311020919p:plain

utctf{colliding_with_md5}

フラグゲット。

問題文がヒントになっているとはいえ、若干のエスパー感がある問題だった。