ãã®èšäºã§ã¯ãSMTãœã«ããŒã«ã€ããŠèª¬æããŸãã ãã®ããããã®ãããã¯ã«é¢ããç 究è³æã«è¯ãäŒçµ±ãç»å ŽããŸããã ãã§ã«äœåºŠããããŸããŸãªç 究è ãSMTãœã«ããŒã®äºè£ãšåãäŸãéžæããŸãã ãããã¯ãããã¯ããŒã kaoã®äººãçºæããäºè£ã§ãã ããŠããã®äŒçµ±ãç¶ããŠãèšå·èšç®çšã®å¥ã®ããŒã«ã§ããTritonã䜿çšããŠäºè£ã解決ããŠã¿ãŸãããã
SMTãœã«ããŒã«é¢ããäžèš
çè«ã®å ¬åŒã®å 足å¯èœæ§ã®åé¡ïŒè±èªã®å 足å¯èœæ§ã¢ãžã¥ãçè«ãSMTïŒã¯ããããã®åºç€ãšãªãçè«ãèæ ®ããè«çåŒã®å 足å¯èœæ§ã®åé¡ã§ãã ãã®ãããªSMTåŒã®çè«ã®äŸã¯æ¬¡ã®ãšããã§ããæŽæ°ãšå®æ°ã®çè«ããªã¹ãã®çè«ãé åãããããã¯ãã«ãªã©- ãŠã£ãããã£ã¢
SMTã¿ã¹ã¯ã¯ãSATã¿ã¹ã¯ã®å»¶é·ã§ãïŒããŒã«å 足å¯èœæ§åé¡ãŸãã¯åœé¡å 足å¯èœæ§åé¡ãè±èªæåŠã§ã¯SATISFIABILITYãŸãã¯SATããã·ã¢æåŠã§ã¯VypãšåŒã°ããããšããããŸãïŒã
ãŠã£ãããã£ã¢ããã®å¥ã®åŒçšïŒ
SATã¿ã¹ã¯ã®ã€ã³ã¹ã¿ã³ã¹ã¯ãå€æ°åãè§ãã£ããANDãORãHEæŒç®ã®ã¿ã§æ§æãããããŒã«åŒã§ãã ã¿ã¹ã¯ã¯æ¬¡ã®ãšããã§ããåŒã§çºçãããã¹ãŠã®å€æ°ã«å€ãfalseãããã³ãtrueããå²ãåœãŠãŠãåŒãtrueã«ãªãããã«ããããšã¯å¯èœã§ããã - ãŠã£ãããã£ã¢
SMTãœã«ããŒã¯ããŸããŸãªçè«ã§æ©èœãããããåŸæ¥ã®ããã»ããµã¢ãŒããã¯ãã£ã®ã¢ã«ãŽãªãºã ã«ãããã䜿çšããããšãå¯èœã«ãªããŸãã ãããã£ãŠãSMTãœã«ããŒã¯2ã€ã®åé¡ã解決ã§ããŸãã
- ã¢ã«ãŽãªãºã ã®ç¹å®ã®åºåå€ãç¹å®ã®å ¥åå€ã§å¯èœãã©ãããšãã質åã«çããŸãã
- ã¢ã«ãŽãªãºã ã®çµæã«åºåå€ãäžããããå ¥åå€ã決å®ããŸãã
SMTãœã«ããŒã¯ãç§åŠæè¡ã®ããŸããŸãªåéã§å¿çšãããŠããŸãã Z3 ã miniSAT ã CVC4ãªã©ã®SMTåŒã解ãããã®åå¥ã®ããŒã«ãããã³BAP ã radare2ãŸãã¯angrãªã©ã®SMTåŒã®æ§æã§æ©æ¢°èªã§ã¢ã«ãŽãªãºã ãè¡šãããã®åå¥ã®ããŒã«ããããŸã ã ããŒã«ã¯çµ¶ããæ¹åãããŠãããAPIã¯ãã匷åã«ãªããæ°åã¯ãªãã¯ããã ãã§ãªããŒã¹ãšã³ãžãã¢ãªã³ã°ã®åé¡ã§SMTæ°åŠè£ çœ®å šäœã䜿çšã§ããŸãã
ãŸããã·ã³ããªãã¯ããã©ãŒãã³ã¹ã«ã¯ããã€ãã®ã¿ã€ããããããšã«æ³šæããŠãã ããã éçã·ã³ããªãã¯å®è¡ïŒSSEïŒã¯ãã·ã³ããªãã¯å€æ°ã®ã¿ã«åºã¥ããŠãããã·ã³ããªãã¯åŒã®ã¿ã䜿çšããŸãã åçã·ã³ããªãã¯å®è¡ïŒDSEïŒïŒã³ã³ã³ãªãã¯å®è¡ãšãåŒã°ããŸãïŒã¯ãããã°ã©ã å®è¡äžã«æ°å€å€æ°ã®ç¹å®ã®å€ãšãšãã«ã·ã³ããªãã¯èšç®ã䜿çšããŸãã ãã®ãã¯ã€ãããŒããŒã§ã¯ãéçæåã®å®è¡ã®ã¿ã䜿çšããŸãã
è±çã®ãã€ãããžã§ã¯ãã¯ã©ãã¯ã¹ããŒãªãŒ
ã¯ã©ãã¯è±çã®ãã€ãããžã§ã¯ãã¯éåžžã«ã·ã³ãã«ã§ãã 1ã€ã®ãŠã£ã³ããŠã«ãç¹å®ã®16é²æ°ã®ã·ãŒã±ã³ã¹ã衚瀺ããããã®ã·ãŒã±ã³ã¹ã«æå¹ãªããŒã®å ¥åãæ±ããããŸãã
圌ã®ç©èªã¯ã次ã®å¹Žä»£èšã®åœ¢ã§è¡šçŸã§ããŸãã
2012幎3æ4æ¥- è±çã®ããã¡ããããžã§ã¯ããšä»£æ°æå·è§£èª -dcoderãandrewl-代æ°æå·è§£èªãSAT
ãã®ã¯ã©ãã¯å°çšã®æåã®äœåã¯2012幎ã«ç»å ŽããŸããã ãã®äžã§ãããã¯ããŒã dcoderãæã£ãŠãã人ã代æ°æå·è§£èªã䜿çšããŠãœãªã¥ãŒã·ã§ã³ãå ¬éãããã®äœæ¥ã®å ±åèè andrewlãSATãœã«ããŒãæ£åžžã«é©çšããŸããã
03/06/2012- ã·ã³ããªãã¯å®è¡ã«ããåèªåå ¥åã¯ã©ããã£ã³ã°ãèªåããŒãžã§ãã¬ãŒã¿ãŒçæãžã®ã¢ããªã±ãŒã·ã§ã³ -Rolf Rolles-z3ãã¬ã³ãŒããŒ
ãã®åŸãæåãªç 究è ã§ãããã«ãã»ããŒã«ãºã¯ãæåã«SMTãœã«ããŒããœãªã¥ãŒã·ã§ã³ã«é©çšããŸããã ãŸããZ3ã§æ°åŒãæåã§äœæãã次ã«OCamlã§ãã·ã³ã³ãŒãã®äžéè¡šçŸããæ°åŒãèªåçã«çæããããŒã«ãæ瀺ããŸããã 圌ã䜿çšããäžéèšèªã¯èªåã§éçºããŸããã
BitBlazeãšBAPã§äœ¿çšãããŠãããã®ãšéåžžã«ãã䌌ãIRã䜿çšããŠããŸãããVEXã䜿çšããã®ã§ã¯ãªããç¬èªã®IRãã©ã³ã¹ã¬ãŒã¿ãŒãäœæããŸããã ç§ã®å®è£ ã¯æåããæžãããŠããããªãŒãã³ãœãŒã¹ã®ãã¬ãŒã ã¯ãŒã¯ãšã³ãŒããå ±æããŸããã -openrce.org
11.2013- ãœãããŠã§ã¢ã»ãã¥ãªãã£çšã®SMTãœã«ã㌠-Georgy Nosenko-BAPãz3
ãã®åŸãååã®ãžã§ãŒãžã»ãã»ã³ã³ã®ç 究ãå§ãŸããŸãããããã§ã¯ãBAPãã¬ãŒã ã¯ãŒã¯ãšåãZ3ãœã«ããŒãæ¢ã«åŒã®çæã«äœ¿çšãããŠããŸããã
2015.2015- OpenREILããã³Z3ã䜿çšããèªå代æ°æå·è§£æ -Cr4sh-OpenREILãz3
Cr4shãšããŠãç¥ãããDmitry Oleksyukã¯ã圌ã®ç 究ã§ãäžéèšèªOpenREILãžã®å€æãšããã®åŸã®Z3ã§ã®åŒã®çæã䜿çšããŸããã
04.2016- ã·ã³ããªãã¯å®è¡ãšangrã«ããè±çã®ããã¡ããããžã§ã¯ãã®è§£æ±º-Extreme Codersããã°-angr
ãããŠæåŸã«ã2016幎ã«å¥ã®äœåãç»å Žããangrãã¬ãŒã ã¯ãŒã¯ã䜿çšãããœãªã¥ãŒã·ã§ã³ã«ã€ããŠèª¬æããŠããŸãã Angrã¯ãã·ã³ããªãã¯å®è¡ã«VEXäžéèšèªãšclaripyã©ã€ãã©ãªã䜿çšããŸãã
å¥ã®ãã¬ã€ã€ãŒãSMTã¢ãªãŒãã«ç»å ŽããŸãã-Tritonããã®äœåã§ã¯ãæåãªã¯ã©ãã¯ã解決ããããã«ããã䜿çšããŸãã
ããªãã³
Tritonã¯Quarkslabã«ãã£ãŠäœæãããŸãããQuarkslab㯠ããªããŒã¹ãšã³ãžãã¢ãªã³ã°ã®ããã®å€ãã®èå³æ·±ãããŒã«ãäœæããŸããã
ãŸããTritonã®ä»çµã¿ã«ã€ããŠå°ã説æããŸãã 圌ã®ä»äºã®éçšã§ã圌ã¯æ¬¡ã®ã¢ã¯ã·ã§ã³ãå®è¡ããŸãã
- ãã€ããªã³ãŒãã®å®è¡ãã¹ã解æããæ©æ¢°èªåœä»€ã®ãã¹ãŠã®å¯äœçšãèæ ®ããæœè±¡æ§æã³ãŒãããªãŒãçæããŸãã
- æœè±¡æ§æããªãŒããã€ãã¹ããŠãSMT-LIB圢åŒã®SMTåŒãçæããŸãã
- ãœã«ããŒz3ã䜿çšããŠæ°åŒã解ããŸãã
æœè±¡æ§æããªãŒãæ§ç¯ããå ŽåãTritonã¯ïŒbapãangrãšã¯ç°ãªãïŒãã·ã³ã³ãŒãã®äžéè¡šçŸã䜿çšãããçŸåšã¯x86ããã³x86-64ã¢ãŒããã¯ãã£ã§ã®äœæ¥ã®ã¿ããµããŒãããŠããŸãã
Tritonã¯2ã€ã®ã¢ãŒãã®ããããã§åäœããŸãã æåã®ãªã³ã©ã€ã³ã¢ãŒã-å®è¡ãã¬ãŒã¹ã¯ãTritonã®äžéšã§ããã ãã³DBIãã¬ãŒã ã¯ãŒã¯ã䜿çšããç¹å¥ãªãã¬ãŒãµãŒã䜿çšããŠèšé²ãããŸã ã 2çªç®-ãªãã©ã€ã³ã¢ãŒã-ãã©ãã¯ã¯å€éšæ段ã«ãã£ãŠèšé²ãããŸãã ã«ãŒãã«ã¯ãäžé£ã®åœä»€ãšãã®ãªãã³ãŒããå«ãŸããŠããå¿ èŠããããŸãã 2çªç®ã®ã±ãŒã¹ã§ã¯ãåæã³ã³ããã¹ããç¬ç«ããŠäœæããå¿ èŠããããŸããã€ãŸããã¬ãžã¹ã¿ãšäœ¿çšã¡ã¢ãªã®å€ã決å®ããŸãã
TritonãæäŸããAPIã¯éåžžã«è±å¯ã§ãéåžžã«äžå®å®ã§ãã APIã®ç»å Žä»¥æ¥ãåŸæ¹äºææ§ãç¶æããããšãªãããã¡ãã4åå€æŽãããŠããŸãã ãã®ãããTritonã䜿çšããå€ãããŒã«ã®ã³ãŒãã¯ãæ°ããããŒãžã§ã³ã§å®è¡ããããã«æžãçŽãå¿ èŠããããŸãã è¯ãç¹ã¯ãAPIã«Pythonã®ãã€ã³ãã£ã³ã°ãããããšã§ãã ãªããžããªã«ã¯ãC ++ããã³Pythonã§ã®APIã®äœ¿çšæ¹æ³ã瀺ãããã€ãã®äŸããããããããç解ããã®ã¯éåžžã«ç°¡åã§ãã
ããã§ã¯ã解決çã«åãæãããŸãããã
解決ç
ãŸããå ¥åãããããŒããã§ãã¯ããã¢ã«ãŽãªãºã ãèŠã€ããå¿ èŠããããŸãã ã³ãŒãããã£ãšèŠãŠã¿ããšãçæãããã·ãŒã±ã³ã¹ã¯å®éã«ã¯8ã€ã®32ãããæŽæ°ã§ããããªãã«ãšã³ãã£ã¢ã³ãã¥ãŒã§ã¯ã¡ã¢ãªå ã«é£ç¶ããŠååšãããŠã£ã³ããŠã§ã¯ããã°ãšã³ãã£ã¢ã³ãšããŠè¡šç€ºãããŠããŸãã ããŒã®åœ¢åŒãXXXXXXXX-XXXXXXXXã§ããããšãããããŸããXã¯16é²æ°ã§ãã ããŒããã®åœ¢åŒã§å ¥åãããå Žåãæ€èšŒæé ãåŒã³åºãããŸãã ããã¯ãIDA Proéã¢ã»ã³ãã©ãŒã®å€èŠ³ã§ãã
æ€èšŒæé ã§ã¯ãå ¥åãæåã«åæåãããŸãïŒcipherã¯ãªãã«ãšã³ãã£ã¢ã³ãã¥ãŒã®32ãã€ãã®ãœãŒã¹ã·ãŒã±ã³ã¹ãString1ã¯å€æåŸã®åºåã·ãŒã±ã³ã¹ã®ãããã¡ãŒãedxããã³ebxã¬ãžã¹ã¿ãŒã¯32ãããæŽæ°ãšããŠè¡šãããããŒã®ååã§ãã 次ã«ãå€æã¢ã«ãŽãªãºã èªäœïŒxorããã³rolæäœã䜿çšãã32ãµã€ã¯ã«ïŒãç¶ããString1ãããã¡ãŒããã®çµæã®æååãæååã0how4zdy81jpe5xfu92kar6cgiq3lst7ããšæ¯èŒãããŸãã ããããåäžã§ããå ŽåãããŒã¯æå¹ãšèŠãªãããŸãã
ãããã£ãŠã次ã®ã¿ã¹ã¯ãSMTãœã«ããŒã«å¯ŸããŠçæãããŸããã¢ã«ãŽãªãºã ãå®è¡ãããåŸãedxããã³ebxã¬ãžã¹ã¿ã®ã©ã®å ¥åå€ãç¹å®ã®16é²æ°ã·ãŒã±ã³ã¹ãç»é²ããããæååã0how4zdy81jpe5xfu92kar6cgiq3lst7ãã«å€æããŸãã
ã¯ã©ãã¯ã®ããWindowsçšã«äœæãããŠãããããTritonãã¬ãŒãµãŒã¯Linuxçšã«ã³ã³ãã€ã«ãããŠããããåäœããŸããã ãã¡ãããWindowsçšã«èªåã§ã³ã³ãã€ã«ããããšãã§ããŸããããããã¯ãŸã åéºã§ãã ãããã£ãŠãPythonã«ã¯ãªãã©ã€ã³ã¢ãŒããšTritonãã€ã³ãã£ã³ã°ã䜿çšããŸãã
ãŸããå¿ èŠãªå®æ°ã玹ä»ããŸãã
ADDR_CIPHER = 0x4093A8 ADDR_TEXT = 0x409185 ADDR_EBP = 0x18f980 TEXT = "0how4zdy81jpe5xfu92kar6cgiq3lst7" cipher = None
ãããŠãåæåãå®è¡ããŸãã
ctx = TritonContext() ctx.setArchitecture(ARCH.X86) ctx.setConcreteRegisterValue(ctx.registers.ebp, ADDR_EBP) ctx.setConcreteRegisterValue(ctx.registers.esp, 0x18f95b) ctx.setConcreteRegisterValue(ctx.registers.eip, 0x4010ec) ctx.setConcreteMemoryAreaValue(ADDR_CIPHER, cipher) ctx.setConcreteMemoryAreaValue(ADDR_TEXT, list(map(ord, TEXT))) edx = ctx.convertRegisterToSymbolicVariable(ctx.getRegister(REG.X86.EDX)) ebx = ctx.convertRegisterToSymbolicVariable(ctx.getRegister(REG.X86.EBX)) keys = [ctx.convertMemoryToSymbolicVariable(MemoryAccess(ADDR_EBP-0x21, 1)) for i in xrange(32)]
åæåäžã«ãã³ã³ããã¹ããäœæããã¢ãŒããã¯ãã£ã確ç«ããã¬ãžã¹ã¿ãšã¡ã¢ãªãåæåãããã¡ããã·ã³ãã«å€æ°ãäœæããŸãïŒedxãšebxã®ã¬ãžã¹ã¿ãããã³å€æãããã·ãŒã±ã³ã¹ã®ãããã¡ãåŒã®å¶éã«ããå€ã課ãããŸãã
次ã«ãå®è¡ãã¬ãŒã¹ãäœæããŸãã ãªãã©ã€ã³ã¢ãŒãã§ãããè¡ãã«ã¯ããã€ããªã³ãŒããããŠã³ããŒãããã ãã§ãã
code = {0x4010EC: '\x55', # push ebp 0x4010ED: '\x8b\xec', # mov ebp, esp 0x4010EF: '\x83\xc4\xdc', # add esp, -24h 0x4010F2: '\xb9\x20\x00\x00\x00', # mov ecx, 20h 0x4010F7: '\xbe\xa8\x93\x40\x00', # mov esi, offset cipher 0x4010FC: '\x8d\x7d\xdf', # lea edi, [ebp+string1] 0x4010FF: '\x8b\x55\x08', # mov edx, [ebp+arg_0] 0x401102: '\x8b\x5d\x0c', # mov ebx, [ebp+arg_4] # loc_401105: 0x401105: '\xac', # lodsb 0x401106: '\x2a\xc3', # sub al, bl 0x401108: '\x32\xc2', # xor al, dl 0x40110A: '\xaa', # stosb 0x40110B: '\xd1\xc2', # rol edx, 1 0x40110D: '\xd1\xc3', # rol ebx, 1 0x40110F: '\xe2\xf4'} # loop loc_401105
åœä»€ã®åŠçãéå§ããŸãã
ip = 0x4010ec while ip < 0x401111: inst = Instruction() inst.setOpcode(code[ip]) inst.setAddress(ip) ctx.processing(inst) ip = ctx.buildSymbolicRegister(ctx.registers.eip).evaluate()
åœä»€ã®åŠçäžã«ãTritonã¯ããããèšå·åœ¢åŒã«å€æããåãåã£ãèšå·åœä»€ãã³ã³ããã¹ãã«è¿œå ããŸãã ãã®ã³ãŒãã§ã¯ãipã¬ãžã¹ã¿ã®ã·ã³ããªãã¯ãšãã¥ã¬ãŒã·ã§ã³ã䜿çšããŠãå®è¡é ã«æ¬¡ã®åœä»€ãèšç®ããŸãã
ãã®åŸãå€æ°ã®å€ã«å¿ èŠãªå¶éãã³ã³ããã¹ãã«å°å ¥ããããšãæ®ã£ãŠããŸãã TEXTå®æ°ã«é 眮ããæååã0how4zdy81jpe5xfu92kar6cgiq3lst7ããšå€æãããæååãçãããã©ããã«ã€ããŠããã®æ¡ä»¶ããããŸãã
for i in xrange(32): r_ast = ast.bv(ord(TEXT[i]), 8) l_id = ctx.getSymbolicMemoryId(ADDR_EBP-0x21 + i) l_ast = ctx.getAstFromId(l_id) ex = ast.equal(l_ast, r_ast) expr.append(ex) expr = ast.land(expr)
å¶çŽã¯ãæœè±¡æ§æããªãŒïŒASDïŒã®ããŒãã®åœ¢åŒã§èšå®ãããŸãã ã«ãŒãã§ã¯ãæååã®1æåã®ASDããŒããšãå€æãããã·ãŒã±ã³ã¹ã®1ã€ã®èŠçŽ ã®ASDããŒããäœæãããŸãã 次ã«ãããã2ã€ã®ããŒããæ¯èŒããæäœãå«ãæ°ããASDããŒããäœæãããŸãã ãã¹ãŠã®èŠçŽ ã®ç䟡æ¡ä»¶ã¯åæã«æºããããå¿ èŠãããããããµã€ã¯ã«ã§ããããåãåã£ãåŸãè«çANDæŒç®expr = ast.landïŒexprïŒã®äžã§1ã€ã®ASDã«çµåãããŸãã
ãã¹ãŠã解ãèšç®ããæºåãã§ããŠããŸãã æå®ãããexprå¶çŽãæã€ã·ã³ããªãã¯åŒã®ããŒã¿ã¢ãã«ãååŸããŸãã
model = ctx.getModel(expr)
keygenã¹ã¯ãªããå šäœã¯ãããããå®å šã«ããŠã³ããŒãã§ããŸã ã
ã¹ã¯ãªãããå®è¡ãããš...äœãèµ·ãããŸããã ãããã°ã¯ãåœä»€ã®åŠç段éã§å®è¡ã«ãŒããçºçããããšã瀺ããŠãããã«ãŒãåœä»€ãåŠçãããŠããªãããšãããã«æããã«ãªããŸãã ããªãã³ã¯ãã®åœä»€ããç¥ããªãããšãå€æãã ã ãã®åé¡ã«å¯ŸåŠããæ¹æ³ã¯ïŒ æ°ããåœä»€ã®ã»ãã³ãã£ã¯ã¹ãTritonãœãŒã¹ã«è¿œå ããŠåæ§ç¯ã§ããŸãã ããããWindowsã§ã®åæ§ç¯ã¯ããªã骚ã®æããäœæ¥ã§ãããšæ¢ã«è¿°ã¹ãŸããã ããŒããããã«åæºããããšã¯ãããŸãããã³ãŒããããçŽããŠãã ããã ã«ãŒããå®éã®åäœãšåãåœä»€ã»ããã§çœ®ãæããŠã¿ãŠãã ãããäŸïŒ
dec ecx jz 0401105h
ãããŠãæåã§ã«ãŒããå±éããŠãå éšã«ã«ãŒãã®ãããããã¯ã§ã¯ãªããecxã¬ãžã¹ã¿ã«æžã蟌ãŸããŠããã«ãŒãæ¬äœïŒ32ïŒã ããåŠçããããšãã§ããŸããã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
code = ['\xac', # lodsb '\x2a\xc3', # sub al, bl '\x32\xc2', # xor al, dl '\xaa', # stosb '\xd1\xc2', # rol edx, 1 '\xd1\xc3'] # rol ebx, 1 ctx.setConcreteRegisterValue(ctx.registers.esi, ADDR_CIPHER) ctx.setConcreteRegisterValue(ctx.registers.edi, ADDR_EBP - 0x21) ctx.setConcreteRegisterValue(ctx.registers.eip, 0x401105) ctx.setConcreteMemoryAreaValue(ADDR_CIPHER, cipher) ctx.setConcreteMemoryAreaValue(ADDR_TEXT, list(map(ord, TEXT))) edx = ctx.convertRegisterToSymbolicVariable(ctx.registers.edx) ebx = ctx.convertRegisterToSymbolicVariable(ctx.registers.ebx) ip = 0x401105 for i in xrange(32): for c in code: inst = Instruction() inst.setOpcode(c) inst.setAddress(ip) ctx.processing(inst) ip = ctx.buildSymbolicRegister(ctx.registers.eip).evaluate()
ããã§ãæ°ãããªãã·ã§ã³ãèµ·åããŸãã ä»åã¯ãåŠçãå®å šã«å®è¡ãããäºæ³ã©ããããã°ããã®éãã¢ãã«ã®èšç®ã«æåããŸãã ç§ãã¡ã¯åŸ ã£ãŠããŸã...åŸ ã£ãŠããŸã...ç§ãã¡ã¯éåžžã«é·ãéåŸ ã£ãŠããŸããã åŸ ããªãã£ãã ä»åã¯ãåé¡ã¯ã¢ãã«ãèšç®ããæ©èœã§ãããããã§ãšã©ãŒãæ€åºããã®ã¯ããã»ã©ç°¡åã§ã¯ãªããããããŸããã çµæã®åŒã¯éåžžã«å€§ããããã®èšç®ã«ã¯éåžžã«é·ãæéãããããšæ³å®ã§ããŸãã ããã確èªããããã«ãåŠçãè¡ãããã«ãŒãã®å埩åæ°ãæžãããŸãã å®éãå埩åæ°ãå°ãªããšãçµæãåºåãããŸãã éžææ¹æ³ã䜿çšãããšãå®éšçšã©ãããããã§èšç®ã«èŠããæéããããå埩åæ°ã®äžéã¯12ã§ããããšãããããŸãããã¯ããéåžžã«å°ããããã®å¢å ã«äŒŽããæéãææ°é¢æ°çã«å¢å ããŸãã 32åã®å埩ã¯12ãã¯ããã«è¶ ããŠãããC ++ã§ã³ãŒããæžãæãããšããŠãããšã«ãããã¢ãã«ã®èšç®ã¯èš±å®¹ã§ããªãã»ã©é·ããªãããã§ãã
getModelé¢æ°ã§éåžžã«æéãããããããã°ã調ã¹ãããšãããšããããã¯triton::ast::TritonToZ3Ast::convert
é¢æ°ã®ååž°åŒã³åºãã§ããããšãtriton::ast::TritonToZ3Ast::convert
ãŸãã
ããã¥ã¡ã³ãã«æžãããŠããããã«ãTritonã¯ã«ã¹ã¿ã ASDããªãŒã䜿çšããŸãã
æœè±¡æ§ææšïŒASTïŒã¯ãææ³ãæšãšããŠè¡šçŸãããã®ã§ãã Tritonã¯ãåŒã«ã«ã¹ã¿ã ASTã䜿çšããŸãã ãã¹ãŠã®åŒã¯å®è¡æã«æ§ç¯ããããããASTã¯åããã°ã©ã ãã€ã³ãã§äœ¿çšã§ããŸãã -Tritonããã¥ã¡ã³ã
ãã®é¢æ°ã¯ãTritonã®ADSãz3ã®åŒã«å€æããŸãã
Tritonã®ASDãæ§æããè¡šçŸãèŠãŠã¿ãããšãã§ããŸãã ã¢ãã«ãååŸããåã«ã次ã®è¡ãè¿œå ããŸãã
tsym = ctx.getSymbolicExpressions() for ek in sorted(tsym.keys()): e = tsym[ek].getAst() print str(e)
ãã®åŸã次ã®TritonåŒãã³ã³ãœãŒã«ã«è¡šç€ºãããŸãã
ref!0 = SymVar_0 ref!1 = SymVar_1 ref!2 = SymVar_33 ; Byte reference ref!3 = (concat ((_ extract 31 8) (_ bv0 32)) (_ bv29 8)) ; LODSB operation ref!4 = (ite (= (_ bv0 1) (_ bv0 1)) (bvadd (_ bv4232104 32) (_ bv1 32)) (bvsub (_ bv4232104 32) (_ bv1 32))) ; Index operation ref!5 = (_ bv4198662 32) ; Program Counter ref!6 = (concat ((_ extract 31 8) ref!3) (bvsub ((_ extract 7 0) ref!3) ((_ extract 7 0) ref!1))) ; SUB operation ref!7 = (ite (= (_ bv16 8) (bvand (_ bv16 8) (bvxor ((_ extract 7 âŠ
SMT-LIBæ§æã®åŒãååŸããã«ã¯ãå¥ã®åŒã³åºããè¿œå ããå¿ èŠããããŸãã
print ctx.unrollAst(e)
ãã®å ŽæunrollAst
ãTritonã®åŒããSMT-LIBåŒãžã®åãå€æãè¡ãããŸãããããã§ãgetModelé¢æ°ã®ããã«å®äºãåŸ
ã€ããšã¯ãããŸããã
SMT-LIBæ§æã«ç²ŸéããŠãã人ã¯ãTritonã®åŒãSSAïŒåäžéçå²ãåœãŠïŒã®åœ¢åŒã®ã¿ã®SMT-LIBåŒã§ããããšã«æ°ä»ãã§ãããã SMT-LIBã«ã¯å€æ°ã®å²ãåœãŠæäœã¯ãããŸãã-æ©èœçãªletæŒç®åã«çœ®ãæããããŸãã ããããASDããããã€ããã«Tritonã®æ§æãSMT-LIBæ§æã«ç¬ç«ããŠå€æããSSAãã©ãŒã ãletã¹ããŒãã¡ã³ãã«çœ®ãæããŠããz3pyã«ãã£ãŒãããããšãããšã©ããªããŸããïŒ ããªãé¢åã§åé·ã«èãããŸãããéçºè
ãTritonãå®æããããŸã§ãã®ç¶æ³ããæãåºãå¿
èŠããããŸãã
ãããã£ãŠãçµæã®åŒã䜿çšããŠã次ã®ã¢ã¯ã·ã§ã³ãå®è¡ããŸãã
- SMT-LIBæ§æã§å€æ°ã宣èšããŸãã
- å²ãåœãŠæŒç®åãletã¹ããŒãã¡ã³ãã«çœ®ãæããŸãã
- çµæã®åŒã¯ãSMT-LIBèšèªã§å ±éã®åŒã«çµåãããŸãã
çµæã¯ãTritonæ§æããSMT-LIBæ§æãžã®å€æé¢æ°ã§ãã ãã¡ãããããã¯æ®éçã§ã¯ãããŸããããå°ãªããšãç§ãã¡ã®ä»äºã«ã¯åœ¹ç«ã¡ãŸãã
def convert(ctx, asserts): zsym = "" tsym = ctx.getSymbolicExpressions() for ek in sorted(tsym.keys()): e = tsym[ek].getAst() if e.getKind() == AST_NODE.VARIABLE: zsym += "(declare-fun ref!%d () (_ BitVec %d))\n" % (ek, e.getBitvectorSize()) nodes = [] for ek in sorted(tsym.keys()): e = tsym[ek].getAst() if e.getKind() <> AST_NODE.VARIABLE: nodes.append("let ((ref!%d %s))" % (ek, e)) # print reduce(lambda x, y: "%s (%s)" % (x, y), reversed(nodes)) def fold(x, y): if not isinstance(y, list): raise TypeError if len(y) == 1: return y[0] return "%s\n(%s)" % (x, fold(y[0], y[1:])) nodes = ["assert"] + nodes nodes[-1] += '\n' + str(asserts) zsym = zsym + '(' + fold(nodes[0], nodes[1:]) + ')' return zsym
é¢æ°ã®çµæã¯ãèšç®ã®ããã«z3pyãœã«ããŒã«éä¿¡ããå¿ èŠããããŸãã
s = z3.Solver() cs = z3.parse_smt2_string(expr) s.assert_exprs(cs) s.check() m = s.model() edx, ebx = m.decls()
çŸåšãedxããã³ebxå€æ°ã«ã¯ã z3.z3.FuncDeclRef
ã¯ã©ã¹ã®ãªããžã§ã¯ããz3.z3.FuncDeclRef
ãŸãã ãããã®æ°å€è¡šçŸãååŸããäºè£å
ã®å€æã¯äºãã«ãããããåŸã«å®è¡ããããããããããããããããå¿
èŠããããŸãã
edx, ebx = m[edx].as_long(), m[ebx].as_long() print "%x-%x" % (edx, edx ^ ebx)
2çªç®ã®ããŒãžã§ã³ã®ã³ãŒãã¯githubããååŸããããšãã§ããŸãã
ãã®ãããäºè£ã®ãããŠã£ã³ããŠã®å ¥åãã£ãŒã«ãã«ã³ããŒããã ãã®è¡ãåŸãããŸãã æã®ããã¿ã¯ãã§ã«ãããããŠããŸãã
ãã£ãïŒ keygenã¯æ£åžžã«åäœããŠããŸãã
ãã³ã»
Tritonã«åºã¥ããŠãIDA Proã®Ponceãã©ã°ã€ã³ãšããå¥ã®ã¯ãŒã«ãªããŒã«ãæ§ç¯ãããŸãã IDAéã¢ã»ã³ãã©ãŒã§ã®ã·ã³ããªãã¯å®è¡ãšæ±æåæãçŽæ¥è¡ãããšã§ãéåžžã«é åçãªããšãã§ããŸãã æ®å¿µãªãããã¯ã©ãã¯å ã«ã«ãŒãåœä»€ãååšãããããPonceããã§ãã¯ã§ããŸããã ãã¶ããTritonã«ã«ãŒããè¿œå ããã人ããŸã ããã§ããããïŒ :)ãŸãã¯ãå¥ã®ãªãã·ã§ã³ããããŸãã kao crackedã«ã¯ã¢ã»ã³ãã©ã®ãœãŒã¹ã³ãŒããä»å±ããŠãããããã«ãŒããåè¿°ã®åæ§ã®åœä»€ã»ããã«çœ®ãæããããšãã§ããŸãã ãã®åŸãPonceã䜿çšããŠãã®åãæããããšãå€æããŸãã èå³ã®ããèªè ã«ãšã£ãŠãããã¯ã¯ãŒã«ãªã¿ã¹ã¯ã«ãªããŸãã
çµè«
ççŽã«èšã£ãŠãããªãã³ã¯ã¿ã¹ã¯ã«å¯ŸåŠããŸããã§ããã ãã ããå³å¯ã«ãªããããªãããã«ããŸããããã«ãŒãã¹ããŒãã¡ã³ãã¯ç°¡åã«è¿œå ã§ããŸãããŸããã¢ã»ã³ããªã®å±¥æŽããå€æãããšãéçºè ã¯æ¢ã«å埩åŠçãéå§ããŠããŸã ã
ææ°ã®ãªããŒã¹ãšã³ãžãã¢ãªã³ã°ãšãã·ã³ããªãã¯å®è¡ã䌎ããªããœãããŠã§ã¢ã®è匱æ§ã®æ€çŽ¢ã¯éå»ã®ãã®ã§ãã ããã¯ãããšãã°ãDARPAãµã€ããŒã°ã©ã³ããã£ã¬ã³ãžäžã«äœæãããèªåè匱æ§æ€çŽ¢ããã³ãšã¯ã¹ããã€ãçæã·ã¹ãã ã«ãã£ãŠèšŒæãããŸãã ãã®ãããTritonãªã©ã®ããŒã«ã¯çŸåšå€§ããªéèŠããããŸãã ããããçºå±ããã«ã€ããŠããããã¯ãŸããŸã䜿ãããããªãããã®çµæã象城çãªããã©ãŒãã³ã¹ã¯ç 究è ã®ä»äºã«ãããŠéåžžã«æé ã§å¹æçãªããŒã«ã«ãªããŸãã