%20%E4%B8%8A%E4%B8%8D%E5%B0%8D%E7%99%BB%E5%85%A5%20shell%20%E6%87%89%E7%94%A8%E4%BB%BB%E4%BD%95%E9%99%90%E5%88%B6%EF%BC%9F.png)
我使用的是 Debian 9(Stretch)。我有一個deploy
用戶,我已將 shell 設定為/bin/rbash
.這是來自的行/etc/passwd
:
deploy:x:9000:9000::/home/deploy:/bin/rbash
如果我是 root 用戶,並且運行su - deploy
或su -l deploy
,那麼它會啟動rbash
( echo $SHELL # => /bin/rbash
),但命令不受限制:
~$ echo $SHELL
/bin/rbash
~$ cd /tmp
/tmp$ echo asdf > /tmp/file
/tmp$ /bin/cat /tmp/file
asdf
# (Should not allow any commands with a slash)
如果我只是跑su deploy
:
~$ echo $SHELL
/bin/rbash
~$ cd /tmp
rbash: cd: restricted
~$ /bin/cat /etc/passwd
rbash: /bin/cat: restricted: cannot specify `/' in command names
rbash
如果這是登入 shell,為什麼不應用任何限制?
答案1
來自 Bash 手冊:
如果 Bash 以 name 啟動
rbash
,或在呼叫時提供--restricted
或-r
選項,則 shell 會受到限制。
現在,「從名字開始」意味著$0
,或者的第零個元素argv
是那個名字。但是當su
它作為登入 shell 啟動時,它會將名稱設為-su
.且該選項也沒有使用,因此在啟動登入 shell-r
時,沒有使用啟動受限 shell 的方法。su
對於其他正確的登入方式(例如 SSH 或login(1)
透過 TTY),它應該仍然有效。