php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17163 rename() bypasses safe_mode
Submitted: 2002-05-12 11:00 UTC Modified: 2002-05-12 11:42 UTC
From: ilia at prohost dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.0 OS: Linux 2.4.18
Private report: No CVE-ID: None
 [2002-05-12 11:00 UTC] ilia at prohost dot org
rename() function can be used to rename files a user has no access to according to safe_mode.

Ex.

touch test
<?php rename('test', 'test2'); ?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-12 11:18 UTC] rasmus@php.net
Actually, we allow a rename in a directory if that directory is owned by the same user id as the running script.  So this one is not a bug.  Verify this statement and re-open if you find that this is not the case.
 [2002-05-12 11:22 UTC] rasmus@php.net
Just to follow up on this because I can already see your mind working on how this might be exploited through a script making a copy of itself and now having the web server user id as its owner.  The theory is that the web server user id does not own any system critical directories and user directories are supposed to be owned by individual users so the only potential for an exploit would be a cloned script renaming something in a directory created by another user through a web interface, but that is a bit of a tradeoff I made on purpose way back when.
 [2002-05-12 11:38 UTC] ilia at prohost dot org
mkdir test;
ls -ld test drwxr-xr-x   2 forum    forum        4096 May 12 11:33 test

ls -l a.php
-rw-rw-rw-   1 www      www            44 May 12 10:57 a.php
a.php:
<?php rename('test', 'test3'); ?>

Script runs without errors, end result:

ls -ld test3 drwxr-xr-x   2 forum    forum        4096 May 12 11:35 test3
 [2002-05-12 11:39 UTC] ilia at prohost dot org
mkdir test;
ls -ld test drwxr-xr-x   2 forum    forum        4096 May 12 11:33 test

ls -l a.php
-rw-rw-rw-   1 www      www            44 May 12 10:57 a.php
a.php:
<?php rename('test', 'test3'); ?>

Script runs without errors, end result:

ls -ld test3
drwxr-xr-x   2 forum    forum        4096 May 12 11:35
test3

It works with files as well as directories.
 [2002-05-12 11:42 UTC] rasmus@php.net
Perhaps I didn't explain it well.  Safe-mode also checks the directory that a.php is in.  If the owner of a.php matches the owner of '.' then the rename is allowed.  
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Aug 07 10:00:03 2025 UTC