admin管理员组文章数量:1123801
I've built a sandbox that restricts the user to the rbash shell. But what I've found was that the user was still able to execute functions which can be bad for the environment because it enables the use of a fork bomb:
:(){ :|:& };:
I don't want to set a process limit for the user. I would like to just disable the user from declaring and executing functions.
I've built a sandbox that restricts the user to the rbash shell. But what I've found was that the user was still able to execute functions which can be bad for the environment because it enables the use of a fork bomb:
:(){ :|:& };:
I don't want to set a process limit for the user. I would like to just disable the user from declaring and executing functions.
Share Improve this question asked 17 hours ago IyadELwyIyadELwy 231 silver badge6 bronze badges 4 |1 Answer
Reset to default 2Does rbash restrict the use of functions?
No.
The manual documents the complete list of restrictions:
A restricted shell behaves identically to bash with the exception that the following are disallowed or not performed:
- Changing directories with the
cd
builtin.- Setting or unsetting the values of the
SHELL
,PATH
,HISTFILE
,ENV
, orBASH_ENV
variables.- Specifying command names containing slashes.
- Specifying a filename containing a slash as an argument to the
.
builtin command.- Specifying a filename containing a slash as an argument to the
history
builtin command.- Specifying a filename containing a slash as an argument to the
-p
option to thehash
builtin command.- Importing function definitions from the shell environment at startup.
- Parsing the value of
SHELLOPTS
from the shell environment at startup.- Redirecting output using the ‘
>
’, ‘>|
’, ‘<>
’, ‘>&
’, ‘&>
’, and ‘>>
’ redirection operators.- Using the
exec
builtin to replace the shell with another command.- Adding or deleting builtin commands with the
-f
and-d
options to theenable
builtin.- Using the
enable
builtin command to enable disabled shell builtins.- Specifying the
-p
option to the command builtin.- Turning off restricted mode with ‘
set +r
’ or ‘shopt -u restricted_shell
’.These restrictions are enforced after any startup files are read.
The only restriction on functions in restricted bash is that the shell does not inherit them from its parent's environment. There is no limitation on defining or calling them, though their behavior is of course subject to the above restrictions.
You're concerned that access to functions enables users to create and execute fork bombs, but that's only half true. Bash functions can certainly be used to implement fork bombs, and they do work around some of the restrictions placed by a restricted shell on what commands can be executed. However, it is pretty easy to implement a fork bomb that works in a restricted shell without using functions, too, so functions are not a sole enabler of such malicious behavior.
For example, as long as the user can create files in their working directory, they can create a file such as this:
boom.sh
while true; do
bash boom.sh &
done
and run it via bash boom.sh
. With a bit more work, a malicious user can run a similar fork bomb even without being able to create files.
You say you don't want to set a process limit for users, but I daresay you really do. Inasmuch as you account it a problem that a user might forkbomb the system, you should have at least as much concern that a non-malicious user may negligently try to use more resources, including processes, than they should do. Placing a process limit on untrusted users is absolutely an appropriate measure to take on a multi-user system where you are unwilling risk users negligently or maliciously creating excessive numbers of processes, whether via a bona fide fork bomb or via a well-intended normal workload.
本文标签: linuxDoes rbash restrict the use of functionsStack Overflow
版权声明:本文标题:linux - Does rbash restrict the use of functions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736571581a1944779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
bash -r -c ':(){ echo OK; };:'
– Gilles Quénot Commented 17 hours ago:() { :; }; :
and wait a few seconds... – Renaud Pacalet Commented 15 hours ago