Remove HTTPParty from depends, gonna use the NET/HTTP library from the STDLib, even though it needs more coding to make work.
Replace HTTPParty code with NET/HTTP code.
Move opswat_client and virus_total_client into their own directories for organization
This commit is contained in:
VetheonGames 2024-02-11 11:05:39 -07:00
parent a841b4bce7
commit 4c2f190bed
5 changed files with 55 additions and 25 deletions

View File

@ -8,6 +8,4 @@ gem 'sequel', '~> 5.77'
gem 'sqlite3', '~> 1.7' gem 'sqlite3', '~> 1.7'
gem 'httpparty', '~> 0.2.0'
gem 'dotenv', '~> 2.8' gem 'dotenv', '~> 2.8'

View File

@ -0,0 +1,47 @@
# frozen_string_literal: true
require 'net/http'
require 'uri'
require 'json'
require 'yaml'
# main class for communication with the VirusTotal API v3
class VirusTotalClient
API_KEY = YAML.load_file(File.join(__dir__, '../../config/api_keys.yml'))['virus_total']
BASE_URL = 'https://www.virustotal.com/api/v3/'
# Method to scan URLs
def self.scan_url(url)
uri = URI("#{BASE_URL}urls")
request = Net::HTTP::Post.new(uri)
request['x-apikey'] = API_KEY
request['Content-Type'] = 'application/json'
request.body = { url: }.to_json
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
# TODO: Implement proper response handling
JSON.parse(response.body)
end
# method to upload files to scan
def self.scan_file(file_path)
uri = URI("#{BASE_URL}files")
request = Net::HTTP::Post.new(uri)
request['x-apikey'] = API_KEY
request['accept'] = 'application/json'
request['Content-Type'] = 'multipart/form-data'
form_data = [['file', File.open(file_path)]]
request.set_form form_data, 'multipart/form-data'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
# TODO: Implement proper response handling
JSON.parse(response.body) # Simplified example; adjust based on actual needs
end
end

View File

@ -1,18 +0,0 @@
# frozen_string_literal: true
require 'httparty'
require 'yaml'
# Main class for handling communication with the Virus Total API v3
class VirusTotalClient
API_KEY = YAML.load_file(File.join(__dir__, '../../config/api_keys.yml'))['virus_total']
BASE_URL = 'https://www.virustotal.com/api/v3/'
def self.scan_url(url)
response = HTTParty.post("#{BASE_URL}urls",
headers: { 'x-apikey' => API_KEY },
body: { url: })
# TODO: Implement proper response handling
{ is_safe: response.ok? } # Placeholder: Implement based on actual API response
end
end

View File

@ -1,13 +1,16 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'httparty' require 'httparty'
require_relative 'api_clients/virus_total_client' require_relative 'api_clients/virus_total/virus_total_client'
require_relative 'api_clients/opswat/opswat_client'
# Main class for sending files/links to the security vendors, and getting the response. # Main class for sending files/links to the security vendors, and getting the response.
class VirusScanner class VirusScanner
def self.scan_file(url) def self.scan_file_with_virustotal(file_path)
response = VirusTotalClient.scan_url(url) VirusTotalClient.scan_file(file_path)
# TODO: Implement proper return end
response['is_safe']
def self.scan_file_with_opswat(file_path)
OpswatClient.scan_file(file_path)
end end
end end