惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
C
Check Point Blog
有赞技术团队
有赞技术团队
H
Help Net Security
V
Vulnerabilities – Threatpost
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 最新话题
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 【当耐特】
爱范儿
爱范儿
I
InfoQ
V
Visual Studio Blog
O
OpenAI News
Google DeepMind News
Google DeepMind News
S
Security Affairs
T
Troy Hunt's Blog
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
N
Netflix TechBlog - Medium
Latest news
Latest news
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Webroot Blog
Webroot Blog
S
Schneier on Security
MongoDB | Blog
MongoDB | Blog
T
Tor Project blog
V2EX - 技术
V2EX - 技术
Security Latest
Security Latest
Cloudbric
Cloudbric
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
S
Securelist
C
Cisco Blogs
博客园_首页
TaoSecurity Blog
TaoSecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Proofpoint News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Threat Research - Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts

WangDeer

非机动车交通规则测验 微软 50 周年壁纸是在 macOS上设计的? 「转」西二旗折叠:蜂巢经济学启示录 难得空明 Ubuntu Clean ApidocJs apigroup Support Chinese int(10)里面的10是什么意思? 5-3 会话 2021-03-25 「PHP架构师」面试准备 Laravel 上传 Docx 文件,表单验证不通过 4-4 发送信号 4-3 信号集 4-2 编写中断信号处理程序 2022-03-10 面试复盘 4-1 什么是中断信号(软中断) 3-7 进程查看 3-5多进程编写 3-4进程调度 3-3进程exec 3-2进程退出和回收 3-1进程标识与fork 2-3解释器文件 2-2命令行参数与环境参数表 2-1程序与进程 1-1课程介绍 终极复盘 第八章 传承篇 第七章 自由篇 第六章 品牌篇 第五章 作品篇 第四章 定位篇 第三章 金钱篇 第二章 富人篇 第一章 财务自由篇 财富思维觉醒课前作业 This Set Cookie Was Blocked Because It Was Not Sent Over a Secure Connection 「转」Windows11右键恢复至Windows10模式 Ecshop 4.0 微信登录 一直循环授权登录 PHP判断指定日期是否为工作日 PHP Ajax 跨域请求允许多个域名 返回键劫持,强制跳转到指定链接 Chromium Adobe Flash Player下载 批量检查并清除BOM头 Ecshop之smarty与js冲突问题 Ecshop 广告位宽度值必须在1 1024之间 修改方法 PHP获取指定时区当前时间-PHP获取世界时钟 phpcms 更新栏目缓存 `PHP Has Encountered a Stack Overflow` 解决办法 php判断是否手机访问-php判断访问终端类型 丢了 如果昨天是明天的话就好了,这样今天就周五了 Ecshop自定义调用指定广告位 Destoon修改商务便签文字 Ecshop首页获取指定分类的推荐商品 QQ空间如何屏蔽好友刷屏广告 Css实现文字竖排 英尺(inch)、厘米(cm) JS转换 网页禁止鼠标右键 Destoon 选择支付方式 可单独关闭对联广告两枚 网页打开不是在最顶部,而是跳到中间位置解决方法 Ecmall iis 伪静态规则 Destoon 复制商城模块 QQ在线客服设置 QQ开启临时会话教程 Ecshop加入购物车js报错 IE浏览器“浏览器模式”和“文本模式” 网站图片在IE浏览器下不显示 Ecshop 去掉头部版权信息 echsop “transport.js/run() error:'process_request' 未定义”-解决方法 Ecshop Deprecated:Assigning the Return Value of New by Reference Is Deprecated in 报错解决方法 PHPCMS全局循环调用二级类目导航 如何使EditPlus打开tpl文件高亮显示代码 Ecshop前台英文后台中文实现方法 Ecshop安装报错warning:date_default_timezone_get() 1970年1月1日(00:00:00 GMT)Unix时间戳(Unix Timestamp) 黑莓bb微信 2.6 for os5 黑莓微信内测版问题总结及开发建议 360安全卫士卸载过程 管理距离AD值(Administrative Distance) 思科在中国的总代及金牌、银牌代理商 黑莓7100T拆机全程实录 CCNA静态路由配置实例 8700G国产壳白色,太粗糙了 黑莓7100T玉照曝光 黑莓手机电池的正确使用和保养 51啦统计不能打开,求分析,求解释 处女作,黑莓8707G4.2主题出炉 我的2011 Xweibo手机版底部版权修改 常用ping地址,逗逗搜索引擎,SEO必备 飞飞影视系统快播播放列表前缀修改 飞飞影视系统title修改 这才整明白啥叫被跨省,上网有风险,发帖需谨慎 为emlog添加Gravatar头像服务功能 三层交换机实现VLAN间通信 路由器的基本配置 路由器接口类型及连接方式 19岁双IE 谈Cisco认证 Secondary IP-Address 用途 儿童节NA战报 CCNA疑难解析之network x.x.x.x
3-6 SUID特权进程
王二 · 2022-03-08 · via WangDeer

SUID、SGID 概念

The Unix access rights flags setuid and setgid (short for “set user ID” and “set group ID”) allow users to run an executable with the file system permissions of the executable’s owner or group respectively and to change behaviour in directories. They are often used to allow users on a computer system to run programs with temporarily(暂时、临时) elevated(提高) privileges in order to perform a specific task. While the assumed user id or group id privileges provided are not always elevated, at a minimum they are specific.

The flags setuid and setgid are needed for tasks that require different privileges than what the user is normally granted, such as the ability to alter system files or databases to change their login password. Some of the tasks that require additional privileges may not immediately be obvious, though, such as the ping command, which must send and listen for control packets on a network interface.

——setuid

效果:

The setuid and setgid flags have different effects, depending on whether they are applied to a file, to a directory or binary executable or non binary executable file. The setuid and setgid flags have an effect only on binary executable files and not on scripts (e.g., Bash, Perl, Python).

set user ID,set group ID 设置用户ID,设置组ID。

设置了 setuid 的程序就是一个特权程序了,启动之后就是一个特权进程。

当特殊标志 s 这个字符出现在文件拥有者的 x 权限位的时候就叫 setuid,简称SUID,或SUID特殊权限。

例如:


$ ls -al /usr/bin/passwd 
-rwsr-xr-x 1 root root 68208 7月  15  2021 /usr/bin/passwd

$ file /usr/bin/passwd 
/usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=6af93256cb810d90b2f96fc052b05b43b954f5b2, for GNU/Linux 3.2.0, stripped

SUID,SGID用途

一般,以 root 启动的程序都是超级进程,是一些重要的服务程序。

有时候我们经常是以普通用户来执行程序的,例如 www 用户。

但有时候普通进程需要访问一些特殊的资源,这时就需要提升权限来访问。

例如:linux 下 shadow 文件(包含系统用户密码信息),普通用户是无法查看,修改,删除的。但是 root 可以。


laradock@3a6c2da5a07b:/var/www$ cat /etc/shadow
cat: /etc/shadow: Permission denied

laradock@3a6c2da5a07b:/var/www$ ls -al /etc/shadow
-rw-r----- 1 root shadow 557 Jan 21 16:07 /etc/shadow

普通用户 laradock 可以通过 /usr/bin/passwd 这个 ELF 可执行文件修改 /etc/shadow 文件,因为普通用户拥有 /usr/bin/passwd 的可执行权限,并且 /usr/bin/passwd 是 SUID 特权程序,拥有 /etc/shadow 的读写权限。

如何设置 SUID

在可执行文件的权限 x 位上设置 chmod u/g/o + s elf file

在编写特权进程时,提权访问资源之后一定要把权限改回来。

PHP 示例:

<?php

$file = "pwd.txt";
$uid = posix_getuid();
$euid = posix_geteuid();

fprintf(STDOUT, "uid=%d,euid=%d\n", $uid, $euid);

// 这样设置是不行的
// 为啥不行?
// Set the effective user ID of the current process. This is a privileged function and needs appropriate privileges (usually root) on the system to be able to perform this function.
posix_setuid($uid);
posix_seteuid($euid);

$uid = posix_getuid();
$euid = posix_geteuid();

fprintf(STDOUT, "uid=%d,euid=%d\n", $uid, $euid);

if (posix_access($file,POSIX_W_OK)){

    fprintf(STDOUT,"我能修改...\n");
    $fd = fopen($file,"a");
    fwrite($fd,"php is the best ?\n");
    fclose($fd);

}else{
    fprintf(STDOUT,"我不能修改此文件...\n");
}

posix_access/access 检查用户是否对指定文件拥有某个权限。

提权前:


$ php demo10.php
uid=1000,euid=1000
uid=1000,euid=1000
我不能修改此文件...

$ cat pwd.txt

chmod u+s /usr/bin/php 提权后:


$ php demo10.php
uid=1000,euid=0
uid=0,euid=0
我能修改...

$ cat pwd.txt 
php is the best ?