このエントリーはSophos UTMでのRESTの概要と、REST APIを使ってSophos UTMから情報を取得するところまで。
API概要
参考URL:Sophos UTM RESTful API
ラボ環境を作る
AWSでSophos UTMを立ち上げる。
-
- FWを立ち上げる
- sshでFWにアクセス
- RESTでアクセスできるように設定。
最初、キーが手元になかったので、WebGUIでSSH鍵認証を無効(パスワード認証)にしましたが、今回起動したUTM(version 9.506)ではパスワード認証は”Access Denied”となってしまいうまくいきませんでした。SophosUTMではSSHパスワード認証に難があるようで、フォーラムを見てもバージョンごとに修復、再発を繰り返しているようです。
$ssh -i aws_eu-ce1.pem loginuser@******* Using username "loginuser". Sophos UTM (C) Copyright 2000-2017 Sophos Limited and others. All rights reserved. Sophos is a registered trademark of Sophos Limited and Sophos Group. All other product and company names mentioned are trademarks or registered trademarks of their respective owners. For more copyright information look at /doc/astaro-license.txt or http://www.astaro.com/doc/astaro-license.txt NOTE: If not explicitly approved by Sophos support, any modifications done by root will void your support. loginuser@sophons9_eu-central-1:/home/login > su - Password: sophons9_eu-central-1:/root # sophons9_eu-central-1:/root # cc set webadmin rest_api 1 1 sophons9_eu-central-1:/root #
APIを使ってみる
APIの構成は、”https://<FWのIPアドレス>:<ポート番号(デフォルトは4444)>/api/definitions”からたどることが出来る。下の例ではethernetのインタフェース情報は”/objects/interface/ethernet/”で取得できることがわかる
Sophos UTMのAPI認証は、ユーザー名とパスワードをリクエストと一緒に送る(BASIC認証)と、事前にTOKENを発行しておく二種類の方法がある。今回はBASIC認証を使う。
import requests from pprint import pprint def main(): source = "https://******.eu-central-1.compute.amazonaws.com:4444/api" path = "/objects/interface/ethernet/" url = source + path headers = {"content-Type":"application/json", "Accept":"application/json", } r = requests.get(url, headers=headers, verify=False, auth=('api-user', '******')) return r.json() if __name__ == '__main__': pprint(main())
これを実行するとこんな感じで情報が返ってくる
ec2-user:~/environment/sophos_api $ python3 get-interface.py [{'_locked': '', '_ref': 'REF_DefaultInternal', '_type': 'interface/ethernet', 'additional_addresses': [], 'bandwidth': 100000000, 'comment': 'Auto-created on installation', 'inbandwidth': 0, 'itfhw': 'REF_ItfHwDefaultInternal', 'link': True, 'mtu': 9001, 'mtu_auto_discovery': True, 'name': 'Internal', 'outbandwidth': 0, 'primary_address': 'REF_ItfParamsDefaultInternal', 'proxyarp': False, 'proxyndp': False, 'status': True}] ec2-user:~/environment/sophos_api $