

linux下如何自动提升权限
source link: https://blogread.cn/it/article/3784?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

linux下如何自动提升权限
问题: httpd server是用web用户执行的,如何才能通过httpd server来做root才能做到事情呢?
我想大概这样可以:
我们知道linux上到可执行文件到属主有一个s位,则该文件就可以seteuid到该用户到权限来做事情,于是写如下测试脚本:
====== agent.c=========
#include
#include
#include
#include
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,说明提升权限成功了
------------------------------
问题: 按说如果添加来s位,则非属主用户不应该有写权限,换言之,如果非属主用户有来写权限,则s位应该无效;但事实上, chmod a+w agent 后,提升权限还是成功来,为什么?
建议继续学习:
扫一扫订阅我的微信号:IT技术博客大学习
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK