Autor |
Nachricht |
Sebastian R.
Anmeldungsdatum: 22.11.2006 Beiträge: 3
|
Verfasst am: 02. Dez 2006 13:27 Titel: Korrektur meines Tutorials |
|
|
Hallo,
ich habe eines meiner Tutorials(, die ich für meine Homepage geschrieben habe) ins Englische übersetzt und wollte euch mal fragen, ob ich denn irgendwo Fehler eingebaut habe. Ich würde mich sehr freuen, wenn ihr mir über mögliche grammatikalische Fehler Auskunft geben könntet.
Code: | How to gain root rights with exec() in PHP
by Sebastian R.
Preface
In case you want to execute a command on your server using PHP, you have to use functions like exec() or system(). Unfortunately these commands are executed with the rights of the so-called nobody user. This tutorial will show you how to gain root rights with those functions.
In order to use the root account, we will use the program sudo, which should be installed on every Linux system.
Let’s go – Change the /etc/sudoers file
(Before we can use sudo to execute commands, we have to change the file /etc/sudoers. Open this file with an editor like joe or nano.)
Search for the following line:
root =(ALL) ALL
Below this line, add the following two lines:
nobody =(ALL) NOPASSWD: ALL
www =(ALL) NOPASSWD: ALL
Both the www and nobody users, are now allowed to execute root commands.
How to use sudo in your scripts
With the following syntax, you can execute commands with the root account of your server:
exec(„sudo command“);
(Replace command with your commands.) Let’s have a look at the following example.
exec(„sudo mkdir test“);
This code creates a new directory by using the sudo program.
Warning: This method is dangerous
This is one working method on how to gain root rights in PHP scripts. Please consider that every script using sudo has root rights now. That’s very dangerous, especially if your scripts aren’t protected against code injection.
To prevent yourself from being hacked, you can only allow a few commands to be executed with root rights. In order to add only one or two commands, just replace the last ALL with a list of commands. Example:
nobody =(ALL) NOPASSWD: /usr/bin/mkdir
Using this syntax, your scripts only can use the mkdir command.
|
Danke schonmal im Voraus, Sebastian R. |
|
|
MI Administrator
Anmeldungsdatum: 22.01.2005 Beiträge: 1140 Wohnort: München
|
Verfasst am: 02. Dez 2006 15:54 Titel: |
|
|
Beim Überfliegen ist mir nur der letzte Satz aufgefallen.
Es müsste glaube ich heißen: "Your scripts can only use the mkdir command".
Und vielleicht noch ein fehlender Doppelpunkt hinter "How to use sudo in your scripts".
Gruß
MI |
|
|
Sebastian R.
Anmeldungsdatum: 22.11.2006 Beiträge: 3
|
Verfasst am: 02. Dez 2006 17:18 Titel: |
|
|
Danke schonmal für den Tipp, hab ich gleich verbessert.
Hinter das "How to use sudo in your scripts" muss kein Doppelpunkt, da das im fertigen Tutorial als Überschrift dargestellt wird (also fett und zentriert).
Für weitere Tipps bin ich dankbar. |
|
|
ACH
Anmeldungsdatum: 26.01.2006 Beiträge: 117
|
Verfasst am: 03. Dez 2006 09:12 Titel: |
|
|
"In case you want to ...." ist zwar verstaendlich, aber nicht elegant: "Should you want to..., ... you will have to ...." ist besser.
Anstatt "Please consider..." wuerde ich "Please be aware that..." verwenden, da dass den hinweisende Character des Satzes besser ausdrueckt.
"To prevent yourself from being hacked" ist zwar grob korrekt, aber richtigerweise ist es ja der Server der gehackt wird, also "To prevent your server from being hacked/ broken in to."
Ausserdem wuerde ich den Satzbau von "...you can only allow a few commands...." veraendern: "allow only a few" ist englischer, meiner Meinung nach.
Gleiches gilt fuer den letzten Satz: "....only your scripts can use..." ist besser.
Hope that has helped somewhat,
ACH _________________ A Stór Mo Chroí, when you're far away//Far from the land you'll be leaving, // It's many a time by night and by day// That your heart will be sorely grieving.
---Irish patriotic song (Brian O'Higgins) |
|
|
Sebastian R.
Anmeldungsdatum: 22.11.2006 Beiträge: 3
|
Verfasst am: 04. Dez 2006 18:25 Titel: |
|
|
Hi ACH,
danke für deine Tipps - ihr habt beide sehr geholfen.
MfG, Sebastian. |
|
|
|