-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetqitems.py
executable file
·191 lines (171 loc) · 6.55 KB
/
getqitems.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/python3
import base64
import requests
import json
from datetime import datetime,timedelta
#parameters
# -dt <minutes> - specify number of minutes before current time as interval for searching for quarantined items
# -host <hostname> - specify hostname or IP of BD console server
# -k <apikey> - specify API key to connect to BD console server
# -h <help> - show short instructions
# -ca <collector account>
# -cp <collector pass>
# -ch <collector host>
#https://YOUR-HOSTNAME/api/v1.0/jsonrpc/quarantine/exchange
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-dt", "--deltatime",type=int,
help="specify number of minutes before current time as interval for searching for quarantined items",required=True)
parser.add_argument("-host", "--hostname", help="specify hostname or IP of BD console server",required=True)
parser.add_argument("-k", "--apikey", help="specify API key to connect to BD console server",required=True)
parser.add_argument("-ca", "--collectoraccount", help="specify collector account - email address",required=True)
parser.add_argument("-cp", "--collectorpassword",help="specify collector password",required=True)
parser.add_argument("-ch", "--collectorhostname",help="specify collector hostname mailbox server",required=True)
args = parser.parse_args()
apiKey = args.apikey
loginString = apiKey + ":"
encodedBytes = base64.b64encode(loginString.encode())
encodedUserPassSequence = str(encodedBytes,'utf-8')
authorizationHeader = "Basic " + encodedUserPassSequence
datetimenow=datetime.now()
endDate = datetimenow.isoformat()
datetimestart=datetimenow - timedelta(minutes=args.deltatime)
startDate= datetimestart.isoformat()
apiEndpoint_Url = "https://" + args.hostname + "/api/v1.0/jsonrpc/quarantine/exchange"
request = ''' {
"params": {
"page": 1,
"perPage": 100,
"filters": {
# "actionStatus": 1,
"startDate": '''+startDate+''',
"endDate": '''+endDate+''',
}
},
"jsonrpc": "2.0",
"method": "getQuarantineItemsList",
"id": "5399c9b5-0b46-45e4-81aa-889952433d86"
}
'''
result = requests.post(apiEndpoint_Url,data=request,verify=False,headers= {"Content-Type":"application/json","Authorization":authorizationHeader})
#print(result.json())
#for testing:
jsonsample = '''
{
"id":"5399c9b5-0b46-45e4-81aa-889952433d86",
"jsonrpc":"2.0",
"result": {
"page": "2",
"pagesCount": "10",
"perPage": "1",
"total": "10",
"items":[{
"id": "5b7d219bb1a43d170b7b23ee",
"quarantinedOn": "2019-08-01T07:15:20",
"actionStatus": 1,
"endpointId": "5d36c255f23f730fa91944e2",
"endpointName": "Computer 1",
"endpointIP": "57.238.160.118",
"endpointAvailable": true,
"threatName": "Virus 0",
"companyId": "55896b87b7894d0f367b23c6",
"details": {
"threatStatus": 4,
"itemType" : 0,
"detectionPoint": 1,
"email": {
"senderIP": "185.36.136.238",
"senderEmail": "[email protected]",
"subject":
"Test subject_5b7d2128b1a43da20c7b23c6",
"recipients": [
"emailprotected", "email protected"
],
"realRecipients": [
"emailprotected", "email protected"
]
}
}
}]
}
}
'''
#json_q_items = json.load(result.json())
json_q_items = json.loads(jsonsample)
print(type(json_q_items))
quarantineItemsIds=[]
for item in json_q_items["result"]["items"]:
for itemprop in item:
print(itemprop + ":" + json_q_items[itemprop])
quarantineItemsIds.append(json_q_items[id])
#response sample
# {
# "id":"5399c9b5-0b46-45e4-81aa-889952433d86",
# "jsonrpc":"2.0",
# "result": {
# page: 2,
# pagesCount: 10,
# perPage: 1,
# total: 10
# items[{
# "id": "5b7d219bb1a43d170b7b23ee",
# "quarantinedOn": "2019-08-01T07:15:20",
# "actionStatus": 1,
# "endpointId": "5d36c255f23f730fa91944e2",
# "endpointName": "Computer 1",
# "endpointIP": "57.238.160.118",
# "endpointAvailable": true,
# "threatName": "Virus 0",
# "companyId": "55896b87b7894d0f367b23c6",
# "details": {
# "threatStatus": 4,
# "itemType" : 0,
# "detectionPoint": 1,
# "email": {
# "senderIP": "185.36.136.238",
# "senderEmail": "[email protected]",
# "subject":
# "Test subject_5b7d2128b1a43da20c7b23c6",
# "recipients": [
# "[email protected]", "
# [email protected]",
# ]
# "realRecipients": [
# "[email protected]", "
# [email protected]"
# ]
# }
# }
# }]
# }
# }
# de interes:
# id
# quarantinedOn
# actionStatus
# senderIP
#create array of quarantineItemsIds
#call createRestoreQuarantineExchangeItemTask
#https://YOUR-HOSTNAME/api/v1.0/jsonrpc/quarantine/exchange
# Request:
# {
# "params": {
# "quarantineItemsIds": [
# "63896b87b7894d0f367b23c6",
# "65896b87b7894d0f367b23c6"
# ],
# "username": "user@domain",
# "password": "userPassword",
# "email": "[email protected]"
# },
# "jsonrpc": "2.0",
# "method": "createRestoreQuarantineExchangeItemTask",
# "id": "5399c9b5-0b46-45e4-81aa-889952433d86"
# }
# Response:
# {
# "id": "5399c9b5-0b46-45e4-81aa-889952433d86",
# "jsonrpc":"2.0",
# "result": True
# }
#connect to email server to download elements