Linuxã«ãŒãã«ã®è匱æ§ãåŠäœè«æã®ããŒã¿åéã«ã©ã®ããã«åœ¹ç«ã€ããšãã話
æ°å¹Žåãç§ã¯åœŒãã¹ããŒããã©ã³ã®ç»é¢ã«å ¥åãããžã§ã¹ãã£ãŒã§äººãç¹å®ã§ãããã©ããã調ã¹ãããšã«ããŸããã ç¹å®ã®ãããŒããŒãææžããã§ãããã¿ããã¹ã¯ãªãŒã³å°çšã§ãã ãããç解ããã«ã¯ãå€ãã®ç°ãªããŠãŒã¶ãŒããã®äœåäžãã®ãžã§ã¹ãã£ãŒãåæããå¿ èŠããããŸãã ããã...ã¹ããŒããã©ã³ã§ãã®ããŒã¿ãåéããæ¹æ³ã¯ïŒ
ãã®åé¡ã解決ããæ¹æ³ã«ã€ããŠã話ããŸãã 圌ã¯é·ããŠããšãã ããã§ãããããšã£ãŠããšããµã€ãã£ã³ã°ã§ãïŒ åœŒããã©ããŒããŠãLinuxãAndroidããããã®ã»ãã¥ãªãã£ãããã³ãããã®å éšã«ã€ããŠæ°ããäœããåŠã¶ããšã«èå³ãããããšãé¡ã£ãŠããŸãã ç§ã¯Linuxããã€ã¹ã®ç¬¬äžäººè ã§ã¯ãªãã®ã§ãäžéšã®äººã«ã¯èª¬æãäžå¿ èŠã«è©³çŽ°ã§ããããã«èŠãããããããŸãããããããç§ã®ããæ¹ã§ãããããã»ã¹ã§åŠãã ããšããã¹ãŠè©³ãã説æããŸãã ããã«ãããçµéšã®ããLinuxãŠãŒã¶ãŒãçå€ããããä»ã®ãã¹ãŠã®ãŠãŒã¶ãŒã®ãšã³ããªãŒãããå€ããããã«äžããããšãé¡ã£ãŠããŸãã ã ããã Androidçšã®ã¿ãããã¬ãŒãå®è£ ããæ¹æ³ã¯ïŒ
ãã¹éžæ
[1]ã§è¡ãããããã«ãæãåçŽã§æçœãªè§£æ±ºçã¯ãå¥åã®ã¢ããªã±ãŒã·ã§ã³ãèšè¿°ãããã®äžã§ã®ã¿ãžã§ã¹ãã£ãŒãã©ã¡ãŒã¿ãŒãåéããããšã§ãã ããããããã¯ãŸã£ããé¢çœããªãã¿ã¹ã¯ã§ãã ããã¯åçŽãããããã ãã§ã¯ãããŸããã ããŒã¿åéã1ã€ã®ã¢ããªã±ãŒã·ã§ã³ã«å¶éãããšã ç¹å¥ãªæ¡ä»¶äžã§ã®ã¿çºçãããŠãŒã¶ãŒãžã§ã¹ãã£ã®ããã€ãã®éèŠãªåäœç¹æ§ãèŠéãå±éºããããŸãã ãããã£ãŠããŠãŒã¶ãŒãäœæ¥ããŠããã¢ããªã±ãŒã·ã§ã³ã«é¢ä¿ãªããžã§ã¹ãã£ãåéããããšæããŸããããããè¡ãã®ã¯ããã»ã©ç°¡åã§ã¯ãããŸããã
ã¢ãã€ã«OSã¯ããã¹ã¯ãããOSãããæ¡éãã«ä¿è·ãããŠããŸãã åŸè ãšã¯ç°ãªããã»ãã¥ãªãã£ãšããã»ã¹ã®åé¢ã«ã€ããŠçå£ã«èãããšãã«éçºããããã®ã§ãããåãAndroidã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®ãã¥ãŒå€ã§ãŠãŒã¶ãŒã®ãžã§ã¹ãã£ãŒã远跡ããããšã¯ã§ããŸããã ä»ã®ã¢ãã€ã«OSã§ãåãç¶æ³ã ãšæããŸãã ãããããã¹ãŠãæ¬åœã«ååã«ä¿è·ãããŠããã®ã§ãã¿ããã®åº§æšãååŸããããã«ãLinuxã«ãŒãã«ã®è匱æ§ã®å©ãã«é Œããªããã°ãªããŸããã§ãããïŒ
ããšãã°ãä»ã§ã¯å€ãã®äººããAndroidã¢ã¯ã»ã·ããªãã£ãµãŒãã¹-ãŠãããŒãµã«ã¢ã¯ã»ã¹ãµãŒãã¹ã«ã€ããŠèŠããŠããŸãã é害ãæã€äººã ãæ¯æŽããããAndroidåãã®ããŸããŸãªçš®é¡ã®ããã€ã®æšéŠ¬ãäœæãããããã®ã«äŸ¿å©ã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ãŠãããŒãµã«ã¢ã¯ã»ã¹ã€ãã³ãã«ãµãã¹ã¯ã©ã€ããããŠãŒã¶ãŒãžã§ã¹ãã£ã«é¢ããããŒã¿ãåä¿¡ã§ããŸãã ã©ãããïŒ äœ¿çšããŠããã¹ãŠããã§ã«ããªãã®ããã«æžãããŠããŸãã ããããæ®å¿µãªããããã®ããŒã¿ããå¿ èŠãªãžã§ã¹ãã£ãŒãã©ã¡ãŒã¿ãŒãæœåºããããšã¯ã§ããŸããã
ãŸããå€ãã®ãªãã·ã§ã³ã¯æ®ã£ãŠããŸããã ããšãã°ãéçºè ã®ã¡ãã¥ãŒã«ããã£ã¹ãã¬ã€ã¿ããããšããé ç®ãå«ããããã«ããŠãã ããã
ãã®åŸãã©ã®ãããªã¢ããªã±ãŒã·ã§ã³ã§ãããžã§ã¹ãã£ãŒã®çè·¡ãç»é¢ã«æ®ããŸãã ãããã£ãŠããã®ã³ãŒãã¯å°ãªããšãã¿ããã®åº§æšã«é¢ããæ å ±ã«ã¢ã¯ã»ã¹ã§ããŸãã 圌ã¯ã©ãã§ãã®ããŒã¿ãå ¥æããã®ã ãããïŒ çããæ¢ããŠãAndroidã®ãœãŒã¹ã«çªå ¥ãã ãããèŠã€ããŸã ã
mPointerLocationView
è¡ã«ããã
mPointerLocationView
ãªããžã§ã¯ãã¯ã¿ããã¹ã¯ãªãŒã³ããã®ãã¹ãŠã®å ¥åã€ãã³ã
mPointerLocationView
åŠçã§ããŸãã
ã¯ã©ã¹éå±€ãšåŒã³åºãã°ã©ãã調ã¹ããšãæçµçã«ã¯ãã¹ãŠ
WindowManagerService
ã·ã¹ãã ãµãŒãã¹ã§
registerPointerEventListener
ã¡ãœãããåŒã³åºãããšã«ãªããŸãã
WindowManager
ã€ã³ã¿ãŒãã§ãŒã¹ãä»ããåŸè ã«ãããéåžžã®ã¢ããªã±ãŒã·ã§ã³ã¯ã¡ãœããããªã¢ãŒãã§åŒã³åºãããšãã§ããŸãã ã¢ããªã±ãŒã·ã§ã³ã§
WindowManager
ã«ã¢ã¯ã»ã¹ãããã®ã¡ãœãããåŒã³åºãã ãã§ååã§ããããã«æãããã¢ããªã±ãŒã·ã§ã³ã¯ã·ã¹ãã ããã®åº§æšãåŠçã§ããããã«ãªããŸãã ãã ãã泚æç¹ããããŸããAndroidã§ã¯ãã·ã¹ãã ãµãŒãã¹ãžã®ã¢ã¯ã»ã¹ã¯Binder IPCãä»ããŠæäŸããã察å¿ããAIDLãã¡ã€ã«ã«ããã¡ãœããã®ã¿ãWindowManagerããåŒã³åºãããšãã§ããŸãã æ®å¿µãªããããã®ã¡ãœããã¯AIDLã«å«ãŸããŠããªãããããŠãŒã¶ãŒã¢ããªã±ãŒã·ã§ã³ãããªã¢ãŒãã§åŒã³åºãããšã¯ã§ããŸããã ãã ãããã³ããŒã§ãããä»ã«ãŠãŒã¶ãŒã远跡ããæ¹æ³ãããããªãå Žåã¯ãAndroidãœãŒã¹ãå€æŽããããã€ã¹ã®ãã¡ãŒã ãŠã§ã¢ã«ãžã§ã¹ãã£ãŒãã®ã³ã°ãçŽæ¥è¿œå ããããšãã§ããŸã ã 確ãã«ãç§ãã¡ã®å Žåããã®ãããªãœãªã¥ãŒã·ã§ã³ã¯é©åããŸããã ããŒã¿åéã®ããã«1ã€ã2ã€ã®ããã€ã¹ããã©ãã·ã¥ã§ããŸãããæ°å人ã®ãªãã¿ã®ãªããã¹ããŠãŒã¶ãŒã¯ãã®ãããªã¹ããããèžãããšã¯ãããŸããã ããæ®éçãªæ¹æ³ãå¿ èŠã§ãã
ããŠãããã«ãç§ã¯ä»£æ¿æ段ãèŠã€ããããã«ããããæ段ãè©ŠããŸããããã§ããŸããã§ããã ãã®ãããAndroidã¯Linuxã«ãŒãã«ã«åºã¥ããŠãããå ¥åã·ã¹ãã ã®ã¢ãŒããã¯ãã£ã¯Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³ãšåãã§ãã ã¿ããã¹ã¯ãªãŒã³ãå«ãå ¥åããã€ã¹ã®ãã©ã€ããŒã¯ã
/dev/input/
ã«ããæåããã€ã¹ãä»ããŠãŠãŒã¶ãŒã¹ããŒã¹ã«ããŒã¿ãéä¿¡ããããããèªã¿åãå¯èœã«ããŸãã ãŸãããã©ã€ããŒããçŽæ¥ãå¿ èŠãªãã¹ãŠã®ããŒã¿ãååŸã§ããŸãã座æšãã¿ã€ã ã¹ã¿ã³ããã¿ããé åããžã§ã¹ãã£ãŒã®ã¿ã€ããªã©ãè€æ°ã®èª¿æ»ã«ååã§ãã 確ãã«ããã£ããããããŸããAndroidã§ã¯ããããã®ããã€ã¹ãžã®ã¢ã¯ã»ã¹ã«ã¯ãrootãŸãã¯å ¥åã°ã«ãŒãã«å±ãããŠãŒã¶ãŒãããŸãã Androidã¢ããªã±ãŒã·ã§ã³ã¯ããã®ãããªæš©å©ãèªæ ¢ã§ããªããŠãŒã¶ãŒã®ããã«èµ·åãããŸãã
ãã®ç¶æ³ããæãåºãæ¹æ³ã¯ãã«ãŒãåãããããã€ã¹ã§ããŒã¿ãåéããããã®ã¢ããªã±ãŒã·ã§ã³ãèµ·åããããšã§ãã ãã®ç®çã®ããã« ãã¿ãããã¬ãŒã®2çªç®ã®ããŒãžã§ã³ãäœæããŸãã ã
ãã®ããŒãžã§ã³ã䜿çšããŠããŒã¿ãåéããŸããã å©ããããšæã人ã¯ååã«ããŸãããããããã€ã«ãªã£ãããã€ã¹ã¯ãããã§ããã®ã§ãããŸãåéããŸããã§ããã ã«ãŒããã€ã³ã¹ããŒã«ããã«ããŒã¿ãåéããæ¹æ³ãèŠã€ããå Žåãããé©åãªãã¹ãããã€ã¹ãäœæ¡ããããŸããããã«ãããåæã®ããã«æ°çŸã¡ã¬ãã€ãã®è²ŽéãªããŒã¿ãåŸãããŸãã Linuxã«ãŒãã«ã®1ã€ã®çŽ æŽãããè匱æ§ãããã«åœ¹ç«ã¡ãŸãã
CVE-2016-5195å¥åDirtyCOW
人ã«
ãã®è匱æ§ã®çºèŠãšä¿®æ£ã®æŽå²ã¯ãããèªäœéåžžã«é¢çœããã®ã§ãã 圌女ã¯11幎åã«èª€ã£ãŠçºèŠãããŸãããã決ããŠéããããŸããã§ããã ããã䜿çšããæ¢è£œã®ãšã¯ã¹ããã€ããçºèŠãããåŸã2016幎ã«ã®ã¿åçºèŠããã³ä¿®æ£ãããŸããã ãããã11幎ã®æŽå²ãæã€è匱æ§ããŒããã€ã«å€ãã£ãçç±ã§ãã 泚ç®ãã¹ãã¯ã2.6.22以éã®ãã¹ãŠã®ããŒãžã§ã³ã®ã«ãŒãã«ã«ååšããããšã§ãïŒ ã€ãŸããAndroidã®ãã¹ãŠã®ããŒãžã§ã³ã§ã Androidã»ãã¥ãªãã£éå ±ã§ã¯ããã®è匱æ§ã¯ 2016幎12æã«ç»å ŽããŸãããã€ãŸãããã®æ¥ä»ä»¥éã«ã»ãã¥ãªãã£æŽæ°ããã°ã©ã ãåä¿¡ããããã€ã¹ã§ã®ã¿ä¿®æ£ãããŸããã ããšãã°ãNexus 5ã¯ãä»ã®æ°çŸã®Androidããã€ã¹ãšåæ§ã«ãé²åºãããŸãŸã§ãã
dirtyCOWã¯äœãããŸããïŒ ã€ãŸãããŠãŒã¶ãŒãèªã¿åãå°çšã®ãã¡ã€ã«ãäžæžãã§ããŸãã ãanyããšã¯ããã¡ã€ã«ã·ã¹ãã èªäœãèªã¿åãå°çšã«ããŠã³ããããŠããå Žåã§ãïŒAnythingãæå³ããŸãïŒAndroidã®å Žåã/ systemã»ã¯ã·ã§ã³ã«ã¯ãæãããããã·ã¹ãã ãã¡ã€ã«ãä¿åãããŸãïŒã è匱æ§ã®ã¢ã¯ã·ã§ã³ã®ã¡ã«ããºã ã«é¢ãã詳现ã¯ãäŸãã°ããã«ãããŸã ã èŠããŠããã¹ãããšã¯2ã€ã ãã§ãã æåïŒèªã¿åãå°çšãã¡ã€ã«ã·ã¹ãã ãžã®å€æŽã¯åèµ·ååŸã«æ¶ããŸãã2çªç®ïŒãã¡ã€ã«ãµã€ãºãå€æŽããããšã¯ã§ããŸãããã€ãŸãããã£ã¹ã¯ã¹ããŒã¹ãå æãã以äžã®æžã蟌ã¿ãè¡ãããšã¯ã§ããŸããã
ããŠããã®è匱æ§ã«ãã£ãŠäžããããåã«ãããèªã¿åãå¯èœãªã·ã¹ãã ãã¡ã€ã«ãäžæçã«äžæžãã§ããŸãã ããã¯ç§ãã¡ã®æãåŒãé¢ããŠããããã«æããŸã;ããªãã¯ããªããããããããšãã§ããŸãïŒ ãã ããAndroidã¯ååã«ä¿è·ãããŠããããããã®ä¿è·ãåé¿ããŠç®æšãéæããå¿ èŠããããŸãã
å®è£ ã¢ã€ãã¢
ç§ãã¡ã®ã¿ã¹ã¯ã¯ãå ¥åããã€ã¹ããããŒã¿ãèªã¿åãããšãã§ããéåžžã®ã¢ããªã±ãŒã·ã§ã³ããããã»ã¹ãéå§ããããšã§ãã UID = 0ïŒã«ãŒãïŒã®ãŠãŒã¶ãŒãŸãã¯å ¥åã°ã«ãŒãïŒAndroidã§ã¯GID = 1004ïŒã®ãŠãŒã¶ãŒããéå§ããããã»ã¹ã®ã¿ãå ¥åããã€ã¹ã«ã¢ã¯ã»ã¹ã§ããããšãæãåºãããŠãã ããã
ããšãã°ããã¡ã€ã«
/system/bin/ping
èããŠãã ããã ã»ãŒãã¹ãŠã®Androidããã€ã¹ã«ããããã¹ãŠã®äººãèªã¿åãããã³å®è¡ã§ããŸãã 泚ç®ã«å€ããã®ã¯ããã®ãã¡ã€ã«ã«SUIDããããããããšã§ãã SUIDïŒå®è¡æã«èšå®ãããææè ãŠãŒã¶ãŒID-å®è¡æã«ææè UIDãèšå®ïŒã¯ãLinuxã®ãã¡ã€ã«å±æ§ã®1ã€ã§ãã éåžžãããã»ã¹ã¯ããããéå§ãããŠãŒã¶ãŒã®æš©éãç¶æ¿ããŸãã SUIDããããååšãããšãå®è¡å¯èœãã¡ã€ã«ã®ææè ã®æš©å©ãããã³ãã®UIDãšGIDã§ããã»ã¹ãéå§ã§ããŸãã ãããã£ãŠãpingã®ææè ã¯rootã§ããããããã®ãã¡ã€ã«ã¯rootãšããŠå®è¡ãããŸãã ç§ãåŸãŠãããã®ãåç §ããŠãã ããïŒ pingãdirtyCOWã§æžãæããŠå®è¡ãããšãã³ãŒãã¯ã«ãŒããšããŠå®è¡ãããå ¥åããã€ã¹ãèªã¿åãããšãã§ããŸãïŒ çŽ³å£«ãããã§ãšããç§ãã¡ã¯æåããŸããããã¹ãŠã®å倧ãªä»²éãç§ãã¡ã¯åæããŸãã...ãããã
SELinux
ã¯ããç§ãã¡ã®èšç»ã¯4.2ãŸã§ã®Androidã®ãã¹ãŠã®ããŒãžã§ã³ã§é©ãã»ã©æ©èœããŸãã ããããããæ°ããããŒãžã§ã³ã§ã¯ããããçºçããå¯èœæ§ãããã5.0ããã¯ãããã€ãã®åé¡ãå¿ ãçºçããŸãã æ¬ ç¹ã¯SELinuxïŒSecurity-Enhanced LinuxïŒã§ããããã¯ãæ¢åã®ä»»æã®ããªã·ãŒã«å ããŠå¿ é ã®ã»ãã¥ãªãã£ããªã·ãŒãå®è£ ããã«ãŒãã«ã¢ãžã¥ãŒã«ã§ãã ä»çµã¿ã«ã€ããŠç°¡åã«èª¬æããŸãã åãŠãŒã¶ãŒãããã»ã¹ããã¡ã€ã«ããããã¯ãŒã¯ããŒãããã£ã©ã¯ã¿ãŒããã€ã¹ãªã©ã«ã¯ãããããã»ãã¥ãªãã£ã³ã³ããã¹ãïŒç¹å®ã®ã©ãã«ãè¿œå å±æ§ïŒããããŸãã ã·ã¹ãã ã«ã¯ããŠãŒã¶ãŒãšããã»ã¹ã®ã³ã³ããã¹ãã«åºã¥ããŠèš±å¯ãããæäœãèšè¿°ããäžé£ã®ããªã·ãŒããããŸãã ããªã·ãŒã®ã»ããã«å«ãŸããªããã¹ãŠã®æäœã¯çŠæ¢ãããã·ã¹ãã ã«ãã£ãŠå³å¯ã«æå¶ãããŸãã
ãµãŒãããŒãã£ã®ã¢ããªã±ãŒã·ã§ã³ã¯ãuntrusted_appã³ã³ããã¹ããæã€ããã»ã¹ã§å®è¡ãããŸãã ãã§ã«ã³ã³ããã¹ãã®ååããããã®ãããªããã»ã¹ã«ã¯ã»ãšãã©æš©éããªãããšãããããŸãã
/system/bin/ping
ãã¡ã€ã«ã«ã¯system_fileã³ã³ããã¹ãããããã¯ããSELinuxã¯system_fileãuntrusted_appã³ã³ããã¹ãããå®è¡ããããšãèš±å¯ããŸããã ãããã£ãŠãSUIDããããæã€ä»ã®ã·ã¹ãã ãã¡ã€ã«ã®ããã«ãAndroid 5.0以éã®ã¢ããªã±ãŒã·ã§ã³ããpingãå®è¡ããããšã¯ã§ããŸããã
å®éãSELinuxã®ã³ã³ããã¹ãã¯ããã€ãã®éšåã§æ§æãããŠããŸããããšãã°ãpingã®å Žåãã³ã³ããã¹ãã®å®å šãªåœ¢åŒã¯u:object_r:system_file:s0
ã§ããŠãŒã¶ãŒã®å Žåã¯u:r:untrusted_app:s0
ã§ãã ç§ãã¡ã®å Žåãããã¯åé¡ã§ã¯ãªãã®ã§ãçãã¬ã³ãŒãã䜿çšããŸãã
ä»ã®æ¹æ³
ãã®ãããã·ã¹ãã ã«ã¯ããµãŒãããŒãã£ã®ã¢ããªã±ãŒã·ã§ã³ããèµ·åããããã«å©çšå¯èœãªSUIDããããæã€ãã¡ã€ã«ã¯ãããŸããã ããããããã€ãã®ãã¡ã€ã«ãäžæžãããã·ã¹ãã ã«ãããã«ãŒãèªäœãšããŠå®è¡ããããšã©ããªããŸããïŒ Androidã«ã¯ããµãŒãã¹ãªã©ããããŸãã ããªãã®ã¢ããªã±ãŒã·ã§ã³ããå§ãŸããããã¯ã°ã©ãŠã³ãã§äœãããããã®ã§ã¯ãããŸããã ãµãŒãã¹ã¯ãã·ã¹ãã ã®èµ·åæã«éå§ãããããŒã¢ã³ã§ãã
init.rcãã¡ã€ã«ã«èšè¿°ãããŠãããµãŒãã¹ã®äŸ
ç¹ã«ãã¢ã³ããã€ãã¯ã¯ã©ãã·ã¥ããå Žåã«ãµãŒãã¹ãåèµ·åããŸãã ããã«èå³æ·±ãããšã«ãå€ãã®ãµãŒãã¹ã¯ã«ãŒããšããŠå®è¡ãããŸãã android 6.0.1ã§ã¯ããããã¯voldãhealthãdebuggerdãinstalldãzygoteãªã©ã§ãã ãããŠãã¯ãããã¡ã€ã«
/system/bin/app_process
ïŒå¥åzygoteïŒã¯ããã¹ãŠã®ãŠãŒã¶ãŒãèªã¿åãå¯èœã§ãïŒ
å¥ã®ãã¡ã€ã«ã«èšè¿°ãããŠããZygoteãµãŒãã¹
æ°ããèšç»ã®æŠèŠã¯åŸã ã«æµ®äžããŠããŸãã ãã€ããŒãã§
/system/bin/app_process
ãäžæžãããzygoteãµãŒãã¹ããããããããšãã¢ã³ããã€ãã¯ãããåèµ·åããapp_processãã¡ã€ã«å ã®ã³ãŒãã¯ã«ãŒããšããŠå®è¡ãããŸãã
åé¡ã¯ãæ¥ååãèœãšãæ¹æ³ã§ãã å®éãããã¯ã¿ãããã¬ãŒã®å®è£ ã«ãããŠæãä¿¡é Œã§ããªãç¬éã§ãã ä»
/system/bin/app_process
ããã€ããŒãã§
/system/bin/app_process
äžæžããããšãzygoteã¯ãåç¬ã§ããããããããšããäºå®ã«äŸåããŠããŸãã ãããããããåžžã«æ©èœãããšããä¿èšŒã¯ãããŸããã app_processãã¡ã€ã«ãæžãæãããšãã«äœãèµ·ãããããããŠãããã¯ã©ãã·ã¥ãåŒãèµ·ããå¯èœæ§ããããã©ãããèŠãŠã¿ãŸãããã
ä»®æ³ã¡ã¢ãªãšmmap
Linuxã§ã¯ãåããã»ã¹ã«ç¬èªã®ä»®æ³ã¢ãã¬ã¹ã¹ããŒã¹ããããŸãã ã¹ã¿ãã¯ãããŒããç°å¢å€æ°ãªã©ãããã»ã¹ã«å¿ èŠãªãã¹ãŠã®ããŒã¿ãä¿åãããŸãã ãã®ã¹ããŒã¹ã¯ãã«ãŒãã«ã«ãã£ãŠRAMã®ç©çã¢ãã¬ã¹ã«å€æãããŸãã
ãã®æŠå¿µã®åªããèŠèŠåã
ãã ããåãã¹ããŒã¹ã«ã¯ãããã»ã¹èªäœã®å®è¡å¯èœãã¡ã€ã«ããã®ã€ã³ã¿ãŒããªã¿ãŒããã®äŸåé¢ä¿ããã®ã©ã€ãã©ãªãŒãããã³ããã«å€ãã®ç°ãªããã¡ã€ã«ããããŸãã ããããã¹ãŠãRAMã«ä¿åããã®ã¯ãã£ãããªãã®ã§ãLinuxã«ã¯RAMããŸã£ããç¡é§ã«ããã«ããã»ã¹ã¡ã¢ãªã«ãã¡ã€ã«ãããŒãããããã®éåžžã«ãšã¬ã¬ã³ããªã¡ã«ããºã ããããŸãã ããã¯ãã¡ã¢ãªã«ãããããããã¡ã€ã«ããŸãã¯ã¡ã¢ãªã«åæ ããããã¡ã€ã«ãšåŒã°ããŸãã ã«ãŒãã«ã¯ããã»ã¹ã®ã¢ãã¬ã¹ç©ºéã«ãã¡ã€ã«ã®å 容ãå«ãããŒãžãäœæããŸãããå®éã«ã¯ããã®ä»®æ³ããŒãžã¯ã«ãŒãã«ã«ãã£ãŠRAMã«å€æãããã®ã§ã¯ãªããçŽæ¥ãã£ã¹ã¯ã«å€æãããŸãã ã€ãŸããããã»ã¹ã¯ãã¡ã€ã«ã®å 容ã䜿çšããŠãå²ãåœãŠãããã¡ã¢ãªã®å€§ããªéšåã§åäœããŸãããå®éã«ã¯ãã£ã¹ã¯ãžã®ãã€ãã®èªã¿åããŸãã¯æžã蟌ã¿ãè¡ããŸãã ïŒã¡ãªã¿ã«ãdirtyCOWã®ä»çµã¿ãèªãã§ããªãå Žåã¯ãã¡ã¢ãªã«åæ ããããã¡ã€ã«ãžã®ãã«ãã¹ã¬ããã¢ã¯ã»ã¹ã®ãã°ã«åºã¥ããŠããŸãïŒã
ãã®ãåæ ãããã圢åŒã§ããã®å®è¡å¯èœãã¡ã€ã«ãããã»ã¹ã¡ã¢ãªã«ä¿åãããŸãã éšåçã«ã¡ã¢ãªã«ããŒããããŸãããã»ãšãã©ã¯ãã£ã¹ã¯ã«æ®ããŸãã ãããã£ãŠããã¡ã€ã«ã®å€æŽã¯ããã«ããã»ã¹ã¡ã¢ãªã«è¡šç€ºãããŸãã å®è¡å¯èœãã¡ã€ã«ã眮æããåŸãããã»ã¹ãã¡ã¢ãªãã次ã®åœä»€ãããŒããããšããŸãã é«ã確çã§ãããã¯ãäžé©åã«ãèœäžããããã»ã¹ãèœäžãããããåãçµæã«ãªã£ãŠãŽãã«ãªãããšãããããŸãã ãã ããå®è¡ãã¡ã€ã«ã®çœ®æäžã®ããã»ã¹ã¯ãselectïŒïŒãreadïŒïŒããŸãã¯waitpidïŒïŒãå®è¡ããããšã«ãããããããã³ã°åŒã³åºãã§ããã³ã°ãããããšããããŸãã ãã®å Žåãã³ãŒã«ãçµäºãã圌ãååšãç¶ãããŸã§ã圌ã«ã¯äœãèµ·ãããŸããã å®è¡å¯èœãã¡ã€ã«ã眮ãæããåŸã®ããã»ã¹ã®åç¶ã«ã¯ãããããä»ã®ã·ããªãªããããŸãããLinuxã§ã®ç§ã®çµéšãå°ãªãããããããã«æ £ããŠããŸããã
ãã¡ã€ã«ãäžæžããããšãã«äœãèµ·ãããããããŠãããããã»ã¹ãã¯ã©ãã·ã¥ãããïŒãŸãã¯ãããªãïŒæ¹æ³ãèŠã€ããŸããã åèµ·åããããã®ããä¿¡é Œæ§ã®é«ãæ¹æ³ãæãã€ããããšããªãã®ã§ããã®ãŸãŸã«ããŠãããŸãããã ããã«ããã®æ¹æ³ã¯éåžžã«ããŸãæ©èœããŸãïŒãµã ã¹ã³ããã€ã¹ã¯ãç¬èªã®ãµã ã¹ã³ããžãã¯ãåããŠãããzygoteã¯å®è¡å¯èœãã¡ã€ã«ãäžæžãããŠãèœäžããŸããããããã©ã®ããã«æ©èœãããã¯ãŸã ããããŸããïŒã
zygoteã«æ»ããŸãã ä»ã®ãã€ããªãã¡ã€ã«ã§ç°¡åã«çœ®ãæããããšãã§ãããããã»ã©éèŠã§ãªããµãŒãã¹ãšã¯äœã§ããïŒ Zygoteã¯ããã¹ãŠã®Androidã¢ããªã±ãŒã·ã§ã³ãçæããããã»ã¹ã§ãã åãã¯ã©ãã·ã¥ã®ã¯ã©ã³ã®ã¢ã€ã³ã³ãã¯ãªãã¯ãããšãzygoteã¯forkïŒïŒã䜿çšããŠããã»ã¹ã®ã³ããŒãäœæãããã®ã³ããŒã§ç®çã®ã¢ããªã±ãŒã·ã§ã³ãèµ·åããŸãã ããã¯ããªãœãŒã¹ãç¯çŽããèµ·åãé«éåããããã«è¡ãããŸãã zygoteã殺ããšããã¹ãŠã®Androidã¢ããªã±ãŒã·ã§ã³ã¯åœŒã®åŸã«èœã¡ãŸãã ãã®ç¶æ³ã¯ãã¿ãããã¬ãŒããæå³ã奪ããŸãã ã¬ã³ã¬ããã«ã¹ã¿ã ãžã§ã¹ãã£ãŒãåéããçç± å¹žããªããšã«ããã®åé¡ã¯ç°¡åã«åé¿ã§ããŸãã
æªé
ãŸããzygoteãã¯ã©ãã·ã¥ããå Žåããã¹ãŠã®Androidã¢ããªã±ãŒã·ã§ã³ãçªç¶çµäºããã®ã¯ãªãã§ããïŒ çµå±ã®ãšãããLinuxã®èŠªããã»ã¹ã®æåŸã§ãåã¯åŒãç¶ãæ£åžžã«åäœããinitã¯æ°ãã芪ã«ãªããŸãã ããããå®éã«ã¯ãèµ·åæã«zygoteãæ°ããããã»ã¹ã®ã°ã«ãŒããŸãã¯æ°ããã»ãã·ã§ã³ãçæããŸãã ãã®ã»ãã·ã§ã³ã§ã¯ããã¹ãŠã®Androidã¢ããªã±ãŒã·ã§ã³ãAndroidã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®åããã»ã¹ããããã®åããã»ã¹ãªã©ãèµ·åãããŸãã ã»ãã·ã§ã³ãçæããããã»ã¹ãçµäºãããšãåãã»ãã·ã§ã³å ã®ãã®åå«ã®åå²ããªãŒå šäœãããã§çµäºããŸãã ãããã£ãŠãã¿ãŒããã«ãšãã¥ã¬ãŒã¿ãŒãéãããšãããã§å®è¡ãããŠãããã¹ãŠã®ããã»ã¹ãçµäºããŸãã ããããzygoteããã¹ãŠã®Androidã¢ããªãã¯ã©ãã·ã¥ããå Žåã«ã¯ã©ãã·ã¥ããçç±ã§ãã
äžèšã®ããã«ãããã¯ããã€ãã®åé¡ãåŒãèµ·ãããŸãã æåã®ãã®ã ãã€ããŒããèµ·åãããã¢ããªã±ãŒã·ã§ã³ã匷å¶çµäºãããåŸã誰ãapp_processããã®å Žæã«è¿ããŸããïŒ ãããŠ2ã€ç®ã app_processãæ»ã£ãåŸããã€ããŒããå®è¡ãããŸãŸã«ããæ¹æ³
ã»ãã·ã§ã³ã®çµäºåŸãããã»ã¹ãæ©èœãç¶ããããã«ã¯ãçŸåšã®ã»ãã·ã§ã³ãã解æŸããå¿ èŠããããŸã...æ°ããã»ãã·ã§ã³ãèªçããŸããïŒ ããã¯ãsetsidïŒïŒã·ã¹ãã ã³ãŒã«ã䜿çšããŠè¡ãããŸãã ãããããã£ãšããªãããŒãªããšãã§ããŸãã 1åã®åŒã³åºãã§ãæ°ããããã»ã¹ãéå§ããçŸåšã®ã»ãã·ã§ã³ããåãé¢ããæšæºå ¥åºåã¹ããªãŒã ããåãé¢ãããšãã§ããŸãã ãã®éæ³ã®åŒã³åºãã¯daemonïŒïŒãšåŒã°ããforkïŒïŒãšsetsidïŒïŒã®åãçµã¿åãããŠãããŒã¢ã³èªäœãå°çã®ç£ç©ã§ããããã芪ãã»ãã·ã§ã³å šäœã§å°çã«èœã¡ãŠãåäœããæ°ããããŒã¢ã³ããã»ã¹ãäœæããŸãã
ããŒã¢ã³ïŒïŒã䜿çšãããšãäžèšã®åé¡ã¯äž¡æ¹ãšãå®å šã«è§£æ±ºãããŸãã ãŸããã¢ããªã±ãŒã·ã§ã³å ã«ããŒã¢ã³ãäœæããŸãã zygoteã®èœäžåŸãåç¶ããããããã€ããŒãã§app_processãäžæžãããéå§ããã®ãåŸ ã£ãŠããapp_processãè¿ãããšãã§ããŸãã
åçã®æåã®åé¡ã®è§£æ±ºç
2çªç®ã¯åãæ¹æ³ã§è§£æ±ºãããŸããã·ã¹ãã ããã€ããŒããéå§ãããšããã®äžã«å¥ã®ããŒã¢ã³ãäœæããŸããããã¯app_processã®åŸ©å åŸã«æ©èœããŸãã ããããããã§ããããïŒ å®è¡å¯èœãã¡ã€ã«ãäžæžããããšãã«ããã»ã¹ã®ã¯ã©ãã·ã¥ããã£ã³ã»ã«ãã人ã¯ããŸããã§ãããæªéã§ãããä¿åãããŸããã å®è¡äžã®ãã¡ã€ã«ã®å®è¡äžã®çœ®æã®ã¿ãããããä¿åãããŸãã ãªããããããªãã®ã§ããïŒ
å®è¡ïŒïŒ
execveã®æ¬è³ªïŒïŒ
ãã®ã·ã¹ãã ã³ãŒã«ã¯ãçŸåšã®ããã»ã¹ãæ°ããããã»ã¹ã«çœ®ãæããåŒæ°ã§æå®ããããã€ããªãã¡ã€ã«ãèµ·åããŸãã ããã«ã€ããŠã¯ã察å¿ããmanã§è©³ããèªãããšãã§ããŸãã
ãšããã§ãLinuxã®ã»ãšãã©ãã¹ãŠã®ããã»ã¹ã¯forkïŒïŒ+ execveïŒïŒã«ãã£ãŠèµ·åãããŸãã
ãã®çµæãã·ã¹ãã ã¯ãã€ããŒããèµ·åããŸãã ããŒã¢ã³ïŒïŒãšexecveïŒïŒãå®è¡ããŠå¥ã®binarãèµ·åããexec_payloadãšåŒã³ãŸãã ãã®åŸãapp_processããã®å Žæã«æ»ããŸãããexec_payloadã¯åŒãç¶ãæ©èœããŸãã
åçã®2çªç®ã®åé¡ã®è§£æ±ºç
ããã§ãéåžžã®ã¢ããªã±ãŒã·ã§ã³ããã«ãŒããšããŠããã»ã¹ãéå§ããæ¹æ³ãããããŸããã ããæ£ç¢ºã«ã¯ãã·ã¹ãã ã®ååã匷å¶çµäºããŠãã«ãŒããšããŠã³ãŒããå®è¡ãããã¹ãŠãããã®ãŸãŸãè¿ãããã«ããæ¹æ³ã§ãã ããããå°é£ã¯ããã ãã§ã¯çµãããŸããã SELinuxãèŠããŠããŸããïŒ ãããã£ãŠã圌ã¯ã©ãã«ãè¡ããããŸã å€ãã®æäœã®å®è¡ãèš±å¯ããŠããŸããã
SELinux [2]
SELinuxã³ã³ããã¹ãã®èŠ³ç¹ããéå§ããåŸãexec_payloadãã©ã®ãããªç¶æ³ã«ãªãããæ€èšããŠãã ããã Zygoteã®ã³ã³ããã¹ãã¯åãã§ã-zygoteã Exec_payloadã¯ãèµ·åæã«ãããç¶æ¿ããŸãã
/dev/input
å ã®ãã£ã©ã¯ã¿ãŒããã€ã¹ã«ãç¬èªã®ã³ã³ããã¹ãinput_deviceããããŸãã ãããŠãäºæ³éããSELinuxã¯ãzygoteã³ã³ããã¹ããæã€ããã»ã¹ãinput_deviceã³ã³ããã¹ããæã€ãã¡ã€ã«ã«ã¢ã¯ã»ã¹ããããšãèš±å¯ããŸããã SELinuxãåã³å®è¡ããããã«ãæ¬åœã«ãã®ããã«ãã¹ãŠãè¡ã£ãã®ã§ããããïŒ
ããã§ããªãã ä»åã¯ç¶æ³ã¯ãŸã å°ãè¯ããªã£ãŠãããç§ãã¡ã¯ããå€ãã®æš©å©ãæã£ãŠããŸãã zygoteã¯ãã¹ãŠã®Androidã¢ããªã±ãŒã·ã§ã³ãå®è¡ããããšãèŠããŠããŸããïŒ ãããã£ãŠãzygoteã³ã³ããã¹ããæã€ããã»ã¹ã«untrusted_appã³ã³ããã¹ãïŒãŸãã¯çµã¿èŸŒã¿ã¢ããªã±ãŒã·ã§ã³ã®å Žåã¯platform_appããŸãã¯çç±ããããisolated_app ...ïŒãæã€åãããå Žåãzygoteã«ã¯selinuxã³ã³ããã¹ããå€æŽããæš©å©ãããããšãæå³ããŸãã å ¥åããã€ã¹ã«ã¢ã¯ã»ã¹ã§ããç®çã®ã³ã³ããã¹ããèŠã€ããããšã¯æ®ã£ãŠããŸãã èŠã€ããããã§ããããã¯ã·ã§ã«ã§ãã
ã·ã§ã«ã¯ïŒåãååã®ã³ã³ããã¹ããæã€ïŒãŠãŒã¶ãŒã§ããã ADB ïŒAndroidãããã°ããªããžïŒãä»ããŠãªã¢ãŒãã§Androidããã€ã¹ã«ã¢ã¯ã»ã¹ãããšããã¹ãŠã®ã³ãã³ããå®è¡ãããŸãã 圌ã¯ãinitãŸãã¯ã«ãŒãã«ã³ã³ããã¹ãã䜿çšããrootãããæš©éã¯äœããªããŸãããAndroidã¢ããªã±ãŒã·ã§ã³ãããã¯ããã«å€ãã®æš©éãæã£ãŠããŸãã ç¹ã«ãã·ã§ã«ãŠãŒã¶ãŒã¯èªã¿åãããã³æžã蟌ã¿çšã®å ¥åããã€ã¹ã«ã¢ã¯ã»ã¹ã§ããŸãã ã³ã³ããã¹ããzygoteããshellã«å€æŽããå ¥åã°ã«ãŒãã«èªåãè¿œå ããããšã«ãããexec_payloadã¯æçµçã«åæãããŠããå ¥åããã€ã¹ã«ã¢ã¯ã»ã¹ã§ããããã«ãªããŸãã
zygoteããã·ã§ã«ã³ã³ããã¹ããååŸãã
#ifdef __aarch64__ void * selinux = dlopen("/system/lib64/libselinux.so", RTLD_LAZY); #else void* selinux = dlopen("/system/lib/libselinux.so", RTLD_LAZY); #endif if (selinux) { void* getcon = dlsym(selinux, "getcon"); const char* error = dlerror(); if (!error) { getcon_t* getcon_p = (getcon_t*) getcon; char* secontext; int ret = (*getcon_p)(&secontext); void* setcon = dlsym(selinux, "setcon"); const char* error = dlerror(); if (!error) { setcon_t* setcon_p = (setcon_t*) setcon; if ((*setcon_p)("u:r:shell:s0") != 0) { LOGV("Unable to set context: %s!", strerror(errno)); } (*getcon_p)(&secontext); LOGV("Current context: %s", secontext); } } dlclose(selinux); } else { LOGV("SELinux not found."); }
ãããŠæåŸã«ãæåŸã®åé¡ã解決ããããšãæ®ã£ãŠããŸããïŒã·ã¹ãã ã®ååãèœã¡ãåŸã«åèµ·åãããïŒã¢ããªã±ãŒã·ã§ã³ãšããŒã¿ãèªã¿èŸŒãããŒã¢ã³ãšã®éã§ããŒã¿ã亀æããæ¹æ³ã¯
/dev/input/event[X]
ïŒããã€ãã®ãªãã·ã§ã³ãå¯èœã§ããæ®å¿µãªããããããã®ãã¡æãé©åãªãã®ïŒUNIXãœã±ãããFIFOïŒã¯å©çšã§ããŸããïŒéªéãªSELinuxïŒïŒã1ã€ã®ããã»ã¹ã§SDã«ãŒãã«ããŒã¿ãæžã蟌ã¿ãå¥ã®ããã»ã¹ã§ããããããŒã¿ãèªã¿åãããšã¯æ®ããŸããæãã¯ãŒã«ãªãªãã·ã§ã³ã§ã¯ãããŸããããããã§ãã§ããããã«ãamãã«ãã€ã³ãŠãŒãã£ãªãã£ã䜿çšããŠãç¹å¥ãªç®çã§ã¢ããªã±ãŒã·ã§ã³ã«ããŒã¿ãéä¿¡ã§ããŸãïŒå®éãããã¯Activity Managerã®ã³ãã³ãã€ã³ã¿ãŒãã§ã€ã¹ã§ãïŒãããããç§ãèããŠããªãä»ã®æ¹æ³ããããŸãã
ããŒã¿åéã®ãæåãæ¹æ³
ãšã¯ã¹ããã€ãã䜿çšããŠããŸããŸãªç®æšãéæããããšã¯éåžžã«ä¿¡é Œã§ããŸãããããããããŒãžã§ã³ã®AndroidãæèŒãããã¹ãŠã®ããã€ã¹ã§åäœããæ®éçãªãšã¯ã¹ããã€ãããŒã¹ã®ãœãªã¥ãŒã·ã§ã³ãå®è£ ããããšã¯ã»ãšãã©äžå¯èœã§ããç§ã®ã¿ãããã¬ãŒã®å®è£ ãäŸå€ã§ã¯ãããŸããã app_processãæžãæããåŸãzygoteãã©ãã«ã§ãèœã¡ãããã§ã¯ãããŸãããããããããã¹ãŠã®SELinuxããã€ã¹ã§ã¯ãã³ã³ããã¹ããzygoteããã·ã§ã«ããã€ããŒãã«å€æŽã§ããããã§ã¯ãããŸããããããŠãç§ã«ã¯ãŸã ç¥ãããŠããªãä»ã®èœãšãç©Žã確ãã«ãããŸãã
ãã ããç§ãã¡ã®ç®æšã¯å ¥åã€ãã³ããåéããããšã§ãããã¹ããŠãŒã¶ãŒãããã«ããã€ã¹ãæäŸããããšã«åæããå Žåãã·ã³ãã«ã§100ïŒ ãŠãããŒãµã«ãªå¥ã®ãœãªã¥ãŒã·ã§ã³ãå°å ¥ã§ããŸãã確ãã«ããããèµ·åããã«ã¯ãããã€ãã®æåæäœãè¡ãå¿ èŠããããŸãã adbã§exec_payloadããã£ã¬ã¯ããªã«ããããããå Žå
/data/local/tmp
ïŒã·ã§ã«ãã¢ã¯ã»ã¹ã§ããå ŽæïŒãããããèµ·åããŸã-ããŒã¢ã³ã¯ãã¢ããªã±ãŒã·ã§ã³ãèµ·åããŠããããã«åäœãå§ããŸããå¯äžã®ããšã¯ãUIDãç°ãªãïŒ0ã§ã¯ãªã2000ïŒããšã§ãããããã¯å ¥åããã€ã¹ãžã®ã¢ã¯ã»ã¹ã«ã¯åœ±é¿ããŸããããã®ãããã¿ãããã¬ãŒã®3çªç®ã®ããŒãžã§ã³ïŒçŸåšãé ã«æµ®ãã³ãŸãïŒã§ã¯ãå¥ã®ããã¯ã¢ãããªãã·ã§ã³ãšããŠã«ãŒãåãããããã€ã¹ã§å®è¡ããå¯èœæ§ãæ®ããªãããæåŸã®æ段ãšããŠãã®ãããªãªãã·ã§ã³ãæäŸããŸãã
ãã®ä»ã®DirtyCOW Androidã¢ããªã±ãŒã·ã§ã³
ãã¡ããããšã¯ã¹ããã€ãã¯åžžã«ç§åŠã®ãããªé«è²Žãªç®çã«äœ¿çšãããããã§ã¯ãããŸããïŒã»ãšãã©äœ¿çšãããŸããïŒããããŠããããããäžèšã®ç¹æš©ãšã¹ã«ã¬ãŒã·ã§ã³æ¹æ³ã䜿çšããŠãDirtyCOWãä»ã®ã¢ããªã±ãŒã·ã§ã³ãèŠã€ããããšãã§ããã®ãçåã«æãã§ãããããåãã®ããã«ãããã¯å®å šãªã«ãŒãã§ã¯ãªããããæ©èœã¯éåžžã«éãããŠããŸããããã«ããããããããããã®æš©å©ã§ãããããè¡ãããšãã§ããŸãããŸããå ¥åããã€ã¹ãžã®ã¢ã¯ã»ã¹ã䜿çšããŠãã¹ã¯ãŒããçãããšãã§ããŸãïŒã¿ãããã¬ãŒã§ã¯ããäžæåæ¢ããã¿ã³ãäœæããŠããã®ããŒã¿ãèªåã®ãã®ã«ãªã£ãããééã£ãæã«æž¡ããªãããã«ããŸãïŒ 2çªç®ïŒamãpmãªã©ã®çµã¿èŸŒã¿ãŠãŒãã£ãªãã£ã䜿çšã§ããŸããããã«ãããã¢ããªã±ãŒã·ã§ã³ãå¯ãã«ã€ã³ã¹ããŒã«ããã³ã¢ã³ã€ã³ã¹ããŒã«ã§ããŸãã次ã«ãAmã䜿çšãããšãçŸåšå®è¡äžã®ã¢ã¯ãã£ããã£ã«é¢ããæ å ±ãä»ã®ã¢ã¯ãã£ããã£ã®äžã§ååŸã§ããŸããéè¡ã®ããã€ã®æšéŠ¬ã«æé©ãªæ©èœãããã¯ãéè¡æ¥åã¢ããªã±ãŒã·ã§ã³ãéå§ãããšãã«ãç¬èªã®ãã°ã€ã³ãã©ãŒã ã®äžã«æç»ããŸããäžè¬ã«ãdirtyCOWã¯ãä»ã®ããŒã«ãšåæ§ã«ãè¯ãç®çãšããã§ãªãç®çã®äž¡æ¹ã§ããŸããŸãªç®çã«äœ¿çšã§ããŸãã
æåŸã®ããªãã¯
çµè«ãšããŠãæãèå³æ·±ãã®ã¯ãããç¹æš©ã®ãããŠãŒã¶ãŒããã³ãŒããå®è¡ããå¥ã®æ¹æ³ã§ããçªç¶å¿ èŠã«ãªã£ãå ŽåãmediaserverãnetdãdebuggerdããŸãã¯ãã®ä»ã®ãµãŒãã¹ã®ç¹æš©ã§ã³ãŒããå®è¡ã§ããŸãã
å®éãå®è¡æã«ä»»æã®ã³ãŒããå®è¡ããããã«å®è¡å¯èœãã¡ã€ã«ãäžæžãããå¿ èŠã¯ãããŸãããããã¯ããã®ãã¡ã€ã«ãèªã¿åãæš©éããªãå ŽåããŸãã¯ãã¡ã€ã«ã®ãµã€ãºãå°ããããŠå€å°æçšãªãã®ã§äžæžãã§ããªãå Žåãéåžžã«è¯ããã¥ãŒã¹ã§ãã
ããªãã¯ã®èŠç¹ã¯éåžžã«ã·ã³ãã«ã§ãšã¬ã¬ã³ãã§ãã Androidã®ã»ãŒãã¹ãŠã®å®è¡å¯èœãã¡ã€ã«ã¯ãlibcutils.soã·ã¹ãã ã©ã€ãã©ãªã«äŸåããŠããŸãããããŠãå®è¡å¯èœãã¡ã€ã«ãå®è¡ãããšããã®ã©ã€ãã©ãªãããã»ã¹ã¡ã¢ãªã«ããŒããããŸãã ELF圢åŒã®å ±æã©ã€ãã©ãªã®ç¹æ§ã¯ãç¹å¥ãªã»ã¯ã·ã§ã³
.init
ãšãæã£ãŠããããš
.init_array
ã§ãããããã®ã»ã¯ã·ã§ã³ã«ã¢ãã¬ã¹ãé 眮ãããé¢æ°ã¯ãã©ã€ãã©ãªãããã»ã¹ã«ããŒãããããšãã«å®è¡ãããŸãããããã£ãŠãã»ã¯ã·ã§ã³å ã®é¢æ°ã䜿çšããŠã©ã€ãã©ãªãã³ã³ãã€ã«ã
.init_array
ããã¡ã€ã«
/system/lib/libcutils.so
ãäžæžããããšãããã»ã¹ã«ããŒãããããšããã®é¢æ°ã¯ããã»ã¹ã®ç¹æš©ã§å®å šã«å®è¡ãããŸãã
__attribute__((constructor)) void say_hello() { payload_main(); }
ã³ã³ã¹ãã©ã¯ã¿ãŒå±æ§ãæã€é¢æ°ã¯ãã³ã³ãã€ã«æã«
.init_array
ã©ã€ãã©ãªã»ã¯ã·ã§ã³ã«é 眮ãããŸãã
ãããããã®ãœãªã¥ãŒã·ã§ã³ã¯ã©ãã»ã©æ®éçã§ããããïŒAndroidã®ç°ãªãããŒãžã§ã³ã®ããã»ã¹ãããã®éèŠãªã©ã€ãã©ãªã§ç¹å®ã®æ©èœãèŠã€ããããšãã§ããªããšããäºå®ã«åé¡ãæ±ããããšã¯æã¿ãŸãããå®éãlibcutilsèªäœã®æžãæãã¯éåžžã«å±éºã§ãããããã圌ã¯ãŸããä»ã®ã©ã€ãã©ãªã«äŸåããŠããŸãã確ãã«ãä»ã®ã©ã€ãã©ãªã¯éåžžã«éèŠã§ãããç§ã¯ãããã«è§ŠããããããŸãããããã§ã¯ãããå°ãåçŽã§ã¯ãããŸãããããããšã¬ã¬ã³ããªããã¯ãå©ãã«ãªããŸãã
DT_SONAMEâDT_NEEDED
ELF圢åŒã®åã©ã€ãã©ãªã«ã¯ãã©ã€ãã©ãªã«å¿ èŠãªãã¹ãŠã®ãªã³ã«ãŒæ å ±ãå«ãããããŒããããŸãã圌女ã®äŸåé¢ä¿ãšååã«é¢ããæ å ±ã«èå³ããããŸããããã¯ãã¹ãŠãããšãã°æ¬¡ã®ã³ãã³ãã䜿çšããŠåŠç¿ã§ããŸã
objdump -p
ã
: [.....] STRTAB 0x00001660 STRSZ 0x000014ec GNU_HASH 0x00002b4c NEEDED liblog.so NEEDED libc++.so NEEDED libdl.so NEEDED libc.so NEEDED libm.so SONAME libcutils.so FINI_ARRAY 0x0000fbf0 [.....]
ãããlibcutils.soããããŒã¹ããããã®å€èŠ³ã§ãã NEEDEDãã£ãŒã«ãã«ã¯ãlibcutilsèªäœãšåãããã»ã¹ã§ãªã³ã«ãŒã«ãã£ãŠããŒããããäŸåé¢ä¿ãå«ãŸããŠããŸããã©ã€ãã©ãªã®ååãå«ãSONAMEãã£ãŒã«ãã«æ³šæããŠãã ããããªã³ã«ãéåžžã®æäœã«ãããå¿ èŠãšããªãããšã¯æ³šç®ã«å€ããŸã;ããã¯ãã¡ã€ã«åã§ã©ã€ãã©ãªãæ€çŽ¢ããŸããã§ã¯ãELFããããŒã解æããŠããã®äžèŠãªãã£ãŒã«ãã®ä»£ããã«å¥ã®äŸåé¢ä¿ãæ¿å ¥ããŠã¿ãŸãããïŒããã»ã©éèŠã§ã¯ãªãã·ã¹ãã ã©ã€ãã©ãªããïŒããã§æ³šæããå¿ èŠããããŸããæ°ããäŸåé¢ä¿ã®ååã®é·ãã¯ãã©ã€ãã©ãªèªäœã®ååã®é·ããè¶ ããŠã¯ãªããŸããïŒãããã£ãŠãlibcã§ã¯ãªãlibcutilsãéžæããŸããïŒã幞ããªããšã«ãåªç§ãªåè£ããããŸãïŒlibmtp.soã倧ããïŒæ°åãããã€ãïŒãçãååã§ãMTPãããã³ã«ã䜿çšããŠãã¡ã€ã«ã転éããããã«USBçµç±ã§ã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããå Žåã«ã®ã¿å¿ èŠã§ããã€ãŸãã2åéããããªãã§çããããšãã§ããŸããæ®ãã¯æè¡ã®åé¡ã§ãã ELFãã¡ã€ã«ã解æããã©ã€ãã©ãªåãæã€ãã£ãŒã«ããèŠã€ãããã£ãŒã«ãã®ã¿ã€ããDTââ_SONAMEïŒ0xEïŒããDT_NEEDEDïŒ0x1ïŒã«å€æŽããååãlibmtp.soã«å€æŽããŸããã§ããïŒ Libcutils.soã«ã¯æ°ããäŸåé¢ä¿ããããŸãã
: [.....] STRTAB 0x00001660 STRSZ 0x000014ec GNU_HASH 0x00002b4c NEEDED liblog.so NEEDED libc++.so NEEDED libdl.so NEEDED libc.so NEEDED libm.so NEEDED libmtp.so FINI_ARRAY 0x0000fbf0 [.....]
ããã§åé¡ã¯å°ãããªããŸãïŒlibmtp.soãèªç±è£éã§æžãçŽããã³ãŒããå®è¡ããããã«ããã»ã¹ãåèµ·åããŸããããããzygoteãããããããããšã§å®è¡ã§ããŸããããã¯ãAndroidã¢ããªã±ãŒã·ã§ã³ã ãã§ãªããå€ãã®ã·ã¹ãã ãµãŒãã¹ãããã«è¿œéããããã§ãã
Android.Loki.28.originãŠã€ã«ã¹ã®äœè ã«æè¬ãã䟡å€ããããŸãããã®äœè ãããã©ã€ãã©ãªã«äŸåé¢ä¿ãå®è£ ããããšã§ãã®çŽ æŽãããã¢ã€ãã¢ãåŸãŸããã
çµè«ã®ä»£ããã«
Androidã®ãšã¯ã¹ããã€ããOSã»ãã¥ãªãã£ã®æçœãªè匱æ§ã䜿çšããŠãããããå 責ã§äœã§ãã§ããããã«ãªããŸãããä»æ¥ãAndroidã¯ååã«ä¿è·ãããŠãããããŒãžã§ã³4.3ã§å°å ¥ããã5.0ã§ããã©ã«ãã§æå¹åãããSELinuxã¯ãä¿è·ã«å€§ããè²¢ç®ããŸãããããã«ãããããããé²åŸ¡ã®æãç©Žã¯äŸç¶ãšããŠååšãããããã¯äŸç¶ãšããŠç¹æš©ãå¢ãããŠãããããå®éã®ç®çã§ããããŠæªã®ããã«äœ¿çšã§ããããã«ããŸããAndroidã§æãèŠããäžåœ¹ã«ç«ããªããšã¯ã¹ããã€ãã®1ã€ãã©ã®ããã«æçšãªã¢ããªã±ãŒã·ã§ã³ãèŠã€ããããšãã§ãããã«ã€ããŠãããªããèå³ãæã£ãŠããããšãé¡ã£ãŠããŸãããããŠãã¿ãããã¬ãŒã®æ°ããããŒãžã§ã³ããæã䟡å€ã®ãããŠãŒã¶ãŒããŒã¿ã®è»ãåéããã¿ããã¹ã¯ãªãŒã³äžã®ãžã§ã¹ãã£ãŒã®è¡åå åã®ç 究ãåé²ãããã®ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã