Skip to content

Proxy Support #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions Python/intelx/intelxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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=""):
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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']
5 changes: 3 additions & 2 deletions Python/scripts/intelx.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,21 @@ 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
if 'INTELX_KEY' in os.environ:
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".')
Expand Down
Loading