-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_apex_so.py
50 lines (38 loc) · 1.74 KB
/
list_apex_so.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
#!/usr/bin/env python
#
# Script will read SO from Apex and save to file for checking
import base64
import jwt
import hashlib
import requests
import time
import json
import urllib.parse
from tmconfig import CONFIG
if(CONFIG.use_url_base == ''):
exit()
def create_checksum(http_method, raw_url, headers, request_body):
string_to_hash = http_method.upper() + '|' + raw_url.lower() + '|' + headers + '|' + request_body
base64_string = base64.b64encode(hashlib.sha256(str.encode(string_to_hash)).digest()).decode('utf-8')
return base64_string
def create_jwt_token(appication_id, api_key, http_method, raw_url, headers, request_body,
iat=time.time(), algorithm='HS256', version='V1'):
payload = {'appid': appication_id,
'iat': iat,
'version': version,
'checksum': create_checksum(http_method, raw_url, headers, request_body)}
token = jwt.encode(payload, api_key, algorithm=algorithm).decode('utf-8')
return token
# Use this region to setup the call info of the Apex Central server (server url, application id, api key)
productAgentAPIPath = '/WebApp/api/SuspiciousObjects/UserDefinedSO/'
canonicalRequestHeaders = ''
useRequestBody = ''
useQueryString=""
jwt_token = create_jwt_token(CONFIG.use_application_id, CONFIG.use_api_key, 'GET',
productAgentAPIPath + useQueryString,
canonicalRequestHeaders, useRequestBody, iat=time.time())
headers = {'Authorization': 'Bearer ' + jwt_token , 'Content-Type': 'application/json;charset=utf-8'}
#Choose by call type.
r = requests.get(CONFIG.use_url_base + productAgentAPIPath + useQueryString, headers=headers, verify=False)
#print(r.status_code)
print(json.dumps(r.json(), indent=4))