Skip to contentSkip to conversation

iptables permission problem in perl scripts

DISCUSSION afshin lamei 5 participants 5 messages Aug 14, 2005 – Aug 15, 2005

lore
Share & tools
lore
#0 lore raw

Dear all,
I have a cgi script, which uses some perl scripts in which i'm running iptables command using "system" function, like this:
myfile.pl:
......
system("iptables -F FORWARD")
......

the cgi file is owned by root/root and is run by user nobody. myfile.pl is owned by root/root, and I've it setuid (chmod u+s myfile.pl ; chown root:nobody myfile.pl) to be able to run iptable commands, but it returns this error:
/////
modprobe: Can't locate module ip_tables.
iptables v1.2.11: can't initialize iptables table `nat': Permission denied (you must be root) perhaps iptables or your kernel needs to be upgraded.
/////
what's the solution?
thanks a lot
afshin lame

#1 lore raw
Quoted 8 lines · afshin lamei

Dear all,
I have a cgi script, which uses some perl scripts in which i'm running iptables command using "system" function, like this:
myfile.pl:
......
system("iptables -F FORWARD")
......

Quoted 11 lines

the cgi file is owned by root/root and is run by user nobody. myfile.pl is owned by root/root, and I've it setuid (chmod u+s myfile.pl ; chown root:nobody myfile.pl) to be able to run iptable commands, but it returns this error:
/////
modprobe: Can't locate module ip_tables.
iptables v1.2.11: can't initialize iptables table `nat': Permission denied (you must be root) perhaps iptables or your kernel needs to be upgraded.
/////
what's the solution?

Use "sudo"

You can grant apache permission or another user etc.

Signature · 6 lines
Kind Regards,

Gavin Henry.
Open Source. Open Solutions(tm).

http://www.suretecsystems.com/
#2 lore raw
In reply to afshin lamei

Can we get an ls -l of the files in question? What is the user that the web server is running as?

Grant. . . .

Quoted 21 lines · afshin lamei

Dear all,
I have a cgi script, which uses some perl scripts in which i'm running iptables command using "system" function, like this:
myfile.pl:
......
system("iptables -F FORWARD")
......

the cgi file is owned by root/root and is run by user nobody. myfile.pl is owned by root/root, and I've it setuid (chmod u+s myfile.pl ; chown root:nobody myfile.pl) to be able to run iptable commands, but it returns this error:
/////
modprobe: Can't locate module ip_tables.
iptables v1.2.11: can't initialize iptables table `nat': Permission denied (you must be root) perhaps iptables or your kernel needs to be upgraded.
/////
what's the solution?
thanks a lot
afshin lame

#4 lore raw
In reply to afshin lamei
Quoted 5 lines

the cgi file is owned by root/root and is run by user nobody. myfile.pl is owned by root/root, and I've it setuid (chmod u+s myfile.pl ; chown root:nobody myfile.pl) to be able to run iptable commands, but it returns this error:

To run suid perl scripts, you must
- chmod u+s the script AND
- use "suidperl" AND
- have suidperl being u+s

And it's the biggest security hole as everyone says - does not [yet] reflect my opinion, though. So use some sudo magic (as recommended) if possible.

Jan Engelhardt

#3 lore raw
In reply to Grant Taylor
Quoted 2 lines · Grant Taylor

Can we get an ls -l of the files in question? What is the user that the web server is running as?

The OP said it was "nobody". It's not a file permission issue; it is the fact that only root can manipulate the kernel's netfilter rules. SUID (messy and risky) or sudo(1) (clean and possibly less risky if done right) are really the only solutions.

Signature · 2 lines
    mail to this address is discarded unless "/dev/rob0"
    or "not-spam" is in Subject: header