XYM让看一下ionCube,一款PHP加密工具。有试用版Encoder,Decoder是免费的。
$ cd /home/scz/src/php
$ php -c php.ini -f hello.php
Hello World
$ ./ioncube_encoder_xxx_64 hello.php -o hello_enc.php
Error: The Encoder evaluation period has expired.复制
一个月前还可以试用ionCube Encoder,中间去支持其他逆向工程的活儿,回来再测就提示试用结束。
在"ioncube_encoder_evaluation/EVALUATION-README.txt"中看到
* WHAT IS DIFFERENT IN THE EVALUATION VERSION?
All features of the evaluation Encoder are fully functional, however:
1) Encoded files will expire after 36 hours, or sooner if you encode files to
expire earlier. Files can be encoded again to continue testing.
2) Encoded files contain a PHP comment to show they are encoded by the
evaluation Encoder. This text does not alter operation of encoded files,
and is not present in the release version.
* HOW LONG IS THE EVALUATION PERIOD?
The evaluation version will be functional for 14 days.复制
意思是hello_enc.php只有36小时可用,试用版Encoder本身只有14天可用,先剁后者。
strace -v -i -f -ff -o ioncube_encoder_xxx_64.log ./ioncube_encoder_xxx_64 hello.php -o hello_enc.php
复制
在strace日志中看到,用exit_group(101)退出
gdb -q -nx -x /tmp/gdbinit_x64.txt -x "/tmp/ShellPipeCommand.py" -x "/tmp/GetOffset.py" -ex 'display/5i $pc' ./ioncube_encoder_xxx_64
info files
b *0x4046a8
r hello.php -o hello_enc.php复制
目标ELF没有_start符号,只能用地址设断。命中_start()后增设断点
catch syscall exit_group
(gdb) c
Continuing.
Error: The Encoder evaluation period has expired.
Catchpoint 2 (call to syscall exit_group), 0x00007ffff75ccc99 in _exit () from /lib64/libc.so.6
1: x/5i $pc
=> 0x7ffff75ccc99 <_exit+57>: cmp rax,0xfffffffffffff000
0x7ffff75ccc9f <_exit+63>: jbe 0x7ffff75ccc80 <_exit+32>
0x7ffff75ccca1 <_exit+65>: mov esi,eax
0x7ffff75ccca3 <_exit+67>: neg esi
0x7ffff75ccca5 <_exit+69>: mov DWORD PTR fs:[r10],esi
(gdb) bt
#0 0x00007ffff75ccc99 in _exit () from /lib64/libc.so.6
#1 0x00007ffff7540cfb in __run_exit_handlers () from /lib64/libc.so.6
#2 0x00007ffff7540d87 in exit () from /lib64/libc.so.6
#3 0x000000000040e13f in ?? ()
#4 0x00000000004116ef in ?? ()
#5 0x00007ffff7529555 in __libc_start_main () from /lib64/libc.so.6
#6 0x00000000004046d1 in ?? ()
...
(gdb) info proc mappings
process 22078
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x400000 0x540000 0x140000 0x0 /home/scz/src/php/ioncube_encoder_xxx_64
...
0x744000 0x771000 0x2d000 0x0 [heap]
...
0x7ffff7507000 0x7ffff76cb000 0x1c4000 0x0 /usr/lib64/libc-2.17.so
...复制
先输出过期提示再退出。"b _exit"断不下来,因为ld-.so抢先提供了符号_exit,我们需要断libc中的_exit()。
(gdb) info symbol _exit
_exit in section .text of /lib64/ld-linux-x86-64.so.2复制
从strace日志看,只有一个write(2,x),还可以设断
catch syscall write
复制
不用针对句柄设条件断点。
(gdb) bt
#0 0x00007ffff75f6a90 in __write_nocancel () from /lib64/libc.so.6
#1 0x00007ffff75812f3 in _IO_new_file_write () from /lib64/libc.so.6
#2 0x00007ffff7581b90 in __GI__IO_file_xsputn () from /lib64/libc.so.6
#3 0x00007ffff757605b in fputs () from /lib64/libc.so.6
#4 0x000000000040d1e2 in ?? ()
#5 0x000000000040e01c in ?? ()
#6 0x00000000004116d5 in ?? ()
#7 0x00007ffff7529555 in __libc_start_main () from /lib64/libc.so.6
#8 0x00000000004046d1 in ?? ()
...
(gdb) i r rdi
rdi 0x2 2
(gdb) x/s *(char**)0x744ca0
0x76cb50: "Error: The Encoder evaluation period has expired.\n"复制
过期提示被加密混淆后存放在ELF中,strings直接找不到,一种简单的反静态分析手段。
通过前述两组调用栈回溯在IDA中定位位于main()中的关键调用:
(gdb) x/1i 0x410eb7
0x410eb7: call 0x4de4d0
(gdb) x/7i 0x4de6b4
0x4de6b4: jne 0x4de6c4
0x4de6b6: add rsp,0x88
0x4de6bd: pop rbx
0x4de6be: pop rbp
0x4de6bf: pop r12
0x4de6c1: pop r13
0x4de6c3: ret复制
凭经验判断0x4de4d0处的函数在做过期检查,该函数中有肉眼可见的MD5特征常量,但我未细究函数代码逻辑;0x4de6c3是其返回点,在返回点处让eax恒为0,应该能避免过期退出。
gdb -q -nx -x /tmp/gdbinit_x64.txt -x "/tmp/ShellPipeCommand.py" -x "/tmp/GetOffset.py" -ex 'display/5i $pc' ./ioncube_encoder_xxx_64
b *0x4de6c3
commands $bpnum
silent
set $eax=0
c
end
r hello.php -o hello_enc.php复制
测试经ionCube加密过的hello_enc.php,无误。
$ php -c php.ini -f hello_enc.php
Hello World复制
静态Patch试用版ioncube_encoder_xxx_64
$ rasm2 -a x86 -b 64 -s intel -o 0x4de6b4 "xor eax,eax"
31c0
$ rasm2 -a x86 -b 64 -s intel -o 0x4de6b4 -D 31c0
0x004de6b4 2 31c0 xor eax, eax
$ fc /b old new
000DE6B4: 75 31
000DE6B5: 0E C0
$ ./ioncube_encoder_xxx_64_scz hello.php -o hello_enc.php复制
如有类似需求,理解逆向思路后自行Patch相应版本Encoder,切勿直接照搬。
文章转载自青衣十三楼飞花堂,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年4月中国数据库流行度排行榜:OB高分复登顶,崖山稳驭撼十强
墨天轮编辑部
1555次阅读
2025-04-09 15:33:27
2025年3月国产数据库大事记
墨天轮编辑部
791次阅读
2025-04-03 15:21:16
2025年3月国产数据库中标情况一览:TDSQL大单622万、GaussDB大单581万……
通讯员
568次阅读
2025-04-10 15:35:48
征文大赛 |「码」上数据库—— KWDB 2025 创作者计划启动
KaiwuDB
480次阅读
2025-04-01 20:42:12
数据库,没有关税却有壁垒
多明戈教你玩狼人杀
447次阅读
2025-04-11 09:38:42
国产数据库需要扩大场景覆盖面才能在竞争中更有优势
白鳝的洞穴
430次阅读
2025-04-14 09:40:20
最近我为什么不写评论国产数据库的文章了
白鳝的洞穴
354次阅读
2025-04-07 09:44:54
天津市政府数据库框采结果公布!
通讯员
333次阅读
2025-04-10 12:32:35
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
285次阅读
2025-04-17 17:02:24
优炫数据库成功入围新疆维吾尔自治区行政事业单位数据库2025年框架协议采购!
优炫软件
283次阅读
2025-04-18 10:01:22