-
Notifications
You must be signed in to change notification settings - Fork 7
/
fetcher_threatconnect_community_commonURL.py
53 lines (46 loc) · 1.7 KB
/
fetcher_threatconnect_community_commonURL.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
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
import re
import time, base64,hmac, hashlib
import json
def generate_headers(verb, path, accessID, secret_key):
"""
Create the ThreatConnect authentication headers.
"""
timestamp = str(int(time.time()))
signature = "%s:%s:%s" % (path, verb, timestamp)
hmac_signature = hmac.new(secret_key, signature, digestmod=hashlib.sha256).digest()
authorization = 'TC %s:%s' % (accessID, base64.b64encode(hmac_signature))
headers = {'timestamp': timestamp, 'authorization': authorization}
return headers
# User defined variables
feedID = 'threatconnect_Common_community'
community = 'Common%20Community'
killchain = 'unknown'
accessID = '0000000000000000'
secret_key = 'xxxxxxxxxxxxxxxxx'
total_count = 0
todo_count = 500 # Initially setting it to anything above 0
toprint = []
while total_count < todo_count:
request = '/v1/indicators?owner='+community+'&resultStart='+str(total_count)+'&resultLimit=500'
headers = generate_headers('GET', request, accessID, secret_key)
resp = requests.get('https://api.threatconnect.com'+request, headers=headers)
reports = json.loads(resp.content)
try:
todo_count = reports['data']['resultCount']
# Only shows up in the first request, nothing after offset
except:
pass
ilist = reports['data']['indicator']
for x in ilist:
total_count += 1
if x['type'] == 'URL':
tmp_list = {}
tmp_list['url'] = x['summary']
tmp_list['webLink'] = x['webLink']
tmp_list['dateAdded'] = x['dateAdded']
toprint.append(tmp_list)
del tmp_list
print('url,feedID,killchain,description,webLink,dateAdded')
for x in toprint:
print("%s,%s,%s,%s,%s,%s" % (x['url'], feedID, killchain,'ThreatConnect observed URL', x['webLink'], x['dateAdded']))