首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多参数通配符匹配sudoers文件?

多参数通配符匹配sudoers文件?
EN

Unix & Linux用户
提问于 2017-09-27 20:54:08
回答 2查看 26.5K关注 0票数 10

我试图弄清楚如何在sudoer中创建一个条目,其中允许有限的参数集(一些是可选的),但是命令仍然很有限制性。

有什么简单的方法来限制这些限制吗?

我希望用户能够使用-w标志和可选值运行,但仍然是限制性的。我不想硬编码-w选项的值。用户应该能够运行任何这些命令,其中10是任何数字。

代码语言:javascript
复制
/usr/bin/iptables -nvL *
/usr/bin/iptables -w -nvL *
/usr/bin/iptables -w 10 -nvL *

我想出了这四个条目。是否有更好的方法来定义可选的值?

代码语言:javascript
复制
username ALL=(root) NOPASSWD: /usr/bin/iptables -nvL *
username ALL=(root) NOPASSWD: /usr/bin/iptables -w -nvL *
username ALL=(root) NOPASSWD: /usr/bin/iptables -w [[\:digit\:]] -nvL *
username ALL=(root) NOPASSWD: /usr/bin/iptables -w [[\:digit\:]][[\:digit\:]] -nvL *
EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2019-06-06 08:28:03

我不担心:/

如果你不想使用通配符,比如??,甚至是*,你必须提供非常准确的,你想要的。

根据sudoers手册页,它只提供一般通配符:

代码语言:javascript
复制
Wildcards
  sudo allows shell-style wildcards (aka meta or glob characters) to be used in host names,
  path names and command line arguments in the sudoers file.  Wildcard matching is done via the
  glob(3) and fnmatch(3) functions as specified by IEEE Std 1003.1 (“POSIX.1”).

  *         Matches any set of zero or more characters (including white space).

  ?         Matches any single character (including white space).

  [...]     Matches any character in the specified range.

  [!...]    Matches any character not in the specified range.

  \x        For any character ‘x’, evaluates to ‘x’.  This is used to escape special characters
            such as: ‘*’, ‘?’, ‘[’, and ‘]’.

  NOTE THAT THESE ARE NOT REGULAR EXPRESSIONS.
  Unlike a regular expression there is no way to match one or more characters within a range.
票数 13
EN

Unix & Linux用户

发布于 2020-04-16 20:42:51

正如其他人指出sudo不支持您想要的一样,它只支持泛型通配符。

使用带有sudoers格式的通配符有一些严重的危险。例如,如果您允许rm -Rf /some/path/*,那么您可以使用sudo rm -Rf /some/path/blarg /another/not/allowed/path,并且只要他们也使用该路径,它就允许他们基本上rm任何文件。类似地,您可以滥用相对删除,仍然只能删除另一条路径,同时通过rm -Rf /some/path/../../../../some/path/that/should/be/restricted将指定的目录保持不变。

您可以考虑使用“代理”脚本来进行输入验证。

我强烈建议阅读整个系列文章,但如果不是通配符的话:https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-4-wildcards/

票数 8
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/394845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档