一次菜鸟级二进制逆向

某次在 windows 上升级 aria2c 时忘记在用的是改过最大线程数的版本,一不小心覆盖掉了,然而那个版本确实有些久远了(上次的详情),何不拿最新版重新修改一份呢!

虽然咱是菜鸟,工具要准备好哦。Radare2(可选 GUI Cutter)和 IDA 免费版杀人越货必备神器。

0x0

首先前往 GitHub 下载到最新版本 aria2c.exe。然后来观察下,启动 aria2c 时指定线程数多于 16 会发生什么吶:

C:\Tools\aria2\> .\aria2c.exe --max-connection-per-server=32
Exception: [AbstractOptionHandler.cc:69] errorCode=28 We encountered a problem while processing the option '--max-connection-per-server'.
  -> [OptionHandlerImpl.cc:184] errorCode=1 max-connection-per-server must be between 1 and 16.
Usage:
 -x, --max-connection-per-server=NUM The maximum number of connections to one
                              server for each download.

                              Possible Values: 1-16
                              Default: 1
                              Tags: #basic, #http, #ftp

很好,打印出了错误信息,抛出异常的位置,以及正确的用法。OptionHandlerImpl.cc 抛出的错误信息看起来应该是按条件拼凑而成,追踪分析多半很困难,正确用法的说明 The maximum number of... 这一大段描述文本,猜测应该是作者手写的字符串,从这里开始搜索分析应该不难。

0x1

进入 radare2,我们来搜索这段文本:

C:\Tools\aria2\> r2 .\aria2c.exe
-- ❤️ --
[0x004014e0]> / The maximum number of connections
Searching 33 bytes in [0x8eb200-0x8ec000]
hits: 0
Searching 33 bytes in [0x8eb000-0x8eb200]
hits: 0
Searching 33 bytes in [0x8ea200-0x8eb000]
hits: 0
Searching 33 bytes in [0x8ea000-0x8ea200]
hits: 0
Searching 33 bytes in [0x8e7000-0x8ea000]
hits: 0
Searching 33 bytes in [0x8e2000-0x8e7000]
hits: 0
Searching 33 bytes in [0x8e1200-0x8e2000]
hits: 0
Searching 33 bytes in [0x8a3000-0x8e1200]
hits: 0
Searching 33 bytes in [0x8a2200-0x8a3000]
hits: 0
Searching 33 bytes in [0x87b000-0x8a2200]
hits: 0
Searching 33 bytes in [0x7f5000-0x87b000]
hits: 1
Searching 33 bytes in [0x7f4600-0x7f5000]
hits: 0
Searching 33 bytes in [0x7ee000-0x7f4600]
hits: 0
Searching 33 bytes in [0x7ed600-0x7ee000]
hits: 0
Searching 33 bytes in [0x401000-0x7ed600]
hits: 0
0x00804655 hit0_0 .-per-server=NUM The maximum number of connections to one        .
[0x004014e0]>

哇哦,最后一行,我们找到了这一串文本的地址 0x00804655

0x2

现在进入 IDA 搜索引用,按 G 定位至 0x00804655
Screenshot_20200328_230940.png
可以看到这里有一处数据交叉引用 sub_4C2040,继续跟上:
Screenshot_20200328_232538
有三处常量写入内存 [rsp+188h+var_158][rsp+188h+var_160] 以及 [rsp+188h+var_168]。注意这里是文本 0x00804655 唯一的引用,--max-connection-per-server 参数的上下限检查应该就在附近。关注这里写入内存的两个常量 110h,正好是上下限 1-16,猜测有可能正是目标值。

0x3

修改 0x4c3d70 指令的值为 0FFh,导出 exe 尝试运行,传入参数 32 可以正常运行!好咯,任务达成,最大线程数修改为 256!


0xf

网上搜索偶尔看到有神人只用 vim 就能 hack 二进制,佩服的不要不要😂大体上是这样做的,在 vim 里 :%!xxd 把程序转十六进制文本,然后猜测关键逻辑的指令,用一串 opcode 去搜索到目标,改完后再 :%!xxd -r 转回二进制保存。

Show Comments