0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Tenable.io_SDK_for_Pythonでスキャン結果を自動エクスポートする

Posted at

Tenable.io_SDK_for_Pythonでスキャン結果を自動エクスポートする

1.環境
OS:Windows10
Python3.8.xx(Pythonのパスは通しておく)

2.前準備
Tenalbe.ioでアカウントの作成
Tenalbe.ioでスキャン作成、検査対象のスキャンが完了している

3.手順
3.1.APIキーの取得
Tenalbe.ioでAPIを叩くにはAPIキーで認証を通過する必要があります。
アカウントの設定画面のAPIの項目でGenerateボタンを押して
Access KeyとSecret Keyを表示させて
内容をメモして下さい。

3.2.Tenale.io SDK for Pythonのインストール
コマンドプロンプトにて以下を実行

pip install tenable_io

3.3.作業用ディレクトリの作成

mkdir tio
cd tio

3.4.自動エクスポート用スクリプト作成
{スキャン名1}
{スキャン名2}
{スキャン名3}
{スキャン名4}
{アクセスキー}
{シークレットキー}
{プロキシサーバURL}
は環境に合わせて文字列を置き換えて下さい。

scan_list.txt
{スキャン名1}
{スキャン名2}
{スキャン名3}
{スキャン名4}

プロキシを通さない場合のスクリプト

scan_result_export_non_proxy.py
from tenable_io.client import TenableIOClient
from tenable_io.api.scans import ScanExportRequest
import re

with open('scan_list.txt', 'r') as f:
    kw_list = f.read().split("\n")

client = TenableIOClient(access_key='{アクセスキー}', secret_key='{シークレットキー}')
scans = {scan.name: scan.id for scan in client.scans_api.list().scans}

for kw_name in kw_list:

  scan = client.scan_helper.id(scans[fr'{kw_name}'])

  filename = re.sub(r'\\|\.|\s', '_', fr'{kw_name}')+'.html'
  print(filename)

  scan.download(fr'{filename}', format='html',chapter='vuln_by_plugin')

プロキシを通す場合のスクリプト

scan_result_export_proxy.py
from tenable_io.client import TenableIOClient
from tenable_io.api.scans import ScanExportRequest
import re
import os.path


os.environ['https_proxy'] = 'http://{プロキシサーバURL}/'

with open('scan_list.txt', 'r') as f:
    kw_list = f.read().split("\n")

client = TenableIOClient(access_key='{アクセスキー}', secret_key='[シークレットキー}')
scans = {scan.name: scan.id for scan in client.scans_api.list().scans}

for kw_name in kw_list:

  scan = client.scan_helper.id(scans[fr'{kw_name}'])

  filename = re.sub(r'\\|\.|\s|\/', '_', fr'{kw_name}')+'.html'
  print(filename)

  scan.download(fr'{filename}', format='html',chapter='vuln_by_plugin')

3.5.スクリプトの実行
プロキシが無い環境では、
scan_result_export_non_proxy.py
プロキシがある環境では、
scan_result_export_proxy.py
を実行して下さい。

scan_result_export_proxy.pyでSSL証明書のエラーが出た場合は、
環境で使用するCA証明書をPythonプログラムのディレクトリにある
certificate.pem
に追記して下さい。

4.まとめ
4時間近く掛かっていたスキャン結果のエクスポートが自動で出来るようになり、
かなり楽になりました。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?