From 895779abe599605f9e4ae714071766e30a6783f1 Mon Sep 17 00:00:00 2001 From: AHISSH <74668676+AJHissh@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:20:52 +0800 Subject: [PATCH 1/4] Create shodan-simplified.py --- Shodan-API-Simplified/shodan-simplified.py | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Shodan-API-Simplified/shodan-simplified.py diff --git a/Shodan-API-Simplified/shodan-simplified.py b/Shodan-API-Simplified/shodan-simplified.py new file mode 100644 index 0000000000..323e819c6a --- /dev/null +++ b/Shodan-API-Simplified/shodan-simplified.py @@ -0,0 +1,94 @@ +import shodan +import requests +import json +import os + + +print('--------------WELCOME TO THE EASE-OF-USE SHODAN API PROGRAM---------------') +print('--------------------------------------------------------------------------') +print('😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎') + +## Checks if there is a stored api key in shodan_api.json +try: + with open('shodan_api.json') as file: + api_key = json.load(file) + print("Successfully loaded pre-saved key") +except: +## If there is no shodan_api.json file, you will be requested to input one + api_key = input('Please enter your shodan api key to get started: ') + data = api_key + with open('shodan_api.json', 'w+') as outfile: + json.dump(data, outfile, indent=2) +finally: + print('Starting program.............') + +## Stores your API key for current session +api = shodan.Shodan(api_key) + +## Retrieves IP info from target IP address +def shodan_ip_info(): + x = True + while x is True: + ip_add = input('enter target IP address: ') + try: + info = api.host(ip_add) + ## Saves IP information into shodan_data.json + with open('shodan_data.json', 'w+') as datafile: + json.dump(info, datafile, indent=2) + print(info) + print('---------------------------------------------') + print(f"Output file has been saved at: {os.path.dirname(os.path.abspath(__file__))}\shodan_data.json") + + ## Throws an error if API key is invalid or if target IP has no information + except shodan.APIError as error: + print('Error:', error) + finally: + ## Asks user for next steps + cont_or_exit = str(input('type "main" to go to main menu || type "again" to repeat || type "exit" to exit: ')) + if cont_or_exit in ['Main', 'main', 'MAIN']: + main() + elif cont_or_exit in ['Again', 'again', 'AGAIN']: + x = True + elif cont_or_exit in ['Exit', 'exit', 'EXIT']: + x = False + exit() + +## Targets an IP and finds open ports +def shodan_port_info(): + x = True + while x == True: + try: + ip_add = input('enter target IP address: ') + ## Retrieves Port information from target IP address + host = requests.get(f"https://internetdb.shodan.io/{ip_add}").json() + print(host) + ## Saves Port information into a file called shodan_port_data.json + with open('shodan_port_data.json', 'w+') as portfile: + json.dump(host, portfile, indent=2) + print(f"Output file has been saved at: {os.path.dirname(os.path.abspath(__file__))}\shodan_port_data.json") + ## No API Key needed for this process, so only notifies user if there was any Port information or not + except: + print('No port information for that IP') + finally: + ## Asks user for next steps + cont_or_exit = str(input('type "main" to go to main menu || type "again" to repeat || type "exit" to exit: ')) + if cont_or_exit in ['Main', 'main', 'MAIN']: + main() + elif cont_or_exit in ['Again', 'again', 'AGAIN']: + x = True + elif cont_or_exit in ['Exit', 'exit', 'EXIT']: + x = False + exit() + +def main(): + select = input('Type in 1 for IP address info OR Type in 2 for IP Port Info: ') + if select == '1': + shodan_ip_info() + if select == '2': + shodan_port_info() + else: + print('Did not select an option') + exit() + +main() + From 0ecd6cdf15903693d275bcfa760f1893915daaa4 Mon Sep 17 00:00:00 2001 From: AHISSH <74668676+AJHissh@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:21:57 +0800 Subject: [PATCH 2/4] Create Readme.md --- Shodan-API-Simplified/Readme.md | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Shodan-API-Simplified/Readme.md diff --git a/Shodan-API-Simplified/Readme.md b/Shodan-API-Simplified/Readme.md new file mode 100644 index 0000000000..7f14e740d8 --- /dev/null +++ b/Shodan-API-Simplified/Readme.md @@ -0,0 +1,37 @@ +# Shodan API Ease-of-Use + +[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com) + +This project is adds functionality to a basic use of the Shodan API (NOT the shodan cli), allowing for structured input and repeatability. + +## Usage +* Run the script with python +* ex. python shodan_ip_port_info.py +* Enter your shodan API key when prompted +* Follow prompts to choose options + +## Output: + 1. Run the python file and enter your API + +![shodan1](https://user-images.githubusercontent.com/74668676/197636772-33a222ee-f466-4267-867f-0667146086f4.PNG) + +------------------------------------------------------------------------------------------------------------------------------------ + + 1.1. If your API key is stored in the directory in the file shodan_api.json - you can go straight to the program + +![shodan_saved_api](https://user-images.githubusercontent.com/74668676/197637533-00abcd36-ee04-4ad5-a346-80b9b2bb276d.PNG) + +** If you have reset your API key, you will have to delete shodan_api.json to input your new API key....for now. + + +------------------------------------------------------------------------------------------------------------------------------------ + + + 2. Data from your searches will be saved in the file directory. + + +![shodan3](https://user-images.githubusercontent.com/74668676/197636907-278f95b2-4462-4411-8d78-8872f4c8598f.PNG) + + +## Author +Written by [ajhissh](https://github.com/AJHissh) From 7107ddcfa07bd7ecf01d5d2a10b67008858280dd Mon Sep 17 00:00:00 2001 From: AHISSH <74668676+AJHissh@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:22:50 +0800 Subject: [PATCH 3/4] Create requirements.txt --- Shodan-API-Simplified/requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Shodan-API-Simplified/requirements.txt diff --git a/Shodan-API-Simplified/requirements.txt b/Shodan-API-Simplified/requirements.txt new file mode 100644 index 0000000000..e43ad5e58b --- /dev/null +++ b/Shodan-API-Simplified/requirements.txt @@ -0,0 +1,4 @@ +shodan +requests +json +os From 81375161c525da6d14090f4528fd0d09fe9a04cb Mon Sep 17 00:00:00 2001 From: AHISSH <74668676+AJHissh@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:46:02 +0800 Subject: [PATCH 4/4] Update Readme.md --- Shodan-API-Simplified/Readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Shodan-API-Simplified/Readme.md b/Shodan-API-Simplified/Readme.md index 7f14e740d8..0f1fa2ed73 100644 --- a/Shodan-API-Simplified/Readme.md +++ b/Shodan-API-Simplified/Readme.md @@ -2,7 +2,9 @@ [![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com) -This project is adds functionality to a basic use of the Shodan API (NOT the shodan cli), allowing for structured input and repeatability. +This project is adds functionality to a basic use of the Shodan API (NOT the shodan cli), allowing for ease-of-use, repeatability and storage. + +You can add this program to PATH so you can call it from the CLI, renaming it to a shorter name would be best if you do this - Also, make sure you're in a directory where you don't mind having files saved. ## Usage * Run the script with python