php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #16733 posix_getpw* bypasses safe_mode and open_basedir
Submitted: 2002-04-22 12:53 UTC Modified: 2005-01-31 23:21 UTC
Votes:14
Avg. Score:4.3 ± 1.1
Reproduced:6 of 10 (60.0%)
Same Version:5 (83.3%)
Same OS:6 (100.0%)
From: veins at skreel dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.0 OS: Unix
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: veins at skreel dot org
New email:
PHP Version: OS:

 

 [2002-04-22 12:53 UTC] veins at skreel dot org
I noticed that many of the posix_* functions DO NOT check wether safe_mode or open_basedir restrict access to the user database thus allowing a user to rebuild a complete /etc/passwd without permissions to read /etc/passwd or access the /etc directory.

This is dangerous in some cases where login are kept secret as it allows a user to know what accounts have what privileges and what accounts have access to a shell or not.
For now there is only one thing to do, disable these functions but i'm pretty sure that adding checks to see values of safe_mode and/or open_basedir would be a nice thing to do.

Here's a script that rebuilds /etc/passwd when safe_mode is enabled and open_basedir is set to the user homedirectory:

<?
    for ($i = 0; $i < 60000; $i++)
      {
        if (($tab = @posix_getpwuid($i)) != NULL)
          {
            echo $tab['name'].":";
            echo $tab['passwd'].":";
            echo $tab['uid'].":";
            echo $tab['gid'].":";
            echo $tab['gecos'].":";
            echo $tab['dir'].":";
            echo $tab['shell']."<br>";
          }
      }
?>

On a very large system, if an execution time is set, this will not end up, but hopefully the posix_getpwent() function is missing so the user has to go through all possible uid's.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-25 00:30 UTC] veins at skreel dot org
I think that it shouldn't take too long to add the following checks, maybe I can try helping if you are all busy:

- in case safe_mode is on and script doesn't run as root, then disallow the posix_get* functions.

- in case open_basedir restricts access to /etc then the posix_get* functions should be working neither.
 [2002-05-20 11:29 UTC] mfischer@php.net
ext/posix should not be used in environments where safe_mode is needed, this is documented and will show up shortly in the manual.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Apr 28 01:01:28 2025 UTC