pwnable之codemap

pwnable之codemap

题目

made by YourButterfly


I have a binary that has a lot information inside heap.
How fast can you reverse-engineer this?
(hint: see the information inside EAX,EBX when 0x403E65 is executed)
download: http://pwnable.kr/bin/codemap.exe
ssh codemap@pwnable.kr -p2222 (pw:guest)

题目大意是在codemap这个程序,运行时堆中有大量信息,并且提示我们在程序运行至0x403e65时观察eax,ebx。

ssh连上远程服务器,有三个文件,分别是codemap.c,codemap.exe,readme。

readme提示我们逆向 codemap.exe。然后连上本地的 9021端口,守护进程会询问第二大和第三大的chunk内容是什么

codemap@ubuntu:~$ ls
codemap.c  codemap.exe  readme
codemap@ubuntu:~$ cat readme
reverse engineer the 'codemap.exe' binary, then connect to codemap daemon(nc 0 9021),
the daemon will ask you some question, provide the correct answer to get flag.

codemap@ubuntu:~$ nc 0 9021
What is the string inside 2nd biggest chunk? :
aa
Wait for 10 seconds to prevent brute-forcing...
aa
What is the string inside 3rd biggest chunk? :
Wait for 10 seconds to prevent brute-forcing...
Nah, wrong
codemap@ubuntu:~$ 

ida分析。

ida分析codemap.exe

在0x403E65下断点,debugger->start process,此时eax的值为0xAD4E,EBX指向的是“FItZrTIUzoAHpx”,

这里写图片描述

下面这一部分主要是在准备当前chunks的大小,

这里写图片描述

在申请空间后通过rand()%62的方式从字符串
“abcdefghijklmnopqrstubwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890”
中获取字符,共15次,也就是获得的串长度为15。接下来就是题目提示的部分,eax,ebx分别对应的是chunks大小,和内容。这里记录值比当前eax大就更新记录的chunks大小,和内容,这在这个1000次的循环里意味着寻找最大chunks的大小和内容。

这里写图片描述

需要的是第二大的chunks和第三大的chunks的内容。
人工没办法再1000次循环中找,只能是让程序自己跑了。可以用ida的idc或idapthon脚本跑。当时不会。临时看了下ida权威指南,也从网上搜了一下。

#coding:utf-8
import idc
from idaapi import *

max_eax = 0
second_eax = 0
third_eax = 0
max_ebx = 0
second_ebx = 0
third_ebx = 0
ft=0
sd=0
td=0
#AddBpt(0x263E65).text:00403E65(在这一句下断点)jbe     short loc_403E6D
#在题目提示的地方前下一个断点。
StartDebugger("","","")#启动具有默认参数的调试器

for count in xrange(999): 
    code = GetDebuggerEvent(WFNE_SUSP|WFNE_CONT, -1) # 恢复执行,等待断点
    eax = GetRegValue("EAX")
    ebx = GetRegValue("EBX")

    if max_eax < eax :
        td=sd
        sd=ft
        ft=count
        third_eax = second_eax
        third_ebx = second_ebx
        second_eax = max_eax
        second_ebx = max_ebx
        max_eax = eax;  
        max_ebx = ebx;  
    elif second_eax < eax :
        td=sd
        sd=count
        third_eax = second_eax
        third_ebx = second_ebx
        second_eax = eax
        second_ebx = ebx
    elif third_eax < eax:
        td=count
        third_eax = eax
        third_ebx = ebx
Message("max eax: %d, ebx: %x, count %d, second eax: %d, ebx: %x, count %d, third eax: %d, ebx: %x, count %d\n" % (max_eax, max_ebx, ft, second_eax, second_ebx, sd, third_eax, third_ebx, td))

虽说chunks的大小和内容是随机的,但srand(),rand()并不是真的随机,每次程序运行seed值都是一样的,实际上是伪随机,每次跑出的结果都是一样的。运行结果每次第一二三大的chunks其count值,大小,内容都相同,也说明了这一点。

参考链接
https://hex-rays.com/products/ida/debugger/scriptable.shtml
http://blog.csdn.net/qq_19550513/article/details/72846279

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值