来自 UCSB 的团队 Shellphish,为参加 DARPA 举办的 CGC 竞赛,设计并实现了 CRS(Cyber Reasoning System)Mechaphish。该系统包含自动化漏洞挖掘模块 Driller、Exploit自动生成引擎 Rex、自动补丁模块 Patcherex 以及 ropchain 生成模块 angrop。本文主要对其中的 Exploit 自动生成引擎 Rex 进行介绍,通过分析 Rex 源码,重点对 Crash 复现及可利用判断部分进行说明。弟作为一只资深菜鸡,文中难免存在不当之处,望各位师傅指正 Orz…

一、概述
Exploit 自动生成引擎 Rex 在硬件模拟器 QEMU 与二进制分析平台 angr 的基础上,通过 Concolic Execution 实现 Exploit 的自动生成。将待分析的应用程序及导致应用程序崩溃的 Crash 作为系统输入,Rex 将复现崩溃路径,并对崩溃时的寄存器状态及内存布局进行分析,判断 Crash 的可利用性,并自动生成 Exploit。

源码中对漏洞类型的定义:

二、安装
安装 Rex 存在两种方式:1)安装 Mechaphish,安装文档;2)仅安装 Rex,安装文档。二者的差别在于 Mechaphish 包含漏洞挖掘模块 Driller、自动利用模块 Rex、自动补丁模块 Patcherex 以及 ropchain 生成模块 angrop。由于各模块之间相互独立,因此本文选择仅安装自动利用模块 Rex。本地环境采用 Ubuntu 16.04.5 Desktop(64 bit)。部署过程中,Rex 所需依赖如下:

依赖过程中部分路径需要调整,根据提示信息修改即可。各个依赖所承担的功能如下:

组件名称 功能
angr A powerful and user-friendly binary analysis
platform! tracer Utilities for generating dynamic traces.
angrop angrop is a rop gadget finder and chain builder.
compilerex POV templates and compilation support for CGC binaries.
compilerex is a hacky cgc binary compiler shellphish-qemu
Shellphish’s pip-installable package of QEMU povsim POV
simulation for CGC.

安装完成后,使用以下代码对 Rex 的功能进行测试。

# triage a crash
>>> crash = rex.Crash("./legit_00003", b"\x00\x0b1\xc1\x00\x0c\xeb\xe4\xf1\xf1\x14\r\rM\r\xf3\x1b\r\r\r~\x7f\x1b\xe3\x0c`_222\r\rM\r\xf3\x1b\r\x7f\x002\x7f~\x7f\xe2\xff\x7f\xff\xff\x8b\xc7\xc9\x83\x8b\x0c\xeb\x80\x002\xac\xe2\xff\xff\x00t\x8bt\x8bto\x00t\x8b\xc7\xdd\x83\xc2t~n\xac\xe2\xff\xffk\x00t\x8b\xc7\xdd\x83\xc2t~n\xac\xe2\xff\xff\x00t\x8bt\x8b\xac\xf1\x83\xc2t~c\x00\x00\x00~~\x7f\xe2\xff\xff\x00t\x9e\xac\xe2\xf1\xf2@\x83\xc3t")
>>> crash.crash_types
['write_what_where']
>>> crash.explorable()
True
explore the crash by setting segfaulting pointers to sane values and re-tracing
>>> crash.explore()
now we can see that we control instruction pointer
>>> crash.crash_types
'ip_overwrite'
generate exploits based off of this crash
it may take several minutes
>>> arsenal = crash.exploit()
we generated a type 1 POV for every register
>>> len(arsenal.register_setters) # we generate one circumstantial register setter, one shellcode register setter
2
and one Type 2 which can leak arbitrary memory
>>> len(arsenal.leakers)
1
exploits are graded based on reliability, and what kind of defenses they can
bypass, the two best exploits are put into the 'best_type1' and 'best_type2' attributes
>>> arsenal.best_type1.register
'ebp'
exploits can be dumped in C, Python, or as a compiled POV
>>> arsenal.best_type2.dump_c('legit3_x.c')
>>> arsenal.best_type2.dump_python('legit3_x.py')
>>> arsenal.best_type2.dump_binary('legit3_x.pov')
also POVs can be tested against a simulation of the CGC architecture
>>> arsenal.best_type1.test_binary()
True

测试结果如下:


三、源码分析
查看 Rex 源码的目录结构:

分析各类之间的依赖关系,从逻辑上大致可分为四部分: 1)Exploit_factory:调用各模块,负责自动生成 Exploit; 2)Crash:复现崩溃路径,判定 Crash 的可利用性; 3)Technique:对于可利用的 Crash,采用针对性的技术,生成 Exploit; 4)Shellcode_factory:shellcode 仓库,根据需要选用合适的 Shellcode。

下文重点对 Crash 可利用性判定部分进行分析。

四、Crash 可利用性判定
Rex 以 Concolic Execution 的方式复现 crash 路径,分析崩溃时寄存器状态及内存布局,并对 crash 的可利用性进行判定,相关功能代码集中在 Crash.py 中。对原理感兴趣的同学可以参考论文《SoK: (State of) The Art of War: Offensive Techniques in Binary Analysis》,以下是对论文原文的引用:

Vulnerable States. Unlike AEG/Mayhem, but similar to AXGEN, we generate exploits by performing concolic execution on crashing program inputs using angr. We drive concolic execution forward, forcing it to follow the same path as a dynamic trace gathered by concretely executing the crashing input applied to the program. Concolic execution is stopped at the point where the program crashed, and we inspect the symbolic state to determine the cause of the crash and measure exploitability. By counting the number of symbolic bits in certain registers, we can triage a crash into a number of categories such as frame pointer overwrite, instruction pointer overwrite, or arbitrary write, among others.

1、Concrete Execution
Concolic Execution 原理请感兴趣的同学自行查阅。angr 在实现 concolic execution 时,需要提供 crash_addr。

因此,通过 QEMU 加载二进制程序及 PoC,以获取 crash_addr。相关功能在 Tracer 模块中实现。

Crash.py 中调用 Tracer 模块的代码如下:

tracer_args={
'ld_linux': os.path.join(bin_location, 'tests/i386/ld-linux.so.2'),'library_path': os.path.join(bin_location, 'tests/i386')}
r = tracer.QEMURunner(binary=binary, input=input_data, argv=argv, trace_timeout=trace_timeout, **tracer_args)

2、Concolic Execution
在获取 crash_addr 之后,对 angr 进行配置,并执行 Concolic Execution。 其中,较为关键的配置包括:初始状态设定、State Plugin 选择、路径探索策略。

(1)初始状态设定

配置 simulation_manager 中的 save_unconstrained 参数。 其中 r 为 tracer.QEMURunner() 返回值,当 PoC 成功触发崩溃时 r.crash_mode 为 True,失败时为 False。

通过 full_init_state()方法,设置程序的初始状态:



设置 tracing 模式:mode = ‘tracing’


add_options:

Option name Description
so.MEMORY_SYMBOLIC_BYTES_MAP Maintain a mapping of symbolic variable to which memory address it “really” corresponds to, at the paged memory level?
so.TRACK_ACTION_HISTORY track the history of actions through a path (multiple states). This action affects things on the angr level
so.CONCRETIZE_SYMBOLIC_WRITE_SIZES Concretize the sizes of symbolic writes to memory
so.CONCRETIZE_SYMBOLIC_FILE_READ_SIZES Concreteize the sizes of file reads
so.TRACK_MEMORY_ACTIONS Keep a SimAction for each memory read and write
remove_options:
由于 ‘tracing’ 模式下预制了一些选项,因此在优化策略时,不仅需要add_options,而且需要 remove_options。定义在./angr/sim_options.py中:

Option name Description
so.TRACK_CONSTRAINT_ACTIONS Keep a SimAction for each constraint added
so.LAZY_SOLVES Don’t check satisfiability until absolutely necessary
so.ALL_FILES_EXIST Attempting to open an unkown file will result in creating it with a symbolic length
so.TRACK_REGISTER_ACTIONS Keep a SimAction for each register read and write
so.TRACK_TMP_ACTIONS Keep a SimAction for each temporary variable read and write
so.TRACK_JMP_ACTIONS Keep a SimAction for each jump or branch
so.ACTION_DEPS Track dependencies in SimActions
so.SIMPLIFY_MEMORY_WRITES Run values stored to memory through z3′s simplification
设置约束条件:

(2) State Plugins
SimState 属于 angr 核心概念之一,并被设计为插件式的架构,可以根据分析任务的不同,选用针对性的插件。Rex 默认选用了 ‘posix’ 与 ‘preconstrainer’。插件源码位于./angr/state_plugins/目录下。

SimSystemPosix( ):

Data storage and interaction mechanisms for states with an environment conforming to posix.Available as state.posix.

SimStatePreconstrainer( ):

This state plugin manages the concept of preconstraining – adding constraints which you would like to remove later.:param constrained_addrs : SimActions for memory operations whose addresses should be constrained during crash analysis

(3) 路径探索策略
路径搜索策略的选择,对符号执行来说举足轻重。由于 Rex 在采用 Concolic Execution,因此设置了 ‘Tracer’、’Oppologist’ 两种路径搜索策略。

angr 内置的路径搜索方法存储于 ./angr/exploration_techniques/ 目录下。Crash.py 中调用代码如下:

3、Crash Triage
_triage_crash() 中根据 eip、ebp 中符号变量的个数,及发生崩溃时的操作,对 Crash 类型进行判定。

http://www.45zq.cn/portal/article/index/id/192.html

Driller、Exploit自动生成引擎 Rex相关推荐

  1. 用JAVA写的word模板自动生成引擎

    大家好,我是TJ 一个励志推荐10000款开源项目与工具的程序员 TJ君做项目的时候最头疼什么?当然是写各种文档啦,尤其是在大公司做项目,各种规范文档不可少,虽然说一个成熟的项目管理过程中的确是要依靠 ...

  2. EasyJWeb Tools中代码自动生成引擎详解

    在EasyJWeb-0.6.0推出来以后,很多网友对其中的代码生成部分非常感兴趣,并来信问了一些如何使用easyjwebtools.如何支持多表生成.生成页面的定制.业务逻辑的定制等很多问题.下面以我 ...

  3. 人脸照片自动生成游戏角色_ICCV2019论文解析

    人脸照片自动生成游戏角色_ICCV2019论文解析 Face-to-Parameter Translation for Game Character Auto-Creation 论文链接: http: ...

  4. 开源!开源!我写的Anto.exe C#代码自动生成工具.欢迎下载。。

    在开发的过程中开发人员不得不经常要写很多重复的代码, 为了把精力放到更重要的方面去很多人为都做了N多努力,随便google一下自动生成工具, 你都会很容易得到很多这样的工具.园子就有好几款,其中李天平 ...

  5. 使用NVelocity自动生成Favorite收藏夹的导航页面

    你是否碰到你的收藏夹凌乱不堪,或者很多收藏网页地址虽然分类,可是使用起来却感觉不太好,有没有想过把你的收藏夹内容自动生成一个网页的导航页面生成类似Hao123(http://www.hao123.co ...

  6. 解放程序员双手!GPT-3自动生成SQL语句 | 代码开源

    金磊 发自 凹非寺 量子位 报道 | 公众号 QbitAI "无所不能"的GPT-3,现在又来解放程序员们的双手了. 像这样,只需用简单的英文问下GPT-3"上个月注册了 ...

  7. python list转字符串_我用python写了个自动生成给文档生成索引的脚本!懒人智慧...

    我用 python 写了一个自动生成索引的脚本 简介:为了刷算法题,建了一个 GitHub仓库: PiperLiu / ACMOI_Journey ,记录自己的刷题轨迹,并总结一下方法.心得.想到一个 ...

  8. 自动生成Mapper文件(基于Mybatis Maven插件)

    自动生成Mybatis的Mapper文件 工作中使用mybatis时我们需要根据数据表字段创建pojo类.mapper文件以及dao类,并且需要配置它们之间的依赖关系,这样的工作很琐碎和重复,myba ...

  9. php写实体类,自动生成实体类(方式一)

    YMP框架自v1.0开始就支持通过数据库表结构自动生成实体类代码,所以v2.0版本不但重构了实体代码生成器,而且更简单好用! #------------------------------------ ...

最新文章

  1. bmw info source
  2. [BUUCTF-pwn]——bjdctf_2020_router
  3. Apache用户身份验证
  4. c 和java互相验签_C椭圆曲线签名 用java验签
  5. php 函数变量的顺序,PHP实现参数的自定义顺序调用 | 剑花烟雨江南
  6. 转:linux中fork()函数详解
  7. sqlalchemy 查询
  8. 动态为GridView控件创建列
  9. 7.docker pull
  10. python课题_python课题报告
  11. NO.4 计算有序数组的平方
  12. Java核心技术卷1:基础知识(原书第10版)
  13. python怎样分析文献综述怎么写_如何写文献综述?
  14. 桌面计算机找不到硬盘,bios找不到硬盘完美解决方法 选择STATConfigur
  15. Java课程设计学生考勤管理
  16. android 彻底 关 亮度,Android设置屏幕亮度为0关闭屏幕 – 如何避免
  17. 针式打印机偏移测试软件,精打教程(3)打印机打印偏移设置
  18. windows画图工具,两张图片叠加
  19. 解决chrt: failed to set pid 0‘s policy: Operation not permitted
  20. 详解FC交换机基础知识

热门文章

  1. js-cookie设置token过期时间
  2. 自动驾驶层次测试体系(单元测试/集成测试/SIL/HIL/VIL/RIL/LABCAR/实车等)
  3. 手机app开发用的是什么语言?有哪些优势?
  4. AJAX学习笔记——发送AJAX的POST请求,模拟from表单提交
  5. Java爬虫 爬取某招聘网站招聘信息
  6. linux shell遍历多个数组
  7. 第十四届蓝桥杯C++B组题解(不完全对)
  8. 验证码—基本功能实现02_点击重新获取验证码
  9. Photoshop CS2 视频教程-PS锁定图层(转)
  10. 都说在阿里年薪百万不难,面试入职阿里需要准备什么?