LoginSignup
32
5

More than 3 years have passed since last update.

AnyConnect のコマンドラインをいろいろ使ってみる

Posted at

はじめに

この記事は、Cisco Systems Japan Advent Calendar 2020 1枚目 の 21日目として投稿しています。
今年は 2枚目 の Calendar まで立ち上がっており、例年以上に盛り上がっております。

2017年版: https://qiita.com/advent-calendar/2017/cisco
2018年版: https://qiita.com/advent-calendar/2018/cisco
2019年版: https://qiita.com/advent-calendar/2019/cisco
2020年度版1枚め: https://qiita.com/advent-calendar/2020/cisco <-- この記事はこちら
2020年度版2枚め: https://qiita.com/advent-calendar/2020/cisco2

リモートアクセス VPN と AnyConnect

今年ほど在宅勤務やリモートワークに注目された年はありません。新型コロナウイルスの影響で、日本の企業も、可能なところであれば、一気に緊急的にリモートワークの環境が整備され、実際に使われるようになりました。もともとの業務的には可能だったものの、「やっぱり足を現場に運んでナンボ」な文化は変わらなかったのですが、今年は一気にその文化が変わった年ではないでしょうか。

さて、そのリモートワークの傾向の1つに「VPNレス」というキーワードがあります。リモートワークの手段として、リモートアクセス VPN 以外の手法を使おう、という考え方です。この「VPNレス」という考え方については、業務的に、インフラ的に可能なのであれば、どんどん進めていっていいと私的には思います。しかしながら、本当に完全な「VPNレス」に行ける環境ではないインフラや業務の方も多数おられるかと思います。シスコ社員でも、もうほとんどリモートアクセス VPN を使っていない人もいますが、例えば社内に構築したラボへの安全なアクセスだったり、社内アドレスからしか到達できない IPv4 プライベートアドレスで動いているサーバへのアクセス等で、リモートアクセス VPN をまだまだ利用している人も多数います。私もそのひとりです。

シスコの製品にてリモートアクセス VPN を構築するとなると、Cisco ASA という、Basic Firewall 兼 VPN 終端装置 + AnyConnect クライアントという組み合わせが、最も多く使われており、私も商談で提案することが多い組み合わせです。

GUI に触らずに AnyConnect を使いたい

その AnyConnect ですが、当然、最初にインストールが必要です。AnyConnect は VPN 機能以外にも、Umbrella との連携が可能なローミングセキュリティモジュール等、いろいろなモジュールの追加が可能であり、追加の際にはそのモジュールのインストールがまた必要になります。

AnyConnect を使ってリモートアクセス VPN を繋ぐ際にも、AnyConnect のアイコンをダブルクリックする必要があります。

このインストール作業や VPN 接続のオペレーションをもっと簡素化したい、という要望は多いようです。もっと言えば、GUI でダブルクリックするようなことを省きたい、という要望です。

意外と知られていませんが、AnyConnect をコマンドラインで使うことは可能です。実際に試してみたいと思います。

AnyConnect をコマンドラインでインストールする

AnyConnect の VPN コアモジュールはもちろん、その他のモジュールも、インストーラさえ PC に置いておけば、コマンドラインでのインストールが可能です。実際に利用者に配布する PC を想定し、今回は Windows 10 で試してみたいと思います。

まずはインストーラを準備します。AnyConnect が利用可能な方は cisco.com のダウンロードサイトから取得ができるかと思いますが、どのファイルがそのインストーラなのかがわかりにくいのでご注意ください。Pre-Deployment と書いてあるファイルがそれにあたります。

image.png

ダウンロードしたファイルは解凍して、インストールに必要なファイルだけを、PC に配布してください。例えば、VPN コアモジュールと Umbrella ローミングセキュリティモジュールをインストールするのであれば、以下の2つのファイルがそれにあたります。x.x.xxxx はバージョンの数字です。

・anyconnect-win-x.x.xxxx-core-vpn-predeploy-k9.msi
・anyconnect-win-x.x.xxxx-umbrella-predeploy-k9.msk

コマンドラインでのインストールは簡単で、管理者権限のコマンドプロンプトから msiexec コマンドを実行するだけです。例えば、単純に AnyConnect の VPN コアモジュールをインストールするだけであれば、msiexec /package でインストールファイルを引数で渡すだけでインストールができてしまいます。

実際に実施してみましょう。実行すると以下のようにセットアップウィザードが起動し、普通にインストールができました。

C:\tmp\AnyConnect>msiexec /package anyconnect-win-4.9.04053-core-vpn-predeploy-k9.msi

image.png

image.png

image.png

Umbrella ローミングセキュリティモジュールも同様の手順でインストールができました。

C:\tmp\AnyConnect>msiexec /package anyconnect-win-4.9.04053-umbrella-predeploy-k9.msi

image.png

image.png

image.png

AnyConnect の VPN をコマンドラインで接続してみる

インストールした AnyConnect の VPN を、実際にコマンドラインで繋いでみましょう。接続先として、ASAv を準備し、設定しました。ASAv のインターフェイスは 192.168.10.54 です。

Windows クライアントであれば、コマンドラインでの実行ファイルである vpncli.exe は C:/Program Files (x86)/Cisco/Cisco AnyConnect にあります。ちなみに実行するときの管理者権限は不要です。vpncli.exe だけを実行して対話式に connect 等のコマンドを打つ方法と、vpncli.exe の後に connect 等の引数を入れて実施する方法があります。

前者の例はこんな感じです。vpncli.exe 実施後に connect 192.168.10.54 (VPN 接続先の IP アドレス or FQDN) と実施して VPN 接続を行っています。途中でサーバ証明書の警告が出ていますが、正しく ASAv にサーバ証明書をインストールしていれば、このような警告は出ません。また、今回はユーザ認証を行っていますが、ASA 側で証明書のみの認証にしていれば、完全にインタラプト無しで接続ができるはずです。その他 stats というコマンドで接続状況の確認ができます。disconnect コマンドで VPN を切断します。

C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client>vpncli.exe
Cisco AnyConnect Secure Mobility Client (version 4.9.04053) .

Copyright (c) 2004 - 2020 Cisco Systems, Inc.  All Rights Reserved.


  >> state: Disconnected
  >> state: Disconnected
  >> notice: Ready to connect.
  >> registered with local VPN subsystem.

VPN> connect 192.168.10.54
  >> contacting host (192.168.10.54) for login information...
  >> notice: Contacting 192.168.10.54.
AnyConnect cannot verify server: 192.168.10.54
    - Certificate does not match the server name.
    - Certificate is from an untrusted source.
Connecting to this server may result in a severe security compromise!

Most users do not connect to untrusted servers unless the reason for the error condition is known.

Connect Anyway? [y/n]: y

  >> Please enter your username and password.

Username: [user1] user1
Password:
  >> state: Connecting
  >> notice: Establishing VPN session...
  >> notice: The AnyConnect Downloader is performing update checks...
  >> notice: Checking for profile updates...
  >> notice: Checking for product updates...
  >> notice: Checking for customization updates...
  >> notice: Performing any required updates...
  >> notice: The AnyConnect Downloader updates have been completed.
  >> notice: Establishing VPN - Initiating connection...
  >> state: Connecting
  >> notice: Establishing VPN session...
  >> notice: Establishing VPN - Examining system...
  >> notice: Establishing VPN - Activating VPN adapter...
  >> notice: Establishing VPN - Configuring system...
  >> notice: Establishing VPN...
  >> state: Connected
  >> notice: Connected to 192.168.10.54.
  >> state: Connected
  >> notice: Connected to 192.168.10.54.
VPN>

VPN> stats
VPN>

[ Connection Information ]

    Connection State:            Connected
    Tunnel Mode (IPv4):          Tunnel All Traffic
    Tunnel Mode (IPv6):          Drop All Traffic
    Dynamic Tunnel Exclusion:    None
    Dynamic Tunnel Inclusion:    None
    Duration:                    00:02:27
    Session Disconnect:          None
    Management Connection State: Disconnected (user tunnel active)

[ Address Information ]

    Client Address (IPv4):       192.168.20.211
    Client Address (IPv6):       Not Available
    Server Address:              192.168.10.54

[ Bytes ]

    Bytes Sent:                  32179
    Bytes Received:              35628

[ Frames ]

    Packets Sent:                189
    Packets Received:            9

[ Control Frames ]

    Control Packets Sent:        13
    Control Packets Received:    8

[ Client Management ]

    Administrative Domain:       Undefined
    Profile Name:                Not Available

[ Transport Information ]

    Protocol:                    DTLSv1.2
    Cipher:                      ECDHE_ECDSA_AES256_GCM_SHA384
    Compression:                 None
    Proxy Address:               Not Available
    FIPS Mode:                   Disabled

[ Feature Configuration ]

    FIPS Mode:                   Disabled
    Trusted Network Detection:   Disabled
    Always On:                   Disabled

[ Secure Mobility Solution ]

    Network Status:              Network Access: Restricted
    Appliance:                   Not Available
    SMS Status:                  Unconfirmed

[ Secured Routes (IPv4) ]

    Network                                Subnet             Host(s)
    0.0.0.0                                0

[ Secured Routes (IPv6) ]

    Network                                Subnet             Host(s)

VPN>

VPN> disconnect
  >> state: Disconnecting
  >> notice: Disconnect in progress, please wait...
  >> state: Disconnecting
  >> notice: Disconnect in progress, please wait...
  >> state: Disconnecting
  >> state: Disconnected
  >> state: Disconnected
  >> notice: Ready to connect.
  >> notice: Ready to connect.
VPN>

VPN> exit
goodbye...

ASA 側でも正しく AnyConnect が接続されていることが確認できます。

asav-tatskoba-1# show vpn-sessiondb anyconnect 

Session Type: AnyConnect

Username     : user1                  Index        : 105
Assigned IP  : 192.168.20.211         Public IP    : 192.168.10.110
Protocol     : AnyConnect-Parent SSL-Tunnel DTLS-Tunnel
License      : AnyConnect Premium
Encryption   : AnyConnect-Parent: (1)none  SSL-Tunnel: (1)AES-GCM-256  DTLS-Tunnel: (1)AES-GCM-256
Hashing      : AnyConnect-Parent: (1)none  SSL-Tunnel: (1)SHA384  DTLS-Tunnel: (1)SHA384
Bytes Tx     : 16262                  Bytes Rx     : 31368
Group Policy : DfltGrpPolicy          Tunnel Group : DefaultWEBVPNGroup
Login Time   : 16:22:33 JST Thu Dec 17 2020
Duration     : 0h:02m:09s
Inactivity   : 0h:00m:00s
VLAN Mapping : N/A                    VLAN         : none
Audt Sess ID : c0a81436000690005fdb0739
Security Grp : none                   

後者の例はこんな感じで、stats を見たり disconnect する場合に、都度、vpncli.exe に引数を渡して実施するようになります。

C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client>vpncli.exe connect 192.168.10.54
Cisco AnyConnect Secure Mobility Client (version 4.9.04053) .

Copyright (c) 2004 - 2020 Cisco Systems, Inc.  All Rights Reserved.


  >> state: Disconnected
  >> state: Disconnected
  >> notice: Ready to connect.
  >> registered with local VPN subsystem.
  >> contacting host (192.168.10.54) for login information...
  >> notice: Contacting 192.168.10.54.
AnyConnect cannot verify server: 192.168.10.54
    - Certificate does not match the server name.
    - Certificate is from an untrusted source.
Connecting to this server may result in a severe security compromise!

Most users do not connect to untrusted servers unless the reason for the error condition is known.

Connect Anyway? [y/n]: y

  >> Please enter your username and password.

Username: [user1] user1
Password:
  >> state: Connecting
  >> notice: Establishing VPN session...
  >> notice: The AnyConnect Downloader is performing update checks...
  >> notice: Checking for profile updates...
  >> notice: Checking for product updates...
  >> notice: Checking for customization updates...
  >> notice: Performing any required updates...
  >> notice: The AnyConnect Downloader updates have been completed.
  >> notice: Establishing VPN - Initiating connection...
  >> state: Connecting
  >> notice: Establishing VPN session...
  >> notice: Establishing VPN - Examining system...
  >> notice: Establishing VPN - Activating VPN adapter...
  >> notice: Establishing VPN - Configuring system...
  >> notice: Establishing VPN...
  >> state: Connected
  >> notice: Connected to 192.168.10.54.
VPN>


C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client>vpncli.exe stats
Cisco AnyConnect Secure Mobility Client (version 4.9.04053) .

Copyright (c) 2004 - 2020 Cisco Systems, Inc.  All Rights Reserved.


  >> state: Connected
  >> state: Connected
  >> state: Connected
  >> notice: Connected to 192.168.10.54.
  >> registered with local VPN subsystem.
VPN>

[ Connection Information ]

    Connection State:            Connected
    Tunnel Mode (IPv4):          Tunnel All Traffic
    Tunnel Mode (IPv6):          Drop All Traffic
    Dynamic Tunnel Exclusion:    None
    Dynamic Tunnel Inclusion:    None
    Duration:                    00:00:30
    Session Disconnect:          None
    Management Connection State: Disconnected (user tunnel active)

[ Address Information ]

    Client Address (IPv4):       192.168.20.211
    Client Address (IPv6):       Not Available
    Server Address:              192.168.10.54

[ Bytes ]

    Bytes Sent:                  17845
    Bytes Received:              35568

[ Frames ]

    Packets Sent:                105
    Packets Received:            8

[ Control Frames ]

    Control Packets Sent:        2
    Control Packets Received:    1

[ Client Management ]

    Administrative Domain:       Undefined
    Profile Name:                Not Available

[ Transport Information ]

    Protocol:                    DTLSv1.2
    Cipher:                      ECDHE_ECDSA_AES256_GCM_SHA384
    Compression:                 None
    Proxy Address:               Not Available
    FIPS Mode:                   Disabled

[ Feature Configuration ]

    FIPS Mode:                   Disabled
    Trusted Network Detection:   Disabled
    Always On:                   Disabled

[ Secure Mobility Solution ]

    Network Status:              Network Access: Restricted
    Appliance:                   Not Available
    SMS Status:                  Unconfirmed

[ Secured Routes (IPv4) ]

    Network                                Subnet             Host(s)
    0.0.0.0                                0

[ Secured Routes (IPv6) ]

    Network                                Subnet             Host(s)

VPN>


C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client>vpncli.exe disconnect
Cisco AnyConnect Secure Mobility Client (version 4.9.04053) .

Copyright (c) 2004 - 2020 Cisco Systems, Inc.  All Rights Reserved.


  >> state: Connected
  >> state: Connected
  >> state: Connected
  >> notice: Connected to 192.168.10.54.
  >> registered with local VPN subsystem.
  >> state: Disconnecting
  >> notice: Disconnect in progress, please wait...
  >> state: Disconnecting
  >> notice: Disconnect in progress, please wait...
  >> state: Disconnecting
  >> state: Disconnected



C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client>

AnyConnect のインストールオプションいろいろ

AnyConnect をコマンドラインでインストールする際に、様々なオプションを使うことができます。
例えば、/passive を入れることで、セットアップウィザードが起動せず、勝手にインストール完了までを実施することが可能です。

C:\tmp\AnyConnect>msiexec /package anyconnect-win-4.9.04053-core-vpn-predeploy-k9.msi /passive

image.png

image.png

image.png

他にも以下のようなオプションが使えます。

・PRE_DEPLOY_DISABLE_VPN=1 --> VPN 機能が不要でコアモジュールだけ入れば良い場合に使うオプション
・LOCKDOWN=1 --> GUI でのサービス停止を禁止する (LOCKDOWN) 場合に使うオプション
・ARPSYSTEMCOMPONENT=1 --> アプリの一覧の GUI に表示させたくない場合に使うオプション

例えば、以下のように実施することで、AnyConnect のサイレントインストールを、VPN コア機能をアプリの一覧の GUI に表示させず、かつ、サービス停止も不可にするようにして実施することができます。

C:\tmp\AnyConnect>msiexec /package anyconnect-win-4.9.04053-core-vpn-predeploy-k9.msi /passive LOCKDOWN=1 ARPSYSTEMCOMPONENT=1

image.png

image.png

もちろん、この状態でも VPN 接続が可能です。

C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client>vpncli.exe connect 192.168.10.54
Cisco AnyConnect Secure Mobility Client (version 4.9.04053) .

Copyright (c) 2004 - 2020 Cisco Systems, Inc.  All Rights Reserved.


  >> state: Disconnected
  >> state: Disconnected

  >> Network error. Unable to lookup host names.
  >> Limited Access - DNS Failure
  >> registered with local VPN subsystem.
  >> contacting host (192.168.10.54) for login information...
  >> notice: Contacting 192.168.10.54.
AnyConnect cannot verify server: 192.168.10.54
    - Certificate does not match the server name.
    - Certificate is from an untrusted source.
Connecting to this server may result in a severe security compromise!

Most users do not connect to untrusted servers unless the reason for the error condition is known.

Connect Anyway? [y/n]:
(以下略)

まとめ

AnyConnect は、非常に多くの環境で使われているが故に、様々なエンドユーザが利用することになり、スキルが高くない方が利用する PC にも導入が必要な場合がありますが、このコマンドラインでのインストールや VPN 接続を使うことで、IT 管理者がバッチ処理にて AnyConnect をインストールしたり VPN 接続サービスを提供することが可能です。

意外と知られていない機能なので、簡単にまとめてみました。
「知ってるよ!」という方もおられるかと思いますが、知らなかったという方に向けて、少しでも何かの役に立てば幸いです。

参考サイト

Cisco AnyConnect Secure Mobility Client Administrator Guide, Release 4.9
Chapter: Customize and Localize the AnyConnect Client and Installer
https://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect49/administration/guide/b_AnyConnect_Administrator_Guide_4-9/customize-localize-anyconnect.html

32
5
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
32
5