2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

copsでセキュリティホールを検出する!

バーデユー大学の学生によって作られた、 cops(Computer Oracle & Password System)は、Unixシステムのセキュリティチェックを行うスクリプトだ。
つまり、自分の鯖のディレクトリ内のファイルを色々な方向からチェックしてくれるお便利ツールである。どのようなチェックをしてくれるかは以下に示す。

1)ファイル・ディレクトリ・デバイスのパーミッション及びモード
2)setuid されたファイルの所在及びそれの書き込み権限
3)貧粗なパスワードを発見する
4)起動ファイル等の設定ファイル・実行ファイルの正当性
5)Passwordファイル、Groupファイルの内容とフォーマット
6)CRCチェックによるバイナリファイルのチェック
7)ユーザホームディレクトリの権限やドットファイル

このような事柄を設定ファイルに則り、チェックしてくれる。これらは、いずれもUnixシステムでは重要な事項だが、見落とされがちであることも事実だ。しかし、初心者の場合は何をどうやってセキュリティを保てばいいのかが解らないのも事実であろう。そんなことから、このようなセキュリティチェックツールは心強い味方ではないだろうか。
昨今のLinuxは、インストールは簡単、設定も簡単、セキュリティは有る程度はデフォルトで保ってくれるのは良いけど、逆にシステムのどこをどのようにいじればセキュリティが今以上強化できるのか?
馬鹿ちょんLinuxは、何から何まで設定済みなので細かい操作が初心者では無理な状態を引き起こしている。
こんな状態でも、ディレクトリやファイルを調べてくれて何処を訂正したり、追加したりをアドバイスしてくれる相棒は頼もしい物である。
尚、オフィシャルサイトは無い。ファイルのダウンロードサイトは、現在 ここ だけのようである。プログラム(C言語と一部Perlで書いてある。つまり、PerlからC言語をキックしているとでも言っておこう。)での更新は既に終了しているようで、これを執筆した2007年5月現在で cops104+.tar.gz が最新版であった。著作権を考えるとプログラムは改変することはできないが、とても良いツールなので、ここのネタをオフィシャルサイト代わりに紹介したいと思っている。現在のLinux用の設定ファイルなどもここで紹介したい。


1.まずはcopsのインスコ
1)セットアップファイルのゲット

wgetでftpサイトからセットアップファイルをゲット。
[root@mail2 ~]# cd /usr/local/src/
[root@mail2 src]# wget ftp://ftp.cerias.purdue.edu/pub/tools/unix/scanners/cops/cops104+.tar.gz

–09:50:22– ftp://ftp.cerias.purdue.edu/pub/tools/unix/scanners/cops/cops104+.tar.gz
=> `cops104+.tar.gz’
Resolving ftp.cerias.purdue.edu… 128.10.252.10
Connecting to ftp.cerias.purdue.edu|128.10.252.10|:21… connected.
Logging in as anonymous … Logged in!
==> SYST … done. ==> PWD … done.
==> TYPE I … done. ==> CWD /pub/tools/unix/scanners/cops … done.
==> SIZE cops104+.tar.gz … done.
==> PASV … done. ==> RETR cops104+.tar.gz … done.
Length: 288663 (282K) (unauthoritative)

100%[=======================================>] 288,663 109K/s in 2.6s

09:50:35 (109 KB/s) – `cops104+.tar.gz’ saved [288663]

2)ファイルの展開
[root@mail2 src]# tar zxvf cops104+.tar.gz
cops_104+/
cops_104+/MANIFEST
cops_104+/README.1
cops_104+/README.2.pl
cops_104+/README.2.sh
cops_104+/README.3
cops_104+/README.FIRST
cops_104+/XTRA_CREDIT
cops_104+/bug.chk
cops_104+/bug.chk.aix
cops_104+/bug.chk.apollo
cops_104+/bug.chk.dec
cops_104+/bug.chk.next
cops_104+/bug.chk.sgi
cops_104+/bug.chk.sun
cops_104+/bug.chk.svr4
cops_104+/bug_cmp
cops_104+/carp/
cops_104+/carp/carp.1
cops_104+/carp/carp
cops_104+/carp/carp.anlz
cops_104+/carp/carp.table
cops_104+/carp/carp.awk
cops_104+/carp/carp.anlz.1
cops_104+/carp/carp2ps
cops_104+/carp/carp2ps.1
cops_104+/carp/README
cops_104+/carp/How2Change
cops_104+/checkacct/
cops_104+/checkacct/Article
cops_104+/checkacct/Intro
cops_104+/checkacct/Makefile
cops_104+/checkacct/README.FIRST
cops_104+/checkacct/bsd.m4
cops_104+/checkacct/ca.src
cops_104+/checkacct/chkacct.1l
cops_104+/checkacct/dotwrite
cops_104+/checkacct/effect.dotwrit
cops_104+/checkacct/effect.owners
cops_104+/checkacct/effect.read
cops_104+/checkacct/effect.rhosts
cops_104+/checkacct/effect.setuid
cops_104+/checkacct/effect.write
cops_104+/checkacct/owners
cops_104+/checkacct/prm.mm
cops_104+/checkacct/prompt.help
cops_104+/checkacct/readable
cops_104+/checkacct/rhosts
cops_104+/checkacct/rhosts.pl
cops_104+/checkacct/setuid
cops_104+/checkacct/sysV.m4
cops_104+/checkacct/write
cops_104+/chk_strings
cops_104+/cops
cops_104+/cops_filter
cops_104+/crc.chk
cops_104+/cover_letter
cops_104+/crc_list
cops_104+/cron.chk
cops_104+/dev.chk
cops_104+/disclaimer
cops_104+/docs/
cops_104+/docs/COPS.report
cops_104+/docs/KUANG.README
cops_104+/docs/SUID.README
cops_104+/docs/cops
cops_104+/docs/dev.chk
cops_104+/docs/CRC.README
cops_104+/docs/home.chk
cops_104+/docs/pass.chk
cops_104+/docs/is_able
cops_104+/docs/kuang.1
cops_104+/docs/kuang.man
cops_104+/docs/rc.chk
cops_104+/docs/is_able.chk
cops_104+/docs/release.notes
cops_104+/docs/suid.man
cops_104+/docs/tilde
cops_104+/docs/warnings
cops_104+/docs/root.chk
cops_104+/docs/cron.chk
cops_104+/docs/group.chk
cops_104+/docs/pass_diff.chk
cops_104+/docs/user.chk
cops_104+/docs/makefile
cops_104+/docs/passwd.chk
cops_104+/docs/misc.chk
cops_104+/docs/ftp.chk
cops_104+/docs/COPS.tex
cops_104+/docs/readme.sequent
cops_104+/docs/is_writable
cops_104+/docs/readme.C2
cops_104+/docs/readme.apollo
cops_104+/docs/readme.ibm
cops_104+/docs/readme.shadow
cops_104+/docs/readme.svr4
cops_104+/docs/readme.xenix
cops_104+/docs/readme.yp
cops_104+/docs/bug.chk
cops_104+/docs/readme.cfilter
cops_104+/docs/obligatory.joke
cops_104+/docs/readme.filters
cops_104+/docs/obligatory.album
cops_104+/extensions/
cops_104+/extensions/THINGS_2_DO
cops_104+/extensions/YAR
cops_104+/extensions/crypto-stuff
cops_104+/extensions/netstuff
cops_104+/extensions/passwords
cops_104+/extensions/questions
cops_104+/extensions/uucp.hardening
cops_104+/extensions/writing.suid
cops_104+/extra_src/
cops_104+/extra_src/diff_last.sh
cops_104+/extra_src/mail.chk
cops_104+/extra_src/trust.pl
cops_104+/extra_src/bad_dir.pl
cops_104+/extra_src/stop.make
cops_104+/extra_src/README
cops_104+/extra_src/uucp_quick.chk
cops_104+/extra_src/uucp_2.shar
cops_104+/extra_src/rhosts_sweeper
cops_104+/extra_src/pass.mail
cops_104+/extra_src/uucp_1.shar
cops_104+/ftp.chk
cops_104+/gen_fix
cops_104+/group.chk
cops_104+/init_kuang
cops_104+/is_able.chk
cops_104+/is_able.lst
cops_104+/kuang
cops_104+/kuang.pl.shar
cops_104+/makefile
cops_104+/misc.chk
cops_104+/pass.words
cops_104+/pass_diff.chk
cops_104+/passwd.chk
cops_104+/patchlevel.h
cops_104+/perl/
cops_104+/perl/shadow.sh
cops_104+/perl/README.kuang
cops_104+/perl/cops.cf
cops_104+/perl/chk_strings
cops_104+/perl/chk_strings.pl
cops_104+/perl/cops
cops_104+/perl/cron.chk
cops_104+/perl/dev.chk
cops_104+/perl/fgrep.pl
cops_104+/perl/file_mode.pl
cops_104+/perl/file_owner.pl
cops_104+/perl/ftp.chk
cops_104+/perl/get-cf
cops_104+/perl/getopts.pl
cops_104+/perl/glob.pl
cops_104+/perl/group.chk
cops_104+/perl/hostname.pl
cops_104+/perl/is_able.chk
cops_104+/perl/is_able.lst
cops_104+/perl/kuang
cops_104+/perl/is_able.pl
cops_104+/perl/kuang.1
cops_104+/perl/misc.chk
cops_104+/perl/pass.chk
cops_104+/perl/pass.cache.pl
cops_104+/perl/passwd.chk
cops_104+/perl/pathconf.pl
cops_104+/perl/pathconf.sh
cops_104+/perl/rc.chk
cops_104+/perl/reconfig.pl
cops_104+/perl/root.chk
cops_104+/perl/rules.pl
cops_104+/perl/stat.pl
cops_104+/perl/suckline.pl
cops_104+/perl/suid.chk
cops_104+/perl/suid.stop
cops_104+/perl/user.chk
cops_104+/perl/yagrip.pl
cops_104+/perl/README.sgi
cops_104+/platform
cops_104+/quick_start
cops_104+/rc.chk
cops_104+/reconfig
cops_104+/res_diff
cops_104+/root.chk
cops_104+/src/
cops_104+/src/addto.c
cops_104+/src/clearfiles.c
cops_104+/src/crc.c
cops_104+/src/crc_check.c
cops_104+/src/filewriters.c
cops_104+/src/home.chk.c
cops_104+/src/is_able.c
cops_104+/src/is_something.c
cops_104+/src/members.c
cops_104+/src/pass.c
cops_104+/src/tilde.c
cops_104+/src/user.chk.c
cops_104+/src/conf.h
cops_104+/src/crack-fcrypt.c
cops_104+/src/crack-lib.c
cops_104+/src/crack.h
cops_104+/suid.chk
cops_104+/suid.stop
cops_104+/yp_pass.chk

[root@mail2 src]# chown -R root.root cops_104+

[root@mail2 src]# cd cops_104+

3)リコンフィグ
reconfigをすることにより、この鯖のシステムに合わせてコマンドパスが変更される。
[root@mail2 cops_104+]# ./reconfig
checking to make sure all the target(s) are here…
So far so good…
Looking for all the commands now…
Warning! tftp not found! misc.chk will not work as planned.
Warning! uudecode not found! misc.chk will not work as planned.
Ok, now doing substitutions on the shell scripts…
Changing paths in makefile…
Changing paths in docs/makefile…
Changing paths in chk_strings…
Changing paths in cops…
Changing paths in crc.chk…
Changing paths in misc.chk…
Changing paths in dev.chk…
Changing paths in ftp.chk…
Changing paths in is_able.chk…
Changing paths in cron.chk…
Changing paths in group.chk…
Changing paths in passwd.chk…
Changing paths in rc.chk…
Changing paths in root.chk…
Changing paths in suid.chk…
Changing paths in kuang…
Changing paths in init_kuang…
Changing paths in res_diff…
Changing paths in pass_diff.chk…
Changing paths in yp_pass.chk…
Changing paths in bug.chk…
Changing paths in bug.chk.aix…
Changing paths in bug.chk.apollo…
Changing paths in bug.chk.dec…
Changing paths in bug.chk.next…
Changing paths in bug.chk.sgi…
Changing paths in bug.chk.sun…
Changing paths in bug.chk.svr4…
Changing paths in bug_cmp…

diffでreconfigの変更内容の確認を行う。
[root@mail2 cops_104+]# diff makefile makefile.old
41c41
< TEST=/usr/bin/test

> TEST=/bin/test
44c44
< CC=/usr/bin/cc

> CC=/bin/cc

copsファイルの変更内容の確認を行う。
[root@mail2 cops_104+]# diff cops cops.old
77c77
< TEST=/usr/bin/test

> TEST=/bin/test
83c83
< AWK=/bin/gawk

> AWK=/bin/awk

4)makeファイルの編集
一部makefileを訂正する。
[root@mail2 cops_104+]# vi makefile
# Simple Makefile for the COPS system; compiles, and chmods
# the programs.
#
# make all — makes everything
# make install — puts things in their place
# make <program_name> — make a given program
INSTALL_DIR= /usr/local/cops     ←ここを変更(copsのインストールディレクトリを記載)

EXECUTABLE = home.chk user.chk pass.chk is_writable crc crc_check \
addto clearfiles filewriters members tilde is_able
C_SRC = home.chk.c user.chk.c is_able.c pass.c is_something.c \
addto.c clearfiles.c filewriters.c members.c tilde.c \
crc.c crc_check.c
SHELL_PROGS= chk_strings root.chk dev.chk cron.chk is_able.chk \
cops group.chk rc.chk passwd.chk ftp.chk crc.chk \
misc.chk suid.chk kuang init_kuang reconfig res_diff \
yp_pass.chk bug.chk bug.chk.aix bug.chk.apollo \
bug.chk.dec bug.chk.next bug.chk.sgi bug.chk.sun \
bug.chk.svr4 bug_cmp platform
SUPPORT = is_able.lst suid.stop crc_list pass.words

# Running C2 on a sun?
# C2 = -DC2

#
CFLAGS = -O $(C2)
# sequents need “-lseq” as well… uncomment this if you’re running on one:
# SEQFLAGS = -lseq

# Certain systems need to uncomment this to compile the pass.chk; Xenix,
# some SysV:
BRAINDEADFLAGS = -lcrypt    ←ここコメントアウト(パスワードチェックを有効にする)
#
# systems with rindex need to uncomment this:
# CRC_FLAG=-Dstrrchr=rindex

#
# Where the programs are….
#
CHMOD=/bin/chmod
TEST=/usr/bin/test
MKDIR=/bin/mkdir
CP=/bin/cp
CC=/usr/bin/cc
RM=/bin/rm

# make default
default: $(EXECUTABLE)
$(CHMOD) u+x $(SHELL_PROGS)

# make all
all: $(EXECUTABLE)
cd docs; make
$(CHMOD) u+x $(SHELL_PROGS)

# hammer the binaries and formatted docs; if compiled fcrypt stuff,
# will trash the *.o files, too.
clean:
$(RM) -f $(EXECUTABLE) pass.o crack-fcrypt.o crack-lib.o
cd docs; make clean

man:
cd docs; make

# make a dir and shove everything in the proper place
install:
-if $(TEST) ! -d $(INSTALL_DIR) ; then $MKDIR $(INSTALL_DIR) ; fi
$(CP) $(EXECUTABLE) $(SHELL_PROGS) $(SUPPORT) $(INSTALL_DIR)

# make the programs
addto: src/addto.c
$(CC) $(CFLAGS) -o addto src/addto.c

clearfiles: src/clearfiles.c
$(CC) $(CFLAGS) -o clearfiles src/clearfiles.c

filewriters: src/filewriters.c
$(CC) $(CFLAGS) -o filewriters src/filewriters.c

members: src/members.c
$(CC) $(CFLAGS) -o members src/members.c

home.chk: src/home.chk.c
$(CC) $(CFLAGS) -o home.chk src/home.chk.c

user.chk: src/user.chk.c
$(CC) $(CFLAGS) -o user.chk src/user.chk.c

is_able: src/is_able.c
$(CC) $(CFLAGS) -o is_able src/is_able.c

is_writable: src/is_something.c
$(CC) $(CFLAGS) -DWRITABLE -o is_writable src/is_something.c

# If fast crypt will work, comment the first CC line, uncomment
# the next two:
$(CC) $(CFLAGS) -o pass.chk src/pass.c $(BRAINDEADFLAGS) ←ここをコメントアウト
pass.chk: src/pass.c
# $(CC) $(CFLAGS) -Dcrypt=fcrypt -DFCRYPT -o pass.chk src/pass.c \ ←ここコメント
# src/crack-fcrypt.c src/crack-lib.c $(BRAINDEADFLAGS)

tilde: src/tilde.c
$(CC) $(CFLAGS) -o tilde src/tilde.c

crc: src/crc.c
$(CC) $(CFLAGS) -o crc src/crc.c $(SEQFLAGS)

crc_check: src/crc_check.c
$(CC) $(CFLAGS) $(CRC_FLAG) -o crc_check src/crc_check.c $(SEQFLAGS)

# the end

5)この鯖にnroffが無い場合のコンパイル&リンク
もし、この鯖にnroffが無い場合は、以下のようにdocs/makefileを一部編集する。
[root@mail2 cops_104+]# vi docs/makefile
# Simple Makefile for the COPS documentation
#
# make all — makes everything
# make <doc-name> — make a given doc
DOCS = COPS.report.ms suid.man.ms kuang.man.ms
MAN = cops.1 cron.chk.1 dev.chk.1 group.chk.1 is_able.chk.1 \
passwd.chk.1 is_able.1 home.chk.1 user.chk.1 pass.chk.1 \
root.chk.1 rc.chk.1 pass_diff.chk.1 misc.chk.1 \
is_writable.1 bug.chk.1

DOC_SOURCE = COPS.report suid.man kuang.man cops cron.chk dev.chk is_able.chk \
dir.chk file.chk group.chk passwd.chk is_able home.chk \
user.chk pass.chk root.chk rc.chk pass_diff.chk misc.chk \
is_writable bug.chk
ROFFLAGS =                                    ←「 -ms 」を消す

省略

# ‘roff out those docs
#COPS.report.ms: COPS.report                 ←コメントする
# $(NROFF) $(ROFFLAGS) COPS.report > COPS.report.ms    ←コメントする

省略

その後、
[root@mail2 cops_104+]# make

で旨くコンパイルできたら、以降7)の処理に続く。

6)この鯖にnroffが有る場合
make allする。
[root@mail2 cops_104+]# make all
/usr/bin/cc -O -o clearfiles src/clearfiles.c
src/clearfiles.c: In function ‘main’:
src/clearfiles.c:37: warning: comparison between pointer and integer
src/clearfiles.c:41: warning: incompatible implicit declaration of built-in function ‘exit’
/usr/bin/cc -O -o filewriters src/filewriters.c
src/filewriters.c: In function ‘main’:
src/filewriters.c:61: warning: incompatible implicit declaration of built-in function ‘exit’
src/filewriters.c:66: warning: incompatible implicit declaration of built-in function ‘exit’
src/filewriters.c:89: warning: incompatible implicit declaration of built-in function ‘exit’
src/filewriters.c: In function ‘print_uid’:
src/filewriters.c:101: warning: incompatible implicit declaration of built-in function ‘exit’
src/filewriters.c: In function ‘print_gid’:
src/filewriters.c:115: warning: incompatible implicit declaration of built-in function ‘exit’
/usr/bin/cc -O -o members src/members.c
src/members.c: In function ‘main’:
src/members.c:38: warning: incompatible implicit declaration of built-in function ‘exit’
/usr/bin/cc -O -o tilde src/tilde.c
src/tilde.c: In function ‘main’:
src/tilde.c:12: warning: incompatible implicit declaration of built-in function ‘printf’
src/tilde.c:13: warning: incompatible implicit declaration of built-in function ‘exit’
src/tilde.c:19: warning: incompatible implicit declaration of built-in function ‘printf’
/usr/bin/cc -O -o is_able src/is_able.c
src/is_able.c: In function ‘main’:
src/is_able.c:76: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:80: warning: incompatible implicit declaration of built-in function ‘strcpy’
src/is_able.c:85: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:128: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:134: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:154: warning: incompatible implicit declaration of built-in function ‘strlen’
src/is_able.c:157: warning: incompatible implicit declaration of built-in function ‘strncpy’
src/is_able.c:172: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:179: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:183: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:189: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:202: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:208: warning: incompatible implicit declaration of built-in function ‘exit’
src/is_able.c:220: warning: incompatible implicit declaration of built-in function ‘exit’
cd docs; make
make[1]: Entering directory `/usr/local/src/cops_104+/docs’
/usr/bin/nroff -ms COPS.report > COPS.report.ms
/usr/bin/nroff -ms suid.man > suid.man.ms
/usr/bin/nroff -ms kuang.man > kuang.man.ms
/usr/bin/nroff -man cops > cops.1
/usr/bin/nroff -man cron.chk > cron.chk.1
/usr/bin/nroff -man dev.chk > dev.chk.1
/usr/bin/nroff -man group.chk > group.chk.1
/usr/bin/nroff -man is_able.chk > is_able.chk.1
/usr/bin/nroff -man passwd.chk > passwd.chk.1
/usr/bin/nroff -man is_able > is_able.1
/usr/bin/nroff -man home.chk > home.chk.1
/usr/bin/nroff -man user.chk > user.chk.1
/usr/bin/nroff -man pass.chk > pass.chk.1
/usr/bin/nroff -man root.chk > root.chk.1
/usr/bin/nroff -man rc.chk > rc.chk.1
/usr/bin/nroff -man pass_diff.chk > pass_diff.chk.1
/usr/bin/nroff -man misc.chk > misc.chk.1
/usr/bin/nroff -man is_writable > is_writable.1
/usr/bin/nroff -man bug.chk > bug.chk.1
make[1]: Leaving directory `/usr/local/src/cops_104+/docs’
/bin/chmod u+x chk_strings root.chk dev.chk cron.chk is_able.chk cops group.chk rc.chk passwd.c hk ftp.chk crc.chk misc.chk suid.chk kuang init_kuang reconfig res_diff yp_pass.chk bug.chk bug .chk.aix bug.chk.apollo bug.chk.dec bug.chk.next bug.chk.sgi bug.chk.sun bug.chk.svr4 bug_cmp p latform

7)リンクする
copsのインストールディレクトリを作る。
[root@mail2 cops_104+]# mkdir /usr/local/cops

make installする。
[root@mail2 cops_104+]# make install
if /usr/bin/test ! -d /usr/local/cops ; then KDIR /usr/local/cops ; fi
/bin/cp home.chk user.chk pass.chk is_writable crc crc_check addto clearfiles filewriters members tilde is_able chk_strings root.chk dev.chk cron.chk is_able.chk cops group.chk rc.chk passwd.chk ftp.chk crc.chk misc.chk suid.chk kuang init_kuang reconfig res_diff yp_pass.chk bug.chk bug.chk.aix bug.chk.apollo bug.chk.dec bug.chk.next bug.chk.sgi bug.chk.sun bug.chk.svr4 bug_cmp platform is_able.lst suid.stop crc_list pass.words /usr/local/cops

[root@mail2 cops_104+]# cp /usr/local/src/cops_104+/patchlevel.h /usr/local/cops
copsは実行時にpatchlevel.hを探すようなので・・・・・・。
これで、インスコは終わり。


2.設定ファイルの編集
1)copsのメインディレクトリファイルを参照してみる
copsのディレクトリへ移動する。
[root@mail2 cops_104+]# cd /usr/local/cops

cops内のファイルを眺める。
[root@mail2 cops]# ls -al
total 296
drwxr-xr-x 2 root root 4096 May 16 10:06 .
drwxr-xr-x 12 root root 4096 May 16 10:06 ..
-rwxr-xr-x 1 root root 7030 May 16 10:06 addto
-rwxr–r– 1 root root 3959 May 16 10:06 bug.chk
-rwxr–r– 1 root root 1650 May 16 10:06 bug.chk.aix
-rwxr–r– 1 root root 1132 May 16 10:06 bug.chk.apollo
-rwxr–r– 1 root root 1218 May 16 10:06 bug.chk.dec
-rwxr–r– 1 root root 2016 May 16 10:06 bug.chk.next
-rwxr–r– 1 root root 1097 May 16 10:06 bug.chk.sgi
-rwxr–r– 1 root root 6360 May 16 10:06 bug.chk.sun
-rwxr–r– 1 root root 1491 May 16 10:06 bug.chk.svr4
-rwxr–r– 1 root root 1364 May 16 10:06 bug_cmp
-rwxr–r– 1 root root 2020 May 16 10:06 chk_strings
-rwxr-xr-x 1 root root 5350 May 16 10:06 clearfiles
-rwxr–r– 1 root root 10800 May 16 10:06 cops
-rwxr-xr-x 1 root root 8615 May 16 10:06 crc
-rwxr–r– 1 root root 2208 May 16 10:06 crc.chk
-rwxr-xr-x 1 root root 8105 May 16 10:06 crc_check
-rwx—— 1 root root 1143 May 16 10:06 crc_list
-rwxr–r– 1 root root 2291 May 16 10:06 cron.chk
-rwxr–r– 1 root root 3502 May 16 10:06 dev.chk
-rwxr-xr-x 1 root root 6020 May 16 10:06 filewriters
-rwxr–r– 1 root root 8447 May 16 10:06 ftp.chk
-rwxr–r– 1 root root 5957 May 16 10:06 group.chk
-rwxr-xr-x 1 root root 5269 May 16 10:06 home.chk
-rwxr–r– 1 root root 949 May 16 10:06 init_kuang
-rwxr-xr-x 1 root root 8016 May 16 10:06 is_able
-rwxr–r– 1 root root 2341 May 16 10:06 is_able.chk
-rwx—— 1 root root 1699 May 16 10:06 is_able.lst
-rwxr-xr-x 1 root root 5552 May 16 10:06 is_writable
-rwxr–r– 1 root root 5974 May 16 10:06 kuang
-rwxr-xr-x 1 root root 5572 May 16 10:06 members
-rwxr–r– 1 root root 4182 May 16 10:06 misc.chk
-rwxr-xr-x 1 root root 13406 May 16 10:06 pass.chk
-rwx—— 1 root root 3278 May 16 10:06 pass.words
-rwxr–r– 1 root root 6601 May 16 10:06 passwd.chk
-rwx—— 1 root root 2387 May 16 10:06 platform
-rwxr–r– 1 root root 3274 May 16 10:06 rc.chk
-rwx—— 1 root root 6139 May 16 10:06 reconfig
-rwxr–r– 1 root root 1338 May 16 10:06 res_diff
-rwxr–r– 1 root root 4951 May 16 10:06 root.chk
-rwxr–r– 1 root root 6724 May 16 10:06 suid.chk
-rwx—— 1 root root 644 May 16 10:06 suid.stop
-rwxr-xr-x 1 root root 4936 May 16 10:06 tilde
-rwxr-xr-x 1 root root 5901 May 16 10:06 user.chk
-rwxr–r– 1 root root 890 May 16 10:06 yp_pass.chk

2)copsの実行ファイルを編集する
[root@mail2 cops]# vi cops

省略

#
# If this is changed to “NO”, the report that cops creates
# will not be deleted and the results will not be mailed to anyone.
MMAIL=YES                   ←YESでメールで結果を管理者へ通達する

省略

#
# Do you want to run suid.chk within cops?
RUN_SUID=NO

省略

# Where is everyone?
ECHO=/bin/echo
TEST=/usr/bin/test
RM=/bin/rm
CAT=/bin/cat
MAIL=/bin/mail
DATE=/bin/date
CHMOD=/bin/chmod
AWK=/bin/gawk
SED=/bin/sed
MV=/bin/mv
MKDIR=/bin/mkdir

# send errors and verbosity to…
BIT_BUCKET=/dev/null
# send verbose messages to…
VERBUCKET=/dev/null

######################
# Change these lines!
######################
SECURE=/usr/local/cops            ←copsのインストールディレクトリを記載
SECURE_USERS=”root@xxxxxxxx.jp”    ←結果を通達したい管理者のメールアドレスを記載
######################

省略

# use the -a option for checking anon-ftp; e.g., “$SECURE/ftp.chk -a”
if $TEST -n “$verbose” ; then
$ECHO “**** ftp.chk ****” >> $VERBUCKET ; fi
$SECURE/ftp.chk -a >> $RESULT 2>> $BIT_BUCKET    ←-aを追加する

省略

3)アクセス権チェックの為の設定ファイルの編集
以下の is_able.lstファイル は、システムファイルのアクセス権を調査するための設定ファイルだ。
したがって、必要に応じて各自追加しなくてはならない(俺の場合以下のように編集した)。今現在のLinuxシステムのファイル構造に編集した。ワイルドカード使用可。

以下の内容の is_able.lstファイル は ここ に置いてある。

[root@mail2 cops]# vi is_able.lst
# This lists any/all sensitive files the administration wants to ensure
# non-read/writability of. Comments are lines starting with a “#”.
#
# USE FULL PATHNAMES!
#
# Lines are of the format:
#
# /path/to/{dir|file} World/Group Read/Write/Both
#
# as above {w|g} {r|w|b}
#
/ w w
/etc w w
/usr w w
/bin w w
/lib w w
/dev w w
/usr/bin w w
/usr/etc w w
/usr/lib w w
/usr/include w w
/ver/mail w w
/ver/spool w w
/ver/spool/mail w w
/usr/local w w
/usr/local/bin w w
/usr/local/lib w w
/usr/local/include w w

# some Un*x’s put shadowpass stuff here:
/etc/shadow   w r

# /.bash_profile /.bashrc /.cshrc
/.* w w

# I think everything in /etc should be !world-writable, as a rule; but
# if you’re selecting individual files, do at *least* these:
# /etc/passwd /etc/group /etc/inittab /etc/rc /etc/rc.local /etc/rc.boot
# /etc/hosts.equiv /etc/profile /etc/syslog.conf /etc/export /etc/utmp
# /etc/wtmp
/etc/* w w
/bin/* w w
/lib/* w w
/usr/bin/* w w
/usr/etc/* w w
/usr/lib/* w w
/usr/include/* w w
/usr/local/lib/* w w
/usr/local/bin/* w w
/usr/local/include/* w w

# individual files:
/etc/crontab    w b
/etc/aliases   w w
/usr/sbin/sendmail w w

# root.chk dev.chk group.chk
# home.chk rc.chk passwd.chk
# is_able.chk pass.chk user.chk
# cron.chk misc.chk ftp.chk
#
# The U-kuang system runs these additional programs:
# init_kuang kuang addto
# clearfiles filewriters members

4)ファイル改ざんチェックの為の設定ファイルの編集
ファイル改ざんをチェックする為のcrc_listを編集する。今現在のLinuxシステムのファイル構造に編集した。ワイルドカード使用可。

以下の内容の crc_listファイル は ここ に置いてある。

[root@mail2 cops]# vi crc_list
# This lists any/all sensitive files the administration wants to have a
# CRC value for. Comments are lines starting with a “#”.
#

# some key files that might not change too often:
/.bash_profile
/.bashrc
/.cshrc
/etc/*
/etc/crontab
/etc/aliases

# some that you might like to keep an eye on, depending on your site
# stability and/or paranoia:
#/etc/passwd
#/etc/group

# default is individual files; can use wildcards, or whatever;
# here are some examples, using wildcards:
/bin/*
/lib/*
/usr/bin/*
/usr/lib/*
/usr/local/lib/*
/usr/local/bin/*

# Alternately, here are individual files that are important:
/bin/fsck
/bin/sh
/bin/login
/bin/ls
/bin/mount
/bin/ps
/bin/sh
/bin/su
/usr/sbin/sendmail
/usr/bin/telnet
/usr/bin/ftp
/usr/bin/chgrp
/usr/bin/df
/usr/bin/login
/usr/bin/mail
/usr/bin/passwd


3.copsの実行
[root@mail2 cops]# ./cops

これで実行されるが定期的に実行したい場合は、cronとかを使うのがベスト。


4.copsの実行結果
1)管理者に届いたcopsによるチェック結果メールの内容

ATTENTION:
Security Report for Thu May 17 09:55:18 JST 2007
from host mail2, COPS v. Usage ./cops [-a arch] [-b bit_bucket] [-s sec_dir] [-f filter] [-g gen_fix] [-m user] [-dvVx]


① Warning! /etc/crontab is _World_ readable!
② Warning! User www-data’s home directory /var/www is mode 0777!
③ Warning! Password file, line 19, uid Debian-exim > 8 chars
Debian-exim:x:100:102::/var/spool/exim4:/bin/false
④ Warning! Password file, line 26, uid hogehogehoge > 8 chars
hogehogehoge:x:1001:100::/home/hogehogehoge:/bin/sh
⑤ Warning! /etc/ftpusers should exist!
⑥ Warning! Need user for anonymous ftp to work!

Warning!の意味。
① /etc/crontabディレクトリは一般ユーザにはreadさせるべきではない。
② /var/wwwディレクトリは誰でも書き込み可能になっている。
③ パスワードチェックにおいて、ユーザid Debian-eximはフィールド数8文字をオーバーしている。
④ パスワードチェックにおいて、ユーザid hogehogehogeはフィールド数8文字をオーバーしている。
⑤ 有るはずのファイル/etc/ftpusersが無い。
⑥ anonymous ftpを行う為のユーザが必要。

結果はメール配送されるが、このファイルは、 /usr/local/cops/このホスト名 以下に収納される。

2)実行結果は、ファイルとして残る
実行結果も/usr/local/copsディレクトリ内の cops を実行したホスト名のディレクトリにファイルとして残る。例えば、cameleonと言うホスト名のホストでcopsを実行すると。

root@cameleon:/usr/local/cops# ./cops
root@cameleon:/usr/local/cops# ls -al

total 356
drwx—— 3 root root 4096 2007-06-01 00:53 ./
drwxr-xr-x 12 root root 4096 2007-06-01 00:44 ../
-rwxr-xr-x 1 root root 10271 2007-06-01 00:44 addto*
-rwxr–r– 1 root root 3955 2007-06-01 00:44 bug.chk*
-rwxr–r– 1 root root 1646 2007-06-01 00:44 bug.chk.aix*
-rwxr–r– 1 root root 1124 2007-06-01 00:44 bug.chk.apollo*
-rwxr–r– 1 root root 1214 2007-06-01 00:44 bug.chk.dec*
-rwxr–r– 1 root root 2012 2007-06-01 00:44 bug.chk.next*
-rwxr–r– 1 root root 1093 2007-06-01 00:44 bug.chk.sgi*
-rwxr–r– 1 root root 6352 2007-06-01 00:44 bug.chk.sun*
-rwxr–r– 1 root root 1487 2007-06-01 00:44 bug.chk.svr4*
-rwxr–r– 1 root root 1364 2007-06-01 00:44 bug_cmp*
drwxr-xr-x 2 root root 4096 2007-06-01 00:51 cameleon/
-rwxr–r– 1 root root 2016 2007-06-01 00:44 chk_strings*
-rwxr-xr-x 1 root root 8803 2007-06-01 00:44 clearfiles*
-rwxr–r– 1 root root 10819 2007-06-01 00:51 cops*
-rwxr-xr-x 1 root root 12358 2007-06-01 00:44 crc*
-rwxr–r– 1 root root 2204 2007-06-01 00:44 crc.chk*
-rwxr-xr-x 1 root root 11312 2007-06-01 00:44 crc_check*
-rwx—— 1 root root 849 2007-06-01 00:49 crc_list*
-rw-r–r– 1 root root 849 2007-06-01 00:48 crc_list.1
-rwxr–r– 1 root root 2287 2007-06-01 00:44 cron.chk*
-rwxr–r– 1 root root 3498 2007-06-01 00:44 dev.chk*
-rwxr-xr-x 1 root root 9469 2007-06-01 00:44 filewriters*
-rwxr–r– 1 root root 8443 2007-06-01 00:44 ftp.chk*
-rwxr–r– 1 root root 5949 2007-06-01 00:44 group.chk*
-rwxr-xr-x 1 root root 8589 2007-06-01 00:44 home.chk*
-rwxr–r– 1 root root 949 2007-06-01 00:44 init_kuang*
-rwxr-xr-x 1 root root 10648 2007-06-01 00:44 is_able*
-rwxr–r– 1 root root 2337 2007-06-01 00:44 is_able.chk*
-rwx—— 1 root root 2455 2007-06-01 00:49 is_able.lst*
-rw-r–r– 1 root root 2455 2007-06-01 00:48 is_able.lst.1
-rwxr-xr-x 1 root root 8876 2007-06-01 00:44 is_writable*
-rwxr–r– 1 root root 5970 2007-06-01 00:44 kuang*
-rwxr-xr-x 1 root root 9029 2007-06-01 00:44 members*
-rwxr–r– 1 root root 4178 2007-06-01 00:44 misc.chk*
-rwxr-xr-x 1 root root 16633 2007-06-01 00:44 pass.chk*
-rwx—— 1 root root 3278 2007-06-01 00:44 pass.words*
-rwxr–r– 1 root root 6593 2007-06-01 00:44 passwd.chk*
-rwx—— 1 root root 22 2007-06-01 00:53 patchlevel.h*
-rwx—— 1 root root 2387 2007-06-01 00:44 platform*
-rwxr–r– 1 root root 3270 2007-06-01 00:44 rc.chk*
-rwx—— 1 root root 6139 2007-06-01 00:44 reconfig*
-rwxr–r– 1 root root 1334 2007-06-01 00:44 res_diff*
-rwxr–r– 1 root root 4943 2007-06-01 00:44 root.chk*
-rwxr–r– 1 root root 6716 2007-06-01 00:44 suid.chk*
-rwx—— 1 root root 644 2007-06-01 00:44 suid.stop*
-rwxr-xr-x 1 root root 8279 2007-06-01 00:44 tilde*
-rwxr-xr-x 1 root root 9201 2007-06-01 00:44 user.chk*
-rwxr–r– 1 root root 886 2007-06-01 00:44 yp_pass.chk*

root@cameleon:/usr/local/cops# cd cameleon/
root@cameleon:/usr/local/cops/cameleon# ls -al
total 12
drwxr-xr-x 2 root root 4096 2007-06-01 00:51 ./
drwx—— 3 root root 4096 2007-06-01 00:53 ../
-rw-r–r– 1 root root 1178 2007-06-01 00:53 2007_Jun_1

root@cameleon:/usr/local/cops/cameleon# more 2007_Jun_1
ATTENTION:
Security Report for Fri Jun 1 00:53:41 JST 2007
from host cameleon, COPS v. Version 1.04+

Warning! /bin/login could have a hole/bug! (CA-89:01)
Warning! /usr/bin/rdist could have a hole/bug! (CA-91:20)

以上

コメント