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?

More than 3 years have passed since last update.

xrdpのログを監査し、ログイン成功したら外部メール送信する#2

Posted at

xrdpで、linux-desktopを開放しているので、ログ監査をする。

  • CentOS7.5
  • ログイン成功したら、メールを送信する。
  • メール送信は、swatchを使う。
  • メール送信設定は、これを参考に。
    メール送信設定

ログ監査の検討

ログサンプル

/var/log/xrdp-sesman.log
## ログイン
[20200808-21:39:26] [INFO ] ++ created session (access granted): username USERNAME, ip WWW.XXX.YYY.ZZZ:PORT - socket: 12
## ログアウト
[20200808-21:49:57] [INFO ] ++ terminated session:  username USERNAME, display :10.0, session_pid 17979, ip WWW.XXX.YYY.ZZZ:PORT - socket: 12

ログ監査

swatchをインストール

# yum install swatch

swatchで /var/log/xrdp-sesman.log を監査する

swatchのスクリプト

/root/binbin/swatch.webarena.xrdp.sh
#
# Swatch for /var/log/xrdp-sesman.log on webarenavps (centos)
#   /lib/systemd/system/user_swatch_xrdp.service
#

## swatchを無視する条件
ignore   /from MY.HOME.IP.ADDR.*/
## mailする条件
watchfor /access granted/
  mail=YOUR@MAIL.DOMAIN,subject="webarenavps:xrdp login successful"
    threshold track_by=/access granted/,type=limit,count=1,seconds=300

MY.HOME.IP.ADDRからのxrdpログイン成功は無視する。

作成したswatchスクリプトをsystemdにサービス登録する

/usr/lib/systemd/system/user_swatch_xrdp.service
[Unit]
Description=xrdp-log Authentication
After=rsyslog.service

[Service]
ExecStart=/usr/bin/swatch -c /root/binbin/swatch.webarenavps.xrdp.sh -t /var/log/xrdp-sesman.log --pid-file /root/user_swatch_xrdp.pid > /dev/null 2>&1
PIDFile=/root/user_swatch_xrdp.pid
KillMode=process
Type=simple
Restart=no

[Install]
WantedBy=multi-user.target

systemdでサービス登録

# systemctl enable user_swatch_xrdp
# systemctl start  user_swatch_xrdp
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?