URL
發送並掃描URL
首先發送掃描一個url,要向https://www.virustotal.com/vtapi/v2/url/scan
發送一個http post 請求,
其中api 接受請求中的兩個參數:
url:要掃描的url
apikey: 註冊virus用戶,登錄後得到的public key。這是使用api的關鍵。
當進行批量掃描時候,其中url參數接受一個最大長度爲4的urls列表,並且每個url之間以’\n’作爲間隔符
如果請求速率超過了api限定速率,將被返回http 204狀態碼,若嘗試執行沒有所需權限的函數調用,將被返回http 403異常
e.g.
parameters ={“url”:”http://www.virustotal.com\nhttp://www.virustotal.com”,”apikey”: your api-key}
def scanURL(urls,apikey):
print urls
url = 'https://www.virustotal.com/vtapi/v2/url/scan'
parameters = {"url":urls,"apikey":apikey}
data = urllib.urlencode(parameters)
try:
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json = response.read()
#print json
except urllib2.HTTPError, error:
print 'HTTPError--code:'+str(error.code)
except urllib2.URLError,error:
print 'URLError--reason:'+str(error.reason)
上圖爲返回的json數據:
參數解讀:
scan_id: URL scan report retrieving API 中用於查找掃描報告所需參數
response_code :若搜索項不在VirusTotals的收錄中,將被返回0;若請求項仍入隊請求分析,將被返回-2;若請求項存在並且可被檢索,將返回1。
verbose_msg:提供有關response_code 的詳細信息。
檢索URL掃描報告
檢索一個url的掃描報告,要向 http://www.virustotal.com/vtapi/v2/url/report 提交一個post請求
http post 請求參數:
resource:若給定url,將檢索給定的URL的最新報告。你也可以指定SCAN_ID訪問對應的報告。同時,也可以指定由哈希和scan_ids組合的CSV列表,用來執行批請求(標準速率同樣是最多4個請求)。當多次發送時,scan_ids或URL必須通過新的行字符分隔。
scan(可選參數):當設置爲“1”,將自動提交URL進行分析,如果在VirusTotal服務的數據庫中沒有發現已有的報告,此時,返回的結果將包含一個SCAN_ID字段可用於查詢稍後的分析報告。
apikey:你的API密鑰。
def reportURL(urls,apikey):
print urls
url = "https://www.virustotal.com/vtapi/v2/url/report"
parameters = {"resource": urls, "apikey": apikey,"scan":1}
data = urllib.urlencode(parameters)
try:
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json = response.read()
#print json
except urllib2.HTTPError, error:
print 'HTTPError--code:'+str(error.code)
except urllib2.URLError,error:
print 'URLError--reason:'+str(error.reason)