4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sudoの変化と、sudo1.8からsudoreplay (自動で操作ログをキャプチャ)が追加された

Last updated at Posted at 2016-04-13

参考

バージョンの変化

distribusion sudo
CentOS4 1.6.7
CentOS5 1.7.2
CentOS6 1.8.6
Ubuntu16.04 1.8.12
Debian9 1.8.15

項目の変化 (未確認)

項目 1.6 1.7 1.8
(NO)PASSWD o o o
(NO)SETENV x o o
(NO)EXEC x o o
(NO)LOG_INPUT x x o
(NO)LOG_OUTPUT x x o

sudoers はコマンドの入出力ストリームのロギングもサポートしている。
入出力ロギングは、デフォルトでは ON になっていないが、
デフォルト設定の log_input や log_output フラグを使って有効にすることができる。
コマンド・タグの LOG_INPUTや LOG_OUTPUTを使って有効にすることも可能だ。

  • 1.8からsudoreplayコマンドが入った様子。

sudoreplay

Monitoring What Your Privileged Users are doing on Linux and UNIX w/ Randy Franklin Smith

/etc/sudoers
+ Defaults:user1 log_output,log_input
  • /var/log/sudo-io/ 以下に保存されます。
sudoreplay記録一覧
 4月 14 07:23:56 2016 : user1 : TTY=/dev/pts/6 ; CWD=/var/log ; USER=root ; TSID=000001 ; COMMAND=/usr/bin/fizsh
 4月 14 07:24:26 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000002 ; COMMAND=/usr/bin/sudoreplay -l
 4月 14 07:24:50 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000003 ; COMMAND=/usr/bin/sudoreplay user1 000001
 4月 14 07:25:04 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000004 ; COMMAND=/usr/bin/sudoreplay 000001
 4月 14 07:25:50 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000005 ; COMMAND=/bin/cat /etc/sudoers
 4月 14 07:25:53 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000006 ; COMMAND=/usr/bin/vim /etc/sudoers
 4月 14 07:26:33 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000007 ; COMMAND=/usr/bin/sudoreplay -l
 4月 14 07:27:13 2016 : user1 : TTY=/dev/pts/5 ; CWD=/home/user1 ; USER=root ; TSID=000008 ; COMMAND=/usr/bin/sudoreplay -l
再生方法
sudo sudoreplay 000006
  • scriptreplay のように再生される。

CentOS4 (sudo1.6)

sudo -sコマンドの変化

CentOS4(これは出来ない)
$ sudo -s tar
Password:
/bin/tar: /bin/tar: cannot execute binary file
CentOS4(これは出来る)
$ sudo tar
tar: You must specify one of the `-Acdtrux' options
Try `tar --help' for more information.
CentOS5(これは出来る)
$ sudo -s tar
tar: You must specify one of the `-Acdtrux' options
Try `tar --help' for more information.

自身に読み取り権限がないファイルをtarで固めることが出来ない。

  • CentOS5からは対応
準備
sudo mkdir a
sudo date > a/date.txt
sudo chmod 400 a/date.txt
事象
$ sudo tar czf a.tar.gz a
$ tar tvf a.tar.gz
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Error exit delayed from previous errors

CentOS5.5 (sudo1.7)

CentOS5.5では、デフォルトで、sudoを実行したユーザのPATHが引き継がれない

PATHを引き継ぎたい場合

/etc/sudoers
+ Default env_keep+="PATH"

sudo -l

ubuntu16.04
$ sudo -l
Matching Defaults entries for user1 on mvm:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User user1 may run the following commands on mvm:
    (ALL : ALL) ALL
    (ALL : ALL) NOPASSWD: ALL
centos4
$ sudo -l
User user1 may run the following commands on this host:
    (ALL) ALL

sudo env

  • Ubuntu16.04ではPATHがリセットされるが、CentOS4ではPATHが一般ユーザのものを引き継いでいる。

sudo -iと-sの違い

  • -i : デフォルトのシェルを起動。(fizshを使っていてもbashが起動される)
  • -s : ユーザのシェルを起動。(fizshの場合、fizshが起動)

sudo を使って X11 アプリを実行

/etc/sudoers
+ Defaults env_keep += "HOME"

sudo sudo -V

バージョンを表示
sudo -V
さらなる情報を表示
sudo sudo -V
CentOS4
$ sudo sudo -V
Password:
Sudo version 1.6.7p5

Authentication methods: 'pam'
Syslog facility if syslog is being used for logging: authpriv
Syslog priority to use when user authenticates successfully: notice
Syslog priority to use when user authenticates unsuccessfully: alert
Ignore '.' in $PATH
Send mail if the user is not in sudoers
Use a separate timestamp for each user/tty combo
Lecture user the first time they run sudo
Require users to authenticate by default
Root may run sudo
Allow some information gathering to give useful error messages
Visudo will honor the EDITOR environment variable
Set the LOGNAME and USER environment variables
Length at which to wrap log file lines (0 for no wrap): 80
Authentication timestamp timeout: 5 minutes
Password prompt timeout: 5 minutes
Number of tries to enter a password: 3
Umask to use or 0777 to use users: 022
Path to mail program: /usr/sbin/sendmail
Flags for mail program: -t
Address to send mail to: root
Subject line for mail messages: *** SECURITY information for %h ***
Incorrect password message: Sorry, try again.
Path to authentication timestamp dir: /var/run/sudo
Default password prompt: Password:
Default user to run commands as: root
Path to the editor for use by visudo: /bin/vi
Environment variables to check for sanity:
	LANGUAGE
	LANG
	LC_*
Environment variables to remove:
	PERL5OPT
	PERL5LIB
	PERLLIB
	JAVA_TOOL_OPTIONS
	SHELLOPTS
	PS4
	BASH_ENV
	ENV
	TERMCAP
	TERMPATH
	TERMINFO_DIRS
	TERMINFO
	_RLD*
	LD_*
	PATH_LOCALE
	NLSPATH
	HOSTALIASES
	RES_OPTIONS
	LOCALDOMAIN
	CDPATH
	IFS
When to require a password for 'list' pseudocommand: any
When to require a password for 'verify' pseudocommand: all
Local IP address and netmask pairs:
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?