課題 334: ネットワークセキュリティ
334.4 バーチャルプライベートネットワーク(VPN)
LPIC303の試験範囲である主題331~335まであるうちの「334: ネットワークセキュリティ」から「334.4 バーチャルプライベートネットワーク(VPN)」についてのまとめ
総重量:4
説明:
OpenVPN, IPsec, WireGuardについて、サイト間VPNでのリモートアクセスでの設定を行い、利用を熟知している。主要な知識範囲:
ブリッジ・ルーティングされたVPNの概念を理解している。
OpenVPN, IPsec, IKEv2, WIreGuardプロトコルの主な違いと概念を理解している。
OpenVPNサーバとクライアントを設定・操作する。
IPsecサーバとクライアントを、strongSwanを利用して設定・操作する。
WireGuardサーバとクライアントを設定・操作する。
重要なファイル、用語、ユーティリティ:
/etc/openvpn/
openvpn
/etc/strongswan.conf
/etc/strongswan.d/
/etc/swanctl/swanctl.conf
/etc/swanctl/
swanctl
/etc/wireguard/
wg
ip
VPNの概念
Virtual Private Network(仮想閉域ネットワーク)
暗号化された仮想的なネットワークを実現する
「認証」と「暗号化」が重要
VPNの種類
PPTP
1723/TCP を使うSSTP
443/TCP を使う
Microsoft社によって開発されたプロトコルIPSec
ESP(暗号化):プロトコル番号 50
AH(認証):プロトコル番号 51
(TCP/UDPの情報は暗号化されているのでポート番号での識別は不可)L2TP
認証機能を提供する
暗号化の機能は持たないのでIPSecと併用する L2TP/IPSec がある
1701/UDP を使用するIKEv2
鍵交換機能を提供
500/UDP を使用するSSL-VPN
443/TCP を使う
OpenVPNの場合は 1194/tcp を使うNATトラバーサル
4500/UDP を使用する
VPNの接続形態(1)
site-to-sitevpn
拠点間VPN
拠点のVPN機器がVPNトンネルを構成するので、クライアントPCはVPNを使っていることを意識することはないremote access vpn
リモートアクセスVPN
モバイルユーザーが利用する
PCには専用のVPNクライアントをインストールして使うのが一般的
なりすましや認証情報の漏洩といった脅威への対策としてOTP、MFAなどを併用する
VPNの接続形態(2)
ルート接続
VPNクライアント側とVPNサーバー側でそれぞれ異なるネットワークアドレスを割り当ててルーティングよって相互通信を実現するブリッジ接続
VPNクライアント側とVPNサーバー側で同じネットワークアドレスを割り当ててLayer2レベル相互通信を実現する
VPN接続の諸問題
NATが越えられない
VPNはプロトコルの性質上NAT/PAT環境では不具合が生じる場合があるので、HTTPSでも使われているSSL/TLSを使うSSTPやSSL-VPNを使ったり、NATトラバーサル、VPNパススルーといった機能を使うことで接続性を向上させることが可能になる。
Firewallが超えられない
VPNは様々なプロトコルを組み合わせて使われるので、Firewall設定の難易度は高くなる。
また、暗号化の過程で様々なヘッダが付加されるためMSS値やMTU値を通常より少ない値に調整しないと通信できない場合がある。
速度が出ない
通信するすべてのデータを暗号化/復号化処理をすることになるので、通信速度はPCスペックの影響を受けることになる
OpenVPN, IPsec, IKEv2, WireGuardプロトコルの主な違いと概念
OpenVPNの特徴
IPSecの特徴
OSI参照モデルのネットワーク層(Layer3)で暗号化するプロトコル
- 認証と改ざん防止:AH(Authentication Header)
- 暗号化:ESP(Encapsulated Security Payload)
- 鍵交換:IKE(Internet Key Exchange protocol)
- 論理的な経路:SA(Security Association)
- SAD(Security Association Database)
- SPD(Security Policy Database)
IKEv2
IPSecでは共通鍵暗号方式を使っていることから安全に秘密鍵を交換する必要があるためIKEが使われることが多い。
IKEはInternet Key Exchange の略で、VPNに必要な共通鍵を安全に交換するためのプロトコル。
WireGuard
参考
OpenVPNサーバとクライアントを設定・操作する
OpenVPNとは
SSL-VPNを実現するオープンソースソフトウェア
インストール
RockyLinux 9
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# dnf install openvpn[root@lpic303-rocky34 ~]#
Ubuntu 22.04
root@lpic303-ubuntu35:~#root@lpic303-ubuntu35:~# apt install openvpnroot@lpic303-ubuntu35:~#
設定ファイル
/etc/openvpn/*
/etc/openvpn/client/*
/etc/openvpn/server/*
設定ファイル:client.conf
SAMPLE
/usr/share/doc/openvpn/sample/sample-config-files/client.conf
ca<ファイル名>
cert<ファイル名>
key<ファイル名>
proto <tcp | udp>
cipher<暗号化方式>
remote <hostname | ipaddress> [port]
nobind
特定のポート番号を使用したい場合はdev <tun | tap>
tun:ルート接続
tap:ブリッジ接続
設定ファイル:server.conf
SAMPLE
/usr/share/doc/openvpn/sample/sample-config-files/server.conf
ca<ファイル名>
cert<ファイル名>
key<ファイル名>
keepalive<間隔><待ち時間>
port<ポート番号>
proto <tcp | udp>
push "route <宛先ネットワークアドレス>"
push "dhcp-option <DHCPオプション>"
server <ネットワークアドレス>
cipher<暗号化方式>
dev <tun | tap>
tun:ルート接続
tap:ブリッジ接続
コマンド
--daemon
--genkey--secret <鍵>
--mlock
--show-ciphers
--show-tls
--tls-timeout <秒>
--resolv-retry <秒>
参考
strongSwanを利用して設定・操作
strongSwanとは
IKEでVPNを実現するオープンソースソフトウェア
FreeS/WANプロジェクトから派生したプロジェクト
類似の派生プロジェクトにOpenswanがある
インストール
RockyLinux 9
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# dnf install strongswan[root@lpic303-rocky34 ~]#
Ubuntu 22.04
root@lpic303-ubuntu35:~#root@lpic303-ubuntu35:~# apt install strongswanroot@lpic303-ubuntu35:~#
構成要素
swanctl
VICI(Versatile IKE Control Interface)を介してcharonデーモンを操作するCLIツールcharon
IKEv2 デーモン
設定ファイル(RockyLinux9)
strongSwan
/etc/strongswan/*
/etc/strongswan/strongswan.conf
/etc/strongswan/strongswan.d/charon/*.conf
/etc/strongswan/strongswan.d/*.confswanctl
VPN接続に関する設定
/etc/strongswan/swanctl/*
/etc/strongswan/swanctl/swanctl.confipsec
旧VPN接続に関する設定(Deprecated)
/etc/strongswan/ipsec.conf
/etc/strongswan/ipsec.secrets
/etc/strongswan/ipsec.d/cacerts/*:認証局証明書
/etc/strongswan/ipsec.d/certs/*:サーバー証明書
/etc/strongswan/ipsec.d/private/*:認証局・サーバーの秘密鍵
(補足)
2019年にリリースされたstrongSwan5.8.0から "ipsec.conf" の内容は "swanctl.conf" に記述することになっているため "ipsec.conf" の使用は非推奨となっている。
LPIC303-300がリリースされたのが2021年10月で、試験範囲にも "ipsec.conf" の記載がないことから、"swanctl.conf" について学習する必要があると推測される。
コマンド
/usr/sbin/charon-cmd
IKEを使ったIPSec接続を設定するコマンド
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# charon-cmd --helpUsage: /usr/sbin/charon-cmd --help print this usage information and exit --version show version information and exit --debug <level> set the default log level (-1..4, default: 1) --host <hostname> DNS name or address to connect to --identity <identity> identity the client uses for the IKE exchange --eap-identity <eap-identity> identity the client uses for EAP authentication --xauth-username <xauth-username> username the client uses for XAuth authentication --remote-identity <identity> server identity to expect, defaults to host --cert <path> certificate for authentication or trust chain validation --rsa <path> RSA private key to use for authentication --p12 <path> PKCS#12 file with private key and certificates to use for authentication and trust chain validation --agent[=socket] use SSH agent for authentication. If socket is not specified it is read from the SSH_AUTH_SOCK environment variable --local-ts <subnet> additional traffic selector to propose for our side --remote-ts <subnet> traffic selector to propose for remote side --ike-proposal <proposal> a single IKE proposal to offer instead of the default --esp-proposal <proposal> a single ESP proposal to offer instead of the default --ah-proposal <proposal> a single AH proposal to offer instead of the default --profile <name> authentication profile to use, where name is one of: ikev2-pub, ikev2-eap, ikev2-pub-eap ikev1-pub[-am], ikev1-xauth[-am], ikev1-xauth-psk[-am], ikev1-hybrid[-am][root@lpic303-rocky34 ~]#
/usr/sbin/charon-systemd
charonのsystemd用のプログラム/usr/sbin/strongswan
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# strongswan --helpstrongswan command [arguments]Commands: start|restart [arguments] update|reload|stop up|down|route|unroute <connectionname> down-srcip <start> [<end>] status|statusall [<connectionname>] listalgs|listpubkeys|listcerts [--utc] listcacerts|listaacerts|listocspcerts [--utc] listacerts|listgroups|listcainfos [--utc] listcrls|listocsp|listplugins|listall [--utc] listcounters|resetcounters [name] leases [<poolname> [<address>]] rereadsecrets|rereadcacerts|rereadaacerts rereadocspcerts|rereadacerts|rereadcrls|rereadall purgecerts|purgecrls|purgeike|purgeocsp pki stroke versionRefer to the strongswan(8) man page for details.Some commands have their own man pages, e.g. pki(1).[root@lpic303-rocky34 ~]#
/usr/sbin/swanctl
charonデーモンを操作するコマンド
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# swanctl --helpstrongSwan 5.9.10 swanctlloaded plugins: pkcs11 aesni aes des rc2 sha2 sha1 md4 md5 mgf1 random nonce x509 revocation constraints acert pubkey pkcs1 pkcs7 pkcs12 pgp dnskey sshkey pem openssl gcrypt pkcs8 fips-prf gmp curve25519 chapoly xcbc cmac hmac kdf ctr ccm gcm drbg newhope curlusage: swanctl --reload-settings (-r) reload daemon strongswan.conf swanctl --stats (-S) show daemon stats information swanctl --version (-v) show version information swanctl --log (-T) trace logging output swanctl --load-pools (-a) (re-)load pool configuration swanctl --load-creds (-s) (re-)load credentials swanctl --load-conns (-c) (re-)load connection configuration swanctl --load-authorities (-b) (re-)load authority configuration swanctl --load-all (-q) load credentials, authorities, pools and connections swanctl --flush-certs (-f) flush cached certificates swanctl --list-algs (-g) show loaded algorithms swanctl --list-pools (-A) list loaded pool configurations swanctl --list-certs (-x) list stored certificates swanctl --list-conns (-L) list loaded configurations swanctl --list-authorities (-B) list loaded authority configurations swanctl --list-pols (-P) list currently installed policies swanctl --monitor-sa (-m) monitor for IKE_SA and CHILD_SA changes swanctl --list-sas (-l) list currently active IKE_SAs swanctl --install (-p) install a trap or shunt policy swanctl --uninstall (-u) uninstall a trap or shunt policy swanctl --redirect (-d) redirect an IKE_SA swanctl --rekey (-R) rekey an SA swanctl --terminate (-t) terminate a connection swanctl --initiate (-i) initiate a connection swanctl --counters (-C) list or reset IKE event counters swanctl --help (-h) show usage information[root@lpic303-rocky34 ~]#
参考
WireGuardサーバとクライアントを設定・操作
WireGuardとは
VPNを実現するオープンソースソフトウェア
設定がシンプル
インストール
RockyLinux 9
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# dnf install wireguard-tools[root@lpic303-rocky34 ~]#
Ubuntu 22.04
root@lpic303-ubuntu35:~#root@lpic303-ubuntu35:~# apt install wireguardroot@lpic303-ubuntu35:~# apt install wireguard-toolsroot@lpic303-ubuntu35:~#
設定ファイル
/etc/wireguard/*
コマンド
[root@lpic303-rocky34 ~]#[root@lpic303-rocky34 ~]# wg --helpUsage: wg <cmd> [<args>]Available subcommands: show: Shows the current configuration and device information showconf: Shows the current configuration of a given WireGuard interface, for use with `setconf' set: Change the current configuration, add peers, remove peers, or change peers setconf: Applies a configuration file to a WireGuard interface addconf: Appends a configuration file to a WireGuard interface syncconf: Synchronizes a configuration file to a WireGuard interface genkey: Generates a new private key and writes it to stdout genpsk: Generates a new preshared key and writes it to stdout pubkey: Reads a private key from stdin and writes a public key to stdoutYou may pass `--help' to any of these subcommands to view usage.[root@lpic303-rocky34 ~]#
wg genkey
秘密鍵を作成するwg pubkey
秘密鍵に対応する公開鍵を作成するwg showconf
設定を表示する
リダイレクトして設定ファイルとして保存する
設定ファイルは/etc/wireguard/<NIC名>.conf とするwg-quick<NIC名>
設定ファイルを読み取ってVPN接続を開始/終了する
参考
L2TPの知識
L2TPとは
Layer 2 Tunneling Protocol
交渉、認証、通知、監視の機能を持つPPP(Point-to-Point Protocol)をデータリンク層(Layer2)でカプセル化するプロトコル
データの暗号化機能はないため、IPSecを併用する L2TP/IPSec が使われる
1701/UDP を使う
コマンド
ip l2tp add tunnel
ip l2tp add session
ip l2tp del tunnel
ip l2tp del session
ip l2tp show tunnel
ip l2tp show session