セキュリティ
今回はセキュリティ的に実行を監視しておきたいユーザの動作をトレースするDスクリプトを取り上げます
ユーザとグループ、
DTraceを使うと、
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option destructive
inline int ALLOWED_UID = 501;
dtrace:::BEGIN
{
printf("Watching setuid(), allowing only uid %d...\n", ALLOWED_UID);
}
/*
* Kill setuid() processes who are becomming root, from non-root, and who
* are not the allowed UID.
*/
syscall::setuid:entry
/arg0 == 0 && curpsinfo->pr_uid != 0 && curpsinfo->pr_uid != ALLOWED_UID/
{
printf("%Y KILLED %s %d -> %d\n", walltimestamp, execname,
curpsinfo->pr_uid, arg0);
raise(9);
}
このDスクリプトは、
setuid(2)というシステムコールはたとえばsu(8)コマンドで別のユーザになるときに呼ばれます。つまり、
# ./nosetuid.d Watching setuid(), allowing only uid 501...
上記のようにDスクリプトを実行しつつ、
% id uid=501(daichi) gid=20(staff) groups=20(staff),0(wheel),5(operator),501(daichi) % su -l Password: # id uid=0(root) gid=0(wheel) groups=0(wheel),5(operator) #
今度はUIDが501以外のユーザで同じ処理を行おうとすると、
% id uid=1001(sasaki) gid=1001(sasaki) groups=1001(sasaki),0(wheel) % su -l Password: % su -l Password: %
Dスクリプトを実行したターミナルを見てみると、
# ./nosetuid.d Watching setuid(), allowing only uid 501... 2017 Mar 27 13:13:33 KILLED su 1001 -> 0 2017 Mar 27 13:14:23 KILLED su 1001 -> 0 2017 Mar 27 13:14:27 KILLED su 1001 -> 0
こんな感じでシステムコールの捕捉とユーザIDでの切り分けを実施してあげれば、
※ ここに掲載したサンプルスクリプトは"DTrace Dynamic Tracing In Oracle Solaris, Mac OS X & FreeBSD", by Brendan Gregg and Jim Mauro P.
勉強会
第62回 4月28日(火)19:00~FreeBSD勉強会 エンジニアのための英会話入門~なぜ英語ができないのか~ 講師: 後藤大地(BSDコンサルティング株式会社)
FreeBSDの情報の多くは英語で入手できます。ほかの言語と比べると日本語は翻訳されたドキュメントが豊富にありますが、
日本は義務教育の間に英語を学びますが、
参加申し込みはこちらから。
第63回 5月23日(火)19:00~FreeBSD勉強会
現在検討中です。
FreeBSD勉強会 発表者募集
FreeBSD勉強会では発表者を募集しています。FreeBSDに関して発表を行いたい場合、