Exploit
ãã®è¨äºã¯ãCTF Advent Calendar 2016ã24æ¥ç®ã®è¨äºã§ãã ãglibc malloc exploit techniquesãã§ã¯ä¸»è¦ãªmallocç³»exploitãã¯ããã¯ã«ã¤ãã¦èª¬æããããæ´å²çã«ã¯ä»ã«ããã¾ãã¾ãªææ³ãå ¬è¡¨ããã¦ããã ããã§ã¯ã2005å¹´ã«Bugtraqã¡ã¼ãªã³ã°ãªã¹ãã«â¦
ãã®è¨äºã¯ãCTF Advent Calendar 2016ã17æ¥ç®ã®è¨äºã§ãã ã¡ããã¡ããè¦ããã¦ã¯ããã®ã ããå®æ¦ã§ããå¿ãã¦ãã¾ãã®ã§å¿ç¨ã®å¹ããããªãã®ãã¾ã¨ãã¦ããã ROPããã®GOT overwrite åç´ãªROPåé¡ã®å ´åãGOTã«ç½®ãããé¢æ°ã¢ãã¬ã¹ãèªã¿åºããå¾ofâ¦
mallocç³»exploitãã¯ããã¯ã®ãã¡ãå¿ç¨ããããããªãã®ã®ã¡ã¢ã ç°å¢ Ubuntu Server 16.04.1 LTS 64bitçãGLIBC 2.23 $ uname -a Linux vm-ubuntu64 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux $ lsbâ¦
ãWindowsã§ããã¤ã¹ãã©ã¤ãã®èå¼±æ§ããã®æ¨©éææ ¼ããã£ã¦ã¿ããã§ã¯ãHalDispatchTableã®æ¸ãæããè¡ããã¨ã§ã·ã§ã«ã³ã¼ãã®å®è¡ãè¡ã£ãã ããããHalDispatchTableããã®ä¸ã®ãã¤ã³ã¿ãå¼ã³åºãé¢æ°ã®å®è£ ã¯OSã®ã¡ã¸ã£ã¼ã¢ãããã¼ããªã©ã§å¤æ´ããâ¦
ãWindowsã§ããã¤ã¹ãã©ã¤ãã®èå¼±æ§ããã®æ¨©éææ ¼ããã£ã¦ã¿ããã§ã¯ãSystemããã»ã¹ã®Tokenãèªèº«ã®ããã»ã¹ã®Tokenã«ã³ãã¼ããã·ã§ã«ã³ã¼ãã使ã£ã¦æ¨©éææ ¼ãè¡ã£ãã ãã®æ¹æ³ã®ã»ãã«ãSystem権éã§åä½ããããã»ã¹ã®ACLï¼Access Control Listï¼â¦
Windowsã«ããã¦ãä»»æã¢ãã¬ã¹æ¸ãæãï¼arbitrary address writeï¼ã®èå¼±æ§ãããããã¤ã¹ãã©ã¤ããä½ãããã®èå¼±æ§ãå©ç¨ãã権éææ ¼ããã£ã¦ã¿ãã ç°å¢ Windows 8.1 Enterprise Evaluation 32 bitçãVisual Studio Community 2015 >systeminfo OS Nâ¦
ASLR+DEP+FullRELROãæå¹ãªç°å¢ã§ãDynamic ROPï¼JIT-ROPï¼ã«ããä»»æã®ã·ã§ã«ã³ã¼ããå®è¡ãã¦ã¿ãã ããã¯ãã»ãã¥ãªãã£ã»ãã£ã³ãå ¨å½å¤§ä¼2015ã®è¬ç¾©ã«ã¦è¡ã£ãæ¼ç¿ã«è¥å¹²ã®ä¿®æ£ãå ãããã®ã§ããã ç°å¢ Ubuntu Server 14.04.2 64bitç $ uname -a Lâ¦
ãWindowsã§é»åãèµ·åããã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ããã§ã¯ã32ãããã®Windowsç°å¢ã§åä½ããã·ã§ã«ã³ã¼ããæ¸ããã ããã§ã¯ãMicrosoftãæä¾ããèå¼±æ§ç·©åãã¼ã«EMETï¼Enhanced Mitigation Experience Toolkitï¼ã®æ¤ç¥æ©æ§ãåé¿ããã·ã§ã«ã³ã¼ããæ¸â¦
ãWindowsã§Return-oriented Programmingï¼ROPï¼ã«ããDEPåé¿ããã£ã¦ã¿ããã§ã¯ãWindows 32ãããç°å¢ã§ROPã«ããDEPåé¿ãè¡ã£ãã ããã§ã¯ãWindows 64ãããç°å¢ã§ã®ROPããã£ã¦ã¿ãã ç°å¢ Windows 8.1 Pro 64 bitçãVisual Studio Community 2013 â¦
ãWindowsã§connect-backã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ããã§ã¯ããã°ã©ã ãWinsockãå©ç¨ãã¦ãããã¨ãåæã«ãconnect-back shellãèµ·åããã·ã§ã«ã³ã¼ããæ¸ããã ãã®ä»ã«ãWindowsã§ã¯ã¤ã³ã¿ã¼ãããããå®è¡ãã¡ã¤ã«ããã¦ã³ãã¼ããå®è¡ããã·ã§ã«ã³ã¼ãâ¦
ãWindowsã§é»åãèµ·åããã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ããã§ã¯ãWindows 32bitã¢ããªã±ã¼ã·ã§ã³ç¨ã®ã·ã§ã«ã³ã¼ããä½æããã ããã§ã¯ãWindows 64bitã¢ããªã±ã¼ã·ã§ã³ããé»åãèµ·åããã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ãã ç°å¢ Windows 8.1 Pro 64 bitçãVisual Stâ¦
LoadLibraryé¢æ°ã¯å®è¡æã«DLLããã¼ãããé¢æ°ã§ããããå¼æ°ã«UNCãã¹ãä¸ãããã¨ã«ãããSMBãããã³ã«ï¼Windowsãã¡ã¤ã«å ±æï¼ãä»ãã¦ãªã¢ã¼ããã¹ãã«ããDLLããã¼ãã§ãããã¨ãç¥ããã¦ããã ã¾ããDLLã¯ãã¼ãæã«DLLMainé¢æ°ãèªåçã«å¼ã³åºãâ¦
Metasploit Frameworkã¯ãã¨ã¯ã¹ããã¤ãã³ã¼ãå®è¡ãã¯ããã¨ãã種ã ã®ã¿ã¹ã¯ãçµ±ä¸ãããã¤ã³ã¿ãã§ã¼ã¹ã§æ±ãããã®çµ±åç°å¢ï¼ãã¬ã¼ã ã¯ã¼ã¯ï¼ã§ããã ããã§ã¯ãã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼èå¼±æ§ã®ããããã°ã©ã ãç¨æããããã«å¯¾ããexploitâ¦
主ã«Windowsç°å¢ã«å¯¾ãã¦ä½¿ãããé«æ©è½ãªãªã¢ã¼ãæä½ã³ã³ã½ã¼ã«ã¨ãã¦ãMeterpreterã¨å¼ã°ãããã®ãããã ããã§ã¯ãMetasploit Frameworkã使ãMeterpreterç¨ã®ã·ã§ã«ã³ã¼ããçæãã¦ã¿ãã ããã«ãã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼èå¼±æ§ãå©ç¨ãã¦ãâ¦
ã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼æ»æã«å¯¾ããé²å¾¡ææ³ã®ã²ã¨ã¤ã«stack canaryãããã ããã¯é¢æ°ã®å é ã§canaryã¨å¼ã°ããã©ã³ãã ãªå¤ãã¹ã¿ãã¯ã«ç©ãã§ãããé¢æ°ã®æ«å°¾ã§ãã®å¤ãæ¸ãæãããã¦ããªãããã§ãã¯ãããã¨ã§æ»æãæ¤ç¥ããã¨ãããã®ã§ãâ¦
ãWindowsã§Return-oriented Programmingï¼ROPï¼ã«ããDEPåé¿ããã£ã¦ã¿ããã§ã¯ãå®è¡ãã¡ã¤ã«ä¸ã§VitrualProtecté¢æ°ã使ããã¦ãããã¨ãåæã«ROPãè¡ã£ãã ããã§ã¯ãASLRãç¡å¹ãªå¤ãã·ã¹ãã DLLãå©ç¨ãããã¨ã«ãããVirtualProtecté¢æ°ãå¼ã³åºãâ¦
ãWindowsã§åç´ãªã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼æ»æããã£ã¦ã¿ããã§ã¯ãDEPãç¡å¹ã«ããç¶æ ã§ã·ã§ã«ã³ã¼ãã®å®è¡ãè¡ã£ãã ããã§ã¯ãDEPãæå¹ãªç°å¢ä¸ã«ããã¦ãROPï¼Return-oriented Programmingï¼ã«ããã·ã§ã«ã³ã¼ãå®è¡ããã£ã¦ã¿ãã ç°å¢ Windoâ¦
Windowsã§å種ã»ãã¥ãªãã£æ©æ§ããªãã«ãã¦ãåç´ãªã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼ã«ããã·ã§ã«ã³ã¼ãå®è¡ããã£ã¦ã¿ãã ç°å¢ Windows 8.1 Pro 64 bitçãVisual Studio Community 2013 with Update 4 >systeminfo OS å: Microsoft Windows 8.1 Pro OS â¦
ä»ç³æµ©æã®æ¥è¨: chroot ããããã£ã¬ã¯ããªããè±åºãã¦ã¿ã ä¸ã®è¨äºã§ã¯ãchrootãsuperuserãªãã°è±åºå¯è½ã§ãããã¨ã«ã¤ãã¦æ¸ããã¦ããã ã¾ããå®éã«ããã¥ã¢ã«ã確èªããã¨ã確ãã«ãã®ãã¨ãè¨è¼ããã¦ããã CHROOT(2) Linux Programmer's Manuaâ¦
ãWindowsã§é»åãèµ·åããã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ããã§ã¯PEBããã©ã¤ãã©ãªé¢æ°ã®ã¢ãã¬ã¹ãç¹å®ããWinExecé¢æ°ã使ã£ã¦é»åãèµ·åããã·ã§ã«ã³ã¼ããæ¸ããã ããã§ã¯ãããã°ã©ã ãWinsockãå©ç¨ãã¦ãããã¨ãåæã«ãconnect-back shellãèµ·åããã·â¦
ãWindowsã§é»åãèµ·åããã¢ã»ã³ããªã³ã¼ããæ¸ãã¦ã¿ããã§ã¯å¼ã³åºãã©ã¤ãã©ãªé¢æ°ã®ã¢ãã¬ã¹ããã¼ãã³ã¼ãããå½¢ã§ã¢ã»ã³ããªã³ã¼ããæ¸ããããASLRãæå¹ãªDLLã«ã¤ãã¦ã¯DLLãèªã¿è¾¼ã¾ãããã³ã«ãã¼ã¹ã¢ãã¬ã¹ãå¤åãããã常ã«ã¯æ©è½ããªãã ãâ¦
éå®çãªç°å¢ã«ããã¦é»åãèµ·åããã¢ã»ã³ããªã³ã¼ããæ¸ããã·ã§ã«ã³ã¼ãã¨ãã¦å®è¡ãã¦ã¿ãã ç°å¢ Windows 8.1 Pro 64 bitçãVisual Studio Community 2013 with Update 4 >systeminfo OS å: Microsoft Windows 8.1 Pro OS ãã¼ã¸ã§ã³: 6.3.9600 N/A â¦
ãLinuxã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã§ret2usrã«ãã権éææ ¼ããã£ã¦ã¿ããã§ã¯ãKernel Address Display Restrictionï¼KADRï¼ãç¡å¹ã«ããä¸ã§/proc/kallsymsããã«ã¼ãã«ã·ã³ãã«ã®ã¢ãã¬ã¹ãåå¾ããã«ã¼ãã«ç©ºéããã¦ã¼ã¶ç©ºéã®é¢æ°ãå®è¡ããããã¨ã«ãã権éâ¦
Linuxã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã«ãããä»»æã¢ãã¬ã¹æ¸ãæãï¼Arbitrary address writeï¼ã®èå¼±æ§ãå©ç¨ããret2usrï¼Return-to-userï¼ã¨å¼ã°ããææ³ã«ããroot権éã¸ã®æ¨©éææ ¼ããã£ã¦ã¿ãã ç°å¢ Ubuntu 14.04.1 LTS 64bitçãIntel SMEPç¡å¹ $ uname -a Linuâ¦
Linuxã«ãããã«ã¼ãã«ã¨ã¯ã¹ããã¤ãã®ä¸æºåã¨ãã¦ãç¡æ¡ä»¶ã§æ¨©éææ ¼ããï¼å®å ¨ã§ãªãï¼ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãæ¸ãã¦ã¿ãã ç°å¢ Ubuntu 14.04.1 LTS 64bitç $ uname -a Linux vm-ubuntu64 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 201â¦
ãARMã§Return-oriented Programmingï¼ROPï¼ããã£ã¦ã¿ããã§ã¯libcã®ãã¼ã¹ã¢ãã¬ã¹ãlibcé¢æ°ã®ãªãã»ããã調ã¹ãä¸ã§ROPãè¡ã£ãã ããã§ã¯ãASLRãæå¹ã¨ãªã£ã¦ããå ´åãæ³å®ããGOTã¢ãã¬ã¹ã®æ¸ãåºãããã³stack pivotããã¨ã«ããDynamic ROPï¼JITâ¦
ARM EABIï¼armelï¼ç°å¢ã§Return-oriented Programmingï¼ROPï¼ããã£ã¦ã¿ãã ç°å¢ Ubuntu 14.04.2 LTS ARMçï¼ã¦ã¼ã¶ã¢ã¼ãQEMUå©ç¨ï¼ # uname -a Linux c7b94bb2fc1e 2.6.32 #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 armv7l armv7l armv7l GNU/Linux #â¦
ãåç´ãªã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼æ»æããã£ã¦ã¿ããã¨åæ§ã«ãLinux ARMï¼armelï¼ç°å¢ã§ã¹ã¿ãã¯ãããã¡ãªã¼ãã¼ããã¼ããã®ã·ã§ã«ã³ã¼ãå®è¡ããã£ã¦ã¿ãã ç°å¢ Ubuntu 14.04.2 LTS ARMçï¼ã¦ã¼ã¶ã¢ã¼ãQEMUå©ç¨ï¼ # uname -a Linux c7b94bb2fc1â¦
ãLinux x86ç¨ã®ã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ããã¨åæ§ã«ãLinux ARMï¼armelï¼ç¨ã®ã·ã§ã«ã³ã¼ããæ¸ãã¦ã¿ãã ç°å¢ Ubuntu 14.04.2 LTS ARMçï¼ã¦ã¼ã¶ã¢ã¼ãQEMUå©ç¨ï¼ # uname -a Linux c7b94bb2fc1e 2.6.32 #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 armvâ¦
ãuse-after-freeã«ããC++ vtable overwriteããã£ã¦ã¿ããã§ã¯ãASLRãç¡å¹ã«ããæ¡ä»¶ä¸ã§ã·ã§ã«èµ·åãè¡ã£ãã ASLRãæå¹ã®å ´åãæ¸ãæããvtableã®é¢æ°ãã¤ã³ã¿ãæãã¢ãã¬ã¹ãæ¨æ¸¬å¯è½ã§ãªããã°ãªããªããããã¼ãé åã«ä»»æã®æ°ã®ãªãã¸ã§ã¯ããçâ¦