9

Can PHP move and edit root system files on a server?

 2 years ago
source link: https://www.codesd.com/item/can-php-move-and-edit-root-system-files-on-a-server.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Can PHP move and edit root system files on a server?

advertisements

this might seem like a stupid question but I've Googled to no avail.

I've always thought of PHP as a language for creating dynamic database driven sites, and I've never thought about using it to move system files on the actual server (as I have never had a need to). My question is:

  1. can a standard PHP 5.3.x.x installation move, copy or edit system files (I'm using a Linux sever as an example) around in /bin or maybe /etc?
  2. is this a good idea/practise?

It has never occurred to me that if a malicious hacker were to be able to inject some PHP into a site, that they would effectively be granted access to the entire Linux server (and all its system files). I have only ever thought of PHP as something that operates inside the /vhosts directory (perhaps naively).

Sorry if this sounds like a stupid question, but I can't really test my theory as if my boss was to see me writing/uploading/executing a script that moved stuff around in the Linux file system I would be dead.

Thanks for your help guys! :)


PHP can to your server whatever the permissions of the user account it runs as allow it to do. PHP as a language is not restricted in any way (at least, in terms of permissions), it is the user account that is restricted.

This is why people will usually create a user for Apache/nginx/insert web server here to run as, and only give it permissions to manipulate files and directories related to the web server. If you don't give this user access permissions to /bin or /etc, it's can't do anything that will affect them.

is this a good idea/practice?

Normally not. Leave system administration to your sysadmin and not the user requesting your PHP scripts.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK