Coder Social home page Coder Social logo

deflat's Introduction

Deobfuscation: recovering an OLLVM-protected program

Flat_control_flow

Description

基于SnowGirlsdeflat,利用angr框架实现去除控制流平坦化,详细内容请参考利用符号执行去除控制流平坦化

脚本仅依赖于angr框架,测试使用的angr版本为8.19.4.5

Usage

0x400530 是函数check_password()的地址。

(angr-dev) <path>/deflat/flat_control_flow$ python3 deflat.py -f samples/bin/check_passwd_x8664_flat --addr 0x400530
*******************relevant blocks************************
prologue: 0x400530
main_dispatcher: 0x400554
pre_dispatcher: 0x40099b
retn: 0x40098f
relevant_blocks: ['0x40086a', '0x40080d', '0x4008ee', '0x40094f', '0x40084e', '0x400819', '0x400886', '0x40095b', '0x4007ec', '0x40092e', '0x4008a9', '0x4008cc', '0x40091b', '0x40097c', '0x400837']
*******************symbolic execution*********************
-------------------dse 0x40086a---------------------
-------------------dse 0x40080d---------------------
-------------------dse 0x4008ee---------------------
-------------------dse 0x40094f---------------------
-------------------dse 0x40084e---------------------
-------------------dse 0x400819---------------------
-------------------dse 0x400886---------------------
-------------------dse 0x40095b---------------------
-------------------dse 0x4007ec---------------------
-------------------dse 0x40092e---------------------
-------------------dse 0x4008a9---------------------
-------------------dse 0x4008cc---------------------
-------------------dse 0x40091b---------------------
-------------------dse 0x40097c---------------------
-------------------dse 0x400837---------------------
-------------------dse 0x400530---------------------
************************flow******************************
0x40084e:  ['0x40086a', '0x40095b']
0x40086a:  ['0x400886', '0x40094f']
0x400530:  ['0x4007ec']
0x4008a9:  ['0x4008cc', '0x40094f']
0x400886:  ['0x4008a9', '0x40094f']
0x4007ec:  ['0x400819', '0x40080d']
0x40091b:  ['0x40098f']
0x40080d:  ['0x40084e']
0x40092e:  ['0x40094f']
0x4008ee:  ['0x40091b', '0x40092e']
0x400819:  ['0x400837']
0x40094f:  ['0x40097c']
0x40095b:  ['0x40097c']
0x40097c:  ['0x40098f']
0x400837:  ['0x4007ec']
0x4008cc:  ['0x4008ee', '0x40094f']
0x40098f:  []
************************patch*****************************
Successful! The recovered file: check_passwd_flat_recovered

Bogus_control_flow

Description

利用angr框架去除虚假的控制流,详细内容请参考Deobfuscation: recovering an OLLVM-protected program

原文的主要思路是在进行符号执行时,对约束条件进行"精简",通过将x * (x + 1) % 2 替换为0,使得(y < 10 || x * (x + 1) % 2 == 0)恒成立,从而获取正确的基本块,避免死循环。

在使用angr框架解决该问题时,也可以按照上述思路进行。另外一种思路是直接将xy的值设为0,同样可以使得上面的约束恒成立。在默认条件下,xy的值会被初始化为0,无需手动进行设置。也就是说,可以直接利用符号执行来解决,而不会遇到死循环的问题。

通过符号执行,获取所有执行过的基本块之后,再进行patch去除冗余的基本块即可。

对控制流进行精简后,通过F5查看伪代码,与源码基本一致。另外,可以在此基础上对控制流进行进一步精简,比如去除冗余的指令等。

Usage

0x080483e0 是函数target_function()的地址。

(angr-dev) <path>/deflat/bogus_control_flow$ python3 debogus.py -f samples/bin/target_x86_bogus --addr 0x80483e0
*******************symbolic execution*********************
executed blocks:  ['0x8048686', '0x804868b', '0x8048991', '0x8048592', '0x8048914', '0x8048715', '0x8048897', '0x8048720', '0x8048725', '0x80484ab', '0x804862c', '0x804842e', '0x80484b6', '0x80484bb', '0x80487bb', '0x80487c0', '0x80486c7', '0x8048950', '0x8048551', '0x80488d3', '0x8048955', '0x8048556', '0x8048856', '0x80489d8', '0x80488d8', '0x804885b', '0x80483e0', '0x80485e0', '0x8048761', '0x80485eb', '0x80485f0', '0x80484f7', '0x80487fc']
************************patch******************************
Successful! The recovered file: ./target_bogus_recovered

Description

Supported Arch

目前,脚本仅在以下架构的程序上进行测试:

  • x86系列:x86, x86_64
  • arm系列:arm(armv7), arm64/aarch64(armv8)

Misc

am_graph.py脚本来自于angr-management/utils/graph.py,用于将CFG转换为supergraph,因为angr框架中CFGIDA中的不太一样。

A super transition graph is a graph that looks like IDA Pro's CFG, where calls to returning functions do not terminate basic blocks.

通常在安装angr时,并不会安装angr-managerment (angr的GUI),所以这里直接将angr-management/utils/graph.py拷贝到当前目录,并重命名为am_graph.py.

Requirements

  • python3
  • angr

Reference

deflat's People

Contributors

cq674350529 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deflat's Issues

This Script support arm64 ios dylib binary??

This Script support arm64 ios dylib binary??

ios dylib binary load failed...

raise CLECompatibilityError("Unable to find a loader backend for %s. Perhaps try the 'blob' loader?" % spec)

运行脚本出错

Traceback (most recent call last):
File ".\debogus.py", line 114, in
main()
File ".\debogus.py", line 35, in main
supergraph = am_graph.to_supergraph(target_function.transition_graph)
AttributeError: 'NoneType' object has no attribute 'transition_graph'

KeyError: 'bw'

First of all thank you very much for this tool.
Some errors occurred during my use.

`KeyError:'bw',`

I used arm files, error stackclll: ins_b_jmp_hex_arm(), called:
line(243), patch_value = ins_b_jmp_hex_arm(instr.address, children[0], bx_cond)

bx_cond = 'b' + instr.mnemonic[len('mov'):]
Then I added a new print below: print('[x] b: {:#x}'.format(instr.address))
Then, the assembly corresponding to the address is:
MOVW R2, #0xBA7B,
How to deal with this?

local variable 'retn_node' referenced before assignment

I got these error when ruuning with deflat.py:"local variable 'retn_node' referenced before assignment".
I check the script and find out when the function has no "return code"( no matching condition for if supergraph.out_degree(node) == 0 and len(node.out_branches) == 0), the function cannot work.

Will it support arm64?

It seems that one angr dependency cle doesn't support mach-o backend very well. What would be the possible ways to solve it?

AttributeError: 'NoneType' object has no attribute 'transition_graph'

安装一致版本的angr之后,py3.6.0,grapy.py已复制到相同目录下,运行deflat.py时报错:
Traceback (most recent call last):
File "deflat.py", line 96, in
supergraph = am_graph.to_supergraph(target_function.transition_graph)
AttributeError: 'NoneType' object has no attribute 'transition_graph'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.