メインコンテンツへスキップ
見出し画像

SoftEtherVPN Serverをソースからリージョンロックを解除し、ワンタイムパスワード対応とした時のメモ

    すでに、バイナリ形式のSoftEtherVPNサーバーが動作しているものとして、
    バイナリ形式にない、RADIUSサーバーへの接続をできるようにするものです。

    ■SoftEtherダウンロードセンターから所定のLinux64bit版のソースをダウンロードして、/usr/local/srcに置きます。今回は、

    softether-src-v4.42-9798-rtm.tar.gz

    というファイルになります。

    cd /usr/local/src/
    tar xzvf softether-src-v4.42-9798-rtm.tar.gz
    vi v4.42-9798/src/Cedar/Server.c
    ------------------------------------------------------------------
    10900 bool SiIsEnterpriseFunctionsRestrictedOnOpenSource(CEDAR *c)
    10901 {
    10902 /*
    10903         char region[128];
    10904         bool ret = false;
    10905         // Validate arguments
    10906         if (c == NULL)
    10907         {
    10908                 return false;
    10909         }
    10910
    10911
    10912         SiGetCurrentRegion(c, region, sizeof(region));
    10913
    10914         if (StrCmpi(region, "JP") == 0 || StrCmpi(region, "CN") == 0)
    10915         {
    10916                 ret = true;
    10917         }
    10918
    10919         return ret;
    10920 */
    10921         return false;
    10922 }
    ------------------------------------------------------------------
    保存し、viを終了

    10902行から10920行をコメントアウトして、return falese;とする。

    cd v4.42-9798/
    ./configure
    make
    
    #バイナリ形式のファイルを一旦、退避
    mv /usr/local/vpnserver/vpnserver /usr/local/vpnserver/vpnserver_binary
    mv /usr/local/vpnserver/vpncmd /usr/local/vpnserver/vpncmd_binary
    mv /usr/local/vpnserver/hamcore.se2 /usr/local/vpnserver/hamcore.se2_binary
    
    #makeしたファイルを所定のフォルダへコピー
    cp -p /usr/local/src/v4.42-9798/bin/vpncmd/vpncmd /usr/local/vpnserver/
    cp -p /usr/local/src/v4.42-9798/bin/vpnserver/* /usr/local/vpnserver/
    
    #権限の再設定
    chmod 600 /usr/local/vpnserver/*
    chmod 700 /usr/local/vpnserver/vpncmd
    chmod 700 /usr/local/vpnserver/vpnserver
    
    #プロセスを再起動
    systemctl restart vpnserver
    
    #確認
    /usr/local/vpnserver/vpncmd /TOOLS /CMD check
    

    一部、不合格の表示になりました。しかし、動作には、影響がないようにみえます。

    ■RADIUSサーバーの構築
    SoftEtherVPNサーバーと同居するものとして、ワンタイムパスワードは、スマホアプリのgoogle-authenticatorを使う。としています。

    dnf install freeradius freeradius-utils pam-devel -y
    
    vi /etc/raddb/radiusd.conf
    ------------------------------------------------------------------
    337行付近
    #auth = no
    auth = yes
    
    362行付近
    #auth_badpass = no
    #auth_goodpass = no
    auth_badpass = yes
    auth_goodpass = yes
    
    505行付近
    #user = freerad
    #group = freerad
    user = root
    group = root
    ------------------------------------------------------------------
    
    vi /etc/raddb/proxy.conf 
    ------------------------------------------------------------------
    修正なしで、確認のみ
    ipaddr = 127.0.0.1
    port = 1812
    secret = testing123    #SoftEtherVPNサーバーで設定するシークレットの文字列
    ------------------------------------------------------------------
    
    vi /etc/raddb/users
    ------------------------------------------------------------------
    67行あたりに挿入
    DEFAULT    Group != "radius-enabled", Auth-Type := Reject
           Reply-Message = "Your account has been disabled."
    DEFAULT        Auth-Type := PAM
    ------------------------------------------------------------------
    
    vi /etc/raddb/sites-available/default
    ------------------------------------------------------------------
    520行付近 #をはずす
    #	pam
    	pam
    ------------------------------------------------------------------
    
    vi /etc/pam.d/radiusd
    ------------------------------------------------------------------
    # auth       include    password-auth
    # account    required   pam_nologin.so
    # account    include    password-auth
    # password   include    password-auth
    # session    include    password-auth
    auth    requisite /usr/lib64/security/pam_google_authenticator.so
    account required  pam_permit.so
    session required  pam_permit.so
    ------------------------------------------------------------------
    
    vi /etc/raddb/clients.conf
    ------------------------------------------------------------------
    末尾に追記
    client 192.168.0.0/16 {                 # VPC の CIDR
            secret          = testing123    # SoftEtherで設定していた共有シークレット
            shortname       = from-vpc      # ログに出てくるだけ?
    }
    ------------------------------------------------------------------
    
    #pamを有効にする
    ln -s /etc/raddb/mods-available/pam /etc/raddb/mods-enabled/
    
    systemctl restart radiusd
    systemctl enable radiusd
    
    #radiusdの起動をデバッグする場合は、次を実行する。
    /usr/sbin/radiusd -C -lstdout -xxx
    

    ■google-authenticatorに読み込ますQRコードの準備

    dnf install epel-release -y
    dnf install google-authenticator -y
    
    #ユーザー名をuser001として、
    groupadd radius-enabled
    useradd -g radius-enabled user001
    
    sudo -u user001 /usr/bin/google-authenticator
    ------------------------------------------------------------------
    Do you want authentication tokens to be time-based (y/n) y
    
    Warning: pasting the following URL into your browser exposes the OTP secret to Google:
      https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=ot~ 
    
    上記、URLは、QRコードが表示されます。そのQRコードをスマホアプリの Google authenticator で読み込み、
    ワンタイムパスワードを表示します。
    
    Failed to use libqrencode to show QR code visually for scanning.
    Consider typing the OTP secret into your app manually.
    Your new secret key is: E3CLHOIFLOKEG2ZVHKMZ5G6BCE
    
    Enter code from app (-1 to skip): 184--- #ここに表示されたワンタイムパスワードをいれます。
    Code confirmed
    Your emergency scratch codes are:
      28482981
      12908965
      39563570
      64432661
      98739621
    
    Do you want me to update your "/home/user001/.google_authenticator" file? (y/n) y
    
    Do you want to disallow multiple uses of the same authentication
    token? This restricts you to one login about every 30s, but it increases
    your chances to notice or even prevent man-in-the-middle attacks (y/n) y
    
    By default, a new token is generated every 30 seconds by the mobile app.
    In order to compensate for possible time-skew between the client and the server,
    we allow an extra token before and after the current time. This allows for a
    time skew of up to 30 seconds between authentication server and client. If you
    experience problems with poor time synchronization, you can increase the window
    from its default size of 3 permitted codes (one previous code, the current
    code, the next code) to 17 permitted codes (the 8 previous codes, the current
    code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
    between client and server.
    Do you want to do so? (y/n) y
    
    If the computer that you are logging into isn't hardened against brute-force
    login attempts, you can enable rate-limiting for the authentication module.
    By default, this limits attackers to no more than 3 login attempts every 30s.
    Do you want to enable rate-limiting? (y/n) y
    ------------------------------------------------------------------
    

    ■SoftEtherVPNサーバーの設定

    画像

    共有シークレットは、Defaultでは、testing123 となります。

    SoftEtherVPNクライアントから、ユーザー名とスマホアプリのgoogle-authenticatorに表示されるパスワードを入力して、サーバーに接続します。

    あなたへのおすすめ