このファイルサーバーは,firewallによって閉ざされたprivate LAN内に存在します。LAN内においては各種OSの共有機能によるアクセスを許可し,LAN外からのアクセスはftpのみ許可しています。LAN外からのtelnet, sshによるアクセスはできません。従って,唯一ftp接続が外部からの不正アクセスを受ける可能性があります。
外部からのftp接続は,firewallサーバーのログに詳細に記録されています。そのログをチェックするプログラムを作成し,cron.dailyにより毎日プログラムを実行することで,外部からの不正アクセスをチェックします。
チェックするログファイル
/var/log/delegate/aged/$year/$month/$day/21出力ファイル
/var/log/ftp/$month/$dayスクリプト
/etc/cron.daily/log-check1.0.pl
#!/usr/bin/perl #written by Shunsuke Sakai(2000/02/27) $,=' '; $\="\n"; %calendar=(1,31,2,29,3,31,4,30,5,31,6,30,7,31,8,31,9,30,10,31,11,30,12,31); ################# find the yesterday's log file ############################ system('date "+%Y %m %d" > /var/log/ftp/datefile'); open(DATE,"< /var/log/ftp/datefile"); while($date=){ chop $date; @line=split(/ +/,$date); $line[1]=~s/^0//; $year=$line[0]; $month=$line[1]; $yesterday=$line[2]-1; if($yesterday eq 0){ $month=$month-1; if($month eq 0){ $year=$year-1; $month=12; } $yesterday=$calendar{$month}; } $year=~s/^..//; if(length($month) eq 1){ $month=~s/^/0/; } if(length($yesterday) eq 1){ $yesterday=~s/^/0/; } } close(DATE); ########## get the yesterday's log file, & check the failed access ########## open(LOG,'<'."/var/log/delegate/aged/$year/$month/$yesterday/21"); while($log= ){ chop $log; $log=~s/^ +/0/; @line=split(/ +/,$log); if($line[7]=~m/incorrect/){ @check=(@check,$line[2]); system('mkdir','-p',"/var/log/ftp/$month"); open(CHECK,'>'."/var/log/ftp/$month/$yesterday"); } @sample=(@sample,[@line]); } foreach $a (@check){ foreach $b (@sample){ if($a eq @$b[2]){ print CHECK @$b; } } print CHECK "\n", '*****************************************************************************', "\n" } close(CHECK); close(LOG);