檢查點 R80.10 API。 透過 CLI、腳本等進行管理

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

我相信每一個曾經合作過的人 檢查點,有人投訴 無法從命令列編輯配置。 對於以前使用過 Cisco ASA 的人來說,這尤其奇怪,因為在 Cisco ASA 中,一切都可以在 CLI 中設定。 對於 Check Point,情況正好相反 - 所有安全設定都完全從圖形介面執行。 然而,有些事情透過 GUI 來完成是完全不方便的(即使像 Check Point 那樣方便)。 例如,新增 100 個新主機或網路的任務會變成一個漫長而乏味的過程。 對於每個對象,您必須按一下滑鼠幾次並輸入 IP 位址。 建立一組網站或批次啟用/停用 IPS 簽章也是如此。 在這種情況下,出錯的可能性就很高。

最近發生了一個「奇蹟」。 隨著新版本的發布 蓋亞R80 機會已被宣布 API使用,這為自動化設定、管理、監控等開闢了廣泛的機會。 現在你可以:

  • 創建物件;
  • 新增或編輯存取清單;
  • 啟用/停用刀片;
  • 配置網路介面;
  • 設定政策;
  • 等等。

說實話,我不明白哈布爾是怎麼傳出這個消息的。 在本文中,我們將簡要描述如何使用 API 並提供幾個實際範例。 使用腳本進行 CheckPoint 設定.

我想立即預訂該 API 僅用於管理伺服器。 那些。 如果沒有管理伺服器,仍然無法管理網關。

原則上誰可以使用這個API?

  1. 希望簡化或自動化日常 Check Point 設定任務的系統管理員;
  2. 想要將 Check Point 與其他解決方案(虛擬化系統、票證系統、配置管理系統等)整合的公司;
  3. 想要標準化設定或建立其他 Check Point 相關產品的系統整合商。

典型方案

那麼,讓我們想像一下 Check Point 的典型方案:

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

像往常一樣,我們有一個網關(SG)、管理伺服器(短信)和管理控制台(智能控制台)。 在這種情況下,通常的網關設定流程如下所示:

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

那些。 首先需要在管理員電腦上執行 智能控制台,我們用它連接到管理伺服器(短信)。 安全性設定是在 SMS 上進行的,然後才套用(安裝策略)到網關(SG).

當使用 管理接口,我們基本上可以跳過第一點(啟動SmartConsole)並使用 API指令 直接傳送至管理伺服器 (SMS)。

API使用方法

使用 API 編輯配置的主要方法有四種:

1) 使用 mgmt_cli 實用程式

例子 - # mgmt_cli 新增主機名稱 host1 ip 位址 192.168.2.100
此命令從管理伺服器 (SMS) 命令列執行。 我認為該命令的語法很清楚 - host1 是使用位址 192.168.2.100 建立的。

2)透過clish輸入API指令(專家模式)

基本上,您需要做的就是登入命令列(管理登入)位於透過 SmartConsole 連線時所使用的帳戶(或 root 帳戶)下。 然後你可以輸入 API指令 (在這種情況下,無需在每個命令之前使用該實用程序 管理工具)。 您可以創建成熟的 BASH 腳本。 主機建立的腳本範例:

腳本

#!/bin/bash

main() {
    clear

    #LOGIN (don't ask for username and password, user is already logged in to Management server as 'root' user)
    mgmt_cli login --root true > id_add_host.txt
    on_error_print_and_exit "Error: Failed to login, check that the server is up and running (run 'api status')"

    #READ HOST NAME
    printf "Enter host name:n"
    read -e host_name
    on_empty_input_print_and_exit "$host_name" "Error: The host's name cannot be empty."

    #READ IP ADDRESS
    printf "nEnter host IP address:n"
    read -e ip
    on_empty_input_print_and_exit "$ip" "Error: The host's IP address cannot be empty."

    #CREATE HOST
    printf "Creating new host: $host_name with IP address: $ipn"
    new_host_response=$(mgmt_cli add host name $host_name ip-address $ip -s id_add_host.txt 2> /dev/null)
    on_error_print_and_exit "Error: Failed to create host object. n$new_host_response"

    #PUBLISH THE CHANGES
    printf "nPublishing the changesn"
    mgmt_cli publish --root true -s id_add_host.txt &> /dev/null
    on_error_print_and_exit "Error: Failed to publish the changes."

    #LOGOUT
    logout
	
	printf "Done.n"
}

logout(){
	mgmt_cli logout --root true -s id_add_host.txt &> /dev/null
}

on_error_print_and_exit(){
    if [ $? -ne 0 ]; then
        handle_error "$1" 
	fi
}

handle_error(){
    printf "n$1n" #print error message
    mgmt_cli discard --root true -s id_add_host.txt &> /dev/null
    logout
    exit 1
}

on_empty_input_print_and_exit(){
	if [ -z "$1" ]; then
		printf "$2n" #print error message
		logout
		exit 0
	fi
}

# Script starts here. Call function "main".
main

如果您有興趣,可以觀看相應的影片:

3) 透過 SmartConsole 開啟 CLI 窗口

您所需要做的就是打開窗戶 CLI的 直接從 智能控制台,如下圖所示。

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

在此視窗中,您可以立即開始輸入 API 命令。

4) 網路服務。 使用 HTTPS Post 請求(REST API)

我們認為,這是最有前景的方法之一,因為允許您基於以下內容“構建”整個應用程式 管理伺服器管理 (抱歉同義反覆)。 下面我們將更詳細地了解這個方法。

總結一下:

  1. API + 命令列介面 比較適合習慣Cisco的人;
  2. API+外殼 用於應用腳本和執行日常任務;
  3. REST API 用於自動化。

啟用API

預設情況下,此 API 在具有超過 4GB RAM 的管理伺服器和具有超過 8GB RAM 的獨立配置上啟用。 您可以使用以下命令檢查狀態: API狀態

如果發現該 api 被停用,那麼可以很容易地透過 SmartConsole 啟用它: 管理與設定 > 刀片 > 管理 API > 進階設置

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

然後發布(發布) 更改並運行命令 介面重啟.

網路請求+Python

若要執行 API 命令,您可以使用 Web 請求 蟒蛇 和圖書館 請求, JSON。 一般來說,Web請求的結構由三個部分組成:

1)地址

(https://<managemenet server>:<port>/web_api/<command>) 


2) HTTP 標頭

content-Type: application/json
x-chkp-sid: <session ID token as returned by the login command>


3) 請求負載

包含不同參數的 JSON 格式的文本

調用各種命令的範例:


def api_call(ip_addr, port, command, json_payload, sid):
    url = 'https://' + ip_addr + ':' + str(port) + '/web_api/' + command
    if sid == “”:
        request_headers = {'Content-Type' : 'application/json'}
    else:
        request_headers = {'Content-Type' : 'application/json', 'X-chkp-sid' : sid}
    r = requests.post(url,data=json.dumps(json_payload), headers=request_headers,verify=False)
    return r.json()                                        
'xxx.xxx.xxx.xxx' -> Ip address GAIA

以下是管理 Check Point 時最常遇到的一些典型任務。

1)授權和登出功能範例:

腳本


    payload = {‘user’: ‘your_user’, ‘password’ : ‘your_password’}
    response = api_call('xxx.xxx.xxx.xxx', 443, 'login',payload, '')
    return response["sid"]

    response = api_call('xxx.xxx.xxx.xxx', 443,'logout', {} ,sid)
    return response["message"]

2) 打開刀片並設定網路:

腳本


new_gateway_data = {'name':'CPGleb','anti-bot':True,'anti-virus' : True,'application-control':True,'ips':True,'url-filtering':True,'interfaces':
                    [{'name':"eth0",'topology':'external','ipv4-address': 'xxx.xxx.xxx.xxx',"ipv4-network-mask": "255.255.255.0"},
                     {'name':"eth1",'topology':'internal','ipv4-address': 'xxx.xxx.xxx.xxx',"ipv4-network-mask": "255.255.255.0"}]}
new_gateway_result = api_call('xxx.xxx.xxx.xxx', 443,'set-simple-gateway', new_gateway_data ,sid)
print(json.dumps(new_gateway_result))

3)更改防火牆規則:

腳本


new_access_data={'name':'Cleanup rule','layer':'Network','action':'Accept'}
new_access_result = api_call('xxx.xxx.xxx.xxx', 443,'set-access-rule', new_access_data ,sid)
print(json.dumps(new_access_result))

4)新增應用層:

腳本


add_access_layer_application={ 'name' : 'application123',"applications-and-url-filtering" : True,"firewall" : False}
add_access_layer_application_result = api_call('xxx.xxx.xxx.xxx', 443,'add-access-layer', add_access_layer_application ,sid)
print(json.dumps(add_access_layer_application_result))

set_package_layer={"name" : "Standard","access":True,"access-layers" : {"add" : [ { "name" : "application123","position" :2}]} ,"installation-targets" : "CPGleb"}
set_package_layer_result = api_call('xxx.xxx.xxx.xxx', 443,'set-package', set_package_layer ,sid)
print(json.dumps(set_package_layer_result))

5)發布並設定策略,檢查命令的執行情況(task-id):

腳本


publish_result = api_call('xxx.xxx.xxx.xxx', 443,"publish", {},sid)
print("publish result: " + json.dumps(publish_result))
new_policy = {'policy-package':'Standard','access':True,'targets':['CPGleb']}
new_policy_result = api_call('xxx.xxx.xxx.xxx', 443,'install-policy', new_policy ,sid)
print(json.dumps(new_policy_result)

task_id=(json.dumps(new_policy_result ["task-id"]))
len_str=len(task_id)
task_id=task_id[1:(len_str-1)]
show_task_id ={'task-id':(task_id)}
show_task=api_call('xxx.xxx.xxx.xxx',443,'show-task',show_task_id,sid)
print(json.dumps(show_task))

6)新增主機:

腳本


new_host_data = {'name':'JohnDoePc', 'ip-address': '192.168.0.10'}
new_host_result = api_call('xxx.xxx.xxx.xxx', 443,'add-host', new_host_data ,sid)
print(json.dumps(new_host_result))

7) 新增威脅防護欄位:

腳本


set_package_layer={'name':'Standard','threat-prevention' :True,'installation-targets':'CPGleb'}
set_package_layer_result = api_call('xxx.xxx.xxx.xxx', 443,'set-package',set_package_layer,sid)
print(json.dumps(set_package_layer_result))

8)查看會話列表

腳本


new_session_data = {'limit':'50', 'offset':'0','details-level' : 'standard'}
new_session_result = api_call('xxx.xxx.xxx.xxx', 443,'show-sessions', new_session_data ,sid)
print(json.dumps(new_session_result))

9)建立一個新的設定檔:

腳本


add_threat_profile={'name':'Apeiron', "active-protections-performance-impact" : "low","active-protections-severity" : "low or above","confidence-level-medium" : "prevent",
  "confidence-level-high" : "prevent", "threat-emulation" : True,"anti-virus" : True,"anti-bot" : True,"ips" : True,
  "ips-settings" : { "newly-updated-protections" : "staging","exclude-protection-with-performance-impact" : True,"exclude-protection-with-performance-impact-mode" : "High or lower"},
  "overrides" : [ {"protection" : "3Com Network Supervisor Directory Traversal","capture-packets" : True,"action" : "Prevent","track" : "Log"},
                  {"protection" : "7-Zip ARJ Archive Handling Buffer Overflow", "capture-packets" : True,"action" : "Prevent","track" : "Log"} ]}
add_threat_profile_result=api_call('xxx.xxx.xxx.xxx',443,'add-threat-profile',add_threat_profile,sid)
print(json.dumps(add_threat_profile_result))  

10) 更改 IPS 簽章的操作:

腳本


set_threat_protection={
  "name" : "3Com Network Supervisor Directory Traversal",
  "overrides" : [{ "profile" : "Apeiron","action" : "Detect","track" : "Log","capture-packets" : True},
    { "profile" : "Apeiron", "action" : "Detect", "track" : "Log", "capture-packets" : False} ]}
set_threat_protection_result=api_call('xxx.xxx.xxx.xxx',443,'set-threat-protection',set_threat_protection,sid)
print(json.dumps(set_threat_protection_result))

11) 新增您的服務:

腳本


add_service_udp={    "name" : "Dota2_udp", "port" : '27000-27030',
"keep-connections-open-after-policy-installation" : False,
"session-timeout" : 0, "match-for-any" : True,
"sync-connections-on-cluster" : True,
"aggressive-aging" : {"enable" : True, "timeout" : 360,"use-default-timeout" : False  },
"accept-replies" : False}
add_service_udp_results=api_call('xxx.xxx.xxx.xxx',443,"add-service-udp",add_service_udp,sid)
print(json.dumps(add_service_udp_results))

12) 新增類別、網站或群組:

腳本


add_application_site_category={  "name" : "Valve","description" : "Valve Games"}
add_application_site_category_results=api_call('xxx.xxx.xxx.xxx',443,"add-application-site-category",add_application_site_category,sid)
print(json.dumps(add_application_site_category_results))

add_application_site={    "name" : "Dota2", "primary-category" : "Valve",  "description" : "Dotka",
  "url-list" : [ "www.dota2.ru" ], "urls-defined-as-regular-expression" : False}
add_application_site_results=api_call('xxx.xxx.xxx.xxx',443,"add-application-site " , 
add_application_site , sid)
print(json.dumps(add_application_site_results))

add_application_site_group={"name" : "Games","members" : [ "Dota2"]}
add_application_site_group_results=api_call('xxx.xxx.xxx.xxx',443,"add-application-site-group",add_application_site_group,sid)
print(json.dumps(add_application_site_group_results))

此外,在幫助下 Web API 您可以新增和刪除網路、主機、存取角色等。 刀片可自訂 防毒、反殭屍、IPS、VPN。 甚至可以使用以下命令安裝許可證 運行腳本。 所有 Check Point API 命令均可在此處找到 這裡.

檢查點 API + 郵差

使用起來也方便 檢查點 Web API 和這個結合 郵差。 Postman 有 Windows、Linux 和 MacOS 的桌面版。 此外,還有一個適用於 Google Chrome 的插件。 這就是我們將要使用的。 首先你需要在Google Chrome商店中找到Postman並安裝:

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

使用此實用程序,我們將能夠產生對 Check Point API 的 Web 請求。 為了不記住所有 API 命令,可以匯入所謂的集合(範本),其中已經包含所有必要的命令:

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

這裡 你會找到 彙集 R80.10。 導入後,API命令模板將可供我們使用:

檢查點 R80.10 API。 透過 CLI、腳本等進行管理

在我看來,這非常方便。 您可以使用 Check Point API 快速開始開發應用程式。

檢查點 + Ansible

我還想指出的是,有 Ansible 用於檢查點 API。 此模組可讓您管理配置,但對於解決奇異問題不太方便。 使用任何程式語言編寫腳本都提供了更靈活、更方便的解決方案。

產量

我們可能會在這裡完成 Check Point API 的簡短回顧。 在我看來,這個功能是非常期待且必要的。 API 的出現為使用 Check Point 產品的系統管理員和系統整合商帶來了非常廣泛的機會。 編排、自動化、SIEM 回饋…現在一切皆有可能。

PS 更多關於 檢查點 一如既往,您可以在我們的部落格上找到它 哈伯 或在部落格上 在線.

PSS 對於與設定 Check Point 相關的技術問題,您可以 這裡

只有註冊用戶才能參與調查。 登入, 請。

您打算使用 API 嗎?

  • 企業排放佔全球 70,6%是12

  • 企業排放佔全球 23,5%4號

  • 企業排放佔全球 5,9%已經在使用1

17 位用戶投票。 3 名用戶棄權。

來源: www.habr.com

添加評論