6月 122011
 

问题: httpd server是用web用户执行的,如何才能通过httpd server来做root才能做到事情呢?

我想大概这样可以:
我们知道linux上到可执行文件到属主有一个s位,则该文件就可以seteuid到该用户到权限来做事情,于是写如下测试脚本:
====== agent.c=========
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(int ac, char ** av) {

seteuid(0);
printf("%d",  geteuid()); // 返回0
// 这里干活就是root的身份了
return 0;
}
========================
编译文件:
gcc -o agent agent.c

生成文件:
-rwxr-xr-x 1 root root 7213 2011-06-13 00:02 agent

修改文件属性:
chmod +s agent
-rwsr-sr-x 1 root root 7213 2011-06-13 00:02 agent

执行agent:
./agent
0

返回结果为0,说明提升权限成功了
——————————
问题: 按说如果添加来s位,则非属主用户不应该有写权限,换言之,如果非属主用户有来写权限,则s位应该无效;但事实上, chmod a+w agent 后,提升权限还是成功来,为什么?

 Posted by at 上午 10:33

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据