{"id":3278,"date":"2017-07-16T15:04:12","date_gmt":"2017-07-16T13:04:12","guid":{"rendered":"https:\/\/0x90r00t.com\/?p=3278\/"},"modified":"2018-04-11T21:36:08","modified_gmt":"2018-04-11T19:36:08","slug":"meepwn-2017-crypto-100-math-write-up","status":"publish","type":"post","link":"https:\/\/0x90r00t.com\/fr\/2017\/07\/16\/meepwn-2017-crypto-100-math-write-up\/","title":{"rendered":"[MeePwn 2017] [Crypto 100 \u2013 MATH] Write Up"},"content":{"rendered":"<h2>Description<\/h2>\n<p>I hack your brain!<\/p>\n<p>Et nous avons un script en python nomm\u00e9 hack.py dont voici le contenu.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/python\r\nfrom Crypto.Util.number import *\r\nfrom hashlib import md5\r\n \r\nflag = &quot;XXX&quot;\r\nassert len(flag) == 14\r\npad = bytes_to_long(md5(flag).digest())\r\n \r\nhack = 0\r\nfor char in flag:\r\n    hack+= pad\r\n    hack*= ord(char)\r\nprint hack\r\n \r\n#hack = 64364485357060434848865708402537097493512746702748009007197338675\r\n#flag_to_submit = &quot;MeePwnCTF{&quot; + flag + &quot;}&quot;\r\n<\/pre>\n<p><!--more--><\/p>\n<h2>Resolution<\/h2>\n<p>Une rapide analyse du script en python permet de comprendre que 64364485357060434848865708402537097493512746702748009007197338675 est un produit plusieurs facteurs.<\/p>\n<p>Avec <a href=\"https:\/\/factordb.com\/\">factordb<\/a>, nous obtenons\u00a0la liste de tous les facteurs\u00a0: 3,3,5,5,7,107,487,607,28429,29287,420577267963,3680317203978923 et 1002528655290265069.<\/p>\n<p>Apr\u00e8s avoir test\u00e9 le script plusieurs fois avec un flag de 14 caract\u00e8res, on voit que le pad contient environ 39 chiffres. De plus, le pad est un produit de plusieurs facteurs parmi ceux trouv\u00e9s pr\u00e9c\u00e9demment.<\/p>\n<p>Il est donc possible de bruteforcer le pad pour en d\u00e9duire les caract\u00e8res du flag.<\/p>\n<p>Pour cela, il faut g\u00e9n\u00e9rer toutes les combinaisons possibles du pad \u00e0 partir des facteurs trouv\u00e9s, en rejetant les combinaisons comprenant moins de 39 chiffres.<\/p>\n<p>Oui, mais le pad contient combien de facteurs\u00a0?<\/p>\n<p>Apr\u00e8s plusieurs tentative, nous avons trouv\u00e9 une solution avec 6 facteurs.<\/p>\n<p>De plus, pour r\u00e9soudre cette \u00e9preuve, le but est de\u00a0 \u00ab\u00a0reverse\u00a0\u00bb cette partie du script dans la r\u00e9alisation du bruteforce:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n\r\nhack+= pad\r\n\r\nhack*= ord(char)\r\n\r\n<\/pre>\n<p>C&rsquo;est assez facile, il suffit de faire:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n\r\nhack \/= ord(char)\r\n\r\nhack -= pad\u00a0\r\n\r\n<\/pre>\n<p>Notre premier script donne trop de faux positifs, il faut donc penser \u00e0 tester les solutions pour trouver la bonne.<\/p>\n<p>Voici le script final qui donne la solution.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/python\r\nimport itertools\r\nfrom Crypto.Util.number import *\r\nfrom hashlib import md5\r\n \r\nl = &#x5B;3,3,5,5,7,107,487,607,28429,29287,420577267963,3680317203978923,1002528655290265069] \r\n \r\nnbre_permutation = 6\r\ncomb = list(itertools.permutations(l, nbre_permutation))\r\ncandidat = list()\r\nfor i in comb:\r\n  p = 1\r\n  for j in range(nbre_permutation):\r\n    p *= i&#x5B;j]\r\n    if p not in candidat and p &gt; 10000000000000000000000000000000000000: candidat.append(p) # Au moins 37 chiffres\r\n \r\ncharset = &#x5B;' ', '!', '&quot;', '#', '$', '%', '&amp;', &quot;'&quot;, '(', ')', '*', '+', ',', '-', '.', '\/', '0', '1',\r\n          '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '&lt;', '=', '&gt;', '?', '@', 'A', 'B', 'C', 'D', 'E',\r\n          'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',\r\n          'Z', '&#x5B;', '\\\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\r\n          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}']\r\nprint charset\r\n  \r\nhack = 64364485357060434848865708402537097493512746702748009007197338675\r\nfor p in candidat:\r\n  for c in charset:\r\n  l = hack\/ord(c)\r\n  if l*ord(c) == hack:\r\n    h = hack\/ord(c) - p\r\n    for c1 in charset:\r\n      l1 = h\/ord(c1)\r\n      if l1*ord(c1) == h:\r\n        h1 = h\/ord(c1) -p\r\n        for c2 in charset:\r\n          l2 = h1\/ord(c2)\r\n          if l2*ord(c2) == h1:\r\n            h2 = h1\/ord(c2) -p\r\n            for c3 in charset:\r\n              l3 = h2\/ord(c3)\r\n              if l3*ord(c3) == h2:\r\n                h3 = h2\/ord(c3) - p\r\n                for c4 in charset:\r\n                  l4 = h3\/ord(c4)\r\n                  if l4*ord(c4) == h3:\r\n                    h4 = h3\/ord(c4) - p\r\n                      for c5 in charset:\r\n                        l5 = h4\/ord(c5)\r\n                        if l5*ord(c5) == h4:\r\n                          h5 = h4\/ord(c5) - p\r\n                          for c6 in charset:\r\n                            l6 = h5\/ord(c6)\r\n                            if l6*ord(c6) == h5:\r\n                              h6 = h5\/ord(c6) - p\r\n                              for c7 in charset:\r\n                                l7 = h6\/ord(c7)\r\n                                if l7*ord(c7) == h6:\r\n                                  h7 = h6\/ord(c7) - p\r\n                                  for c8 in charset:\r\n                                    l8 = h7\/ord(c8)\r\n                                    if l8*ord(c8) == h7:\r\n                                      h8 = h7\/ord(c8) - p\r\n                                      for c9 in charset:\r\n                                        l9 = h8\/ord(c9)\r\n                                        if l9*ord(c9) == h8:\r\n                                          h9 = h8\/ord(c9) - p\r\n                                           for c10 in charset:\r\n                                             l10 = h9\/ord(c10)\r\n                                             if l10*ord(c10) == h9:\r\n                                               h10 = h9\/ord(c10) - p\r\n                                               for c11 in charset:\r\n                                                 l11 = h10\/ord(c11)\r\n                                                 if l11*ord(c11) == h10:\r\n                                                   h11 = h10\/ord(c11) - p\r\n                                                   for c12 in charset:\r\n                                                     l12 = h11\/ord(c12)\r\n                                                     if l12*ord(c12) == h11:\r\n                                                       h12 = h11\/ord(c12) - p\r\n                                                       for c13 in charset:\r\n                                                         l13 = h12\/ord(c13)\r\n                                                         if l13*ord(c13) == h12:\r\n                                                           h13 = h12\/ord(c13) - p\r\n                                                           sol = c+c1+c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13\r\n                                                             if h13 == 0:\r\n                                                               flag = sol&#x5B;::-1] # On retourne le string # Verification de la solution pour eliminer les faux positifs\r\n                                                               pad2 = bytes_to_long(md5(flag).digest())\r\n                                                               hack2 = 0\r\n                                                               for char in flag:\r\n                                                                 hack2 += pad2\r\n                                                                 hack2 *= ord(char)\r\n                                                                 if hack2 == hack:\r\n                                                                   print &quot;Bingo !!!&quot;\r\n                                                                   print sol&#x5B;::-1]\r\n \r\n<\/pre>\n<p>Le flag est MeePwnCTF{d0y0ul1keM@TH?}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description I hack your brain! Et nous avons un script en python nomm\u00e9 hack.py dont voici le contenu. #!\/usr\/bin\/python from Crypto.Util.number import * from hashlib import md5 flag = &quot;XXX&quot; assert len(flag) == 14 pad = bytes_to_long(md5(flag).digest()) hack = 0 for char in flag: hack+= pad hack*= ord(char) print hack #hack = 64364485357060434848865708402537097493512746702748009007197338675 #flag_to_submit = &hellip; <a href=\"https:\/\/0x90r00t.com\/fr\/2017\/07\/16\/meepwn-2017-crypto-100-math-write-up\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">[MeePwn 2017] [Crypto 100 \u2013 MATH] Write Up<\/span>  <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[245,263],"tags":[],"class_list":["post-3278","post","type-post","status-publish","format-standard","hentry","category-245","category-meepwn"],"_links":{"self":[{"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/posts\/3278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/comments?post=3278"}],"version-history":[{"count":32,"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/posts\/3278\/revisions"}],"predecessor-version":[{"id":3390,"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/posts\/3278\/revisions\/3390"}],"wp:attachment":[{"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/media?parent=3278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/categories?post=3278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/0x90r00t.com\/fr\/wp-json\/wp\/v2\/tags?post=3278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}