4
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 1 year has passed since last update.

Falco Ruleを紹介するシリーズ - Disallowed SSH Connection

Last updated at Posted at 2022-09-02

本シリーズでは、ランタイム脅威検知のデファクトスタンダードであるFalcoの検知Ruleを、1つの記事で1つ簡単に紹介していきます。
ランタイムセキュリティやFalco自体の概要を知りたい方はこちらのブログ記事をご参照ください。
今回ご紹介する検知Ruleは「Disallowed SSH Connection」です。

Rule記述

- rule: Disallowed SSH Connection
  desc: Detect any new ssh connection to a host other than those in an allowed group of hosts
  condition: (inbound_outbound) and ssh_port and not allowed_ssh_hosts
  enabled: false
  output: Disallowed SSH Connection (command=%proc.cmdline connection=%fd.name user=%user.name user_loginuid=%user.loginuid container_id=%container.id image=%container.image.repository)
  priority: NOTICE
  tags: [network, mitre_remote_service]

Rule概要

ホストへの新規のSSH接続を検知します。
攻撃対象領域を減らすことは、セキュリティのベストプラクティスの一つですが、SSHなどのリモートコンソールサービスへの自由な接続を取り除くことで、サーバーのリスクに対する露出を減らすことができます。
実際、SSHポートをインターネットに公開すると、最初のSSHブルートフォース攻撃は12時間以内に発生すると言われています。
関連情報として、EC2上のSSHに関するこちらのブログ記事もご参照ください。
許可されたホストグループ以外のホストでSSH接続が使用された場合、このRuleを使うことで検知可能です。

Condition(条件)

(inbound_outbound) and ssh_port
SSHポート接続が行われ、

かつ

and not allowed_ssh_hosts
SSH接続を許可されたホストグループではない場合

今回は簡単な条件なので、Conditionを構成するマクロも見てみましょう。

- macro: inbound_outbound
  condition: >
    ((((evt.type in (accept,listen,connect) and evt.dir=<)) and
     (fd.typechar = 4 or fd.typechar = 6)) and
     (fd.ip != "0.0.0.0" and fd.net != "127.0.0.0/8") and
     (evt.rawres >= 0 or evt.res = EINPROGRESS))

((evt.type in (accept,listen,connect) and evt.dir=<)) and
イベント名がaccept, listen, connectのどれかのexitイベントで、

(fd.typechar = 4 or fd.typechar = 6)) and
ファイルディスクリプタがIPv4もしくはIPv6ソケットで、

(fd.ip != "0.0.0.0" and fd.net != "127.0.0.0/8") and
IPアドレスが"0.0.0.0"ではなく、IPネットワークが"127.0.0.0/8"でもなく、

(evt.rawres >= 0 or evt.res = EINPROGRESS)
イベントが成功もしくは進行中の場合

- macro: ssh_port
  condition: fd.sport=22

fd.sport=22
サーバーポートが22の場合

- macro: allowed_ssh_hosts
  condition: ssh_port

ssh_port
メインのfalcoルールファイルでは、sshアクセスが許可される特定のホストを知る方法がないので、このマクロは上記のssh_portマクロを繰り返すだけで、効果的にすべてのホストからのsshを許可します。ローカルのfalcoルールファイルでマクロを上書きして特定のホストを設定する場合、条件は "fd.sip="a.b.c.d" or fd.sip="e.f.g.h" のような感じになります。

Output(出力)

許可されていないSSH接続

%proc.cmdline
コマンドライン

%fd.name
接続名

%user.name
ユーザー名

%user.loginuid
ユーザーのログインUID

%container.id
コンテナID

%container.image.repository
コンテナイメージリポジトリ

4
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
4
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?