Jump to content

0xcffaedfe

Members
  • Posts

    11
  • Joined

  • Last visited

    Never
  1. yep u need add domain= to Authorization field in header and add user on ksc.
  2. Skip (CertificateValidation)! ServicePointManager.ServerCertificateValidationCallback = Function(se As Object, cert As X509Certificate, chain As X509Chain, sslerror As SslPolicyErrors) True 2. Escape Double! (Name\Password hash must be quoted!) request.Headers.Add("Authorization", "KSCBasic user=""" + ksc_u_b64 + """, pass=""" + ksc_p_b64 + """")
  3. Проблема в неправильном хедере логин и пасс передаются в кавычках: Headers = @{ 'Authorization' = "KSCBasic user=`"$user`", pass=`"$password`"" } ну и на всякий скинуть проверку cерта: Invoke-RestMethod @parameters -SkipCertificateCheck
  4. think u should use another auth method. <?php // get cURL resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, 'https://ip:13299/api/v1.0/Session.StartSession'); // <-! // set method curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // set headers curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: KSCBasic user="login", pass="pass"', 'X-KSC-VServer: x', 'Content-Type: application/json; charset=utf-8', ]); // json body $json_array = [ ]; $body = json_encode($json_array); // set body curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); // send the request and save response to $response $response = curl_exec($ch); // stop if fails if (!$response) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); } echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL; echo 'Response Body: ' . $response . PHP_EOL; // close curl resource to free up system resources curl_close($ch); server response will be as example: {"PxgRetVal":"nngQKNEDkx9E6Pe63Be8eOQ=="} u should user this token in header with key: X-KSC-Session <?php // get cURL resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, 'https://ip:13299/api/v1.0/HostGroup.FindGroups'); // set method curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // set headers curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'X-KSC-VServer: x', 'X-KSC-Session: n9M8NjkzZUADIgn5wnKCkZA==', // !< - Auth token received from Session.StartSession 'Content-Type: application/json; charset=utf-8', ]); // json body $json_array = [ 'vecFieldsToOrder' => null, 'pParams' => [ 'KLGRP_FIND_FROM_CUR_VS_ONLY' => true, 'KLSRVH_SLAVE_REC_DEPTH' => 0 ], 'vecFieldsToReturn' => [ 'id', 'name', 'grp_full_name', 'creationDate', 'KLGRP_CHLDHST_CNT', 'KLSRV_HSTSTAT_CRITICAL', 'KLSRV_HSTSTAT_WARNING' ], 'lMaxLifeTime' => 100, 'wstrFilter' => ' (& (!"KLGRP_CHLDHST_CNT" = 0) (!"grp_from_unassigned" = true) )' ]; $body = json_encode($json_array); // set body curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); // send the request and save response to $response $response = curl_exec($ch); // stop if fails if (!$response) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); } echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL; echo 'Response Body: ' . $response . PHP_EOL; // close curl resource to free up system resources curl_close($ch); but this token expires in 3 minutes =)
  5. as one of the solutions you can create a category in gui ksc read it through api and see how the fields you need look like. working example below... very simple example { "pCategory" : { "CategoryType" : 0, "CustomCategoryCipCompatible" : false, "Md5WithoutSha256Exists" : false, "exclusions" : [], "fromMaster" : false, "inclusions" : [ { "type" : "params", "value" : { "ex_type" : 0, "str" : "text", "str_op" : 3 } } ], "name" : "test", "descr" : "test2", "version" : 65535 } } client.FileCategorizer2.CreateCategory(ctx, kaspersky.CategoryParams{ PCategory: &kaspersky.PCategory{ CategoryType: 0, CustomCategoryCipCompatible: false, Md5WithoutSha256Exists: false, Exclusions: []kaspersky.Exclusions{}, FromMaster: false, Inclusions: []kaspersky.Inclusion{ { Type: "params", InclusionValue: &kaspersky.InclusionValue{ ExType: 0, Str: "text", StrOp: 3, }, }, }, Name: "test", Descr: "test2", Version: 65535, }})
  6. It’s mean strAccessor is expired LMaxLifeTime is very low or u create another session.
  7. I think this is superfluous: curl_setopt($ch, CURLOPT_HTTPHEADER, ['"Content-Type": "application/json"']); curl_setopt($ch, CURLOPT_POSTFIELDS, array()); working example below <?php // get cURL resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, 'https://ksc_ip:13299/api/v1.0/HostGroup.FindGroups'); // set method curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // set headers curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: KSCBasic user="login_hash", pass="pass_hash"', 'X-KSC-VServer: x', 'Content-Type: application/json; charset=utf-8', ]); // json body $json_array = [ 'vecFieldsToOrder' => null, 'pParams' => [ 'KLGRP_FIND_FROM_CUR_VS_ONLY' => true, 'KLSRVH_SLAVE_REC_DEPTH' => 0 ], 'vecFieldsToReturn' => [ 'id', 'name', 'grp_full_name', 'creationDate', 'KLGRP_CHLDHST_CNT', 'KLSRV_HSTSTAT_CRITICAL', 'KLSRV_HSTSTAT_WARNING' ], 'lMaxLifeTime' => 100, 'wstrFilter' => ' (& (!"KLGRP_CHLDHST_CNT" = 0) (!"grp_from_unassigned" = true) )' ]; $body = json_encode($json_array); // set body curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // send the request and save response to $response $response = curl_exec($ch); // stop if fails if (!$response) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); } echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL; echo 'Response Body: ' . $response . PHP_EOL; // close curl resource to free up system resources curl_close($ch);
  8. <?php // get cURL resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, 'https://you_ip:13299/api/v1.0/login'); // set method curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // set headers curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: KSCBasic user="login", pass="pass"', ‘X-KSC-VServer: x', ]); $response = curl_exec($ch); // stop if fails if (!$response) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); } echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL; echo 'Response Body: ' . $response . PHP_EOL; curl_close($ch); worked… also I`ll now writing client library for accessing the KSC, you can see how certain elements work. Here
×
×
  • Create New...