-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathbazaar_query.py
39 lines (31 loc) · 1.4 KB
/
bazaar_query.py
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
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
import requests
import json
import argparse
from jq import jq
__author__ = "Corsin Camichel"
__copyright__ = "Copyright 2020, Corsin Camichel"
__license__ = "Creative Commons Attribution-ShareAlike 4.0 International License."
__version__ = "1.0"
__email__ = "cocaman@gmail.com"
parser = argparse.ArgumentParser(description='Query sample information by tag or signature on Malware Bazaar by abuse.ch')
parser.add_argument('-t', '--type', help='Query type (tag or signature)', type=str, metavar="TYPE", default="tag", choices=["tag", "signature"], required=True)
parser.add_argument('-q', '--query', help='Query value (e.g. trickbot, exe)', type=str, metavar="QUERY", required=True)
parser.add_argument('-f', '--field', help='Single field you want', type=str, metavar="FIELD", required=False, choices=['sha256_hash', 'sha1_hash', 'md5_hash', 'file_name', 'signature', 'imphash'])
args = parser.parse_args()
if(args.type == "tag"):
data = {
'query': 'get_taginfo',
'tag': ''+args.query+'',
}
else:
data = {
'query': 'get_siginfo',
'signature': ''+args.query+'',
}
response = requests.post('https://mb-api.abuse.ch/api/v1/', data=data, timeout=15)
json_response = response.content.decode("utf-8", "ignore")
if(args.field):
query = ".data[]." + args.field
json_response = jq(query).transform(text=json_response, text_output=True)
print(json_response)