tigerの導入


■はじめに

 侵入の痕跡を検知することもまた、平常時からの確認が必要なものなのです。
 日本語、かつフレッシュな記事が無かったので、少し冗長に行きましょう。
 ※フレッシュは死語かも知れない。「tiger」は、ネコ科のAppleのOSとは無関係(のはず)。。。

■「tiger」パッケージの検索

$ apt-cache search ^tiger
tiger - Report system security vulnerabilities
tiger-otheros - 他の OS で Tiger を起動するためのスクリプト

■「tiger」って何をするの?
 一言で言うと、「lsof」の自動化。

$ sudo apt-cache show tiger | grep "Suggests\|Recommends"
Recommends: sendmail | mail-transport-agent, john, chkrootkit
Suggests: lsof

■「lsof」って何?

$ apropos lsof
lsof (8)             - list open files

$ apt-cache show lsof | grep -A 3 Desc
Description-ja: 開いているファイルの一覧化
 lsof は UNIX 専用の診断ツールです。その名称は LiSt Open Files の略で、
 その通りの動作をします。システム上で現在実行中のプロセスによって開かれ
 ている全ファイルに関する情報を一覧化します。

■余談。「lsof」のCSV化
 単純にスペースが一つ以上あったら、「,」に変換します。
 ※一つを含む正規表現に注意。

$ sudo lsof | sed s/"  *"/","/g | head -5
COMMAND,PID,USER,FD,TYPE,DEVICE,SIZE/OFF,NODE,NAME
init,1,root,cwd,DIR,8,1,4096,2,/
init,1,root,rtd,DIR,8,1,4096,2,/
init,1,root,txt,REG,8,1,36992,376854,/sbin/init
init,1,root,mem,REG,8,1,14696,458789,/lib/libdl-2.11.3.so

■脱線。「lsof」のCSV化
 ダブルコーテーションで囲わないとイヤという人は以下のように。
 ※列幅を増やす「タブ区切り」は無しの方向で。。。

$ sudo lsof | sed s/"  *"/","/g | head -5 | sed s/"^\|\$\|\,"/"\"&"/g | sed s/"\,"/"&\""/g
"COMMAND","PID","USER","FD","TYPE","DEVICE","SIZE/OFF","NODE","NAME"
"init","1","root","cwd","DIR","8","1","4096","2","/"
"init","1","root","rtd","DIR","8","1","4096","2","/"
"init","1","root","txt","REG","8","1","36992","376854","/sbin/init"
"init","1","root","mem","REG","8","1","14696","458789","/lib/libdl-2.11.3.so"

■「john」って何?
 「john the ripper」で分かるはずです。。。そうでなければググりましょう。。。

$ apt-cache show john | grep ^Desc -A 8
Description-ja: 有能なパスワードクラッキングツール
 john は、通常 john the ripper と呼ばれており、あなたのユーザの
 脆弱なパスワードを見つけ出し、もし望むなら自動的にユーザへメールを
 送信してくれるツールです。
 .
 異なる暗号テキスト型式内の脆弱なパスワードを見つけるのにも使うことが
 できます。対応型式: UNIX の DES と MD5, Kerberos AFS passwords 対応、
 Windows の LM ハッシュ、 BSDI の extended DES, OpenBSD の Blowfish
Homepage: http://www.openwall.com/john/

■簡単に。。。

$ dpkg -L john | grep 'bin/'
/usr/sbin/mailer
/usr/sbin/john
/usr/sbin/unique
/usr/sbin/unshadow
/usr/sbin/unafs

$ dpkg -L john | grep 'bin/' | sed s%".*\/"%%g | for list in `xargs`;do apropos "^${list}\$";done
mailer (8)           - script to warn users about their weak passwords
john (8)             - a tool to find weak passwords of your users
unique (8)           - removes duplicates from a wordlist
unshadow (8)         - combines passwd and shadow files
unafs (8)            - script to warn users about their weak passwords

$ dpkg -L john-data| grep "\.[cl]"
/usr/share/john/password.lst
/usr/share/john/lanman.chr
/usr/share/john/alnum.chr
/usr/share/john/digits.chr
/usr/share/john/all.chr
/usr/share/john/alpha.chr

■パスワードハッシュを持ったユーザを探す。
 まさか、「group」や「passwd」に平文は無いですよね?
 実際の実行はマニュアルか、「tiger」で自動的に。。。

$ sudo awk -F\: '{if ($2=="*" || $2=="!" || $2=="x") ;else print $1}' /etc/passwd
$ sudo awk -F\: '{if ($2=="*" || $2=="!" || $2=="x") ;else print $1}' /etc/group
$ sudo awk -F\: '{if ($2=="*" || $2=="!" || $2=="x") ;else print $1}' /etc/shadow
root
labunix

■「chkrootkit」って何?

 chkrootkit、tripwire、clamavチェック
 http://d.hatena.ne.jp/labunix/20120830

$ apt-cache show chkrootkit | grep -A 12 ^Desc
Description-ja: ルートキット検知ツール
 chkrootkit セキュリティスキャナはローカルシステムが 'rootkit' に感染
 した兆候を走査します。ルートキットは既知のセキュリティ欠陥を使って
 ターゲットマシンの制御を乗っ取るように設計されたプログラムやハックの
 集合体です。
 .
 chkrootkit は認識可能なルートキットの種類はプロジェクトのホームページに
 記載されています。
 .
 chkrootkit が侵入を検知していないからといって、そのシステムが侵入されていない
 ことを保証しているわけではないことに中尉してください。chkrootkit の起動に
 加え、より特化したテストを常時実行すべきです。
Homepage: http://www.chkrootkit.org/

■結局、「tiger」って何?

$ dpkg -L tiger | grep 'bin/'
/usr/sbin/tiger
/usr/sbin/tigexp
/usr/sbin/tigercron
/usr/lib/tiger/bin/getpermit
/usr/lib/tiger/bin/snefru
/usr/lib/tiger/bin/md5
/usr/lib/tiger/bin/testsuid
/usr/lib/tiger/bin/realpath

$ dpkg -L tiger | grep 'bin/' | sed s%".*/"%%g | for list in `xargs`;do apropos "^${list}\$";done
tiger (8)            - UNIX Security Checker
tigexp (8)           - UNIX Security Checker Explanation Generator
tigercron (8)        - Cron utility for Tiger UNIX Security Checker
md5 (1ssl)           - message digests
realpath (3)         - 正規化された絶対パス名を返す
realpath (1)         - return the canonicalised absolute pathname

■実行して気長に待ちましょう。。。

$ sudo tiger
Tiger UN*X security checking system
   Developed by Texas A&M University, 1994
   Updated by the Advanced Research Corporation, 1999-2002
   Further updated by Javier Fernandez-Sanguino, 2001-2010
   Contributions by Francisco Manuel Garcia Claramonte, 2009-2010
   Covered by the GNU General Public License (GPL)

Configuring...

Will try to check using config for 'x86_64' running Linux 2.6.32-5-amd64...
--CONFIG-- [con005c] Using configuration files for Linux 2.6.32-5-amd64. Using
           configuration files for generic Linux 2.
Tiger security scripts *** 3.2.3, 2008.09.10.09.30 ***
22:23> Beginning security report for vmdebian.localdomain.
22:23> Starting file systems scans in background...
22:23> Checking password files...
22:23> Checking group files...
22:23> Checking user accounts...
22:24> Checking .rhosts files...
22:24> Checking .netrc files...
22:24> Checking ttytab, securetty, and login configuration files...
22:24> Checking PATH settings...
22:24> Checking anonymous ftp setup...
22:24> Checking mail aliases...
22:24> Checking cron entries...
22:24> Checking 'services' configuration...
22:24> Checking NFS export entries...
22:24> Checking permissions and ownership of system files...
--CONFIG-- [con010c] Filesystem 'fuse.vmware-vmblock' used by 'vmware-vmblock' is not recognised as a valid filesystem
22:24> Checking for indications of break-in...
--CONFIG-- [con010c] Filesystem 'fuse.vmware-vmblock' used by 'vmware-vmblock' is not recognised as a valid filesystem
22:24> Performing rootkit checks...
22:25> Performing system specific checks...
22:31> Performing root directory checks...
22:31> Checking for secure backup devices...
22:31> Checking for the presence of log files...
22:31> Checking for the setting of user's umask...
22:31> Checking for listening processes...
22:31> Checking SSHD's configuration...
22:31> Checking the printers control file...
22:31> Checking ftpusers configuration...
22:31> Checking NTP configuration...
22:31> Waiting for filesystems scans to complete...
22:31> Filesystems scans completed...
22:31> Performing check of embedded pathnames...
22:32> Security report completed for ibm-amddebian.labunix.net.
Security report is in '/var/log/tiger/security.report.vmdebian.localdomain.120912-22:23'.

■「at」は止めてます。
 「su」は極力使わず、通常は「sudo」です。
 「passwd」にはパスワードはありません。
 「wall」は。。。

$ sudo grep ALERT /var/log/tiger/security.report.vmdebian.localdomain.120912-22:23
--ALERT-- [perm023a] /bin/su is setuid to 'root'.
--ALERT-- [perm023a] /usr/bin/at is setuid to 'daemon'.
--ALERT-- [perm024a] /usr/bin/at is setgid to 'daemon'.
--ALERT-- [perm023a] /usr/bin/passwd is setuid to 'root'.
--ALERT-- [perm024a] /usr/bin/wall is setgid to 'tty'.

■「wall」を無視する。

$ apropos ^wall
wall (1)             - 全員の端末にメッセージを送る。
$ apropos ^mesg
mesg (1)             - 使用中の端末への書き込み許可属性を制...
$ mesg
is y
$ mesg n
$ mesg
is n

■「/etc/profile」の最終行に追加、再度ログインしなおし確認する。

$ sudo tail -1 /etc/profile
mesg n
$ exit

$ mesg
is n

■「tiger」コマンドでチェックする項目
 ※「sort」で「=N」、「=Y」の順に並べ替えているので、
  「grep -v "=Y"」を入れなくても、また、「column」しなくても読みやすいはず。

$ sudo grep "Tiger_Check" /etc/tiger/tigerrc | awk '{print $1}' | sort -t\= -k 2 | grep -v "=Y" | column -c 100
Tiger_Check_APACHE=N            Tiger_Check_OMNIBACK=N          Tiger_Check_PATHALL=N
Tiger_Check_DELETED=N           Tiger_Check_PASSWD_FORMAT=N     Tiger_Check_RUNPROC=N
Tiger_Check_ETCISSUE=N          Tiger_Check_PASSWD_NIS=N        Tiger_Check_SENDMAIL=N
Tiger_Check_EXRC=N              Tiger_Check_PATCH=N             Tiger_Check_SIGNATURES=N

■「tigercron」
 ※これは気長に待ちますか。。。

$ apropos tigercron
tigercron (8)        - Cron utility for Tiger UNIX Security Checker

$ sudo grep "^0" /etc/tiger/cronrc
0,8,16 * *   check_known check_rootkit check_logfiles check_runprocs check_rootdir check_root
0,4,6,10,14,18,20 * *           check_listeningprocs

$ sudo tigercron
Configuring...

Will try to check using config for 'x86_64' running Linux 2.6.32-5-amd64...
--CONFIG-- [con005c] Using configuration files for Linux 2.6.32-5-amd64. Using
           configuration files for generic Linux 2.

$ sudo grep -i "^Tiger.*CRON" /etc/tiger/tigerrc | awk '{print $1}'
Tiger_Check_CRON=Y
Tiger_Cron_SendOKReports=N
TigerCron_Log_Keep_Max=10
Tiger_Cron_Template=N
Tiger_Cron_CheckPrev=Y
Tiger_CRON_Output_Width=0
Tiger_Running_Procs='syslogd'

$ sudo grep "tigercron" /var/log/syslog | sed s/".*\: "// | sed s/";"/"& \\\\\n"/g
(root) CMD (   test -x /usr/sbin/tigercron && { [ -r "$DEFAULT" ] && . "$DEFAULT" ; \
 nice -n$NICETIGER /usr/sbin/tigercron -q ; \
 })

$ sudo tigercron --help | grep -A 1 "\-q"
       -q     Supress messages to be as quiet as possible, only
              security messages will be shown.

$ sudo cat /etc/cron.d/tiger | sed s/";"/"& \\\\\n"/g
#
# Regular cron jobs for the tiger package
#
# Configuration file
DEFAULT=/etc/default/tiger
#  default setting, overriden in the above file
NICETIGER=10
#
0 * * * *      root    test -x /usr/sbin/tigercron && { [ -r "$DEFAULT" ] && . "$DEFAULT" ; \
 nice -n$NICETIGER /usr/sbin/tigercron -q ; \
 }

■手動チェック
 これは様子見コースですね。。。

$ su root -c 'env DEFAULT=/etc/default/tiger \
              test -x /usr/sbin/tigercron && \
              { \
                [ -r "$DEFAULT" ] && \
                  . "$DEFAULT" ; \
                  nice -n10 /usr/sbin/tigercron ; \
               }'
Configuring...

Will try to check using config for 'x86_64' running Linux 2.6.32-5-amd64...
--CONFIG-- [con005c] Using configuration files for Linux 2.6.32-5-amd64. Using
           configuration files for generic Linux 2.