原文地址:http://drops.wooyun.org/papers/3091

0x00 写在前面


在乌云zone里看到了《HFS 2.3x 远程命令执行(抓鸡黑客末日)》的文章,以前只是分析二进制漏洞,这种命令注入漏洞还是第一次分析,从网上下了HFS 2.3.279这个版本,运行起来之后,执行POC,四个calc就执行起来了。

poc:

http://localhost:80/?search==%00{.exec|calc.}

PS:分析到最后,google查找可执行模块中的字符串“parserLib”,才知道这个漏洞是CVE2014-6287。。。。。。一种淡淡的忧伤。不过还是说一下分析的过程吧。

0x01 准备工作


首先是分析前的一些准备工作,用PEiD查看了一下文件,加了asp的壳,通过PEiD通用脱壳器简单的进行脱壳。

enter image description here

enter image description here

通过IDA加载脱壳后的文件,看到一些函数如图,根据之前对c++中string类实现的认识,看来应该是使用了静态编译,字符串处理的库代码被静态链接到了可执行文件中。

enter image description here

通过PEid对脱壳后的文件进行编译器识别,识别为Borland Delphi 6.0 - 7.0,通过IDA加载相应的签名库,对函数进行签名,这样就能识别出大量的内联函数,方便分析。通过签名,已经可以识别出5636个内联函数,这样分析起来就方便很多。

enter image description here

enter image description here

0x02 分析过程


通过IDA查看文件导入函数,查找WinExec、ShellExecuteA等进程启动相关函数,通过交叉引用找到函数调用点,通过windbg设置断点,观察参数,确实是由ShellExecuteA启动了计算器。同时查看程序的调用栈。

enter image description here

enter image description here

通过调用栈,可已找到sub_531438函数,该函数解释了exec|calc命令,并启动了calc。对函数进行分析,可知该函数是对用户的命令进行解释执行的函数,相关代码如下。

enter image description here

继续通过调用栈,结合IDA对“exec|calc”的传递过程进行分析,找到

int __stdcall sub_51E268(signed char *** a1, int a2)

函数,**a1指向需要解释的字符串“\x00{.exec|calc.}”,其中int __cdecl sub_51DFA0(int a1)函数对“\x00{.exec|calc.}”对其进行分析并执行。

enter image description here

enter image description here

对于

http://localhost:80/?search=%20{.exec|calc.}

通过对比sub_51E268处**a1指向需要解释的字符串,可以看到{.|等字符都被编码了。

enter image description here

可见

http://localhost:80/?search=%00{.exec|calc.}

%00导致了{.exec|calc.}中的特殊字符转换失败,因此需要对转换函数进行定位。在模块中对“&#”字符串进行查找,定位得到

int __fastcall sub_528EB0(int a1, int a2)

完成对{|等字符进行转换。

enter image description here

sub_51E390做正则表达式匹配,查找{|等字符,当%20{.exec|calc.}传递给该函数时,该函数返回值为2。下面由

sub_4B827C、Sysutils::IntToStr

将字符转换为10进制字符串形式,最终替换掉原始字符串中的{。

enter image description here

enter image description here

对于

http://localhost:80/?search=%00{.exec|calc.}

sub_51E390返回值为0,因此后面的{|等字符不会被转换,最终导致了后面的命令执行。

enter image description here

查看

int __fastcall sub_51E390(int a1, int a2)

函数,可以看到“\\{[.:]|[.:]\\}|\\|”和“m!”,在分析的过程中,看到过字符串“parserLib”,就google一下。。。。。。。

enter image description here

enter image description here

查看该漏洞详情,可以看到和分析的结果一致,由于正则表达式的问题,导致了最终的远程代码执行。

enter image description here