Skip to content

Commit

Permalink
fix: json parse error when vt look up failed
Browse files Browse the repository at this point in the history
  • Loading branch information
fukusuket committed Sep 17, 2023
1 parent 56a7eaf commit 3df44c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/takajopkg/vtDomainLookup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ var vtAPIDomainChannel: Channel[VirusTotalResult] # channel for receiving parall

proc queryDomainAPI(domain:string, headers: httpheaders.HttpHeaders) {.thread.} =
let response = get("https://www.virustotal.com/api/v3/domains/" & encodeUrl(domain), headers)
let jsonResponse = parseJson(response.body)
var jsonResponse = %* {}
var singleResultTable = newTable[string, string]()
var malicious = false
singleResultTable["Domain"] = domain
singleResultTable["Link"] = "https://www.virustotal.com/gui/domain/" & domain
if response.code == 200:
jsonResponse = parseJson(response.body)
singleResultTable["Response"] = "200"
# Parse values that need epoch time to human readable time
singleResultTable["CreationDate"] = getJsonDate(jsonResponse, @["data", "attributes", "creation_date"])
Expand Down
6 changes: 3 additions & 3 deletions src/takajopkg/vtHashLookup.nim
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Todo: add more info useful for triage, trusted_verdict, signature info, sandbox results etc...
# TODO: add more info useful for triage, trusted_verdict, signature info, sandbox results etc...
# https://blog.virustotal.com/2021/08/introducing-known-distributors.html
# TODO:
# Add output not found to txt file

var vtAPIHashChannel: Channel[VirusTotalResult] # channel for receiving parallel query results

proc queryHashAPI(hash:string, headers: httpheaders.HttpHeaders) {.thread.} =
let response = get("https://www.virustotal.com/api/v3/files/" & hash, headers)
let jsonResponse = parseJson(response.body)
var jsonResponse = %* {}
var singleResultTable = newTable[string, string]()
var malicious = false
singleResultTable["Hash"] = hash
singleResultTable["Link"] = "https://www.virustotal.com/gui/file/" & hash
if response.code == 200:
jsonResponse = parseJson(response.body)
singleResultTable["Response"] = "200"

# Parse values that need epoch time to human readable time
Expand Down
3 changes: 2 additions & 1 deletion src/takajopkg/vtIpLookup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ var vtIpAddressChannel: Channel[VirusTotalResult] # channel for receiving parall

proc queryIpAPI(ipAddress:string, headers: httpheaders.HttpHeaders) {.thread.} =
let response = get("https://www.virustotal.com/api/v3/ip_addresses/" & ipAddress, headers)
let jsonResponse = parseJson(response.body)
var jsonResponse = %* {}
var singleResultTable = newTable[string, string]()
var malicious = false
singleResultTable["IP-Address"] = ipAddress
singleResultTable["Link"] = "https://www.virustotal.com/gui/ip_addresses/" & ipAddress
if response.code == 200:
jsonResponse = parseJson(response.body)
singleResultTable["Response"] = "200"

# Parse values that need epoch time to human readable time
Expand Down

0 comments on commit 3df44c0

Please sign in to comment.