卡巴斯基安全中心-新级别

在Habr上已经有关于卡巴斯基安全中心(KSC)自动化的一些注意事项


这里这里


今天,我建议更深入地研究并迈入一个新的高度使用:卡巴斯基安全中心10+的KSC Open API。


为了监视状态,将新工作站分配到组中,我不得不使用管理控制台来生成报告,它具有广泛的功能,但是其工作速度仍有很多不足之处。


对Open API的支持看起来像是一口新鲜空气,立即决定使用此解决方案,并且像往常一样,使用Go惯用的编程语言编写了一个,该库允许使用其提供的API访问KSC服务器。


要在我们的项目中使用该包,我们通常需要获取它:


go get -u github.com/pixfid/go-ksc/kaspersky


将包导入到创建的项目中。


import (
    "github.com/pixfid/go-ksc/kaspersky"
)

我们创建一个新客户端以使用KSC服务器


func main() {
    ctx := context.Background()
        cfg := kaspersky.Config { //    
              Username: "login",
              Password: "password",
              Server: fmt.Sprintf(`https://%s:%s`, "ip", "port"),
        }

    client := kaspersky.New(cfg) //  
    client.KSCAuth(ctx) //
}

授权很简单,POST是一个端点请求/api/v1.0/login,具有设置请求标头:


AuthorizationKSCBasic user=base64(login),pass=base64(pass)
X-KSC-VServerx
Content-Length2


如果成功,服务器将返回: {}


, , accessor , requestId .


:


\ , , github.


:


func GetAllGroups(ctx context.Context, client *kaspersky.Client) *FullGroupsInfos {
    groups := &FullGroupsInfos{} //    .

    groupParam := kaspersky.HGParams{
        WstrFilter: `
        (&
            (!"KLGRP_CHLDHST_CNT" = 0)
            (!"grp_from_unassigned" = true)
        )`,
        VecFieldsToReturn: []string{
            "id",
            "name",
            "grp_full_name",
            "creationDate",
            "KLGRP_CHLDHST_CNT",
            "KLSRV_HSTSTAT_CRITICAL",
            "KLSRV_HSTSTAT_WARNING",
        },
        PParams: kaspersky.PParams{
            KlsrvhSlaveRecDepth:    0,
            KlgrpFindFromCurVsOnly: true,
        },
        LMaxLifeTime: 100,
    }

    accessor, _, _ := client.HostGroup.FindGroups(ctx, groupParam) //  
    count, _, _ := client.ChunkAccessor.GetItemsCount(ctx, accessor.StrAccessor) //     

    _, _ = client.ChunkAccessor.GetItemsChunk(ctx, kaspersky.ItemsChunkParams{
        StrAccessor: accessor.StrAccessor,
        NStart:      0,
        NCount:      count.Int,
    } , groups) //    
    client.ChunkAccessor.Release(ctx, accessor.StrAccessor) // 

    return groups
}

, API []byte, inteface{} .


:


{
  "pChunk" : {
    "KLCSP_ITERATOR_ARRAY" : [
      {
        "type" : "params",
        "value" : {
          "KLGRP_CHLDHST_CNT" : 1,
          "creationDate" : {
            "type" : "datetime",
            "value" : "2020-03-13T18:48:43Z"
          },
          "grp_full_name" : " /Broken/",
          "id" : 160,
          "name" : "Broken"
        }
      }
    ]
  },
  "PxgRetVal" : 1
}

:


ts, _, _ := client.Tasks.GetAllTasksOfHost(ctx, "domain.name", "d7f6c44c-6743-416d-81b3-343e464f1ec9")

d7f6c44c-6743-416d-81b3-343e464f1ec9 , KSC


:
{ "PxgRetVal": ["101", "117", "118", "192"] }


(, , ) .


func (ts *Tasks) SuspendTask(ctx context.Context, strTask string) ([]byte, error)
func (ts *Tasks) ResumeTask(ctx context.Context, strTask string) ([]byte, error)
func (ts *Tasks) RunTask(ctx context.Context, strTask string) ([]byte, error)
func (ts *Tasks) DeleteTask(ctx context.Context, strTask string) ([]byte, error)



API, KSC 10, KSC 12.


GitHub


.
C.


All Articles