Repository navigation
Expand file tree
/
Copy pathpython_oop.py
More file actions
126 lines (104 loc) · 4.16 KB
/
Copy pathpython_oop.py
File metadata and controls
126 lines (104 loc) · 4.16 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import json
import requests
import resilient
import configparser
import time
import os
global basedir
basedir = os.path.abspath(os.path.dirname(__file__))
class alienVault():
url = 'https://otx.alienvault.com/api/v1/pulses/5d120d47d09d67b4d8dc5241'
def __init__(self,headers):
self.headers=headers
def fetch_feed(self):
response = requests.get(self.url, headers=self.headers)
response_json = response.json()
# print(json.dumps(response_json, indent=4))
return response_json
#def send_feed(self,feed):
# with open('eventfeeds.json','a+') as write_file:
# json.dump(feed, write_file)
# write_file.write("\n")
class resilientAPI():
def __init__(self):
pass
def client_connection(self):
config = configparser.ConfigParser()
section = "resilient"
config.read("config.cfg")
host = config.get(section, 'host')
port = config.get("resilient", 'port')
email = config.get("resilient", 'email')
password = config.get("resilient", 'password')
org = config.get("resilient", 'org')
url = "https://{0}:{1}".format(host, port or 443)
client = resilient.SimpleClient(org_name=org,
base_url=url,
verify=False)
userinfo = client.connect(email, password)
assert userinfo
print("working")
return client
def fetch_incident(self, client):
incident_id = 2120
url = "/incidents/{}?handle_format=names".format(incident_id)
response = client.get(url)
assert response
return response
class KeyInformationGathering():
eventFeeds=[]
def __init__(self):
pass
def save_feed(self, feed):
list_of_feeds=[]
for i in feed:
list_of_feeds.append(feed)
# print(json.dumps(list_of_feeds, indent=4))
with open('eventfeeds.json', 'a+') as write_file:
json.dump(feed, write_file)
# write_file.write(",\n")
def retrieve_key_info(self):
with open('eventfeeds.json','r') as read_file:
data=json.load(read_file)
for i in data:
#print(json.dumps(i, indent=4))
if 'id' in i or 'author' in i:
try:
# resilient info gathering
id = i['id']
eventName=i['name']
orgName=i['properties']['gsma_member']
date=i['create_date']
tlp=i['severity_code']
category=i['incident_type_ids'][0]
self.store_key_info(id, eventName, orgName, tlp, category, date)
except:
# alien vault info gathering
id = i['author']['id']
eventName = i['name']
orgName = i['author_name']
tlp = i['TLP']
category = i['industries'][0]
date = i['created']
self.store_key_info(id, eventName, orgName, tlp, category, date)
def store_key_info(self, id, eventName, orgName, tlp, category, date):
tempFeed={}
tempFeed.update( {"id":id, 'eventName':eventName, 'orgName':orgName,
'date':date, 'tlp':tlp, 'category':category})
KeyInformationGathering.eventFeeds.append(tempFeed)
print(json.dumps(KeyInformationGathering.eventFeeds, indent=4))
def main():
headers = {
'X-OTX-API-KEY': '4dcb5c735bcbc704ab7c3744df540e5d8caece6089684dcb68feb2c733a1b5d9'
}
apiObject = KeyInformationGathering()
otxObject = alienVault(headers)
otx_feed = otxObject.fetch_feed()
# otxObject.send_feed(otx_feed)
resilientObject = resilientAPI()
resilient_feed = resilientObject.fetch_incident(resilientObject.client_connection())
KeyInformationGathering.save_feed(None, [otx_feed, resilient_feed])
apiObject.retrieve_key_info()
# otxObject.send_feed(feed)
if __name__ == "__main__":
main()