版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
腾讯全球数字生态大会
腾讯安全云鼎实验室腾讯云安全全
.
PHP25hellandHowAIisImpacting
theSecurityofCriticalOpenSourceSoftware
Hi.mynameisWeilinDu[杜伟霖]
Module=>Authors
<?phpphpcredits();?>
lamaPHPcoredeveloperandacybersecurityfan.Maintainerof:
-ext/zip/*:zipfilesupport
-ext/phar/*:pharfilesupport
-ext/intl/*:PHP'si18nmodule
-ext/readline/*:PHP'sinteractiveshellinterface
5o,wheredoyougetinternalstuffofhowtheteamdealwithit?
ThesecurityteamsponsoredbythePHP
foundationhasbeenworkingperfectlyonthismatter.
Thistalkisreviewedandsupportedbytheinternal
securityteamcontent-wise!We'llgettoitsoon:)
ThePHP
Foundation
HowPHP25hellWorks?
OOM->UAF->RCE?
Oneruntimeservesmanyrequestlifecycles[mod_php&php_fpm]
m5HUTDOWn
Moduleshutdown
mINIT
Modulestartup
Sharedinfrastructure
RequestB
RequestA
RINIT
RINIT
ExecuteapplicationRSHUTDOWN
Releasepersistentstate
ExecuteapplicationRSHUTDOWN
Whatwillhappen,whenthingsaren'tfullycleaned-upbetweenrequests?
RequestBmightsomehowunexpectedlygetRequestA'sstuff!
Toachievethis:firstweneedtoskipclean-UpsfromRequestA[theformerrequest]
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
php_hash_environment();/*WHERETHESESSIONISINITIALIZED!*/
zend_activate_modules();/*EachextensionrunsRINITtoresetitsrequeststate*/
PG(modules_activated)=1;
/*...executetheapplicationscript...*/
/*php_request_shutdown():tear
zend_deactivate_modules();
down/*Each
inreverseorder*/
extension'sRSHUTDOWN;gated
byPG(modules_activated)*/
shutdown_memory_manager();/*ReleasetheentirerequestheapbacktoZendMM(alwaysexecuted)*/
zend_deactivate();/*ZendEngineteardown:destroythesymboltable*/
Thisusuallyworksjust*fine*.
However,whenaOOMistriggered,the
engineisforcedtorunbailouts
(zend_bailouts),whichinourcaseiscaughtinzend_active_modules.
Thebailouttriggersalongjump.
PG(modules_activated)isstill0,andRSHUTDOWNis*skipped*
Secondly,weneedtoskipinitializationfromRequestB[thelatterrequest]
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
Aswecansee.Beforezend_activate_modules.Thereisphp_hash_environment.
php_hash_environment();
zend_activate_modules();PG(modules_activated)=1;
/*WHERETHESESSIONISINITIALIZED!*/
/*EachextensionrunsRINITtoresetitsrequeststate*/
/*...executetheapplicationscript...*/
/*php_request_shutdown():teardowninreverseorder*/
zend_deactivate_modules();/*Eachextension'sRSHUTDOWN;gatedbyPG(modules_activated)*/
shutdown_memory_manager();/*ReleasetheentirerequestheapbacktoZendMM(always
zend_deactivate();/*ZendEngineteardown:destroythesymboltable*/
executed)*/
Iftheformerrequest(RequestA)hasbailedout,
nobodydoesthecleanup.thememoryisamessfulloftreasuresfromRequestA.
Whatif-WecanusethatmemorybeforeRINITinthenextrequest(i.e.inphp_hash_environment)?Willthatcausememorybugs?YES!
Lastthingweneed:“Global”Varsthatcanbealiveacro55RINITandR5HUTDOWn
GlobalcontainerRequestheap
PS(id)zend_string
Sessionglobalsinanon-thread-safebuild
#definePS(v)(psglobals.V)
zendstring*id;
zval
http_session_vars;
Thinkaboutit:AssumewehaveaglobalpointerwhichispointingtoamemoryinRequestAHowever,sinceclean-upsareskipped,thepointerisstillpointingtothatmemoryinrequestBEVENTHEMEMORYITPOINTSTOISNOLONGERUSEABLE!
Now.Let'smovethepuzzlestogether.
TotriggeraUAFweneed:
a.ADOmtoskipcleanupfromRequestAaftermalicious5essionmemoryisset
b.Aglobalpointerthatsurvivesacro55requestthatpointstoainvalidmemoryinA
C.AwaytodereferencethatpointerbeforeRequestBinitialize
a.The0Om
WeneedaOOMaftersessiondataisloadedandbefore
zend_active_modulessoourbailout
canskipclean-ups.Whichmakesthe
perfecttimetobewhentheinterpreterisinterpretingrequests!
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
php_hash_environment();/*WHERETHESESSIONISINITIALIZED!*/
zend_activate_modules();/*EachextensionrunsRINITtoresetitsrequeststate*/
PG(modules_activated)=1;
/*...executetheapplicationscript...*/
/*php_request_shutdown():teardowninreverseorder*/
zend_deactivate_modules();/*Eachextension'sRSHUTDOWN;gatedbyPG(modules_activated)*/zend_deactivate();/*ZendEngineteardown:destroythesymboltable*/
shutdown_memory_manager();/*ReleasetheentirerequestheapbacktoZendMM(alwaysexecuted)*/
a.The0Om
WeneedsomewayshintthememorylimitofaPHPworkerinarelativelysmallrequest.
-ChunkedmultipartwithnoContent-Lengthcanbypassthepre-checkofpost_max_size
-Iffilenameis”,thatfileintherequest
bodywon'tbecountedintomax_file_uploads,
butwestillconstructtheSFILESarrayinmemory.
-Alsoyoucanputamillionheadersinapart:)
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
php_hash_environment();/*WHERETHESESSIONISINITIALIZED!*/
zend_activate_modules();/*EachextensionrunsRINITtoresetitsrequeststate*/
PG(modules_activated)=1;
/*...executetheapplicationscript...*/
/*php_request_shutdown():tear
zend_deactivate_modules();
zend_deactivate();
shutdown_memory_manager();
downinreverseorder*/
/*Eachextension'sRSHUTDOWN;gatedbyPG(modules_activated)*//*ZendEngineteardown:destroythesymboltable*/
/*ReleasetheentirerequestheapbacktoZendMM(alwaysexecuted)*/
b.Adanglingglobalpointer
SincePHP5.4,afeatureknownassession.upload_progressisadded.The
featureisdesignedtosenduploadprogress
fromthefront-endthroughsession.Yes,as
youmaywonder,becausethatinformation
shouldbereadybeforethescriptis
executed,thedeserializationofthatsession
headerhappens*before*RINIT,whichis
wherethevulnerabilityistriggered.
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
php_hash_environment();/*WHERETHESESSIONISINITIALIZED!*/
zend_activate_modules();/*EachextensionrunsRINITtoresetitsrequeststate*/
PG(modules_activated)=1;
/*...executetheapplicationscript...*/
/*php_request_shutdown():tear
zend_deactivate_modules();
zend_deactivate();
shutdown_memory_manager();
downinreverseorder*/
/*Eachextension'sRSHUTDOWN;gatedbyPG(modules_activated)*//*ZendEngineteardown:destroythesymboltable*/
/*ReleasetheentirerequestheapbacktoZendMM(alwaysexecuted)*/
b.Adanglingglobalpointer
AftertheOOM:PS(id)andPS(
http_session_vars)point
intoRequestA
'
s
heap.
PG(modules_activated)staysfalseso
SessionRSHUTDOWNisskipped.
Requestshutdownfreestheheapwhiletheglobalspointerisstillvalid,causing
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
php_hash_environment();/*WHERETHESESSIONISINITIALIZED!*/
zend_activate_modules();/*EachextensionrunsRINITtoresetitsrequeststate*/
PG(modules_activated)=1;
/*...executetheapplicationscript...*/
/*php_request_shutdown():teardowninreverseorder*/
zend_deactivate_modules();/*Eachextension'sRSHUTDOWN;gatedbyPG(modules_activated)*/zend_deactivate();/*ZendEngineteardown:destroythesymboltable*/
adangling
```markdown```
shutdown_memory_manager();/*ReleasetheentirerequestheapbacktoZendMM(alwaysexecuted)*/
globalpointer.
cC.Dereferenceit!
NowRequestAend.RequestBarrived.ItsendsaSessionIDandprogressfield,butnofilepart.WithoutFILE_STARTwejustsimplyrunphp_session_initialize()
*before*RINIT,usingthestaleglobalvariableswejustsetinRequestA.
BOOM!
/*php_request_startup()*/
zend_activate();/*ResetcoreZendEnginestate*/
sapi_activate();
php_hash_environment();/*WHERETHESESSIONISINITIALIZED!*/
zend_activate_modules();/*EachextensionrunsRINITtoresetitsrequeststate*/
PG(modules_activated)=1;
/*...executetheapplicationscript...*/
/*php_request_shutdown():teardowninreverseorder*/
zend_deactivate_modules();/*Eachextension'sRSHUTDOWN;gatedbyPG(modules_activated)*/
zend_deactivate();/*ZendEngineteardown:destroythesymboltable*/
shutdown_memory_manager();/*ReleasetheentirerequestheapbacktoZendMM(alwaysexecuted)*/
```markdown```
Okay.What'snow?
SincetheinvalidmemoryinrequestAthatispointedbythedanglingglobalpointerisverycontrollable.Let'sseehowPHPusethatcontrolledmemory(i.e.thesink)
php_session_rfc1867_callback(MULTIPART_EVENT_END)
php_session_rfc1867_cleanup()
php_sessioninitialize()//HerewefirstaccessPS(id)
php_rshutdown_sessionglobals()
zval_ptr_dtor(PS(
http_session_vars
))
zend_reference_destroy()
zend_arraydestroy()
zend_hash_destroy()
ht->pDestructor(&p->val)TheUAF
-Bysendingafakezend_stringlengthstructure,wecan
lettheenginesplitthatmuchlengthofheapmemoryoutthroughtheSet-Cookieheader.Fromthat,wecanderivethebaseaddressofheap,andfinallyphp's
addresstobypassaslr.
Wecanalsowritemaliciousstuffintophp'ssessionfile.Iftheframeworkthattargetuse(Wordpress,Laravel)
hasaPOPchaintowardsfunctionslikesystem(),wewin!
TheFixondHowAIIsImpacting
Fromthefirstreporttothefinalpatch
PHP25helldisclosureandfixtimeline
2024
DOmriskidentified
Auditfollow-upfinds
theOOMflaw.Noconcrete
exploitpathyet.
30Jul2026
Califauditbegins
PatchthePlanetbringsanotherexternalaudittoPHP.
11Aug
RCEconfirmed
CalifreportsRCEwiththesamerootcause.
Fixbecomestoppriority.
24Aug/185ep
Moreattackvectors
Wizreportson24Aug.
20Dct
Disclosuredisrupted
OpenAladdsvectorson18Sep.
CVEIDsleak.APoC
videofollows.Release
movesforwardoneday.
21Dct,14:00UTC
5ecurityrelease
acrosssupportedbranches.
Originallydueon22Oct.
TwocriticalCVEsfixed
Buthey!Icertainlyheardsomeoneonsocialmediareproducedthiswayearliec.thanyouguysright?
Thehypeof"stupid"irresponsibledisclosingisoutofcontrol
GyberSecuityResearchertn20103
CyberSecurityResearcherin2026
Read
EQ\*jc3\*hps96\o\al(\s\up12(t),e)
EQ\*jc3\*hps96\o\al(\s\up12(h),n)
EQ\*jc3\*hps96\o\al(\s\up12(rought),gineere)
EQ\*jc3\*hps96\o\al(\s\up12(h),d)
EQ\*jc3\*hps96\o\al(\s\up12(een),ass)
EQ\*jc3\*hps96\o\al(\s\up12(re),mb)
ly
codebas
EQ\*jc3\*hps96\o\al(\s\up2147483646(ean),forf)
EQ\*jc3\*hps96\o\al(\s\up2147483646(fin),n)
d3vulnsHeyChathowtoopengd
Thehypeof"stupid"irresponsibledisclosingisoutofcontrol
Before,asecurityresearchtakesalotoftime&effort
Now,anyonecanpromptaAltoclaimthatthey"reproduce"or“find”anyvulnerabilitywithaseeminglyreasonableandfancyproof.
2.Applythestopgap(best-intel,low-risk,rever
sible
)
Inphp
ession.upload_progress.enabled-Off
ReloadPHP-FPMoryourwebserver.Thisclosesbothpaths(session
.c:32
39).
Butwhyisthisharmful?
-Wrongmitigationiswidespread.
-Peoplegettinghorrified.
-Mostoftheanalyzesareslop,causingitdifficulttodoanyfurther
research.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年中药学(中药制剂工艺)专业测试试题及答案
- 2027年湖北省教师招聘考试新课改押题试卷电子版及答案
- 2027年温州市教师招聘考试教师职业道德模拟试卷及答案
- 汝州市2025届四年级数学第二学期期末检测试题(含答案解析)
- 2027年杭州市教师招聘考试班级管理名师押题试卷电子版及答案
- 武汉市蔡甸区2025年三年级数学第二学期期末综合测试试题含答案解析
- 2026年全国范围内计算机基础知识试卷带答案
- 江苏省无锡市新吴区2026年上半年招聘编制外人员模拟试题及答案
- 2026年压弧焊理论模拟试题及参考答案
- 2026年全国范围内儿童安全教育知识竞赛试卷带答案
- CSCO结直肠癌诊疗指南(2026版)
- 高考英语命题分享课件
- 伤口大小测量与记录临床规范指南-伤口护理精准评估与数字化实践
- PETS公共英语二级大纲词汇(超全)
- 第6课 人民当家作主 第1课时 课件(内嵌视频)2026-2027学年道德与法治五年级上册统编版
- 水泥稳定碎石基层监理实施细则
- 2025深圳市龙华区招聘社区网格员辅助行政职业社区综合治理题库
- 产业研究专题系列报告之五:区域篇-江苏省“十五五”产业规划与布局
- GB/T 13237-2026优质碳素结构钢冷轧钢板及钢带
- 唐山市玉田县(2025年)辅警招聘考试题库 (答案+解析)
- 《老年人慢性便秘评估专家共识(2026版)》权威完整解读
评论
0/150
提交评论