I put this file in cgi-bin folder of Apache server. Here is my problem : when I run this file with shell as root user it makes change to iptables, but when I use my browser to run this file, it doesn’t make any change. I’m sure this is because Apache doesn’t have permission to manipulate iptables.
How can I start Apache as a user with root privileges ?
Any suggestion will be appreciated.
Also… YIKES!!! Hopefully this is not the end of the line with regard
to this script. Setting wwwrun to be able to do ANYTHING without a
password is a terrible, terrible idea. You can easily limit sudoers to
make apache ONLY able to modify the iptables command. Maybe even better,
put that command in a script so that apache only has sudo access to that
script and that script only does the one thing with iptables (so somebody
doesn’t somehow use wwwrun to tweak your firewall without you knowing).
Good luck.
On 07/17/2010 09:56 AM, ken yap wrote:
>
> You have to explicitly run the program under sudo, it doesn’t
> automatically make any command privileged. I.e.:
>
> system(“sudo iptables …”);
>
> You might want to restrict the commands that can be run under sudo to
> just this one, for safety reasons.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
Mortezz, glad to hear things are working. As mentioned earlier you ought to consider restricting wwwrun to only being able to run the needed command(s) as root. Here is something like what I think you should add to sudoers to make what you’re doing a little safer.
wwwrun ALL=(root) NOPASSWD: /usr/sbin/iptables
This allows wwwrun to run just iptables as root without needing a password.
Going further, would be even better to give wwwrun sudo access to only a specific script instead of iptables entirely.
Also, you can put the arguments required by your iptables command in /etc/sudoers. Then the invocation must match exactly those arguments, saving you an intermediate script.