-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVulDBApiDemoRuby.rb
75 lines (63 loc) · 1.95 KB
/
VulDBApiDemoRuby.rb
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
=begin
vuldb_api_demo - Ruby VulDB API Demo
License: GPL-3.0
Required Dependencies:
* net/http
* uri
* json
Optional Dependencies: None
=end
require 'net/http'
require 'uri'
require 'json'
class VulDBApiDemo
def self.run
begin
# API-URL
url = URI.parse("https://vuldb.com/?api")
# Headers for authentication
personal_api_key = "" # Enter your personal API key here.
user_agent = "VulDB API Advanced Ruby Demo Agent"
# Request body parameters
recent = "5" # Default value is "5"
details = "0" # Default value is "0"
id = nil # Example: "290848", enter specific VulDB id to search for (Default value is nil)
cve = nil # Example: "CVE-2024-1234", enter a CVE to search for (Default value is nil)
# Construct the request body
request_body =
if id.nil? && cve.nil?
"recent=#{recent}&details=#{details}"
elsif !cve.nil?
"search=#{cve}&details=#{details}"
else
"id=#{id}&details=#{details}"
end
# Initialize the HTTP request
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path)
request["User-Agent"] = user_agent
request["X-VulDB-ApiKey"] = personal_api_key
request.body = request_body
# Send the request
response = http.request(request)
if response.code.to_i == 200
# Parse and display the response body
puts "Response:"
puts response.body
else
# Handle non-200 response codes
puts "Request failed with response code: #{response.code}"
puts "Response message: #{response.message}"
end
rescue URI::InvalidURIError => e
puts "Invalid URI: #{e.message}"
rescue Net::HTTPError => e
puts "HTTP Error: #{e.message}"
rescue StandardError => e
puts "Error: #{e.message}"
end
end
end
# Run the demo
VulDBApiDemo.run