官术网_书友最值得收藏!

Preventing users from using shell escapes

Certain programs, especially text editors and pagers, have a handy shell escape feature. This allows a user to run a shell command without having to exit the program first. For example, from the command mode of the Vi and Vim editors, someone could run the ls command by doing :!ls. Executing the command would look like this:

# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

~
~
:!ls

The output would look like this:

[donnie@localhost default]$ sudo vim useradd
[sudo] password for donnie:

grub nss useradd

Press ENTER or type command to continue
grub nss useradd

Press ENTER or type command to continue

Now, imagine that you want Frank to be able to edit the sshd_config file and only that file. You might be tempted to add a line to your sudo configuration that would look like this:

frank     ALL=(ALL)     /bin/vim /etc/ssh/sshd_config

This looks like it would work, right? Well, it doesn't because once Frank has opened the sshd_config file with his sudo privilege, he can then use Vim's shell escape feature to perform other root-level commands, which would include being able to edit other configuration files. You can fix this problem by having Frank use sudoedit instead of vim:

frank     ALL=(ALL)     sudoedit /etc/ssh/sshd_config

sudoedit has no shell escape feature, so you can safely allow Frank to use it.

Other programs that have a shell escape feature include the following:

  • emacs
  • less
  • view
  • more
主站蜘蛛池模板: 来安县| 黄龙县| 大埔县| 休宁县| 嘉义市| 双牌县| 海南省| 泰宁县| 舟曲县| 新津县| 泌阳县| 西青区| 永康市| 华蓥市| 平顺县| 蒙山县| 历史| 南投县| 绥阳县| 灌云县| 蒙自县| 吴桥县| 鲁山县| 和硕县| 曲阳县| 咸丰县| 忻州市| 包头市| 滨州市| 合阳县| 垣曲县| 兴国县| 饶平县| 榆林市| 汶川县| 定日县| 灵台县| 汽车| 且末县| 武冈市| 嘉定区|