Chybeta

CSAW CTF 2017-Shia Labeouf-off-writeup

CSAW CTF 2017-Shia Labeouf-off-writeup
SSTI Django-debug

根据wp复现。

Task

1
2
3
4
5
6
7
8
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

Solution

用awvs扫了一下,发现Django的debug模式没有关闭

比如访问: http://web.chal.csaw.io:5487/polls/4/ ,给出的DEBUG页面里有很多重要的信息。

./polls/views.py:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
context = {'latest_poll_list': latest_poll_list[1:3]}
return render(request, 'polls/index.html', context)
def detail(request, poll_id):
if int(poll_id) > 3:
return render(request, 'polls/detail.html', {'poll': {"id": int(poll_id), "question": "ahhhhh"}})
poll = get_object_or_404(Poll, pk=poll_id)
return render(request, 'polls/detail.html', {'poll': poll})
def results(request, poll_id):
poll = get_object_or_404(Poll, pk=poll_id)
return render(request, 'polls/results.html', {'poll': poll})

./polls/templatetags/pools_extras.py:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@register.filter(name='getme')
def getme(value, arg):
return getattr(value, arg)
@register.filter(name='checknum')
def checknum(value):
check(value)
@register.filter(name='listme')
def listme(value):
return dir(value)
def check(value):
if value > 2:
raise Exception("Our infrastructure can't support that many Shias!")

http://web.chal.csaw.io:5487/ad-lib/ 页面存在SSTI漏洞。由于Django的DEBUG模式开启,模板会存在内置的tab;\{\% debug \%\}

它会输出页面的debug信息,包括当前的上下文和导入的模块。


对比前面的:

1
Where you want a noun, just put: "{{ noun }}", for a verb: "{{ verb }}", and for an adjective: "{{ adjective }}"!

会注意到一个与众不同的变量/模块mrpoopy

考虑到前面我们通过报错获取到的部分代码,在./polls/templatetags/pools_extras.py中,有这样一个过滤器

1
2
3
@register.filter(name='listme')
def listme(value):
return dir(value)

当我们传入的变量为:mrpoopy | listme

后端会调用dir(mrpoopy)并返回。

./polls/templatetags/pools_extras.py,还有另外一个过滤器

1
2
3
@register.filter(name='getme')
def getme(value, arg):
return getattr(value, arg)

当我们传入:\{\{mrpoopy|getme:"__flag__"\}\}

经过过滤器,会调用getme(mrpoopy,"__flag__"),也就是调用getattr(mrpoopy,"__flag__"),从而返回mrpoopy的__flag__属性的值。

Refference

微信扫码加入知识星球【漏洞百出】
chybeta WeChat Pay

点击图片放大,扫码知识星球【漏洞百出】

本文标题:CSAW CTF 2017-Shia Labeouf-off-writeup

文章作者:chybeta

发布时间:2017年09月18日 - 13:09

最后更新:2017年09月19日 - 23:09

原始链接:http://chybeta.github.io/2017/09/18/CSAW-CTF-2017-Shia-Labeouf-off-writeup/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。