检查点 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))

此外,在帮助下 网络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 名用户弃权。

来源: habr.com

添加评论