-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVulDBApiDemoGo.go
78 lines (67 loc) · 1.77 KB
/
VulDBApiDemoGo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
vuldb_api_demo - Go VulDB API Demo
License: GPL-3.0
Required Dependencies:
* bytes
* fmt
* io/ioutil
* net/http
Optional Dependencies: None
*/
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
// API URL
url := "https://vuldb.com/?api"
// Headers for authentication
personalAPIKey := "" // Enter your personal API key here
userAgent := "VulDB API Advanced Go Demo Agent"
// Request body parameters
recent := "5" // Default is 5
details := "0" // Default is 0
id := "" // Example: "290848", Default: id := ""
cve := "" // Example: "CVE-2024-1234", Default: cve := ""
// Construct the request body
var requestBody string
if id == "" && cve == "" {
requestBody = fmt.Sprintf("recent=%s&details=%s", recent, details)
} else if cve != "" {
requestBody = fmt.Sprintf("search=%s&details=%s", cve, details)
} else {
requestBody = fmt.Sprintf("id=%s&details=%s", id, details)
}
// Create HTTP request
client := &http.Client{}
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(requestBody)))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("User-Agent", userAgent)
req.Header.Set("X-VulDB-ApiKey", personalAPIKey)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
// Send the request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// Read the response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
// Output response
if resp.StatusCode == 200 {
fmt.Println("Response:", string(body))
} else {
fmt.Printf("Request failed with response code: %d\n", resp.StatusCode)
}
}