Yuri Slobodyanyuk Blog on Information Security 2024年07月23日
Checkpoint API tutorial, part 1 - getting started
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本教程介绍如何使用Postman软件远程访问Checkpoint Management Server上的API,验证API是否已启用,以及如何通过HTTP请求创建第一个网络对象-主机。该教程不需要任何编码技能,并逐步介绍了启用API远程访问,验证API状态,创建登录会话,获取身份验证令牌以及创建和发布主机对象等步骤。

**✅ 启用API远程访问并验证** Checkpoint API默认情况下已安装并启用,但需要确保服务器有足够的内存。为了允许远程访问,需要在SmartConsole中配置管理API的访问设置。可以通过设置“所有IP地址”或“所有可用于GUI客户端的IP地址”来允许所有IP地址或特定IP地址访问API。然后,需要重启API服务,并使用`api status`命令验证API设置是否生效。

**✅ 创建身份验证会话,记录会话标识符** 在与API通信之前,需要先进行身份验证。身份验证过程会验证用户权限并授权访问相应的资源。使用Postman发送POST请求到`/web_api/login`资源,并提供管理员用户名和密码。API服务会返回一个JSON格式的响应,包含身份验证令牌(sid),该令牌需要保存用于后续请求。

**✅ 创建主机对象并发布结果** 使用Postman发送POST请求到`/web_api/add-host`资源,并提供身份验证令牌(sid)、主机名称和IP地址来创建主机对象。创建完成后,需要发送POST请求到`/web_api/publish`资源,并提供身份验证令牌(sid)来发布主机对象。

**✅ 验证API请求结果** 在使用API时,需要检查HTTP响应代码,200 OK表示成功,其他代码表示失败。此外,还需要查看响应正文以了解错误原因。例如,如果试图访问不存在的对象属性或发送错误的请求格式,API会返回相应的错误信息。

**✅ 总结** 本教程介绍了使用Postman远程访问Checkpoint Management Server上的API,并创建了第一个网络对象-主机。通过逐步介绍API访问、身份验证、对象创建和发布等步骤,为读者提供了使用Checkpoint API的基础知识。在后续教程中,将介绍如何修改和安装安全策略等更高级的功能。

In this, 1st part of tutorial series, I will show how to enable remote access to API on Checkpoint Management Server, verify that it is running and is indeed enabled for remote access, and create first Network object - Host via HTTP request. All this I will do in Postman software, so no coding skills are required.

Introduction

Before diving in it is worth knowing those things about Checkpoint API:

    API is a Management Server only feature. There is no API on the firewall gateway so far, but I heard Checkpoint are working on it as well.

    API in Checkpoint can be accessed in 4 ways: Web/HTTP REST API, SmartConsole applet CLI, mgmt_cli CLI tool (available on both - Management and local PC), and GAIA clish.

    Web API service listens on the same port configured for the GAIA management portal access.

    Access to Web API is via https only (naturally).

    API first appeared in Checkpoint R80.

    API is versioned as 1.x for the current R8x train. API versions will update with major version releases (e.g. R80.20 to R80.30), as well as optionally with Jumbo Hotfixes.

    API is part of the Management server: you don’t need to install/update or manage it in any way. Once the Management is installed, the API is inside.

    All previous API versions are available on every Management version. E.g. the current/latest API version on R80.40 is v1.6, but you can also use API v1.5, v1.4 etc on it. You just append to your API commands the version explicitly. This ensures that scripts/dashboards developed for one API version will work in the future.

    API versions are mostly compatible. After the major change (81 additions) from R80 to R80.10, most of the changes are either addition of new API functions, or addition of new properties to existing ones. So, while there is no guarantee, it is not necessary to cling to a specific version fearing the code will break.

    All Web API requests will start with the path web_api. This way Checkpoint can differentiate HTTP requests to Web API versus requests to GAIA portal.

Now, let’s configure something.

Enable API remote access and verify

API is installed and enabled by default, except for the corner case of low memory - "By default, the API server is active on management servers with 4GB of RAM (or more) and on stand-alone servers with 8GB of RAM (or more)".

So, provided your server has enough of RAM, next step is to allow remote access to the API, otherwise only local to Management server access is possible.

To do so, in the SmartConsole, go to Manage and Settings → Blades → Management API → Advanced Settings and check either All IP addresses (this removes IP restrictions on the API server level, firewall secuity rules still work as expected if there any [and they should be]) or All IP addresses that can be used for GUI clients (this references GUI clients setting for the SmartConsole access).

Next, click on Publish and Install. Then restart the API service on the Management server on CLI in Expert mode, no other services are affected, so no downtime: api restart.

You should see the output like that:

[Expert@CP80-40:0]# api restart2021-Apr-21 12:35:36 - Stopping API...2021-Apr-21 12:35:39 - API stopped successfully.2021-Apr-21 12:35:39 - Starting API.... . . . . . . . . . . . .2021-Apr-21 12:36:51 - API started successfully.

Here comes the first verificaiton task - make sure the change actually took effect. It happens that you need to ask the Management twice to do this - I had to do Policy Install twice after changing the access. Or you’ll have to restart the API service twice, happens.

The following will show the settings that are in effect:

api status

[Expert@CP80-40:0]# api statusPI Settings:---------------------Accessibility:                      Require ip 127.0.0.1 (1)Automatic Start:                    Enabled (2)Processes:Name      State     PID       More Information-------------------------------------------------API       Started   32042CPM       Started   10098     Check Point Security Management Server is running and ready (3)

    This means the API is ready to accept requests only sourced from the Management server itself, the default state, not good.

    Unless someone messed with the Managent it should be Enabled

    Self-explanatory

After setting, in this case, in SmartConsole to allow from IPs allowed the GUI access, the output will look:

Expert@CP80-40:0]# api statusAPI Settings:---------------------Accessibility:                      Require all granted (1)Automatic Start:                    EnabledProcesses:Name      State     PID       More Information-------------------------------------------------API       Started   911CPM       Started   10098     Check Point Security Management Server is running and ready

    The state changed to what we desire, good.

Create authenticated session, record session identifier

Before we can talk to API, we have to authenticate ourselves to the Management server. This process will also authorize our session to do/query only things our user is allowed via administrator profile assigned on the Management server.

To do so, we start every new API session with login request.

Note
As this is a tutorial on Web API, I will not include mgmt_cli, clish and SmartConsole CLI applet in our discussion, but just be aware the process is the same - 1st you log in, then you work with the API.

On successful login request, the API service will answer with JSON formatted data in the body.

In this tutorial I will use admin user with full privileges, something you may stay away in production firewall. I will, at a later time, show how to apply admin profiles to the user or alternatively use api-key instead of username/password.

sid is one of the parameters returned by login POST request (we talk with API in HTTP/1.1) and it contains the one-time authentication token we need to save for further requests in this session.

Ok, now, that we know enough to be dangerous, let’s make a login POST request.

Create a login session

If you don’t know, Postman is the (free) software with GUI for testing API. Even if in production you work in code (Python/Golang/etc.), I highly recommend getting to know this tool, as it allows to understand what is going on with any API and without resorting to print on every other line of code.

I assume you already downloaded the Postman and have it open.

We need to set the following parameters for our POST request session:

    IP address and port of the Management server: whom we are going to query.

    username/password of administrator: by administrator I mean any user that can login into SmartConsole/GAIA. We set it inside the request body in JSON format. In the JSON format it will look as (I am using qwe123 for the password just because it is a lab, don’t do it in production):

{    "user" : "admin",    "password" : "qwe123"}

    Content-type: applicaiton/json header. Hint to Postman, otherwise it will try to guess appropriate type of the content and may do it wrong.

    path to login resource: We request web_api/login resource on the API server.

The screenshot of the above settings:

As you can see, we got in reply sid with the authentication token. Now we can copy its value and move to the next step - creating a Host object.

Create a Host object and publish the result

First, we need to know what API function creates a Host object. This can be looked up at Checkpoint API documentation .From there we learn that the required parameters are x-chkp-sid header, name, and ip-address and we should request /web_api/add-host.

x-chkp-sid will contain the sid token and the rest is obvious. So, let’s create a host object named Dummy\_33 with the IP address of 33.33.33.33.

Again, with these parameters I construct a new request. The bottom picture is of the answer to the request:

As seen above, the object was successfully (response code 200) created. The final step is to publish the result, so all Checkpoint admins will be able to use this object. We need to send POST request for the resource /web_api/publish using the same token from sid and Content-type: applicaiton/json header. I’ll live it as an exercise.

Verification

Few points about verification:

    In Web API, always check the HTTP response code: anything but 200 OK means something went wrong.

    Additionally, look in the body of the response for clues on what wasn’t right.

Here are 2 examples of something going wrong.

Case 1: Trying to reference a property of the object that doesn’t exist

I tried to set property tags while there is no such one, the tag is the correct property:

As you can see, the response message tells me exactly what was wrong.

Case 2: Sending POST request as a form instead of the JSON in the body:

Checkpoint gives exact reason in the message as well. This is in addition to response error code of 400 bad Request.

That’s all for this part in which I showed how to create login session, obtain authentication token, create host object, and publish the result. In the next part I will talk about changing and installing the Security Policy.

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Checkpoint API Postman 网络安全 远程访问 主机对象
相关文章