Loading [MathJax]/jax/output/SVG/jax.js
  • 中国精品科技期刊
  • CCF推荐A类中文期刊
  • 计算领域高质量科技期刊T1类
高级检索

基于控制流和数据流分析的内存拷贝类函数识别技术

尹小康, 芦斌, 蔡瑞杰, 朱肖雅, 杨启超, 刘胜利

尹小康, 芦斌, 蔡瑞杰, 朱肖雅, 杨启超, 刘胜利. 基于控制流和数据流分析的内存拷贝类函数识别技术[J]. 计算机研究与发展, 2023, 60(2): 326-340. DOI: 10.7544/issn1000-1239.202110990
引用本文: 尹小康, 芦斌, 蔡瑞杰, 朱肖雅, 杨启超, 刘胜利. 基于控制流和数据流分析的内存拷贝类函数识别技术[J]. 计算机研究与发展, 2023, 60(2): 326-340. DOI: 10.7544/issn1000-1239.202110990
Yin Xiaokang, Lu Bin, Cai Ruijie, Zhu Xiaoya, Yang Qichao, Liu Shengli. Memory Copy Function Identification Technique with Control Flow and Data Flow Analysis[J]. Journal of Computer Research and Development, 2023, 60(2): 326-340. DOI: 10.7544/issn1000-1239.202110990
Citation: Yin Xiaokang, Lu Bin, Cai Ruijie, Zhu Xiaoya, Yang Qichao, Liu Shengli. Memory Copy Function Identification Technique with Control Flow and Data Flow Analysis[J]. Journal of Computer Research and Development, 2023, 60(2): 326-340. DOI: 10.7544/issn1000-1239.202110990
尹小康, 芦斌, 蔡瑞杰, 朱肖雅, 杨启超, 刘胜利. 基于控制流和数据流分析的内存拷贝类函数识别技术[J]. 计算机研究与发展, 2023, 60(2): 326-340. CSTR: 32373.14.issn1000-1239.202110990
引用本文: 尹小康, 芦斌, 蔡瑞杰, 朱肖雅, 杨启超, 刘胜利. 基于控制流和数据流分析的内存拷贝类函数识别技术[J]. 计算机研究与发展, 2023, 60(2): 326-340. CSTR: 32373.14.issn1000-1239.202110990
Yin Xiaokang, Lu Bin, Cai Ruijie, Zhu Xiaoya, Yang Qichao, Liu Shengli. Memory Copy Function Identification Technique with Control Flow and Data Flow Analysis[J]. Journal of Computer Research and Development, 2023, 60(2): 326-340. CSTR: 32373.14.issn1000-1239.202110990
Citation: Yin Xiaokang, Lu Bin, Cai Ruijie, Zhu Xiaoya, Yang Qichao, Liu Shengli. Memory Copy Function Identification Technique with Control Flow and Data Flow Analysis[J]. Journal of Computer Research and Development, 2023, 60(2): 326-340. CSTR: 32373.14.issn1000-1239.202110990

基于控制流和数据流分析的内存拷贝类函数识别技术

基金项目: 科技委基础加强重点项目(2019-JCJQ-ZD-113)
详细信息
    作者简介:

    尹小康: 1993年生.博士.主要研究方向为网络安全、二进制代码分析和机器学习

    芦斌: 1982年生.博士,副教授.主要研究方向为信息安全和机器学习

    蔡瑞杰: 1990年生.硕士,讲师.主要研究方向为网络安全、二进制代码分析和漏洞挖掘

    朱肖雅: 1996年生.硕士研究生.主要研究方向为二进制代码分析和机器学习

    杨启超: 1992年生.硕士,讲师.主要研究方向为网络对抗和网络安全

    刘胜利: 1973年生.博士,教授,博士生导师.主要研究方向为网络攻击检测和网络基础设施安全

    通讯作者:

    刘胜利(mr_shengliliu@163.com

  • 中图分类号: TP309

Memory Copy Function Identification Technique with Control Flow and Data Flow Analysis

Funds: This work was supported by the Foundation Strengthening Key Project of Science & Technology Commission (2019-JCJQ-ZD-113).
  • 摘要:

    内存错误漏洞仍是当前网络攻击中造成危害最严重的漏洞之一.内存错误漏洞的产生往往与对内存拷贝类函数的误用有关.目前针对内存拷贝类函数的识别主要借助于符号表和代码特征模式匹配,具有较高的误报率和漏报率,并且适用性较差.提出了一种内存拷贝类函数识别技术CPYFinder(copy function finder).该技术在内存拷贝类函数控制流特征的基础上,将二进制代码转换为中间语言表示VEX IR(intermediate representation)进行数据流的构建和分析,根据内存拷贝类函数在数据流上的特征进行识别.该技术能够在较低的运行时间下对多种指令集架构(x86,ARM,MIPS,PowerPC)的二进制程序中的内存拷贝类函数进行识别.实验结果表明,相比于最新的工作BootStomp和SaTC,CPYFinder在对内存拷贝类函数识别上具有更好的表现,在精准率和召回率上得到更好的平衡,并且运行时间与SaTC几乎相等,仅相当于BootStomp耗时的19%.此外,CPYFinder在漏洞函数识别上也具有更好的表现.

    Abstract:

    Memory error vulnerability is still one of the most widely used and harmful vulnerabilities in current cyber-attacks, whose timely discovery and repair in binary programs bear great value in preventing cyber-attacks. Memory error vulnerabilities are often associated with the misuse of memory copy functions. However, the current identification techniques of memory copy functions mainly rely on the matching of symbol tables and code feature pattern, which have high false positive and false negative rates and poor applicability, and there are still many problems to be solved. To address the above problems, we propose a memory copy function identification technology CPYFinder, based on the control flow of memory copy functions. CPYFinder lifts the binary code into the VEX IR (Intermediate Representation) code to construct and analyze the data flow, and identifies binary code according to the pattern of the memory copy function on the data flow. This method can identify the memory copy functions in stripped binary executables of various instruction set architectures (i.e. x86, ARM, MIPS and PowerPC) in a short runtime. Experimental results show that CPYFinder has better performance in identifying memory copy functions in C libraries and user-defined implementations. Compared with the state-of-the-art works BootStomp and SaTC, CPYFinder gets a better balance between precision and recall, and has equal time consumption compared with SaTC and its runtime only amounts to 19% of BootStomp. In addition, CPYFinder also has better performance in vulnerability function identification.

  • 国密SM4算法[1]是一种常用的分组密码算法,广泛应用于数据保护、加密通信等领域. SM4算法常见工作模式有ECB(electronic codebook),CBC(cipher block chaining)等,对于相同的明文块,ECB模式下会产生完全相同的密文,而在CBC模式下,当前的明文块会与前一块的密文异或后进行运算. 因此,即使是完全相同的明文输入也可能会有完全不同的密文输出. 相比于ECB模式,CBC模式提供了更高的安全性和抵抗攻击的能力,有着更高的应用需求. 提高SM4算法在CBC模式下的性能,对于在边缘设备中使用SM4算法是至关重要的. 但是,在CBC模式下存在着难以提高吞吐率的问题:每组的输入必须等待前一组运算结束后才能获得,因而难以使用流水线方法提升吞吐率.

    文献[2]中提到了一种改进方法,将电路中的S盒以外的其他逻辑结构进行预计算,并把预计算的结果与S盒进行融合构成新的查找表,从而提高SM4算法在CBC模式下吞吐率. 本文基于此工作进一步优化了S盒的表示,并针对轮函数的迭代过程进行了优化,最终减少了轮函数关键路径上的2次异或运算,有效提高了算法的性能.

    本文的设计针对CBC模式下的SM4算法,在TSMC 40 nm,SMIC 55 nm工艺下,使用Synopsys Design Compiler分别进行了ASIC综合. 综合结果显示,本文所提出的设计在CBC模式下的吞吐率达到了4.2 Gb/s,同时单位面积吞吐量达到了129.4 Gb·s−1·mm−2,明显优于已发表的类似设计. 这些结果表明本文所提出的化简方法在改进SM4算法性能方面具有很大的潜力.

    本文的结构为:首先介绍了SM4算法及其在CBC模式下存在的性能瓶颈问题. 然后,详细描述了本文提出的2个化简方法,并解释了它们在轮函数迭代和S盒置换过程中的作用. 接下来,介绍了实验设计并给出了实验结果分析和对比. 最后,对进一步改进和应用的方向进行了展望.

    SM4算法是一种对称密钥密码算法,被广泛应用于数据加密和保护领域,它是中国密码算法的标准之一,具有较高的安全性和良好的性能.

    SM4采用了分组密码的设计思想,将明文数据划分为128 b的数据块,并通过密钥对每个数据块进行加密和解密操作. 对单组数据进行加解密的流程如图1所示,分为密钥扩展算法和加解密算法2部分. 图1中的FK是系统预设的参数,与用户密钥进行异或运算后作为密钥扩展算法的输入. 加解密算法接受密钥扩展算法产生的32轮轮密钥rki对明文进行加解密,最后经反序变换输出. 加解密使用的是同一套计算流程,唯一的区别是解密时使用轮密钥的顺序与加密过程相反.

    图  1  SM4算法工作流程
    Figure  1.  Workflow of SM4 algorithm

    密钥扩展算法和加解密算法2部分均由32次轮函数迭代构成,整体结构均采用4路并行的Feistel结构,在计算过程中,以128 b数据为输入、128 b数据为输出,其内部的运算逻辑如图2所示. 输出中的前96 b数据等于输入中的后96 b数据,输出后的32 b数据通过轮函数运算产生.

    图  2  4路并行的Feistel结构
    Figure  2.  Four parallel Feistel structure

    在密钥扩展算法中使用的密钥是算法给定的固定密钥,记作cki. 在加解密算法中使用的密钥是由密钥扩展算法通过用户给的密钥扩展出来的轮密钥,记作rki.

    SM4密钥扩展算法结构如图3所示,密钥扩展的主要过程包括32轮密钥扩展的轮函数,其中,密钥为128 b,FK为SM4标准中规定的一个128 b常数. 二者异或后的值将会作为密钥扩展轮函数的首轮输入,并通过一个选择器进行循环迭代,总计迭代32轮产生32个轮密钥.

    图  3  SM4的密钥扩展算法结构
    Figure  3.  Key expansion algorithm structure of SM4

    设用户输入的密钥为MK,则该密钥对应的32轮轮密钥可以按照式(1)求出:

    {(k0,k1,k2,k3)=MKFK,ki+4=kiF(ki+1ki+2ki+3cki),rki=ki+4, (1)

    其中,cki是系统预设的32 b参数,rki代表第i轮的轮密钥,F代表密钥扩展轮函数,其由S盒置换算法τ:Z322Z322和线性变换算法L(x)=x(x<<<13)(x<<<23)组成,其中<<<表示循环左移运算.

    SM4算法的加解密算法的整体结构与密钥扩展算法类似,均包含32轮的轮函数迭代,区别在于加解密算法中额外包含1次反序变换.

    SM4算法的轮函数迭代流程如图4所示,X1~X4为第1轮的输入,X2~X5为第1轮的输出,同时也是第2轮的输入. rk1为第1轮的轮密钥,T函数代表加解密模块的轮函数. 与密钥扩展部分的轮函数F类似,由S盒置换算法τ和一个线性变换算法L(x)=x(x<<<2)(x<<<10) (x<<<18)(x<<<24)组成.

    图  4  SM4加解密模块轮函数结构
    Figure  4.  Round function structure of SM4 encryption and decryption modules

    通过多轮的迭代过程,SM4算法能够实现高强度的数据加密和解密. 然而,在CBC模式下,由于相邻数据之间的依赖关系,传统的流水线技术难以提高算法的吞吐率. 因此,针对这一问题,本文提出了2种化简方法,以减少关键路径上的运算,从而提高SM4算法在CBC模式下的性能.

    加解密模块的轮函数的结构如图4所示,若不考虑T函数带来的时序延迟,单次轮函数迭代的关键路径上共包含3次异或运算. 以公式的形式描述SM4算法加解密轮函数的迭代关系可得到式(2):

    Xi+4=Xi(Xi+1Xi+2Xi+3rki). (2)

    若考虑相邻的2次轮函数迭代,则有:

    {Xi+4=XiT(Xi+1Xi+2Xi+3rki),Xi+5=XiT(Xi+2Xi+3Xi+4rki+1). (3)

    观察式(1)~(3)不难发现,由于SM4采用了4条数据线路的Feistel结构进行设计,在相邻的2次轮函数迭代过程中,均有96 b的输入是完全一致的,在式(3)的计算过程中,相邻2轮的轮函数将Xi+2Xi+3计算了2次.

    因此,一个简单的优化思路便是,我们在轮函数之间传递数据时,额外传递Xi+2Xi+3rki+1的运算结果,并作用于下一次计算,得到的流程图如图5所示.

    图  5  优化的轮函数结构
    Figure  5.  Optimized round function structure

    相比于图4的运算流程,在计算当前轮次的输出时,二次优化过后的轮函数通过提前获取下一轮次使用的密钥,并利用2轮之间相同的数据提前计算,可以使得在加解密的流程中总计节省32次异或运算的时间.

    S盒是密码学领域的一个基本组件,其功能是实现数据的非线性变换,在DES,AES,SM1,SM4等算法中均有应用. 在SM4算法中,其提供了一个8 b到8 b的非线性变换.

    在SM4算法中,S盒模块通常与另一个线性变换函数L组合使用,即图4图5中的T函数,其位于加解密算法轮函数的关键路径上,因此,如果能找到优化T函数关键路径的方法延时,也可以使得整个加解密模块的延时变小,进而提高运算效率.T函数的内部结构如图6所示,图中的<<<表示对32 b数据进行循环左移,关键路径包括1个S盒和3次异或运算. 在硬件实现中,循环移位可以通过硬件连线来实现,不会带来额外的路径延时.

    图  6  SM4加解密模块T函数结构
    Figure  6.  T function structure of SM4 encryption and decryption modules

    T函数中包含4次异或运算,反映到电路设计中,其关键路径上至少存在3次异或运算. 因此,一个优化思路便是,将算法中的S盒的输入输出修改为8 b输入、32 b输出[2-3] ,并提前将L函数作用于图中的4个S盒,如图7所示. 图7中,通过编码的形式保存其运行结果,将图6中的SBox与后续的线性变换L组合形成exSBox,之后仅需要将4个exSBox的输出异或即可,从而减少了1次异或运算.

    图  7  优化的T函数结构
    Figure  7.  Optimized T-function structure

    虽然修改后的S盒比原先的S盒输出了更多的数据,但在硬件实现中,仍然是通过相同数量的多路选择器查表输出. 因此修改前后的S盒的路径延时及其安全性并未改变.

    图7中的exSBox1为例,使用0xff作为输入展示exSBox1的构造方式,首先获得0xff作用于S盒后的运行结果0x48. 由于exSBox1的输入对应最高四位,因此,将其拓展为32 b数据为0x48000000. 在经过L函数后,得到的值是0x68492121. 如表1所示,表中前5行加粗部分表示传入的数据及其循环移位后所处位置,其余位置在任意输入下都恒等于0.

    表  1  搜索空间降低比率和命中率
    Table  1.  Search Space Reduction Rate and Hit Rate
    原数据 01001000 00000000 00000000 00000000
    <<<2 00100000 00000000 00000000 00000001
    <<<10 00000000 00000000 00000001 00100000
    <<<18 00000000 00000001 00100000 00000000
    <<<24 00000000 01001000 00000000 00000000
    异或和 01101000 01001001 00100001 00100001
    注:加粗部分表示传入的数据及其循环移位后所处位置.
    下载: 导出CSV 
    | 显示表格

    观察表1的运算结果不难发现,除最后一行加粗数字表示的第0~5位,第14,15位由异或运算产生,其余的24位均是输入的8位数据的排列组合,因此在硬件设计时,可以仅使用8 b输入、16 b输出的S盒实现. 对于图7中剩余的3个exSBox,在相同的输入下,可以通过对表1中的数据进行循环移位,得到对应的输出. 上述结论对4个位于不同部位的S盒均成立.

    具体而言,令p为输入的8 b数据,τ(p)为标准SM4算法中S盒的输出. X=(x0,x1,,x15)为exSBox1中存储的16 b数据,Y=(y0,y1,,y31)为优化后的T函数中需要的32 b输出. τ为SM4算法标准中使用的S盒置换函数,其对于8 b输入,产生对应的8 b输出,则X可以由式(4)产生:

    {(x0,x1,,x7)=τ(p),(x8,x9,,x15)=τ(p)(τ(p)<<<2). (4)

    表1可知,Y的取值实际上可以由X经过排列组合得到,对于exSBox2,exSBox3,exSBox4的取值,可以通过Y循环移位得到,且由于该过程中仅包含赋值运算,在电路设计中可以通过物理连线完成. 相比于文献[2]中的设计,节约了1/3的面积消耗. 具体的计算方式如式(5)所示.

    {(y0,y1,,y5)=(x8,x9,,x13)(y6,y7=(x6,x7)(y8,y9,,y13)=(x0,x1,,x5)(y14,y15=(x14,x15)(y16,y17,,y21)=(x2,x3,,x7)(y22,y23=(x0,x1)(y24,y25,,y29)=(x2,x3,,x7)(y30,y31=(x0,x1). (5)

    现场可编程逻辑门阵列(FPGA)和专用集成电路(ASIC)是目前主流使用硬件电路实现密码算法的2个方式. FPGA虽然具有可编程性、灵活性和快速设计等优势,但ASIC相较于FPGA拥有更高的性能,与本文设计追求的高效率目标相符,所以选择在ASIC下实现.

    SM4硬件系统的整体结构设计如图8所示,包括密钥扩展模块、加解密模块和适配CBC工作模式的组合逻辑. 对于单个加解密任务,若明文被分为n组,会执行1次密钥扩展和n次加解密. 因此,优化加解密算法的执行效率是优化SM4硬件设计的重点. 本文所提出的2种化简方法,对于每一组明文输入,可以减少64级异或门的延时,极大地提升了运算效率.

    图  8  SM4硬件整体架构
    Figure  8.  Overall architecture of SM4 hardware

    SM4算法的硬件实现主要有2种方案:一种方案是流水线结构,即通过寄存器连接多个加解密模块同时工作以提高加解密的效率,如图9(a)所示;另一种方案是使用循环迭代的方式. 即一次性提取32个轮函数中的n轮组合成一个组合电路,称为n合1电路,如图9(b)所示. 流水线结构的优势是可以充分利用n个加密核心的性能,在不影响整体工作频率的情况下加速运算. 对于SM4算法而言,在合理范围内堆叠流水线可以实现极高的吞吐量.

    图  9  流水线结构与循环迭代结构
    Figure  9.  Pipeline architecture and loop iteration architecture

    然而,流水线结构仅适用于ECB等数据无前后依赖的工作模式. 在CBC工作模式下,由于需要将前一轮的输出与本轮的输入进行异或运算,相邻的数据存在依赖,故而无法使用流水线加速运算. 因此,在本设计中没有选用流水线结构.

    虽然循环迭代结构会降低整体模块的工作频率,对吞吐量的提升较为有限,但可以同时兼容 ECB,CBC这 2种工作模式. 本设计最终选择了循环迭代的设计方式.

    在SM4算法中,密钥扩展与加解密算法类似,均包含32轮迭代. 密钥扩展模块采用图2所示的单轮组合逻辑电路循环32次来实现32轮迭代.

    在密钥扩展模块的输出端,使用寄存器存放每一轮电路的轮密钥,标号为0~31,如图10所示. 标号从0开始的好处是:在解密时,使用到的密钥顺序相反的,加密的第k轮使用的是第k1号密钥,解密的第k轮使用的是第32k号密钥. 在二进制下,二者的标号可以通过取反操作相互转化.

    图  10  轮密钥的存储与使用
    Figure  10.  Storage and usage of round keys

    为了保证运算结果的准确性,密钥扩展模块还 会向加解密模块发出控制信号表明自己的工作状态,以避免在轮密钥尚未完全更新时使用错误的轮密钥进行加解密.

    在国家标准文档[1]中,并没有针对CBC工作模式给出具体的测试用例. 因此,本文设计方案通过完整的Verilog HDL语言实现,通过在FPGA平台进行综合、仿真和上板验证,以确保功能正确并进行相关性能分析,如图11所示. 具体而言,通过PCIE上位机下发随机的明文数据到FPGA开发板,开发板完成加密后传回上位机,通过与软件对比实现功能验证. 若在循环验证多次后二者的输出均完全相同,则认为设计的SM4电路的功能正确.

    图  11  测试流程
    Figure  11.  Testing procedures

    最终,本文的设计在Zynq 7020 FPGA开发板上完成了上板验证,确保了功能的正确性,工作频率最高可达95 MHz,吞吐量约为1.5 Gb/s.

    ASIC上主要针对2种工艺SMIC 55 nm与 TSMC 40 nm进行了测试、通过Synopsys公司的EDA工具DesignCompiler进行时序等综合约束,我们选择了芯片面积和芯片使用的逻辑门数量(gates)作为评估指标,其结果如表2表3所示,在CBC模式下,本文的设计在3.97 mW的功耗下,单位面积吞吐率达129.4 Gb·s−1·mm−2,明显优于同类设计. 此外,以使用逻辑门的数量为评估标准,本文提出的设计在该指标上也明显优于同类设计,单位面积吞吐率为0.205×10−3 Gb·s−1·gates−1.

    表  2  SM4综合结果与面积效率对比
    Table  2.  Comparison of SM4 Synthesis Results and Area Efficiency
    工艺节点 芯片面积/mm2 吞吐率/(Gb·s−1 单位面积吞吐率/
    (Gb·s−1·mm−2
    功耗/mW
    40 nm* 0.0335 4.34 129.40 3.97
    55 nm* 0.0877 4.41 50.30 10.88
    65 nm[2] 0.1260 5.24 41.59
    180 nm[4] 0.0790 0.10 1.27 5.31
    55 nm[5] 0.0870 0.40 4.59 4.35
    350 nm[6] 0.0270 0.412 15.26
    注:*标注的表示本文的结果.
    下载: 导出CSV 
    | 显示表格
    表  3  SM4综合结果与门效率对比
    Table  3.  Comparison of SM4 Synthesis Results and Gates Efficiency
    工艺节点 gates 吞吐率/(Gb·s−1 单位面积吞吐率/
    (Gb·s−1·gates−1
    40 nm* 21.2×103 4.34 0.205×10−3
    55 nm* 21.1×103 4.41 0.209×10−3
    180 nm[6] 32.0×103 0.80 0.025×10−3
    65 nm[7] 31.0×103 1.23 0.040×10−3
    55 nm[8] 22.0×103 0.27 0.012×10−3
    130 nm[9] 22.0×103 0.80 0.036×10−3
    注:*标注的表示本文的结果.
    下载: 导出CSV 
    | 显示表格

    在不同工艺、电压下对该设计进行综合,可以得到本文设计在不同使用场景下的吞吐率. 在TSMC 40 nm、SMIC 55 nm、SMIC 130 nm下使用不同的工艺角分别对本文的设计进行综合,结果如表4所示.

    表  4  不同工艺角下的SM4综合结果与效率对比
    Table  4.  Comparison of SM4 Synthesis Results and Efficiency with Different Process Corners
    工艺节点 工艺角 面积/gates 吞吐率/(Gb·s−1 功耗/mW
    40 nm 0.99V/125°C/SS 21.0×103 2.40 2.55
    1.1V/25°C/TT 21.2×103 4.34 3.97
    1.21V/0°C/FF 20.9×103 6.96 8.35
    55 nm 1V/25°C/TT 20.0×103 2.78 4.10
    1.2V/25°C/TT 21.1×103 4.41 10.88
    1.32V/0°C/FF 17.8×103 6.84 33.59
    130 nm 1.08V/125°C/SS 20.8×103 1.11 6.86
    1.2V/25°C/TT 21.0×103 1.75 15.70
    1.32V/0°C/FF 21.8×103 2.45 23.03
    下载: 导出CSV 
    | 显示表格

    根据本文提出的2种对SM4加解密模块关键路径进行化简以及降低面积的方法,实现了4合1的SM4电路,并基于Zynq7020开发板进行了功能验证. 此外,ASIC综合结果表明本文的SM4电路相比于其他方案有更高的单位面积吞吐率和更低的功耗. 因此,这种对SM4算法进行的优化是有效的,并且对其他分组算法提高CBC模式下的单位面积吞吐率具有参考价值.

    作者贡献声明:郝泽钰提出研究方案并完成了论文的撰写;代天傲、黄亦成、段岑林协助完成了ASIC平台上的验证实验;董进、吴世勇、张博、王雪岩、贾小涛提出指导意见并修改论文;杨建磊提出指导意见并讨论定稿.

  • 图  1   开发者实现的内存拷贝类函数

    Figure  1.   Memory copy function implemented by developer

    图  2   httpd服务中IP地址转换的函数

    Figure  2.   Function for IP address conversion in the httpd service

    图  3   C语言库中strcpy函数的实现

    Figure  3.   Implementation of strcpy function in C library

    图  4   MIPS指令集下的strncpy函数

    Figure  4.   The strncpy function under the MIPS instruction set

    图  5   x86指令集下的memcpy函数

    Figure  5.   The memcpy function under the x86 instruction set

    图  6   Karonte中静态污点分析依赖于函数名信息

    Figure  6.   Static taint analysis in Karonte relies on function name information

    图  7   SaTC中静态污点分析依赖于函数名信息

    Figure  7.   Static taint analysis in SaTC relies on function name information

    图  8   内存拷贝类函数识别的流程

    Figure  8.   Workflow of memory copy function identification

    图  9   汇编代码和VEX IR代码

    Figure  9.   Assembly code and VEX IR code

    图  10   CPYFinder未识别出的漏洞函数

    Figure  10.   Vulnerable functions not identified by CPYFinder

    图  11   CPYFinder提供给用户模式选择的界面

    Figure  11.   The interface that CPYFinder provides to the user for mode selection.

    图  12   CPYFinder的单函数模式single下的输出

    Figure  12.   Output of CPYFinder in single function mode

    图  13   CPYFinder的all模式在IDA Pro中的可视化结果

    Figure  13.   Visualization results of CPYFinder’s all-mode in IDA Pro

    表  1   VEX IR的指令类型及示例

    Table  1   Instruction Types and Examples of VEX IR

    指令类型VEX IR操作码示例
    寄存器访问GET, PUTPUT(r7) = t2
    内存访问LDb(l)e, STb(l)eSTbe(t22) = t23
    算术运算Sub, Add, Mul, Divt6 = Add16(t4,0x001)
    逻辑运算Xor, Not, Or, Andt2 = Not32(t3)
    移位运算Shl, Shrt57 = Shl32(t54,0x02)
    转换*to*, *Uto*,*Sto*t16 = 1Uto32(t17)
    函数调用Ijk_CallPUT(pc) = 0x11008
    其他指令Cmp, ITE, Ctz, Clz, ift10 = CmpNE8(t6,t9)
    下载: 导出CSV

    表  2   现有方法与CPYFinder对比

    Table  2   Comparison of Existing Methods and CPYFinder

    方法依赖工具支持的指令集
    BootStompIDA ProARM
    Karonteangr, pyvexARM, MIPS
    SaTCangr, pyvexARM, MIPS
    CPYFinderIDA Pro, pyvexx86, ARM, MIPS, PPC
    下载: 导出CSV

    表  3   实验中使用的内存拷贝类函数

    Table  3   Memory Copy Functions Used in the Experiment

    来源文件函数
    string.hmemcpy, memmove, strcpy, strncpy,
    strcat, strncat, strxfrm
    wchar.hwcscat, wcscpy, wcsxfrm, mbsnrtowcs, wcsncpy, wmemmove, wcsnrtombswcsncat, wmemcpy
    Netgear R7000及Miraimy_copy, yystpcpy, yy_flex_strncpy, zmemcpy, stpcpy, unistrcpy, BUF_strlcpy, util_memcpy, tr_strlcpy, g_strlcpy, wxStrncpy, wxStrcpy, wxStrcat, w_copy, strlcpy, MD5_memcpy, resolv_domain_to_hostname, alps_lib_toupper, strncpy_w, sstrncpy,
    alpha_strcpy_fn, StrnCpy_fn
    下载: 导出CSV

    表  4   评估实验中所使用的编译器

    Table  4   Compilers Used in the Evaluation Experiments

    编译器编译器版本优化等级
    GCC4.5.4, 4.6.4, 4.7.4, 4.8.5, 5.4.0, 5.5.0, 6.5.0, 7.5.0O0~O3
    Clang3.9.1, 4.0.1, 5.0.1, 6.0.1O0~O4
    下载: 导出CSV

    表  5   各方法对C语言库中内存拷贝函数识别对比

    Table  5   Comparison of Methods for Identifying Memory Copy Functions in C Libraries

    二进制
    程序(ARM)
    BootStompSaTCSaTC+CPYFinder
    RPRPRPRP
    gcc-4.5.4-00.501.00.070.090.360.281.00.56
    gcc-4.6.4-00.501.00.140.200.360.281.00.56
    gcc-4.7.4-00.431.00.000.000.290.441.00.81
    gcc-4.8.5-00.431.00.000.000.360.500.850.79
    注:R为召回率;P为精准率.
    下载: 导出CSV

    表  6   各方法对自定义内存拷贝类函数识别对比

    Table  6   Comparison of Methods on the Identification of Custom Memory Copy Functions

    二进制程序
    (ARM)
    BootStompSaTC+CPYFinder
    RPRPRP
    gcc-4.5.4-O00.000.000.290.640.450.62
    gcc-4.6.4-O00.000.000.290.640.450.62
    gcc-4.7.4-O00.000.000.290.640.450.62
    gcc-4.8.5-O00.021.00.290.640.680.81
    gcc-5.4.0-O00.021.00.290.610.680.81
    gcc-5.5.0-O00.021.00.290.610.680.81
    gcc-6.5.0-O00.021.00.290.610.680.81
    gcc-7.5.0-O00.021.00.290.610.700.87
    注:R为召回率;P为精准率.
    下载: 导出CSV

    表  7   不同指令集及优化等级对识别的影响

    Table  7   Effect of Different Instruction Sets and Optimization Levels on the Identification

    二进制程序x86ARMMIPSPPC
    RPRPRPRP
    gcc-O00.620.760.810.680.810.650.870.63
    gcc-O10.780.640.780.640.780.640.780.61
    gcc-O20.710.620.640.600.710.620.710.58
    gcc-O30.710.660.640.640.710.660.710.62
    注:R为召回率;P为精准率.
    下载: 导出CSV

    表  8   优化等级对各个方法识别的影响

    Table  8   Effect of Optimization Level on the Identification of Each Method

    二进制程序
    (ARM)
    BootStompSaTC+CPYFinder
    RPRPRP
    gcc-O00.031.00.300.610.810.68
    gcc-O10.221.00.190.440.780.64
    gcc-O20.220.890.080.600.640.60
    gcc-O30.191.00.080.750.640.64
    注:R为召回率;P为精准率.
    下载: 导出CSV

    表  9   不同编译器下各方法的识别效果对比

    Table  9   Comparison of the Identification Effect of Each Method Under Different Compilers

    编译器二进制程序
    (ARM)
    BootStompSaTC+CPYFinder
    RPRPRP
    GCCgcc-4.5.4-O10.131.00.240.560.780.64
    gcc-4.6.4-O10.161.00.180.430.780.64
    gcc-4.7.4-O10.181.00.160.420.780.64
    gcc-4.8.5-O10.181.00.160.420.760.62
    Clangclang-3.9.1-O10.291.00.270.580.810.72
    clang-4.0.1-O10.291.00.270.580.810.72
    clang-5.0.1-O10.291.00.270.580.870.73
    clang-6.0.1-O10.291.00.270.580.870.73
    注:R为召回率;P为精准率.
    下载: 导出CSV

    表  10   Clang编译器对内存拷贝类函数识别的影响

    Table  10   Effect of Clang Compiler on the Identification of Memory Copy Function

    二进制程序
    (ARM)
    BootStompSaTC+CPYFinder
    RPRPRP
    clang-3.9.1-O00.00.00.160.660.750.63
    clang-3.9.1-O10.291.00.270.580.810.72
    clang-3.9.1-O20.241.00.00.00.780.68
    clang-3.9.1-O30.241.00.020.500.780.68
    clang-3.9.1-O40.241.00.020.500.780.68
    clang-6.0.1-O00.00.0 0.160.66 0.810.65
    clang-6.0.1-O10.291.00.270.580.870.73
    clang-6.0.1-O20.241.00.020.500.780.68
    clang-6.0.1-O30.241.00.00.00.780.68
    clang-6.0.1-O40.241.00.00.00.780.68
    注:R为召回率;P为精准率.
    下载: 导出CSV

    表  11   对由循环拷贝导致的溢出漏洞的识别结果

    Table  11   Identification Results for Overflow Vulnerabilities Caused by Loop Copy

    溢出漏洞厂商检测结果
    BootStompSaTC+CPYFinder
    CVE-2017-13772TP-Link*×
    CVE-2018-3950TP-Link**
    CVE-2018-3951TP-Link**
    CVE-2018-11013D-Link*××
    CVE-2020-8423TP-Link*×
    注:* 表示不支持或者运行崩溃;×表示未识别出;√表示识别出.
    下载: 导出CSV

    表  12   对内存拷贝类函数识别时耗对比

    Table  12   Comparison of Time Consumption for Memory Copy Functions Identification

    二进制程序时耗/s
    BootStompSaTCSaTC+CPYFinder
    gcc-4.5.4-O012.544.163.953.8
    gcc-4.6.4-O014.474.264.573.60
    gcc-4.7.4-O09.751.590.842.56
    gcc-4.8.5-O09.680.990.862.56
    gcc-5.5.0-O071.8415.1213.8910.47
    总时耗/s118.2826.1224.1122.99
    时耗比值/%198895100
    注:时耗比值为CPYFinder的时耗除以其他方法的时耗.
    下载: 导出CSV
  • [1]

    The MITRE Corporation. 2021 CWE top 25 most dangerous software weaknesses[EB/OL]. [2021-08-20]. http://cwe.mitre.org/top25/archive/2021/2021_cwe_top25.html

    [2]

    The MITRE Corporation. CWE-787: Out-of-bounds write[EB/OL]. [2021-07-20]. https://cwe.mitre.org/data/definitions/787.html

    [3]

    The MITRE Corporation. CWE-125: Out-of-bounds read[EB/OL]. [2021-07-20]. https://cwe.mitre.org/data/definitions/125.html

    [4]

    The MITRE Corporation. CWE-119: Improper restriction of operations within the bounds of a memory buffer[EB/OL]. [2021-07-20]. https://cwe.mitre.org/data/definitions/119.html

    [5] 王雅文,姚欣洪,宫云战,等. 一种基于代码静态分析的缓冲区溢出检测算法[J]. 计算机研究与发展.,2012,49(4):839−845

    Wang Yawen, Yao Xinhong, Gong Yunzhan, et al. A method of buffer overflow detection based on static code analysis[J]. Journal of Computer Research and Development, 2012, 49(4): 839−845 (in Chinese)

    [6] 李珍,邹德清,王泽丽,等. 面向源代码的软件漏洞静态检测综述[J]. 网络与信息安全学报,2019,5(1):1−14 doi: 10.11959/j.issn.2096-109x.2019001

    Li Zhen, Zou Deqing, Wang Zeli, et al. Survey on static software vulnerability detection for source code[J]. Chinese Journal of Network and Information Security, 2019, 5(1): 1−14 (in Chinese) doi: 10.11959/j.issn.2096-109x.2019001

    [7]

    Heelan S, Gianni A. Augmenting vulnerability analysis of binary code[C] //Proc of the 28th Annual Computer Security Applications Conf. New York: ACM, 2012: 199−208

    [8]

    Redini N, Machiry A, Das D, et al. BootStomp: On the security of bootloaders in mobile devices[C] //Proc of the 26th USENIX Security Symp (USENIX Security 17). Berkeley, CA: USENIX Association, 2017: 781−798

    [9]

    Redini N, Machiry A, Wang Ruoyu, et al. Karonte: Detecting insecure multi-binary interactions in embedded firmware[C] //Proc of the 41st IEEE Symp on Security and Privacy (SP). Piscataway, NJ: IEEE, 2020: 1544−1561

    [10]

    Chipounov V, Kuznetsov V, Candea G. S2E: A platform for in-vivo multi-path analysis of software systems[J]. ACM SIGPLAN Notices, 2011, 46(3): 265−278 doi: 10.1145/1961296.1950396

    [11]

    Cha S K, Avgerinos T, Rebert A, et al. Unleashing mayhem on binary code[C] //Proc of the 33rd IEEE Symp on Security and Privacy (SP). Piscataway, NJ: IEEE, 2012: 380−394

    [12]

    Mouzarani M, Sadeghiyan B, Zolfaghari M. A smart fuzzing method for detecting heap-based buffer overflow in executable codes[C] //Proc of the 21st IEEE Pacific Rim Int Symp on Dependable Computing (PRDC). Piscataway, NJ: IEEE, 2015: 42−49

    [13]

    Cheng Kai, Li Qiang, Wang Lei, et al. DTaint: Detecting the taint-style vulnerability in embedded device firmware[C] //Proc of the 48th Annual IEEE/IFIP Int Conf on Dependable Systems and Networks (DSN). Piscataway, NJ: IEEE, 2018: 430−441

    [14]

    Chen Libo, Wang Yanhao, Cai Quanpu, et al. Sharing more and checking less: Leveraging common input keywords to detect bugs in embedded systems[C] //Proc of the 30th USENIX Security Symp (USENIX Security 21). Berkeley, CA: USENIX Association, 2021: 303−319

    [15]

    The MITRE Corporation. A buffer overflow in the httpd daemon on TP-Link TL-WR841N V10[EB/OL]. [2021-07-20]. https://cve.mitre.org/cgi-bin/cvename.cgi?name=2020-8423

    [16]

    Hex-ray Corporation. Fast library identification and recognition technology[EB/OL]. [2021-07-30]. https://hex-rays.com/products/ida/tech/flirt/

    [17]

    Radare2 Organization. The Official Radare2 Book[M/OL]. 1st ed. 2018 [2021-07-30]. https://github.com/radareorg/radare2-book

    [18]

    Free Software Foundation. Options that control optimization[EB/OL]. [2021-07-15]. https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

    [19] 刘剑,苏璞睿,杨珉,等. 软件与网络安全研究综述[J]. 软件学报,2018,29(1):42−68 doi: 10.13328/j.cnki.jos.005320

    Liu Jian, Su Purui, Yang Min, et al. Software and cyber security—A survey[J]. Journal of Software, 2018, 29(1): 42−68 (in Chinese) doi: 10.13328/j.cnki.jos.005320

    [20] 陈千,程凯,郑尧文,等. 函数级数据依赖图及其在静态脆弱性分析中的应用[J]. 软件学报,2020,31(11):3421−3435 doi: 10.13328/j.cnki.jos.005833

    Chen Qian, Cheng Kai, Zheng Yaowen, et al. Function-level data dependence graph and its application in static vulnerability analysis[J]. Journal of Software, 2020, 31(11): 3421−3435 (in Chinese) doi: 10.13328/j.cnki.jos.005833

    [21] 王蕾,何冬杰,李炼,等. 基于稀疏框架的静态污点分析优化技术[J]. 计算机研究与发展,2019,56(3):480−495 doi: 10.7544/issn1000-1239.2019.20180071

    Wang Lei, He Dongjie, Li Lian, et al. Sparse framework based static taint analysis optimization[J]. Journal of Computer Research and Development, 2019, 56(3): 480−495 (in Chinese) doi: 10.7544/issn1000-1239.2019.20180071

    [22]

    Tonder R, Kotheimer J, Goues C. Semantic crash bucketing[C] //Proc of the 33rd ACM/IEEE Int Conf on Automated Software Engineering. New York: ACM, 2018: 612–622

    [23]

    Bao T, Burket J, Woo M, et al. BYTEWEIGHT: Learning to recognize functions in binary code[C] //Proc of the 23rd USENIX Security Symp (USENIX Security 14). Berkeley, CA: USENIX Association, 2014: 845−860

    [24]

    Shin E C R, Song D, Moazzezi R. Recognizing functions in binaries with neural networks[C] //Proc of the 24th USENIX Security Symp (USENIX Security 15). Berkeley, CA: USENIX Association, 2015: 611−626

    [25]

    Cisco. SNMP remote code execution, CVE-2017-6736[EB/OL]. [2021-08-10]. https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20170629-snmp

    [26]

    The MITRE Corporation. Multiple stack-based buffer overflows in TP-Link WR940N[EB/OL]. [2021-08-10]. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-13772

    [27]

    Rawat S, Mounier L. Finding buffer overflow inducing loops in binary executables[C] //Proc of the 6th IEEE Int Conf on Software Security and Reliability. Piscataway, NJ: IEEE, 2012: 177−186

    [28]

    Luo Peng, Zou Deping, Du Yajuan, et al. Static detection of real-world buffer overflow induced by loop[J]. Computers & Security, 2020, 89: 101616

    [29]

    Song D, Brumley D, Yin Heng, et al. BitBlaze: A new approach to computer security via binary analysis[C] //Proc of the 4th Int Conf on Information Systems Security. Berlin: Springer, 2008: 1−25

    [30]

    Pewny J, Garmany B, Gawlik R, et al. Cross-architecture bug search in binary executables[C] //Proc of the 36th IEEE Symp on Security and Privacy. Piscataway, NJ: IEEE, 2015: 709−724

    [31]

    Shoshitaishvili Y, Wang Ruoyu, Salls C, et al. Python bindings for Valgrind's VEX IR[EB/OL]. [2021-05-23]. https://github.com/angr/pyvex

    [32]

    Shoshitaishvili Y, Wang Ruoyu, Salls C, et al. Sok (state of) the art of war: Offensive techniques in binary analysis[C] //Proc of the 37th IEEE Symp on Security and Privacy (SP). Piscataway, NJ: IEEE, 2016: 138−157

    [33]

    Hu Yikun, Zhang Yuanyuan, Li Juanru, et al. Cross-architecture binary semantics understanding via similar code comparison[C] //Proc of the 23rd IEEE Int Conf on Software Analysis, Evolution, and Reengineering (SANER). Piscataway, NJ: IEEE, 2016: 57−67

    [34]

    Hu Yikun, Zhang Yuanyuan, Li Juanru, et al. Binmatch: A semantics-based hybrid approach on binary code clone analysis[C] //Proc of the 34th IEEE Int Conf on Software Maintenance and Evolution (ICSME). Piscataway, NJ: IEEE, 2018: 104−114

    [35]

    Hagberg A, Schult A, Swart J. Exploring network structure, dynamics, and function using networkx[C/OL] //Proc of the 7th Python in Science Conf (SciPy2008). 2008 [2021-05-23]. http://conference.scipy.org/proceedings/SciPy2008/paper_2/

    [36]

    Netgear. Netgear GPL code[EB/OL]. [2021-06-15]. https://github.com/jameshilliard/R7000

    [37]

    Senpai A. Leaked Mirai source code for research purposes[EB/OL]. [2021-06-15]. https://github.com/jgamblin/Mirai-Source-Code

  • 期刊类型引用(1)

    1. 石明丰,甘永根,赵玉珂,刘飞飞,何晓蓉. 智能量测开关与智能物联锁具信息交互设计. 中国新技术新产品. 2024(21): 137-139 . 百度学术

    其他类型引用(1)

图(13)  /  表(12)
计量
  • 文章访问数:  267
  • HTML全文浏览量:  39
  • PDF下载量:  121
  • 被引次数: 2
出版历程
  • 收稿日期:  2021-10-10
  • 修回日期:  2022-02-09
  • 网络出版日期:  2023-02-26
  • 刊出日期:  2023-01-31

目录

/

返回文章
返回