Skip to content

Commit

Permalink
Merge pull request #3 from IntelligenceX/python-code
Browse files Browse the repository at this point in the history
Adding Python implementation
  • Loading branch information
Kleissner committed Apr 4, 2019
2 parents 6612d8b + 9db9bc6 commit 9d10b87
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 4 deletions.
45 changes: 45 additions & 0 deletions Python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Intelligence X API Python client

1. [ix_search.py to search and show results](ix_search.py)
2. [ix_phonebook.py to make a phonebook lookup](ix_phonebook.py)

## Usage

First, make sure to download the dependencies:

```
pip install termcolor
pip install requests
```

Using the Python files is straight forward:

```shell
ix_search.py <selector>
ix_phonebook.py <selector>
```

Examples:

```shell
ix_search.py test.com
ix_phonebook.py test.com
```

The results are currently displayed as raw JSON data. Contributions for a more user-friendly representation are welcome.

## Notes

If you have an account on intelx.io go to the developer tab at https://intelx.io/account?tab=developer to get your own API key and URL.

In the `ix_search.py` change the default API host and key here:

```python
ix_search("public.intelx.io","9df61df0-84f7-4dc7-b34c-8ccfb8646ace",sys.argv[1])
```

The same for `ix_phonebook.py`:

```python
ixphonebook("public.intelx.io","9df61df0-84f7-4dc7-b34c-8ccfb8646ace",sys.argv[1])
```
67 changes: 67 additions & 0 deletions Python/ix_phonebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import re,sys,os,time
import requests
import json
from termcolor import colored
import urllib
from datetime import date
import datetime


#Phonebook search that will return results for a given selector
def ixphonebook(baseurl,apikey,term):

headers = {
"User-Agent": "ix-client/python",
"x-key": apikey,
}

payload = {
"term": term,
"buckets": [],
"lookuplevel": 0,
"maxresults": 10,
"timeout": 0,
"datefrom": "",
"dateto": "",
"sort": 4,
"media": 0,
"terminate": []
}

print(colored("[+] " + str(date.today()) + ": Kicking off phonebook query of " + str(term) + " with max results set at " + str(payload['maxresults']),"red"))

#initial POST to intelligence X service to retrieve the results ID and do all the fun stuff
getid = requests.post("https://" + baseurl + "/phonebook/search",data=json.dumps(payload),headers=headers)
id_response = getid.json()

if id_response['status'] == 0:
print(colored("[+]Successful API Authentication. Searching available records...","green"))
resulturl = "https://" + baseurl + "/phonebook/search/result?id=%s" %str(id_response['id'])

status = 3 # status 3 = No results yet, keep trying. 0 = Success with results
while status == 3 or status == 0:

getresults = requests.get(resulturl,headers=headers)
data = getresults.json()
status = data['status']

if status == 0 or status == 1:
print(data)
elif status == 2:
print("----------------------------------------------")
print("[!] Error Code 2 Search ID Not Found ")
print("----------------------------------------------")

if id_response['status'] == 1:
print("[!]Invalid term used.")

if id_response['status'] == 2:
print("[!] Reached the MAX number of concurrent connections for this API Key.")

if __name__ == "__main__":

start = time.time()
#python ix_phonebook.py <selector>
ixphonebook("public.intelx.io","9df61df0-84f7-4dc7-b34c-8ccfb8646ace",sys.argv[1])
end = time.time()
print(colored("[*] The script executed in [" + str((end-start)) + " seconds|" + str(((end-start)/60)) + " minutes].","blue"))
69 changes: 69 additions & 0 deletions Python/ix_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import re,sys,os,time
import requests
import json
from termcolor import colored
import urllib


def ix_search(baseurl,apikey,term):

headers = {
"User-Agent": "ix-client/python",
"x-key": apikey,
}

payload = {
"term": term,
"buckets": [],
"lookuplevel": 0,
"maxresults": 10, #change the limit of max results here
"timeout": 0,
"datefrom": "",
"dateto": "",
"sort": 4,
"media": 0,
"terminate": []
}

searchurl = 'https://' + baseurl + '/intelligent/search'
getid = requests.post("https://" + baseurl + "/intelligent/search",data=json.dumps(payload),headers=headers)

if getid.status_code == 200:
id_response = getid.json()

#Authenticate to API
if id_response['status'] == 0:
print(colored("[+]Successful API Authentication. Starting records search.","green"))
#Craft API URL with the id to return results
resulturl = str(searchurl) + "/result?id=%s" %str(id_response['id'])

status = 3 # status 3 = No results yet, keep trying. 0 = Success with results
while status == 3 or status == 0:

getresults = requests.get(resulturl,headers=headers)
data = getresults.json()
status = data['status']

if status == 0 or status == 1:
#print data in json format to manipulate as desired
print(data)
elif status == 2:
print("----------------------------------------------")
print("[!] Error Code 2 Search ID Not Found ")
print("----------------------------------------------")

else:
print("----------------------------------------------")
print("[!] Error Code Status: <" + str(getid.status_code) + ">")
print("----------------------------------------------")
print("204 | No Content")
print("400 | Bad Request. Invalid input.")
print("401 | Unauthorized. Access not authorized.")
print("402 | Payment Required. No credits available")
print("404 | Not Found. Item or identifier not found.")
print("----------------------------------------------")

if __name__ == "__main__":
#python ix_search.py <selector>
ix_search("public.intelx.io","9df61df0-84f7-4dc7-b34c-8ccfb8646ace",sys.argv[1])

17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ The SDK contains these parts:
1. [API documentation](Intelligence%20X%20Public%20API.pdf)
2. [HTML code example](HTML/search.html)
3. [PHP code example](PHP/index.php)
4. [Go package and code](Go/ixapi/README.md)
5. [API calls in Fiddler archive](Public%20API%20Examples%20Fiddler.saz)
4. [Python code examples](Python/)
5. [Go package and code](Go/ixapi/README.md)
6. [API calls in Fiddler archive](Public%20API%20Examples%20Fiddler.saz)

## Link to intelx.io

Instead of directly using the API, you can always do the ghetto version instead and just link to the website.

```
https://intelx.io/?s=[search term]
```

Examples:

```
https://intelx.io/?s=test.com
https://intelx.io/?s=test@example.com
```
Expand All @@ -40,8 +44,13 @@ The search engine supports only the following strong selector types. Anything el
* Credit card number
* IBAN

## Credits

Special thanks for their contributions to:
* Cyberblack for providing the Python code in Q1 2019

## Contact

For any questions please contact <info@intelx.io>. Feel free to use the issue tracker for any feature requests and bug reports.
We love contributions! Feel free to use the issue tracker for any feature requests, bug reports and contributions. You can contact us via email <info@intelx.io>.

&copy; 2018 Intelligence X
&copy; 2018 - 2019 Intelligence X

0 comments on commit 9d10b87

Please sign in to comment.