当前位置:网站首页>Angr(四)——angr_ctf
Angr(四)——angr_ctf
2022-07-25 09:27:00 【c1rcl3】
通过angr_ctf熟悉angr的使用方法
参考链接:
04
1. 直接下载angr_ctf提供的ELF可执行文件04_angr_symbolic_stack
2. 用IDA静态分析,可以发现程序关键逻辑在handle_user中

程序调用scanf读取两个无符号整数(unsigned int)到栈上,之后调用complex_function0和complex_function1对两个参数分别进行处理,最后进行逻辑判断,输出Good Job或Try again。
3. 编写脚本求解程序输出Good Job时对应的输入,可以指定符号执行从handle_user函数调用scanf方法读取输入后开始,需要对栈进行部署。
import angr
def isGood(state):
return b'Good Job.' in state.posix.dumps(1)
def isBad(state):
return b'Try again.' in state.posix.dumps(1)
p = angr.Project("./04")
start_addr = 0x8048697
init_state = p.factory.blank_state(addr=start_addr)
padding_size = 8
init_state.stack_push(init_state.regs.ebp)
init_state.regs.ebp = init_state.regs.esp
init_state.regs.esp -= padding_size
pass1 = init_state.solver.BVS('pass1', 32)
pass2 = init_state.solver.BVS('pass2', 32)
init_state.stack_push(pass1)
init_state.stack_push(pass2)
sm = p.factory.simulation_manager(init_state)
sm.explore(find=isGood, avoid=isBad)
for i in range(0, len(sm.found)):
found_state = sm.found[i]
res1 = found_state.solver.eval(pass1)
res2 = found_state.solver.eval(pass2)
print("{} {}".format(res1, res2))4. 运行脚本查看结果

5. 验证结果正确性
![]()
05
1. 直接下载angr_ctf提供的ELF可执行文件05_angr_symbolic_memory
2. 用IDA静态分析

程序调用scanf读取4个8字节字符串到指定内存中,之后对32个字节逐个进行处理,最后通过字符串比较进行判断,输出Good Job或Try again。
3. 编写脚本求解程序输出Good Job时对应的输入,可以指定符号执行从调用scanf方法读取输入后开始,需要对内存进行部署。
import angr
import claripy
def isGood(state):
return b'Good Job.' in state.posix.dumps(1)
def isBad(state):
return b'Try again.' in state.posix.dumps(1)
p = angr.Project("./05")
start_addr = 0x8048601
init_state = p.factory.blank_state(addr=start_addr)
p1 = claripy.BVS('p1', 64)
p2 = claripy.BVS('p2', 64)
p3 = claripy.BVS('p3', 64)
p4 = claripy.BVS('p4', 64)
p1_addr = 0xA1BA1C0
p2_addr = 0xA1BA1C8
p3_addr = 0xA1BA1D0
p4_addr = 0xA1BA1D8
init_state.memory.store(p1_addr, p1)
init_state.memory.store(p2_addr, p2)
init_state.memory.store(p3_addr, p3)
init_state.memory.store(p4_addr, p4)
sm = p.factory.simulation_manager(init_state)
sm.explore(find=isGood, avoid=isBad)
for i in range(0, len(sm.found)):
found_state = sm.found[i]
res1 = found_state.solver.eval(p1, cast_to=bytes).decode()
res2 = found_state.solver.eval(p2, cast_to=bytes).decode()
res3 = found_state.solver.eval(p3, cast_to=bytes).decode()
res4 = found_state.solver.eval(p4, cast_to=bytes).decode()
print(res1)
print(res2)
print(res3)
print(res4)4. 运行脚本查看结果

5. 验证结果正确性
![]()
边栏推荐
猜你喜欢

message from server: “Host ‘xxx.xxx.xxx.xxx‘ is not allowed to connect to this MySQL server“

升级 GLIBC 2.29 checking LD_LIBRARY_PATH variable... contains current directory error 解决方案

OSPF协议的配置(以华为eNSP为例)

复现 ASVspoof 2021 baseline RawNet2

nodejs版本升级或切换的常用方式

UE4 LoadingScreen动态加载启动动画

@Import,Conditional和@ImportResourse注解

Redis使用场景

Angr(六)——angr_ctf

DHCP的配置(以华为eNSP为例)
随机推荐
多数相合问题总结
mysql 解决不支持中文的问题
The first week of the fifth stage
软件测试笔记,测试用例设计
Detailed explanation of MySQL database
一文学会,三款黑客必备的抓包工具教学
Reflection 反射
Pytorch 张量列表转换为张量 List of Tensor to Tensor 使用 torch.stack()
Chrome开发者工具详解
Record some JS tool functions
IO流中的输入流
Set creation and common methods
vant问题记录
简易加法计算器
Usage of string slicing
struct2的原理
Round to the nearest
力扣刷题组合问题总结(回溯)
【无标题】
Pnpm Brief