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

智能推荐

Linux 基础入门 & 操作命令_命令' ls -l >tmp-程序员宅基地

这篇文章介绍了Linux系统的基础知识和操作命令,包括其特点、支持的平台以及一些常用的命令如grep。

如何在windows上安装Openssl环境_windows openssl-程序员宅基地

文章浏览阅读6k次,点赞7次,收藏13次。openssl windows版安装_windows openssl

在win10上使用Ubuntu Linux,不用虚拟机,win10自带Linux子系统 WSL putty 导入配置 WSL桌面_windows10 不用wsl直接用ubantu-程序员宅基地

文章浏览阅读1k次。大部分按照此教程即可:https://www.jianshu.com/p/6d6e629df051若出错,在Store中安装ubuntu时候提示,重试该操作,无法加载页面。轻稍后重试。错误码:0x80131500,按照https://blog.csdn.net/han12398766/article/details/88068036错误码:0x80000403,需要打开Windows Upd..._windows10 不用wsl直接用ubantu

CSS命名规范——BEM思想(非常赞的规范)_bem规范-程序员宅基地

文章浏览阅读3.7w次,点赞61次,收藏112次。特别声明:此篇文章由David根据csswizardry的英文文章原名《MindBEMding – getting your head ’round BEM syntax》进行翻译,整个译文带有我们自己的理解与思想,如果译得不好或不对之处还请同行朋友指点。如需转载此译文,需注明英文出处:http://csswizardry.com/2013/01/mindbemding-getting-you_bem规范

JAVA代码覆盖率检测工具-EMMA_java 测试用例检测覆盖的api-程序员宅基地

文章浏览阅读1.8k次。EMMA 是一个用于检测和报告 JAVA 代码覆盖率的开源工具。它不但能很好的用于小型项目,很方便得得出覆盖率报告,而且适用于大型企业级别的项目。EMMA 有许多优点,首先你能免费得到它,并把它用于自己项目的开发。它支持许多种级别的覆盖率指标:包,类,方法,语句块(basic block)和行,特别是它能测出某一行是否只是被部分覆盖,如条件语句短路的情况。它能生成 text,xml,html_java 测试用例检测覆盖的api

Docker-程序员宅基地

文章浏览阅读1.4k次,点赞17次,收藏11次。当谈论 Docker 时,通常是指 Docker 容器化平台。Docker 是一种容器化平台,它使用容器来打包、交付和运行应用程序。下面是关于 Docker 的一些关键概念和重要功能

随便推点

支持向量机的基本思想_深度讲解支持向量机背后的数学思想-程序员宅基地

文章浏览阅读535次。在支持向量机(support vector machine,SVM)算法中,有诸多数学思想。学习SVM是一个非常好的实践数学思想的过程,为我们以后创新解决问题思路提供了启发。在卷积神经网络兴起之前,在机器学习界一直是非常受追捧的算法,不光是因为其有良好的泛化能力、很高的准确度,更是因为其完备的数学理论依据以及诸多较难理解的数学知识。这两点让人们觉得SVM是一个很精妙很酷的算法!所以在实际应用也非常..._简述支持向量机中核函数方法的基本思想。

曲率高斯滤波去噪python实现(附代码详解)_曲率滤波-程序员宅基地

文章浏览阅读7.3k次,点赞8次,收藏40次。曲率高斯滤波及平均滤波去噪python实现(附代码)曲率滤波的理论基础可以参考下曲率滤波的理论基础和应用,这篇博客介绍的思想完美的避开了一大堆数学公式,简直是我的福音,但还是要细看的,不然很容易忽略重点,我这里就简单的做个总结,所有图片均来源于前面这篇博客。曲率滤波基本原理1、曲率曲面上的一点有一切平面tangent plane,此点处会有各个方向上的曲率,但是必然会有最大主曲率和最小主曲..._曲率滤波

AI之AutoML:Google AutoML(Google Cloud自动化机器学习平台库)的简介、安装、使用方法-程序员宅基地

文章浏览阅读1.4w次,点赞10次,收藏34次。​AI之AutoML:Google AutoML(Google Cloud自动化机器学习平台库)的简介、安装、使用方法目录Google AutoML(Google Cloud自动化机器学习平台库)的简介AutoML的安装AutoML的使用方法Google AutoML(Google Cloud自动化机器学习平台库)的简介​​​​​​​1、Google AutoML的概述背景 ​​​​​​​AutoML 基于谷歌最新的图像识别技术神经架构搜索( Neural A_automl

Linux-Unix编程手册(上下两册全).pdf 高清原版_linux/unix系统编程手册pdf-程序员宅基地

文章浏览阅读8.5k次,点赞144次,收藏34次。文章目录Linux-Unix编程手册(上下两册全).pdf 高清原版 可复制 可搜索 带书签简介预览下载Linux-Unix编程手册(上下两册全).pdf 高清原版 可复制 可搜索 带书签简介《linux/unix系统编程手册(上、下册)》是介绍linux与unix编程接口的权威著作。linux编程资深专家michael kerrisk在书中详细描述了linux/unix系统编程所涉及的系统调用和库函数,并辅之以全面而清晰的代码示例。《linux/unix系统编程手册(上、下册)》涵盖了逾500个系统_linux/unix系统编程手册pdf

Flask框架(flask中的request对象,获取请求参数,保存上传的文件)_request.form.name只能获取第一个-程序员宅基地

文章浏览阅读1w次。1.request中包含了前端发送过来的所有数据 ,请求的 request 对象中保存了一次HTTP请求的一切信息。 通过request.from可以直接发送提取请求体中的表单格式数据,是一个类字典的对象 通过get方法只能拿到多个重名参数的第一个 2. reques常用的属性: 4.这里会用到Postman工具 下载:打开官网,https..._request.form.name只能获取第一个

需求分析(知识点总结)_功能需求分析-程序员宅基地

文章浏览阅读9.9k次,点赞9次,收藏73次。学习目标:需求分析(知识点总结)学习内容:数据流图(Data Flow Diagram,简称DFD)建模方法核心:数据流特性:1、抽象性:只有信息和数据存储、流动、使用以及加工的情况,所以描述的是抽象出来的数据2、概括性:把系统对各种业务的处理过程联系起来考虑,形成总体,反映数据流之间的概括情况数据库应用系统(DBAS)性能指标:1、数据操作响应时间(数据访问响应时间)2、系统吞吐量:指系统在单位时间内可以完成的数据库事务或查询的数量3、允许并发访问的最大用户数4、每TPS代价值_功能需求分析

推荐文章

热门文章

相关标签