<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>ASLR - 标签 - Refrain69 的博客</title><link>https://blog.refrain69.com/tags/aslr/</link><description>ASLR - 标签 - Refrain69 的博客</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>contact@refrain69.com (Refrain69)</managingEditor><webMaster>contact@refrain69.com (Refrain69)</webMaster><copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright><lastBuildDate>Sat, 27 Sep 2025 17:45:20 +0800</lastBuildDate><atom:link href="https://blog.refrain69.com/tags/aslr/" rel="self" type="application/rss+xml"/><item><title>PE 文件基址及其随机化</title><link>https://blog.refrain69.com/posts/pe-base-address-and-aslr/</link><pubDate>Sat, 27 Sep 2025 17:45:20 +0800</pubDate><author><name>Refrain69</name></author><guid>https://blog.refrain69.com/posts/pe-base-address-and-aslr/</guid><description><![CDATA[<h2 id="pe-文件基址" class="headerLink">
    <a href="#pe-%e6%96%87%e4%bb%b6%e5%9f%ba%e5%9d%80" class="header-mark"></a>1 PE 文件基址</h2><p>PE (Portable Executable) 文件是 Windows 操作系统中可执行文件和动态链接库 (DLL) 的标准格式。在操作系统加载 PE 文件时，它会将文件映射到进程的虚拟地址空间中。PE 文件的基址 (Base Address) 是指操作系统尝试将该文件加载到内存中的首选地址。一般来说，在 Windows 系统中，<code>x86</code> 架构的 EXE 文件默认基址是 <code>0x00400000</code>，而 <code>x64</code> 架构的 EXE 文件默认基址是 <code>0x140000000</code>。</p>
<h2 id="aslr" class="headerLink">
    <a href="#aslr" class="header-mark"></a>2 ASLR</h2><p>ASLR (Address Space Layout Randomization) 是一种安全技术，用于随机化进程的内存地址布局，以防止攻击者利用已知的内存地址进行攻击。通过随机化基址，ASLR 使得攻击者难以预测关键数据结构和代码的位置，从而增加了攻击的难度。详见 <a href="https://en.wikipedia.org/wiki/Address_space_layout_randomization" target="_blank" rel="noopener noreferrer">Wikipedia</a>。</p>
<p>然而，对于逆向分析和调试来说，这一机制导致每次重启调试器时，PE 文件的基址都会发生变化。而一些反编译工具会采用默认基址进行分析，导致对比分析出现不便。</p>
<h2 id="关闭-aslr" class="headerLink">
    <a href="#%e5%85%b3%e9%97%ad-aslr" class="header-mark"></a>3 关闭 ASLR</h2><h3 id="原理" class="headerLink">
    <a href="#%e5%8e%9f%e7%90%86" class="header-mark"></a>3.1 原理</h3><p>PE 文件格式中，有一个标志位 <code>IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE</code>，用于指示操作系统是否启用 ASLR。如果该标志位被置零，操作系统将不会随机化该 PE 文件的基址，而是使用其默认基址进行加载。</p>
<p>该标志位位于 PE 文件的可选头 (Optional Header) 中的 <code>DllCharacteristics</code> 字段。这个字段是一个 16 位的位掩码，每一位代表不同的特性。可以通过将该 ushort 值与 <code>0x0040</code> 进行按位与操作来检查该标志位是否被设置。</p>
<h3 id="方法" class="headerLink">
    <a href="#%e6%96%b9%e6%b3%95" class="header-mark"></a>3.2 方法</h3><h4 id="方法一修改-pe-文件标志位" class="headerLink">
    <a href="#%e6%96%b9%e6%b3%95%e4%b8%80%e4%bf%ae%e6%94%b9-pe-%e6%96%87%e4%bb%b6%e6%a0%87%e5%bf%97%e4%bd%8d" class="header-mark"></a>3.2.1 方法一：修改 PE 文件标志位</h4><p>使用任何 PE 编辑工具或十六进制编辑器，打开目标 PE 文件，找到并修改 <code>IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE</code> 标志位。</p>
<h5 id="使用-010-editor" class="headerLink">
    <a href="#%e4%bd%bf%e7%94%a8-010-editor" class="header-mark"></a>3.2.1.1 使用 010 Editor</h5><ol>
<li>
<p>打开 010 Editor，加载目标 PE 文件。</p>
</li>
<li>
<p>运行 <code>EXE.bt</code> 模板，定位到 <code>Optional Header</code> 部分，找到 <code>DllCharacteristics</code> 字段下的 <code>IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE</code> 位。</p>
<figure><a class="lightgallery" href="/posts/pe-base-address-and-aslr/1.png" title="IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 位置" data-thumbnail="/posts/pe-base-address-and-aslr/1.png" data-sub-html="<h2>IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 位置</h2>"><img  loading="lazy" src='/posts/pe-base-address-and-aslr/1.png' srcset="/posts/pe-base-address-and-aslr/1_hu_75462b9dde052a6.webp 800w, /posts/pe-base-address-and-aslr/1_hu_9d22c779013562ff.webp 1200w, /posts/pe-base-address-and-aslr/1_hu_b23e5853d766be02.webp 1600w" sizes="auto" alt="IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 位置" height="1466" width="1403"></a><figcaption class="image-caption">IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 位置</figcaption>
       </figure>
</li>
<li>
<p>将其改为 <code>0</code>，保存。</p>
</li>
</ol>
<h4 id="方法二修改调试器设置" class="headerLink">
    <a href="#%e6%96%b9%e6%b3%95%e4%ba%8c%e4%bf%ae%e6%94%b9%e8%b0%83%e8%af%95%e5%99%a8%e8%ae%be%e7%bd%ae" class="header-mark"></a>3.2.2 方法二：修改调试器设置</h4><p>在 <code>x64dbg</code> 调试器中，选择 <code>选项</code> -&gt; <code>引擎</code>，勾选 <code>禁用 ASLR</code> 选项。</p>
<div class="details admonition note open">
    <div class="details-summary admonition-title">
        <span class="icon"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M497.9 142.1l-46.1 46.1c-4.7 4.7-12.3 4.7-17 0l-111-111c-4.7-4.7-4.7-12.3 0-17l46.1-46.1c18.7-18.7 49.1-18.7 67.9 0l60.1 60.1c18.8 18.7 18.8 49.1 0 67.9zM284.2 99.8L21.6 362.4.4 483.9c-2.9 16.4 11.4 30.6 27.8 27.8l121.5-21.3 262.6-262.6c4.7-4.7 4.7-12.3 0-17l-111-111c-4.8-4.7-12.4-4.7-17.1 0zM124.1 339.9c-5.5-5.5-5.5-14.3 0-19.8l154-154c5.5-5.5 14.3-5.5 19.8 0s5.5 14.3 0 19.8l-154 154c-5.5 5.5-14.3 5.5-19.8 0zM88 424h48v36.3l-64.5 11.3-31.1-31.1L51.7 376H88v48z"/></svg></span>注意<span class="details-icon"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"/></svg></span>
    </div>
    <div class="details-content">
        <div class="admonition-content">修改该设置后可能报错！如出现任何问题，请使用方法一。</div></div></div>
]]></description></item></channel></rss>