{"componentChunkName":"component---src-templates-post-template-js","path":"/ctf-sec4b-2021-en","result":{"data":{"markdownRemark":{"id":"f6e2bd44-838a-5fd3-997c-16700e59315f","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/ctf-sec4b-2021\">original page</a>.</p>\n</blockquote>\n<p>I participated in <a href=\"https://www.seccon.jp/2021/seccon_beginners/_seccon_beginners_ctf_2021.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">SECCON Beginners CTF 2021</a>, held on May 22–23.</p>\n<p>In fact, the first CTF I ever entered when I started was last year’s SECCON Beginners CTF, and at the time I could only solve one or two problems and lost badly.</p>\n<p>This time I was pumped up to participate as a rematch, to confirm how much I had grown over the past year.</p>\n<p>And the result — I managed to solve all five Reversing problems!</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/df22497720fe60257b6c301d04b99b74/0b533/c41386c0-f785-7f56-864e-a96189007346.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 37.916666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAARlAAAEZQAGA43XUAAABQklEQVQoz3VR2W6EMAzk/7+u6kvVly6ly2YLwTk4lpBj6mTvVo00cewBezSuXj5e8da+Q8NA8T0kuiMSKKk7Fx84rudIl3hF5YJDbyRELyCkwLqt0J4bbBo+eth1RL2v0akeIQUQ1/VmynerXzG5CSd/gvOu/FOBzzAQmqbhOOQUYxgx+bm8iQifzCmlLtwEfdI4tALfXYd9u8fhKKDoPKhaI3eeOVkMzMnCpQ2KFWaVf7i4gbzGFBYgoTRs2/Y2zHiLqvMSMl49Uch5HwaGxDNHJe+4ToEdDRYmnlHejCGwhxERejIQncCxPyLGWCaZzWYRsMuIpv1CTxIpJVjm+iQxgJ4XiDOKhx1L3+12HPsi3fq7h5mr6xpSypuHuSHx3vOGf6PKfpiVFTkLu42YOSevyjZnv0AzZ934wGnINPzb8AfQj2agevw54wAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/df22497720fe60257b6c301d04b99b74/8ac56/c41386c0-f785-7f56-864e-a96189007346.webp 240w,\n/static/df22497720fe60257b6c301d04b99b74/d3be9/c41386c0-f785-7f56-864e-a96189007346.webp 480w,\n/static/df22497720fe60257b6c301d04b99b74/b0a15/c41386c0-f785-7f56-864e-a96189007346.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/df22497720fe60257b6c301d04b99b74/8ff5a/c41386c0-f785-7f56-864e-a96189007346.png 240w,\n/static/df22497720fe60257b6c301d04b99b74/e85cb/c41386c0-f785-7f56-864e-a96189007346.png 480w,\n/static/df22497720fe60257b6c301d04b99b74/0b533/c41386c0-f785-7f56-864e-a96189007346.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/df22497720fe60257b6c301d04b99b74/0b533/c41386c0-f785-7f56-864e-a96189007346.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>This time I would like to write a brief writeup for the “firmware” problem from among the Reversing challenges.</p>\n<h2 id=\"disclaimer\" style=\"position:relative;\"><a href=\"#disclaimer\" aria-label=\"disclaimer permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Disclaimer</h2>\n<p>The content of this article is not intended to promote any actions that violate social order.</p>\n<p>Please note in advance that attempting to attack systems other than those you own or have been authorized to test may violate the “Act on Prohibition of Unauthorized Computer Access.”</p>\n<h2 id=\"writeup\" style=\"position:relative;\"><a href=\"#writeup\" aria-label=\"writeup permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>WriteUp</h2>\n<p>First, extracting the provided archive file revealed the following two files:</p>\n<ul>\n<li>firmware.bin</li>\n<li>README.txt</li>\n</ul>\n<p>The contents of README.txt were as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ctf4b networks SUPER SECURE device's firmware\n\n*NOTE*\n\nIt is allowed to reverse engineer this firmware.\nI hope you enjoy reversing this file!</code></pre></div>\n<p>It appears that firmware.bin is a firmware program for some kind of network device.</p>\n<p>Running the <code class=\"language-text\">file</code> command on it showed that it is a data file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$file firmware.bin \nfirmware.bin: data</code></pre></div>\n<p>Next, running <code class=\"language-text\">strings</code> on it revealed the following filenames:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ascii.txt \nsquare.svg\nbootstrap-grid.css\nfa-regular-400.woff2\nfile.svg\nlogo.png\nfirm\nlogo.jpg\nfolder.svg\ncertificate.pem\nindex.html\nplus-square.svg\nstar.svg</code></pre></div>\n<p>The following text was also found:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">This is a IoT device made by ctf4b networks. Password authentication is required to operate.\nInput password (password is FLAG) > \nIncorrect password.\nCorrect password!!!\nGCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0</code></pre></div>\n<p>It became clear that firmware.bin consists of multiple files, and that the executable inside it would ask for a password string that is the FLAG.</p>\n<p>However, since firmware.bin showed as a data file, I could not successfully analyze it with Ghidra, radare2, objdump, or similar tools.</p>\n<h2 id=\"about-firmwarebin\" style=\"position:relative;\"><a href=\"#about-firmwarebin\" aria-label=\"about firmwarebin permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>About firmware.bin</h2>\n<p>So I changed my approach and researched firmware analysis tools, and found that <a href=\"https://github.com/ReFirmLabs/binwalk\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">binwalk</a> is a tool designed specifically for firmware analysis.</p>\n<p>I had used binwalk before to decompress ZLIB files in steganography challenges, but I did not realize that firmware analysis was its original purpose.</p>\n<p>Running binwalk on firmware.bin produced the following output:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token variable\">$binwalk</span> firmware.bin \n\nDECIMAL       HEXADECIMAL     DESCRIPTION\n--------------------------------------------------------------------------------\n<span class=\"token number\">127</span>           0x7F            Base64 standard index table\n<span class=\"token number\">2343</span>          0x927           Copyright string: <span class=\"token string\">\"Copyright 2011-2021 The Bootstrap Authors\"</span>\n<span class=\"token number\">2388</span>          0x954           Copyright string: <span class=\"token string\">\"Copyright 2011-2021 Twitter, Inc.\"</span>\n<span class=\"token number\">83503</span>         0x1462F         PNG image, <span class=\"token number\">594</span> x <span class=\"token number\">100</span>, <span class=\"token number\">8</span>-bit grayscale, non-interlaced\n<span class=\"token number\">83544</span>         0x14658         Zlib compressed data, best compression\n<span class=\"token number\">90593</span>         0x161E1         ELF, <span class=\"token number\">32</span>-bit LSB shared object, ARM, version <span class=\"token number\">1</span> <span class=\"token punctuation\">(</span>SYSV<span class=\"token punctuation\">)</span>\n<span class=\"token number\">100906</span>        0x18A2A         Unix path: /usr/lib/gcc/arm-linux-gnueabihf/9/<span class=\"token punctuation\">..</span>/<span class=\"token punctuation\">..</span>/<span class=\"token punctuation\">..</span>/arm-linux-gnueabihf/Scrt1.o\n<span class=\"token number\">103485</span>        0x1943D         JPEG image data, JFIF standard <span class=\"token number\">1.01</span>\n<span class=\"token number\">117167</span>        0x1C9AF         PEM certificate\n<span class=\"token number\">117786</span>        0x1CC1A         HTML document header\n<span class=\"token number\">118641</span>        0x1CF71         HTML document footer</code></pre></div>\n<p>From this output, it is clear that I need to extract the ELF file that handles the FLAG password string.</p>\n<h2 id=\"extracting-binary-data-between-arbitrary-addresses\" style=\"position:relative;\"><a href=\"#extracting-binary-data-between-arbitrary-addresses\" aria-label=\"extracting binary data between arbitrary addresses permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Extracting Binary Data Between Arbitrary Addresses</h2>\n<p>I had done this a few times before, so it was not particularly difficult.</p>\n<p>Specifically, I used the <code class=\"language-text\">dd</code> command.</p>\n<p>Many people have used <code class=\"language-text\">dd</code> when writing an ISO image to a USB drive on Linux — it is a command for file conversion and copying.</p>\n<p>Reference: <a href=\"https://man7.org/linux/man-pages/man1/dd.1.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">dd(1) - Linux manual page</a></p>\n<p>Using <code class=\"language-text\">dd</code> to extract binary data requires nothing particularly complicated.</p>\n<p>As shown below, I specified firmware.bin as the input file, set <code class=\"language-text\">bs</code> to 1 to write one byte at a time, and set the start address and byte count obtained from binwalk:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">dd</span> <span class=\"token assign-left variable\">if</span><span class=\"token operator\">=</span>./firmware.bin <span class=\"token assign-left variable\">of</span><span class=\"token operator\">=</span>./program <span class=\"token assign-left variable\">bs</span><span class=\"token operator\">=</span><span class=\"token number\">1</span> <span class=\"token assign-left variable\">skip</span><span class=\"token operator\">=</span><span class=\"token number\">90593</span> <span class=\"token assign-left variable\">count</span><span class=\"token operator\">=</span><span class=\"token number\">12892</span>\n<span class=\"token number\">12892</span>+0 records <span class=\"token keyword\">in</span>\n<span class=\"token number\">12892</span>+0 records out\n<span class=\"token number\">12892</span> bytes <span class=\"token punctuation\">(</span><span class=\"token number\">13</span> kB, <span class=\"token number\">13</span> KiB<span class=\"token punctuation\">)</span> copied, <span class=\"token number\">0.0391655</span> s, <span class=\"token number\">329</span> kB/s</code></pre></div>\n<p>Checking the extracted file confirms it was properly obtained as an ELF file:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">file</span> program \nprogram: ELF <span class=\"token number\">32</span>-bit LSB pie executable, ARM, EABI5 version <span class=\"token number\">1</span> <span class=\"token punctuation\">(</span>SYSV<span class=\"token punctuation\">)</span>, dynamically linked, interpreter /lib/ld-linux-armhf.so.3, missing section headers</code></pre></div>\n<h2 id=\"analyzing-the-binary-file\" style=\"position:relative;\"><a href=\"#analyzing-the-binary-file\" aria-label=\"analyzing the binary file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Analyzing the Binary File</h2>\n<p>I considered setting up an ELF32 execution environment for dynamic analysis to extract the FLAG, but setting up the dynamically linked libraries was too much trouble, so I skipped it.</p>\n<p>Since the binary was fairly straightforward, static analysis alone was sufficient to obtain the FLAG.</p>\n<p>I loaded it into Ghidra.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/3efbaae8748ba0bbaa401c106a680e15/0b533/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 62.083333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAARlAAAEZQAGA43XUAAACO0lEQVQoz12SiXKbQAyG8/4P1mNSxxNcJz6wDeaGZZfLXE7yVWC3aatBsxrBfuj4H/Z7G9vxWB8CdueUvZdxCHKOoebgK4kVtpzPr3u+fF3z8pry7dHDWltstmte3T1O7GFMycn1eKjKiu4N4vqD7AJpA0nzMfscSz7vYePERFHAZHWdkeQujnaph4Lr2zjntSl4yFVO2Y74ZiAyI1FxFR8JzadnLTz93GM9W3fgkTDbsEpf6MaO35YpLcBcU3VXAoEEWU+ox9mneHY9kMudx9WOp+VyvpjrnCQ9o+RsW0XblXNe5eY/oBpuVelbHOTDP8DlHah1iylCitqnbmLMRdGPJVHs86D/AK/EU7vl3ed2b+3PQGvLYrGYgW2bkmYWVmrJrON7w++kSk0V5jPQk1tOdMFLR9xgOjv8tMVTLfKwWNusVqs7sCBJDvgqorrkDEP92XKWKd4/wPN9Hp9skkw2LYSy7gTmkTUl8prD6cwksdtSBsrK0Fw049jQD82cjzJZipItT5YkIeufR5GG/EmA7aUjSiO8SM/vXddhu93dgJVNWBzYGJu/zVfmEzhpbLncywahqnu6bhAZRBydBJVe2NlnTs75tpT8yDlyZGGhfKelwvYGnCqcWp41lMasrCNGgGXZ03cjiQmoWmlHena9EMd173prqJpQQDXX60VG9jbn01k22jCMV+zTie8/tsSZLCMSnSU5p8CRWTZ0fS8zdNnsbJlvwznMiXVCUhhM1chMG5lnSxDG/AIzIol9/u+SUAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/3efbaae8748ba0bbaa401c106a680e15/8ac56/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.webp 240w,\n/static/3efbaae8748ba0bbaa401c106a680e15/d3be9/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.webp 480w,\n/static/3efbaae8748ba0bbaa401c106a680e15/b0a15/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/3efbaae8748ba0bbaa401c106a680e15/8ff5a/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.png 240w,\n/static/3efbaae8748ba0bbaa401c106a680e15/e85cb/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.png 480w,\n/static/3efbaae8748ba0bbaa401c106a680e15/0b533/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/3efbaae8748ba0bbaa401c106a680e15/0b533/d6775f71-5216-e201-8d62-ea3f2f3ab0fa.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>The main function is a bit lengthy, but the important parts are not that many.</p>\n<p>Since <code class=\"language-text\">strings</code> had already revealed a section that receives a password input and checks whether it is correct, I searched for that.</p>\n<p>The branch just before reaching the “Correct Password” address looked suspicious.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/f49c0166b80270ed614d7a8517b35166/0b533/bcba90e2-d275-8406-2412-0e6b6214cd05.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 42.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAARlAAAEZQAGA43XUAAABwklEQVQoz42SWW/TUBCF/f//AYKyFPHEAw+8swiJVoAiUkpUEicteMm1HS/Xsa+X2P4Y2wiJPnGkkWek4zNzZq6l8wJnH3HreLiqJsl72n4gziTXDVXbo4uCfRxzp0LisCAJS/K8oe4G8qrBCCfJDY/OnmIdkoy1l7BxE3aqYRd0kjcsb2I+Xx/4dWhwkxI70PyUJkEB6tij8g5fn/iuFNs4x4lKEXyCZaqa1c2aL4sFPzYGXw00JwiE4Hg5PbAPXWzHIctKiqIkyjVF3dJ2CHfgJKT0WPHw8TlWWRq2W5tvV0ts25CmTMiyaooRnr9ns/PRcUnXisXG0PXdTByG6VOI9Qdnz7AqmdC2ba5EcLszKJmwriGWn11PT+QgUKxu7/ClW/9HYNYa/tZHmfz8+QusumnYiOBy+VWEx6lmcpIYIrE9Ik58PHUgkmOkWcm/mAUznfPuw8dRsGW1WnF5ecF6bTgcZloo14yiYsrT1KFtzeSu73tOp07qfoqm6aSWV5Fo3rx9Px8lDENc1xWxlmpeG8a0k+0RZZlPlsZ9G2PQemxmCMeQqZWSY/oxr1+9xBqvNtyzMNzb0/8g05qLTwt+AxWsqnz+n0ZHAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/f49c0166b80270ed614d7a8517b35166/8ac56/bcba90e2-d275-8406-2412-0e6b6214cd05.webp 240w,\n/static/f49c0166b80270ed614d7a8517b35166/d3be9/bcba90e2-d275-8406-2412-0e6b6214cd05.webp 480w,\n/static/f49c0166b80270ed614d7a8517b35166/b0a15/bcba90e2-d275-8406-2412-0e6b6214cd05.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/f49c0166b80270ed614d7a8517b35166/8ff5a/bcba90e2-d275-8406-2412-0e6b6214cd05.png 240w,\n/static/f49c0166b80270ed614d7a8517b35166/e85cb/bcba90e2-d275-8406-2412-0e6b6214cd05.png 480w,\n/static/f49c0166b80270ed614d7a8517b35166/0b533/bcba90e2-d275-8406-2412-0e6b6214cd05.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/f49c0166b80270ed614d7a8517b35166/0b533/bcba90e2-d275-8406-2412-0e6b6214cd05.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Searching around, I found a branch that clearly looked like a password check.\n(Variable names were edited during analysis.)</p>\n<p>Reading the decompiled code, it appears to compare the input value against the FLAG string character by character from position 0 to 60.</p>\n<p>The input is XORed with 0x53 (83) for each character before comparison.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 402px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/cba23adf2bb49534e4c9efeee5f9c4d7/0ec92/fe4c1939-bc8d-a1e7-4eca-688a0abac51d.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 52.916666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB9ElEQVQoz22SW08aURSF+f8vVQERkLsCc59hBjQ2IH3oe/9A00QNitxmuIiI8HUzCCkND9/ZeydnVtY6eyLNXoXbvs5dcIM19GiOTVoTF2/soQ5U7qRv+gYN3+X7aDPfUuvbYf2xbtNetmh/trhf3tNetYmUewaFbo7Ug0W+U0TtxaiOklyNLsg+n1LsyjytkA0ypPtJqoGCOimhBymMaR5lmEEZpCn7FbR3nYi7srBGKeESe5jAHJXIC9GXqBAj3j1Hm+vUaeDKKd6/6q4/JOJ86Bi9OObwAqP7TWqevF/kpHPCaeeUs+coykyRq3Vqa5eafBbW//svQkGzv3GWxng9E8FC6DDejZPsJUOXyts/gl+Ejtbetl97eyLO0hSRNKaflaWcY/k5CkGBpMS/lKfIybwV2EVshHUnuhffRa59mth+DCvIovWzlDsquVedcqChvt1gzG2MmcbmXm1l47yrOEvnUBR3T8Re2Fw9VFB6OdShQvGxzvWjRuZ3gcKTRrVf4vohhjlISII06stm8+J65e1jH0TWZw2iv36S+yPRB1GcSRonSFB+imLPSrhLcbdQsOZVHMFeiPO5hvNZOx5ZmxpYizr6zMP+MHA2yLtaCx1nLYtgi7v/berbBR3ZcLjl8XLMlC0TOQ9Yj48yDuvkKH8BACzhJUPOtwoAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/cba23adf2bb49534e4c9efeee5f9c4d7/8ac56/fe4c1939-bc8d-a1e7-4eca-688a0abac51d.webp 240w,\n/static/cba23adf2bb49534e4c9efeee5f9c4d7/56632/fe4c1939-bc8d-a1e7-4eca-688a0abac51d.webp 402w\"\n              sizes=\"(max-width: 402px) 100vw, 402px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/cba23adf2bb49534e4c9efeee5f9c4d7/8ff5a/fe4c1939-bc8d-a1e7-4eca-688a0abac51d.png 240w,\n/static/cba23adf2bb49534e4c9efeee5f9c4d7/0ec92/fe4c1939-bc8d-a1e7-4eca-688a0abac51d.png 402w\"\n            sizes=\"(max-width: 402px) 100vw, 402px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/cba23adf2bb49534e4c9efeee5f9c4d7/0ec92/fe4c1939-bc8d-a1e7-4eca-688a0abac51d.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Once I understood this, the rest was straightforward.</p>\n<p>I determined the address range of the <code class=\"language-text\">flag_val</code> array from the decompiled output.</p>\n<p>I found that addresses 0xea4 to 0xf94 correspond to this array.</p>\n<p>Since the array is defined as <code class=\"language-text\">uint</code>, the difference is 0xF0, meaning exactly 60 characters of storage are allocated.</p>\n<p>With this information, I wrote a solver that extracts the binary data in that address range and XORs each byte with 0x53 to output the characters:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"program\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"rb\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> prog<span class=\"token punctuation\">:</span>\n    data <span class=\"token operator\">=</span> prog<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    data <span class=\"token operator\">=</span> data<span class=\"token punctuation\">[</span><span class=\"token number\">3748</span><span class=\"token punctuation\">:</span><span class=\"token number\">3988</span><span class=\"token punctuation\">]</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">240</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">chr</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token operator\">^</span><span class=\"token number\">83</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Running it yields the FLAG:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ python3 solver.py \nctf4b<span class=\"token punctuation\">{</span>i0t_dev1ce_xxxxxxxx_xxxxxxxx_xxxxxxxx_a_l0t_of_5ecre7s<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>Looking back, it was an Easy-level problem, but I wasted a lot of time on silly mistakes.</p>\n<p>In particular, carelessly editing the freshly extracted file in a text editor — which corrupted it and prevented binwalk from analyzing it correctly — was a painful mistake.</p>\n<p>Going forward, if I get stuck for a while, trying to re-download the problem file might be a good first step.</p>\n<p>That said, having settled last year’s score and confirmed that I can now clear all problems in my strongest genre at SECCON Beginners CTF shows tremendous growth, which I am happy about.</p>\n<p>I will continue to study while aiming for even higher rankings.</p>\n<p>Once again, many thanks to the organizers for such a great contest!\nI heard there were some infrastructure issues, but personally I enjoyed it without any major stress.</p>\n<p>Next time I will aim for a satisfying result at SECCON CTF as well.</p>\n<h2 id=\"references\" style=\"position:relative;\"><a href=\"#references\" aria-label=\"references permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>References</h2>\n<ul>\n<li><a href=\"https://man7.org/linux/man-pages/man1/dd.1.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">dd(1) - Linux manual page</a></li>\n<li><a href=\"https://github.com/ReFirmLabs/binwalk\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ReFirmLabs/binwalk: Firmware Analysis Tool</a></li>\n</ul>","fields":{"slug":"/ctf-sec4b-2021-en","tagSlugs":["/tag/ctf-en/","/tag/reversing-en/","/tag/english/"]},"frontmatter":{"date":"2021-10-03","description":"From among the Reversing challenges, I will write a brief writeup for the problem called \"firmware.\"","tags":["CTF (en)","Reversing (en)","English"],"title":"firmware Writeup (Reversing) [SECCON Beginners CTF 2021]","socialImage":{"publicURL":"/static/334bd91f01f5d703919e643c6130dca6/ctf-elf-training.png"}}}},"pageContext":{"slug":"/ctf-sec4b-2021-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}