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

智能推荐

python全栈开发—函数再战—实现模块化设计_全栈开发与数学-程序员宅基地

文章浏览阅读256次。函数再战—熟练基础,精通技能,触类旁通之所以又整理了一遍函数,主要是因为当我进行后续学习的时候,发现函数比想象的要NB的多,于是又厚着脸皮又来了一遍,嗯,果然很NB。建议在学习的过程中遇到了难题,记得回头复习复习,也许正是那些你忽略的内容,给未来的你营造出自己是SB的难题。内容概括:函数基本语法及特性函数与局部变量返回值嵌套函数递归匿名函数函数式编程介绍高阶函数内置函数..._全栈开发与数学

在vs开发环境中用opencv读取图片,Debug模式下成功,release模式下失败的可能原因_visual studio的debug模式可以include opencv release模式不行-程序员宅基地

文章浏览阅读921次。1 检查一下release模式下的链接器的输入,其依赖的lib名称最后一个字母是没有"d",d代表debug如图:2 检查一下路径,看是否因为带中文的路径导致编码错误..._visual studio的debug模式可以include opencv release模式不行

教你一步一步使用Excel获取API接口的金融数据_excel的api key-程序员宅基地

文章浏览阅读5.6k次,点赞7次,收藏26次。在用EXCEL做量化分析的时候,经常需要通过一些金融数据平台的API接口,获取各种数据。最常用的公共API接口有Yahoo Finance,Google Finance,新浪财经,搜狐财经等。这些都不需要注册,就可以直接使用。获取方式相对简单,但数据种类不够丰富,通常只包括交易数据和财务数据。另外一些免费的金融数据平台,如国外的Quandl和国内的Tushare也都提供了API接口,数据种类更..._excel的api key

ThinkPHP去除url中的index.php,绝对管用!-程序员宅基地

文章浏览阅读1.6k次。例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index.php呢?1.httpd.conf配置文件中加载了mod_rewrite.so模块 //在APACHE里面去配置#LoadModule rewrite_module modu

Qt核心机制与原理_qt原理-程序员宅基地

文章浏览阅读3.8k次,点赞5次,收藏39次。★了解Qt和C++的关系★掌握Qt的信号/槽机制的原理和使用方法★了解Qt的元对象系统★掌握Qt的架构★理解Qt的事件模型,掌握其使用的时机信号与槽、元对象系统、事件模型是Qt机制的核心,如果您想要掌握Qt编程,就需要对它们有比较深入的了解。本章重点介绍了信号与槽的基本概念和用法、元对象系统、Qt的事件模型,以及它们在实际使用过程中应注意的一些问题。Qt对标准C++的扩展标准C++对象模型为面向对象编程提供了有效的实时支持,但是它的静态特性在一些领域中表现的不够灵活。事实上,GUI应用程序_qt原理

CC2640R2F BLE5.0 TI-RTOS概述_ti rtos 总中断-程序员宅基地

文章浏览阅读8.2k次,点赞3次,收藏25次。TI-RTOS概述TI-RTOS是CC2640R2F设备上蓝牙低能耗项目的运行环境。TI-RTOS内核是传统SYS/BIOS内核的定制版本,可作为具有驱动程序,同步和调度工具的实时抢占式多线程操作系统。线程模块TI-RTOS内核管理线程执行的四个不同的任务级别,如图21所示。线程模块列表如下图所示,按照优先级降序排列。硬件中断软件中断任务后台空闲功能的空闲任务_ti rtos 总中断

随便推点

爬虫框架 - feapder_feapder 网盘-程序员宅基地

文章浏览阅读1.0k次。1. 前言众所周知,Python 最流行的爬虫框架是 Scrapy,它主要用于爬取网站结构性数据今天推荐一款更加简单、轻量级,且功能强大的爬虫框架:feapder项目地址:https://github.com/Boris-code/feapder2. 介绍及安装和 Scrapy 类似,feapder 支持轻量级爬虫、分布式爬虫、批次爬虫、爬虫报警机制等功能内置的 3 种爬虫如下: AirSpider 轻量级爬虫,适合简单场景、数据量少的爬虫 Spider._feapder 网盘

《数据结构与算法分析:Java语言描述》.pdf-程序员宅基地

文章浏览阅读6k次,点赞2次,收藏6次。关注“Java后端技术全栈”回复“面试”获取全套大厂面试资料程序=数据结构+算法这好比是软件工程师的“武林秘籍”。数据结构指的是数据与数据之间的逻辑关系;算法指的是解决特定问题的步骤和方..._数据结构与算法分析java语言描述pdf

PyTorch——自注意力(self-attention)机制实现(代码详解)_自注意力机制代码-程序员宅基地

文章浏览阅读8w次,点赞111次,收藏691次。参考链接https://www.bilibili.com/video/BV1JE411g7XF?p=54https://arxiv.org/abs/1706.03762https://blog.csdn.net/qq_36653505/article/details/83375160简述自注意力机制(self-attention)self-attention可以视为一个特征提取层,给定输入特征a1,a2,⋅⋅⋅ana^{1},a^{2},\cdot \cdot \cdot a^{n}a1,a2_自注意力机制代码

在Vue中应用cornerstone并且实时更新缩放比例等数据_浏览器缩放倍数变化时 更新数据 vue-程序员宅基地

文章浏览阅读1.6k次。在Vue中应用cornerstone并且跟随dicom实时更新缩放比例等数据最近需要在cornerstone的显示界面中显示一些数据,比如缩放比例以及渲染时间等,但是这些是需要根据鼠标事件进行实时更新的,想想肯定是有这个接口的,于是便试了一下。1、获取到当前视窗的对象获取到视窗这个对象因为它里面肯定会有许多属性可以直接被使用,刚好我们的缩放比例就是里面的scale,还有一些属性可以直接取用。..._浏览器缩放倍数变化时 更新数据 vue

C语言中常用的函数_c语言常用函数-程序员宅基地

文章浏览阅读3.1w次,点赞135次,收藏1k次。C语言中常用的函数1、putchar()函数2、getchar()函数3、pow( a , b )函数4、sqrt( a )函数5、fabs(a)函数6、puts(字符数组)函数——输出字符串的函数7、gets(字符数组)——输入字符串的函数8、strcat(a , b)函数——字符串连接函数9、strcpy函数——字符串复制函数10、strncpy函数——字符串复制函数11、strcmp函数——字符串比较函数12、strlen函数——测量字符串长度的函数13、strlwr函数——转换为小写的函数14、_c语言常用函数

webpack打包时如何修改文件名_webpack打包文件名称设置-程序员宅基地

文章浏览阅读5k次。webpack打包时如何修改文件名在使用webpack进行项目打包的时候,我们可通过以下方式对不同类型的资源,进行文件名或文件路径的修改_webpack打包文件名称设置

推荐文章

热门文章

相关标签