0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

/var/log/secureを分類・整理する

Last updated at Posted at 2025-02-02

インターネット上のsshを公開しているので、sshのアクセスログを分析する。
secureログには、アクセスしたユーザ名、接続元IPアドレスが残っているので、これを分類整理する。

アウトプットイメージ

スクリーンショット 2025-02-02 16.47.23.png

sshdの設定。デフォルトのまま

/etc/ssh/sshd_conf
# Logging
#SyslogFacility AUTH
#LogLevel INFO

secureログのサンプル

  • ユーザ名「admin」,接続元IPアドレス「92.255.85.107」を正規化したCSVファイルを作成する
/var/log/secure
2025-02-02T00:03:56.881822+09:00 indigo sshd[375538]: Invalid user admin from 92.255.85.107 port 47890
2025-02-02T00:03:57.171420+09:00 indigo sshd[375538]: Connection reset by invalid user admin 92.255.85.107 port 47890 [preauth]

ソース

gist

  • sec01.sh リモートホストから、/var/log/secureを取得するシェル
  • sec02.sh secureを分類・整理するシェル。sec_001.plを起動
  • sec03.sh sec02.shで作成した、secure.tsvをカウントするシェル
  • sec_001.pl secureを分類・整理するPerl
  • secTSV.pl secureをTSV化するPerl
  • Secure.pl 部品集(secureを分解する)
  • Dbglog.pl 部品集(レベル分けしてSTDERRにログ出力する)

PATH_TO_PERLのディレクトリに *.pl を配置する。シェルは任意の場所でOK。

  • 入力ファイル:SECURE="secure"
  • 出力ファイル:SECTSV="secure.tsc"
    • 出力ファイルはTAB区切り
sec02.sh
#!/bin/sh
PLBIN=/PATH_TO_PERL

## 001.pl
[ ! -f "$SECURE" ] && echo "!!ERR not found $SECURE" && exit 1
echo "!!INF, Count secure by MSG-TYPE, sec_001.pl IN:$SECURE OT:$SECTSV"
$PLBIN/sec_001.pl --inf=$SECURE --otf=$SECTSV
#
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?