油炸小可爱|黑客大神谈一谈Linux与suid提权( 二 )
但经过测试我们发现 , 这个方法启动的shell似乎仍然是当前用户的 , 并没有我们想象中的提权 。
Linux发行版与shell我曾使用interactive模式提权成功 , 但是因为那个nmap版本过老 , 没有script支持 , 所以没法测试script的提权方法;同样 , 新的nmap支持script但又没有interactive模式 , 无法做直观对比 , 我只能先猜想提权失败的原因:
? nmap在高版本中限制了suid权限
? lua脚本中限制了suid权限
? 新版Linux系统对子进程的suid权限进行了限制
这些猜想中变量太多 , 所以我需要控制一下 。 首先我阅读了老版本nmap的源码 , 发现其实!sh执行的就是很简单的system('sh') , 而且前面并没用丢弃Effective UID权限的操作:
} else if (*myargv[0] == '!') { cptr = strchr(command, '!'); system(cptr + 1);}
那么我们将这个过程抽象成这么一个C程序suid.c:
int main(int argc, char* argv[]) { return system(argv[1]);}
编译 , 并赋予其suid权限:
root@linux:/tmp# gcc suid.c -o suidroot@linux:/tmp# chmod +s suid
接着我尝试在不同系统中 , 用www-data用户运行./suid id:
Linux发行版
Ubuntu 14.04
Ubuntu 16.04
Ubuntu 18.04
CentOS 6
CentOS 8
Debian 6
Debian 8
Kali 2019
可见 , 有些系统是root权限 , 有些系统仍然是原本用户权限 。 那么上面nmap提权失败的原因 , 就可以排除nmap的原因了 。
同样 , CentOS 6和Debian 6都是较老的发行版 , 但CentOS 6的表现却和新版Ubuntu类似 , 经过网上的询问和翻文档 , 得到了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.
如果启动bash时的Effective UID与Real UID不相同 , 而且没有使用-p参数 , 则bash会将Effective UID还原成Real UID 。
我们知道 , Linux的system()函数实际上是执行的/bin/sh -c , 而CentOS的/bin/sh是指向了/bin/bash:
[root@localhost tmp]# ls -al /bin/sh lrwxrwxrwx. 1 root root 4 Apr 10 2017 /bin/sh -> bash
这就解释了为什么CentOS中suid程序执行id获得的结果仍然是www-data 。 假设我们此时将sh修改成dash , 看看结果是什么:
[root@localhost tmp]# su -s /bin/bash nobodybash-4.1$ ls -al /bin/sh lrwxrwxrwx. 1 root root 9 Feb 19 00:21 /bin/sh -> /bin/dashbash-4.1$ ./suid iduid=99(nobody) gid=99(nobody) euid=0(root) egid=0(root) groups=0(root),99(nobody) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
dash并没有限制Effective UID , 这里可以看到成功获取了root权限 。
Ubuntu的特殊处理【油炸小可爱|黑客大神谈一谈Linux与suid提权】但是 , 我们来看看Ubuntu 16.04 , 其/bin/sh指向的同样是dash:
$ ls -al /bin/shlrwxrwxrwx 1 root root 4 9月 18 2016 /bin/sh -> dash$ ls -al /bin/dash -rwxr-xr-x 1 root root 154072 2月 17 2016 /bin/dash
为什么仍然会出现无法提权的情况?
此时我们又需要了解另一个知识了 。 通常来说 , 类似Ubuntu这样的发行版都会对一些程序进行修改 , 比如我们平时在查看PHP版本的时候 , 经常会看到这样的banner:PHP 7.0.33-0ubuntu0.16.04.11 , 在官方的版本号后会带上Ubuntu的一些版本号 , 这是因为Ubuntu发行版在打包这些软件时会增加一些自己的代码 。
推荐阅读
- 油炸小可爱|秒批、曲线、送龙腾!返现3%的华为信用卡来了
- 油炸小可爱|有些吓人!SSD温度超85度,用它之后骤降25度,这下清凉了
- |万茜道歉风云录,是黑客还是手滑,两大平台评论隔空对战
- 江水寒|《琉璃》昊辰VS刘学义,粉丝大惊,想不到你是这样一个小可爱
- 油炸小可爱|电动车逮虾户?雅迪冠能T5领衔电动车续航新方案
- 油炸小可爱|黑客大神总结:全端口蜜罐的部署过程与数据分析
- 阿根廷中文播报|被索百万“赎金”,阿根廷移民局数据库遭黑客侵入
- 小呀么小可爱|爆笑GIF:妹子们可得抓紧啊这么大的风别被吹跑了!
- 科技实验室|国外黑客通过程序实现体感操作,用乐高马力欧来玩马力欧游戏
- 口感|第1步不是用油炸!多做1步,花菜脆爽不油腻,更好吃做干煸花菜
