Angr 初体验之探索口令-程序员宅基地

技术标签: python  

目标文件:http://whalectf.xin/files/3e8c3473ea4d6bfb6edc385131313dfa/r100

用angr模块来寻找口令在内存的地址,并且获取口令的内容,python2和python3的解决方案有不一样的地方,值得我记录下来。

解决方案:

首先我们使用radare2来获取函数的反汇编代码.

┌─[root@parrot]─[~/whalectf]
└──╼ #r2 -Ad r100
Process with PID 5592 started...
= attach 5592 5592
bin.baddr 0x00400000
Using 0x400000
asm.bits 64
[x] Analyze all flags starting with sym. and entry0 (aa)
[Warning: Invalid range. Use different search.in=? or anal.in=dbg.maps.x
Warning: Invalid range. Use different search.in=? or anal.in=dbg.maps.x
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Check for objc references
[x] Check for vtables
[TOFIX: aaft can't run in debugger mode.ions (aaft)
[x] Type matching analysis for all functions (aaft)
[x] Use -AA or aaaa to perform additional experimental analysis.
 -- I am Pentium of Borg. Division is futile. You will be approximated.
[0x7f3f9ecaa090]> afll
address            size  nbbs edges    cc cost          min bound range max bound          calls locals args xref frame name
================== ==== ===== ===== ===== ==== ================== ===== ================== ===== ====== ==== ==== ===== ====
0x0000000000400610   41     1     0     1   15 0x0000000000400610    41 0x0000000000400639     1    0      1    0     8 entry0
0x00000000004005d0    6     1     0     1    3 0x00000000004005d0     6 0x00000000004005d6     0    0      0    1     0 sym.imp.__libc_start_main
0x0000000000400590    6     1     0     1    3 0x0000000000400590     6 0x0000000000400596     0    0      0    1     0 sym.imp.getenv
0x00000000004005a0    6     1     0     1    3 0x00000000004005a0     6 0x00000000004005a6     0    0      0    2     0 sym.imp.puts
0x00000000004005b0    6     1     0     1    3 0x00000000004005b0     6 0x00000000004005b6     0    0      0    1     0 sym.imp.__stack_chk_fail
0x00000000004005c0    6     1     0     1    3 0x00000000004005c0     6 0x00000000004005c6     0    0      0    1     0 sym.imp.printf
0x00000000004005e0 6 1 0 1 3 0x00000000004005e0 6 0x00000000004005e6 0 0 0 1 0 sym.imp.fgets
0x0000000000400600    6     1     0     1    3 0x0000000000400600     6 0x0000000000400606     0    0      0    1     0 sym.imp.ptrace
0x00000000004007e8  153     8     9     5   56 0x00000000004007e8   153 0x0000000000400881     6    2      0    1   280 main
0x00000000004006d0   99     8    10     6   44 0x0000000000400670   141 0x00000000004006fd     0    0      0    0     8 entry.init0
0x00000000004007a8   64     5     6     3   30 0x00000000004007a8    64 0x00000000004007e8     2    0      0    0     8 entry.init1
0x00000000004006b0   28     3     3     2   14 0x00000000004006b0    28 0x00000000004006cc     1    0      0    0     0 entry.fini0
0x0000000000400640   41     4     4     4   20 0x0000000000400640    41 0x0000000000400669     0    0      0    1     8 fcn.00400640
[0x7f3f9ecaa090]> pdf @  main
/ (fcn) main 153
|   int main (int argc, char **argv, char **envp);
|           ; var int32_t var_110h @ rbp-0x110
|           ; var int32_t var_8h @ rbp-0x8
|           ; DATA XREF from entry0 (0x40062d)
|           0x004007e8      55             push rbp
|           0x004007e9      4889e5         mov rbp, rsp
|           0x004007ec      4881ec100100.  sub rsp, 0x110
|           0x004007f3      64488b042528.  mov rax, qword fs:[0x28]    ; [0x28:8]=-1 ; '(' ; 40
|           0x004007fc      488945f8       mov qword [var_8h], rax
|           0x00400800      31c0           xor eax, eax
|           0x00400802      bf37094000     mov edi, str.Enter_the_password: ; 0x400937 ; "Enter the password: "
|           0x00400807      b800000000     mov eax, 0
|           0x0040080c      e8affdffff     call sym.imp.printf         ; int printf(const char *format)
|           0x00400811      488b15500820.  mov rdx, qword [obj.stdin]; MOV rdx = [0x601068] = 0x0 rbp
 ; [0x601068:8]=0
|           0x00400818      488d85f0feff.  lea rax, [var_110h]
|           0x0040081f      beff000000     mov esi, 0xff               ; 255
|           0x00400824      4889c7         mov rdi, rax
|           0x00400827      e8b4fdffff     call sym.imp.fgets          ; char *fgets(char *s, int size, FILE *stream)
|           0x0040082c      4885c0         test rax, rax
|       ,=< 0x0040082f      7435           je 0x400866
|       |   0x00400831      488d85f0feff.  lea rax, [var_110h]
|       |   0x00400838      4889c7         mov rdi, rax
|       |   0x0040083b      e8bdfeffff     call 0x4006fd
|       |   0x00400840      85c0           test eax, eax
|      ,==< 0x00400842      7511           jne 0x400855
|      ||   0x00400844      bf4c094000     mov edi, str.Nice           ; 0x40094c ; "Nice!"
|      ||   0x00400849      e852fdffff     call sym.imp.puts           ; int puts(const char *s)
|      ||   0x00400849      e852fdffff     call sym.imp.puts           ; int puts(const char *s)
|      ||   0x0040084e      b800000000     mov eax, 0
|     ,===< 0x00400853      eb16           jmp 0x40086b
|     |`--> 0x00400855      bf52094000     mov edi, str.Incorrect_password ; 0x400952 ; "Incorrect password!"
|     | |   0x0040085a      e841fdffff     call sym.imp.puts           ; int puts(const char *s)
|     | |   0x0040085f      b801000000     mov eax, 1
|     |,==< 0x00400864      eb05           jmp 0x40086b
|     ||`-> 0x00400866      b800000000     mov eax, 0
|     ||    ; CODE XREFS from main (0x400853, 0x400864)
|     ``--> 0x0040086b      488b4df8       mov rcx, qword [var_8h]
|           0x0040086f      6448330c2528.  xor rcx, qword fs:[0x28]
|       ,=< 0x00400878      7405           je 0x40087f
|       |   0x0040087a      e831fdffff     call sym.imp.__stack_chk_fail ; void __stack_chk_fail(void)
|       `-> 0x0040087f      c9             leave
\           0x00400880      c3             ret

找到angr需要使用的两个地址,分别为'Nice!'调用地址0x00400844和‘Incorrect password!‘调用地址0x00400855

python2脚本如下,和python3的略有不同,即dumps函数的索引不同。

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from angr import *

proj = Project('./r100',auto_load_libs = False)
state = proj.factory.entry_state()
simgr = proj.factory.simgr(state)
simgr.explore(find = 0x400844 ,avoid = 0x40085a)
print  simgr.found[0].posix.dumps(3)                    //dumps(3)

 执行结果如下:

┌─[root@parrot]─[~/whalectf]
└──╼ #python2 angr_py2_template.py 
WARNING | 2019-06-12 09:26:41,097 | angr.analyses.disassembly_utils | Your version of capstone does not support MIPS instruction groups.
WARNING | 2019-06-12 09:26:42,138 | angr.state_plugins.posix | Tried to look up a symbolic fd - constrained to 3 and opened /tmp/angr_implicit_0
Code_Talkers�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

 

python3脚本如下:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from angr import *

proj = Project('./r100',auto_load_libs = False)
state = proj.factory.entry_state()
simgr = proj.factory.simgr(state)
simgr.explore(find = 0x400844 ,avoid = 0x40085a)
print(simgr.found[0].posix.dumps(0))                   //dumps(0)

 执行结果如下:

┌─[root@parrot]─[~/whalectf]
└──╼ #python3 angr_py3_template.py 
WARNING | 2019-06-12 09:27:26,251 | angr.state_plugins.symbolic_memory | The program is accessing memory or registers with an unspecified value. This could indicate unwanted behavior.
WARNING | 2019-06-12 09:27:26,252 | angr.state_plugins.symbolic_memory | angr will cope with this by generating an unconstrained symbolic variable and continuing. You can resolve this by:
WARNING | 2019-06-12 09:27:26,252 | angr.state_plugins.symbolic_memory | 1) setting a value to the initial state
WARNING | 2019-06-12 09:27:26,252 | angr.state_plugins.symbolic_memory | 2) adding the state option ZERO_FILL_UNCONSTRAINED_{MEMORY,REGISTERS}, to make unknown regions hold null
WARNING | 2019-06-12 09:27:26,253 | angr.state_plugins.symbolic_memory | 3) adding the state option SYMBOL_FILL_UNCONSTRAINED_{MEMORY_REGISTERS}, to suppress these messages.
WARNING | 2019-06-12 09:27:26,255 | angr.state_plugins.symbolic_memory | Filling register r15 with 8 unconstrained bytes referenced from 0x400890 (PLT.ptrace+0x290 in r100 (0x400890))
WARNING | 2019-06-12 09:27:26,260 | angr.state_plugins.symbolic_memory | Filling register r14 with 8 unconstrained bytes referenced from 0x400895 (PLT.ptrace+0x295 in r100 (0x400895))
WARNING | 2019-06-12 09:27:26,263 | angr.state_plugins.symbolic_memory | Filling register r13 with 8 unconstrained bytes referenced from 0x40089a (PLT.ptrace+0x29a in r100 (0x40089a))
WARNING | 2019-06-12 09:27:26,267 | angr.state_plugins.symbolic_memory | Filling register r12 with 8 unconstrained bytes referenced from 0x40089f (PLT.ptrace+0x29f in r100 (0x40089f))
WARNING | 2019-06-12 09:27:26,276 | angr.state_plugins.symbolic_memory | Filling register rbx with 8 unconstrained bytes referenced from 0x4008b0 (PLT.ptrace+0x2b0 in r100 (0x4008b0))
WARNING | 2019-06-12 09:27:26,339 | angr.state_plugins.symbolic_memory | Filling register cc_ndep with 8 unconstrained bytes referenced from 0x400690 (PLT.ptrace+0x90 in r100 (0x400690))
b'Code_Talkers\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\x00'

 

转载于:https://www.cnblogs.com/heycomputer/articles/11010456.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30432579/article/details/99600405

智能推荐

MongoDB详解(有这一篇就够了)-程序员宅基地

文章浏览阅读4.1k次,点赞6次,收藏23次。MongoDB 是由C++语言编写的,基于分布式文件存储的数据库,是一个介于关系数据库和非关系数据库之间的产品,是最接近于关系型数据库的NoSQL数据库。MongoDB 旨在为 WEB 应用提供可扩展的高性能数据存储解决方案。MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成。MongoDB 文档类似于JSON对象。字段值可以包含其他文档,数组及文档数组类似于MongoDB优点:数据处理能力强,内存级数据库,查询速度快,扩展性强,只是不支持事务。_mongodb

两种内存池管理方法对比_非固定大小的内存池-程序员宅基地

文章浏览阅读1.9k次,点赞4次,收藏11次。目录一、问题背景二、两种内存池管理2.1 固定大小内存块分配(参考正点原子STM32F4 malloc.c)2.1.1 初始化2.1.3释放原理2.2 可变大小内存块分配(参考WSF BLE协议栈buffer management)2.2.1 初始化2.2.2 分配原理2.2.3 释放原理三、总结和对比一、问题背景最近在调试ambiq apollo..._非固定大小的内存池

MPEG TS流简介-程序员宅基地

文章浏览阅读3.1k次。TS简介MPEG-TS(Transport stream)即Mpeg传输流定义于ITU-T Rec. H.222.0和ISO 13818-1标准中,属于MPEG2的系统层。MPEG2-TS面向的传输介质是网络和卫星等可靠性较低的传输介质,这一点与面向较可靠介质如DVD等的MPEG PS不同。1. TS数据包TS流由TS数据包即Transport stream packet组成。TS p...

Deepin wine QQ/微信中文显示为方块的原因之一_wine 字体方块-程序员宅基地

文章浏览阅读984次。问题原因:目录下~/.deepinwine,查找乱码的应用Deepin-QQ、Deepin-WeChat,相同路径/drive_c/windows/Fonts下查看是否有字体,笔者发现没有任何字体,这就是原因所致,wine程序会在此处寻找字体,而不能直接利用linux系统的字体解决方法:把/usr/share/fonts/Fonts_Win下字体复制到这里,使wine应用程序能找到至少一种fallback字体,也可以在别的地方的fonts问价夹下,拷贝.ttf字体文件到这里..._wine 字体方块

整个元素周期表通用,AI 即时预测材料结构与特性-程序员宅基地

文章浏览阅读264次。编辑 | 绿萝材料的性质由其原子排列决定。然而,现有的获得这种排列的方法要么过于昂贵,要么对许多元素无效。现在,加州大学圣地亚哥分校纳米工程系的研究人员开发了一种人工智能算法,可以几乎即时地预测任何材料(无论是现有材料还是新材料)的结构和动态特性。该算法被称为 M3GNet,用于开发 matterverse.ai 数据库,该数据库包含超过 3100 万种尚未合成的材料,其特性由机器学习算法预测。M..._人工智能预测材料属性

Docker & Nvidia-docker 镜像基础操作_dokcer怎么使用nvidia作为基础镜像-程序员宅基地

文章浏览阅读5.8k次,点赞2次,收藏25次。简述 docker & nvidia-docker感觉是深度学习的环境配置与部署简化很多,下面记录一下基础的命令,为自己后续用到查阅。在使用之前请先安装好NVIDIA驱动,CUDA以及docker & nvidia-docker的基本环境。docker & nvidia-docker 导入与导出镜像导出镜像:nvidia-docker save -o /save_p..._dokcer怎么使用nvidia作为基础镜像

随便推点

dwd明细粒度事实层设计_dwd层如何设计-程序员宅基地

文章浏览阅读1.8k次。目录1-数仓dwd事实层介绍2-数仓dwd层事实表设计原则3-数仓dwd层事实表设计规范4-建表示例1-数仓dwd事实层介绍明细粒度事实层以业务过程驱动建模,基于每个具体的业务过程特点,构建最细粒度的明细层事实表。您可以结合企业的数据使用特点,将明细事实表的某些重要维度属性字段做适当冗余,即宽表化处理。公共汇总粒度事实层(DWS)和明细粒度事实层(DWD)的事实表作为数据仓库维度建模的核心,需紧绕业务过程来设计。通过获取描述业务过程的度量来描述业务过程,包括引用的维度和与业务过程有关的度量。度量通常为_dwd层如何设计

Ambari 2.7.3.0 安装部署 hadoop 3.1.0.0 集群视频完整版_ambari2.7.3 hadoop 部署-程序员宅基地

文章浏览阅读1.5k次。一、前言很多小伙伴也都知道,最近一直在做 Ambari 集成自定义服务的教学笔记和视频。之前在准备 Ambari 环境的时候,考虑到有朋友会在 Ambari 安装部署时遇到问题,所以贴心的我呢,就在搭建 Ambari 环境的时候,把这个视频录制好了,总共时长共 87 分钟,将近1个半小时,附带移除 SmartSense 服务及 FAQ 。也提前介绍一下搭建好的 Ambari 相关版本信息:..._ambari2.7.3 hadoop 部署

使用R语言保存CSV文件_r软件保存为csv文件-程序员宅基地

文章浏览阅读881次。本文介绍了如何使用R语言保存CSV文件。我们使用write.csv函数将数据框保存为CSV格式。您只需提供要保存的数据对象和文件路径,即可轻松创建CSV文件。CSV文件是一种通用的数据交换格式,在数据分析和数据处理中广泛使用。希望本文对您有所帮助,祝您在R语言中保存CSV文件时顺利进行数据处理和分析!_r软件保存为csv文件

VR技术赋能数字经济发展新机遇,加快构建双循环新发展格局_vr商城建设对区域经济-程序员宅基地

文章浏览阅读498次。当下,数字化浪潮正重塑世界经济发展格局,数字经济正在成为全球经济可持续增长新引擎。我国超大规模的市场经济优势为数字经济发展提供了广阔而丰富的应用场景,也成为推动传统产业升级改造、加快”构建国内国际双循环相互促进的新发展格局“的重要引擎。据国家统计局数据显示:2020年第一季度,我国GDP呈现出6.8%的负增长态势。今年1月份至5月份,与互联网相关的新业态、新模式却继续保持逆势增长。全国实物商品网上零售额同比增长11.5%;实物商品网上零售额占社会消费品零售总额比重为24.3%,比去年同期提高5.4个百分点_vr商城建设对区域经济

HCS12X–数据定义(如何在CodeWarrior中将数据定义到分页区)_codewarrior数组如何定义-程序员宅基地

文章浏览阅读384次。由于在暑假匆忙接收的嵌入式项目中需要使用特别大的数组,非分页RAM的内存不够用了,没办法,硬着头皮尝试使用分页RAM,但是完全没有单片机的基础,导致极其的困难。之前写程序都是按照纯软件的思维,主要考虑架构,不会考虑到每个变量具体存在哪个物理地址这么底层的问题,结果被飞思卡尔这分页地址、prm文件什么的搞得一头雾水,而网上的资料又少,讲的又大同小异的笼统,最后写出来的程序因为这分页地址的原因存在各种_codewarrior数组如何定义

wed服务器简介_wed服务器的主要特点之一就是它具有十几个html文件连接到另一个html文件的能力称为-程序员宅基地

摘要:Web服务器是用于提供Web服务的软件,它通过HTTP协议来传输和接收网页和其他资源。在Inteet上,HTTP通信通常在TCP/IP连接上进行,使用端口号80。Apache是一种常见的Web服务器软件,其主程序为httpd,根目录为/var/www/html。

推荐文章

热门文章

相关标签