[질문] Bash version 2에서의 system() 사용시, suid(sgid) drop

superkdk의 이미지

web 상에서 파일이나 폴더를 핸들링하기 위한 cgi application이 있습니다.

복사, 이동, 압축 등을 처리하기 위해서 system() 함수를 사용한다고 했을 때,
bash version 2에서는 /bin/sh로 system 명령어를 실행시킬 때,
suid/sgid 권한을 드롭시키고 실행이 됩니다.

따라서 4755로 cgi에 suid를 걸고 실행시켜도, bash version 2에서는
제대로 처리가 되지 않습니다. copy, move 같은 경우에는 따로 함수로
만들어서 처리해도 큰 문제가 없지만, 압축 등의 경우에는 그렇게 처리하는게
비효율적으로 생각됩니다.

정리해서, bash version 2 환경에서 system (or pipe) 함수 실행시에
suid 권한을 가지고 실행될 수 있도록 처리할 수 있는 방법을 알려주세요.

좋은 하루보내세요... ^^

cinsk의 이미지

RTFM!

man 3 system wrote:

Do not use system() from a program with suid or sgid privileges, because strange values for some environment variables might be used to subvert system integrity. Use the exec (3) family of functions instead, but not execlp (3) or execvp (3). system() will not, in fact, work properly from programs with suid or sgid privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup. (Debian uses a modified bash which does not do this when invoked as sh .)