VulnCheck 平台採用 API 與入口網站共用的權杖系統。透過這套共用權杖系統,您可以使用同一個權杖存取 API 與網頁入口網站(並在兩者之間自由切換),也能在同一處集中管理您的權杖。本指南將逐步說明如何建立及使用權杖。
若要開始呼叫 VulnCheck 平台的 API,您需要為帳號核發一個權杖。請依照以下步驟操作:
任何連續 30 天未使用的權杖都會失效。
VulnCheck 支援 3 種傳遞權杖的方式。
以自訂標頭的形式加入:Authorization: Bearer insert_token_here。
curl --request GET \
--url https://api.vulncheck.com/v3/index/initial-access \
--header 'Accept: application/json' \
--header 'Authorization: Bearer insert_token_here'
client := &http.Client{}
var responseJSON interface{}
request, _ := http.NewRequest("GET", "https://api.vulncheck.com/v3/index/initial-access", nil)
request.Header.Set("Accept", "application/json")
request.Header.Set("Authorization", "Bearer " + "insert_token_here")
response, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
_ := json.NewDecoder(response.Body).Decode(responseJSON)
import requests
url = "https://api.vulncheck.com/v3/index/initial-access"
headers = {
"accept": "application/json",
"authorization": "Bearer {token}"
}
params = {}
response = requests.get(url, headers=headers, params=params)
print(response.json())
您可以將 API 權杖作為 GET/URL 參數傳遞,方便在瀏覽器中測試權杖及瀏覽端點。
curl --request GET \
--url https://api.vulncheck.com/v3/index/initial-access \
--header 'Accept: application/json' \
--url-query token=insert_token_here
client := &http.Client{}
var responseJSON interface{}
request, _ := http.NewRequest("GET", "https://api.vulncheck.com/v3/index/initial-access", nil)
request.Header.Set("Accept", "application/json")
params := url.Values{}
params.Add("token", "insert_token_here")
response, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
_ := json.NewDecoder(response.Body).Decode(responseJSON)
import requests
url = "https://api.vulncheck.com/v3/index/initial-access"
headers = {
"accept": "application/json"
}
params = {
"token": "insert_token_here"
}
response = requests.get(url, headers=headers, params=params)
print(response.json())
我們也允許以 Cookie 傳遞權杖,這其實正是我們網頁入口網站的運作方式,讓您能透過入口網站存取 API,同時完整掌控您的權杖。
curl --request GET \
--url https://api.vulncheck.com/v3/index/initial-access \
--header 'Accept: application/json' \
--cookie "token=insert_token_here"
client := &http.Client{}
var responseJSON interface{}
request, _ := http.NewRequest("GET", "https://api.vulncheck.com/v3/index/initial-access", nil)
request.Header.Set("Accept", "application/json")
request.AddCookie(&http.Cookie{
Name: "token",
Value: "insert_token_here",
})
response, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
_ := json.NewDecoder(response.Body).Decode(responseJSON)
import requests
url = "https://api.vulncheck.com/v3/index/initial-access"
headers = {
"accept": "application/json"
}
cookies = {
"token": "insert_token_here"
}
response = requests.get(url, headers=headers, cookies=cookies)
print(response.json())
VulnCheck 提供 CLI 與 SDK 來與 API 互動。您可以設定 VC_TOKEN 環境變數,在 CLI 或 SDK 中使用權杖。
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
vulncheck "github.com/vulncheck-oss/sdk-go-v2/v2"
)
func main() {
configuration := vulncheck.NewConfiguration()
configuration.Scheme = "https"
configuration.Host = "api.vulncheck.com"
client := vulncheck.NewAPIClient(configuration)
token := os.Getenv("VULNCHECK_API_TOKEN")
auth := context.WithValue(
context.Background(),
vulncheck.ContextAPIKeys,
map[string]vulncheck.APIKey{
"Bearer": {Key: token},
},
)
resp, httpRes, err := client.IndicesAPI.IndexInitialAccessGet(auth).Execute()
if err != nil || httpRes.StatusCode != 200 {
log.Fatal(err)
}
prettyJSON, err := json.MarshalIndent(resp.Data, "", " ")
if err != nil {
log.Fatalf("Failed to generate JSON: %v", err)
return
}
fmt.Println(string(prettyJSON))
}
import vulncheck_sdk
configuration = vulncheck_sdk.Configuration(host="https://api.vulncheck.com/v3")
configuration.api_key["Bearer"] = "insert_token_here"
with vulncheck_sdk.ApiClient(configuration) as api_client:
indices_client = vulncheck_sdk.IndicesApi(api_client)
api_response = indices_client.index_initial_access_get()
print(api_response.data)
export VC_TOKEN=insert_token_here
vulncheck index browse initial-access