題目資訊
Do it
Just do it
Don’t let your dreams be dreams
Yesterday you said tomorrow
So just do it
Make your dreams come true
Just do it
Pick 1: http://web.chal.csaw.io:5487 http://web.chal.csaw.io:5488 http://web.chal.csaw.io:5489 http://web.chal.csaw.io:5490
解法
網站是用 Django 寫成,在 http://web.chal.csaw.io:5487/ad-lib/ 有個 textarea 提供使用者寫 template 給 server 用。
介面大致上長這樣子:
Where you want a noun, just put: ““, for a verb: ““, and for an adjective: ““!
先輸入 {{}}
來引發錯誤,可以看到 debug 資訊。
顯示了錯誤的行數跟 template 的 source :
在 Traceback 也有一些資訊:./ad-lib/views.py in index
看起來 mrpoopy
應該是個關鍵, render 後是一個 obj 。
嘗試輸入 {{ mrpoopy }}
得到 <ad-lib.someclass.Woohoo instance at 0x7fa795932638>
。
不過不知道有哪些 attribute ,所以再來應該就是要想辦法得知才能使用。
再觀察一下可發現在 template 裡有 {% load pools_extras %}
,也許 load 進來後有一些東西可以利用。
再來看看 http://web.chal.csaw.io:5487/polls/
有兩個連結,分別是 /polls/2/
跟 /polls/1/
。
隨意嘗試了投票,都會顯示 You are unable to vote at this time.
那麼如果連到 http://web.chal.csaw.io:5487/polls/3/ 看看呢?
出現了 Our infrastructure can't support that many Shias!
錯誤,列出 debug 資訊!
./polls/templatetags/pools_extras.py in checknum
./polls/templatetags/pools_extras.py in check
發現 pools_extras
有 getme
跟 listme
可以用!
回到 http://web.chal.csaw.io:5487/ad-lib/
先看有哪些 attribute 可以用
輸入 {{ mrpoopy|listme }}
再來就用 getme
來執行 __flag__
輸入 {{ mrpoopy|getme:'__flag__' }}
Flag: flag{wow_much_t3mplate}
後記
我不會 Django QAQ,看了一堆官方文件,找了一堆資料,努力把 template tag 的部分看完,最後終於知道 template 跟 view 怎麼運作的了!我看得好辛苦啊啊 _(:з」∠)_
簡單來說就是:Template(template_data).render(RequestContext(request, context_data))
view 在 render 時把 context 資料放進 teamplate 裡,就會得到最後看到的網頁 HTML 了。
寫網誌也遇到一些問題,像是 {{ }}
跟 {% %}
會被 hexo 解析,所以要用 {% raw %} {% endraw %}
把它們包起來,有點麻煩呢 (´・ω・`)