Docker Quizãåæã§è§£ã
ããããã®ããã£ã:
äºæéç®ã³ã³ããã®è¬ç¾©ã§ã¯Docker Quizãåºé¡ãåã¯ããã¹ã¦è§£ããã¨ãã§ãããï¼
— hatenatech (@hatenatech) 2020å¹´9æ7æ¥
$ docker run --rm -i hatena/intern-2020-docker-quiz #hatenaintern2020
èªç¤¾ã®ã¤ã³ã¿ã¼ã³ã®èª²é¡ã ãã©, åã¯ä»å¹´ã®ã¤ã³ã¿ã¼ã³ã«ã¯å ¨ãé¢ãã£ã¦ããªãã®ã§, æ°é®®ãªæ°æã¡ã§åé¡ã楽ããã. ã¿ããªè©±é¡ã«ãã¦ããã®ã¯Q7ã§ãªããªã骨ããã. å ¨ä½çã«CTFã£ã½ãããã(åå ãããã¨ãªãã®ã§ããããã©)ä¸ã§, Q7ã¯ã¨ãã«ãã£ã¡æ¹åã®é¢ç½ãããã.
Q7 ãã®ã¤ã¡ã¼ã¸ã®entrypointã¨ãã¦æå®ããã¦ããã³ãã³ãã®ã½ã¼ã¹ã³ã¼ãã復å ãã¦ããã®åé¡ã®çããåå¾ãã
ãã½ã¼ã¹ã³ã¼ãã復å ãã¦ãã¨è¨ããã¦ããã¼ã, ãããã³ãã«å¾©å ããªãã¨ãã¡ããª?ãã¨èãã¦ããããã¯ã·ãè¥ãé ã¯ãã¤ããªçãå®ããã¤ããªã¢ã³ã¨ãã¦æã®ããã«æ¦ã£ããããããã¿ãããªæ°æã¡ãæ¥æ¿ã«æ¹§ãã¦ãã¦, 復å ããã«è§£ãã¦ããã, ã¨ãªã£ã.
ã¡ãªã¿ã«, å®éã¯éä¸ã§è«¦ãã¦æ®éã«ã½ã¼ã¹ã³ã¼ãã復å ãã¦è§£ãã¦ãã¾ã£ãã®ã§, ããã«æ¸ãã®ã¯ãå¾ã«ãã¦æãã°ãããã£ã¦ãã解ãã¦ããªãã¨ãããã¤ã§ã. å¾åºãã¸ã£ã³ã±ã³ã§ã. ãã¨æ³å®ããã解ãæ¹ã¨éãã¨ã¯ãã, èªãã°Q7ã®çããããã£ã¦ãã¾ãã®ã§èªåã§ææ¦ããã人ã¯ææ¦ããå¾ã§èªããã¨ããªã¹ã¹ã¡ãã¾ã.
éã¢ã»ã³ãã«
ãã¤ããªã¢ã³ã ã¨ãå¨å¢ã®ãããã¨ãè¨ã£ããã©, 10年以ä¸åã«åå¼·ã®ããã«å®è¡ãã¡ã¤ã«ãã¯ã©ãã¯ããç·´ç¿ãã¡ãã£ã¨ãã£ããã¨ãããç¨åº¦ã§, ãã®ã¨ããOllyDbgã¨ã使ã£ã¦ãã. ã¢ã»ã³ããªã³ã¼ããããã«ã¯ãªã£ã¦ãã¦ããããªãã¨æã足ãåºãªã.
ä»åã®å®è¡ãã¡ã¤ã«docker_quiz
ã¯ã©ãããGoã§æ¸ããã¦ãããã§, ãããªãã¨go tool objdump
ã§éã¢ã»ã³ãã«ã§ãã. -S
ã¨ãããªãã·ã§ã³ããã£ããã©, ããã¾ã§å½¹ã«ç«ã¤æ
å ±ãããããåºãæãã§ã¯ãªãã£ã. Goã®ãã¼ã«ã§ãªãã¦ãããã辺ã®éã¢ã»ã³ãã©ã使ã£ã¦ãããã¾ã§å¤§å·®ãªããã.
çãåãããã¦ããç®æãç¹å®
ã¾ãæåã®æ¹ãè¦ãã¨/usr/local/go/src/internal/cpu/cpu.go
ã¨ãè¨ã£ã¦ãã¦, ããã¯ãã£ã¨Goã®ã©ã³ã¿ã¤ã ã®å
é¨ã³ã¼ãã ãã. éçãªã³ã¯ãªã®ã§ããããã®ãã¤ãã¦ãã. éã«ä¸çªä¸ãè¦ãã¨/app/docker_quiz.go
ã®main.main
ã¨è¨ã£ã¦ãã¦, ãããã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã£ã½ã.
ã¢ã»ã³ããªã³ã¼ãã®èªã¿æ¹ãã ãã¶å¿ãã¦ããã, 以åèªãã ãã¨ãããã®ã¯CãC++ããã³ã³ãã¤ã«ããããã®ã§, Goã§ã³ã³ãã¤ã«ããã¨ãã®æ§åãã©ãããæããå ¨ãç¥ããªãã®ã§, ã¬ãã§ä¸åä¸å¥èªãã®ã¯ãªãã¹ãé¿ããã.
main.main
ããã£ããçºããã¨CALL main.printQuestions(SB)
ã¨ããã®ãç®ã«ã¤ã. ãã£ã¨ãããåé¡ãåºåãã¦ããã¨ããã ãã. ããã«è¦ã¦ããã¨CALL main.verify(SB)
ã¨ããã®ããã. è¦ãããã«çãåãããã¦ããã¨ããã£ã½ã! ãã®é¢æ°ã®ä¸èº«ã«çµã£ã¦è¦ã¦ããã°ããããã .
main.verify
ã¯ããããã®é·ãã ãã©, ç¹å¾´çãªã¨ããã¨ãã¦crypto/sha512
ã使ã£ã¦ãã. ã©ãããçãåããã¯SHA-512ã®ããã·ã¥å¤ã§ç
§åãã¦ããã .
docker_quiz.go:96 0x4b0b0f e82c91fdff CALL crypto/sha512.(*digest).Sum(SB)
確ãã«, (åé¡æã«æ¸ãã¦ããQ1ãã³ãã³ãã§åºåãããQ2ã¯å¥ã¨ãã¦)Q3~Q6ã®çãã¯ãã¤ããªãã¡ã¤ã«ãstrings
ãã¦ãç»å ´ããªãã®ã . ããã, Q7ã®çããSHA-512ã§ç
§åãã¦ãã®ã ã¨ããã¨, ãã¨ãã½ã¼ã¹ã³ã¼ãã復å
ãã¦ãçããããããªãã®ã§ã¯ãªãã? ããã¨ãã¤ãããã¯çãã®æååãªããã«ã¼ããã©ã¼ã¹ã§ãå²ã¨ç¾å®çãªã®ã ããã?
main.verify
ãããå°ã観å¯ãã¦ã¿ãã¨, SHA-512ã使ã£ã¦ãã辺ãã¯å¾ãã®æ¹ã§, ããã«ãã£ã¦ããã®ã¯æ¡ä»¶åå²ã§é£ãã§ããã¨ãã ãã®ããã .
docker_quiz.go:92 0x4b0975 4883fe03 CMPQ $0x3, SI docker_quiz.go:92 0x4b0979 0f85ea000000 JNE 0x4b0a69
SI
ã3
ãããªãã£ãã¨ãã ãSHA-512ã§ç
§åãã¦ããã. ã§ã¯éã«3
ã ã£ãã¨ãã¯ã©ããªãã®ã. ã¡ã¢ãªæä½ããããã¹ã©ã¤ã¹ãä½ã£ãããã¦ããã®ãç¡è¦ãã¦ããã¨, ãã£ã, ããã!!
docker_quiz.go:106 0x4b09f2 83f3ff XORL $-0x1, BX
-1
ã¨XORãã¨ã£ã¦ãã. -1
ã¨ãããã0xFF
ã¨XORãåãã¨è¨ã£ãæ¹ãããããããã. ã¤ã¾ãQ7ã ãSHA-512ã§ã¯ãªã0xFF
ã¨XORããå¤(ãããå転ããå¤)ã§ç
§åãã¦ããã®ã§ã¯ãªãã?
çããç¹å®
Q6ã¾ã§ã®çãã¯FLAG_xxxxxxxx
ã¨ãããã®ãå¤ã, Q7ã®çãããããããã®å½¢å¼ã ãã. ããããã¨FLAG_
ã®æååããããå転ããb9b3beb8a0
(16é²)ã§å§ã¾ããã¤ãåãå®è¡ãã¡ã¤ã«ã®ä¸ã«æ¸ããã¦ããã¯ãã§, ããããããã«8ãã¤ãèªãã°ç
§åå
ã®å¤ããããã¯ã. ãã¤ããªã¨ãã£ã¿ã§æ¤ç´¢ããã¨, ããã£ã½ãç®æããã. ãã³ã´!
00188510: 0100 0000 0000 0000 b9b3 beb8 a0ce c98a ................ 00188520: ca95 889d 8d00 0000 2f64 6576 2f75 7261 ......../dev/ura
ãã¨ã¯ããããããå転ãã¦æåååããã°Q7ã®çããå¾ããã.
å®éã«ã¯ã©ãã ã£ãã
SHA-512ã§ç §åãã¦ããã ãã, ã¾ã§ã¯ä¸ã«æ¸ããã®ã¨å ¨ãåãæµã.
ãã ãããã¨ãã¤ãããã¯çãã®æååãªããã«ã¼ããã©ã¼ã¹ã§ãå²ã¨ç¾å®çãªã®ã ããã?ãã¨æã£ãã®ã§, æéãããã ããããã²ã¨ã¾ããã«ã¼ããã©ã¼ã¹ããã³ã¼ãã¯æ¸ãã¦èµ°ããã¦ããã. ã¾ãQ6ã¾ã§ã®SHA-512å¤ãæ¸ãã¦ããå ´æããã¤ããªã¨ãã£ã¿ã§æ¢ãã¦, Q7ã®SHA-512å¤ãæ¸ãã¦ããã¨ããããã, ã¨ãããã¤ãåã«å¯¾ãã¦ãã«ã¼ããã©ã¼ã¹ãã. FLAG_xxxxxxxx
ã®x
ã«ã¯åè§å°æåè±æ°åãå
¥ãããã§, ãªã®ã§3å
éãããããã. ã¡ãªã¿ã«ã·ã³ã°ã«ã¹ã¬ããã§æå
ã®ãã·ã³ã§èµ°ãããæãã ã¨æå¤ã¨ã©ãã©ãé²ãã§, 1ã¶æãããããã°æ®éã«çµãã£ã¦ããã ã£ã. å®éã«ã¯SHA-512ã§ã¯ãªãã®ã§ããã¶å¤ããéå½ã ãã©ã......
èµ°ããã¦ãéã«SHA-512ãããªãåå²ã®è¾ºããèªãã§ã¿ããã©, ããããããªãã£ã. SHA-512ãããªãã¨ãããXORã¨ã足ãããå¼ãããã¨ãã ãããªã, ã¨æã£ã¦XORãè¦ã¦ããªããé¢ä¿ãªããããªXORãã¡ããã¡ããåºã¦ãã¦ãããããã. ããããããã¯3
ã§åå²ãã¦ã¦ããã¯Q3ã ããã§ãã¯æ¹æ³ãéãã®ã§ã¯? (ã¨ãã®ã¨ãã¯æã£ããã©ããããããæããªãQ4ã ãã.) ãã¼ã, ãããã. ãã¨ãã£ã¦ã¢ã»ã³ããªã³ã¼ããã¤ã¶ãã«èªãã§ããã®, ãããããªã. ãããããæ£æ»æ³ã§è§£ãã. ã¨ããæãã§è«¦ãã¦ãã¾ã£ã¦ãã.
-1
ã¨XORãã¦ãã®ã¯ç®ã«å
¥ã£ã¦ãããã©-1
ããã¸ãã¯ãã³ãã¼æãªãã¦ç®ãæ»ã£ã¦ãã¾ã£ã¦ãã. æãã!