{"componentChunkName":"component---src-templates-post-template-js","path":"/magical-windbg-vol2-06-en","result":{"data":{"markdownRemark":{"id":"ca4c185c-d8db-5e8a-910c-a9531aea8b70","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/magical-windbg-vol2-06\">original page</a>.</p>\n</blockquote>\n<p>In this chapter, we will identify the second Flag by dynamically analyzing DoPDriver using Windows kernel debugging.</p>\n<p>As confirmed in Chapter 5, to identify the second Flag, you need to launch a process whose image file name can pass the validation performed by the checkImageFileName function (the function at address 0x140001000).</p>\n<p>In this chapter, we will dynamically analyze DoPDriver with kernel debugging while identifying the correct image file name through a brute-force attack.</p>\n<p>For instructions on loading a Windows kernel driver into a virtual machine and setting up an environment for kernel debugging, please refer to Chapter 1.</p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents 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>Table of Contents</h2>\n<ul>\n<li><a href=\"#dynamically-analyze-the-driverentry-function\">Dynamically Analyze the DriverEntry Function</a></li>\n<li><a href=\"#dynamically-analyze-the-callback-function-registered-with-pssetcreateprocessnotifyroutine\">Dynamically Analyze the Callback Function Registered with PsSetCreateProcessNotifyRoutine</a></li>\n<li><a href=\"#identify-the-flag-with-a-brute-force-attack-using-breakpoint-settings\">Identify the Flag with a Brute-Force Attack Using Breakpoint Settings</a></li>\n<li><a href=\"#dynamically-analyze-the-checkimagefilename-function\">Dynamically Analyze the checkImageFileName Function</a></li>\n<li><a href=\"#identify-the-image-file-name-with-a-javascript-based-debugger-script\">Identify the Image File Name with a JavaScript-Based Debugger Script</a></li>\n<li><a href=\"#inspect-the-paged-pool-information\">Inspect the Paged Pool Information</a></li>\n<li><a href=\"#identify-the-memory-block-address-from-the-pool-tag\">Identify the Memory Block Address from the Pool Tag</a></li>\n<li><a href=\"#identify-the-memory-allocation-address-using-poolhittag\">Identify the Memory Allocation Address Using PoolHitTag</a></li>\n<li><a href=\"#summary-of-chapter-6\">Summary of Chapter 6</a></li>\n<li><a href=\"#afterword\">Afterword</a></li>\n<li><a href=\"#links-to-each-chapter\">Links to Each Chapter</a></li>\n</ul>\n<h2 id=\"dynamically-analyze-the-driverentry-function\" style=\"position:relative;\"><a href=\"#dynamically-analyze-the-driverentry-function\" aria-label=\"dynamically analyze the driverentry function 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>Dynamically Analyze the DriverEntry Function</h2>\n<p>As described in Chapter 5, a kernel driver module such as DoPDriver executes the DriverEntry function when it starts.</p>\n<p>However, unlike a user-mode program, a kernel driver cannot be launched from the debugger.</p>\n<p>Also, debugging the DriverEntry function by setting a breakpoint on it requires a slightly special approach.</p>\n<p>This is because you cannot use DoPDriver’s routine names until the driver has been loaded, so you cannot use the <code class=\"language-text\">bp</code> command to set a breakpoint on the DriverEntry function.</p>\n<p>Therefore, to debug the DriverEntry function, you must either use the <code class=\"language-text\">bu</code> command to set a deferred breakpoint on an unresolved routine name, or enable debugging when the module is loaded by using a WinDbg feature.</p>\n<p>If you want to set a deferred breakpoint on the DriverEntry function with the <code class=\"language-text\">bu</code> command, use <code class=\"language-text\">bu DoPDriver+0x11cc</code>.</p>\n<p>After executing <code class=\"language-text\">bu DoPDriver+0x11cc</code>, once DoPDriver is loaded, the routine name is resolved automatically and the system stops in the DriverEntry function.</p>\n<p>The easiest way to debug the DriverEntry function is probably to set a deferred breakpoint with the <code class=\"language-text\">bu</code> command, but in this book I will intentionally use the method of enabling debugging when a module is loaded.</p>\n<p>To enable debugging when a module is loaded, attach WinDbg to the virtual machine as a kernel debugger, open [File] > [Settings] in WinDbg, and change [Events &#x26; Exception] > [Load module on all modules] to [Break].</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 926px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/7dfbb6d27ebd59e5e52a8495f81ff879/69476/driver-kernel-debug-001.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: 69.58333333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACKUlEQVQ4y31T227TQBA1PADqEyp9RSDxtVXVi0pA7XfxRArEvcix48t6vTfbiXOYmcQhEVVHGq13vXvmnNmz0afbW0Snp/hwdYXfT08wuoEPAc55ybZt0XU9+n5JYyfJ38vdvEcIrextGoPozfk53l1e4uNkgun9A5y1MGaTVaVoNNBaoyxLWPrnnKP1Cmlewlgn+3k9EIk8LxjwAseTr/hyc4Mf0yni2R85vFqttmw6WALp+x4cvGapiPMtVsOA/Wg0MXx7cYH319f4/O07fsYx0iRBTYwYsG07ktFI9fV6jWFYy5yTgbkdvM7JoaldO8kn1MPHbIFAbDQdWBKj2nhUqoZSClmaijRrjcgchpXsOQCsCfCIwI4I7JjGnIB2QZs0AXIvuYdFUaAlphUdSvIKhbZQ9G8fkPcKw+jsTG55UWv5MWw3GReg6lokMihfyDzL8TDPUTSkxIUDQEfz6DWBsW1O9gA3/RrkIswWbIySmNbUApbbhkNAaz2i6AVAHzrpW00sx4thWey3li+Fcj+E4atnAEfJDR3OidEomeWzL7lIT2Dee1HBuVySGuOeBxwtsnkBGyOzN/kg26WqSswXJTHshf0iy6AaZv4i4LB5Vt4LQ/YcB0svywIlvSIuyIUUWaujYs1/DPUhw1bYVGLYf6+hEclrKhh8QEr+ZED2pVL6EHAaP6Igj6VpjiwrZJzPF5LjGn8nSbZbT5IUs1mMOL7H3d0v/AWzRvFpGVJ8IQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/7dfbb6d27ebd59e5e52a8495f81ff879/8ac56/driver-kernel-debug-001.webp 240w,\n/static/7dfbb6d27ebd59e5e52a8495f81ff879/d3be9/driver-kernel-debug-001.webp 480w,\n/static/7dfbb6d27ebd59e5e52a8495f81ff879/dafe9/driver-kernel-debug-001.webp 926w\"\n              sizes=\"(max-width: 926px) 100vw, 926px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/7dfbb6d27ebd59e5e52a8495f81ff879/8ff5a/driver-kernel-debug-001.png 240w,\n/static/7dfbb6d27ebd59e5e52a8495f81ff879/e85cb/driver-kernel-debug-001.png 480w,\n/static/7dfbb6d27ebd59e5e52a8495f81ff879/69476/driver-kernel-debug-001.png 926w\"\n            sizes=\"(max-width: 926px) 100vw, 926px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/7dfbb6d27ebd59e5e52a8495f81ff879/69476/driver-kernel-debug-001.png\"\n            alt=\"Change the Load module on all modules setting\"\n            title=\"Change the Load module on all modules setting\"\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>After changing [Load module on all modules] to [Break], resume system execution with the <code class=\"language-text\">g</code> command and have DoPClient load DoPDriver into the system.</p>\n<p>If the setting has been applied correctly, the virtual machine’s system will temporarily stop at this point, and you will be able to use kernel debugger commands.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/a826d54c05a22ea273fa1f080bfa0ceb/78415/driver-kernel-debug-002.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: 34.166666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA7UlEQVQoz41Qi26DMAzM///dxmgQBALiMbYAg4rwkuDqeKLapkmtpZMdx7mcTyilkOc5jDHo+y9CD2stpmnCvu8PcRzHr7OI45jJ1nVlImtnzPOCZVkoz4zv/v8Yx/FeOxEiDEMEQQCXFZF7XgcV1UgShbr+4M+KoiCUqKqKUZblHW67szbmE8INNE3Dg13XoTEt1e/ca9uWlW/bxvknzt7fOyGlT2o0K9Q6wfU6ICZfoyhCmqZM7Lx5NmjlgAkTrYlQYxgGZFnGhM7fcbRs/LMQb94Lq/N9n/x7pTXJQ1J4uUhIKdHTBy7OB4/iBu8MFeUZhyKfAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/a826d54c05a22ea273fa1f080bfa0ceb/8ac56/driver-kernel-debug-002.webp 240w,\n/static/a826d54c05a22ea273fa1f080bfa0ceb/d3be9/driver-kernel-debug-002.webp 480w,\n/static/a826d54c05a22ea273fa1f080bfa0ceb/e46b2/driver-kernel-debug-002.webp 960w,\n/static/a826d54c05a22ea273fa1f080bfa0ceb/459db/driver-kernel-debug-002.webp 1207w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/a826d54c05a22ea273fa1f080bfa0ceb/8ff5a/driver-kernel-debug-002.png 240w,\n/static/a826d54c05a22ea273fa1f080bfa0ceb/e85cb/driver-kernel-debug-002.png 480w,\n/static/a826d54c05a22ea273fa1f080bfa0ceb/d9199/driver-kernel-debug-002.png 960w,\n/static/a826d54c05a22ea273fa1f080bfa0ceb/78415/driver-kernel-debug-002.png 1207w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/a826d54c05a22ea273fa1f080bfa0ceb/d9199/driver-kernel-debug-002.png\"\n            alt=\"The system stops when the driver is loaded\"\n            title=\"The system stops when the driver is loaded\"\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>By using the [Load module on all modules] debugger setting to stop the system when DoPDriver is loaded, you can set breakpoints using DoPDriver symbols.</p>\n<p>So, to analyze the DriverEntry function, set a breakpoint at <code class=\"language-text\">DoPDriver+0x11cc</code>, which Chapter 5 identified as the address of the DriverEntry function.</p>\n<p>Even when WinDbg is used as a kernel debugger, many commands are the same as those used when debugging a user-mode program.</p>\n<p>Therefore, execute <code class=\"language-text\">bp DoPDriver+0x11cc ; g</code> to set a breakpoint on the DriverEntry function and then resume system execution.</p>\n<p>Once the breakpoint is set and system execution resumes, the system almost immediately stops at <code class=\"language-text\">DoPDriver+0x11cc</code>.</p>\n<p>At this point, issuing a command such as <code class=\"language-text\">uf @rip</code> lets you inspect the disassembly of the DriverEntry function.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 708px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/d0d87671154942423c3a51540095c639/3cb0f/driver-kernel-debug-003.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: 57.50000000000001%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB7klEQVQoz2VT13LqUAz0/39XCMGAfdzAvWCKC31432iVOPdO8qCRT1utdmVrs9nAcRykaYbb7Ybz+az5er1qnr6n9e/8O6yPhQ1n7cD3A8TbLaqqxuv1UuA8z9F1HZI0wTAMeD6feDweGvy+3+8aXE9FvgAdF67LcGDbtmSDrYBnWYa+H+AZF1G0QdM00kmKoiiQJIkUr2Sv1jULKkN7uYTneQjDCEHgYz6f6+UsS5UhL/q+L4AhIpGHhaMoQprlGMcRl8vlJyvgwl7qJbZsJM/e3kBdd22rDLq+RyCAxhhlV9c1drsdWjknY35z7z+GKwEyyoIP1+u1MCtwPB5RlqW03GvBoih1j0UINrGi1n8ZOq4Cep4RvTzEcaz6sfJJTOE+JaFW1JZSVHJGhm1LhtVfhp7nq/jvsxkWYlQomjXyqOt6BTSiM7VbrVaidaDgZMsuUtG76zt13LKFIQF5yZdHNIUgg7TKRxwbsg/DUNcEIPNRWp1aZkxzaS1Xax0T1VBAZ8IwlXbHcVCA4+mkZ/E2Vob8CUph9m+YOfS377hSQ1s1NKKd/20K2z8JEHU8HA7q8KRfGAY/blO/L5Ma1FWuZlkEikTwjVzmuOz3e538XlolEzprRFvOJs2oxQgWymQOuS6KHGlyEfZkesEnK91e0h2ObiQAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/d0d87671154942423c3a51540095c639/8ac56/driver-kernel-debug-003.webp 240w,\n/static/d0d87671154942423c3a51540095c639/d3be9/driver-kernel-debug-003.webp 480w,\n/static/d0d87671154942423c3a51540095c639/3f436/driver-kernel-debug-003.webp 708w\"\n              sizes=\"(max-width: 708px) 100vw, 708px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/d0d87671154942423c3a51540095c639/8ff5a/driver-kernel-debug-003.png 240w,\n/static/d0d87671154942423c3a51540095c639/e85cb/driver-kernel-debug-003.png 480w,\n/static/d0d87671154942423c3a51540095c639/3cb0f/driver-kernel-debug-003.png 708w\"\n            sizes=\"(max-width: 708px) 100vw, 708px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/d0d87671154942423c3a51540095c639/3cb0f/driver-kernel-debug-003.png\"\n            alt=\"Inspect the disassembly of DriverEntry\"\n            title=\"Inspect the disassembly of DriverEntry\"\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>As confirmed in Chapter 5, the DriverEntry function first creates a device object by calling IoCreateDevice with arguments such as DeviceName.</p>\n<p>Here, we will first use the debugger to identify the value of DeviceName, which is passed as a <code class=\"language-text\">UNICODE_STRING</code> object to the IoCreateDevice function, and the addresses of the functions assigned as dispatch routines in the driver object.</p>\n<p>To do this, continue execution until <code class=\"language-text\">DoPDriver+0x1229</code>, which executes the <code class=\"language-text\">call  qword [rel IoCreateDevice]</code> instruction.</p>\n<p>There are several ways to continue execution to a specific address, but here I used <code class=\"language-text\">pa DoPDriver+0x1229</code> to step all the way to <code class=\"language-text\">DoPDriver+0x1229</code> at once.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 715px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/0fb8f0402bc7ab6bc2cdeefff42c79af/d0c0e/driver-kernel-debug-004.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: 90.41666666666666%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACRUlEQVQ4y4WUyZbaQAxF+f9PI2CTNBgIo/GAJ8Bm2iq6sssNnfTJQkdQlK6ehmLwe7mU5WIhs1kg6/VakjSVsizl8XjItWnkdruZPZ9Pud/v3xr3scGP4VC88Vg8z1foTI7Ho1RVJXVdS3Q4SJZlEkWR5Hkul8vlWzufz3I6nWQwNpgn+I9fH7JUxavVSlJVinEJIOqBZpowTY+WOI5jrShRH9k9wAb0FQh0qgp3u51BgyCQ/X4vRVFa4Ha7te+AN5uNJeWcCpIk+QRS8ng0UoWeBPO5XQZaFLkctGT6iQ/D0AIBAj4eMwPQmrpu+rIH1j81gHMFkpngRgeSdgOi5DDc9wkwgr9aX7JnJetQgnbSDkpJBOM5d2dtgtCUkgRfVad3IAqn06mVjNJIA1HIxMMukD4xmKIo7LMz7rwp9DsggwDIFF3JBlQ1AOkbnl4CaJq662H92UNgk4mv9tOmG0UHg2CsRllWViIgd04bUJnlmSnOddK9QgP6vvh+u9j0CjBrEqsSAABRjlJ+3253dobRU0vm1qZVOOleSmAggAs1Ljsgq+T28WAvKO/7iT/9rXAiC33Tbg/jOLFe9Qo7EL//X6Hvm0qUtaUd5Hq99ntIEKvBd6fqooNgcCw1vh/KSF8Ja+NryUG3h2Rkcq9AVCcdkOfGuvxzsVvY+9oAJeB1bdyk17r0fHaArzYYdm95NBr3i03plEUP8e5V4N0/EcFusV9VDngVrS1MmXtm7Q6WphAwQ4qitpftMCI753OS6Lkm4+4fdmUjQ9eZLakAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/0fb8f0402bc7ab6bc2cdeefff42c79af/8ac56/driver-kernel-debug-004.webp 240w,\n/static/0fb8f0402bc7ab6bc2cdeefff42c79af/d3be9/driver-kernel-debug-004.webp 480w,\n/static/0fb8f0402bc7ab6bc2cdeefff42c79af/cb533/driver-kernel-debug-004.webp 715w\"\n              sizes=\"(max-width: 715px) 100vw, 715px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/0fb8f0402bc7ab6bc2cdeefff42c79af/8ff5a/driver-kernel-debug-004.png 240w,\n/static/0fb8f0402bc7ab6bc2cdeefff42c79af/e85cb/driver-kernel-debug-004.png 480w,\n/static/0fb8f0402bc7ab6bc2cdeefff42c79af/d0c0e/driver-kernel-debug-004.png 715w\"\n            sizes=\"(max-width: 715px) 100vw, 715px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/0fb8f0402bc7ab6bc2cdeefff42c79af/d0c0e/driver-kernel-debug-004.png\"\n            alt=\"Step to the address that calls IoCreateDevice\"\n            title=\"Step to the address that calls IoCreateDevice\"\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 <code class=\"language-text\">pa</code> command <sup id=\"fnref-1\"><a href=\"#fn-1\" class=\"footnote-ref\">1</a></sup> is a type of step command, but because it can perform step execution all the way to the specified address, it is convenient when you want to advance execution to a given address without setting a breakpoint.</p>\n<p>However, because the <code class=\"language-text\">pa</code> command executes the program step by step, the runtime overhead is large.</p>\n<p>Therefore, if the number of steps to the specified address is high, it is better to use the <code class=\"language-text\">g</code> command or something similar.</p>\n<p>After using the <code class=\"language-text\">pa</code> command to reach the address immediately before the call to IoCreateDevice (<code class=\"language-text\">DoPDriver+0x1229</code>), next inspect the register and stack information with <code class=\"language-text\">r rcx,rdx,r8,r9 ; dps rsp L3</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1: kd> r rcx,rdx,r8,r9 ; dps rsp L3\nrcx=ffff818bb49eaa70 rdx=0000000000000000 r8=ffffbc0b8ff338a0 r9=0000000000000022\nffffbc0b`8ff33860  00000000`00000000\nffffbc0b`8ff33868  00000000`00000000\nffffbc0b`8ff33870  ffff818b`b71e83d0</code></pre></div>\n<p>Under the Windows x64 calling convention, when all arguments are integer values, the first argument is stored in the RCX register and the third argument is stored in the R8 register.</p>\n<p>In other words, the pointer to the driver object passed as the first argument to the IoCreateDevice function is in RCX, and DeviceName passed as the third argument is stored at the address held in the R8 register.</p>\n<p>In fact, even if you output the data at the address pointed to by the R8 register with <code class=\"language-text\">db @R8 L0x10</code>, you can confirm that DeviceName is not stored as a plain string.</p>\n<p>However, if you interpret the address pointed to by the R8 register as a <code class=\"language-text\">UNICODE_STRING</code> structure with the <code class=\"language-text\">dt nt!_UNICODE_STRING @R8</code> command, you can confirm in the debugger that a DeviceName of <code class=\"language-text\">\\Device\\DoPDriver</code> is defined.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 686px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/b4c374a39ef9aa88718184128e402b7d/f6386/driver-kernel-debug-005.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: 32.49999999999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAA7DAAAOwwHHb6hkAAABKUlEQVQoz41R246CQAyd//81dV1uicIICogRBLmjCJ5ta9y4b0tyUkpnzqUorTUMwyCYcBwH3+s1FosF+Pt+v4e73UotigJVVf1BWZa/ePfqcDjIZdf1EMcxkuSIKIqQZRciuaLrOrRth2EYBK++kTqOI263G6ZpkneuKk1TnM9nJKcTkaTIqI+IOAxDHImcBd9CQRAI+DyLJkkirvq+J4FWqmJ3lmXBtm2J7tgWVqsvmKZJrl0sl0tYNON1aO0JWZ7nJJ4J6romxy2aphEo3g+78H1PXHQ05Gh8ieM8pgfmecZ/H7Xzd9hsNDmISTGn5ZYyiCnSidbA5ByFwQKveJ244f75fMp5rgzFC66qHpcMdGAmN5MMhqGXKJ+43+/yQ5iMo7LYJxnjB8FWEBydqg5IAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/b4c374a39ef9aa88718184128e402b7d/8ac56/driver-kernel-debug-005.webp 240w,\n/static/b4c374a39ef9aa88718184128e402b7d/d3be9/driver-kernel-debug-005.webp 480w,\n/static/b4c374a39ef9aa88718184128e402b7d/7dbce/driver-kernel-debug-005.webp 686w\"\n              sizes=\"(max-width: 686px) 100vw, 686px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/b4c374a39ef9aa88718184128e402b7d/8ff5a/driver-kernel-debug-005.png 240w,\n/static/b4c374a39ef9aa88718184128e402b7d/e85cb/driver-kernel-debug-005.png 480w,\n/static/b4c374a39ef9aa88718184128e402b7d/f6386/driver-kernel-debug-005.png 686w\"\n            sizes=\"(max-width: 686px) 100vw, 686px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/b4c374a39ef9aa88718184128e402b7d/f6386/driver-kernel-debug-005.png\"\n            alt=\"Inspect the third argument when IoCreateDevice is called\"\n            title=\"Inspect the third argument when IoCreateDevice is called\"\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>Now that we have confirmed DeviceName, next inspect the driver object and check the values assigned to its dispatch routines.</p>\n<p>The pointer to the driver object is held in the RCX register, which is the first argument to the IoCreateDevice function.</p>\n<p>If you run the <code class=\"language-text\">dt nt!_DRIVER_OBJECT @RCX</code> command against this address, you can inspect the driver object information whose DriverName is set to <code class=\"language-text\">\\Device\\DoPDriver</code>.</p>\n<p>Furthermore, if you click MajorFunction, you can confirm—just as in Chapter 5—that two dispatch routines are registered: <code class=\"language-text\">DriverObject->MajorFunction[0(IRP_MJ_CREATE)]</code> and <code class=\"language-text\">DriverObject->MajorFunction[2(IRP_MJ_CLOSE)]</code>, and you can inspect the addresses of the functions registered for each.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/9d31ccc98a589ebfed8b3cf1a8902a45/29229/driver-kernel-debug-006.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: 54.166666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB50lEQVQoz32SXW+bMBSG8/9/xNZpa+83ad3HRdutiaZVSklFABuDKQGMCZAPkqsky7tjN43SVRrSI5uDec6xfXqO4yBNUyilIJMEi8UCy+US8/n8hBlmsydexl/Tu7v7Dc/z0DQ1fN9HFMdISFxV1XGRSfIvJv6c5BQSBri9LSFERWIXjjOyCTxvTDEBrUsr11rTqO3cjG3bvpAeKxwMOK6uO8RyDsYZAhbS1lM6hgxZrlDXLQlqqHJq0bqBrpqj8JljhYHr42GYIuYc3HeIEbjnYCJ9pDKAymKUeYxZHWO1eKRRoFLMVmxEXdfZM1+tVliv11Rh+wXun4+4yi7wafwG3+QHfE/O8VWc4TJ8h8/EJc1v8vf4WZzjRr3Fj8kFVdjQWRpRh81mg+12i91uh15OZnIjUAID9xcekjG8LMBQOLiPRhgS9zR304DiIfyc0xoPUkqUZWkv6PTprQ/vUzUF8xjyNKctlkgiSSQHJG1dQRclNJ1rKh8RUzeYVjPbNs9+v7f0mmZvA0VRwHVd2zKTyQShCO0th5bQxvI8JzK6QPkfYf0k1LpCEAS2yc2PURRZhDCjQJZlFC9Q0Dd5EJotvxLWByHnIfr9PkIazWLf98AZA2OcYFZiqswI0/wmmUls2udU+Bc38ycnIq1ZBQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/9d31ccc98a589ebfed8b3cf1a8902a45/8ac56/driver-kernel-debug-006.webp 240w,\n/static/9d31ccc98a589ebfed8b3cf1a8902a45/d3be9/driver-kernel-debug-006.webp 480w,\n/static/9d31ccc98a589ebfed8b3cf1a8902a45/e46b2/driver-kernel-debug-006.webp 960w,\n/static/9d31ccc98a589ebfed8b3cf1a8902a45/3eff0/driver-kernel-debug-006.webp 1167w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/9d31ccc98a589ebfed8b3cf1a8902a45/8ff5a/driver-kernel-debug-006.png 240w,\n/static/9d31ccc98a589ebfed8b3cf1a8902a45/e85cb/driver-kernel-debug-006.png 480w,\n/static/9d31ccc98a589ebfed8b3cf1a8902a45/d9199/driver-kernel-debug-006.png 960w,\n/static/9d31ccc98a589ebfed8b3cf1a8902a45/29229/driver-kernel-debug-006.png 1167w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/9d31ccc98a589ebfed8b3cf1a8902a45/d9199/driver-kernel-debug-006.png\"\n            alt=\"Inspect the dispatch routines in the driver object\"\n            title=\"Inspect the dispatch routines in the driver object\"\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<h2 id=\"dynamically-analyze-the-callback-function-registered-with-pssetcreateprocessnotifyroutine\" style=\"position:relative;\"><a href=\"#dynamically-analyze-the-callback-function-registered-with-pssetcreateprocessnotifyroutine\" aria-label=\"dynamically analyze the callback function registered with pssetcreateprocessnotifyroutine 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>Dynamically Analyze the Callback Function Registered with PsSetCreateProcessNotifyRoutine</h2>\n<p>Next, let’s use the debugger to inspect the behavior of the callback function registered with PsSetCreateProcessNotifyRoutine.</p>\n<p>First, set a breakpoint with <code class=\"language-text\">bp DoPDriver+0x12E0 ; g</code> and resume system execution.</p>\n<p>You can then confirm that the system will not break and debugger commands will be unavailable until some process is created or deleted on the system.</p>\n<p>After that, clear all breakpoint settings with the <code class=\"language-text\">bc *</code> command, then set a new breakpoint with an associated command using <code class=\"language-text\">bp DoPDriver+0x131C \"da @RAX ; g\"</code>, and resume system execution with the <code class=\"language-text\">g</code> command.</p>\n<p>The address <code class=\"language-text\">DoPDriver+0x131C</code> is the instruction immediately after the PsGetProcessImageFileName function executes, which Chapter 5 showed returns a process’s image file name.</p>\n<p>Because the PsGetProcessImageFileName function returns the process image file name as its return value, executing <code class=\"language-text\">da @RAX</code> prints the retrieved image file name to the console.</p>\n<p>In fact, after setting this breakpoint, you can confirm that every time some process is created in the system, the <code class=\"language-text\">da @RAX</code> command runs and the image file name is printed to the console.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 619px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/6e1cf38b3bbc9c664ae330e7cd0a394a/e628c/driver-kernel-debug-007.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: 70.41666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABu0lEQVQ4y5VT2ZKiQBDk/z9tnkYY5UYOhQZBQQ5FkJyqcnbDp92hIzKaPsjKyqrWmqZGniso1aGqFpzPTzT1THNJ+znNZ8E0zWjbFmVZCi6Xi5zzzOvb7YZlWaCBxjgOMHcTPj6AzQZw3QXHYwTbthGGISzbQtcPFLCE53pwPQ9hFME0Tbp3lHtFcWIqaBy1rjlaiyIfKdpIUUeKOOB6vRL4vMYwDOj7Hk3TCPiM59f/Ndquw+PxgKayDGma0oWa+Cc8nw/CRClOmOf5L3j9vvfn+30WwowIGSpTyFVOSgtZ1z8eJUkiPnVdj/v9Ll79C5rvudjtTETkSRAEUgBWnCQx0mMq6bDZv4W2D3xYliXmG19fKE4nMZ73WCmns2ZocURVNC3EcUwkr2qF+z1835N0azKex68VMqFtO6/2IFVVVQmR4zgShKv4TvhfhZzydruDR731+bkhhYWoM3SdSG1kSq0j9FyHmlkXRbpukG9KyA1DpwZ3UVGRljWEAanhKgek1DBeReH0mYxfATfz6pRNKgq3jUkenuhdsne+79P7VriP4zqFKktJ3R6Hw0FSPVMTcx+ySiZcq/Ab2vUtc5Ugi2gAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/6e1cf38b3bbc9c664ae330e7cd0a394a/8ac56/driver-kernel-debug-007.webp 240w,\n/static/6e1cf38b3bbc9c664ae330e7cd0a394a/d3be9/driver-kernel-debug-007.webp 480w,\n/static/6e1cf38b3bbc9c664ae330e7cd0a394a/3aa79/driver-kernel-debug-007.webp 619w\"\n              sizes=\"(max-width: 619px) 100vw, 619px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/6e1cf38b3bbc9c664ae330e7cd0a394a/8ff5a/driver-kernel-debug-007.png 240w,\n/static/6e1cf38b3bbc9c664ae330e7cd0a394a/e85cb/driver-kernel-debug-007.png 480w,\n/static/6e1cf38b3bbc9c664ae330e7cd0a394a/e628c/driver-kernel-debug-007.png 619w\"\n            sizes=\"(max-width: 619px) 100vw, 619px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/6e1cf38b3bbc9c664ae330e7cd0a394a/e628c/driver-kernel-debug-007.png\"\n            alt=\"The image file name of the process that triggered the callback function\"\n            title=\"The image file name of the process that triggered the callback function\"\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<h2 id=\"identify-the-flag-with-a-brute-force-attack-using-breakpoint-settings\" style=\"position:relative;\"><a href=\"#identify-the-flag-with-a-brute-force-attack-using-breakpoint-settings\" aria-label=\"identify the flag with a brute force attack using breakpoint settings 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>Identify the Flag with a Brute-Force Attack Using Breakpoint Settings</h2>\n<p>Now let’s use WinDbg to identify the image file name that can pass the validation performed by the checkImageFileName function (the function at address 0x140001000).</p>\n<p>First, we will try to obtain the Flag using the simplest possible method: breakpoints.</p>\n<p>For example, if you set the following two breakpoints, every time some process is started you can print its image file name to the console and then output whether it passed validation in the checkImageFileName function.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">bp DoPDriver+0x131C \"da @RAX ; g\"\nbp DoPDriver+0x1333 \".if (@zf == 1) { .printf \\\"======> Correct\\\\n \\\" } .else { .printf \\\"======> Failed\\\\n \\\" ; g }\"</code></pre></div>\n<p>At the second breakpoint, processing branches depending on whether the zero flag is 1 after the return value of the checkImageFileName function is compared.</p>\n<p>If the image file name passes validation in the checkImageFileName function, it prints the string Correct and temporarily stops system execution.</p>\n<p>On the other hand, if the image file name does not pass validation, it prints the string Failed and then resumes program execution with the <code class=\"language-text\">g</code> command.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/a2f3ccc5325da5ffbfb7bc0706494928/0fb99/driver-kernel-debug-008.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: 45.833333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA2klEQVQoz6WSiQ6CMBBE+f9flCMUaORquSyQaMfuAkqixmuTybKknbxZ8OI4hn/wEUURhBBIkgTCqWkaaK2htOLnuq557roOSikWvSdVVcW9bVt4+fGIIAiQSYlhGFCWJfq+B5W19tY37ef9ma08MiC6LMtgjGGSaZoeLm61n++mTuu8GIaL4cmcGJ9i2fWk/VJeURQcOU1TjkqG8zy/JHxXjrBAGIaOUGIcR7RuudSfRfzIkIjIUIiECXmH/xDmec6RpVwIyfR8vvxEx4ba/We0PzI260f5Z4dXtBS9jtM5hn0AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/a2f3ccc5325da5ffbfb7bc0706494928/8ac56/driver-kernel-debug-008.webp 240w,\n/static/a2f3ccc5325da5ffbfb7bc0706494928/d3be9/driver-kernel-debug-008.webp 480w,\n/static/a2f3ccc5325da5ffbfb7bc0706494928/e46b2/driver-kernel-debug-008.webp 960w,\n/static/a2f3ccc5325da5ffbfb7bc0706494928/32b94/driver-kernel-debug-008.webp 965w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/a2f3ccc5325da5ffbfb7bc0706494928/8ff5a/driver-kernel-debug-008.png 240w,\n/static/a2f3ccc5325da5ffbfb7bc0706494928/e85cb/driver-kernel-debug-008.png 480w,\n/static/a2f3ccc5325da5ffbfb7bc0706494928/d9199/driver-kernel-debug-008.png 960w,\n/static/a2f3ccc5325da5ffbfb7bc0706494928/0fb99/driver-kernel-debug-008.png 965w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/a2f3ccc5325da5ffbfb7bc0706494928/d9199/driver-kernel-debug-008.png\"\n            alt=\"Brute-force attack using breakpoint settings\"\n            title=\"Brute-force attack using breakpoint settings\"\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>After setting the above breakpoints, it is theoretically possible to identify the Flag by brute-forcing processes whose image file names are 13 characters long using a Python script or something similar.</p>\n<p>However, breakpoint evaluation by the debugger has a large overhead, and especially in kernel debugging—where the system being debugged is itself interrupted—repeating the above cycle of stopping and resuming the system takes a very long time.</p>\n<p>Therefore, in a case like this, brute-forcing a 13-character image file name using printable ASCII characters would require an enormous number of attempts, so you would not be able to identify the correct image file name even after spending tens of hours on it.</p>\n<p>So, we will dynamically analyze the validation process of the checkImageFileName function to look for a more efficient way to identify the Flag.</p>\n<h2 id=\"dynamically-analyze-the-checkimagefilename-function\" style=\"position:relative;\"><a href=\"#dynamically-analyze-the-checkimagefilename-function\" aria-label=\"dynamically analyze the checkimagefilename function 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>Dynamically Analyze the checkImageFileName Function</h2>\n<p>To dynamically analyze the checkImageFileName function (the function at address 0x140001000), let’s revisit the analysis results from Chapter 5.</p>\n<p>As confirmed in Chapter 5, checkImageFileName extracts the image file name string passed as an argument one character at a time, performs some complex calculation on it, and compares the result with hard-coded integer values.</p>\n<p>We also know that when a loop counter with an initial value of 0 becomes 13 (0xd) or greater, the loop exits, which means the correct image file name is 13 characters long.</p>\n<p>So first, let’s use dynamic analysis to check whether the above analysis result is correct.</p>\n<p>After clearing existing breakpoints with <code class=\"language-text\">bc *</code>, first set a breakpoint with the <code class=\"language-text\">bp DoPDriver+0x1050</code> command.</p>\n<p>At this address, the <code class=\"language-text\">movsx   eax,byte ptr [r11]</code> instruction is executed.</p>\n<p>As confirmed in Chapter 5, the image file name that checkImageFileName receives as an argument is stored at the pointer address held in the R11 register.</p>\n<p>The code executed at <code class=\"language-text\">DoPDriver+0x1050</code> corresponds to extracting that string one character at a time inside the loop.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 568px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/5c738770c483f5a8b8ee5f39fc650d4f/10e91/driver-kernel-debug-009.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: 104.58333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAVCAYAAABG1c6oAAAACXBIWXMAAA7DAAAOwwHHb6hkAAADOUlEQVQ4y31U23baSBDUtwQHJHS/oQuSJduY2AgkMJc42bNn9/9/orZ6Bmy8cfJQp0caTauqu3qM9XaDzX7AatNhtVopPK97dNs9ut0Rq+EF3csJ3bBD13XYDD3W/QbL5fJTGFldoLyrkBYzOI5L2IQDx9bRdR3Y0+kbppc196eX5/O3AqNo56i/tSqhZVoIwxBxHCOMI8yKDHESwXY9uEEIx/fhhRIDeJ6HIAjgE5LUsiwFo1o2aNcLzEqdME1TZFmGdDZDkmdI+JzXNfKmhhdF8JIEbhiphGEUIiAsawrTNBWMgnKrxS3iWaz+kGcx2ipDkSUocibLE30w8JU0n2x910VAliERkLWsIzIPqcKoHhs0z/dkk6qECQ9XRaoSzhnbpqT8WCV1ySqOYh6OkMQJZskMKWMUxnwmuGeUDzVun+5UwqkkTFKFKIlZw1xLohT52XWtLEtLNLk2L2uRnLclpI4xpY3HY0pO2BSyiSiH8WY0ws3NDUaC0VUk5L3sy7nJZKJgPO06rE8DFs8LFEWB23qObvWM/X6LDf3W9z02mx7bfo0dIXE7cE303B+2A5q2Za1zdd54GlboDj0WTwvU7GZZlti/bPHPv3/j9ecrfvz1A6fXVxwPL/h+2OHEKPh+3OFw2ON4OuJhscCc56qqYg3Z4WZ1rySbk0tddM0cz4XFupn2VEn9MnqXq9cjhfHXr++S82aubUO7iC00HFrCU6Z1aRHprm1Pr/Y/4jIxAkOm5I7Gzug9e/rxQ48M52WuJqeoSmXmS7c/BQ1OhiXmD7e0TfLxr2JisszSSDH1iD8mO1tKM9w8cpbTt6G/DLt8JCxlYlzPUQfMsyeVN01LwbzyqWbIGkZk8n/JF0gdo/g8v/SmMBaP+qrOPiKOrXsuh1EvP2d4XXBhe8dbSQzvMYlqlIq83qjAC9g0RyvgpOguK4ZXid4le5ilMdda2mTyPmYKfJ6MJ2qtJMvl0HYPtE3yQbJOyE6TTUK52jq2YugIwzM8SvY5psJYMSzvK9Sc5d/VUKwgyZtGJEfq1vHVxerrmvICjkjGDwN1uej78LH5RfIbU2kKE4ask8S3Lp9xkS7dFsn/Afn0nd3R4YcfAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/5c738770c483f5a8b8ee5f39fc650d4f/8ac56/driver-kernel-debug-009.webp 240w,\n/static/5c738770c483f5a8b8ee5f39fc650d4f/d3be9/driver-kernel-debug-009.webp 480w,\n/static/5c738770c483f5a8b8ee5f39fc650d4f/bebff/driver-kernel-debug-009.webp 568w\"\n              sizes=\"(max-width: 568px) 100vw, 568px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/5c738770c483f5a8b8ee5f39fc650d4f/8ff5a/driver-kernel-debug-009.png 240w,\n/static/5c738770c483f5a8b8ee5f39fc650d4f/e85cb/driver-kernel-debug-009.png 480w,\n/static/5c738770c483f5a8b8ee5f39fc650d4f/10e91/driver-kernel-debug-009.png 568w\"\n            sizes=\"(max-width: 568px) 100vw, 568px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/5c738770c483f5a8b8ee5f39fc650d4f/10e91/driver-kernel-debug-009.png\"\n            alt=\"Loop processing that extracts the image file name one character at a time\"\n            title=\"Loop processing that extracts the image file name one character at a time\"\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>After setting the breakpoint and resuming system execution with the <code class=\"language-text\">g</code> command, run any program inside the virtual machine.</p>\n<p>In this book, I ran HelloWorld.exe, which can be downloaded from the following repository, as a test.</p>\n<br>\n<p>HelloWorld.exe:</p>\n<p><a href=\"https://github.com/kash1064/ctf-and-windows-debug/blob/main/HelloWorld.exe\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://github.com/kash1064/ctf-and-windows-debug/</a></p>\n<br>\n<p>When you run this program, the breakpoint at <code class=\"language-text\">DoPDriver+0x1050</code> is hit and execution temporarily stops.</p>\n<p>At this point, running the <code class=\"language-text\">da @R11</code> command confirms that the string <code class=\"language-text\">HelloWorld.exe</code> is stored at the pointer address held in the R11 register.</p>\n<p>Furthermore, after stepping through the <code class=\"language-text\">movsx   eax,byte ptr [r11]</code> instruction, you can confirm that the EAX register contains 0x48 (H), the first character of the image file name.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 652px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/718ee5052e7cc5cb3fb1b7290e15faba/dba9a/driver-kernel-debug-010.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.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABS0lEQVQoz31Ri46CQAzc//8wgjExeshpRIwIIkrkJUjAx1xn4164O3ObTLrbdtvpVH26LsLdDvv9HpdLjfv9jr7v/8XtdtO26zoN4+dd+b6PIAiwWCxwOCRI0xTn81kHq6pEXhRomgZFkSPPc5RlhSzL0LYtuleh9nrVb96Vv9nAcRzMZjNMp1O48zkmkwlcYU72H6+YPRphLjHm2rYNy7LAv1EUYeWtQGKcUpHd2vOwkWCSJAjDELEEyJTMNAPpfhUWZkTzpjzP5/MbD4E6Ho+6EG0mo7IjOxUyalVVfzR69x5CcaTtNhD9DoikEBlSIzIgyJKo61pb+nhns3dQZVnKdi96ESxEZsZn/MbHpZxOqf5otv0bar32tOgUmHpyGY6Iv1wu9VLG4zE80TiOY81+KzmUyEjCRkMoI37X9eD5IfLjoe27M8wb4gsL1amkFWY9owAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/718ee5052e7cc5cb3fb1b7290e15faba/8ac56/driver-kernel-debug-010.webp 240w,\n/static/718ee5052e7cc5cb3fb1b7290e15faba/d3be9/driver-kernel-debug-010.webp 480w,\n/static/718ee5052e7cc5cb3fb1b7290e15faba/db2ac/driver-kernel-debug-010.webp 652w\"\n              sizes=\"(max-width: 652px) 100vw, 652px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/718ee5052e7cc5cb3fb1b7290e15faba/8ff5a/driver-kernel-debug-010.png 240w,\n/static/718ee5052e7cc5cb3fb1b7290e15faba/e85cb/driver-kernel-debug-010.png 480w,\n/static/718ee5052e7cc5cb3fb1b7290e15faba/dba9a/driver-kernel-debug-010.png 652w\"\n            sizes=\"(max-width: 652px) 100vw, 652px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/718ee5052e7cc5cb3fb1b7290e15faba/dba9a/driver-kernel-debug-010.png\"\n            alt=\"Extract one character from the R11 register into the EAX register\"\n            title=\"Extract one character from the R11 register into the EAX register\"\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 code that compares a hard-coded integer value with the result of performing some calculation on the character extracted at <code class=\"language-text\">DoPDriver+0x1050</code> is at <code class=\"language-text\">DoPDriver+0x114a</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 459px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/7816dd122f2e719b452f962d3fcdb5f0/48711/driver-kernel-debug-011.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.916666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB10lEQVQ4y32SW2+bQBSE/WswLPfdZZer71JV3DgPiRKpiqqkb5XyB9IWO03zvydnMdBYwX0YGczyMWfmTL5+v8PN3S2ubq+xu7jAbrdrVW+3eLj/hufnA34f9mj2DZqmwZ/9T7wenvCyf6LrX3h5/Ysfj4/Y1nX73mRz+QnlZoZsliMIgkE+ScQxBBcQUpKOv1LEJA7OY3B6zjlHFEXwPQ++72My/7xCOs8hUgnG2AfZtg0uOYIwhExTxAQLZALbYbAsC1Oj6RSO47RqgdmyQJIpuARw6Uuu655IqgQJSWuNqsqgUw1JjsMobD/kkTMDMwYmi+0a6SInYPIBZGQOaa2gyJ0i0KxUqOYZRCIR0cghycTzD1ivkS0KqEKPAj1yLHgE1jlnrocgjuAwt43DMepg7ciL2oxcQpXjwF6mqLSgDAkWUSH+uzF72DCyASY5ZeiyUZhDBRjQks5pJcilccpOgL2Glo/AsZFdCFqVMPARUwnmvm/0vbMBeHRYjAL9NjdTikRBpZWUc+B7Z2FDKcWmgq7S49r0QIJ53SHLmtKu2cO+nYN1wBXyddWVwoZV4YlAZJY4DGg1wpOXzsFa4PLLBtmKgIU62b2CIqgpX5Mb6/77H6jXG2hqoJSvgUUKAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/7816dd122f2e719b452f962d3fcdb5f0/8ac56/driver-kernel-debug-011.webp 240w,\n/static/7816dd122f2e719b452f962d3fcdb5f0/25604/driver-kernel-debug-011.webp 459w\"\n              sizes=\"(max-width: 459px) 100vw, 459px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/7816dd122f2e719b452f962d3fcdb5f0/8ff5a/driver-kernel-debug-011.png 240w,\n/static/7816dd122f2e719b452f962d3fcdb5f0/48711/driver-kernel-debug-011.png 459w\"\n            sizes=\"(max-width: 459px) 100vw, 459px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/7816dd122f2e719b452f962d3fcdb5f0/48711/driver-kernel-debug-011.png\"\n            alt=\"Compare the result of performing some calculation on the extracted character with an integer value\"\n            title=\"Compare the result of performing some calculation on the extracted character with an integer value\"\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>So next, set a breakpoint at this address and see whether the above validation can be bypassed by tampering with the zero flag.</p>\n<p>After setting a breakpoint with the <code class=\"language-text\">bp DoPDriver+0x114a</code> command, resume execution with the <code class=\"language-text\">g</code> command.</p>\n<p>If you run the <code class=\"language-text\">r zf</code> command immediately after the integer value is checked, you can confirm that the zero flag is 0, which tells you that the character H is not the first character of the image file name that yields the correct Flag.</p>\n<p>If you resume program execution as is, the validation will fail and the loop processing will end, so before resuming execution, overwrite the zero flag to 1 with <code class=\"language-text\">r zf=1</code>.</p>\n<p>When you enter the <code class=\"language-text\">g</code> command and resume system execution with the zero flag tampered, the loop continues and the breakpoint at <code class=\"language-text\">DoPDriver+0x1050</code> is hit again.</p>\n<p>At this point, the loop is on its second iteration, and you can confirm that the pointer address in the R11 register has shifted to point to the second character of the image file name.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 475px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/08a1cc12b9a7973f3395d5e9efd64b23/466da/driver-kernel-debug-012.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: 33.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA+klEQVQoz51R22qEMBDN/3+YdB/qylq2FVbXKxh1jUlcLyCezggW6UNbOnCYa+ZyIqQs0fc9tNb4SdZ13fBbjUiSBOM4omkaWGMxzzOmafo3RBjekKYZ6rqGNmYL8oAde+HRP+a/Q5zPHi4XH3F8RxAE1DzF8zlsNOxUMAwNY5+1tfYrz/YR4vRyguu68DwPjuPglWxuGgQfiKIIj0cL3XUoyxJhGKKqKhRFQQvEuFOer8uyHEwdx8X+8M33cb2+o20VlFKQUqIiGoZh2E7h6RxnmzdTqkVHg/bNtdGwpEWaJsjzgrrnpPOtybIsqOj3eSv+LEm6Jxr+Ip/JtBVlVbDnXQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/08a1cc12b9a7973f3395d5e9efd64b23/8ac56/driver-kernel-debug-012.webp 240w,\n/static/08a1cc12b9a7973f3395d5e9efd64b23/4287c/driver-kernel-debug-012.webp 475w\"\n              sizes=\"(max-width: 475px) 100vw, 475px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/08a1cc12b9a7973f3395d5e9efd64b23/8ff5a/driver-kernel-debug-012.png 240w,\n/static/08a1cc12b9a7973f3395d5e9efd64b23/466da/driver-kernel-debug-012.png 475w\"\n            sizes=\"(max-width: 475px) 100vw, 475px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/08a1cc12b9a7973f3395d5e9efd64b23/466da/driver-kernel-debug-012.png\"\n            alt=\"The pointer in the R11 register points to the second character of the image file name\"\n            title=\"The pointer in the R11 register points to the second character of the image file name\"\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 confirms that the checkImageFileName function validates the image file name one character at a time, and that tampering with the zero flag at address <code class=\"language-text\">DoPDriver+0x114a</code> lets you bypass the validation result.</p>\n<p>In other words, just like DoPClient, all characters in the image file name can be validated in a single attempt, which means the correct image file name can be identified with at most 95 brute-force attempts from 0x20 to 0x7E.</p>\n<h2 id=\"identify-the-image-file-name-with-a-javascript-based-debugger-script\" style=\"position:relative;\"><a href=\"#identify-the-image-file-name-with-a-javascript-based-debugger-script\" aria-label=\"identify the image file name with a javascript based debugger script 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>Identify the Image File Name with a JavaScript-Based Debugger Script</h2>\n<p>In Chapter 4, we used cdb.exe and a debugger command script to identify the correct Flag.</p>\n<p>This time, unlike DoPClient, the loaded debugger script is not reinitialized every time a brute-force attempt is made, so we can perform the brute-force attack with a powerful JavaScript-based debugger script.</p>\n<p>To identify the correct image file name, we will use the following JavaScript file loaded into the kernel debugger and a Python script file that runs in the virtual machine and brute-forces the image file name.</p>\n<p>The JavaScript loaded into the kernel debugger is as follows.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// .scriptrun C:\\CTF\\Autorun2.js</span>\n<span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> word <span class=\"token operator\">=</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> correctImageFileName <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">13</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">fill</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"*\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">RunCommands</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">cmd</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> ctl <span class=\"token operator\">=</span> host<span class=\"token punctuation\">.</span>namespace<span class=\"token punctuation\">.</span>Debugger<span class=\"token punctuation\">.</span>Utility<span class=\"token punctuation\">.</span>Control<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> output <span class=\"token operator\">=</span> ctl<span class=\"token punctuation\">.</span><span class=\"token function\">ExecuteCommand</span><span class=\"token punctuation\">(</span>cmd<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> line <span class=\"token keyword\">of</span> output<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\nhost<span class=\"token punctuation\">.</span>diagnostics<span class=\"token punctuation\">.</span><span class=\"token function\">debugLog</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"  \"</span><span class=\"token punctuation\">,</span> line<span class=\"token punctuation\">,</span> <span class=\"token string\">\"\\n\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">return</span> output<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">SetBreakPoints</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> ctl <span class=\"token operator\">=</span> host<span class=\"token punctuation\">.</span>namespace<span class=\"token punctuation\">.</span>Debugger<span class=\"token punctuation\">.</span>Utility<span class=\"token punctuation\">.</span>Control<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> breakpoint<span class=\"token punctuation\">;</span>\n\nbreakpoint <span class=\"token operator\">=</span> ctl<span class=\"token punctuation\">.</span><span class=\"token function\">SetBreakpointAtOffset</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"DoPDriver\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0x1054</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nbreakpoint<span class=\"token punctuation\">.</span>Command <span class=\"token operator\">=</span> <span class=\"token string\">\"dx -r1 @$autoRun2.CheckPoint1() ; g\"</span><span class=\"token punctuation\">;</span>\n\nbreakpoint <span class=\"token operator\">=</span> ctl<span class=\"token punctuation\">.</span><span class=\"token function\">SetBreakpointAtOffset</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"DoPDriver\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0x114a</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nbreakpoint<span class=\"token punctuation\">.</span>Command <span class=\"token operator\">=</span> <span class=\"token string\">\"dx -r1 @$autoRun2.CheckPoint2() ; r zf = 1 ; g\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Result</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\nhost<span class=\"token punctuation\">.</span>diagnostics<span class=\"token punctuation\">.</span><span class=\"token function\">debugLog</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"correctImageFileName is: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> w <span class=\"token keyword\">of</span> correctImageFileName <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\nhost<span class=\"token punctuation\">.</span>diagnostics<span class=\"token punctuation\">.</span><span class=\"token function\">debugLog</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nhost<span class=\"token punctuation\">.</span>diagnostics<span class=\"token punctuation\">.</span><span class=\"token function\">debugLog</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">CheckPoint1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// Get one character from the image file name from the EAX register</span>\n<span class=\"token keyword\">let</span> context <span class=\"token operator\">=</span> host<span class=\"token punctuation\">.</span>namespace<span class=\"token punctuation\">.</span>Debugger<span class=\"token punctuation\">.</span>State<span class=\"token punctuation\">.</span>DebuggerVariables<span class=\"token punctuation\">.</span>curthread<span class=\"token punctuation\">.</span>Registers<span class=\"token punctuation\">.</span>User<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> eaxValue <span class=\"token operator\">=</span> context<span class=\"token punctuation\">.</span>eax<span class=\"token punctuation\">;</span>\nword <span class=\"token operator\">=</span> String<span class=\"token punctuation\">.</span><span class=\"token function\">fromCodePoint</span><span class=\"token punctuation\">(</span>eaxValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">CheckPoint2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> context <span class=\"token operator\">=</span> host<span class=\"token punctuation\">.</span>namespace<span class=\"token punctuation\">.</span>Debugger<span class=\"token punctuation\">.</span>State<span class=\"token punctuation\">.</span>DebuggerVariables<span class=\"token punctuation\">.</span>curthread<span class=\"token punctuation\">.</span>Registers<span class=\"token punctuation\">.</span>User<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> r9Value <span class=\"token operator\">=</span> context<span class=\"token punctuation\">.</span>r9d<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> r11Value <span class=\"token operator\">=</span> context<span class=\"token punctuation\">.</span>r11<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> zeroFlagValue <span class=\"token operator\">=</span> context<span class=\"token punctuation\">.</span>zf<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Determine whether validation succeeded from the zero flag value</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>zeroFlagValue <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\ncorrectImageFileName<span class=\"token punctuation\">[</span><span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>r9Value<span class=\"token punctuation\">,</span> <span class=\"token number\">16</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> word<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">initializeScript</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">host<span class=\"token punctuation\">.</span>apiVersionSupport</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invokeScript</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">RunCommands</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"dx @$autoRun2 = Debugger.State.Scripts.Autorun2.Contents\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">RunCommands</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"dx @$autoRun2.SetBreakPoints()\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">RunCommands</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"g\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The Python script executed on the virtual machine side is as follows.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n<span class=\"token keyword\">import</span> subprocess\n\nexe_path <span class=\"token operator\">=</span> <span class=\"token string\">\"C:\\\\CTF\\\\HelloWorld.exe\"</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\">0x20</span><span class=\"token punctuation\">,</span><span class=\"token number\">0x7F</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token keyword\">if</span> <span class=\"token builtin\">chr</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"\\\\\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"?\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"&lt;\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\">\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\":\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"*\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"|\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"\\\"\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\".\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"/\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n<span class=\"token keyword\">continue</span>\n\nnew_exe_path <span class=\"token operator\">=</span> <span class=\"token string\">\"C:\\\\CTF\\\\{}.exe\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">chr</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token operator\">*</span><span class=\"token number\">9</span><span class=\"token punctuation\">)</span>\nos<span class=\"token punctuation\">.</span>rename<span class=\"token punctuation\">(</span>exe_path<span class=\"token punctuation\">,</span>new_exe_path<span class=\"token punctuation\">)</span>\nexe_path <span class=\"token operator\">=</span> new_exe_path\nproc <span class=\"token operator\">=</span> subprocess<span class=\"token punctuation\">.</span>Popen<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>exe_path<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\nproc<span class=\"token punctuation\">.</span>kill<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This script can be downloaded from the following repository as Autorun2.js and Stage2_Solver.py, respectively.</p>\n<br>\n<p>Autorun2.js and <code class=\"language-text\">Stage2_Solver.py</code>:</p>\n<p><a href=\"https://github.com/kash1064/ctf-and-windows-debug/blob/main/Autorun2.js\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://github.com/kash1064/ctf-and-windows-debug/</a></p>\n<br>\n<p>The structure of the JavaScript loaded into the kernel debugger is almost the same as Autorun.js used in Chapter 4.</p>\n<p>In this script, a breakpoint is set at <code class=\"language-text\">DoPDriver+0x1054</code>, the address immediately after extracting one character of the image file name from the address held in the R11 register, and the CheckPoint1 function stores the character being evaluated in the variable <code class=\"language-text\">word</code>.</p>\n<p>Then, at the breakpoint set at <code class=\"language-text\">DoPDriver+0x114a</code>, where the evaluation result can be checked, the CheckPoint2 function runs and uses the zero flag value to determine whether the character saved in <code class=\"language-text\">word</code> matches the corresponding character in the correct image file name.</p>\n<p>With this script, you can brute-force each character of the correct image file name by running processes such as <code class=\"language-text\">AAAAAAAAA.exe</code> and <code class=\"language-text\">ZZZZZZZZZ.exe</code>.</p>\n<p>And the script used to brute-force the file name is Stage2_Solver.py.</p>\n<p>This script brute-forces the image file name by renaming and running <code class=\"language-text\">C:\\CTF\\HelloWorld.exe</code>, a program that only outputs the string <code class=\"language-text\">Hello World</code>.</p>\n<p>By using these two scripts, you can identify the correct image file name in 95 attempts from 0x20 to 0x7E.</p>\n<p>The program used here can be replaced with any EXE file, but you can also use HelloWorld.exe by downloading it from the following repository and renaming it. HelloWorld.exe is simply a program that prints the string “Hello World” to the console.</p>\n<p>Place the downloaded HelloWorld.exe directly under the <code class=\"language-text\">C:\\CTF</code> folder in the virtual machine.</p>\n<br>\n<p>HelloWorld.exe:</p>\n<p><a href=\"https://github.com/kash1064/ctf-and-windows-debug/blob/main/HelloWorld.exe\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://github.com/kash1064/ctf-and-windows-debug/blob/main/HelloWorld.exe</a></p>\n<br>\n<p>Once everything is ready, run the following commands in order in the kernel debugger to perform the brute-force attack.</p>\n<p>This flushes the existing breakpoints and then loads the Autorun2.js script.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">bc *\n.scriptrun &lt;full path to Autorun2.js></code></pre></div>\n<p>After loading Autorun2.js into the debugger, run <code class=\"language-text\">Stage2_Solver.py</code> on the virtual machine side.</p>\n<p>Although the number of attempts is only 95, if a breakpoint is hit in the kernel debugger, the system itself may temporarily stop, so it can take more than 10 minutes for all processing to finish.</p>\n<p>After <code class=\"language-text\">Stage2_Solver.py</code> finishes running, the correct image file name should be recorded in the <code class=\"language-text\">correctImageFileName</code> array in Autorun2.js, so run the <code class=\"language-text\">dx -r1 @$autoRun2.Result()</code> command in the debugger.</p>\n<p>This lets us identify the correct image file name as <code class=\"language-text\">topsecret.exe</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 746px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/13e31db4212685fef69e731191a254df/62de4/driver-kernel-debug-013.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: 79.16666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB60lEQVQ4y51TDXOqMBDM//9zr+PYKkJBgYDy4SeogLrv9mw6tuObzmtmzpwh2ezuXczb6yt8P0CaJJjPI8nfEScxhn4Ax+12w/8MM51OEYYRrLVYxAu8S54IeN/3vwScTAQkRJqmiAWQ4GT4a0AnOVHJcwQBJX9l+K94dqEZjUag7MWC7ELJZwp8uVx+ZPPskk/AKAox82fwvBn8wMfhcMAwDDgeW+x2WzRNg/P5rNG2rX57KrkoVijLElVVoSgK1HWN1Wql+Waz0Zx25HmOUvZw33K5lH1rvXS/32P/MfNS03WdsDgKi51uIMh2u9X/PLz7yPltvV7rN+4h00fZHFwznfz0Qt+miciei5extpDNLGLxld5GUYQsyzCRjuDctkdcr9cvXnKQnDKkJ7yZ8iiHFlAy1/I8U6adVN356MC+V5ydYVx7PI62bfSw8+XQ3P9Tuovv1f4ErOsKmc1UipVIRW4cxyiFIdlam94tkPB9X/fxEeT5UgvFgtHbsqzQSi0Mq+qCZruKUz5nHqJntMVFIwU6nU5aTDJnCznrjGsDMiLYHbBUWTzwCOTicd2BMpibRN7tm1SPr2OiDR4pOxaEBWC7cCYDMuELcvOzMGwLz/O0Jcbyrv+8vMh7DnRtPB7rBZRNO+jVT/EXcQjHW09fFCsAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/13e31db4212685fef69e731191a254df/8ac56/driver-kernel-debug-013.webp 240w,\n/static/13e31db4212685fef69e731191a254df/d3be9/driver-kernel-debug-013.webp 480w,\n/static/13e31db4212685fef69e731191a254df/f7ebd/driver-kernel-debug-013.webp 746w\"\n              sizes=\"(max-width: 746px) 100vw, 746px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/13e31db4212685fef69e731191a254df/8ff5a/driver-kernel-debug-013.png 240w,\n/static/13e31db4212685fef69e731191a254df/e85cb/driver-kernel-debug-013.png 480w,\n/static/13e31db4212685fef69e731191a254df/62de4/driver-kernel-debug-013.png 746w\"\n            sizes=\"(max-width: 746px) 100vw, 746px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/13e31db4212685fef69e731191a254df/62de4/driver-kernel-debug-013.png\"\n            alt=\"Identify the image file name by brute force\"\n            title=\"Identify the image file name by brute force\"\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<h2 id=\"inspect-the-paged-pool-information\" style=\"position:relative;\"><a href=\"#inspect-the-paged-pool-information\" aria-label=\"inspect the paged pool information 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>Inspect the Paged Pool Information</h2>\n<p>Now that we have identified the correct image file name as topsecret.exe with a brute-force attack, let’s check whether the Flag is really stored in the region allocated by ExAllocatePoolWithTag.</p>\n<p>Before checking, reboot the virtual machine once to clear the existing paged pool.</p>\n<p>After rebooting the virtual machine, attach the kernel debugger before launching DoPClient and execute the <code class=\"language-text\">!poolused</code> command <sup id=\"fnref-2\"><a href=\"#fn-2\" class=\"footnote-ref\">2</a></sup>.</p>\n<p>If you run this extension command without options, it outputs a list of the pool tags and memory usage for the paged pool and nonpaged pool.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/145896ed7fb8933da771ee64977df6d9/6acbf/driver-kernel-debug-014.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: 89.58333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACJklEQVQ4y42U6Y6jQAyEef9XizSZEG4CgVyEI9cTeP05Y4RWu9H8sLrpbleXq0wHeZ5LURTCeDqd5Hg8StM00g+D3O93mabJ4na72ffj8fgYQV3XUpaFVDpWVSV1XUmaJDqvpW1bOZ/Pcr1edbzIoJeQBPD/IjgcDtIeWmM3KYuh740xTAHc7/fS69rz+ZzBPjJcr9ey2WxkE4ay3W4lTVMJdV6UpWRZJrvdzspdgn0CNYZvDTOJ41i+FTyKIpujKzK0TWs6/oohCYlqViqjg5bJiK5ccrlc5PV6zYb8JoJ+6KXrOhP+eu3sFvQixnG08G/X0WO57nsBLEjCFBzFCExgzkXscxkO+0iQ0/eDmch59qgkoDT0oS24BWNI4NA03exQd+mkUD2jKDajCKQhl2DeKBEDxNVRAWgPgDEEMBjDgvZB0zDcyGq10o74NsNi1Z1uiKKt9SzAwzBKADpiUhoaYBKAgPkfwh4JmAeB8qelnKlrbaZwgAl6UTJt1P/oMo6TaQl7kmFPJMow0Txy+U3Rb24bem0JyI0uPAyRw9oJhgoEiLMjkGPZVgGLLKAVgF4ygKxzO39Lbqa8GQJK+Q446sVz2zhDQGhiHPX2cF3QMNdkTHAgBzXApYZZBuBjNoWD/wLE2a+v9QyUZqmxpjJ0ZkSiuWQammT60EteAlI2DwlghLuO5uTOJbvLJLFI4t+Ane7xZkbxu7GTJJ4fZboCdv5o/AHmvynWoGUwNwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/145896ed7fb8933da771ee64977df6d9/8ac56/driver-kernel-debug-014.webp 240w,\n/static/145896ed7fb8933da771ee64977df6d9/d3be9/driver-kernel-debug-014.webp 480w,\n/static/145896ed7fb8933da771ee64977df6d9/e46b2/driver-kernel-debug-014.webp 960w,\n/static/145896ed7fb8933da771ee64977df6d9/4ad2e/driver-kernel-debug-014.webp 1001w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/145896ed7fb8933da771ee64977df6d9/8ff5a/driver-kernel-debug-014.png 240w,\n/static/145896ed7fb8933da771ee64977df6d9/e85cb/driver-kernel-debug-014.png 480w,\n/static/145896ed7fb8933da771ee64977df6d9/d9199/driver-kernel-debug-014.png 960w,\n/static/145896ed7fb8933da771ee64977df6d9/6acbf/driver-kernel-debug-014.png 1001w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/145896ed7fb8933da771ee64977df6d9/d9199/driver-kernel-debug-014.png\"\n            alt=\"Inspect paged pool information in the kernel debugger\"\n            title=\"Inspect paged pool information in the kernel debugger\"\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>Because the pool tag of the paged pool created by DoPDriver was <code class=\"language-text\">flag</code>, run the <code class=\"language-text\">!poolused 0 flag</code> command using the tag name as the option argument.</p>\n<p>However, because DoPDriver has not yet been used at this point, a paged pool with the tag <code class=\"language-text\">flag</code> does not yet exist, so no information is displayed.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 621px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/410c18f4b92732e21fa9ad80024e4a46/3075e/driver-kernel-debug-015.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: 34.583333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA70lEQVQoz6VRa2/DIAzM//+FqxSp05YsqaKkEF55cuW8UtHPtWSB7fP5DFXf/eHnt0HTNLhcvnC9fqNtW9R1jXEcoZSCtRbzPGNZFnjnoLWWnHMW1hg47yWOMaLiRSkNkwp0lxrYuG0bQghCxDxJhND/ExpjERIR8e55CmFIoCkpme53mUZFn1h1HAeO85SAqnyadrv16PteJjPHyVS377us1nUd1nUVZ630KgQvK8V4YhgGWYWN9LwqbZomuVMAa8sSJEcSWj4rKtgSINv5VFvGZdNbvYhfhFqrlwom+RElyKc4g7kiBWTjM1BxSfgAPy0iJf/FIqoAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/410c18f4b92732e21fa9ad80024e4a46/8ac56/driver-kernel-debug-015.webp 240w,\n/static/410c18f4b92732e21fa9ad80024e4a46/d3be9/driver-kernel-debug-015.webp 480w,\n/static/410c18f4b92732e21fa9ad80024e4a46/b2315/driver-kernel-debug-015.webp 621w\"\n              sizes=\"(max-width: 621px) 100vw, 621px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/410c18f4b92732e21fa9ad80024e4a46/8ff5a/driver-kernel-debug-015.png 240w,\n/static/410c18f4b92732e21fa9ad80024e4a46/e85cb/driver-kernel-debug-015.png 480w,\n/static/410c18f4b92732e21fa9ad80024e4a46/3075e/driver-kernel-debug-015.png 621w\"\n            sizes=\"(max-width: 621px) 100vw, 621px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/410c18f4b92732e21fa9ad80024e4a46/3075e/driver-kernel-debug-015.png\"\n            alt=\"Inspect information about paged pool allocations with the tag flag\"\n            title=\"Inspect information about paged pool allocations with the tag flag\"\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>Now that we have confirmed that no paged pool with the tag <code class=\"language-text\">flag</code> currently exists in the system, next launch DoPClient, enter the password <code class=\"language-text\">FLAG{You_can_use_debug_script_in_WinDbg_Next}</code>, and load DoPDriver into the system again.</p>\n<p>Then run the <code class=\"language-text\">bp DoPDriver+0x135e</code> command in WinDbg to set a breakpoint at <code class=\"language-text\">DoPDriver+0x135e</code>.</p>\n<p>This address is where the ExAllocatePoolWithTag function is called via <code class=\"language-text\">call  qword [rel ExAllocatePoolWithTag]</code>.</p>\n<p>If <code class=\"language-text\">topsecret.exe</code>, which we identified earlier, is indeed the correct image file name, it should pass the validation in the checkImageFileName function and this code should execute.</p>\n<p>When you launch any executable renamed to topsecret.exe in the virtual machine, execution temporarily stops at the address <code class=\"language-text\">DoPDriver+0x135e</code>.</p>\n<p>Here, inspect the arguments to the ExAllocatePoolWithTag function with the <code class=\"language-text\">r ECX,EDX,R8d</code> command.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 553px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/545d2bfa1278e4bc45443315fc0d8bc5/74cfa/driver-kernel-debug-016.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: 100.41666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACp0lEQVQ4y4VV2XLaQBDU/39SKpWDxIAkdIMkDgEWIO6zeHPBpHtANrExftjSqthtdU/3DEaSJNJsNqXT6Yjv+5LEsTSjSPemaUq1WhXbtuV3pSKu60q73ZYwDCVNU9yLJElSybJMlsulbDYbMcbjsQwGAxmPR9LtdvUgF/c8sMLB/X4vq9VKn6fTSc7n8+vzfD7p/uXlRZcxGo1kMpkIgfv9vn4tTdvS6/X0fbvdXS+e/7v42VLAAPKiKJQwCFR+BjDP8yXHb8oS7NbrtS6+P1rGfD6XWs2UP09P8hdPx/MkaqGOzZYsFgtlXBRTORwOemG73T5cxhyXvv+syLcfv6RSs8RyPalU6/L8nANooiwLlIRl2e12X4IaCzCkZMoNritutaQL17kfA2g2m0mej/RCCVhK/AgIho1GQ6PhIBY+JDMWjI3ve9IG8HA4VINWqCGdfsRSAS0LUk3rDRAGMYMEjcJIP0bzmASCl9LvMqQpDhh6AKOzzGAHGezC6aIotHb8KINLtyn/VvJ7UAVs2BfJFmUDXDsCWWTHdHuZgvAcGfISGd7W8y5DyzIBCDDnAshFyeWewDRpBNAyj/dAFdB1XLC0xb5KvxiCvk4TgDkwzdbAs48ZoRRPgt4FZH0ot16vS8Nxri5H6m6W9SSOE5V8PB7V4S8lE5CSHYB5YEVZBIwxdZIEHYNMkhmNmk6n2uMFnrchvwVWyR5Ykdkb4CWH3HOshWEA+ak6zfiwjp+xvEhGDpm7xjWHfuBfgg7WJn7zPFcnUAtsyZxRKgfGB4baKbjMbmGwaQqHbulwfJWcZX10S6bDgv3PMxPk9H1/Gyw4c2jCFLIh2wj5S2AGWca4mOe5sqJ8nn84vkg70ppRagBZTSn/FiiPzDg4eln2CsZRRsfvrX86XK17Nt2GGAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/545d2bfa1278e4bc45443315fc0d8bc5/8ac56/driver-kernel-debug-016.webp 240w,\n/static/545d2bfa1278e4bc45443315fc0d8bc5/d3be9/driver-kernel-debug-016.webp 480w,\n/static/545d2bfa1278e4bc45443315fc0d8bc5/e58ce/driver-kernel-debug-016.webp 553w\"\n              sizes=\"(max-width: 553px) 100vw, 553px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/545d2bfa1278e4bc45443315fc0d8bc5/8ff5a/driver-kernel-debug-016.png 240w,\n/static/545d2bfa1278e4bc45443315fc0d8bc5/e85cb/driver-kernel-debug-016.png 480w,\n/static/545d2bfa1278e4bc45443315fc0d8bc5/74cfa/driver-kernel-debug-016.png 553w\"\n            sizes=\"(max-width: 553px) 100vw, 553px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/545d2bfa1278e4bc45443315fc0d8bc5/74cfa/driver-kernel-debug-016.png\"\n            alt=\"Inspect the arguments to the ExAllocatePoolWithTag function\"\n            title=\"Inspect the arguments to the ExAllocatePoolWithTag function\"\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>As confirmed in Chapter 5, the ExAllocatePoolWithTag function takes the following three arguments and returns a pointer to the allocated memory as its return value.</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\">PVOID <span class=\"token function\">ExAllocatePoolWithTag</span><span class=\"token punctuation\">(</span>\n  <span class=\"token punctuation\">[</span>in<span class=\"token punctuation\">]</span> <span class=\"token function\">__drv_strictTypeMatch</span><span class=\"token punctuation\">(</span>__drv_typeExpr<span class=\"token punctuation\">)</span>POOL_TYPE PoolType<span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span>in<span class=\"token punctuation\">]</span> SIZE_T                                         NumberOfBytes<span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span>in<span class=\"token punctuation\">]</span> ULONG                                          Tag\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The value stored in ECX was 1, which specifies PagedPool as PoolType.</p>\n<p>Also, <code class=\"language-text\">0x67616c66</code>, which is stored in R8d, is the hexadecimal representation of the string <code class=\"language-text\">galf</code>, which is the pool tag <code class=\"language-text\">flag</code> arranged in reverse order. (When specifying a pool tag in the ExAllocatePoolWithTag function, you use the value obtained by reversing a tag name of up to four characters.)</p>\n<p>Next, step through with the <code class=\"language-text\">p</code> command to complete the paged pool allocation performed by the ExAllocatePoolWithTag function.</p>\n<p>If the ExAllocatePoolWithTag function successfully allocates paged pool memory, the RAX register, which stores the return value, holds the pointer address of the allocated memory region.</p>\n<p>Also, if you run the <code class=\"language-text\">!poolused 0 flag</code> command again, you can confirm that one paged pool with the tag <code class=\"language-text\">flag</code>, which did not exist earlier, has now been allocated.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/46d24c84683c6ca44fb6f619c55b7b91/e4900/driver-kernel-debug-017.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: 55.833333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABWklEQVQoz4WT2ZKCMBRE8/9fJwojIqJssi8qWPDUk74aS6Zq9KErubfISacTlOM4CMMQcZygrmtRVVXo+x632w1d26JpGnTdY2x1bb7jfBzHhZS/32O73eJwOGhojOv1KqD7/Y5pmjAMg9TvulwuIs7neV5IEeZ5HlzXlfF0OsH3fYHTaVmWMlJN075gRl3XLaSiKMTxeHweO0YURQJkj/AkSVAUOfI8FzgX8aj/SQVBIIsJKopCcvJ2O7DPHqNI01RAff+A/XW1cGitVlivN1prrPTccX7Ai6JL9wk2F2Bgn6Aq1Ucy+TFPy7Jg2zbszUbXrjhkHIR+gwmQDgg0R2NuBDAG5idP50tuiwyZGwOnCKiqWt4gRVfn8/nlir1P7sQhF/D2CCOULrkJ+1mWy5y9sqyQZ5l8+/6UTG16ikejAxbmaJy3zz+ErggnmJs+Nsr05pmMUmsZI7+3vTO8112gTAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/46d24c84683c6ca44fb6f619c55b7b91/8ac56/driver-kernel-debug-017.webp 240w,\n/static/46d24c84683c6ca44fb6f619c55b7b91/d3be9/driver-kernel-debug-017.webp 480w,\n/static/46d24c84683c6ca44fb6f619c55b7b91/e46b2/driver-kernel-debug-017.webp 960w,\n/static/46d24c84683c6ca44fb6f619c55b7b91/6257a/driver-kernel-debug-017.webp 988w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/46d24c84683c6ca44fb6f619c55b7b91/8ff5a/driver-kernel-debug-017.png 240w,\n/static/46d24c84683c6ca44fb6f619c55b7b91/e85cb/driver-kernel-debug-017.png 480w,\n/static/46d24c84683c6ca44fb6f619c55b7b91/d9199/driver-kernel-debug-017.png 960w,\n/static/46d24c84683c6ca44fb6f619c55b7b91/e4900/driver-kernel-debug-017.png 988w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/46d24c84683c6ca44fb6f619c55b7b91/d9199/driver-kernel-debug-017.png\"\n            alt=\"Inspect the address of the paged pool allocated by ExAllocatePoolWithTag\"\n            title=\"Inspect the address of the paged pool allocated by ExAllocatePoolWithTag\"\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 ExAllocatePoolWithTag function allocates pool memory and returns a pointer to the allocated block.</p>\n<p>In this case, on a 64-bit OS, the allocated block is prefixed with a 16-byte <code class=\"language-text\">POOL_HEADER</code> structure.</p>\n<p>Therefore, if you access the address 16 bytes before the block address allocated by the ExAllocatePoolWithTag function with the <code class=\"language-text\">dt nt!_POOL_HEADER @RAX-0x10</code> command, you can confirm that header information including the pool tag <code class=\"language-text\">flag</code> exists there.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 780px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/dfe37b0c42ec88f28874d0fa4a36a95e/a1792/driver-kernel-debug-018.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: 58.75%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB3UlEQVQoz5VTXY+TQBTl3/offPcHGOOjxgdjNvHJTdQXHzZ1k9K10gItS7ulUBgYZIBCTdYWbI93xnbjJqjZm5xcLsyce+4HGmMMy+USCecQQqAoCjRNg91uh/1+j5MdDgcV/w+aJJtMJr9h2xiPxyqB7wdwHIe8D5m0LEtsNhvUdf1PaCyKMBjomE4dReZ5nvqQkmJdH6DXu4RhjGBZNvI8V8RFUSrfBUU4HA6JcALbNpFlnJTUSJIYI0OnZD14yxusViGqqrrDer3uhMZYhKurAUzzhhR6dLEk0u9IUw+29ZTUPaGy+4giTu+4Kj+OY6Wmm1Ap/ALT8kiNi37fgesG1EePVJtYLFzyNoIgIMJUkSVJoobXWTLnCV3ySMWCSN7Q8zMq2cTtbUP4gbb9SRNvyLf3IDehC1oYrZDlNVj8EdPrRwjDx5TpNbZb47gv+7u1+dP/zTTBM6SrHLVwEMxeIvTPUa4/gfPnNNX3kgIPMW0cjXDJP0MXX/HW+AD92sJ85mI2H2E+N9WqyIXPsuy4MoXaRxnLaecUy2HIczLWLpILnBVnON++w6vwBQwxRFXURFKSym9qJ09/zqlPsocyvtfLY6wJRpniGm3VQgQZmB9RP9lRTa4OPcR+AenpgLoDt0zOAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/dfe37b0c42ec88f28874d0fa4a36a95e/8ac56/driver-kernel-debug-018.webp 240w,\n/static/dfe37b0c42ec88f28874d0fa4a36a95e/d3be9/driver-kernel-debug-018.webp 480w,\n/static/dfe37b0c42ec88f28874d0fa4a36a95e/8369b/driver-kernel-debug-018.webp 780w\"\n              sizes=\"(max-width: 780px) 100vw, 780px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/dfe37b0c42ec88f28874d0fa4a36a95e/8ff5a/driver-kernel-debug-018.png 240w,\n/static/dfe37b0c42ec88f28874d0fa4a36a95e/e85cb/driver-kernel-debug-018.png 480w,\n/static/dfe37b0c42ec88f28874d0fa4a36a95e/a1792/driver-kernel-debug-018.png 780w\"\n            sizes=\"(max-width: 780px) 100vw, 780px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/dfe37b0c42ec88f28874d0fa4a36a95e/a1792/driver-kernel-debug-018.png\"\n            alt=\"Inspect the pool header information\"\n            title=\"Inspect the pool header information\"\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>You can also inspect this memory block with the <code class=\"language-text\">!pool</code> command <sup id=\"fnref-3\"><a href=\"#fn-3\" class=\"footnote-ref\">3</a></sup>, which displays information about a specific pool allocation, and confirm the pool header address and pool tag that way as well.</p>\n<p>This command checks whether the address received as an argument exists within a pool block, and if it does, it can display the pool header address, pool tag, and the contents stored in that pool.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 647px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/b8465ac9e0779d8b586bb0f33d2b1ba5/ca12d/driver-kernel-debug-019.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: 49.583333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACL0lEQVQoz01STW+bQBTk/7dSWlVKD+mh6qVSGyVKTpXSi/NRwNjmy3ztB8uCjcE2bkguvU3f0ksPI+C9tzOz87B4wVGKEoIJrBYrVKVG13Zomxb9bo99t8dwGDDsj9O3waE7YPw94nV8xQs9x9OIl+cXjM8jLNlKeIkHN3YRsGB6hiJEohOIHcciWyIuI+RNNtVZy6CPFTbPG+oLtGOL4c8APWj0px5W9VXBezuHS3DeOFidLcE+cjSfGkKN4F2E5EOM4pyBnXN0nzscvxygLzSCswAx9cSFRPG+gJpVsE5PJ+zveogbgfR7BnkjkX/Loa4Vuh8diksGcS1Q3VZg9F7f1lCXCuqqBL/i6H/2BIrlbsAhO8JSOwXb/4XHxSMevAc4gY2Q0dUahrIVmEceFhSJqRmoTmF72oBvOJbJEmuZQO9rrAXFIgoiLBVc24Fju5i7cyy9BYqccqo0lCwRhTHSJAFnHIzqm2ZDS9vR8iqEQTQt1CyxyHIwWqy13W7pUAg/COD7PuI4BuMcWmvUtcaayLIso2HKkEjNfN/3Uz9NU3CabZoGUgooMmFJIXF/f4/ZzGCGp6dHRERqBqUQcI3rhUe1CGEUoaoq7Np26s+9OWzbnupZlqJUCpZhDwKfEExYr9cQUk6qxmE2XYXyLOlfJfGWyP53mOc5uZNQqvznsNY1PFIyThzHoRxdpHRFSQQVKa78ACFFYg6naUYiNbqumwSMgdXKn0RNX6kKfwHvQ793cEUAYgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/b8465ac9e0779d8b586bb0f33d2b1ba5/8ac56/driver-kernel-debug-019.webp 240w,\n/static/b8465ac9e0779d8b586bb0f33d2b1ba5/d3be9/driver-kernel-debug-019.webp 480w,\n/static/b8465ac9e0779d8b586bb0f33d2b1ba5/8f3a3/driver-kernel-debug-019.webp 647w\"\n              sizes=\"(max-width: 647px) 100vw, 647px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/b8465ac9e0779d8b586bb0f33d2b1ba5/8ff5a/driver-kernel-debug-019.png 240w,\n/static/b8465ac9e0779d8b586bb0f33d2b1ba5/e85cb/driver-kernel-debug-019.png 480w,\n/static/b8465ac9e0779d8b586bb0f33d2b1ba5/ca12d/driver-kernel-debug-019.png 647w\"\n            sizes=\"(max-width: 647px) 100vw, 647px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/b8465ac9e0779d8b586bb0f33d2b1ba5/ca12d/driver-kernel-debug-019.png\"\n            alt=\"Inspect the allocated block with the !pool command\"\n            title=\"Inspect the allocated block with the !pool command\"\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>Now that we have confirmed the creation of paged pool memory by the ExAllocatePoolWithTag function, just to be safe, record the pointer address of the memory block held in the RAX register (0xffff828292b6b270 in this case), then resume system execution with the <code class=\"language-text\">g</code> command.</p>\n<p>Once system execution resumes, DoPDriver should store the second Flag string in the paged pool region it created.</p>\n<p>In fact, after resuming execution with the <code class=\"language-text\">g</code> command, temporarily stopping the system again, and then running the <code class=\"language-text\">!pool 0xffff828292b6b270 1</code> command against the memory block address we identified earlier, you can display the data written into the region allocated with the pool tag <code class=\"language-text\">flag</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 638px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/7ad829ee377b197cb8559625be73e6b4/41be6/driver-kernel-debug-020.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: 57.08333333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB0ElEQVQoz32SXW/iMBBF+f/vSEXqA9qX/hq0iZPYiRM7IR8QoLRk+9zc3nHaaldFC0KxRs6Zc2dYvT694rK9oN10qNce/UOHYT3gZXPFn+2EZt3isBlw2pxC/e3xDdPmhvPDmfUDnrdXTL8m3B5vmNSEFTDj8nJBXubIrYZ1Fq5xqNuazwqmLFB6C2MNqrqCLnS4W3k5Gzzfrvj6zPyu5vd3HA5H5CaHzXNobdC1tOx7qDhGy3NVlsjSjLUBaZLCOzasGyiVYBxPC2yehbgAe76cZRmhOgCbZk9oy1oK5zwM62mSoOO9mE28d6GulPoHKL8AHMcR2hgYnRGiadWi6zqkaQLna9iiCA2llhBcMIn3HlEU43w+/wSKodaaFwnl5ZYvCjSOowVoCzbT6IchNCzYoGmaT8PxJ/DIoqHhElljT5gAxdBzVjJDa20wFIhErusaMc//NRRgnhfY75fIEtMxmpiL2UBDiVxV5bfh6XRnhsfjMcwwGPIpMFlKkiiUlUNZ2pBgGYMKI3DcdPQ7uh+5599BtismebFE67olckNbRyPz2UgMpYHnbGMu5e6WxTDMkEAx/FqKUjGBe5ScX5qmoSZA56pguNvtwvz/Bn4AvssfcWjG3AYAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/7ad829ee377b197cb8559625be73e6b4/8ac56/driver-kernel-debug-020.webp 240w,\n/static/7ad829ee377b197cb8559625be73e6b4/d3be9/driver-kernel-debug-020.webp 480w,\n/static/7ad829ee377b197cb8559625be73e6b4/a2d8a/driver-kernel-debug-020.webp 638w\"\n              sizes=\"(max-width: 638px) 100vw, 638px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/7ad829ee377b197cb8559625be73e6b4/8ff5a/driver-kernel-debug-020.png 240w,\n/static/7ad829ee377b197cb8559625be73e6b4/e85cb/driver-kernel-debug-020.png 480w,\n/static/7ad829ee377b197cb8559625be73e6b4/41be6/driver-kernel-debug-020.png 638w\"\n            sizes=\"(max-width: 638px) 100vw, 638px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/7ad829ee377b197cb8559625be73e6b4/41be6/driver-kernel-debug-020.png\"\n            alt=\"Inspect the header and contents of the allocated block with the !pool command\"\n            title=\"Inspect the header and contents of the allocated block with the !pool command\"\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>However, in this state it is difficult to tell whether the second Flag string has really been written there, so by using the <code class=\"language-text\">du</code> command to display the Unicode string at the target address and executing <code class=\"language-text\">du ffff828292b6b270</code>, we were able to confirm that the correct Flag, <code class=\"language-text\">FLAG{The_important_process_is_topsecret.exe}</code>, had been written into the memory block.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 508px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/35673e0e040c08514ee9bf2ae3824af5/2fd48/driver-kernel-debug-021.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: 12.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAn0lEQVQI102OWQ6DMAxEuf/BGlIBaZZmkcJWfqhIgRtMnUhU/Xgae6QZu4qxR+x7yIdA0zTouhZtViEgpcSyLDjPE8dxFL3ma//3MxVjNZyzpejGWCm1zmGcJhitIZWCImKMUHRAawMfPKy18N4jhEB5h2EYiQFVLvHeQdBHjGbOawoErOubvA5aSRjzLAWc3zHPL+z7B9u2FVJKP818AapG1k4epK3TAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/35673e0e040c08514ee9bf2ae3824af5/8ac56/driver-kernel-debug-021.webp 240w,\n/static/35673e0e040c08514ee9bf2ae3824af5/d3be9/driver-kernel-debug-021.webp 480w,\n/static/35673e0e040c08514ee9bf2ae3824af5/7b066/driver-kernel-debug-021.webp 508w\"\n              sizes=\"(max-width: 508px) 100vw, 508px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/35673e0e040c08514ee9bf2ae3824af5/8ff5a/driver-kernel-debug-021.png 240w,\n/static/35673e0e040c08514ee9bf2ae3824af5/e85cb/driver-kernel-debug-021.png 480w,\n/static/35673e0e040c08514ee9bf2ae3824af5/2fd48/driver-kernel-debug-021.png 508w\"\n            sizes=\"(max-width: 508px) 100vw, 508px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/35673e0e040c08514ee9bf2ae3824af5/2fd48/driver-kernel-debug-021.png\"\n            alt=\"Inspect the Flag in the memory block\"\n            title=\"Inspect the Flag in the memory block\"\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 identifies the second correct Flag.</p>\n<h2 id=\"identify-the-memory-block-address-from-the-pool-tag\" style=\"position:relative;\"><a href=\"#identify-the-memory-block-address-from-the-pool-tag\" aria-label=\"identify the memory block address from the pool tag 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>Identify the Memory Block Address from the Pool Tag</h2>\n<p>We were able to identify the second correct Flag by inspecting the address of the memory block allocated by the ExAllocatePoolWithTag function, but static analysis will not always let you identify the code that allocates the pool associated with a specific pool tag the way it did this time.</p>\n<p>So from here, besides identifying the executing code that performs the memory allocation through static analysis, we will try a different approach to identify the address of the memory block associated with a specific pool tag.</p>\n<p>One way to identify a paged pool address from a pool tag is the <code class=\"language-text\">!poolfind</code> command <sup id=\"fnref-4\"><a href=\"#fn-4\" class=\"footnote-ref\">4</a></sup>.</p>\n<p>The <code class=\"language-text\">!poolfind</code> command can search all paged and nonpaged pool regions for instances with a specific pool tag.</p>\n<p>For example, running <code class=\"language-text\">!poolfind -tag \"Proc\"</code> as shown below lets you search paged pool for the addresses of instances whose tag name is Proc.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 785px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/3cc43efb2e1cd279d858ccd6da8e553e/cda19/driver-kernel-debug-022.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: 77.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACnElEQVQ4y4VU226bQBTk/z+geepDlVZVGyWK1KdKfagUxXXj+M5iG3AAYzBgbgv4FjuZnt3UaS5NgjQ6e3ZhdnbPHJQgCBAEIaaej2gey3GSZiirCqvVGkVZoaoWWCyXqBYL7HY7PHxub28f5UqeRCjzBDyLUfLkbpxGyJMQBc1lcYiUIN7jWUrkFTjnyLIMeZ7Tpqu/eSrnFPPsE0Y/D2FQnDWPMal/QdQ+AWffkHRP4f7+iqvzzxifHSK2OxB6rq+v7yEUb7dbbDYbmStpPEcUzpClMYoil7EqOVZLOmrBkcQRwmCGeRTS3BJvPYpt2zAME+PxFUUDKmM0HmM+n8N1p5hMJghCIluvsSTCsiyxoLt8CYpGBI1GA7VaDZeXl1BVVebdXg99glg3TRPD4RCWZcFxbIS0QZqmSJLkGRSTVPX7fTRbLYyGI/mxyBkRCRKh0HVdaJomFbuU+74PXhSyKE+h+J4Ha2zDsRxYpoU4jBHOAlKnSnWe72FNx93bQ8SbmxsZ/wdlGrroGj0MbIYZ9+VHyTJBrXWO7qAD23GwfeK9V4sS1gOY78cwPjjgJ2vgO8BPc7ADFdMfHjY7ssPmn0X2Kl9UGDkB9DpV+CIFO6NOYQWiQQCn48AduIiTWJr5zsTrtxUO9QGYztDqNdBmTdieBX/uI6RO4RUnT1b3lhDEwjavQdFU8p0xRrPRRKtJd2bZ8KmvZdWyXLaTsIiAGD/Ffm0PhQ0ZBoaGi/YFfl3UqbIa2u02dLJTFEWYUcWF7wREvofIxY8ljuNHGyjH2jEOvY84GL7DUecIrMeoW1TpRYcqLDpJeFFgOnUJ5EUB8qZtW7KL9kolYV/rY3SlQ6N7bPc60HVdkggTi7+IgDw+f25iufaATOAPMzWpc+pXCcYAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/3cc43efb2e1cd279d858ccd6da8e553e/8ac56/driver-kernel-debug-022.webp 240w,\n/static/3cc43efb2e1cd279d858ccd6da8e553e/d3be9/driver-kernel-debug-022.webp 480w,\n/static/3cc43efb2e1cd279d858ccd6da8e553e/f2d53/driver-kernel-debug-022.webp 785w\"\n              sizes=\"(max-width: 785px) 100vw, 785px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/3cc43efb2e1cd279d858ccd6da8e553e/8ff5a/driver-kernel-debug-022.png 240w,\n/static/3cc43efb2e1cd279d858ccd6da8e553e/e85cb/driver-kernel-debug-022.png 480w,\n/static/3cc43efb2e1cd279d858ccd6da8e553e/cda19/driver-kernel-debug-022.png 785w\"\n            sizes=\"(max-width: 785px) 100vw, 785px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/3cc43efb2e1cd279d858ccd6da8e553e/cda19/driver-kernel-debug-022.png\"\n            alt=\"Search for a pool tag with !poolfind\"\n            title=\"Search for a pool tag with !poolfind\"\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>However, in many cases, searching for a pool tag with <code class=\"language-text\">!poolfind</code> takes an extremely long time.</p>\n<p>Also, although the details are unclear, I have seen scattered reports of debugger hangs and missed pool-tag detections, so searching for pool tags with <code class=\"language-text\">!poolfind</code> is not very efficient.</p>\n<p>Therefore, rather than searching for the pool tag, we will use PoolHitTag to detect a memory allocation that uses a specific pool tag, and identify the memory block address from the return value of the ExAllocatePoolWithTag function.</p>\n<h2 id=\"identify-the-memory-allocation-address-using-poolhittag\" style=\"position:relative;\"><a href=\"#identify-the-memory-allocation-address-using-poolhittag\" aria-label=\"identify the memory allocation address using poolhittag 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>Identify the Memory Allocation Address Using PoolHitTag</h2>\n<p>When performing live debugging, one way to identify the memory address associated with a specific pool tag name is to use PoolHitTag.<sup id=\"fnref-5\"><a href=\"#fn-5\" class=\"footnote-ref\">5</a></sup></p>\n<p>PoolHitTag can be configured with the <code class=\"language-text\">ed nt!poolhittag</code> command.</p>\n<p>For example, if you want to specify the pool tag name <code class=\"language-text\">flag</code>, use the four-character tag name reversed to match little-endian format, as in <code class=\"language-text\">ed nt!poolhittag 'galf'</code>.</p>\n<p>If the setting has been applied correctly, you can confirm that the specified pool tag name has been set by running the <code class=\"language-text\">db nt!poolhittag L4</code> command.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 725px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/567a7ccbceda95ad9550f3695717f788/a0209/driver-kernel-debug-023.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: 14.583333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAvklEQVQI1z2Oy2rCQBSG87BKER/Ap3LR2oXQvZUoXnBRS0zMJDNTkpiFKLmMJF8zwfbAB+fC+fgdoSUykXyfPc5SECrBKQo4nr7wvSMq9MlTTZZlKKWI45g0TTDG0LYtTdP8Y2dnspcMtprhMmC48BitBS8byXijmR4SPrrbp3/lXlQ8OokV1XVNWZYURdFTVVWP7Z13N+B1FfHmhsxWgvlOd/wwP1xY+DfcyLCOuwfTwDORTfKH3eV53sts/QJX5tvkl+jOZAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/567a7ccbceda95ad9550f3695717f788/8ac56/driver-kernel-debug-023.webp 240w,\n/static/567a7ccbceda95ad9550f3695717f788/d3be9/driver-kernel-debug-023.webp 480w,\n/static/567a7ccbceda95ad9550f3695717f788/92338/driver-kernel-debug-023.webp 725w\"\n              sizes=\"(max-width: 725px) 100vw, 725px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/567a7ccbceda95ad9550f3695717f788/8ff5a/driver-kernel-debug-023.png 240w,\n/static/567a7ccbceda95ad9550f3695717f788/e85cb/driver-kernel-debug-023.png 480w,\n/static/567a7ccbceda95ad9550f3695717f788/a0209/driver-kernel-debug-023.png 725w\"\n            sizes=\"(max-width: 725px) 100vw, 725px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/567a7ccbceda95ad9550f3695717f788/a0209/driver-kernel-debug-023.png\"\n            alt=\"Configure PoolHitTag\"\n            title=\"Configure PoolHitTag\"\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>Incidentally, to clear the PoolHitTag setting, use the <code class=\"language-text\">ed nt!poolhittag 0</code> command.</p>\n<p>After setting PoolHitTag, running topsecret.exe in the virtual machine causes the system to temporarily stop in the middle of the ExAllocateHeapPool function as shown below.</p>\n<p>At this time, you can confirm that the RAX register contains <code class=\"language-text\">flag</code>, which is the pool tag name you specified.</p>\n<p>Also, if you inspect the stack backtrace at the point where PoolHitTag is hit, you can confirm that DoPDriver is requesting the memory allocation associated with this pool tag.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 814px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/5f9e8856f83d697b88fb77f811dc941f/a4262/driver-kernel-debug-024.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: 59.166666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB70lEQVQoz5VTy27iQBD0//9FpIRLDjnmFq1WglOUkGBjMH6MMX6DMS9jbKC2u4EVV1oqjWfsqa6ubmtxkmI2m6Gua5zPZzRNgyzLsL/uT6cTjscjdpsd6qoGzhDw2Q383Q2aUivYjgWlFCaTCcIoxHg8xtiy4Ps+0jRFVVf41D/RN7/xRRhOTMRRJO/zPMctroRrOO5ECE3TRBiGcF1XSHnNsxzFpsDzn2d0/r7g6eMJXb2HslhisVhgs9mgLEupkEMIXc+Gr3whnDGh44hah1ZW2DYt8jhDFqVIwxRxmMCyLgnX6zWatpXShdBxSiIy6LKLEalSysPg9xeepzCkBBGVxr4aQ4OssSmRJclYXXFVeB/aaOSj3/+GYRgIggARKbRtG9NpQKQeeRqJClbLzWPvFHm3JqLD4YD9fo/tdovdbifQPO/il67rsGiN40TM5Y9v4Euskp/r+oCG1qqqhIDXe2jchHK5lMxDUsmesaLj8fS/c4+ElsznCKj1cVHAoFKDMBJv2LstKXgkZGyinx+k3a7g6/UV9mBA5jvUxcsc8kiw6iVVwYlWqxU1ZC57OSMht2chTHo9FG9vqN/fMe10sCCygi7l9LekaSbzxd6xh4yWRqS5299DCGMqOeHhpAOPlCjqNE8/jwV7+Wj8A+2JiC+wTRXoAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/5f9e8856f83d697b88fb77f811dc941f/8ac56/driver-kernel-debug-024.webp 240w,\n/static/5f9e8856f83d697b88fb77f811dc941f/d3be9/driver-kernel-debug-024.webp 480w,\n/static/5f9e8856f83d697b88fb77f811dc941f/f23e7/driver-kernel-debug-024.webp 814w\"\n              sizes=\"(max-width: 814px) 100vw, 814px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/5f9e8856f83d697b88fb77f811dc941f/8ff5a/driver-kernel-debug-024.png 240w,\n/static/5f9e8856f83d697b88fb77f811dc941f/e85cb/driver-kernel-debug-024.png 480w,\n/static/5f9e8856f83d697b88fb77f811dc941f/a4262/driver-kernel-debug-024.png 814w\"\n            sizes=\"(max-width: 814px) 100vw, 814px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/5f9e8856f83d697b88fb77f811dc941f/a4262/driver-kernel-debug-024.png\"\n            alt=\"Detect the allocation of pool tag flag with PoolHitTag\"\n            title=\"Detect the allocation of pool tag flag with PoolHitTag\"\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>Therefore, by issuing the <code class=\"language-text\">gu</code> command twice to execute until the function completes, you can inspect the registers immediately after DoPDriver executes the ExAllocatePoolWithTag function.</p>\n<p>From here, following the same steps as in the previous section, we were able to use the RAX register—which stores the return value—to identify the address of the memory block allocated with the pool tag <code class=\"language-text\">flag</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 799px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/e8d8ece0f759dca4aded34dad3a6c48f/76cea/driver-kernel-debug-025.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: 82.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAYAAADdRIy+AAAACXBIWXMAAA7DAAAOwwHHb6hkAAADIUlEQVQ4y3VUa4/SUBDt//8JZqNf1g/Ez5qYqHHdKLJAebRA3w9oKe1SWihbWBY4zoyy0U1sMrlt7+2ZM2fOVJkYEwRBgOl0isD3aZ1hPp+jqio8PDygrmtZq22F/X6P3X4n6/9CMU1LANI0RUbBwGVZ4vHxEZvNBtvtFmt6LvICh/0B5+MZh8NBPuYzkmS3ew5lMBxgPJ4gDENhapoGOp0uHMeB53m4z+5hezZu27doD9tQxyosx0I0i+BTRfMkEQKr1Qp5nkPRtD76/QEGgz663S6Bj9Fq3WE4HKKrdpEuMrTHbbx6/wrXn69x9eEK39XvCLwAruciiiKpKs0yAVY0nQAHAwHo9XowDAN3dwSoaVBVlT6IEVPoQx3G2IBlmNA1Xc6ORiPEcSxyMbuiKKDo2hD9HjHs9dFutwWES+YkzWYTEX0QkhStVgsqgajE+ndik+QxnzXnkjmUn2oTvRFlM3UpgXVxXRez2QyWZUnmjMph5lwev2etK2rWpSHshIsblNcf3+Dt17do3DYQzALc3y8JIEWSLARsvV5LKat8hSXtFcQiSzNJklBDfjtkIfdSsk/i5ssc9UMtFmE9FosFAW0k+9PTE/IiRxiHmGdzLMslynUpe+LPP37lVXwYhB58KuGSLY4jTCYGgaZS4ol8N56O8PrTG7xrvkPjRwN2bON4OIrJ2YsMeDqdwBcBuuQ5Fy75jnViQO4e+5CnaEOZKzK479EUhVNMg1A0ZnuxlptNJZWx2QXQcUxYtg3btsTg3Dk+zM3RdY2y16INJ3HJ6I5jwyPAhGThinia/r4UfaRBI1+5Mhm+HLYpQUhsmHFRlKTxUpKwBFHEXfZRk4an0/GfMeRQuFw+LAwIjNt/Ebyud8Lw73eXHwY3gdm9DGVGGZNkTgxt+tt4ZNSQvDYlhgGWxKwmgC39aQ6PeyroLKxOx6Os/PzyUiztJ/TON2idG4mxegtHb6Hf+gJr2KS9G9i0hkYH/qSDwFCR+DpiZ4BtVQrI+Xx+DmUuo+XDtkzMiB03IF0k0u2MDLug+w2be5XLCPLeKicvloV49CXgL7cs4lr8cIwQAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/e8d8ece0f759dca4aded34dad3a6c48f/8ac56/driver-kernel-debug-025.webp 240w,\n/static/e8d8ece0f759dca4aded34dad3a6c48f/d3be9/driver-kernel-debug-025.webp 480w,\n/static/e8d8ece0f759dca4aded34dad3a6c48f/a2266/driver-kernel-debug-025.webp 799w\"\n              sizes=\"(max-width: 799px) 100vw, 799px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/e8d8ece0f759dca4aded34dad3a6c48f/8ff5a/driver-kernel-debug-025.png 240w,\n/static/e8d8ece0f759dca4aded34dad3a6c48f/e85cb/driver-kernel-debug-025.png 480w,\n/static/e8d8ece0f759dca4aded34dad3a6c48f/76cea/driver-kernel-debug-025.png 799w\"\n            sizes=\"(max-width: 799px) 100vw, 799px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/e8d8ece0f759dca4aded34dad3a6c48f/76cea/driver-kernel-debug-025.png\"\n            alt=\"Identify the address of the allocated memory block\"\n            title=\"Identify the address of the allocated memory block\"\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>Identifying the allocation source of memory using PoolHitTag in this way is also useful when troubleshooting issues such as memory leaks in kernel space.</p>\n<h2 id=\"summary-of-chapter-6\" style=\"position:relative;\"><a href=\"#summary-of-chapter-6\" aria-label=\"summary of chapter 6 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 of Chapter 6</h2>\n<p>In this chapter, by using a kernel debugger for dynamic analysis, we were able to identify the correct image file name through brute force and determine the second Flag.</p>\n<p>Kernel debugging is a fairly high-barrier technique, because the memory space being debugged is enormous and it also requires a certain understanding of a difficult OS architecture.</p>\n<p>However, even simply using the minimum knowledge and basic commands introduced in this chapter can help you understand how the OS and drivers behave, and can also be applied to troubleshooting issues such as memory leaks in pool regions.</p>\n<p>Of course, real-world kernel debugging requires consideration of many factors not covered in this chapter, such as the context of processes and user sessions, the object manager, and the I/O manager, but I hope the contents of this book can serve as one stepping stone toward mastering those more advanced techniques.</p>\n<h2 id=\"afterword\" style=\"position:relative;\"><a href=\"#afterword\" aria-label=\"afterword 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>Afterword</h2>\n<p>Thank you very much for reading this book all the way to the end.</p>\n<p>In this book, following my previous work, “Magical WinDbg - Enjoying Windows Dump Analysis and Troubleshooting by Feel -,” I introduced techniques for live debugging of user-mode software and kernel drivers with WinDbg.</p>\n<p>There is a relatively rich body of knowledge about Windows user-mode debugging, but there is far less information about kernel debugging and the powerful scripting features available in the latest WinDbg.</p>\n<p>For that reason, I wrote this book with a particular focus on introducing analysis automation with JavaScript-based debugger scripts and information that can help readers get started with kernel debugging.</p>\n<p>I hope this book will be of some help to anyone who is becoming interested in WinDbg and Windows kernel debugging and wants to get started.</p>\n<p>Once again, thank you for reading this book.</p>\n<h2 id=\"links-to-each-chapter\" style=\"position:relative;\"><a href=\"#links-to-each-chapter\" aria-label=\"links to each chapter 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>Links to Each Chapter</h2>\n<ul>\n<li><a href=\"/magical-windbg-vol2-00-en\">Preface</a></li>\n<li><a href=\"/magical-windbg-vol2-01-en\">Chapter 1: Environment Setup</a></li>\n<li><a href=\"/magical-windbg-vol2-02-en\">Chapter 2: Surface Analysis of DoPClient and DoPDriver</a></li>\n<li><a href=\"/magical-windbg-vol2-03-en\">Chapter 3: Static Analysis of DoPClient</a></li>\n<li><a href=\"/magical-windbg-vol2-04-en\">Chapter 4: Dynamic Analysis of DoPClient</a></li>\n<li><a href=\"/magical-windbg-vol2-05-en\">Chapter 5: Static Analysis of DoPDriver</a></li>\n<li><a href=\"/magical-windbg-vol2-06-en\">Chapter 6: Dynamic Analysis of DoPDriver</a></li>\n</ul>\n<div class=\"footnotes\">\n<hr>\n<ol>\n<li id=\"fn-1\">\n<p>pa (step to address) <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/pa--step-to-address-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/pa—step-to-address-</a></p>\n<a href=\"#fnref-1\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-2\">\n<p>!poolused <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/-poolused\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/-poolused</a></p>\n<a href=\"#fnref-2\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-3\">\n<p>!pool <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/-pool\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/-pool</a></p>\n<a href=\"#fnref-3\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-4\">\n<p>!poolfind <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/-poolfind\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debuggercmds/-poolfind</a></p>\n<a href=\"#fnref-4\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-5\">\n<p>Finding a Kernel-Mode Memory Leak with the Kernel Debugger <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/using-the-kernel-debugger-to-find-a-kernel-mode-memory-leak\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/using-the-kernel-debugger-to-find-a-kernel-mode-memory-leak</a></p>\n<a href=\"#fnref-5\" class=\"footnote-backref\">↩</a>\n</li>\n</ol>\n</div>","fields":{"slug":"/magical-windbg-vol2-06-en","tagSlugs":["/tag/magical-win-dbg/","/tag/windows/","/tag/win-dbg/","/tag/english/"]},"frontmatter":{"date":"2024-05-26","description":"This is the web edition of Magical WinDbg 2 - Learn User-Mode & Kernel Debugging Through CTFs -, distributed at Tech Book Fest 16.","tags":["Magical WinDbg","Windows","WinDbg","English"],"title":"Magical WinDbg VOL.2 [Chapter 6: Dynamic Analysis of DoPDriver]","socialImage":{"publicURL":"/static/e9bfc3718fd53ab58623a496fc9a302e/magical-windbg-vol2.png"}}}},"pageContext":{"slug":"/magical-windbg-vol2-06-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}