PHP2Shell 以及 AI 如何影响重要的开源软件_第1页
PHP2Shell 以及 AI 如何影响重要的开源软件_第2页
PHP2Shell 以及 AI 如何影响重要的开源软件_第3页
PHP2Shell 以及 AI 如何影响重要的开源软件_第4页
PHP2Shell 以及 AI 如何影响重要的开源软件_第5页
已阅读5页,还剩21页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

腾讯全球数字生态大会

腾讯安全云鼎实验室腾讯云安全全

.

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论