root用户C程序中的setuid

root用户C程序中的setuid

本文介绍了为什么我需要与系统调用的管理程序一个setuid root用户C程序中的setuid(0)()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不做一个肮脏的Linux黑客某人因此,尽管是一个非root用户,他们可以开始与 cupsenable PrinterName的 shell命令打印机。我不想让他们能够使用 cupsenable 语法根的全部,所以我只是写一个C包装,进行消毒在的argv [1] 键,通话系统(cupsenable sanitizedprintername)

I had to do a dirty Linux hack for somebody so they could start a printer with the cupsenable printername shell command while being a non-root user. I didn't want them to be able to use the entirety of the cupsenable syntax as root, so I just wrote a C wrapper that sanitizes the input in argv[1] and calls system("cupsenable sanitizedprintername").

我制作的节目setuid root的,但即便如此, cupsenable 失败,拒绝权限。然后,我插入了一个的setuid(0))呼叫系统(和,你瞧,它的工作。

I made the program setuid root, but even so, cupsenable failed with "permission denied". Then I inserted a setuid(0) call before system() and, lo and behold, it worked.

忽略那里是一个更好的方法,让打印机的用户控制的问题。有可能是一个更好的办法。我很感兴趣的是 CHMODü+ S 主场迎战的setuid(0)与<$错综复杂C $ C>系统()。为什么它的行为呀?

Disregard the issue of there being a better way to give users control of the printer. There probably is a better way. What I'm interested in are the intricacies of chmod u+s vs. setuid(0) vs. system(). Why did it behave that way?

推荐答案

人系统

不要使用系统()从设置用户ID或设置组ID的权限,程序,因为一些环境变量奇怪的值可以用来颠覆系统的完整性。使用执行exec(3)系列函数代替,但不能 execlp(3) execvp(3)系统()不会,事实上,正确地从与设置用户ID或程序设置组ID权限在其上系统的工作/ bin / sh的是bash的第2版,因为bash的2滴在启动权限。

和从男人庆典

如果shell启动的有效用户(组)ID不等于真正的用户(组)ID和 -p 选项,不提供,不启动文件被读取,shell函数不会从环境中继承,在 SHELLOPTS 变量,如果它出现在环境中,被忽略,有效用户ID设置为实际用户ID。

看来你的的setuid(0)通话规避这种保护。

It appears your setuid(0) call circumvented that protection.

这篇关于为什么我需要与系统调用的管理程序一个setuid root用户C程序中的setuid(0)()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:30