No Habr, já havia algumas notas sobre a automação do Kaspersky Security Center (KSC)
Aqui e aqui
Hoje, sugiro mergulhar um pouco mais e mudar para um novo nível.Uso: API aberta do KSC para o Kaspersky Security Center 10+.
Para monitorar o status, a distribuição de novas estações de trabalho em grupos, tive que usar o Console de Gerenciamento para gerar relatórios, ele tem uma funcionalidade abrangente, mas a velocidade do trabalho deixa muito a desejar.
E a aparência do suporte à API aberta foi como uma lufada de ar fresco, e imediatamente foi decidido usar essa solução e, como de costume, uma biblioteca foi escrita na linguagem de programação favorita da Go que permitia o acesso ao servidor KSC usando a API fornecida.
Para usar o pacote em nosso projeto, como sempre, precisamos obtê-lo:
go get -u github.com/pixfid/go-ksc/kaspersky
Importe o pacote para o projeto criado.
import (
"github.com/pixfid/go-ksc/kaspersky"
)
Criamos um novo cliente para trabalhar com o servidor 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)
}
A autorização é simples, POST
uma solicitação de terminal /api/v1.0/login
, com a configuração de cabeçalhos de solicitação:
Authorization
: KSCBasic user=base64(login),pass=base64(pass)
X-KSC-VServer
: x
Content-Length
:2
Se for bem-sucedido, o servidor retornará: {}
, , 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.