VirusTotal api 在 python 中的 URL,域名使用

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)

result

上图为返回的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)

result

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
加入这些API可以增强你的搜索和安全分析能力。以下是每个API的简要介绍和如何使用它们: 1. fofa API:可以使用 Fofa API 来搜索互联网上的设备和服务。在使用之前,你需要注册并获取 API 密钥。然后,你可以使用 API 来执行各种查询,例如根据 IP 地址、端口、协议、地理位置等来搜索设备。示例代码如下: ```python import requests api_email = 'your_email' api_key = 'your_api_key' query = 'title="admin" && country="CN"' res = requests.get(f"https://fofa.so/api/v1/search/all?email={api_email}&key={api_key}&qbase64={query}") print(res.json()) ``` 2. Shodan API:与 Fofa API 类似,Shodan API 也可以用来搜索互联网上的设备和服务。你需要注册并获取 API 密钥,然后可以使用 API 来执行各种查询。例如,根据 IP 地址、端口、协议、服务等搜索设备。示例代码如下: ```python import shodan api_key = 'your_api_key' api = shodan.Shodan(api_key) query = 'apache' results = api.search(query) for result in results['matches']: print(result['ip_str']) ``` 3. GitHub API:GitHub API 可以用来搜索代码库、获取代码库信息、获取提交历史记录等。你需要注册并获取 API 密钥,然后可以使用 API 来执行各种查询。例如,搜索代码仓库、获取仓库信息、获取提交历史记录等。示例代码如下: ```python import requests api_key = 'your_api_key' headers = {'Authorization': f'token {api_key}'} # Search repositories query = 'language:python' res = requests.get(f'https://api.github.com/search/repositories?q={query}', headers=headers) print(res.json()) # Get repository information repo_name = 'torvalds/linux' res = requests.get(f'https://api.github.com/repos/{repo_name}', headers=headers) print(res.json()) # Get commit history res = requests.get(f'https://api.github.com/repos/{repo_name}/commits', headers=headers) print(res.json()) ``` 4. VirusTotal APIVirusTotal API 可以用来分析文件、URL 和 IP 地址的恶意程度。你需要注册并获取 API 密钥,然后可以使用 API 来执行各种分析。例如,分析文件、URL 和 IP 地址的恶意程度,获取恶意软件样本等。示例代码如下: ```python import requests api_key = 'your_api_key' headers = {'x-apikey': api_key} # Analyze file file_hash = 'e8f91b8e4b9f0dbd382bfe6c9f776b2c' res = requests.get(f'https://www.virustotal.com/api/v3/files/{file_hash}', headers=headers) print(res.json()) # Analyze URL url = 'https://www.google.com' res = requests.post(f'https://www.virustotal.com/api/v3/urls', headers=headers, json={'url': url}) print(res.json()) # Analyze IP address ip_address = '8.8.8.8' res = requests.get(f'https://www.virustotal.com/api/v3/ip_addresses/{ip_address}', headers=headers) print(res.json()) ``` 以上是如何使用 fofa、shodan、github 和 virustotalAPI 进行搜索和分析的示例代码。注意,在使用这些 API 时需要遵守相应的使用条款和政策。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值