diff --git a/Python/intelx/intelxapi.py b/Python/intelx/intelxapi.py index 48a317d..72f8411 100644 --- a/Python/intelx/intelxapi.py +++ b/Python/intelx/intelxapi.py @@ -24,7 +24,7 @@ class intelx: USER_AGENT = '' # The API key must be always supplied - def __init__(self, key, ua='IX-Python/0.6'): + def __init__(self, key, ua='IX-Python/0.6', proxies=None, verify=True): """ Initialize API by setting the API key. """ @@ -33,6 +33,8 @@ def __init__(self, key, ua='IX-Python/0.6'): self.USER_AGENT = ua self.API_RATE_LIMIT = 1 self.HEADERS = {'X-Key': self.API_KEY, 'User-Agent': self.USER_AGENT} + self.PROXIES = proxies + self.VERIFY = verify def get_error(self, code): """ @@ -73,7 +75,7 @@ def GET_CAPABILITIES(self): """ time.sleep(self.API_RATE_LIMIT) h = {'x-key': self.API_KEY, 'User-Agent': self.USER_AGENT} - r = requests.get(f"{self.API_ROOT}/authenticate/info", headers=h) + r = requests.get(f"{self.API_ROOT}/authenticate/info", headers=h, proxies=self.PROXIES, verify=self.VERIFY) return r.json() def FILE_PREVIEW(self, ctype, mediatype, format, sid, bucket='', e=0, lines=8): @@ -84,7 +86,7 @@ def FILE_PREVIEW(self, ctype, mediatype, format, sid, bucket='', e=0, lines=8): - 1: Picture """ time.sleep(self.API_RATE_LIMIT) - r = requests.get(f"{self.API_ROOT}/file/preview?c={ctype}&m={mediatype}&f={format}&sid={sid}&b={bucket}&e={e}&l={lines}&k={self.API_KEY}") + r = requests.get(f"{self.API_ROOT}/file/preview?c={ctype}&m={mediatype}&f={format}&sid={sid}&b={bucket}&e={e}&l={lines}&k={self.API_KEY}", proxies=self.PROXIES, verify=self.VERIFY) return r.text def FILE_VIEW(self, ctype, mediatype, sid, bucket='', escape=0): @@ -120,7 +122,7 @@ def FILE_VIEW(self, ctype, mediatype, sid, bucket='', escape=0): else: format = 1 time.sleep(self.API_RATE_LIMIT) - r = requests.get(f"{self.API_ROOT}/file/view?f={format}&storageid={sid}&bucket={bucket}&escape={escape}&k={self.API_KEY}") + r = requests.get(f"{self.API_ROOT}/file/view?f={format}&storageid={sid}&bucket={bucket}&escape={escape}&k={self.API_KEY}", proxies=self.PROXIES, verify=self.VERIFY) return r.text def FILE_READ(self, id, type=0, bucket="", filename=""): @@ -143,7 +145,7 @@ def FILE_READ(self, id, type=0, bucket="", filename=""): """ time.sleep(self.API_RATE_LIMIT) h = {'x-key': self.API_KEY, 'User-Agent': self.USER_AGENT} - r = requests.get(f"{self.API_ROOT}/file/read?type={type}&systemid={id}&bucket={bucket}", headers=h, stream=True) + r = requests.get(f"{self.API_ROOT}/file/read?type={type}&systemid={id}&bucket={bucket}", headers=h, stream=True, proxies=self.PROXIES, verify=self.VERIFY) with open(f"{filename}", "wb") as f: f.write(r.content) f.close() @@ -155,7 +157,7 @@ def FILE_TREE_VIEW(self, sid): """ time.sleep(self.API_RATE_LIMIT) try: - r = requests.get(f"{self.API_ROOT}/file/view?f=12&storageid={sid}&k={self.API_KEY}", timeout=5) + r = requests.get(f"{self.API_ROOT}/file/view?f=12&storageid={sid}&k={self.API_KEY}", timeout=5, proxies=self.PROXIES, verify=self.VERIFY) if "Could not generate" in r.text: return False return r.text @@ -258,7 +260,7 @@ def INTEL_SEARCH(self, term, maxresults=100, buckets=[], timeout=5, datefrom="", "terminate": terminate } time.sleep(self.API_RATE_LIMIT) - r = requests.post(self.API_ROOT + '/intelligent/search', headers=h, json=p) + r = requests.post(self.API_ROOT + '/intelligent/search', headers=h, json=p, proxies=self.PROXIES, verify=self.VERIFY) if r.status_code == 200: if r.json()['status'] == 1: return r.json()['status'] @@ -350,7 +352,7 @@ def INTEL_SEARCH_RESULT(self, id, limit): """ time.sleep(self.API_RATE_LIMIT) h = {'x-key': self.API_KEY, 'User-Agent': self.USER_AGENT} - r = requests.get(self.API_ROOT + f'/intelligent/search/result?id={id}&limit={limit}', headers=h) + r = requests.get(self.API_ROOT + f'/intelligent/search/result?id={id}&limit={limit}', headers=h, proxies=self.PROXIES, verify=self.VERIFY) if(r.status_code == 200): return r.json() else: @@ -362,7 +364,7 @@ def INTEL_TERMINATE_SEARCH(self, uuid): """ time.sleep(self.API_RATE_LIMIT) h = {'x-key': self.API_KEY, 'User-Agent': self.USER_AGENT} - r = requests.get(self.API_ROOT + f'/intelligent/search/terminate?id={uuid}', headers=h) + r = requests.get(self.API_ROOT + f'/intelligent/search/terminate?id={uuid}', headers=h, proxies=self.PROXIES, verify=self.VERIFY) if(r.status_code == 200): return True else: @@ -387,7 +389,7 @@ def PHONEBOOK_SEARCH(self, term, maxresults=100, buckets=[], timeout=5, datefrom "terminate": terminate, "target": target } - r = requests.post(self.API_ROOT + '/phonebook/search', headers=h, json=p) + r = requests.post(self.API_ROOT + '/phonebook/search', headers=h, json=p, proxies=self.PROXIES, verify=self.VERIFY) if r.status_code == 200: return r.json()['id'] else: @@ -408,7 +410,7 @@ def PHONEBOOK_SEARCH_RESULT(self, id, limit=1000, offset=-1): """ time.sleep(self.API_RATE_LIMIT) h = {'x-key': self.API_KEY, 'User-Agent': self.USER_AGENT} - r = requests.get(self.API_ROOT + f'/phonebook/search/result?id={id}&limit={limit}&offset={offset}', headers=h) + r = requests.get(self.API_ROOT + f'/phonebook/search/result?id={id}&limit={limit}&offset={offset}', headers=h, proxies=self.PROXIES, verify=self.VERIFY) if(r.status_code == 200): return r.json() else: @@ -438,7 +440,7 @@ def treeview(self, id, bucket): """ time.sleep(self.API_RATE_LIMIT) h = {'x-key': self.API_KEY, 'User-Agent': self.USER_AGENT} - r = requests.get(self.API_ROOT + f'/file/view?f=13&storageid={id}&bucket={bucket}', headers=h) + r = requests.get(self.API_ROOT + f'/file/view?f=13&storageid={id}&bucket={bucket}', headers=h, proxies=self.PROXIES, verify=self.VERIFY) if(r.status_code == 200): return r.json() @@ -581,5 +583,5 @@ def stats(self, search): def selectors(self, document): time.sleep(self.API_RATE_LIMIT) - r = requests.get(self.API_ROOT + f'/item/selector/list/human?id={document}&k={self.API_KEY}') + r = requests.get(self.API_ROOT + f'/item/selector/list/human?id={document}&k={self.API_KEY}', proxies=self.PROXIES, verify=self.VERIFY) return r.json()['selectors'] diff --git a/Python/scripts/intelx.py b/Python/scripts/intelx.py index 0a59ea2..975fa8f 100644 --- a/Python/scripts/intelx.py +++ b/Python/scripts/intelx.py @@ -142,6 +142,7 @@ def main(argv=None): parser.add_argument('--capabilities', help="show your account's capabilities", action="store_true") parser.add_argument('--stats', help="show stats of search results", action="store_true") parser.add_argument('--raw', help="show raw json", action="store_true") + parser.add_argument('--proxy-insecure', help="ignore TLS verification", action="store_false") args = parser.parse_args(argv) # configure IX & the API key @@ -149,13 +150,13 @@ def main(argv=None): if args.identity: ix = IdentityService(os.environ['INTELX_KEY']) else: - ix = intelx(os.environ['INTELX_KEY']) + ix = intelx(os.environ['INTELX_KEY'], verify=args.proxy_insecure) elif args.apikey: if args.identity: ix_identity = IdentityService(args.apikey) else: - ix = intelx(args.apikey) + ix = intelx(args.apikey, verify=args.proxy_insecure) else: exit('No API key specified. Please use the "-apikey" parameter or set the environment variable "INTELX_KEY".')