Project

General

Profile

[OT] unable to assign ip address to the system using "system" function using cgi c programming

Added by neethu 2 months ago

Hi,

I have a problem while setting IP address to the system using "system" command in cgi C . when i run the same code directly from the system the IP is getting updated but when i tried to update through web server it is not working.
I'm attaching the code with this. Can you please heslp me wih this

Thanks regards

Neethu

ipv1.c (1.49 KB) ipv1.c Cgi c script for setting IP address

Replies (4)

RE: unable to assign ip address to the system using "system" function using cgi c programming - Added by gstrauss 2 months ago

This request for help is "not working". Provide more details. "Not working" with no other details is pretty useless.

Why are you writing this in C instead of as a simple shell script? Your C code is insecure. Your fgets() is vulnerable to a stack buffer overflow.

RE: unable to assign ip address to the system using "system" function using cgi c programming - Added by neethu about 2 months ago

I wrote the code in C because i wanted to use CGI C for backend programming.

I wanted to know whether i have to give any permission in lighttpd for this "system" function execution. Because it is running succefully as a normal C code but only thing is when i execute this through lighttpd CGI C program the return value of system function is non zero ( as system function returns ) on success and non zero value on failure ). Do we need to give any permission for lighttpd???

RE: [OT] unable to assign ip address to the system using "system" function using cgi c programming - Added by gstrauss about 2 months ago

I wanted to know whether i have to give any permission in lighttpd for this "system" function execution.

No, not for system() use in general, but the specific command you are executing to reconfigure networking does requires privileges.

You're clearly out of your depth here, writing insecure code, unaware that the commands you are running need to run with root privileges, and more specifically attempting to reconfigure networking via an HTTP request which might be made over the network being reconfigured.

Please start much smaller and get much simpler things working, like a basic CGI program which does not require privileges, before proceeding further.

If I had to guess, I would guess this is a school coding assignment that someone came up with. Just about everything about it is ill-advised. Please don't ask further questions about this here.

RE: [OT] unable to assign ip address to the system using "system" function using cgi c programming - Added by neethu about 2 months ago

I have given the root prvilage and everything for this before posting the question over here..Then also it was not working.simple CGI programs i wrote and executed also. I wanted to change my board IP through my web GUI.Kind of embedded GUI.. C executables takes less memory for that only i am using my cgi C.

    (1-4/4)