defcon ctf qual 2016
binjaã®äººãã¡ããããªã¨è¦ã¦ããä»åã¯çµæ§ãªæéåå ã§ãããã ãã©ãã¾ãã²ãã£ã¨ãããç¯ç´ã§ããæéãããããããã¦ãããã®è²¢ç®åº¦ã ã£ãã¨æããã¾ãå ¥ãã¦ããã£ã¦ããã¾ã¨ãã«æé使ã£ã¦åå ããåãç¡ãã£ããããã®å¢ãã ã£ããããå°ãã¯ãªããã§ãã¦è¯ãã£ãã
b3s23
ã©ã¤ãã²ã¼ã 15ã¿ã¼ã³åãããå¾ã®ç¶æ ãshellcodeã¨ãã¦å®è¡ãã¾ããã¦åé¡ã空éãã«ã¼ããã¦ãªãã¿ã¤ãã®ã©ã¤ãã²ã¼ã ãªãã§ã端ã£ãã®æ¹ã¯å¤§å¤ä½¿ãã«ããâ¦ã®ã§æåã®å½ä»¤ã§ç«¯ãããªãã¨ããã«å®è¡é£ã°ãã¦ããã¨ã¯é©å½ã«ãã¦æ¹éã§ããã¾ã使ããã¸ã£ã³ãä½ãã®ãçµæ§å¤§å¤ã§ãé©å½ãªå½¢ã«ã°ã©ã¤ãã¼ã¶ã¡å½ã¦ã¦é½åããåºã¦ãããã¿ã¼ã³ãæ¢ããã
ãã¾ããã¨ãã£ã¦ã read(0, buf, buf) ã¨ããå¼ã¹ããã© buf ãã¡ãã£ã¨åãããªãã¨ãªã£ã¦ãããã§ãå¥ã®äººã1è¡ç®ã ãã§ã§ããã½ãã£ãã®ã§ãæ¾æ£ãçµãã£ã¦ãããã¼ã«ã«ã§ shellcode åãã¨ããã¾ã§ä½ã£ã¦ãããã
https://gist.github.com/shinh/1891e3f346a1255fc06e8a7cbf63c756
15 o oo ooo oo o oo o o o o oo oo o o oo o o oo oo oo oo o o oo o oo o o o oo oo oo o o o o o oo oo oo oo oo o oo oo oo oo o o oo
kiss
ã¬ã¸ã¹ã¿ãå ¨æ¶å»ã®å¾ RAX RBX RCX RDX ã¯ãã¼ãå ã®å¥½ããªå ´ææããç¶æ ããã㧠RIP ã好ããªã¨ãé£ã°ãã¾ããã£ã¦åé¡ã RSP ãã¾ã¨ããªå¤ã«ããã¨ã©ããããããªãããâ¦ã¨ãããã¨ã§ RSP ããªã¹ãã¢ããã§ãããã libc ã® longjmp ã¨ã setcontext ã¨ããçºããã RSP ã®å¤ã®ä¸æéé¿å ã R[ABCD]X ãªãè¯ãã ãããã¦ãã¨ã§ãã¾ãã§ã R8 ã¨ã使ã£ã¦ã¦æããã£ãããããã®ã®è¦ã¤ãããªãã
ã§å°ãæ¢ç´¢ç¯å²ãåºã㦠RSP ããã£ã¦ãã¨ãæ¢ãã¨
498b0: 48 89 dc mov %rbx,%rsp 498b3: 5f pop %rdi 498b4: 48 85 ff test %rdi,%rdi 498b7: 74 08 je 498c1 <addseverity@@GLIBC_2.2.5+0x591> ; [L5010] 498b9: e8 22 d9 ff ff callq 471e0 <setcontext@@GLIBC_2.2.5>
ã¨ããã®ãè¦ã¤ãã£ãã®ã§ãããé½åè¯ããªãã§ããâ¦ã¨èãã¨ãä»ã®äººã使ãããã¨ããããã¨ã§ãå¾ã¯ãã£ã¦ãããã
çµãã£ã¦ããããä½ããªã¼ã¨èª¿ã¹ã¦ã¿ãã¨ã makecontext ã®å®è£ ã«ä½¿ã£ã¦ãããã©ã³ããªã³ã«ãããã³ã¼ããããã makecontext ã¦æ»ãå¤ã®æ¸ãæãã¨ã使ã£ã¦ããã ãªâ¦
crippled
å¯ã¦èµ·ãã¦äºåº¦å¯ããããªã¨ãã®åã«ã±ã¼ã¿ã¤ãè¦ãã¨ãç§ãå¾æãããã¨è¨ããã¦ãåé¡ã«æ°ä»ãããã£ã¦ã¿ã¦ããã£ããã¨ã¯ãããªãã誰ã§ã解ããã£ã¦ãã¨ã ãã©ãã¾ãç°¡åããã ã£ãã®ã§ãã£ãã
æ¹é ãã C ã³ã³ãã¤ã©ãé©å½ã«ã«ã³ã§å ¥åéã£ã¦ã read(3, buf, 99) ãæåããããã¦åé¡ããã ã read ã使ããã¨ããã¨ãªã³ã¯ã¨ã©ã¼ã write ã®ã³ã¼ãããã³ããã¦ã¿ã㨠EAX ã»ããããã¨ãããã£ã¨ã°ãã° ebx/ecx/edx ãã»ããããã¤ã¤ int 0x80 ãã¦ããã¦è¯ãããã ã£ãã®ã§ãé©å½ã«ã¢ãã¬ã¹æ¢ãã¦çµäºããªãã足ãç®ãå¼ãç®ã«ãªã£ãããããããããããããæ¹é ãããããããã¦ãã¿ããã
int main() { char buf[99]; void (*fn)()=((int)&main)+26; //write(1,fn,555); write(1,"hey",3); fn(3,buf,99); write(1,buf,99); }
step
ç¹å®ã®4Bã®éµã使ãã¨ã³ã¼ãã®ä¸é¨ã復å ãããã½ãã£ãã®ã§ãé©å½ã«ç·å½ãããã¤ã¤ããã£ã½ãã¢ã»ã³ããªãåºãã®ãæ¢ããããã®å¾äºå®ããã£ãã®ã§è±åºã
ããã¾ã§ã¯ã¯ã½ç°¡åã§ããã®å¾ã¯ SIGTRAP ãæ¿ããèµ·ãã¤ã¤2段éç®ã®å¾©å ãè¡ãªããã¦ãå¾ã¯æ®éã® rev ã½ãæããã¨ããæãã½ãã£ãã
crunchtime
æãã£ã pwn ã®ç©´ããµããã ããã¦åé¡ãã³ã¼ããµã¤ãºå°ããã®ã§ä¸éãçºããã¨ããªã¼ã¯ã¯ãããããããã©ãã©ããexploitableãªã¨ããè¦ã¤ãããªããªãã¨ã¼ããããã¦ããã
ä»ã®äººããã©ã°ã¬ã¸ã¹ã¿ããã£ããæååå½ä»¤ã®æåå¤ããããã¨è¨ã£ã¦ãããã ã£ã¦ãã¨ã«ãªãã direction flag ã¦ãããã¤ãå ¨ãç¥ãã¾ããã§ããããããªã®ãã£ããã ãªãâ¦ã¨ããæãããã®ãã°ã¯æåã®æ¹ã®å®é¨ã§å¼ãèµ·ããã¦ã¦ããããã³ãªãã¨èµ·ãã¦ããªãã¦ãã¨ã¯æã£ã¦ãã®ã«ããã£ããå¿ãã¦ã¦ãã¡ã ãªãâ¦ã¨æãã¾ããã
ã§ã¾ãä»ã®äººããã¸ã¡ã«ãã³ãèªãã§ãã½ãã£ãã®ã§ãé©å½ã«éãã§ãã¨ãå²ã¨ç°¡åã« RIP ãæ¸ãæããããã¨ã«æ°ä»ãããã ã RIP 㯠CRC ãè¨ç®ããçµæã«ãªã£ã¦ãã®ã§â¦ã¨ãããã¨ã§é©å½ã«ç·å½ããæ¸ãããããæ¯åº¦éãå¤è¨ç®ããå¿ è¦ããä¸ã«æéå¶éãããããããããã¨æãã
CRC 㯠Quine æ¸ããæã«ãè¨ç®ã§è§£ãåºããããâ¦ï¼ã¨ãæã£ã¦ããã©ããããã§ã³ã¼ãè¦ã¤ãããªããªãã¨æ¢ãããã®ãã¡ä»ã®äººãéå»ã®åé¡ã§ CRC æ¢ãã«ä½¿ã£ãåé¡ãåºãã¦ãã¦ãããã®ã§ãå°ãããã£ã¦ä»åã®ãã©ã¡ã¼ã¿ã§åãããã«ããã
ãã¨ã¯ãã¹ã¿ãã¯ã®ããããã¨ããçã« pivot ã½ããã¨ããªãã¨ã ãªâ¦ã¨ãã¢ã¬ã³ã¬ãã¦ããã¡ã«ãã¹ã¿ãã¯ã®å¤§ããã¢ãã¬ã¹ãããããããã«ãã£ã¦ãä»ã®äººã解ãã¦ãããã
ã¾ã¨ã
æ¸ãã¦ã¿ãã¨æã£ã¦ã以ä¸ã«ä½ããã¦ãªãã£ããã¾ããã¤ãããä»ã®äººã¨å°ãååã¨ãã§ããã®ã¯è¯ãã£ãã¨æããæãã«æåã®è§£æã¨ãæ¹éå®ã¾ã£ã¦ããã®å®è£ ã¨ãã§ã¯ãé度çã«è²¢ç®ã§ããªããªã£ã¦ãããç¹ã«åè ã