티스토리 뷰
VirusTotal에 회원가입을 하면 일반 사용자가 사용할 수 있는 API key를 제공합니다.
받은 API Key를 사용해서 VirusTotal 웹페이지에 들어가지 않고 파일, URL 검사를 할 수 있습니다.
https://developers.virustotal.com/v2.0/reference
VirusTotal
VirusTotal has built its own in-house file similarity clustering functionality. At present, this clustering works only on PE, PDF, DOC and RTF files and is based on a very simple structural feature hash. This hash can very often be confused by certain comp
developers.virustotal.com
https://support.virustotal.com/hc/en-us/articles/115002146469-API-scripts
API Scripts
VirusTotal's API lets you upload and scan files or URLs, access finished scan reports and make automatic comments without the need of using the website interface. In other words, it allows you to b...
support.virustotal.com
첫 번째 링크에서는 VirusTotal API를 사용하는 법과 예제 코드들을 설명하고,
두 번째 링크에서는 다른 사람들이 VirusTotal API를 사용해서 코딩한 코드들이 있습니다.
#Python 3.7
import json
import sys
import requests
url = 'http://www.virustotal.com/vtapi/v2/file/scan'
file_path = 'file_path'
file_name = 'file_name'
api_key = 'your api key'
def FileScan(filepath, apikey) :
params = {'apikey': apikey}
files = {'file': (open(filepath, 'rb'))}
response = requests.post(url, files = files, params = params)
return response.json()
response = FileScan(file_path, api_key)
sys.stdout = open(file_name + '.txt', 'w+')
print(file_path + ' '+ json.dumps(response, indent = 4))
sys.stdout = open(file_name + '.txt', 'w+')
위 코드는 VirusTotal에서 원하는 파일의 해쉬값을 받아서 txt 파일로 저장하는 코드입니다.
받은 해쉬값을 홈페이지에 입력하면 검사결과를 알 수 있습니다.
#Python 2.7
import postfile
import ast
import urllib
import urllib2
import json
virustotal_url = 'www.virustotal.com'
scan_url = 'https://www.virustotal.com/vtapi/v2/file/scan'
report_url = 'https://www.virustotal.com/vtapi/v2/file/report'
api_key = 'your api key'
file_path_name = 'file_path_name'
params = [('apikey', api_key)]
file_to_send = open(file_path_name, 'rb').read()
files = [('file', file_path_name, file_to_send)]
data = postfile.post_multipart(virustotal_url, scan_url, params, files)
data = ast.literal_eval(data)
resource = data['resource']
parameters = {'resource': resource, 'apikey': api_key}
data = urllib.urlencode(parameters)
req = urllib2.Request(report_url, data)
response = urllib2.urlopen(req)
data = response.read()
data = json.loads(data)
scan = data.get('scans', {})
print file_path_name + ' analysis result!\n------------------------------'
keys = scan.keys()
for key in keys :
print '%-20s : %s' % (key, scan[key]['result'])
print '------------------------------'
위 코드는 VirusTotal에서 원하는 파일의 검사결과를 받아오는 코드입니다.
'Programming > Python' 카테고리의 다른 글
[Python] 리눅스 로그 자동 백업 코드 (0) | 2018.10.15 |
---|
- Total
- Today
- Yesterday
- Reversing
- 유니티
- pwnable
- CodeEngn
- Basic RCE
- Level 06
- Unity
- hackerschool
- c++
- xcz.kr
- Advance RCE
- Programming
- Level 04
- C#
- Level 01
- reversing.kr
- ftz
- Android
- 안드로이드 멘토링
- wargame
- Level 03
- 풀이
- Level 05
- unity2d
- 멘토링
- Write-up
- 17th HackingCamp CTF
- Level 02
- 안드로이드
- HackingCamp
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |