{"id":1965,"date":"2016-04-03T00:21:07","date_gmt":"2016-04-02T22:21:07","guid":{"rendered":"https:\/\/www.asafety.fr\/?p=1965"},"modified":"2016-07-25T00:35:15","modified_gmt":"2016-07-24T22:35:15","slug":"ctf-ndh-2016-quals-write-up-inforensic-invest","status":"publish","type":"post","link":"https:\/\/www.asafety.fr\/en\/vuln-exploit-poc\/ctf-ndh-2016-quals-write-up-inforensic-invest\/","title":{"rendered":"[CTF NDH 2016 Quals] Write-Up \u2013 Inforensic : Invest"},"content":{"rendered":"<p><\/p>\n<p style=\"text-align: center;\"><strong>Write-up of the challenge \u201cInforensic\u00a0\u2013 Invest\u201d of Nuit du\u00a0Hack 2016 CTF qualifications.<\/strong><\/p>\n<div class=\"panel panel-success\">\n<p>The weekend of 04\/01\/2016 is pre-qualification for the <strong><a href=\"https:\/\/nuitduhack.com\/fr\/\" target=\"_blank\">Nuit du Hack 2016<\/a><\/strong>\u00a0as a <strong>Jeopardy CTF<\/strong>. Having had the opportunity and the time to participate with some colleagues and friends, here\u2019s a write-up resolution of the challenges which we could participate.<\/p>\n<ul>\n<li>Category: <strong>Inforensic<\/strong><\/li>\n<li>Name: <strong>Invest<\/strong><\/li>\n<li>Description : <em>A paranoid guy seems to have secured his file very well. But I am convinced he made a mistake somewhere&#8230;<\/em><\/li>\n<li>URL : http:\/\/static.quals.nuitduhack.com\/invest.pcapng<\/li>\n<li>Points :\u00a0<strong>50<\/strong><\/li>\n<\/ul>\n<\/div>\n<p>The pcapng file recovered, we open it with Wireshark to observe the different frames. This file is provided, let&#8217;s look to potential objects related to HTTP requests by exporting (File&gt; Export Objects&gt; HTTP &#8230;).<\/p>\n<div id=\"attachment_1966\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/01-1.png\" rel=\"attachment wp-att-1966\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1966\" class=\"size-medium wp-image-1966\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/01-1-300x186.png\" alt=\"Export des objets HTTP depuis le pcap\" width=\"300\" height=\"186\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/01-1-300x186.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/01-1-768x476.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/01-1-1024x634.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/01-1.png 1501w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1966\" class=\"wp-caption-text\">Exporting HTTP object from pcapng file<\/p><\/div>\n<p>When accessing files that have been exported, several are of interest:<\/p>\n<div id=\"attachment_1967\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/02-1.png\" rel=\"attachment wp-att-1967\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1967\" class=\"size-medium wp-image-1967\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/02-1-300x261.png\" alt=\"Fichiers export\u00e9s du pcapng\" width=\"300\" height=\"261\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/02-1-300x261.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/02-1-768x669.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/02-1.png 882w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1967\" class=\"wp-caption-text\">Files exported<\/p><\/div>\n<ul>\n<li><strong>key.txt<\/strong>\n<ul>\n<li>Contains a string composed only of &#8220;0&#8221; and &#8220;1&#8221; as\u00a0a binary string. The filename is speaking &#8230;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>010001110101111001100011011011100100100100111001010111100100011101000111001110010100011100111001010001110011100101000111001110010101111001100011011011100100100101101110010010010011100100110101010111100110001100111001001101010110111001001001011011100100100101000111010111100011100100110101011011100100100101011110011000110100011101011110001110010011010101011110011000110101111001100011010111100110001101000111010111100101111001100011011011100100100101000111010111100011100100110101010001110101111001101110010010010101111001100011010111100110001101101110010010010101111001100011010111100110001100111001001101010100011101011110010111100110001101011110011000110101111001100011010001110101111001000111010111100101111001100011011011100100100101101110010010010101111001100011<\/pre>\n<ul>\n<li><strong>encrypt*<\/strong>\n<ul>\n<li>Many files whose content appears in base64 are present, from\u00a0&#8220;encryptaa&#8221; to &#8220;encryptdc&#8221;, or 81 encrypted files.<\/li>\n<\/ul>\n<\/li>\n<li><strong>12767348_10208095326368148_1014857467_n.jpeg<\/strong>\n<ul>\n<li>This image shows a block diagram of binary processing, consisting of NOT, AND, OR and XOR operators. 8 bit input to provide a single bit in output.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div id=\"attachment_1968\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/12767348_10208095326368148_1014857467_n.jpeg\" rel=\"attachment wp-att-1968\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1968\" class=\"size-medium wp-image-1968\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/12767348_10208095326368148_1014857467_n-300x171.jpeg\" alt=\"Sch\u00e9ma logique\" width=\"300\" height=\"171\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/12767348_10208095326368148_1014857467_n-300x171.jpeg 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/12767348_10208095326368148_1014857467_n.jpeg 715w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1968\" class=\"wp-caption-text\">Logical scheme<\/p><\/div>\n<p>At this stage, we have:<\/p>\n<ul>\n<li>The message will reveal the flag is encrypted and then base64 encoded before being cut into 81 files ordered and named &#8220;encrypt*&#8221;.<\/li>\n<li>The jpeg image of the logical schema presents an algorithm to implement to deal with the binary. 8 bit input to one output.<\/li>\n<li>The &#8220;key.txt&#8221; file contains a relatively large binary string. This string is the decryption key of the encrypted message, but it is encoded and we have to\u00a0decode via the algorithm presented on the image of the logical schema.<\/li>\n<\/ul>\n<p>Let&#8217;s start with the algorithm implementation of the logical schema in Python:<\/p>\n<p>&nbsp;<\/p>\n<pre>#!\/usr\/bin\/python\r\n# Quick'n'dirty logical scheme implementation\r\n\r\nkeyFile = open(\"key.txt\", \"r\");\r\nresFile = open(\"keyresult.txt\", \"w\");\r\n\r\ndef AND(a, b):\r\n if a==\"1\" and b ==\"1\":\r\n return \"1\"\r\n else:\r\n return \"0\";\r\n\r\ndef NOT(a):\r\n if a==\"1\":\r\n return \"0\"\r\n else:\r\n return \"1\";\r\n\r\ndef OR(a, b):\r\n if a==\"1\" or b == \"1\":\r\n return \"1\"\r\n else:\r\n return \"0\";\r\n\r\ndef XOR(a, b):\r\n if (a==\"1\" or b == \"1\") and a!=b:\r\n return \"1\"\r\n else:\r\n return \"0\";\r\n\r\nkey = keyFile.read();\r\n\r\ni = 0;\r\nwhile i &lt; len(key):\r\n a1 = key[i];\r\n a2 = key[i+1];\r\n a3 = key[i+2];\r\n a4 = key[i+3];\r\n a5 = key[i+4];\r\n a6 = key[i+5];\r\n a7 = key[i+6];\r\n a8 = key[i+7];\r\n u13 = NOT(a3)\r\n u16 = NOT(a4)\r\n u15 = NOT(a5)\r\n u14 = NOT(a2)\r\n u17 = NOT(a6)\r\n u20 = NOT(a8)\r\n u1 = AND(a1, u13)\r\n u2 = AND(u14, u13);\r\n u3 = AND(a1, a2);\r\n u18 = XOR(a6, a7); \r\n u19 = XOR(u14, u20);\r\n u4 = AND(u1, u16);\r\n u5 = AND(u16, u2);\r\n u6 = AND(u16, u3);\r\n u7 = AND(u17, a3);\r\n u8 = AND(a3, u19);\r\n u9 = AND(u4, u15);\r\n u10 = AND(u5, u15);\r\n u11 = AND(u15, u6);\r\n u12 = AND(u7, u18);\r\n u21 = OR(u9, u10);\r\n u22 = OR(u11, u12);\r\n u23 = OR(u22, u8);\r\n u24 = OR(u21, u23);\r\n resFile.write(u24);\r\n i = i+8<\/pre>\n<p>The script is run\u00a0to produce the file &#8220;keyresult.txt&#8221; from the binary string in &#8220;key.txt&#8221;:<\/p>\n<pre>001101000101010101101011011110100011100100110101010001100011001001011001011100010101000001101001<\/pre>\n<p>ASCII conversion of this new binary string gives us the following key:<\/p>\n<pre>4Ukz95F2YqPi<\/pre>\n<p>Now regenerate an encrypted file as a bundle:<\/p>\n<pre>cat encrypt* &gt; encrypt-bundle.txt<\/pre>\n<p>Having the key and the encrypted file, proceed to decryption &#8230; Yes, but what algorithm? (DES, 3DES, XOR, AES128, AES256 &#8230;). It turns out that this is the AES256 gives us a decent result:<\/p>\n<pre>openssl enc -aes-256-cbc -d -a -in encrypt-bundle.txt -out decrypt.txt -k 4Ukz95F2YqPi<\/pre>\n<p>So we have a file &#8220;decrypt.txt&#8221;, including portions of its contents appear in clear. A command like &#8220;strings decrypt.txt&#8221; will display all the displayable text of it, and we note that the last strings\u00a0are:<\/p>\n<pre>[...]\r\nword\/theme\/theme1.xmlPK\r\nword\/styles.xmlPK\r\nword\/document.xmlPK\r\ndocProps\/custom.xmlPK\r\ndocProps\/app.xmlPK\r\ndocProps\/core.xmlPK<\/pre>\n<p>It seemed to be an RTF file to open with Word! Rename &#8220;decrypt.txt&#8221; in &#8220;decrypt.rtf&#8221; and &#8230;<\/p>\n<div id=\"attachment_1969\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/03-1.png\" rel=\"attachment wp-att-1969\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1969\" class=\"size-medium wp-image-1969\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/03-1-300x251.png\" alt=\"Fichier RTF d\u00e9chiffr\u00e9\" width=\"300\" height=\"251\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/03-1-300x251.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/03-1-768x644.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/03-1-1024x858.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/03-1.png 1175w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1969\" class=\"wp-caption-text\">RTF file decrypted<\/p><\/div>\n<p>Just &#8220;remove&#8221; or move the image (which is in the foreground), to see the flag appear behind:<\/p>\n<div id=\"attachment_1970\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/04-1.png\" rel=\"attachment wp-att-1970\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1970\" class=\"size-medium wp-image-1970\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/04-1-300x155.png\" alt=\"Flag !\" width=\"300\" height=\"155\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/04-1-300x155.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/04-1-768x396.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/04-1-1024x527.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/04-1.png 1699w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1970\" class=\"wp-caption-text\">Flag !<\/p><\/div>\n<p>Flag : <strong>NDH[59rRS57bd5WH8RxgPbRS27q89a5bWrjL]<\/strong><\/p>\n<p>Greeting to\u00a0<a href=\"http:\/\/www.information-security.fr\/\" target=\"_blank\">nj8<\/a>, <a href=\"http:\/\/0xbadcoded.com\/\" target=\"_blank\">St0rn<\/a>, <a href=\"http:\/\/www.georgestaupin.com\/\" target=\"_blank\">Emiya<\/a>, Mido, downg(r)ade,\u00a0Ryuk@n and\u00a0rikelm, \ud83d\ude09\u00a0\/\/ Gr3etZ<\/p>\n<p><strong>Sources &amp; ressources :<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/nuitduhack.com\/fr\/\" target=\"_blank\">NDH 2016<\/a><\/li>\n<\/ul>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Write-up of the challenge \u201cInforensic\u00a0\u2013 Invest\u201d of Nuit du\u00a0Hack 2016 CTF qualifications. The weekend of 04\/01\/2016 is pre-qualification for the [&hellip;]<\/p>\n","protected":false},"author":1337,"featured_media":1963,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,57,56,524,523,526,527,14],"tags":[465,467,466,468,464,459],"class_list":["post-1965","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cryptanalyse","category-cryptographie","category-cryptologie","category-ctf","category-events","category-ndh","category-ndh2k16","category-vuln-exploit-poc","tag-aes256","tag-inforensic","tag-invest","tag-quals","tag-wireshark","tag-write-up"],"_links":{"self":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/1965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/users\/1337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/comments?post=1965"}],"version-history":[{"count":5,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/1965\/revisions"}],"predecessor-version":[{"id":1989,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/1965\/revisions\/1989"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/media\/1963"}],"wp:attachment":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/media?parent=1965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/categories?post=1965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/tags?post=1965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}