<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>VIM - 标签 - 有价值炮灰</title>
        <link>https://evilpan.com/tags/vim/</link>
        <description>VIM - 标签 - 有价值炮灰</description>
        <generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>i@pppan.net (evilpan)</managingEditor>
            <webMaster>i@pppan.net (evilpan)</webMaster><copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright><lastBuildDate>Sat, 27 Apr 2024 12:40:00 &#43;0800</lastBuildDate><atom:link href="https://evilpan.com/tags/vim/" rel="self" type="application/rss+xml" /><item>
    <title>使用 VIM 进行代码审计</title>
    <link>https://evilpan.com/2024/04/27/audit-with-vim/</link>
    <pubDate>Sat, 27 Apr 2024 12:40:00 &#43;0800</pubDate><author>
        <name>evilpan</name>
    </author><guid>https://evilpan.com/2024/04/27/audit-with-vim/</guid>
    <description><![CDATA[<p>作为一个安服仔，代码审计是一项必备的技能。说好听点是 code review，说直白点就是看代码。说起代码审计这件事，大家都比较关注 source、sink、漏洞模式，而对于代码审计的工具却谈及甚少。因此，本文就来抛砖引玉，谈谈笔者自己的经验。</p>
<h1 id="写在前面" class="headerLink">
    <a href="#%e5%86%99%e5%9c%a8%e5%89%8d%e9%9d%a2" class="header-mark"></a>写在前面</h1><p>看代码和写代码有很大的一点不同，后者通常对于准确的代码补全是刚需，而看代码往往只需要跳转定义、交叉引用等一些基本功能。对于大部分人而言，看代码和写代码的一个相同之处就是使用 IDE 来看。</p>
<p>具体代码审计的习惯往往是因人而异的。有的人喜欢用 JetBrains 看，有的人喜欢用 VSCode 看，有的人喜欢用 SourceInsight 看，还有的人喜欢用 Notepad++ 来看。</p>
<p>此外，有一些通过本地构建代码索引并从浏览器阅读代码的方案，比如：</p>
<ul>
<li><a href="https://github.com/oracle/opengrok" target="_blank" rel="noopener noreferrer">https://github.com/oracle/opengrok</a></li>
<li><a href="https://github.com/livegrep/livegrep" target="_blank" rel="noopener noreferrer">https://github.com/livegrep/livegrep</a></li>
</ul>
<p>而对于一些大型的代码工程，通常官方或者社区也构建了一些在线的代码阅读网站，比如：</p>
<ul>
<li><a href="https://cs.android.com/" target="_blank" rel="noopener noreferrer">https://cs.android.com/</a> - Google Android 源码</li>
<li><a href="https://source.chromium.org/chromium" target="_blank" rel="noopener noreferrer">https://source.chromium.org/chromium</a> - Google Chrome 源码</li>
<li><a href="http://aospxref.com/" target="_blank" rel="noopener noreferrer">http://aospxref.com/</a> - Android 源码，基于 opengrok</li>
<li><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank" rel="noopener noreferrer">https://elixir.bootlin.com/linux/latest/source</a> - Linux 源码</li>
</ul>
<p>各种阅读代码的方法都有它们的优点，笔者大部分也都尝试过，但大部分时间还是喜欢用 VIM 来看。即便切换到其他 IDE，也习惯性先装个 VIM Binding 插件，总感觉不用 HJKL 移动就难受。</p>
<p>虽然笔者是 VIM 爱好者，但并不排斥其他的 IDE。对于一些依赖完整的项目，比如 Java Maven 工程，也会优先使用 IDEA 去进行阅读，充分利用现代 IDE 的语言支持。</p>
<h1 id="示例" class="headerLink">
    <a href="#%e7%a4%ba%e4%be%8b" class="header-mark"></a>示例</h1><p>VIM 的好处在于其本身只是一个文本编辑器，而不是完整的 IDE。很多时候我们审计的代码只是一些零散的 Broken Code，比如泄露的 iBoot 源码、某些 Jar 包反编译出来的代码等，面对这些代码很多 IDE 都无法做到完整的语言支持，进而也退化成了一个只能依赖 Ctrl+F 的文本编辑器，既然如此还不如选择自己喜欢的。</p>
<p>如图是最近刚放出来的 MS-DOS 4.0 的源代码，虽然都是汇编，但使用 VIM 依然可以识别出大部分的符号，并且很方便搜索跳转：</p>
<p><figure><a class="lightgallery" href="/img/2024-04-27-audit-with-vim/0.png" title="MS-DOS" data-thumbnail="/img/2024-04-27-audit-with-vim/0.png" data-sub-html="<h2>MS-DOS 4.0 源码</h2><p>MS-DOS</p>"><img  loading="lazy" src='/img/2024-04-27-audit-with-vim/0.png'   alt="MS-DOS"  ></a><figcaption class="image-caption">MS-DOS 4.0 源码</figcaption>
</figure></p>
<p>后文会简单介绍一下实现的细节。</p>
<h1 id="设计思路" class="headerLink">
    <a href="#%e8%ae%be%e8%ae%a1%e6%80%9d%e8%b7%af" class="header-mark"></a>设计思路</h1><p>作为一个笔者自用的代码审计小工具，一开始就有比较简单的设计目标：</p>
<ol>
<li>主要在 macOS 和 Linux 桌面环境和命令行环境使用，支持在服务器中使用；</li>
<li>支持大部分 VIM 衍生应用，比如 NEOVIM、VIM-GTK、MacVIM 等，支持自定义快捷键；</li>
<li>支持对大部分编程语言构建索引方便跳转，对于冷门的语言也支持快速的搜索功能；</li>
<li>实现对漏洞扫描工具输出的集成，比如 semgrep、CodeQL 以及 SARIF 的支持；</li>
</ol>
<p>对于前两个目标，我们只需要实现一个简单的 VIM 插件，并使用环境变量去触发这些快捷键的开启。因为代码审计本身大都只需要在“只读”模式下，因此很多 VIM 的编辑命令可以腾出来用作其他功能。</p>
<p>对于语言支持，目前选用的是 ctags 和 cscope 卧龙凤雏两兄弟。尽管年代久远，但实际效果还是不错的，许多商业工具实际上也是在此基础上进行优化。</p>
<p>对于工具集成，主要使用的是 VIM 的 <a href="https://vimdoc.sourceforge.net/htmldoc/quickfix.html" target="_blank" rel="noopener noreferrer">quickfix</a> 功能，即前面图片中下方区域。只需要针对特定工具的输出定义 errorformat 即可显示。然后使用快捷键映射 cnext/cprev 可以快速的在结果中进行跳转。</p>
<h2 id="依赖" class="headerLink">
    <a href="#%e4%be%9d%e8%b5%96" class="header-mark"></a>依赖</h2><p>要实现上面的功能，我们首选需要引入一些社区中的优秀插件作为依赖：</p>
<ul>
<li><a href="https://www.vim.org/scripts/script.php?script_id=273" target="_blank" rel="noopener noreferrer">Plug &lsquo;vim-scripts/taglist.vim&rsquo;</a> - 用于在左边显示符号信息；</li>
<li><a href="https://github.com/skywind3000/asyncrun.vim" target="_blank" rel="noopener noreferrer">Plug &lsquo;skywind3000/asyncrun.vim&rsquo;</a> - 在 VIM 中异步运行命令；</li>
</ul>
<p>如果只需要模糊搜索的支持，也可以引入神器 FZF：</p>
<ul>
<li>Plug &lsquo;junegunn/fzf&rsquo;</li>
<li>Plug &lsquo;junegunn/fzf.vim&rsquo;</li>
</ul>
<p>以及一些常用的 SHELL 命令行工具：</p>
<ul>
<li><a href="https://github.com/universal-ctags/ctags" target="_blank" rel="noopener noreferrer">ctags</a> - Universal Ctags；</li>
<li><a href="https://cscope.sourceforge.net/" target="_blank" rel="noopener noreferrer">cscope</a> - 查找代码定义，符号；</li>
<li><a href="https://github.com/BurntSushi/ripgrep" target="_blank" rel="noopener noreferrer">ripgrep</a> - Rust 实现的 grep 搜索；</li>
<li><a href="https://github.com/junegunn/fzf" target="_blank" rel="noopener noreferrer">fzf</a> - 模糊搜索；</li>
</ul>
<h2 id="构建索引" class="headerLink">
    <a href="#%e6%9e%84%e5%bb%ba%e7%b4%a2%e5%bc%95" class="header-mark"></a>构建索引</h2><p>通常使用 ctags 和 cscope 构建索引的过程如下：</p>
<div class="code-block highlight is-open show-line-numbers  tw-group tw-my-2">
  <div class="
    
    tw-flex 
    tw-flex-row
    tw-flex-1 
    tw-justify-between 
    tw-w-full tw-bg-bgColor-secondary
    ">      
    <button 
      class="
        code-block-button
        tw-mx-2 
        tw-flex
        tw-flex-row
        tw-flex-1"
      aria-hidden="true">
          <div class="group-[.is-open]:tw-rotate-90 tw-transition-[transform] tw-duration-500 tw-ease-in-out print:!tw-hidden tw-w-min tw-h-min tw-my-1 tw-mx-1"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"/></svg></div>
          <p class="tw-select-none !tw-my-1">sh</p>
      </button>

   <div class="tw-flex">
      <button 
        class="
          line-number-button
          tw-mx-2 
          tw-hidden 
          group-[.is-open]:tw-block 
          group-[.show-line-numbers]:tw-text-fgColor-link 
          print:!tw-hidden" 
        title="Toggle line numbers"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M61.77 401l17.5-20.15a19.92 19.92 0 0 0 5.07-14.19v-3.31C84.34 356 80.5 352 73 352H16a8 8 0 0 0-8 8v16a8 8 0 0 0 8 8h22.83a157.41 157.41 0 0 0-11 12.31l-5.61 7c-4 5.07-5.25 10.13-2.8 14.88l1.05 1.93c3 5.76 6.29 7.88 12.25 7.88h4.73c10.33 0 15.94 2.44 15.94 9.09 0 4.72-4.2 8.22-14.36 8.22a41.54 41.54 0 0 1-15.47-3.12c-6.49-3.88-11.74-3.5-15.6 3.12l-5.59 9.31c-3.72 6.13-3.19 11.72 2.63 15.94 7.71 4.69 20.38 9.44 37 9.44 34.16 0 48.5-22.75 48.5-44.12-.03-14.38-9.12-29.76-28.73-34.88zM496 224H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-160H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16zm0 320H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM16 160h64a8 8 0 0 0 8-8v-16a8 8 0 0 0-8-8H64V40a8 8 0 0 0-8-8H32a8 8 0 0 0-7.14 4.42l-8 16A8 8 0 0 0 24 64h8v64H16a8 8 0 0 0-8 8v16a8 8 0 0 0 8 8zm-3.91 160H80a8 8 0 0 0 8-8v-16a8 8 0 0 0-8-8H41.32c3.29-10.29 48.34-18.68 48.34-56.44 0-29.06-25-39.56-44.47-39.56-21.36 0-33.8 10-40.46 18.75-4.37 5.59-3 10.84 2.8 15.37l8.58 6.88c5.61 4.56 11 2.47 16.12-2.44a13.44 13.44 0 0 1 9.46-3.84c3.33 0 9.28 1.56 9.28 8.75C51 248.19 0 257.31 0 304.59v4C0 316 5.08 320 12.09 320z"/></svg></button>

      <button 
        class="
          wrap-code-button
          tw-select-none 
          tw-mx-2 
          tw-hidden 
          group-[.is-open]:tw-block 
          group-[.is-wrap]:tw-text-fgColor-link 
          print:!tw-hidden" 
        title="Toggle code wrap"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"/></svg></button>
      
      <button 
        class="
          copy-code-button
          tw-select-none
          tw-mx-2 
          tw-hidden
          group-[.is-open]:tw-block
          hover:tw-text-fgColor-link 
          print:!tw-hidden"
        title="Copy code">
          <span class="copy-icon tw-block"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M433.941 65.941l-51.882-51.882A48 48 0 0 0 348.118 0H176c-26.51 0-48 21.49-48 48v48H48c-26.51 0-48 21.49-48 48v320c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48v-48h80c26.51 0 48-21.49 48-48V99.882a48 48 0 0 0-14.059-33.941zM266 464H54a6 6 0 0 1-6-6V150a6 6 0 0 1 6-6h74v224c0 26.51 21.49 48 48 48h96v42a6 6 0 0 1-6 6zm128-96H182a6 6 0 0 1-6-6V54a6 6 0 0 1 6-6h106v88c0 13.255 10.745 24 24 24h88v202a6 6 0 0 1-6 6zm6-256h-64V48h9.632c1.591 0 3.117.632 4.243 1.757l48.368 48.368a6 6 0 0 1 1.757 4.243V112z"/></svg></span>
          <span class="check-icon tw-hidden"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"/></svg></span>
      </button>
        
      <button 
        class="
          tw-select-none 
          tw-mx-2 
          tw-block 
          group-[.is-open]:tw-hidden 
          print:!tw-hidden" 
        disabled
        aria-hidden="true"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M328 256c0 39.8-32.2 72-72 72s-72-32.2-72-72 32.2-72 72-72 72 32.2 72 72zm104-72c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72zm-352 0c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72z"/></svg></button>
    </div>
  </div>
  <pre style="counter-reset: codeblock;" class="tw-block tw-m-0 tw-p-0"><code 
    id="codeblock-id-1" 
    class="
      chroma 
      !tw-block 
      tw-p-0
      tw-m-0
      tw-transition-[max-height] 
      tw-duration-500 
      tw-ease-in-out 
      group-[.is-closed]:!tw-max-h-0 
      group-[.is-wrap]:tw-text-wrap
      tw-overflow-y-hidden
      tw-overflow-x-auto
      tw-scrollbar-thin
      "><span class="line"><span class="cl"><span class="nb">cd</span> src
</span></span><span class="line"><span class="cl">ctags --fields<span class="o">=</span>+l
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">find . -name <span class="s2">&#34;*.c&#34;</span> -o -name <span class="s2">&#34;*.cpp&#34;</span> -o -name <span class="s2">&#34;*.h&#34;</span> &gt; cscope.files
</span></span><span class="line"><span class="cl">cscope -b -q -k</span></span></code></pre>
</div>
<p>不过这会在源码目录生成 <code>.tags</code> 和 <code>cscope.out</code> 等索引文件。虽然我们可以指定在其他地方生成数据库，但是每次都执行一遍总归是比较繁琐，因此笔者写了一个简单的 Python 脚本用于管理代码对应的数据库。</p>
<p>由于数据库保存到非标准的位置，那么就需要在 VIM Script 中指定对应的 cscope 和 ctags 路径，顺便也就定义一些快捷键了。</p>
<p>这么一来二去，也就有了这个项目：<a href="https://github.com/evilpan/audit.vim" target="_blank" rel="noopener noreferrer">audit.vim</a>。</p>
<h1 id="auditvim" class="headerLink">
    <a href="#auditvim" class="header-mark"></a>audit.vim</h1><p>该项目定义为一个基于 VIM 的轻量级的代码审计工具，为了尊重每个人不同的快捷键习惯，因此采用了自定义安装的方式，即只需将 <code>plugin/audit.vim</code> 放到 <code>$HOME/.vim/plugin</code> 中，额外的插件可以根据个人需求进行安装，比如使用 VimPlug 的可以直接把 <code>Plug</code> 写到自己的 vimrc 中。</p>
<p>配套的 <code>avim.py</code> 脚本用于管理代码的索引文件：</p>
<div class="code-block highlight is-open show-line-numbers  tw-group tw-my-2">
  <div class="
    
    tw-flex 
    tw-flex-row
    tw-flex-1 
    tw-justify-between 
    tw-w-full tw-bg-bgColor-secondary
    ">      
    <button 
      class="
        code-block-button
        tw-mx-2 
        tw-flex
        tw-flex-row
        tw-flex-1"
      aria-hidden="true">
          <div class="group-[.is-open]:tw-rotate-90 tw-transition-[transform] tw-duration-500 tw-ease-in-out print:!tw-hidden tw-w-min tw-h-min tw-my-1 tw-mx-1"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"/></svg></div>
          <p class="tw-select-none !tw-my-1">sh</p>
      </button>

   <div class="tw-flex">
      <button 
        class="
          line-number-button
          tw-mx-2 
          tw-hidden 
          group-[.is-open]:tw-block 
          group-[.show-line-numbers]:tw-text-fgColor-link 
          print:!tw-hidden" 
        title="Toggle line numbers"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M61.77 401l17.5-20.15a19.92 19.92 0 0 0 5.07-14.19v-3.31C84.34 356 80.5 352 73 352H16a8 8 0 0 0-8 8v16a8 8 0 0 0 8 8h22.83a157.41 157.41 0 0 0-11 12.31l-5.61 7c-4 5.07-5.25 10.13-2.8 14.88l1.05 1.93c3 5.76 6.29 7.88 12.25 7.88h4.73c10.33 0 15.94 2.44 15.94 9.09 0 4.72-4.2 8.22-14.36 8.22a41.54 41.54 0 0 1-15.47-3.12c-6.49-3.88-11.74-3.5-15.6 3.12l-5.59 9.31c-3.72 6.13-3.19 11.72 2.63 15.94 7.71 4.69 20.38 9.44 37 9.44 34.16 0 48.5-22.75 48.5-44.12-.03-14.38-9.12-29.76-28.73-34.88zM496 224H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-160H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16zm0 320H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM16 160h64a8 8 0 0 0 8-8v-16a8 8 0 0 0-8-8H64V40a8 8 0 0 0-8-8H32a8 8 0 0 0-7.14 4.42l-8 16A8 8 0 0 0 24 64h8v64H16a8 8 0 0 0-8 8v16a8 8 0 0 0 8 8zm-3.91 160H80a8 8 0 0 0 8-8v-16a8 8 0 0 0-8-8H41.32c3.29-10.29 48.34-18.68 48.34-56.44 0-29.06-25-39.56-44.47-39.56-21.36 0-33.8 10-40.46 18.75-4.37 5.59-3 10.84 2.8 15.37l8.58 6.88c5.61 4.56 11 2.47 16.12-2.44a13.44 13.44 0 0 1 9.46-3.84c3.33 0 9.28 1.56 9.28 8.75C51 248.19 0 257.31 0 304.59v4C0 316 5.08 320 12.09 320z"/></svg></button>

      <button 
        class="
          wrap-code-button
          tw-select-none 
          tw-mx-2 
          tw-hidden 
          group-[.is-open]:tw-block 
          group-[.is-wrap]:tw-text-fgColor-link 
          print:!tw-hidden" 
        title="Toggle code wrap"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"/></svg></button>
      
      <button 
        class="
          copy-code-button
          tw-select-none
          tw-mx-2 
          tw-hidden
          group-[.is-open]:tw-block
          hover:tw-text-fgColor-link 
          print:!tw-hidden"
        title="Copy code">
          <span class="copy-icon tw-block"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M433.941 65.941l-51.882-51.882A48 48 0 0 0 348.118 0H176c-26.51 0-48 21.49-48 48v48H48c-26.51 0-48 21.49-48 48v320c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48v-48h80c26.51 0 48-21.49 48-48V99.882a48 48 0 0 0-14.059-33.941zM266 464H54a6 6 0 0 1-6-6V150a6 6 0 0 1 6-6h74v224c0 26.51 21.49 48 48 48h96v42a6 6 0 0 1-6 6zm128-96H182a6 6 0 0 1-6-6V54a6 6 0 0 1 6-6h106v88c0 13.255 10.745 24 24 24h88v202a6 6 0 0 1-6 6zm6-256h-64V48h9.632c1.591 0 3.117.632 4.243 1.757l48.368 48.368a6 6 0 0 1 1.757 4.243V112z"/></svg></span>
          <span class="check-icon tw-hidden"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"/></svg></span>
      </button>
        
      <button 
        class="
          tw-select-none 
          tw-mx-2 
          tw-block 
          group-[.is-open]:tw-hidden 
          print:!tw-hidden" 
        disabled
        aria-hidden="true"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M328 256c0 39.8-32.2 72-72 72s-72-32.2-72-72 32.2-72 72-72 72 32.2 72 72zm104-72c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72zm-352 0c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72z"/></svg></button>
    </div>
  </div>
  <pre style="counter-reset: codeblock;" class="tw-block tw-m-0 tw-p-0"><code 
    id="codeblock-id-2" 
    class="
      chroma 
      !tw-block 
      tw-p-0
      tw-m-0
      tw-transition-[max-height] 
      tw-duration-500 
      tw-ease-in-out 
      group-[.is-closed]:!tw-max-h-0 
      group-[.is-wrap]:tw-text-wrap
      tw-overflow-y-hidden
      tw-overflow-x-auto
      tw-scrollbar-thin
      "><span class="line"><span class="cl">$ avim.py -h
</span></span><span class="line"><span class="cl">usage: avim.py <span class="o">[</span>-h<span class="o">]</span> <span class="o">[</span>-g<span class="o">]</span> <span class="o">{</span>make,rm,info,open,lv<span class="o">}</span> ...
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">lightweight code audit system with vim
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">positional arguments:
</span></span><span class="line"><span class="cl">  <span class="o">{</span>make,rm,info,open,lv<span class="o">}</span>
</span></span><span class="line"><span class="cl">                        sub actions
</span></span><span class="line"><span class="cl">    make                create new audit session from current directory
</span></span><span class="line"><span class="cl">    rm                  remove audit session
</span></span><span class="line"><span class="cl">    info                show info of audit sessions
</span></span><span class="line"><span class="cl">    open                vim wrapper to open files
</span></span><span class="line"><span class="cl">    lv                  live grep without tags and cscope
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">options:
</span></span><span class="line"><span class="cl">  -h, --help            show this <span class="nb">help</span> message and <span class="nb">exit</span>
</span></span><span class="line"><span class="cl">  -g                    use gvim instead of vim</span></span></code></pre>
</div>
<p>索引文件统一放在 <code>$HOME/audit.vim</code> 目录中，防止污染目标源码。同时 <code>open</code> 会以 READ-ONLY 模式打开 VIM 并设置好对应的 ctags 和 cscope 路径。目前为了防止审计超大型代码时候引入过多的无效文件，使用的是文件后缀白名单模式。虽然在 tag 生成方面可能有所遗漏，但搜索还是全量的，在实践中效果还算不错。</p>
<p>如果你平时审计过程中有沉淀过一些漏洞模式，比如 semgrep 规则，那么可以很容易使用 AsyncRun 的方式去进行快速扫描和漏洞验证，感兴趣的可以自行尝试。</p>
<p><img class="tw-inline" loading="lazy" src='/img/2024-04-27-audit-with-vim/1.png'   alt="linux.png"  ></p>
<h1 id="最后" class="headerLink">
    <a href="#%e6%9c%80%e5%90%8e" class="header-mark"></a>最后</h1><p>好了这就是本期灌水的所有内容了，你们一般都习惯用什么方式来进行代码审计呢，快点在评论区跟小编一起聊聊吧！(逃</p>
<hr>
<blockquote>
  <p><strong>版权声明</strong>: 自由转载-非商用-非衍生-保持署名 (<a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener noreferrer">CC 4.0 BY-SA</a>)<br>
<strong>原文地址</strong>: <a href="https://evilpan.com/2024/04/27/audit-with-vim/" target="_blank" rel="noopener noreferrer">https://evilpan.com/2024/04/27/audit-with-vim/</a><br>
<strong>微信订阅</strong>: <strong>『<a href="http://t.evilpan.com/qrcode.jpg" target="_blank" rel="noopener noreferrer">有价值炮灰</a>』</strong><br>
&ndash; <em>TO BE CONTINUED</em>.</p>
</blockquote><hr>]]></description>
</item></channel>
</rss>
