{"id":328,"date":"2014-03-04T19:56:50","date_gmt":"2014-03-04T17:56:50","guid":{"rendered":"http:\/\/calypt.com\/blog\/?p=328"},"modified":"2014-03-05T16:32:41","modified_gmt":"2014-03-05T14:32:41","slug":"boston-key-party-2014-write-mind-ps-qs-crypto-100","status":"publish","type":"post","link":"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/","title":{"rendered":"Boston Key Party 2014 \u2013 Write-up Mind your P&#8217;s and Q&#8217;s! CRYPTO 100"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-329\" alt=\"Boston Key Party\" src=\"http:\/\/calypt.com\/blog\/wp-content\/uploads\/2014\/03\/525b87dfa0f195a2a56933e1bb601c33.png\" width=\"178\" height=\"178\" srcset=\"https:\/\/www.calypt.com\/blog\/wp-content\/uploads\/2014\/03\/525b87dfa0f195a2a56933e1bb601c33.png 256w, https:\/\/www.calypt.com\/blog\/wp-content\/uploads\/2014\/03\/525b87dfa0f195a2a56933e1bb601c33-150x150.png 150w\" sizes=\"(max-width: 178px) 100vw, 178px\" \/><\/p>\n<p><strong>Fichiers de l&#8217;\u00e9preuve<\/strong> (<strong>fournis par Boston Key Party)<\/strong> : <a href=\"http:\/\/calypt.com\/blog\/wp-content\/uploads\/2014\/03\/challenge-cd6d19866c42e274cd09604adaf4077b.tar.gz\">challenge-cd6d19866c42e274cd09604adaf4077b.tar<\/a><\/p>\n<p><strong>Description<\/strong> : \u00ab The flag has been split into several files, and encrypted under RSA-OAEP. Can you break ALL of the ciphertexts, and reassemble the key \u00bb<\/p>\n<p>&nbsp;<\/p>\n<p>On est face \u00e0 un <a title=\"GreHack 2013 \u2013 Write-up CRYPTO 300 Microsoft PKI\" href=\"http:\/\/calypt.com\/blog\/index.php\/grehack-write-crypto-300\/\" target=\"_blank\">challenge RSA classique<\/a>. Le titre nous met sur la piste de param\u00e8tres <span style=\"text-decoration: underline;\">p<\/span> et <span style=\"text-decoration: underline;\">q<\/span> mal choisis. \u00c9tant donn\u00e9 que l&#8217;archive est compos\u00e9e de 24 chiffr\u00e9s \/ clefs publiques associ\u00e9es, une bonne fa\u00e7on de mal choisir <span style=\"text-decoration: underline;\">p<\/span> et <span style=\"text-decoration: underline;\">q<\/span> serait d&#8217;utiliser plusieurs fois les m\u00eames. On s&#8217;aper\u00e7oit rapidement que c&#8217;est effectivement le cas : en faisant des <a title=\"gcd\" href=\"http:\/\/fr.wikipedia.org\/wiki\/Plus_grand_commun_diviseur\" target=\"_blank\">gcd<\/a> sur les param\u00e8tres <span style=\"text-decoration: underline;\">n<\/span> des clefs publiques, ont retrouve des <span style=\"text-decoration: underline;\">p<\/span> communs.<\/p>\n<p>Pour r\u00e9soudre le challenge on construit donc la liste d[] des clefs priv\u00e9es puis on d\u00e9chiffre en utilisant la librairie <a title=\"PyCrypto\" href=\"https:\/\/www.dlitz.net\/software\/pycrypto\/\" target=\"_blank\">pycrypto<\/a> et plus particuli\u00e8rement le module <a href=\"https:\/\/www.dlitz.net\/software\/pycrypto\/api\/current\/Crypto.Cipher.PKCS1_OAEP.PKCS1OAEP_Cipher-class.html\" target=\"_blank\">OAEP<\/a>. <a title=\"Sage\" href=\"http:\/\/sagemath.org\/index.html\" target=\"_blank\">Sage 6.1.1<\/a> embarque pycrypto et on peut donc r\u00e9soudre le challenge avec le code suivant :<\/p>\n<p>[pastacode provider=&#8221;manual&#8221; lang=&#8221;python&#8221;]<\/p>\n<pre><code>from Crypto.Cipher import PKCS1_OAEP\r\nfrom Crypto.PublicKey import RSA\r\n\r\npub_keys=[]; p=[]; q=[]; d=[]\r\n\r\n#I - import des clefs publiques\r\nfor i in xrange(24): \r\n    pub_keys.append(RSA.importKey(open('\/tmp\/challenge\/'+str(i)+'.key').read()))\r\n\r\n#II - calculs des d[] : l'exposant priv\u00e9\r\nfor i in xrange(24): \r\n    p.append(1)\r\n    tmp=0\r\n    while p[i]&lt;2 or p[i]&gt;=pub_keys[i].n: #recherche d'un p commun parmis les clefs pub\r\n        p[i]=gcd(pub_keys[i].n,pub_keys[tmp].n)\r\n        tmp=tmp+1\r\n    q.append(pub_keys[i].n\/p[i])\r\n    d.append(inverse_mod(pub_keys[i].e,(p[i]-1)*(q[i]-1)))\r\n\r\n#III - dechiffrement RSA OAEP\r\nflag=''\r\nfor i in xrange(24):\r\n    key = RSA.construct((long(pub_keys[i].n),long(pub_keys[i].e),long(d[i])))\r\n    cipher = PKCS1_OAEP.new(key)\r\n    flag+=cipher.decrypt(open(\"\/tmp\/challenge\/\"+str(i)+\".enc\").read())\r\nprint flag<\/code><\/pre>\n<p>[\/pastacode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fichiers de l&#8217;\u00e9preuve (fournis par Boston Key Party) : challenge-cd6d19866c42e274cd09604adaf4077b.tar Description : \u00ab The flag has been split into several files, and encrypted under RSA-OAEP. Can you break ALL of the ciphertexts, and reassemble the key \u00bb &nbsp; On est face \u00e0 un challenge RSA classique. Le titre nous met sur la piste de param\u00e8tres [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[53,17,23,40,39],"tags":[57,48,45],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<meta name=\"description\" content=\"Write-up du CTF Boston Key Party 2014 \u2013 Mind your P&#039;s and Q&#039;s! CRYPTO 100. Challenge RSA classique \u00e0 base de gcd() et d&#039;OAEP. On utilise SAGE et pycrypto.\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Boston Key Party 2014 \u2013 Write-up Mind your P&#039;s and Q&#039;s! CRYPTO 100 - Calypt\" \/>\n<meta property=\"og:description\" content=\"Write-up du CTF Boston Key Party 2014 \u2013 Mind your P&#039;s and Q&#039;s! CRYPTO 100. Challenge RSA classique \u00e0 base de gcd() et d&#039;OAEP. On utilise SAGE et pycrypto.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/\" \/>\n<meta property=\"og:site_name\" content=\"Calypt\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-04T17:56:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-05T14:32:41+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/calypt.com\/blog\/wp-content\/uploads\/2014\/03\/525b87dfa0f195a2a56933e1bb601c33.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.calypt.com\/blog\/#website\",\"url\":\"https:\/\/www.calypt.com\/blog\/\",\"name\":\"Calypt\",\"description\":\"Security thoughts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.calypt.com\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/calypt.com\/blog\/wp-content\/uploads\/2014\/03\/525b87dfa0f195a2a56933e1bb601c33.png\",\"contentUrl\":\"http:\/\/calypt.com\/blog\/wp-content\/uploads\/2014\/03\/525b87dfa0f195a2a56933e1bb601c33.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/#webpage\",\"url\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/\",\"name\":\"Boston Key Party 2014 \\u2013 Write-up Mind your P's and Q's! CRYPTO 100 - Calypt\",\"isPartOf\":{\"@id\":\"https:\/\/www.calypt.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/#primaryimage\"},\"datePublished\":\"2014-03-04T17:56:50+00:00\",\"dateModified\":\"2014-03-05T14:32:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.calypt.com\/blog\/#\/schema\/person\/b39592c4058c8985f373832ef96a7cf6\"},\"description\":\"Write-up du CTF Boston Key Party 2014 \\u2013 Mind your P's and Q's! CRYPTO 100. Challenge RSA classique \\u00e0 base de gcd() et d'OAEP. On utilise SAGE et pycrypto.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.calypt.com\/blog\/\",\"url\":\"https:\/\/www.calypt.com\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/\",\"url\":\"https:\/\/www.calypt.com\/blog\/index.php\/boston-key-party-2014-write-mind-ps-qs-crypto-100\/\",\"name\":\"Boston Key Party 2014 \\u2013 Write-up Mind your P&#8217;s and Q&#8217;s! CRYPTO 100\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.calypt.com\/blog\/#\/schema\/person\/b39592c4058c8985f373832ef96a7cf6\",\"name\":\"Lo\\u00efc\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.calypt.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3c9955a661ca1f761736f9a7f32772c3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3c9955a661ca1f761736f9a7f32772c3?s=96&d=mm&r=g\",\"caption\":\"Lo\\u00efc\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/328"}],"collection":[{"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=328"}],"version-history":[{"count":6,"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/328\/revisions"}],"predecessor-version":[{"id":336,"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/328\/revisions\/336"}],"wp:attachment":[{"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.calypt.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}