免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2328 | 回复: 4
打印 上一主题 下一主题

[系统管理] Linux SUID提权失败? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-18 10:20 |只看该作者 |倒序浏览
本帖最后由 dxcheng 于 2016-02-18 10:20 编辑

最近读到《The Shellcoder's Handbook》一书的"Using an Exploit to Get Root Privileges"这一部分使用SUID获取Root权限。但是我这边试了一下却还是没有得到Root权限,请大神们指教,谢谢!
  1. // shell.c
  2. int main(){
  3.         char *name[2];
  4.         name[0] = “/bin/sh”;
  5.         name[1] = 0x0;
  6.         execve(name[0], name, 0x0);
  7.         exit(0);
  8. }
复制代码
If we compile this code and run it, we can see that it will spawn a shell for us.
[jack@0day local]$ gcc shell.c -o shell
[jack@0day local]$ sudo chown root shell
[jack@0day local]$ sudo chmod +s shell
[jack@0day local]$ ./shell
sh-2.05b#

我这边的结果还是普通用户的权限:
$./shell
sh-4.1$

系统环境如下:
$uname -a
Linux centos_12 2.6.32-279.el6.i686 #1 SMP Fri Jun 22 10:59:55 UTC 2012 i686 i686 i386 GNU/Linux

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
2 [报告]
发表于 2016-02-18 15:09 |只看该作者
http://unix.stackexchange.com/qu ... e-no-effect-on-bash

If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in the environment, are ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
3 [报告]
发表于 2016-02-18 15:26 |只看该作者
  1. cat shell.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>

  6. // shell.c
  7. int main(){
  8.         char *name[2];
  9.         name[0] = "/usr/bin/id";
  10.         name[1] = 0x0;
  11.         printf("%d %d\n", getuid(), geteuid());
  12.         execve(name[0], name, 0x0);
  13.         exit(0);
  14. }
  15. $ ./shell
  16. 1000 0
  17. uid=1000(yjh) gid=1000(yjh) euid=0(root) groups=1000(yjh),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
复制代码
看结果只是euid变了。

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
4 [报告]
发表于 2016-02-18 15:28 |只看该作者
more clear info:

First and foremost, setuid bit simply allows a script to set the uid. The script still needs to call setuid() or setreuid() to run in the the real uid or effective uid respectively. Without calling setuid() or setreuid(), the script will still run as the user who invoked the script.

论坛徽章:
0
5 [报告]
发表于 2016-02-18 16:56 |只看该作者
回复 4# yjh777


You are right, thanks a lot.

Seems to be due to the security reason, the system and exec drop this privileges.
I add a invoking setuid(0) before the execve, and then I get the expected result.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP